diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index f75cbeed..2356033a 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -136,21 +136,25 @@ @endsection @php + if (!extension_loaded('bcmath')) { + throw new Exception('BCMath extension is not loaded.'); + } function calculateSubtotal($po_order_transaction, $currencyRate) { - $subtotal = 0; + $subtotal = "0"; foreach ($po_order_transaction->transactionDetails as $transaction_detail) { - $unitPrice = $transaction_detail->price / $currencyRate; - $itemTotal = $unitPrice * $transaction_detail->quantity; - $subtotal += $itemTotal; + $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 2); + $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 2); + $subtotal = bcadd($subtotal, $itemTotal, 2); } return $subtotal; } function getVoucherDiscount($voucher_redemption) { - return $voucher_redemption ? $voucher_redemption->value * -1 : 0; + return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; } function calculateTotalInvoice($subtotal, $service_charge, $tax, $voucherDiscount) { - return $subtotal + $service_charge + $tax + $voucherDiscount; + return bcadd(bcadd(bcadd($subtotal, $service_charge, 2), $tax, 2), $voucherDiscount, 2); } + @endphp