Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
0498fbe62e
commit
7d305d09e9
@@ -1374,10 +1374,24 @@ function ImportPage() {
|
||||
|
||||
// Inserts must have a non-null client_id; fall back to placeholder
|
||||
// ONLY for genuinely new invoices that never matched anything.
|
||||
let placeholderClient: string | null = null;
|
||||
const insertsNeedingClient = toInsertInv.filter((r) => !r.client_id);
|
||||
if (insertsNeedingClient.length > 0) {
|
||||
placeholderClient = await ensureArchivedClient("Imported (no client)", "imported-no-client");
|
||||
const { data: ph } = await supabase
|
||||
.from("clients")
|
||||
.upsert(
|
||||
{
|
||||
name: "Imported (no client)",
|
||||
external_id: "imported-no-client",
|
||||
client_type: "hoa",
|
||||
archived_at: new Date().toISOString(),
|
||||
notes: "Auto-created from invoice import (no matching client).",
|
||||
created_by: user.id,
|
||||
} as any,
|
||||
{ onConflict: "external_id" },
|
||||
)
|
||||
.select("id")
|
||||
.single();
|
||||
const placeholderClient = (ph?.id as string | undefined) ?? null;
|
||||
if (placeholderClient) {
|
||||
for (const r of insertsNeedingClient) r.client_id = placeholderClient;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user