From 4b476d0bf767e8e94352be5002914459f10f5f47 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Wed, 16 Aug 2023 16:29:33 +0800 Subject: [PATCH] regenerate invoices for 2023 --- .../CreateInvoiceDocumentProcessor.php | 2 +- .../views/pages/pdfs/purchase_order.blade.php | 32 ++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/app/Classes/Modules/Transactions/Processors/CreateInvoiceDocumentProcessor.php b/app/Classes/Modules/Transactions/Processors/CreateInvoiceDocumentProcessor.php index 2bbf5b88..6215a1e1 100644 --- a/app/Classes/Modules/Transactions/Processors/CreateInvoiceDocumentProcessor.php +++ b/app/Classes/Modules/Transactions/Processors/CreateInvoiceDocumentProcessor.php @@ -1,7 +1,7 @@ @php - $subtotal = InvoiceDocumentsHelper::calculateSubtotal($po_order_transaction, $transaction->currency_rate); - $voucherDiscount = InvoiceDocumentsHelper::getVoucherDiscount($voucher_redemption); + $subtotal = calculatePoSubtotal($po_order_transaction, $transaction->currency_rate); + $voucherDiscount = getPoVoucherDiscount($voucher_redemption); $displayedSubtotal = 0; @endphp @@ -118,7 +118,7 @@ @php - $voucherDiscount = InvoiceDocumentsHelper::getVoucherDiscount($voucher_redemption); + $voucherDiscount = getPoVoucherDiscount($voucher_redemption); $subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract @endphp @@ -156,7 +156,7 @@ Adjustment - {{ InvoiceDocumentsHelper::roundUp($discrepancy,2) }} + {{ roundUpPo($discrepancy,2) }} @@ -175,4 +175,28 @@ + @php + function calculatePoSubtotal($po_order_transaction, $currencyRate) { + $subtotal = "0"; + foreach ($po_order_transaction->transactionDetails as $transaction_detail) { + $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); + $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5); + $subtotal = bcadd($subtotal, $itemTotal, 5); + } + return $subtotal; + } + + function getPoVoucherDiscount($voucher_redemption) { + return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; + } + function roundUpPo($number, $decimals) { + $factor = pow(10, $decimals); + if ($number > 0) { + return ceil($number * $factor) / $factor; + } else { + return floor($number * $factor) / $factor; + } + } + + @endphp @endsection