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
@@ -94,26 +94,43 @@ class GenerateCreditNotePdfV2Logic
if($eInvoiceStarted) {
$eInvoiceStarted = false; //reset to re-evaluate second time
$kvp = KeyValuePair::where('key', KVPKey::TRANSACTION_MODEL_CLASS)->where('value', $transaction->id)->first();
$refundTransaction = $kvp ? $kvp->owner : null;
if($refundTransaction && $refundTransaction->type === TransactionType::REFUND){
$metadata = $refundTransaction->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO_CREDIT_NOTE)->first();
//OLD BUSINESS LOGIC
// $kvp = KeyValuePair::where('key', KVPKey::TRANSACTION_MODEL_CLASS)->where('value', $transaction->id)->first();
// $refundTransaction = $kvp ? $kvp->owner : null;
// if($refundTransaction && $refundTransaction->type === TransactionType::REFUND){
// $metadata = $refundTransaction->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO_CREDIT_NOTE)->first();
// if($metadata){
// $autoCountInvoiceId = $metadata->value;
// }
// $metadata = $refundTransaction->attributesKVP()->where('key', KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK_CREDIT_NOTE)->first();
// if($metadata){
// $autoCountEInvoiceValidationLink = $metadata->value;
// }
// if($autoCountInvoiceId && $autoCountEInvoiceValidationLink){
// $eInvoiceStarted = true;
// }
// }
if($transaction && $transaction->type === TransactionType::CREDIT_NOTE){
$metadata = $transaction->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO_CREDIT_NOTE)->first();
if($metadata){
$autoCountInvoiceId = $metadata->value;
}
$metadata = $refundTransaction->attributesKVP()->where('key', KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK_CREDIT_NOTE)->first();
if($metadata){
$autoCountEInvoiceValidationLink = $metadata->value;
}
$metadata = $transaction->attributesKVP()->where('key', KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK_CREDIT_NOTE)->first();
if($metadata){
$autoCountEInvoiceValidationLink = $metadata->value;
}
Log::info('AUTOCOUNT_DOCNO_CREDIT_NOTE: ' . $autoCountInvoiceId);
Log::info('AUTOCOUNT_EINVOICE_VALIDATION_LINK_CREDIT_NOTE: ' . $autoCountEInvoiceValidationLink);
if($autoCountInvoiceId && $autoCountEInvoiceValidationLink){
$eInvoiceStarted = true;
}
}
else{
if($autoCountInvoiceId && $autoCountEInvoiceValidationLink){
$eInvoiceStarted = true;
}
}
}
Log::info('AUTOCOUNT_DOCNO_CREDIT_NOTE: ' . $autoCountInvoiceId);
Log::info('AUTOCOUNT_EINVOICE_VALIDATION_LINK_CREDIT_NOTE: ' . $autoCountEInvoiceValidationLink);
if($eInvoiceStarted)
{