From 38749c11b6cf5b15db27aeca4986a89660fc11a0 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Wed, 16 Aug 2023 16:59:28 +0800 Subject: [PATCH] regenerate invoices for 2023 --- .../Helpers/InvoiceDocumentsHelper.php | 29 ------- resources/views/layouts/base_pdf.blade.php | 3 - .../views/pages/pdfs/deliver_order.blade.php | 34 ++------- resources/views/pages/pdfs/invoice.blade.php | 35 ++------- .../views/pages/pdfs/purchase_order.blade.php | 76 ++++++------------- routes/web.php | 9 ++- 6 files changed, 41 insertions(+), 145 deletions(-) delete mode 100644 app/Classes/Helpers/InvoiceDocumentsHelper.php diff --git a/app/Classes/Helpers/InvoiceDocumentsHelper.php b/app/Classes/Helpers/InvoiceDocumentsHelper.php deleted file mode 100644 index 8b7ba8c4..00000000 --- a/app/Classes/Helpers/InvoiceDocumentsHelper.php +++ /dev/null @@ -1,29 +0,0 @@ -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; - } - - public static function getVoucherDiscount($voucher_redemption) { - return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; - } - - public static function roundUp($number, $decimals) { - $factor = pow(10, $decimals); - if ($number > 0) { - return ceil($number * $factor) / $factor; - } else { - return floor($number * $factor) / $factor; - } - } -} diff --git a/resources/views/layouts/base_pdf.blade.php b/resources/views/layouts/base_pdf.blade.php index f7f40d99..e88d541d 100644 --- a/resources/views/layouts/base_pdf.blade.php +++ b/resources/views/layouts/base_pdf.blade.php @@ -1,6 +1,3 @@ -@php - use App\Classes\Helpers\InvoiceDocumentsHelper; -@endphp diff --git a/resources/views/pages/pdfs/deliver_order.blade.php b/resources/views/pages/pdfs/deliver_order.blade.php index c59cc5a9..1cda9e1c 100644 --- a/resources/views/pages/pdfs/deliver_order.blade.php +++ b/resources/views/pages/pdfs/deliver_order.blade.php @@ -33,7 +33,8 @@
EDO: {{ $transaction->bill_no }}
REF: {{ $transaction->booking->marking }}
-
Date: {{ $supplier->segments->whereIn('id', [23])->first() ? \Carbon\Carbon::now() : $po_order_transaction->created_at }}
+
Date: {{ + $supplier->segments->whereIn('id', [23])->first() ? \Carbon\Carbon::now() : $po_order_transaction->created_at }}
 
@@ -82,8 +83,8 @@ @php - $subtotal = calculateDoSubtotal($po_order_transaction, $transaction->currency_rate); - $voucherDiscount = getDoVoucherDiscount($voucher_redemption); + $subtotal = "0"; + $voucherDiscount = $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; $displayedSubtotal = 0; @endphp @@ -110,7 +111,6 @@ @php - $voucherDiscount = getDoVoucherDiscount($voucher_redemption); $subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract @endphp @@ -148,7 +148,7 @@ Adjustment - {{ roundUpDo($discrepancy,2) }} + {{ ceil($discrepancy * 100) / 100 }} @@ -167,28 +167,4 @@ - @php - function calculateDoSubtotal($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 getDoVoucherDiscount($voucher_redemption) { - return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; - } - function roundUpDo($number, $decimals) { - $factor = pow(10, $decimals); - if ($number > 0) { - return ceil($number * $factor) / $factor; - } else { - return floor($number * $factor) / $factor; - } - } - - @endphp @endsection diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 066fb971..19d03d4a 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -72,8 +72,8 @@ @php - $subtotal = calculateSubtotal($po_order_transaction, $transaction->currency_rate); - $voucherDiscount = getVoucherDiscount($voucher_redemption); + $subtotal = "0"; + $voucherDiscount = $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; $displayedSubtotal = 0; @endphp @@ -100,8 +100,7 @@ @php - $voucherDiscount = getVoucherDiscount($voucher_redemption); - $subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract + $subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); @endphp @@ -133,12 +132,12 @@ $displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2); $expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); $discrepancy = bcsub($displayedTotal, $expectedTotal, 5); - $total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision + $total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); @endphp Adjustment - {{ roundUp($discrepancy,2) }} + {{ roundUp($discrepancy, 2) }} @@ -160,28 +159,4 @@ Account Name: CIEF Worldwide Sdn Bhd
Account No: 564892103405
- @php - function calculateSubtotal($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 getVoucherDiscount($voucher_redemption) { - return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; - } - function roundUp($number, $decimals) { - $factor = pow(10, $decimals); - if ($number > 0) { - return ceil($number * $factor) / $factor; - } else { - return floor($number * $factor) / $factor; - } - } - - @endphp @endsection diff --git a/resources/views/pages/pdfs/purchase_order.blade.php b/resources/views/pages/pdfs/purchase_order.blade.php index e9d1c8fd..99eb09b0 100644 --- a/resources/views/pages/pdfs/purchase_order.blade.php +++ b/resources/views/pages/pdfs/purchase_order.blade.php @@ -24,9 +24,9 @@ @php - $subtotal = calculatePoSubtotal($po_order_transaction, $transaction->currency_rate); - $voucherDiscount = getPoVoucherDiscount($voucher_redemption); + $subtotal = "0"; $displayedSubtotal = 0; @endphp @@ -118,8 +117,12 @@ @php - $voucherDiscount = getPoVoucherDiscount($voucher_redemption); + $voucherDiscount = $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; $subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract + $displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2); + $expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); + $discrepancy = bcsub($displayedTotal, $expectedTotal, 5); + $total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision @endphp @@ -147,12 +150,7 @@ @endif - @php - $displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2); - $expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); - $discrepancy = bcsub($displayedTotal, $expectedTotal, 5); - $total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision - @endphp + @@ -175,28 +173,4 @@
- - Buyer - + + Buyer +
@@ -34,34 +34,34 @@
- {{ $supplier->name }} - + {{ $supplier->name }} + - {{-- {{ $supplier }} --}} - + {{-- {{ $supplier }} --}} +
- @php - $billingAddress = $supplier->addresses()->where('billing', '=', true)->first(); - @endphp + @php + $billingAddress = $supplier->addresses()->where('billing', '=', true)->first(); + @endphp {{ $billingAddress->street_one }} {{ $billingAddress->street_two }} {{ $billingAddress->state()->first()->name }} {{ $billingAddress->district()->first()->name }} - +
- Phone: {{ $supplier->contacts()->first()->phone }} - + Phone: {{ $supplier->contacts()->first()->phone }} +
- - Seller - + + Seller +
- CIEF Worldwide Sdn Bhd (1134596-M) - + CIEF Worldwide Sdn Bhd (1134596-M) +
No. 72-3, Jalan Jalil 1,
The Earth Bukit Jalil,
@@ -90,8 +90,7 @@
{{ number_format($transaction->tax, 2) }}
Adjustment
- @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 diff --git a/routes/web.php b/routes/web.php index 961af5b2..324c03a9 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,5 @@ whereDate('updated_at', '>=', Carbon::parse('01-01-2023'))->get(); foreach($bookings as $booking){ - GenerateInvoice::dispatch($booking); - echo 'Invoice fixing job dispatched.'; + $booking->transactions()->whereIn('transactions.type', [TransactionType::INVOICE, TransactionType::SUPPLIER_DELIVER])->delete(); + $booking->documents()->whereIn('document_type', [DocumentType::INVOICE, DocumentType::PURCHASE_ORDER, DocumentType::DELIVER_ORDER, DocumentType::SUPPLIER_DELIVER_ORDER])->delete(); + $booking->status = ApprovalStatus::APPROVED; + $booking->save(); + + (App()->make(CreateInvoiceTransactionProcessor::class))->execute($booking); } })->name('invoice.fix');