From d8e9e8db4a3431db88092cb317220815a961ac96 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Thu, 20 Feb 2025 10:47:27 +0800 Subject: [PATCH 1/3] fix invoice service charges --- resources/views/pages/pdfs/purchase_order_table.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/pages/pdfs/purchase_order_table.blade.php b/resources/views/pages/pdfs/purchase_order_table.blade.php index e96e6116..62f2f2d1 100644 --- a/resources/views/pages/pdfs/purchase_order_table.blade.php +++ b/resources/views/pages/pdfs/purchase_order_table.blade.php @@ -57,7 +57,7 @@ $serviceCharge = $transaction->service_charge; if (isset($current_paid_amount)) { $refundedServiceCharge = $subtotal + $serviceCharge - $current_paid_amount; - $serviceCharge = $serviceCharge - $refundedServiceCharge + $voucherDiscount; + $serviceCharge = $serviceCharge - $refundedServiceCharge - $voucherDiscount; } ?> {{ number_format($serviceCharge, 2) }} From 5a8c486a98be4e98c6eb8094a2535f5f3d30c7c6 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Thu, 20 Feb 2025 16:47:35 +0800 Subject: [PATCH 2/3] fix invoice --- .../pages/pdfs/purchase_order_table.blade.php | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/resources/views/pages/pdfs/purchase_order_table.blade.php b/resources/views/pages/pdfs/purchase_order_table.blade.php index 62f2f2d1..14c70333 100644 --- a/resources/views/pages/pdfs/purchase_order_table.blade.php +++ b/resources/views/pages/pdfs/purchase_order_table.blade.php @@ -18,6 +18,26 @@ $currency_id = $transaction->owner->fix_currency_id; @endphp + owner; + $paymentSum = $booking->transactions() + ->where('type', TransactionType::PAYMENT) + ->where('status', ApprovalStatus::COMPLETED) + ->get() + ->sum(function ($transaction) { + return round($transaction->amount, 2); + }); + + $refundedAmount = (App()->make(CalculatesBookingRefundAmount::class))->calculateRefundAmount($booking, $booking->fix_currency_id); + + $totalPayment = $paymentSum - $refundedAmount; + ?> + @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) @php $exactUnitPrice = ($currency_id) === 1 ? $transaction_detail->price : bcdiv($transaction_detail->price, $transaction->currency_rate, 7); @@ -55,10 +75,9 @@ Service Charges service_charge; - if (isset($current_paid_amount)) { - $refundedServiceCharge = $subtotal + $serviceCharge - $current_paid_amount; - $serviceCharge = $serviceCharge - $refundedServiceCharge - $voucherDiscount; - } + $current_paid_amount = $totalPayment; + $refundedServiceCharge = $subtotal + $serviceCharge - $current_paid_amount; + $serviceCharge = $serviceCharge - $refundedServiceCharge - $voucherDiscount; ?> {{ number_format($serviceCharge, 2) }} From 000af925f1f07f9a4f18a05b8b7e0d3ca942f250 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Wed, 26 Feb 2025 12:54:34 +0800 Subject: [PATCH 3/3] fix bug on proforma invoice --- .../pages/pdfs/purchase_order_table.blade.php | 9 ++++++--- routes/web.php | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/resources/views/pages/pdfs/purchase_order_table.blade.php b/resources/views/pages/pdfs/purchase_order_table.blade.php index 14c70333..5f62205f 100644 --- a/resources/views/pages/pdfs/purchase_order_table.blade.php +++ b/resources/views/pages/pdfs/purchase_order_table.blade.php @@ -75,9 +75,12 @@ Service Charges service_charge; - $current_paid_amount = $totalPayment; - $refundedServiceCharge = $subtotal + $serviceCharge - $current_paid_amount; - $serviceCharge = $serviceCharge - $refundedServiceCharge - $voucherDiscount; + + // if has payment, calculate and deduct the refund + if ($totalPayment) { + $refundedServiceCharge = $subtotal + $serviceCharge - $totalPayment; + $serviceCharge = $serviceCharge - $refundedServiceCharge - $voucherDiscount; + } ?> {{ number_format($serviceCharge, 2) }} diff --git a/routes/web.php b/routes/web.php index d8518e07..1014aea6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -169,6 +169,25 @@ Route::get('/transfer/{marking}/latest/{document_type}', function ($marking, $do return view('pages.pdfs.' . $lowercaseDocumentType, ['transaction' => $transaction, 'po_order_transaction' => $purchaseOrder, 'supplier' => $supplier, 'voucher_redemption' => $voucherRedemption]); })->name('booking.details.latest_invoice'); +Route::get('/transfer/{marking}/preview-proforma-invoice', function ($marking) { + $booking= Booking::where('marking', $marking)->first(); + + $transaction = $booking->transactions() + ->where('type', TransactionType::PAYMENT) + ->first(); + + $po_order_transaction = $booking->transactions() + ->where('type', TransactionType::PURCHASE_ORDER) + ->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED]) + ->first(); + + $proforma_transaction = $booking->transactions()->where('type', TransactionType::PROFORMA)->first(); + + $supplier = Company::find($transaction->receiver); + + return view('pages.pdfs.proforma_invoice', ['invoice_transaction' => $proforma_transaction, 'po_order_transaction' => $po_order_transaction, 'supplier' => $supplier]); +}); + Route::get('/transfer/merge/{marking}', function ($marking) { return view('pages.bookings.merge', ['marking' => $marking]); })->name('booking.merge');