E-Invoice - Update the conditions for generating Sales Invoice Report with business logic update on generating invoice

This commit is contained in:
Dillon Ngo
2025-11-27 10:31:22 +08:00
parent 01dd8073a1
commit ac3a71627c
2 changed files with 52 additions and 27 deletions
@@ -105,7 +105,8 @@ class CreateInvoiceTransactionV2Processor
}
if ($booking->status === ApprovalStatus::COMPLETED && !$generateEInvoiceRefund) {
return;
Log::info('CreateInvoiceTransactionV2Processor Check 1 Bypass New Business Logic Update for booking ' . $booking->id);
// return;
}
$payable_amount = $this->calculatesBookingPayableAmount->execute($booking, $booking->fix_currency_id, $generateEInvoiceRefund);
@@ -117,7 +118,8 @@ class CreateInvoiceTransactionV2Processor
}
// confirm that all payments has been transferred
if ($this->calculatesBookingTransferredAmount->execute($booking) !== $this->calculatesBookingPaidAmount->execute($booking)) {
return;
Log::info('CreateInvoiceTransactionV2Processor Check 2 Bypass New Business Logic Update for booking ' . $booking->id);
// return;
}
if($generateEInvoiceRefund){
@@ -264,38 +266,40 @@ class CreateInvoiceTransactionV2Processor
$transaction = $paymentTransaction->transactions()->where('type', TransactionType::BILL)->first();
}
else{ // Special handling for refund cases (When a refund is deleted via DeleteRefundTransactionLogic, a booking payment transaction is set to ApprovalStatus::APPROVED)
$temp = $booking->transactions()->payments()->where('status', ApprovalStatus::APPROVED)->first();
$paymentTransactionTemp = $booking->transactions()->payments()->where('status', ApprovalStatus::APPROVED)->first();
// Lets check if there is a refund case
$refund = $temp->transactions()->refunds()->where('status', ApprovalStatus::APPROVED)->first();
$refund = $paymentTransactionTemp->transactions()->refunds()->where('status', ApprovalStatus::APPROVED)->first();
if($refund){
$transaction = $temp;
$transaction = $paymentTransactionTemp->transactions()->where('type', TransactionType::BILL)->first();
}
else{
throw new Exception("No payment found for booking '$booking->id'.");
Log::info("CreateInvoiceTransactionV2Processor NO completed payment transaction, refund transaction found for booking '$booking->id'.");
}
}
$transaction_object = new TransactionObject(
$billNumber,
TransactionType::SUPPLIER_DELIVER,
$transaction->issuer,
$transaction->receiver,
$transaction->recipient_bank_account_id,
$transaction->payment_method,
$payable_amount,
$booking_amount,
$transaction->currency_id,
$transaction->original_currency_id,
$booking_currency_average_rate,
$total_tax,
$total_service_charge,
null,
ApprovalStatus::APPROVED
);
$supplier_deliver_order_transaction = $this->createsTransaction->execute($purchaseOrder->booking, $transaction_object);
if($transaction){
$transaction_object = new TransactionObject(
$billNumber,
TransactionType::SUPPLIER_DELIVER,
$transaction->issuer,
$transaction->receiver,
$transaction->recipient_bank_account_id,
$transaction->payment_method,
$payable_amount,
$booking_amount,
$transaction->currency_id,
$transaction->original_currency_id,
$booking_currency_average_rate,
$total_tax,
$total_service_charge,
null,
ApprovalStatus::APPROVED
);
$supplier_deliver_order_transaction = $this->createsTransaction->execute($purchaseOrder->booking, $transaction_object);
// supply deliver order
$this->invoiceDocumentProcessor->execute($supplier_deliver_order_transaction, $purchaseOrder, $supplier, DocumentType::SUPPLIER_DELIVER_ORDER, null);
// supply deliver order
$this->invoiceDocumentProcessor->execute($supplier_deliver_order_transaction, $purchaseOrder, $supplier, DocumentType::SUPPLIER_DELIVER_ORDER, null);
}
}
//if(!$generateEInvoiceRefund){
@@ -200,7 +200,20 @@
</div>
<div class="row m-b-15" v-if="($store.getters.isAdmin && data.purchase_order.status === 1) || ($store.getters.isCustomer && data.purchase_order.status === 1 && $store.getters.getCompanyId === 199)" >
<div class="col">
<button class="btn btn-sm btn-block btn-success b-rad-none" @click="submit(route('api.booking.po.approval', data.id), 'post', section, true, true)">Approve Purchase Order</button>
<button class="btn btn-sm btn-block btn-success b-rad-none" :disabled="poProcessing" @click="handleRepprove()">Approve Purchase Order</button>
</div>
</div>
<div class="row m-b-15" v-if="$store.getters.isAdmin && data.purchase_order.status === 2" >
<div class="col">
<button class="btn btn-sm btn-block btn-success b-rad-none" :disabled="poProcessing" @click="handleRepprove()">
Repprove Purchase Order
<span class="badge badge-danger position-absolute" style="top:-5px; right:-5px;"
data-toggle="tooltip"
data-placement="right"
data-html="true"
data-custom-class="tooltip-report-export"
title="Allow admin to rerun of 'Approve Purchase Order' to generate invoices, conditions apply">ADMIN</span>
</button>
</div>
</div>
</div>
@@ -258,6 +271,7 @@
products: [],
files: [],
uploadFiles: false,
poProcessing: false,
}
},
validations: {
@@ -379,6 +393,7 @@
}
this.updateList()
}
this.poProcessing = false;
},
errorHandler(error, statusCode, section) { //E-Invoice
if(section === this.section + 'CheckEInvoiceRule' && statusCode === 422){
@@ -441,8 +456,14 @@
};
this.parameters.e_invoice_request = false;
this.submit((this.route('api.company.einvoice.request.change')), 'post', this.section + 'ChangeOfMind', true, true);
},
handleRepprove() {
if (this.poProcessing) return;
this.poProcessing = true;
this.submit(route('api.booking.po.approval', this.data.id), 'post', this.section, true, true);
}
},
mixins: [formHandler]
}
</script>
<