From 1b53d0d44d36d92a51acf44980b039536fd6fd18 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Fri, 27 Jun 2025 19:09:42 +0800 Subject: [PATCH 1/3] E-Invoice - A new exception to when an order/booking is consider expired --- .../Rules/CanPassOrderDurationLimitRule.php | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/app/Classes/Modules/Rules/Standards/Rules/CanPassOrderDurationLimitRule.php b/app/Classes/Modules/Rules/Standards/Rules/CanPassOrderDurationLimitRule.php index 9e07bc23..96ead4fb 100644 --- a/app/Classes/Modules/Rules/Standards/Rules/CanPassOrderDurationLimitRule.php +++ b/app/Classes/Modules/Rules/Standards/Rules/CanPassOrderDurationLimitRule.php @@ -7,6 +7,8 @@ use App\Classes\General\Abstracts\AbstractRule; use App\Classes\Modules\Bookings\Services\FetchesBooking; use App\Classes\Modules\Companies\Services\FetchesCompanyPaymentAttemptLimit; use App\Classes\Modules\Transactions\Services\CalculatesTransactionExpiryDateTime; +use App\Classes\Modules\Bookings\Services\CalculatesBookingOutstanding; +use App\Classes\Modules\Bookings\Services\CalculatesBookingPaidAmount; use App\Classes\Modules\Billplzs\Services\DeletesBillplzBill; use App\Classes\Modules\Transactions\Services\FetchesTransaction; use App\Classes\ValueObjects\Constants\ApprovalStatus; @@ -32,6 +34,12 @@ class CanPassOrderDurationLimitRule extends AbstractRule /** @var FetchesTransaction */ private $fetchesTransaction; + /** @var CalculatesBookingOutstanding */ + private $calculatesBookingOutstanding; + + /** @var CalculatesBookingPaidAmount */ + private $calculatesBookingPaidAmount; + /** * CanPassOrderDurationLimitRule constructor. * @param FetchesBooking $fetchesBooking @@ -39,14 +47,18 @@ class CanPassOrderDurationLimitRule extends AbstractRule * @param CalculatesTransactionExpiryDateTime $calculatesTransactionExpiryDateTime * @param DeletesBillplzBill $deletesBillplzBill * @param FetchesTransaction $fetchesTransaction + * @param CalculatesBookingOutstanding $calculatesBookingOutstanding + * @param CalculatesBookingPaidAmount $calculatesBookingPaidAmount */ - public function __construct(FetchesBooking $fetchesBooking, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, CalculatesTransactionExpiryDateTime $calculatesTransactionExpiryDateTime, DeletesBillplzBill $deletesBillplzBill, FetchesTransaction $fetchesTransaction) + public function __construct(FetchesBooking $fetchesBooking, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, CalculatesTransactionExpiryDateTime $calculatesTransactionExpiryDateTime, DeletesBillplzBill $deletesBillplzBill, FetchesTransaction $fetchesTransaction, CalculatesBookingOutstanding $calculatesBookingOutstanding, CalculatesBookingPaidAmount $calculatesBookingPaidAmount) { $this->fetchesBooking = $fetchesBooking; $this->fetchesCompanyPaymentAttemptLimit = $fetchesCompanyPaymentAttemptLimit; $this->calculatesTransactionExpiryDateTime = $calculatesTransactionExpiryDateTime; $this->deletesBillplzBill = $deletesBillplzBill; $this->fetchesTransaction = $fetchesTransaction; + $this->calculatesBookingOutstanding = $calculatesBookingOutstanding; + $this->calculatesBookingPaidAmount = $calculatesBookingPaidAmount; } /** @@ -76,8 +88,18 @@ class CanPassOrderDurationLimitRule extends AbstractRule //Check if order is still valid (within duration limit, reused PAYMENT_ATTEMPT_DURATION_LIMIT) $expiresOn = $this->calculatesTransactionExpiryDateTime->execute($object->bookingId); $isExpired = Carbon::now()->greaterThan($expiresOn); - if($isExpired){ + if($isExpired) { + $booking = $this->fetchesBooking->execute(['id' => $object->bookingId]); + $amountOutstanding = $this->calculatesBookingOutstanding->execute($booking); + $amountPaid = $this->calculatesBookingPaidAmount->execute($booking); + if($amountPaid > 0.01 && $amountOutstanding > 0){ + Log::info("Transfer already expired but has paid amount: {$amountPaid} and outstanding amount: {$amountOutstanding}, Booking ID: {$object->bookingId}"); + $isExpired = false; + } + } + + if($isExpired){ if($object->paymentReference){ $transaction = $this->fetchesTransaction->execute(['payment_reference' => $object->paymentReference]); if($transaction->status === ApprovalStatus::PENDING_SUBMISSION && $transaction->payment_method == PaymentMethodType::PAYMENT_GATEWAY){ From b800d5b5a7a1d0217ff996185e2fb22f350984de Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Fri, 4 Jul 2025 01:11:28 +0800 Subject: [PATCH 2/3] E-Invoice - Temporary workaround to hide E-Credit Note from user view --- .../vue/components/bookings/elements/PaymentHistoryComponent.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue index bf6a78d3..fc7b077e 100644 --- a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue +++ b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue @@ -512,7 +512,6 @@ let vm = this; var TotalRequestedRefund = 0; this.data.transaction_refunds.forEach(function(refund) { - console.log('refund: ' + JSON.stringify(refund)); TotalRequestedRefund += refund.status === 1 ? refund.amount : 0; }); // if (vm.data.booking.fixed_currency.id != 1 && this.data.transaction_refunds[0]) { From 357a75613fedf61df600bf635054b3b606e1c9cb Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Mon, 7 Jul 2025 16:59:35 +0800 Subject: [PATCH 3/3] E-Invoice - Emergency fix for admin unable to approve payment --- .../Processors/CreateInvoiceDocumentProcessor.php | 7 +++++-- resources/views/pages/pdfs/receipt_voucher.blade.php | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Classes/Modules/Transactions/Processors/CreateInvoiceDocumentProcessor.php b/app/Classes/Modules/Transactions/Processors/CreateInvoiceDocumentProcessor.php index 8bb2c797..98adfd88 100644 --- a/app/Classes/Modules/Transactions/Processors/CreateInvoiceDocumentProcessor.php +++ b/app/Classes/Modules/Transactions/Processors/CreateInvoiceDocumentProcessor.php @@ -47,9 +47,12 @@ class CreateInvoiceDocumentProcessor { // calculate current Paid Amount $booking = $transaction->owner_type == Booking::class ? $transaction->owner : null; + if(!$booking){ + $booking = $transaction->owner->owner_type == Booking::class ? $transaction->owner->owner : null; + } $currentPaidAmount = null; $brn = $supplier->documents->where('document_type', DocumentType::SSM_REGISTRATION)->first(); - $documentDate = $supplier->segments->whereIn('id', [23])->first() ? \Carbon\Carbon::now() : $purchaseOrder->booking->created_at; + $documentDate = $supplier->segments->whereIn('id', [23])->first() ? \Carbon\Carbon::now() : $booking->created_at; $eInvoiceStartDate = Carbon::parse(env('E_INVOICE_START_DATE', '2025-07-01 00:00:00')); if ($booking) { @@ -74,7 +77,7 @@ class CreateInvoiceDocumentProcessor $lowercaseDocumentType = strtolower($document_type); - $order_pdf = LaravelMpdf::loadView('pages.pdfs.' . $lowercaseDocumentType, ['transaction' => $transaction, 'po_order_transaction' => $purchaseOrder, 'supplier' => $supplier, 'voucher_redemption' => $voucherRedemption, 'current_paid_amount' => $currentPaidAmount, 'document_date' => $documentDate, 'brn' => $brn, 'autocountId' => null]); //cief todo: 90 - autocount id to be updated + $order_pdf = LaravelMpdf::loadView('pages.pdfs.' . $lowercaseDocumentType, ['transaction' => $transaction, 'booking' => $booking, 'supplier' => $supplier, 'voucher_redemption' => $voucherRedemption, 'current_paid_amount' => $currentPaidAmount, 'document_date' => $documentDate, 'brn' => $brn, 'autocountId' => null]); //cief todo: 90 - autocount id to be updated if($purchaseOrder && $purchaseOrder->booking->service_id === 4) { $purchaseOrderDocuments = $purchaseOrder->booking->documents()->where('document_type', DocumentType::ECOMMERCE_PURCHASE_ORDER)->get(); diff --git a/resources/views/pages/pdfs/receipt_voucher.blade.php b/resources/views/pages/pdfs/receipt_voucher.blade.php index 64942f6f..d7380337 100644 --- a/resources/views/pages/pdfs/receipt_voucher.blade.php +++ b/resources/views/pages/pdfs/receipt_voucher.blade.php @@ -24,7 +24,7 @@
Receipt Voucher
EI#: {{ $transaction->bill_no }}
-
Ref# {{ $po_order_transaction->owner->marking }}
+
Ref# {{ $booking->marking ?? "-" }}
Date: {{ $transaction->created_at }}
 
@@ -97,7 +97,7 @@ - PAYMENT FOR REF. {{ $po_order_transaction->owner->marking ?? 'N/A' }} + PAYMENT FOR REF. {{ $booking->marking ?? 'N/A' }} {{ number_format($total, 2) }}