fix(export): improve narrative generation logic and add additional ID formats

- Menambahkan validasi untuk memeriksa apakah `transaction` ada sebelum mengakses propertinya sehingga mencegah error pada situasi `null`.
- Menambahkan fallback description jika `transaction` bernilai null pada metode `generateNarrative`.
- Menambahkan dukungan untuk ID narasi tambahan seperti `APITRX`, `ONUSCR`, dan `ONUSDR` pada `getFormatNarrative`.
- Memodifikasi output `cleanPart` dengan menambahkan spasi untuk memastikan format narasi lebih konsisten.
- Mengubah penggantian `<NL>` dalam hasil akhir menjadi spasi kosong untuk meningkatkan keterbacaan hasil narasi.
This commit is contained in:
daengdeni
2025-05-26 16:47:02 +07:00
parent 9025663954
commit 299ed0b018

View File

@@ -198,16 +198,24 @@
private function generateNarrative($item)
{
$narr = '';
if ($item->transaction->narr_type) {
$narr .= $item->transaction->stmt_narr . ' ';
$narr .= $this->getFormatNarrative($item->transaction->narr_type, $item);
// Check if transaction exists before accessing its properties
if ($item->transaction) {
if ($item->transaction->narr_type) {
$narr .= $item->transaction->stmt_narr . ' ';
$narr .= $this->getFormatNarrative($item->transaction->narr_type, $item);
} else {
$narr .= $item->transaction->stmt_narr . ' ';
}
} else {
$narr .= $item->transaction->stmt_narr . ' ';
// Fallback description if transaction is null
$narr .= '';
}
if ($item->ft?->recipt_no) {
$narr .= 'Receipt No: ' . $item->ft->recipt_no;
}
return trim($narr);
}
@@ -231,7 +239,13 @@
$fmt = 'TT.O.TRF';
} else if ($narrParam->_id == 'TTTRFIN') {
$fmt = 'TT.I.TRF';
} else {
} else if ($narrParam->_id == 'APITRX'){
$fmt = 'API.TSEL';
} else if ($narrParam->_id == 'ONUSCR'){
$fmt = 'ONUS.CR';
} else if ($narrParam->_id == 'ONUSDR'){
$fmt = 'ONUS.DR';
}else {
$fmt = $narrParam->_id;
}
@@ -260,7 +274,7 @@
$splitPart = explode('!', $part);
if (count($splitPart) > 0) {
// Remove quotes, backslashes, and other escape characters
$cleanPart = trim($splitPart[0]);
$cleanPart = trim($splitPart[0]).' ';
// Remove quotes at the beginning and end
$cleanPart = preg_replace('/^["\'\\\\]+|["\'\\\\]+$/', '', $cleanPart);
// Remove any remaining backslashes
@@ -306,7 +320,7 @@
}
}
return str_replace('<NL>', '', $result);
return str_replace('<NL>', ' ', $result);
}
/**