E-Invoice - Automapping Issues, Sales Invoice Report (Import)

This commit is contained in:
Dillon Ngo
2025-07-23 22:45:32 +08:00
parent 8e3d0bf30f
commit 7d956888d2
@@ -39,7 +39,28 @@ class ImportExcelLogic extends AbstractControllerLogic
foreach ($object->getFiles() as $file){
$collection = Excel::toCollection(null, json_decode($file)->file_info->original->file, null, null, true);
$rows = $collection->first()->skip(1);
$sheet = $collection->first();
$header = $sheet->first()->toArray();
$normalizedHeader = array_map(fn($h) => strtolower(trim($h)), $header);
$salesInvoiceHeader = [
'docno', 'docdate', 'debtorcode', 'ref', 'shipinfo', 'accno',
'detaildescription', 'furtherdescription', 'classification',
'deptno', 'qty', 'unitprice', 'submiteinvoice', 'consolidatedeinvoice'
];
$customersReportHeader = [
'tin', 'identityno', 'name', 'identitytype', 'taxclassification', 'msiccode',
'businessactivitydesc', 'debtorcode', 'tradename', 'address', 'postcode',
'phone', 'emailaddress', 'city', 'countrycode', 'statecode'
];
if (
($reportType === 'Sales Invoice Report' && $normalizedHeader !== $salesInvoiceHeader) ||
($reportType === 'Customers Report' && $normalizedHeader !== $customersReportHeader)
) {
throw new MalformedRequestException('Uploaded Excel file format is incorrect. Column headers do not match expected format.');
}
$rows = $sheet->skip(1);
foreach ($rows as $index => $details) {
$docNo = $details[0] ?? null;
$docDate = $details[1] ?? null;