From a79ce7e2b75a6852966ca809925d0256ba2c3e29 Mon Sep 17 00:00:00 2001 From: JiaSheng Date: Tue, 15 Aug 2023 22:56:42 +0800 Subject: [PATCH 01/18] transaction not tally --- .../FetchCompanyTransactionStatementLogic.php | 9 +++++++++ .../CustomerTransactionHistorySectionComponent.vue | 9 +++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/Classes/Modules/Transactions/ControllersLogic/FetchCompanyTransactionStatementLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/FetchCompanyTransactionStatementLogic.php index c16ac453..a078a01d 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/FetchCompanyTransactionStatementLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/FetchCompanyTransactionStatementLogic.php @@ -55,6 +55,15 @@ class FetchCompanyTransactionStatementLogic extends AbstractControllerLogic ->where('owner_type', Wallet::class) ->where('type', '!=', TransactionType::PAYMENT); }) + ->orWhere(function ($query) use ($companyId) { + $query + ->where('type', TransactionType::INVOICE) + ->where('owner_type', Booking::class) + ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) + ->whereHas('booking', function ($query) use ($companyId) { + $query->where('company_id', $companyId); + }); + }) ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) ->orderBy('created_at', 'desc') ->get(); diff --git a/resources/assets/vue/components/bookings/elements/CustomerTransactionHistorySectionComponent.vue b/resources/assets/vue/components/bookings/elements/CustomerTransactionHistorySectionComponent.vue index 7b0aee28..026a76c5 100644 --- a/resources/assets/vue/components/bookings/elements/CustomerTransactionHistorySectionComponent.vue +++ b/resources/assets/vue/components/bookings/elements/CustomerTransactionHistorySectionComponent.vue @@ -24,7 +24,8 @@
{{item.created_at}}
{{ convertTransactionType(item.type) }} {{ item.payment_reference ? ' - ' + item.payment_reference : '' }}
{{item.booking_marking}}
-
{{[5, 9].includes(parseFloat(item.type)) ? (Math.round((parseFloat(item.amount) + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : ''}}
+
{{[5, 9].includes(parseFloat(item.type)) ? (Math.round((parseFloat(item.amount) + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : ''}}
+
{{(Math.round(((parseFloat(item.amount) / parseFloat(item.currency_rate) + parseFloat(item.service_charge)) + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}
{{[1, 11].includes(parseFloat(item.type)) ? '- ' + (Math.round((parseFloat(item.amount) + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : ''}}
{{remainingBalance(index)}}
@@ -104,7 +105,11 @@ export default { if(this.transaction){ let transactions = this.transaction.slice().reverse(); transactions.slice(0, transactions.length - index).map(function(transaction) { - [1, 11].includes(transaction.type) ? tempBalance -= (transaction.amount) : tempBalance += (transaction.amount); + if (transaction.type === 2) { + tempBalance += (transaction.amount / transaction.currency_rate + transaction.service_charge); + } else { + [1, 11].includes(transaction.type) ? tempBalance -= (transaction.amount) : tempBalance += (transaction.amount); + } return tempBalance }, 0); } From a03adde5303d8d5278d462459646aef5f84d1a78 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Wed, 16 Aug 2023 15:39:34 +0800 Subject: [PATCH 02/18] regenerate invoices for 2023 --- routes/web.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/routes/web.php b/routes/web.php index cff4a06d..72860b3f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,6 @@ whereDate('updated_at', '>=', Carbon::parse('01-01-2023'))->get(); + + foreach($bookings as $booking){ + $booking->transactions()->whereIn('type', [TransactionType::INVOICE, TransactionType::SUPPLIER_DELIVER])->delete(); + $booking->documents()->whereIn('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'); + Route::get('/1688/fix/{reference}', function($reference){ $booking = Booking::where('marking', $reference)->first(); From e34e27658b0affd082aa939360df822df6d5fc64 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Wed, 16 Aug 2023 15:40:48 +0800 Subject: [PATCH 03/18] regenerate invoices for 2023 --- routes/web.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/web.php b/routes/web.php index 72860b3f..51ce8e15 100644 --- a/routes/web.php +++ b/routes/web.php @@ -469,7 +469,7 @@ Route::get('/invoice/fix', function(){ $bookings = Booking::where('status', ApprovalStatus::COMPLETED)->whereDate('updated_at', '>=', Carbon::parse('01-01-2023'))->get(); foreach($bookings as $booking){ - $booking->transactions()->whereIn('type', [TransactionType::INVOICE, TransactionType::SUPPLIER_DELIVER])->delete(); + $booking->transactions()->whereIn('transactions.type', [TransactionType::INVOICE, TransactionType::SUPPLIER_DELIVER])->delete(); $booking->documents()->whereIn('type', [DocumentType::INVOICE, DocumentType::PURCHASE_ORDER, DocumentType::DELIVER_ORDER, DocumentType::SUPPLIER_DELIVER_ORDER])->delete(); $booking->status = ApprovalStatus::APPROVED; $booking->save(); From 1ad4f3ea023c7c53a42d0717adba93c6a599a562 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Wed, 16 Aug 2023 15:41:31 +0800 Subject: [PATCH 04/18] regenerate invoices for 2023 --- routes/web.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/web.php b/routes/web.php index 51ce8e15..c4ae122a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -470,7 +470,7 @@ Route::get('/invoice/fix', function(){ foreach($bookings as $booking){ $booking->transactions()->whereIn('transactions.type', [TransactionType::INVOICE, TransactionType::SUPPLIER_DELIVER])->delete(); - $booking->documents()->whereIn('type', [DocumentType::INVOICE, DocumentType::PURCHASE_ORDER, DocumentType::DELIVER_ORDER, DocumentType::SUPPLIER_DELIVER_ORDER])->delete(); + $booking->documents()->whereIn('documents.type', [DocumentType::INVOICE, DocumentType::PURCHASE_ORDER, DocumentType::DELIVER_ORDER, DocumentType::SUPPLIER_DELIVER_ORDER])->delete(); $booking->status = ApprovalStatus::APPROVED; $booking->save(); From e88f0c8f0cbcfc8e2b81450973ca31e014553295 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Wed, 16 Aug 2023 15:42:37 +0800 Subject: [PATCH 05/18] regenerate invoices for 2023 --- routes/web.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/web.php b/routes/web.php index c4ae122a..324c03a9 100644 --- a/routes/web.php +++ b/routes/web.php @@ -470,7 +470,7 @@ Route::get('/invoice/fix', function(){ foreach($bookings as $booking){ $booking->transactions()->whereIn('transactions.type', [TransactionType::INVOICE, TransactionType::SUPPLIER_DELIVER])->delete(); - $booking->documents()->whereIn('documents.type', [DocumentType::INVOICE, DocumentType::PURCHASE_ORDER, DocumentType::DELIVER_ORDER, DocumentType::SUPPLIER_DELIVER_ORDER])->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(); From 408545d1845e702b1f56ce7fd6ea856ac1e699d5 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Wed, 16 Aug 2023 16:02:38 +0800 Subject: [PATCH 06/18] regenerate invoices for 2023 --- .../Helpers/InvoiceDocumentsHelper.php | 29 +++++++++++++++++ .../CreateInvoiceDocumentProcessor.php | 2 +- composer.json | 3 +- .../views/pages/pdfs/purchase_order.blade.php | 32 +++---------------- 4 files changed, 36 insertions(+), 30 deletions(-) create mode 100644 app/Classes/Helpers/InvoiceDocumentsHelper.php diff --git a/app/Classes/Helpers/InvoiceDocumentsHelper.php b/app/Classes/Helpers/InvoiceDocumentsHelper.php new file mode 100644 index 00000000..8b7ba8c4 --- /dev/null +++ b/app/Classes/Helpers/InvoiceDocumentsHelper.php @@ -0,0 +1,29 @@ +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/app/Classes/Modules/Transactions/Processors/CreateInvoiceDocumentProcessor.php b/app/Classes/Modules/Transactions/Processors/CreateInvoiceDocumentProcessor.php index 6215a1e1..2bbf5b88 100644 --- a/app/Classes/Modules/Transactions/Processors/CreateInvoiceDocumentProcessor.php +++ b/app/Classes/Modules/Transactions/Processors/CreateInvoiceDocumentProcessor.php @@ -1,7 +1,7 @@ @php - $subtotal = calculatePoSubtotal($po_order_transaction, $transaction->currency_rate); - $voucherDiscount = getPoVoucherDiscount($voucher_redemption); + $subtotal = InvoiceDocumentsHelper::calculateSubtotal($po_order_transaction, $transaction->currency_rate); + $voucherDiscount = InvoiceDocumentsHelper::getVoucherDiscount($voucher_redemption); $displayedSubtotal = 0; @endphp @@ -118,7 +118,7 @@ @php - $voucherDiscount = getPoVoucherDiscount($voucher_redemption); + $voucherDiscount = InvoiceDocumentsHelper::getVoucherDiscount($voucher_redemption); $subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract @endphp @@ -156,7 +156,7 @@ Adjustment - {{ roundUpPo($discrepancy,2) }} + {{ InvoiceDocumentsHelper::roundUp($discrepancy,2) }} @@ -175,28 +175,4 @@ - @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 From c021346beae0736df597546ed8f6db7d5445999b Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Wed, 16 Aug 2023 16:04:36 +0800 Subject: [PATCH 07/18] regenerate invoices for 2023 --- resources/views/layouts/base_pdf.blade.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/resources/views/layouts/base_pdf.blade.php b/resources/views/layouts/base_pdf.blade.php index 99eb376a..f7f40d99 100644 --- a/resources/views/layouts/base_pdf.blade.php +++ b/resources/views/layouts/base_pdf.blade.php @@ -1,3 +1,6 @@ +@php + use App\Classes\Helpers\InvoiceDocumentsHelper; +@endphp @@ -149,4 +152,4 @@ @yield('inner_content') - \ No newline at end of file + From be94423d2dffeca4f916b0b4ee58a63eecca3cd8 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Wed, 16 Aug 2023 16:15:24 +0800 Subject: [PATCH 08/18] regenerate invoices for 2023 --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b8b505d5..c4638c1a 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,8 @@ }, "autoload": { "psr-4": { - "App\\": "app/" + "App\\": "app/", + "App\\Classes\\Helpers\\": "app/Classes/Helpers" }, "classmap": [ "database/seeds", From 4b476d0bf767e8e94352be5002914459f10f5f47 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Wed, 16 Aug 2023 16:29:33 +0800 Subject: [PATCH 09/18] 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 From 2e32ce3059ab0beb28dc8116d05cb8289e9e9414 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Wed, 16 Aug 2023 16:47:11 +0800 Subject: [PATCH 10/18] regenerate invoices for 2023 --- app/Classes/Jobs/GenerateInvoice.php | 43 ++++++++++++++++++++++++++++ routes/web.php | 9 ++---- 2 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 app/Classes/Jobs/GenerateInvoice.php diff --git a/app/Classes/Jobs/GenerateInvoice.php b/app/Classes/Jobs/GenerateInvoice.php new file mode 100644 index 00000000..83191e25 --- /dev/null +++ b/app/Classes/Jobs/GenerateInvoice.php @@ -0,0 +1,43 @@ +booking = $booking; + } + + + public function handle() + { + $this->booking->transactions()->whereIn('transactions.type', [TransactionType::INVOICE, TransactionType::SUPPLIER_DELIVER])->delete(); + $this->booking->documents()->whereIn('document_type', [DocumentType::INVOICE, DocumentType::PURCHASE_ORDER, DocumentType::DELIVER_ORDER, DocumentType::SUPPLIER_DELIVER_ORDER])->delete(); + $this->booking->status = ApprovalStatus::APPROVED; + $this->booking->save(); + + (App()->make(CreateInvoiceTransactionProcessor::class))->execute($this->booking); + } +} diff --git a/routes/web.php b/routes/web.php index 324c03a9..ec389475 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,6 @@ whereDate('updated_at', '>=', Carbon::parse('01-01-2023'))->get(); foreach($bookings as $booking){ - $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); + GenerateInvoice::dispatch($booking); + return 'Invoice fixing job dispatched.'; } })->name('invoice.fix'); From c710b7b111dbf8c95c4d7a93f1a9589468ad77c5 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Wed, 16 Aug 2023 16:47:31 +0800 Subject: [PATCH 11/18] regenerate invoices for 2023 --- routes/web.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/web.php b/routes/web.php index ec389475..961af5b2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -471,7 +471,7 @@ Route::get('/invoice/fix', function(){ foreach($bookings as $booking){ GenerateInvoice::dispatch($booking); - return 'Invoice fixing job dispatched.'; + echo 'Invoice fixing job dispatched.'; } })->name('invoice.fix'); From 38749c11b6cf5b15db27aeca4986a89660fc11a0 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Wed, 16 Aug 2023 16:59:28 +0800 Subject: [PATCH 12/18] 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'); From e082da92a5e37024b87cd723a9af151e7fbc0f73 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Wed, 16 Aug 2023 17:01:05 +0800 Subject: [PATCH 13/18] regenerate invoices for 2023 --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index c4638c1a..b8b505d5 100644 --- a/composer.json +++ b/composer.json @@ -54,8 +54,7 @@ }, "autoload": { "psr-4": { - "App\\": "app/", - "App\\Classes\\Helpers\\": "app/Classes/Helpers" + "App\\": "app/" }, "classmap": [ "database/seeds", From 5d2108b40d3ee22c29981ff79cef1c7f87f3398f Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Wed, 16 Aug 2023 17:05:23 +0800 Subject: [PATCH 14/18] regenerate invoices for 2023 --- resources/views/pages/pdfs/deliver_order.blade.php | 7 ++++++- resources/views/pages/pdfs/invoice.blade.php | 7 ++++++- resources/views/pages/pdfs/purchase_order.blade.php | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/resources/views/pages/pdfs/deliver_order.blade.php b/resources/views/pages/pdfs/deliver_order.blade.php index 1cda9e1c..7f785097 100644 --- a/resources/views/pages/pdfs/deliver_order.blade.php +++ b/resources/views/pages/pdfs/deliver_order.blade.php @@ -148,7 +148,12 @@ Adjustment - {{ ceil($discrepancy * 100) / 100 }} + + @php + $roundedDiscrepancy = ($discrepancy > 0) ? ceil($discrepancy * 100) / 100 : floor($discrepancy * 100) / 100; + echo number_format($roundedDiscrepancy, 2); + @endphp + diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 19d03d4a..8fa07ef9 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -137,7 +137,12 @@ Adjustment - {{ roundUp($discrepancy, 2) }} + + @php + $roundedDiscrepancy = ($discrepancy > 0) ? ceil($discrepancy * 100) / 100 : floor($discrepancy * 100) / 100; + echo number_format($roundedDiscrepancy, 2); + @endphp + diff --git a/resources/views/pages/pdfs/purchase_order.blade.php b/resources/views/pages/pdfs/purchase_order.blade.php index 99eb09b0..326f9d20 100644 --- a/resources/views/pages/pdfs/purchase_order.blade.php +++ b/resources/views/pages/pdfs/purchase_order.blade.php @@ -154,7 +154,12 @@ Adjustment - {{ roundUpPo($discrepancy,2) }} + + @php + $roundedDiscrepancy = ($discrepancy > 0) ? ceil($discrepancy * 100) / 100 : floor($discrepancy * 100) / 100; + echo number_format($roundedDiscrepancy, 2); + @endphp + From bda7c2cc2048d64053162b55c266f4b03acfd422 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 17 Aug 2023 14:58:02 +0800 Subject: [PATCH 15/18] regenerate invoices for 2023 --- resources/views/pages/pdfs/deliver_order.blade.php | 1 + resources/views/pages/pdfs/invoice.blade.php | 1 + resources/views/pages/pdfs/purchase_order.blade.php | 1 + 3 files changed, 3 insertions(+) diff --git a/resources/views/pages/pdfs/deliver_order.blade.php b/resources/views/pages/pdfs/deliver_order.blade.php index 7f785097..a5cb0242 100644 --- a/resources/views/pages/pdfs/deliver_order.blade.php +++ b/resources/views/pages/pdfs/deliver_order.blade.php @@ -94,6 +94,7 @@ $itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5); $displayedItemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 2); $displayedSubtotal = bcadd($displayedSubtotal, $displayedItemTotal, 2); + $subtotal = bcadd($subtotal, $displayedItemTotal, 2); @endphp {{ $key + 1 }} diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 8fa07ef9..41378990 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -83,6 +83,7 @@ $itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5); $displayedItemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 2); $displayedSubtotal = bcadd($displayedSubtotal, $displayedItemTotal, 2); + $subtotal = bcadd($subtotal, $displayedItemTotal, 2); @endphp {{ $key + 1 }} diff --git a/resources/views/pages/pdfs/purchase_order.blade.php b/resources/views/pages/pdfs/purchase_order.blade.php index 326f9d20..984a52bd 100644 --- a/resources/views/pages/pdfs/purchase_order.blade.php +++ b/resources/views/pages/pdfs/purchase_order.blade.php @@ -123,6 +123,7 @@ $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 + $subtotal = bcadd($subtotal, $displayedItemTotal, 2); @endphp From be768a9803a499e904851f85c5dd739101ed7f69 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 17 Aug 2023 15:01:03 +0800 Subject: [PATCH 16/18] regenerate invoices for 2023 --- resources/views/pages/pdfs/deliver_order.blade.php | 7 +------ resources/views/pages/pdfs/invoice.blade.php | 7 +------ resources/views/pages/pdfs/purchase_order.blade.php | 7 +------ 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/resources/views/pages/pdfs/deliver_order.blade.php b/resources/views/pages/pdfs/deliver_order.blade.php index a5cb0242..715244c7 100644 --- a/resources/views/pages/pdfs/deliver_order.blade.php +++ b/resources/views/pages/pdfs/deliver_order.blade.php @@ -149,12 +149,7 @@ Adjustment - - @php - $roundedDiscrepancy = ($discrepancy > 0) ? ceil($discrepancy * 100) / 100 : floor($discrepancy * 100) / 100; - echo number_format($roundedDiscrepancy, 2); - @endphp - + {{number_format($discrepancy, 5)}} diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 41378990..98d6dc05 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -138,12 +138,7 @@ Adjustment - - @php - $roundedDiscrepancy = ($discrepancy > 0) ? ceil($discrepancy * 100) / 100 : floor($discrepancy * 100) / 100; - echo number_format($roundedDiscrepancy, 2); - @endphp - + {{number_format($discrepancy, 5)}} diff --git a/resources/views/pages/pdfs/purchase_order.blade.php b/resources/views/pages/pdfs/purchase_order.blade.php index 984a52bd..e0c9582f 100644 --- a/resources/views/pages/pdfs/purchase_order.blade.php +++ b/resources/views/pages/pdfs/purchase_order.blade.php @@ -155,12 +155,7 @@ Adjustment - - @php - $roundedDiscrepancy = ($discrepancy > 0) ? ceil($discrepancy * 100) / 100 : floor($discrepancy * 100) / 100; - echo number_format($roundedDiscrepancy, 2); - @endphp - + {{number_format($discrepancy, 5)}} From 89e9271c3f0277b2377bf5f795810078ff46555e Mon Sep 17 00:00:00 2001 From: edmondlang Date: Thu, 17 Aug 2023 16:49:58 +0800 Subject: [PATCH 17/18] show latest invoice in html --- routes/web.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/routes/web.php b/routes/web.php index 324c03a9..5cc38fbd 100644 --- a/routes/web.php +++ b/routes/web.php @@ -110,6 +110,27 @@ Route::get('/transfer/{marking}', function ($marking) { return view('pages.bookings.profile', ['marking' => $marking]); })->name('booking.details'); +Route::get('/transfer/{marking}/latest-invoice', function ($marking) { + $booking= Booking::where('marking', $marking)->first(); + + $purchaseOrder = $booking->transactions() + ->where('type', TransactionType::PURCHASE_ORDER) + ->complete() + ->first(); + + $transaction = $booking->transactions() + ->where('type', TransactionType::PAYMENT) + ->latest()->get()[0]; + + $supplier = Company::where('id', $transaction->receiver)->first(); + + $lowercaseDocumentType = strtolower(DocumentType::INVOICE); + + $voucherRedemption = $transaction->voucherRedemption; + + return view('pages.pdfs.' . $lowercaseDocumentType, ['transaction' => $transaction, 'po_order_transaction' => $purchaseOrder, 'supplier' => $supplier, 'voucher_redemption' => $voucherRedemption]); +})->name('booking.details.latest_invoice'); + Route::get('/transfer/merge/{marking}', function ($marking) { return view('pages.bookings.merge', ['marking' => $marking]); })->name('booking.merge'); From 00c2672d16de4a004c225f93d0d221925be49715 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Thu, 17 Aug 2023 23:19:03 +0800 Subject: [PATCH 18/18] update invoice amount --- resources/views/pages/pdfs/invoice.blade.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 98d6dc05..db6c42c5 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -79,11 +79,11 @@ @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) @php - $exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5); + $exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 7); $itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5); $displayedItemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 2); $displayedSubtotal = bcadd($displayedSubtotal, $displayedItemTotal, 2); - $subtotal = bcadd($subtotal, $displayedItemTotal, 2); + $subtotal = bcadd($subtotal, $itemTotal, 5); @endphp {{ $key + 1 }} @@ -130,7 +130,7 @@ @endif @php - $displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2); + $displayedTotal = bcadd(bcadd(bcadd($subtotal, $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($displayedTotal, $expectedTotal, 5); $total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5);