Changed home screen to use account models instead of user model. Home screen now shows multiple accounts
This commit is contained in:
parent
790ece14d1
commit
dde11f73f5
@ -31,8 +31,6 @@ class HomeController extends Controller
|
||||
if (! $o->exists)
|
||||
$o = Auth::user();
|
||||
|
||||
$o->load(['services.invoice_items','services.type']);
|
||||
|
||||
return View('home',['o'=>$o]);
|
||||
}
|
||||
|
||||
|
@ -64,9 +64,15 @@ class Account extends Model implements IDs
|
||||
return $this->hasOneThrough(Group::class,AccountGroup::class,'account_id','id','id','group_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @todo This needs to be optimised, to only return outstanding invoices and invoices for a specific age (eg: 2 years worth)
|
||||
*/
|
||||
public function invoices()
|
||||
{
|
||||
return $this->hasMany(Invoice::class);
|
||||
return $this->hasMany(Invoice::class)
|
||||
->active()
|
||||
->with(['items.taxes','paymentitems.payment']);
|
||||
}
|
||||
|
||||
public function language()
|
||||
@ -76,7 +82,9 @@ class Account extends Model implements IDs
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany(Payment::class);
|
||||
return $this->hasMany(Payment::class)
|
||||
->active()
|
||||
->with(['items']);
|
||||
}
|
||||
|
||||
public function providers()
|
||||
@ -89,7 +97,8 @@ class Account extends Model implements IDs
|
||||
public function services($active=FALSE)
|
||||
{
|
||||
$query = $this->hasMany(Service::class,['account_id','site_id'],['id','site_id'])
|
||||
->withoutGlobalScope(SiteScope::class);
|
||||
->withoutGlobalScope(SiteScope::class)
|
||||
->with(['product.translate','invoice_items']);
|
||||
|
||||
return $active ? $query->active() : $query;
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ class Service extends Model implements IDs
|
||||
protected $with = [
|
||||
//'invoice_items',
|
||||
//'product.type.supplied',
|
||||
//'type',
|
||||
'type',
|
||||
];
|
||||
|
||||
public const INACTIVE_STATUS = [
|
||||
|
@ -105,14 +105,14 @@ class User extends Authenticatable implements IDs
|
||||
{
|
||||
return $this->hasMany(Account::class)
|
||||
->orWhereIn('id',$this->rtm_accounts()->pluck('id'))
|
||||
->active()
|
||||
->with(['services']);
|
||||
->active();
|
||||
}
|
||||
|
||||
/**
|
||||
* This users invoices
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
||||
* @deprecated Accounts have invoices, not users
|
||||
*/
|
||||
public function invoices()
|
||||
{
|
||||
@ -130,16 +130,6 @@ class User extends Authenticatable implements IDs
|
||||
return $this->belongsTo(Language::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* The payments this user has made
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
||||
*/
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasManyThrough(Payment::class,Account::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the routes to market account for this user
|
||||
*
|
||||
@ -151,9 +141,10 @@ class User extends Authenticatable implements IDs
|
||||
}
|
||||
|
||||
/**
|
||||
* THe services this user has
|
||||
* The services this user has
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
||||
* @deprecated Accounts have services, not users
|
||||
*/
|
||||
public function services()
|
||||
{
|
||||
@ -162,6 +153,12 @@ class User extends Authenticatable implements IDs
|
||||
->active();
|
||||
}
|
||||
|
||||
/**
|
||||
* Supplier configuration for this user
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
* @deprecated Move to account->suppliers()
|
||||
*/
|
||||
public function suppliers()
|
||||
{
|
||||
return $this->belongsToMany(Supplier::class)
|
||||
@ -178,7 +175,7 @@ class User extends Authenticatable implements IDs
|
||||
*/
|
||||
public function getNameAttribute(): string
|
||||
{
|
||||
return $this->getFullNameAttribute();
|
||||
return $this->full_name;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -192,13 +189,20 @@ class User extends Authenticatable implements IDs
|
||||
}
|
||||
|
||||
/**
|
||||
* Return my accounts
|
||||
* Return my accounts, but only those accounts with the same group_id
|
||||
*
|
||||
* @note Users can only manage accounts with the same group ID, thereby ensuring they dont see different
|
||||
* pricing options - since prices can be controlled by groups
|
||||
* @return Collection
|
||||
*/
|
||||
public function getMyAccountsAttribute(): Collection
|
||||
{
|
||||
return $this->accounts->where('user_id',$this->id);
|
||||
$result = $this->accounts->where('user_id',$this->id);
|
||||
|
||||
if (! $result->count())
|
||||
return $result;
|
||||
|
||||
return $this->isReseller() ? $result : $result->groupBy('group.id')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,6 +20,30 @@
|
||||
@include('common.account.widget.summary')
|
||||
</div>
|
||||
|
||||
<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')
|
||||
@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">
|
||||
<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">
|
||||
<div class="card-header bg-white">
|
||||
@ -30,13 +54,9 @@
|
||||
<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>
|
||||
|
||||
@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
|
||||
<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>
|
||||
|
||||
@ -45,15 +65,15 @@
|
||||
<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')
|
||||
@include('service.widget.active',['o'=>$ao])
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-xl-5">
|
||||
@include('u.invoice.widgets.due')
|
||||
@include('invoice.widget.due',['o'=>$ao])
|
||||
|
||||
@include('u.invoice.widgets.list')
|
||||
@include('invoice.widget.list',['o'=>$ao])
|
||||
|
||||
@include('u.payment.widgets.list')
|
||||
@include('payment.widget.list',['o'=>$ao])
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -72,20 +92,13 @@
|
||||
<div class="tab-pane" id="tab-futureinvoice">
|
||||
<div class="row">
|
||||
<div class="col-12 col-xl-9">
|
||||
@include('u.invoice.widgets.next',['future'=>TRUE])
|
||||
@include('invoice.widget.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
|
||||
@canany('reseller','wholesaler')
|
||||
<div class="tab-pane {{ session()->pull('supplier_update') ? 'active' : '' }}" id="tab-supplier">
|
||||
<div class="tab-pane {{ session()->pull('supplier_update') ? 'active' : '' }}" id="tab-supplier" role="tabpanel">
|
||||
@include('user.widget.supplier')
|
||||
</div>
|
||||
@endcanany
|
||||
@ -93,6 +106,19 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
|
||||
@if ($o == $user)
|
||||
@canany('reseller','wholesaler')
|
||||
<div class="tab-pane" id="tab-reseller" role="tabpanel">
|
||||
@include('r.home.widgets.home')
|
||||
</div>
|
||||
@endcanany
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('page-scripts')
|
||||
|
@ -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,8 +42,9 @@
|
||||
@js(datatables,bootstrap4|rowgroup)
|
||||
|
||||
<script type="text/javascript">
|
||||
@if ($x->count())
|
||||
$(document).ready(function() {
|
||||
$('#invoices_due').DataTable({
|
||||
$('#invoices_due_{{ $o->id }}').DataTable({
|
||||
order: [[0,'asc'],[3,'desc']],
|
||||
rowGroup: {
|
||||
dataSrc: 0,
|
||||
@ -58,10 +56,7 @@
|
||||
}
|
||||
],
|
||||
});
|
||||
|
||||
$('#invoices_due tbody').on('click','tr', function () {
|
||||
$(this).toggleClass('selected');
|
||||
});
|
||||
});
|
||||
@endif
|
||||
</script>
|
||||
@append
|
@ -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,9 +42,10 @@
|
||||
@js(datatables,bootstrap4|rowgroup)
|
||||
|
||||
<script type="text/javascript">
|
||||
@if ($x->count())
|
||||
$(document).ready(function() {
|
||||
$('#invoices_past').DataTable({
|
||||
order: [[3,'desc'],[0,'asc']],
|
||||
$('#invoices_past_{{ $o->id }}').DataTable({
|
||||
order: [[2,'desc'],[0,'asc']],
|
||||
rowGroup: {
|
||||
dataSrc: 0,
|
||||
},
|
||||
@ -56,10 +56,7 @@
|
||||
}
|
||||
],
|
||||
});
|
||||
|
||||
$('#invoices_past tbody').on('click','tr', function () {
|
||||
$(this).toggleClass('selected');
|
||||
});
|
||||
});
|
||||
@endif
|
||||
</script>
|
||||
@append
|
@ -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">
|
@ -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>--}}
|
@ -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))
|
||||
|
@ -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"> </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');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user