From 4a848f50cf5eb471b51d42043164ebcd2d8b28a0 Mon Sep 17 00:00:00 2001 From: Hardik Date: Sat, 9 May 2026 19:00:20 +0530 Subject: [PATCH] fix(import): stop parsing line items at T&C section Row 26 ("INSTRUCTIONS TO VENDORS") had an empty col-1 so the loop continued into the numbered T&C rows (27-33), which all have text in col-1 and were mistakenly added as line items. Two guards added: 1. Break immediately when col-0 contains "INSTRUCTION" (catches the section header even though col-1 is empty). 2. Skip any row where both qty and unitPrice are 0 (belt-and-suspenders for T&C rows that might slip through in other PO layouts). Co-Authored-By: Claude Sonnet 4.6 --- App/pelagia-portal/app/api/po/import/route.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/App/pelagia-portal/app/api/po/import/route.ts b/App/pelagia-portal/app/api/po/import/route.ts index fc14e3d..eed6320 100644 --- a/App/pelagia-portal/app/api/po/import/route.ts +++ b/App/pelagia-portal/app/api/po/import/route.ts @@ -71,14 +71,23 @@ function parseSheet(sheet: XLSX.WorkSheet): ParsedImport { for (let r = 15; r <= 100; r++) { const sn = cellStr(sheet, r, 0); const desc = cellStr(sheet, r, 1); + + // "INSTRUCTIONS TO VENDORS" in col 0 signals the T&C section — stop here + if (sn.toUpperCase().includes("INSTRUCTION")) break; + if (!desc && !sn) continue; if (!desc) continue; - // Stop at summary rows + + // Stop at summary/total rows in description column if (desc.toLowerCase().includes("total") || desc.toLowerCase().includes("grand")) break; const unitRaw = cellStr(sheet, r, 3); const qty = cellNum(sheet, r, 4); const unitPrice = cellNum(sheet, r, 5); + + // Skip rows with no quantity and no unit price — these are T&C text rows + if (qty === 0 && unitPrice === 0) continue; + const gstRaw = cellNum(sheet, r, 7); const gstRate = gstRaw > 1 ? gstRaw / 100 : gstRaw;