From 4b32a48e07057aae29b8cdbbbbbd4ce3e7844fde Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Tue, 1 Nov 2022 15:30:53 +0800 Subject: [PATCH] shipping sales report --- routes/web.php | 53 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/routes/web.php b/routes/web.php index faf2ef06..64bcac8f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -428,9 +428,9 @@ Route::get('/export/payment-transactions/f614e339d7058904a831aad742e24d55', 'Exp Route::get('/delayed_container/customers', function(){ $containers = Container::whereHas('transports', function($query){ - return $query->whereHas('Schedules', function($query){ - return $query->where('etd', '>', \Carbon\Carbon::parse('15-10-2022')); - }); + return $query->whereHas('Schedules', function($query){ + return $query->where('etd', '>', \Carbon\Carbon::parse('15-10-2022')); + }); })->get(); $orders = $containers->map(function($container){ @@ -448,3 +448,50 @@ Route::get('/delayed_container/customers', function(){ }); + + +Route::get('/container/billing/{month}/{year}', function($month, $year){ + $containers = Container::whereDate('loading_date', '>=', Carbon::parse('01-'.$month.'-'.$year))->get(); + + $totalBillable = 0; + $billed = 0; + $totalBilled = 0; + $totalPaid = 0; + + foreach($containers as $container) { + $packingLists = $container->packingLists; + $totalBillable += count($packingLists); + echo '

'.$container->reference.'

'; + + foreach ($packingLists as $packingList) { + $invoice = $packingList->transactions() + ->where('type', \App\Classes\ValueObjects\Constants\TransactionType::SHIPPING_INVOICE)->whereIn('status', [\App\Classes\ValueObjects\Constants\ApprovalStatus::APPROVED, \App\Classes\ValueObjects\Constants\ApprovalStatus::COMPLETED]) + ->first(); + + if(!$invoice) { + echo '

'.$packingList->reference .' Warning: no billing

'; + continue; + } + + $payments = $invoice->transactions() + ->where('type', \App\Classes\ValueObjects\Constants\TransactionType::PAYMENT)->whereIn('status', [\App\Classes\ValueObjects\Constants\ApprovalStatus::APPROVED, \App\Classes\ValueObjects\Constants\ApprovalStatus::COMPLETED]) + ->get(); + + $billed += 1; + $totalBilled += $invoice->amount; + $totalPaid += $payments->sum('amount'); + + echo $packingList->reference.' | Amount: '.$invoice->amount.' | Paid: '.$payments->sum('amount'); + + } + + echo '


'; + } + + echo '

Total Invoices: '.$billed.'/'.$totalBillable.'

'; + echo '

Billed Total: '.$totalBilled.'

'; + echo '

Total Paid: '.$totalPaid.'

'; + echo '

Outstanding: '.($totalBilled - $totalPaid).'

'; + + +});