Changed home screen to use account models instead of user model. Home screen now shows multiple accounts

This commit is contained in:
Deon George
2023-05-09 19:28:51 +09:00
parent 790ece14d1
commit dde11f73f5
11 changed files with 174 additions and 157 deletions

View File

@@ -20,76 +20,102 @@
@include('common.account.widget.summary')
</div>
<div class="row">
<div class="col-12">
<div class="card-header bg-white">
<ul class="nav nav-pills">
<li class="nav-item"><a class="nav-link {{ (! session()->has('supplier_update')) ? 'active' : '' }}" href="#tab-services" data-toggle="tab">Services</a></li>
{{--
<!-- @todo this is not working -->
<li class="nav-item"><a class="nav-link" href="#tab-nextinvoice" data-toggle="tab">Next Invoice</a></li>
--}}
<li class="nav-item"><a class="nav-link" href="#tab-futureinvoice" data-toggle="tab">Future Invoice</a></li>
<div class="card card-light card-tabs">
<div class="card-header p-0 pt-1">
<ul class="nav nav-tabs" id="accounts-tab" role="tablist">
<li class="pt-2 px-3"><h3 class="card-title">Accounts</h3></li>
@foreach($o->my_accounts as $ao)
<li class="nav-item">
<a class="nav-link @if(! $loop->index)active @endif" href="#account_{{ $ao->id }}" data-toggle="tab" aria-controls="account_{{ $ao->id }}" aria-selected="true">{{ $ao->name }}</a>
</li>
@endforeach
@canany('reseller','wholesaler')
<li class="nav-item ml-auto"><a class="nav-link {{ session()->has('supplier_update') ? 'active' : '' }}" href="#tab-supplier" data-toggle="tab">Supplier</a></li>
@if ($o == $user)
<li class="nav-item "><a class="nav-link" href="#tab-reseller" data-toggle="tab">Reseller</a></li>
@endif
@endcanany
</ul>
</div>
@canany('reseller','wholesaler')
@if ($o === $user)
<li class="nav-item ml-auto">
<a class="nav-link" href="#tab-reseller" data-toggle="tab">Reseller</a>
</li>
@endif
@endcanany
</ul>
</div>
<div class="card-body pl-0 pr-0">
<div class="tab-content">
<div class="tab-pane {{ (! session()->has('supplier_update')) ? 'active' : '' }}" id="tab-services">
<div class="row">
<div class="col-12 col-xl-7">
@include('service.widget.active')
</div>
<div class="col-12 col-xl-5">
@include('u.invoice.widgets.due')
@include('u.invoice.widgets.list')
@include('u.payment.widgets.list')
</div>
</div>
</div>
{{--
<!-- @todo this is not working -->
<div class="tab-pane" id="tab-nextinvoice">
<div class="card-body">
<div class="tab-content" id="accounts-tab-content">
@foreach($o->my_accounts as $ao)
<div class="tab-pane fade @if(! $loop->index)show active @endif" id="account_{{ $ao->id }}" role="tabpanel" aria-labelledby="account_{{ $ao->id }}">
<div class="row">
<div class="col-12">
@include('u.invoice.widgets.next',['future'=>FALSE])
<div class="card-header bg-white">
<ul class="nav nav-pills">
<li class="nav-item"><a class="nav-link {{ (! session()->has('supplier_update')) ? 'active' : '' }}" href="#tab-services" data-toggle="tab">Services</a></li>
{{--
<!-- @todo this is not working -->
<li class="nav-item"><a class="nav-link" href="#tab-nextinvoice" data-toggle="tab">Next Invoice</a></li>
--}}
<li class="nav-item"><a class="nav-link" href="#tab-futureinvoice" data-toggle="tab">Future Invoice</a></li>
<li class="nav-item ml-auto">
<a class="nav-link {{ session()->has('supplier_update') ? 'active' : '' }}" href="#tab-supplier" data-toggle="tab">Supplier</a>
</li>
</ul>
</div>
<div class="card-body pl-0 pr-0">
<div class="tab-content">
<div class="tab-pane {{ (! session()->has('supplier_update')) ? 'active' : '' }}" id="tab-services">
<div class="row">
<div class="col-12 col-xl-7">
@include('service.widget.active',['o'=>$ao])
</div>
<div class="col-12 col-xl-5">
@include('invoice.widget.due',['o'=>$ao])
@include('invoice.widget.list',['o'=>$ao])
@include('payment.widget.list',['o'=>$ao])
</div>
</div>
</div>
{{--
<!-- @todo this is not working -->
<div class="tab-pane" id="tab-nextinvoice">
<div class="row">
<div class="col-12">
@include('u.invoice.widgets.next',['future'=>FALSE])
</div>
</div>
</div>
--}}
<div class="tab-pane" id="tab-futureinvoice">
<div class="row">
<div class="col-12 col-xl-9">
@include('invoice.widget.next',['future'=>TRUE])
</div>
</div>
</div>
@canany('reseller','wholesaler')
<div class="tab-pane {{ session()->pull('supplier_update') ? 'active' : '' }}" id="tab-supplier" role="tabpanel">
@include('user.widget.supplier')
</div>
@endcanany
</div>
</div>
</div>
</div>
</div>
--}}
@endforeach
<div class="tab-pane" id="tab-futureinvoice">
<div class="row">
<div class="col-12 col-xl-9">
@include('u.invoice.widgets.next',['future'=>TRUE])
</div>
</div>
</div>
@if ($o == $user)
@canany('reseller','wholesaler')
<div class="tab-pane" id="tab-reseller">
@include('r.home.widgets.home')
</div>
@endcanany
@endif
@if ($o == $user)
@canany('reseller','wholesaler')
<div class="tab-pane {{ session()->pull('supplier_update') ? 'active' : '' }}" id="tab-supplier">
@include('user.widget.supplier')
<div class="tab-pane" id="tab-reseller" role="tabpanel">
@include('r.home.widgets.home')
</div>
@endcanany
</div>
@endif
</div>
</div>
</div>

View File

@@ -1,3 +1,4 @@
<!-- $o = Account::class -->
<!-- Show outstanding invoices -->
<div class="card card-warning">
<div class="card-header">
@@ -5,16 +6,14 @@
</div>
<div class="card-body">
@if(($x=$o->invoices()->with(['items.taxes','paymentitems.payment','account'])->get()->where('due','>',0))->count())
<table class="table table-bordered w-100" id="invoices_due">
@if(($x=$o->invoices->where('due','>',0))->count())
<table class="table table-bordered w-100" id="invoices_due_{{ $o->id }}">
<thead>
<tr>
<th>Account</th>
<th>#</th>
<th>Issued</th>
<th>Due</th>
<th class="text-right">Total</th>
<th class="text-right">Payments</th>
<th class="text-right">Outstanding</th>
</tr>
</thead>
@@ -23,11 +22,9 @@
@foreach ($x as $oo)
<tr @if ($oo->due_at->isPast()) class="table-danger" @endif>
<td>{{ $oo->account->name }}</td>
<td><a href="{{ url('u/invoice',$oo->id) }}">{{ $oo->sid }}</a></td>
<td>{{ $oo->created_at->format('Y-m-d') }}</td>
<td><a href="{{ url('u/invoice',$oo->id) }}">{{ $oo->lid }}</a></td>
<td>{{ $oo->due_at->format('Y-m-d') }}</td>
<td class="text-right">${{ number_format($oo->total,2) }}</td>
<td class="text-right">${{ number_format($oo->paid,2) }}</td>
<td class="text-right">${{ number_format($oo->due,2) }}</td>
</tr>
@endforeach
@@ -45,23 +42,21 @@
@js(datatables,bootstrap4|rowgroup)
<script type="text/javascript">
$(document).ready(function() {
$('#invoices_due').DataTable({
order: [[0,'asc'],[3,'desc']],
rowGroup: {
dataSrc: 0,
},
columnDefs: [
{
targets: [0],
visible: false,
}
],
@if ($x->count())
$(document).ready(function() {
$('#invoices_due_{{ $o->id }}').DataTable({
order: [[0,'asc'],[3,'desc']],
rowGroup: {
dataSrc: 0,
},
columnDefs: [
{
targets: [0],
visible: false,
}
],
});
});
$('#invoices_due tbody').on('click','tr', function () {
$(this).toggleClass('selected');
});
});
@endif
</script>
@append

View File

@@ -1,18 +1,18 @@
<!-- $o = Account::class -->
<!-- Show past 12 months invoices -->
<div class="card card-dark">
<div class="card card-success">
<div class="card-header">
<h3 class="card-title">Past Invoices</h3>
</div>
<div class="card-body">
@if(($x=$o->invoices()->where('invoices.created_at','>',\Carbon\Carbon::now()->subMonths(12))->with(['items.taxes','paymentitems.payment','account.country.currency'])->get()->where('due','<=',0))->count())
<table class="table table-bordered w-100" id="invoices_past">
@if(($x=$o->invoices->where('created_at','>',\Carbon\Carbon::now()->subMonths(12))->where('due','<=',0))->count())
<table class="table table-bordered w-100" id="invoices_past_{{ $o->id }}">
<thead>
<tr>
<th>Account</th>
<th>#</th>
<th>Issued</th>
<th>Due</th>
<th>Paid</th>
<th class="text-right">Total</th>
</tr>
@@ -24,7 +24,6 @@
<td>{{ $oo->account->name }}</td>
<td><a href="{{ url('u/invoice',$oo->id) }}">{{ $oo->sid }}</a></td>
<td>{{ $oo->created_at->format('Y-m-d') }}</td>
<td>{{ $oo->due_at->format('Y-m-d') }}</td>
<td>{{ $oo->paid_date ? $oo->paid_date->format('Y-m-d') : '' }}</td>
<td class="text-right">${{ number_format($oo->total,2) }}</td>
</tr>
@@ -43,23 +42,21 @@
@js(datatables,bootstrap4|rowgroup)
<script type="text/javascript">
$(document).ready(function() {
$('#invoices_past').DataTable({
order: [[3,'desc'],[0,'asc']],
rowGroup: {
dataSrc: 0,
},
columnDefs: [
{
targets: [0],
visible: false,
}
],
@if ($x->count())
$(document).ready(function() {
$('#invoices_past_{{ $o->id }}').DataTable({
order: [[2,'desc'],[0,'asc']],
rowGroup: {
dataSrc: 0,
},
columnDefs: [
{
targets: [0],
visible: false,
}
],
});
});
$('#invoices_past tbody').on('click','tr', function () {
$(this).toggleClass('selected');
});
});
@endif
</script>
@append

View File

@@ -1,3 +1,4 @@
<!-- @todo These needs to be optimised, and change for $o = Account::class -->
<!-- Show next items for an invoice -->
@if ($o->next_invoice_items($future)->count())
<div class="card">

View File

@@ -1,11 +1,12 @@
<!-- $o = Account::class -->
<!-- Show past 12 months payments -->
<div class="card card-dark">
<div class="card card-success">
<div class="card-header">
<h3 class="card-title">Past Payments</h3>
</div>
<div class="card-body">
@if(($x=$o->payments()->active()->where('payments.created_at','>',\Carbon\Carbon::now()->subMonths(12)->unix())->with(['items','account'])->get())->count())
@if(($x=$o->payments->where('created_at','>',\Carbon\Carbon::now()->subMonths(12)))->count())
<table class="table table-bordered w-100" id="payments_past">
<thead>
<tr>
@@ -22,7 +23,7 @@
@foreach ($x as $oo)
<tr>
<td>{{ $oo->account->name }}</td>
<td>{{ $oo->sid }}</td>
<td>{{ $oo->lid }}</td>
<td>{{ $oo->paid_at->format('Y-m-d') }}</td>
<td class="text-right">${{ number_format($oo->total,2) }}</td>
{{--<td class="text-right">${{ number_format($oo->balance,2) }}</td>--}}

View File

@@ -52,11 +52,7 @@
color: #4c110f;
}
</style>
<style>
.strike {
text-decoration: line-through;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
@if(count($o->services))

View File

@@ -1,4 +1,4 @@
<!-- $o = User::class -->
<!-- $o = Account::class -->
<!-- Show active services -->
<div class="card card-light">
<div class="card-header">
@@ -6,8 +6,8 @@
</div>
<div class="card-body">
@if ($o->services->count())
<table class="table table-striped table-hover w-100" id="services_active">
@if (($x=$o->services->where('active',TRUE))->count())
<table class="table table-striped table-hover w-100" id="services_active_{{ $ao->id }}">
<thead>
<tr>
<th>ID</th>
@@ -19,19 +19,19 @@
</thead>
<tbody>
@foreach ($o->services as $oo)
@foreach ($x as $so)
<tr>
<td><a href="{{ url('u/service',[$oo->id]) }}">{{ $oo->sid }}</a></td>
<td>{{ $oo->product->category_name }}</td>
<td>{{ $oo->name_short }}</td>
<td>{{ $oo->product->name }}</td>
<td>{{ $oo->external_billing ? '-' : $oo->invoice_next->format('Y-m-d') }}</td>
<td><a href="{{ url('u/service',[$so->id]) }}">{{ $so->sid }}</a></td>
<td>{{ $so->product->category_name }}</td>
<td>{{ $so->name_short }}</td>
<td>{{ $so->product->name }}</td>
<td>{{ $so->external_billing ? '-' : $so->invoice_next->format('Y-m-d') }}</td>
</tr>
@endforeach
</tbody>
<tfoot>
<tr>
<th>Count {{ $o->services->count() }}</th>
<th>Count {{ $x->count() }}</th>
<th colspan="4">&nbsp;</th>
</tr>
</tfoot>
@@ -47,19 +47,9 @@
@css(datatables,bootstrap4|rowgroup)
@js(datatables,bootstrap4|rowgroup)
<style>
table.dataTable tr.dtrg-group.dtrg-end.dtrg-level-0 {
font-size: 75%;
background-color: #eeeeee !important;
}
table.dataTable tr.dtrg-group.dtrg-end.dtrg-level-0 td {
background-color: #fefefe !important;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
$('#services_active').DataTable({
$('#services_active_{{ $ao->id }}').DataTable({
order: [[1,'asc'],[2,'asc']],
rowGroup: {
dataSrc: 1,
@@ -75,7 +65,7 @@
],
});
$('#services_active tbody').on('click','tr', function () {
$('#services_active_{{ $ao->id }} tbody').on('click','tr', function () {
$(this).toggleClass('selected');
});
});