Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
dd0ce5dbe9
commit
1897813205
@@ -1055,6 +1055,31 @@ function ImportPage() {
|
||||
return;
|
||||
}
|
||||
|
||||
// For cases: assign sequential "YYYY-####" numbers to any row missing a
|
||||
// case_number, continuing from the highest existing number for the year.
|
||||
if (cfg.table === "cases") {
|
||||
const year = new Date().getFullYear();
|
||||
const prefix = `${year}-`;
|
||||
const { data: existing } = await supabase
|
||||
.from("cases")
|
||||
.select("case_number")
|
||||
.like("case_number", `${prefix}%`);
|
||||
let maxSeq = 0;
|
||||
for (const row of (existing ?? []) as Array<{ case_number: string | null }>) {
|
||||
const m = /^(\d{4})-(\d+)$/.exec(String(row.case_number ?? ""));
|
||||
if (m && m[1] === String(year)) {
|
||||
const n = parseInt(m[2], 10);
|
||||
if (Number.isFinite(n) && n > maxSeq) maxSeq = n;
|
||||
}
|
||||
}
|
||||
for (const r of mapped) {
|
||||
if (!r.case_number || !String(r.case_number).trim()) {
|
||||
maxSeq += 1;
|
||||
r.case_number = `${prefix}${String(maxSeq).padStart(4, "0")}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Batch upsert in chunks of 200
|
||||
const chunkSize = 200;
|
||||
let inserted = 0;
|
||||
|
||||
Reference in New Issue
Block a user