E-Invoice - Update business logic for downloading E-CreditNote

This commit is contained in:
Dillon Ngo
2025-08-26 10:09:18 +08:00
parent d8ce379560
commit d63b46c0ab
5 changed files with 41 additions and 21 deletions
@@ -46,6 +46,8 @@ class GenerateCreditNotePdfV2Logic
{
$pdfTemplateName = 'pages.pdfs.credit_note_v2'; //default since e-invoice implementation
$transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]);
$autoCountInvoiceId = '';
$autoCountEInvoiceValidationLink = 'CIEF';
if($transaction->type === TransactionType::REFUND){
//Retrieve TransactionType::CREDIT_NOTE
@@ -91,20 +93,18 @@ class GenerateCreditNotePdfV2Logic
if($eInvoiceStarted) {
$eInvoiceStarted = false; //reset to re-evaluate second time
$autoCountInvoiceId = '';
$autoCountEInvoiceValidationLink = '';
$metadata = $booking->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->first();
$metadata = $booking->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO_CREDIT_NOTE)->first();
if($metadata){
$autoCountInvoiceId = $metadata->value;
}
$metadata = $booking->attributesKVP()->where('key', KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK)->first();
$metadata = $booking->attributesKVP()->where('key', KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK_CREDIT_NOTE)->first();
if($metadata){
$autoCountEInvoiceValidationLink = $metadata->value;
}
Log::info('autoCountInvoiceId: ' . $autoCountInvoiceId);
Log::info('autoCountEInvoiceValidationLink: ' . $autoCountEInvoiceValidationLink);
Log::info('AUTOCOUNT_DOCNO_CREDIT_NOTE: ' . $autoCountInvoiceId);
Log::info('AUTOCOUNT_EINVOICE_VALIDATION_LINK_CREDIT_NOTE: ' . $autoCountEInvoiceValidationLink);
if($autoCountInvoiceId && $autoCountEInvoiceValidationLink){
$eInvoiceStarted = true;
@@ -127,7 +127,15 @@ class GenerateCreditNotePdfV2Logic
Log::info('Based on booking created date, E-Credit Note not yet started. / Not Yet Ready.');
}
$pdf = LaravelMpdf::loadView($pdfTemplateName, ['transaction' => $transaction, 'booking' => $booking, 'supplier' => $supplier, 'date' => $date, 'brn' => $brn,]);
$pdf = LaravelMpdf::loadView($pdfTemplateName, [
'transaction' => $transaction,
'booking' => $booking,
'supplier' => $supplier,
'date' => $date,
'brn' => $brn,
'autocountId' => $autoCountInvoiceId,
'autocountEInvoiceValidationLink' => $autoCountEInvoiceValidationLink,
]);
$exportFileName = 'CreditNote.pdf';
$filesystemDriver = Storage::getDefaultDriver();