Merge branch 'dillon/90-e-invoice-e' into vapor/staging

This commit is contained in:
Dillon Ngo
2025-07-07 17:15:55 +08:00
4 changed files with 31 additions and 7 deletions
@@ -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){
@@ -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();
@@ -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]) {
@@ -24,7 +24,7 @@
<td class="header-details">
<div class="title"><strong>Receipt Voucher</strong></div>
<div class="number">EI#: {{ $transaction->bill_no }}</div>
<div class="ref">Ref# {{ $po_order_transaction->owner->marking }}</div>
<div class="ref">Ref# {{ $booking->marking ?? "-" }}</div>
<div class="date">Date: {{ $transaction->created_at }}</div>
<div>&nbsp;</div>
</td>
@@ -97,7 +97,7 @@
</thead>
<tbody>
<tr>
<td>PAYMENT FOR REF. {{ $po_order_transaction->owner->marking ?? 'N/A' }}</td>
<td>PAYMENT FOR REF. {{ $booking->marking ?? 'N/A' }}</td>
<td style="text-align:right;">{{ number_format($total, 2) }}</td>
</tr>
</tbody>