Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
6a6d35f82a
commit
c13476b179
@@ -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;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user