Context
In PR #28, repairSequences() was added to main/db.ts to rebuild sequence counters from existing order/bill data on startup. It works correctly but parses order/bill numbers using fixed substr positions:
substr(order_number, 5, 8) // date
substr(order_number, 14) // sequence number
Problem
This is fragile — if the numbering format ever changes (e.g. longer prefixes, different separators), the extraction silently returns wrong values.
Proposed Fix
Replace substr with a regex:
const match = row.order_number.match(/^ORD-(\d{8})-(\d+)$/);
if (match) { /* match[1] = date, match[2] = sequence */ }
Priority
Low — the current format (ORD-YYYYMMDD-NNNN / INV-YYYYMMDD-NNNN) is stable and the function runs with try/catch, so no risk today. Just a robustness improvement for the future.
Context
In PR #28,
repairSequences()was added tomain/db.tsto rebuild sequence counters from existing order/bill data on startup. It works correctly but parses order/bill numbers using fixedsubstrpositions:Problem
This is fragile — if the numbering format ever changes (e.g. longer prefixes, different separators), the extraction silently returns wrong values.
Proposed Fix
Replace
substrwith a regex:Priority
Low — the current format (
ORD-YYYYMMDD-NNNN/INV-YYYYMMDD-NNNN) is stable and the function runs with try/catch, so no risk today. Just a robustness improvement for the future.