From c13476b1796d7a5c9b137c47aeb4d1d052bb983d Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sun, 19 Apr 2026 17:50:56 +0000 Subject: [PATCH] Changes Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com> --- src/routes/settings.import.tsx | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/routes/settings.import.tsx b/src/routes/settings.import.tsx index 016c0fa..0465129 100644 --- a/src/routes/settings.import.tsx +++ b/src/routes/settings.import.tsx @@ -250,10 +250,19 @@ const IMPORTERS: ImporterConfig[] = [ numeric: ["claim_amount", "settlement_amount", "default_hourly_rate", "flat_fee_amount"], dateCols: ["opened_at", "closed_at", "filing_date", "next_hearing_date", "statute_of_limitations"], transform: (r, ctx) => { + // Client resolution priority: + // 1. Client number (external id) + // 2. Client / Community Association / Association Name (by name) + // 3. Management Company (only if nothing else matched) const cid = r._clientext ? ctx.clientByExt.get(String(r._clientext)) : null; - const cidByName = r._clientname ? ctx.clientByName.get(String(r._clientname).toLowerCase()) : null; - r.client_id = cid ?? cidByName ?? null; - delete r._clientext; delete r._clientname; + const cidByName = r._clientname + ? ctx.clientByName.get(String(r._clientname).toLowerCase()) + : null; + const cidByMgmt = r._mgmtcompany + ? ctx.clientByName.get(String(r._mgmtcompany).toLowerCase()) + : null; + r.client_id = cid ?? cidByName ?? cidByMgmt ?? null; + delete r._clientext; delete r._clientname; delete r._mgmtcompany; delete r._assignedname; delete r._originatingname; if (!r.client_id) return null; const closedFlag = String(r._closedflag ?? "").toLowerCase().trim(); @@ -278,7 +287,14 @@ const IMPORTERS: ImporterConfig[] = [ const bm = String(r.billing_method).toLowerCase(); r.billing_method = bm.includes("flat") ? "flat" : bm.includes("contingency") ? "contingency" : bm.includes("hour") ? "hourly" : null; } - if (!r.case_number) r.case_number = `CASE-${Date.now()}-${Math.floor(Math.random() * 1000)}`; + // Generate a collision-free case number when none was provided. + // Uses crypto.randomUUID so simultaneous rows in the same batch never collide. + if (!r.case_number || !String(r.case_number).trim()) { + const uid = (typeof crypto !== "undefined" && "randomUUID" in crypto) + ? crypto.randomUUID().slice(0, 8).toUpperCase() + : `${Date.now().toString(36)}${Math.floor(Math.random() * 1e6).toString(36)}`.toUpperCase(); + r.case_number = `CASE-${uid}`; + } if (!r.title) r.title = r.case_number; return r; },