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 <noreply@anthropic.com>
This commit is contained in:
Hardik 2026-05-09 19:00:20 +05:30
parent 96314d89f8
commit 4a848f50cf

View file

@ -71,14 +71,23 @@ function parseSheet(sheet: XLSX.WorkSheet): ParsedImport {
for (let r = 15; r <= 100; r++) { for (let r = 15; r <= 100; r++) {
const sn = cellStr(sheet, r, 0); const sn = cellStr(sheet, r, 0);
const desc = cellStr(sheet, r, 1); 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 && !sn) continue;
if (!desc) 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; if (desc.toLowerCase().includes("total") || desc.toLowerCase().includes("grand")) break;
const unitRaw = cellStr(sheet, r, 3); const unitRaw = cellStr(sheet, r, 3);
const qty = cellNum(sheet, r, 4); const qty = cellNum(sheet, r, 4);
const unitPrice = cellNum(sheet, r, 5); 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 gstRaw = cellNum(sheet, r, 7);
const gstRate = gstRaw > 1 ? gstRaw / 100 : gstRaw; const gstRate = gstRaw > 1 ? gstRaw / 100 : gstRaw;