Fixed balance display in collections
X-Lovable-Edit-ID: edt-02fa7a6f-3d1a-4ea8-bb30-ab12e0b43a8f Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
@@ -73,7 +73,7 @@ function CollectionsIndexPage() {
|
||||
const [{ data: ents }, { data: tasks }] = await Promise.all([
|
||||
supabase
|
||||
.from("collection_ledger_entries")
|
||||
.select("collection_id, debit, credit")
|
||||
.select("collection_id, assess, late, admin, legal, viol, interest, bank, payment, debit, credit")
|
||||
.in("collection_id", ids),
|
||||
supabase
|
||||
.from("collection_tasks")
|
||||
@@ -85,9 +85,13 @@ function CollectionsIndexPage() {
|
||||
list.forEach((c: any) => {
|
||||
balMap[c.id] = Number(c.homeowner?.opening_balance ?? 0);
|
||||
});
|
||||
const num = (v: any) => Number(v) || 0;
|
||||
(ents ?? []).forEach((e: any) => {
|
||||
balMap[e.collection_id] =
|
||||
(balMap[e.collection_id] ?? 0) + Number(e.debit) - Number(e.credit);
|
||||
const charges =
|
||||
num(e.assess) + num(e.late) + num(e.admin) + num(e.legal) +
|
||||
num(e.viol) + num(e.interest) + num(e.bank) + num(e.debit);
|
||||
const credits = num(e.payment) + num(e.credit);
|
||||
balMap[e.collection_id] = (balMap[e.collection_id] ?? 0) + charges - credits;
|
||||
});
|
||||
setBalances(balMap);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user