E-Invoice - Update in export and import of Credit Note report with update of 'Ref' column

This commit is contained in:
Dillon Ngo
2025-09-30 13:50:05 +08:00
parent e0cfeca54b
commit 20cd90c9f0
7 changed files with 85 additions and 47 deletions
@@ -15,6 +15,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Models\Booking;
use App\Models\Transaction;
use Illuminate\Support\Facades\Log;
@@ -71,19 +72,29 @@ class ProcessCreditNoteReportV2CommandJob implements ShouldQueue
'EInvoiceValidationLink' => $eInvoiceValidationLink,
]);
$booking = Booking::where('marking', $ref)->first();
if($booking){
// $booking = Booking::where('marking', $ref)->first();
// if($booking){
// if($docNo != "" && $docNo != "<<New>>"){
// $payments = $booking->transactions()->payments()->get();
// foreach ($payments as $payment) {
// $refundTransaction = $payment->transactions()->refunds()->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->latest()->first();
// if($refundTransaction){
// $this->updateOrCreateKeyValuePair($refundTransaction, KVPKey::AUTOCOUNT_DOCNO_CREDIT_NOTE, $docNo);
// if($eInvoiceValidationLink){
// $this->updateOrCreateKeyValuePair($refundTransaction, KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK_CREDIT_NOTE, $eInvoiceValidationLink);
// }
// break;
// }
// }
// }
// }
$transaction = Transaction::where('bill_no', $ref)->first();
if($transaction){
if($docNo != "" && $docNo != "<<New>>"){
$payments = $booking->transactions()->payments()->get();
foreach ($payments as $payment) {
$refundTransaction = $payment->transactions()->refunds()->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->latest()->first();
if($refundTransaction){
$this->updateOrCreateKeyValuePair($refundTransaction, KVPKey::AUTOCOUNT_DOCNO_CREDIT_NOTE, $docNo);
if($eInvoiceValidationLink){
$this->updateOrCreateKeyValuePair($refundTransaction, KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK_CREDIT_NOTE, $eInvoiceValidationLink);
}
break;
}
$this->updateOrCreateKeyValuePair($transaction, KVPKey::AUTOCOUNT_DOCNO_CREDIT_NOTE, $docNo);
if($eInvoiceValidationLink){
$this->updateOrCreateKeyValuePair($transaction, KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK_CREDIT_NOTE, $eInvoiceValidationLink);
}
}
}