Removed redundant functions from Invoice, optimised Invoice tables

This commit is contained in:
Deon George
2022-04-22 14:41:18 +10:00
parent a16277d9bb
commit e1a4db700f
22 changed files with 361 additions and 349 deletions

View File

@@ -65,7 +65,7 @@
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
</div>
<input type="date" class="form-control" name="date_start" value="{{ $o->service->date_start ? $o->service->date_start->format('Y-m-d') : '' }}">
<input type="date" class="form-control" name="start_at" value="{{ $o->service->start_at ? $o->service->start_at->format('Y-m-d') : '' }}">
</div>
</div>
</div>

View File

@@ -3,7 +3,7 @@
<thead>
<tr>
<th>&nbsp;</th>
<th>{{ $o->product->type->supplied->supplier_detail->supplier->name }}</th>
<th>{{ ($s=$o->supplied)->supplier_detail->supplier->name }}</th>
<th>Us</th>
<th>&nbsp;</th>
</tr>
@@ -12,7 +12,7 @@
<tbody>
<tr>
<th>Product</th>
<td>#{{ ($s=$o->product->type->supplied)->id }}: {{ $s->name }}</td>
<td>#{{ $s->id }}: {{ $s->name }}</td>
<td>#{{ $o->product->id }}: {{ $o->product->name }}</td>
<td>{{ $s->type }}</td>
</tr>
@@ -20,61 +20,45 @@
<th>Setup</th>
<td>${{ number_format($a=\App\Models\Tax::tax_calc($s->setup_cost,$o->account->taxes),2) }}</td>
<td>${{ number_format($b=\App\Models\Tax::tax_calc($o->product->setup_charge,$o->account->taxes),2) }}</td>
<td>
@if ($a > $b)
<span class="badge bg-danger>">({{ number_format($a ? ($b-$a)/($b ?: 1)*100 : 100,1) }})%</span>
@else
<span class="badge">{{ number_format($a ? ($b-$a)/($b ?: 1)*100 : ($b ? 100: 0),1) }}%</span>
@endif
</td>
<td>{!! markup($a,$b) !!}</td>
</tr>
<tr>
<th>Billed</th>
<td>{{ $s->billing_interval_string }}</td>
<td>{{ $o->product->billing_interval_string }}</td>
<td>{{ $o->billing_interval_string }}</td>
<td>&nbsp;</td>
</tr>
<tr>
<th>Billing Charge</th>
<th>Billing Price</th>
<td>${{ number_format($a=\App\Models\Tax::tax_calc($s->base_cost*\App\Models\Invoice::billing_change($s->billing_interval,$o->product->billing_interval),$o->account->taxes),2) }}</td>
<td>${{ number_format($b=\App\Models\Tax::tax_calc($o->product->getBaseChargeAttribute($o->billing_interval),$o->account->taxes),2) }}</td>
<td>
@if ($a > $b)
<span class="badge bg-danger>">({{ number_format($a ? ($b-$a)/($b ?: 1)*100 : 100,1) }})%</span>
@else
<span class="badge">{{ number_format($a ? ($b-$a)/($b ?: 1)*100 : ($b ? 100: 0),1) }}%</span>
@endif
</td>
<td>${{ number_format($b=$o->billing_charge,2) }}</td>
<td>{!! markup($a,$b) !!}</td>
</tr>
<tr>
<th>Monthly Cost</th>
<th>Monthly Price</th>
<td>${{ number_format($a=\App\Models\Tax::tax_calc($s->base_cost*\App\Models\Invoice::billing_change($s->billing_interval,1),$o->account->taxes),2) }}</td>
<td>${{ number_format($b=\App\Models\Tax::tax_calc($o->product->getBaseChargeAttribute($o->billing_interval)*\App\Models\Invoice::billing_change($o->billing_interval,1),$o->account->taxes),2) }}</td>
<td>
@if ($a > $b)
<span class="badge bg-danger>">({{ number_format($a ? ($b-$a)/($b ?: 1)*100 : 100,1) }})%</span>
@else
<span class="badge">{{ number_format($a ? ($b-$a)/($b ?: 1)*100 : ($b ? 100: 0),1) }}%</span>
@endif
</td>
<td>${{ number_format($b=$o->billing_monthly_price,2) }}</td>
<td>{!! markup($a,$b) !!}</td>
</tr>
<tr>
<th>Contract</th>
<td>{{ $s->contract_term }} months</td>
<td>{{ $o->product->contract_term }} months</td>
<td>{{ $o->contract_term }} months</td>
<td>&nbsp;</td>
</tr>
<tr>
<th>Min Cost</th>
<th>Min Price</th>
<td>${{ number_format($a=\App\Models\Tax::tax_calc($s->min_cost,$o->account->taxes),2) }}</td>
<td>${{ number_format($b=\App\Models\Tax::tax_calc($o->product->getMinChargeAttribute($o->billing_interval),$o->account->taxes),2) }}</td>
<td>
@if ($a > $b)
<span class="badge bg-danger>">({{ number_format($a ? ($b-$a)/($b ?: 1)*100 : 100,1) }})%</span>
@else
<span class="badge">{{ number_format($a ? ($b-$a)/($b ?: 1)*100 : ($b ? 100: 0),1) }}%</span>
@endif
</td>
<td>{!! markup($a,$b) !!}</td>
</tr>
</tbody>
</table>
</table>
@php
function markup($a,$b) {
return ($a > $b)
? sprintf('<span class="badge bg-danger>">(%3.1f%%)</span>',$a ? ($b-$a)/($b ?: 1)*100 : 100)
: sprintf('<span class="badge">%3.1f%%</span>',$a ? ($b-$a)/($b ?: 1)*100 : ($b ? 100: 0));
}
@endphp

View File

@@ -14,8 +14,8 @@
@foreach ($o->invoices as $io)
<tr>
<td class="text-right"><a href="{{ url('u/invoice',$io->id) }}">{{ $io->id }}</a></td>
<td class="text-right">{{ $io->date_orig->format('Y-m-d') }}</td>
<td class="text-right">{{ $io->due_date->format('Y-m-d') }}</td>
<td class="text-right">{{ $io->created_at->format('Y-m-d') }}</td>
<td class="text-right">{{ $io->due_at->format('Y-m-d') }}</td>
<td class="text-right">${{ number_format($io->total,2) }}</td>
<td class="text-right">${{ number_format($io->paid,2) }}</td>
<td class="text-right">${{ number_format($io->due,2) }}</td>

View File

@@ -22,11 +22,11 @@
<tbody>
@foreach ($o->query_invoice_summary()->having('balance','>',0)->get() as $oo)
<tr @if ($oo->due_date->isPast()) class="table-danger" @endif>
<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->date_orig->format('Y-m-d') }}</td>
<td>{{ $oo->due_date->format('Y-m-d') }}</td>
<td>{{ $oo->created_at->format('Y-m-d') }}</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>

View File

@@ -33,7 +33,7 @@
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
</div>
<input type="text" class="form-control" id="datestart" name="date_start" value="{{ ($x=$o->date_start) ? $x->format('Y-m-d') : '' }}">
<input type="text" class="form-control" id="datestart" name="start_at" value="{{ ($x=$o->start_at) ? $x->format('Y-m-d') : '' }}">
</div>
</div>
</div>

View File

@@ -68,7 +68,7 @@
<td class="p-0">Invoice:</td><td class="p-0"><strong>{{ $o->lid }}</strong></td>
</tr>
<tr>
<td class="p-0">Payment Due:</td><td class="p-0"><strong>{{ $o->due_date->format('Y-m-d') }}</strong></td>
<td class="p-0">Payment Due:</td><td class="p-0"><strong>{{ $o->due_at->format('Y-m-d') }}</strong></td>
</tr>
<tr>
<td class="p-0">This Invoice Due:</td><td class="p-0"><strong>${{ number_format($o->total,$o->currency()->rounding) }}</strong></td>
@@ -157,7 +157,7 @@
<table class="table">
<tr>
<th colspan="3" style="width:50%">Subtotal:</th>
<td colspan="2" class="text-right">${{ number_format($o->total_sub,$o->currency()->rounding) }}</td>
<td colspan="2" class="text-right">${{ number_format($o->sub_total,$o->currency()->rounding) }}</td>
</tr>
<tr>
<th>&nbsp;</th>

View File

@@ -21,11 +21,11 @@
<tbody>
@foreach ($x as $oo)
<tr @if ($oo->due_date->isPast()) class="table-danger" @endif>
<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->date_orig->format('Y-m-d') }}</td>
<td>{{ $oo->due_date->format('Y-m-d') }}</td>
<td>{{ $oo->created_at->format('Y-m-d') }}</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>

View File

@@ -5,7 +5,7 @@
</div>
<div class="card-body">
@if(($x=$o->invoices()->where('ab_invoice.date_orig','>',\Carbon\Carbon::now()->subMonths(12)->unix())->with(['items.taxes','paymentitems.payment','account.country.currency'])->get()->where('due','<=',0))->count())
@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">
<thead>
<tr>
@@ -23,8 +23,8 @@
<tr>
<td>{{ $oo->account->name }}</td>
<td><a href="{{ url('u/invoice',$oo->id) }}">{{ $oo->sid }}</a></td>
<td>{{ $oo->date_orig->format('Y-m-d') }}</td>
<td>{{ $oo->due_date->format('Y-m-d') }}</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>
@@ -45,7 +45,7 @@
<script type="text/javascript">
$(document).ready(function() {
$('#invoices_past').DataTable({
order: [[0,'asc'],[3,'desc']],
order: [[3,'desc'],[0,'asc']],
rowGroup: {
dataSrc: 0,
},

View File

@@ -28,16 +28,16 @@
<td>{{ $o->order_info_reference ?? '' }}</td>
</tr>
@endif
@if ($o->date_start AND $o->isPending())
@if ($o->start_at AND $o->isPending())
<tr>
<th>Pending Connection</th>
<td>{{ $o->date_start->format('Y-m-d') }}</td>
<td>{{ $o->start_at->format('Y-m-d') }}</td>
</tr>
@endif
@if ($o->date_end)
@if ($o->stop_at)
<tr>
<th>Cancellation Date</th>
<td>{{ $o->date_end->format('Y-m-d') }}</td>
<td>{{ $o->stop_at->format('Y-m-d') }}</td>
</tr>
@endif
@if (($o->active OR $o->isPending()) AND ! $o->external_billing)
@@ -74,7 +74,7 @@
<tr>
<th>Cancelled</th>
<!-- @todo This should show the cancelled date -->
<td>{!! $o->date_end ? $o->date_end->format('Y-m-d') : ($o->paid_to ? $o->paid_to->format('Y-m-d') : '').'<sup>*</sup>' !!}</td>
<td>{!! $o->stop_at ? $o->stop_at->format('Y-m-d') : ($o->paid_to ? $o->paid_to->format('Y-m-d') : '').'<sup>*</sup>' !!}</td>
</tr>
@endif
</table>