From 276a95f920d2c4445a78e7096d6740ba8cb46baf Mon Sep 17 00:00:00 2001 From: Jia Sheng Lee Date: Wed, 4 Oct 2023 12:56:28 +0800 Subject: [PATCH] reuse table blade --- .../views/pages/pdfs/deliver_order.blade.php | 103 +----------------- resources/views/pages/pdfs/invoice.blade.php | 92 +--------------- .../views/pages/pdfs/purchase_order.blade.php | 103 +----------------- .../pages/pdfs/purchase_order_table.blade.php | 92 ++++++++++++++++ 4 files changed, 95 insertions(+), 295 deletions(-) create mode 100644 resources/views/pages/pdfs/purchase_order_table.blade.php diff --git a/resources/views/pages/pdfs/deliver_order.blade.php b/resources/views/pages/pdfs/deliver_order.blade.php index e957c0f0..d16a68f5 100644 --- a/resources/views/pages/pdfs/deliver_order.blade.php +++ b/resources/views/pages/pdfs/deliver_order.blade.php @@ -69,109 +69,8 @@

- - - - - - - - - - - - - - @php - $subtotal = "0"; - $voucherDiscount = $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 5) : "0"; - $displayedSubtotal = "0"; - $exactTotal = "0"; - @endphp + @include('pages.pdfs.purchase_order_table') - @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) - @php - $exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5); - $itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5); - - // Round half to even for displayed item total - $displayedItemTotal = round(bcmul($exactUnitPrice, $transaction_detail->quantity, 2), 2, PHP_ROUND_HALF_EVEN); - - $displayedSubtotal = bcadd($displayedSubtotal, $displayedItemTotal, 2); - $subtotal = bcadd($subtotal, $itemTotal, 5); - $exactTotal = bcadd($exactTotal, $displayedItemTotal, 5); - @endphp - - - - - - - - - @endforeach - - - @php - $subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); - @endphp - - - - - - - - - - - - @if($voucher_redemption) - - - - - - @endif - - @if($transaction->tax > 0) - - - - - - @endif - @php - // Calculate the totals with 5 decimal places - $expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); - - // Calculate the displayed totals with 2 decimal places - $displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2); - - // Calculate the discrepancy - $discrepancy = bcsub($expectedTotal, $displayedTotal, 5); - - // Calculate the final total - $total = bcadd($expectedTotal, $discrepancy, 5); - @endphp - - - - - - - - - - - -
NoStock CodeDescriptionQuantityUnit Price (RM)Total Amount
(RM)
{{ $key + 1 }}{{ $transaction_detail->product_code }}{{ $transaction_detail->product_name }}{{ $transaction_detail->quantity }} - {{ number_format($exactUnitPrice, 2) }} - - {{ number_format($itemTotal, 2) }} -
Subtotal{{ number_format($subtotal, 2) }}
Service Charges{{ number_format($transaction->service_charge, 2) }}
Voucher ({{ $voucher_redemption->voucher->code }})-{{ number_format($voucherDiscount, 2) }}
Tax{{ number_format($transaction->tax, 2) }}
Adjustment{{number_format($discrepancy, 5)}}
Total - {{ number_format($total, 2) }} -
diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 9a862fe2..810df954 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -58,98 +58,8 @@
-
- - - - - - - - - - - - - @php - $subtotal = "0"; - $voucherDiscount = $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; - $displayedSubtotal = 0; - @endphp + @include('pages.pdfs.purchase_order_table') - @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) - @php - $exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 7); - $displayUnitPrice = round($exactUnitPrice, 2); - $itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5); - $displayedItemTotal = round(bcmul($displayUnitPrice, $transaction_detail->quantity, 7), 2); - $displayedSubtotal = bcadd($displayedSubtotal, $displayedItemTotal, 2); - $subtotal = bcadd($subtotal, $itemTotal, 5); - @endphp - - - - - - - - - @endforeach - - - @php - $subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); - @endphp - - - - - - - - - - - - @if($voucher_redemption) - - - - - - @endif - - @if($transaction->tax > 0) - - - - - - @endif - @php - $displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); - $expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); - $discrepancy = bcsub($expectedTotal, $displayedTotal, 5); - $total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); - @endphp - - - - - - - - - - - -
NoStock CodeDescriptionQuantityUnit Price (RM)Total Amount
(RM)
{{ $key + 1 }}{{ $transaction_detail->product_code }}{{ $transaction_detail->product_name }}{{ $transaction_detail->quantity }} - {{ $displayUnitPrice }} - - {{ $displayedItemTotal }} -
Subtotal{{ number_format($displayedSubtotal, 2) }}
Service Charges{{ number_format($transaction->service_charge, 2) }}
Voucher ({{ $voucher_redemption->voucher->code }})-{{ number_format($voucherDiscount, 2) }}
Tax{{ number_format($transaction->tax, 2) }}
Adjustment{{number_format($discrepancy, 5)}}
Total - {{ number_format($total, 2) }} -

Note: All items purchased are subject to our Terms & Conditions. Please refer to our official website for more information. diff --git a/resources/views/pages/pdfs/purchase_order.blade.php b/resources/views/pages/pdfs/purchase_order.blade.php index 3e79691a..1f6d72d9 100644 --- a/resources/views/pages/pdfs/purchase_order.blade.php +++ b/resources/views/pages/pdfs/purchase_order.blade.php @@ -76,109 +76,8 @@
- - - - - - - - - - - - - - @php - $subtotal = "0"; - $voucherDiscount = $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 5) : "0"; - $displayedSubtotal = "0"; - $exactTotal = "0"; - @endphp + @include('pages.pdfs.purchase_order_table') - @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) - @php - $exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5); - $itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5); - - // Round half to even for displayed item total - $displayedItemTotal = round(bcmul($exactUnitPrice, $transaction_detail->quantity, 2), 2, PHP_ROUND_HALF_EVEN); - - $displayedSubtotal = bcadd($displayedSubtotal, $displayedItemTotal, 2); - $subtotal = bcadd($subtotal, $itemTotal, 5); - $exactTotal = bcadd($exactTotal, $displayedItemTotal, 5); - @endphp - - - - - - - - - @endforeach - - - @php - $subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); - @endphp - - - - - - - - - - - - @if($voucher_redemption) - - - - - - @endif - - @if($transaction->tax > 0) - - - - - - @endif - @php - // Calculate the totals with 5 decimal places - $expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); - - // Calculate the displayed totals with 2 decimal places - $displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2); - - // Calculate the discrepancy - $discrepancy = bcsub($expectedTotal, $displayedTotal, 5); - - // Calculate the final total - $total = bcadd($expectedTotal, $discrepancy, 5); - @endphp - - - - - - - - - - - -
NoStock CodeDescriptionQuantityUnit Price (RM)Total Amount
(RM)
{{ $key + 1 }}{{ $transaction_detail->product_code }}{{ $transaction_detail->product_name }}{{ $transaction_detail->quantity }} - {{ number_format($exactUnitPrice, 2) }} - - {{ number_format($itemTotal, 2) }} -
Subtotal{{ number_format($subtotal, 2) }}
Service Charges{{ number_format($transaction->service_charge, 2) }}
Voucher ({{ $voucher_redemption->voucher->code }})-{{ number_format($voucherDiscount, 2) }}
Tax{{ number_format($transaction->tax, 2) }}
Adjustment{{number_format($discrepancy, 5)}}
Total - {{ number_format($total, 2) }} -
diff --git a/resources/views/pages/pdfs/purchase_order_table.blade.php b/resources/views/pages/pdfs/purchase_order_table.blade.php new file mode 100644 index 00000000..20fac9b8 --- /dev/null +++ b/resources/views/pages/pdfs/purchase_order_table.blade.php @@ -0,0 +1,92 @@ +
+ + + + + + + + + + + + + @php + $subtotal = "0"; + $voucherDiscount = $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; + $displayedSubtotal = 0; + @endphp + + @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) + @php + $exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 7); + $displayUnitPrice = round($exactUnitPrice, 2); + $itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5); + $displayedItemTotal = round(bcmul($displayUnitPrice, $transaction_detail->quantity, 7), 2); + $displayedSubtotal = bcadd($displayedSubtotal, $displayedItemTotal, 2); + $subtotal = bcadd($subtotal, $itemTotal, 5); + @endphp + + + + + + + + + @endforeach + + + @php + $subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); + @endphp + + + + + + + + + + + + @if($voucher_redemption) + + + + + + @endif + + @if($transaction->tax > 0) + + + + + + @endif + @php + $displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); + $expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); + $discrepancy = bcsub($expectedTotal, $displayedTotal, 5); + $total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); + @endphp + + + + + + + + + + + +
NoStock CodeDescriptionQuantityUnit Price (RM)Total Amount
(RM)
{{ $key + 1 }}{{ $transaction_detail->product_code }}{{ $transaction_detail->product_name }}{{ $transaction_detail->quantity }} + {{ number_format($displayUnitPrice, 2) }} + + {{ number_format($displayedItemTotal, 2) }} +
Subtotal{{ number_format($displayedSubtotal, 2) }}
Service Charges{{ number_format($transaction->service_charge, 2) }}
Voucher ({{ $voucher_redemption->voucher->code }})-{{ number_format($voucherDiscount, 2) }}
Tax{{ number_format($transaction->tax, 2) }}
Adjustment{{number_format($discrepancy, 5)}}
Total + {{ number_format($total, 2) }} +
\ No newline at end of file