From 13b6765214fbe8b6dba9fd2b6afb23110772d599 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Fri, 17 Apr 2026 01:51:29 +0000 Subject: [PATCH] Changes Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com> --- src/components/cases/collections-tab.tsx | 380 ++++++++++------------- 1 file changed, 170 insertions(+), 210 deletions(-) diff --git a/src/components/cases/collections-tab.tsx b/src/components/cases/collections-tab.tsx index c4c9d18..c28c607 100644 --- a/src/components/cases/collections-tab.tsx +++ b/src/components/cases/collections-tab.tsx @@ -1045,266 +1045,226 @@ function NewHomeownerDialog({ ); } -// ─── Post ledger entry dialog ─────────────────────────────────────── -function PostEntryDialog({ - open, - onOpenChange, - collectionId, - userId, - onSaved, -}: { - open: boolean; - onOpenChange: (v: boolean) => void; - collectionId: string; - userId?: string; - onSaved: () => void; -}) { - const [form, setForm] = useState({ - entry_date: new Date().toISOString().slice(0, 10), - transaction_type: "assessment", - description: "", - amount: "", - }); +// ─── Add Charge dialog (multi-bucket) ─────────────────────────────── +const CHARGE_BUCKETS: { key: typeof BUCKETS[number]; label: string }[] = [ + { key: "assess", label: "Assessment" }, + { key: "late", label: "Late Fee" }, + { key: "admin", label: "Admin Fee" }, + { key: "legal", label: "Legal Fee" }, + { key: "viol", label: "Violation Fine" }, + { key: "interest", label: "Interest" }, +]; + +function AddChargeDialog({ + open, onOpenChange, collectionId, userId, onSaved, +}: { open: boolean; onOpenChange: (v: boolean) => void; collectionId: string; userId?: string; onSaved: () => void }) { + const [date, setDate] = useState(new Date().toISOString().slice(0, 10)); + const [description, setDescription] = useState(""); + const [account, setAccount] = useState("assess"); + const [amount, setAmount] = useState(""); const [submitting, setSubmitting] = useState(false); useEffect(() => { - if (open) { - setForm({ - entry_date: new Date().toISOString().slice(0, 10), - transaction_type: "assessment", - description: "", - amount: "", - }); - } + if (open) { setDate(new Date().toISOString().slice(0, 10)); setDescription(""); setAccount("assess"); setAmount(""); } }, [open]); - const isPayment = PAYMENT_TYPES.has(form.transaction_type); - const submit = async () => { - const amount = parseFloat(form.amount); - if (isNaN(amount) || amount <= 0) { - toast.error("Enter a valid amount"); - return; - } + const amt = parseFloat(amount); + if (isNaN(amt) || amt <= 0) { toast.error("Enter an amount"); return; } setSubmitting(true); - const { error } = await supabase - .from("collection_ledger_entries") - .insert({ - collection_id: collectionId, - entry_date: form.entry_date, - transaction_type: form.transaction_type, - description: form.description || null, - debit: isPayment ? 0 : amount, - credit: isPayment ? amount : 0, - created_by: userId, - }); + const row: any = { + collection_id: collectionId, entry_date: date, + transaction_type: account, account, description: description || null, + created_by: userId, + }; + row[account] = amt; + const { error } = await supabase.from("collection_ledger_entries").insert(row); setSubmitting(false); - if (error) { - toast.error("Could not post", { description: error.message }); - return; - } - toast.success("Entry posted"); - onOpenChange(false); - onSaved(); + if (error) { toast.error(error.message); return; } + toast.success("Charge posted"); onOpenChange(false); onSaved(); }; return ( - - Post ledger entry - + Add Charge (Debit)
+
setDate(e.target.value)} />
- - - setForm({ ...form, entry_date: e.target.value }) - } - /> -
-
- - setAccount(v as any)}> + - {TXN_TYPES.map((t) => ( - - {t.label} - - ))} + {CHARGE_BUCKETS.map((b) => ({b.label}))}
-
- - setForm({ ...form, amount: e.target.value })} - /> -
-
- -