From 53c8938c2f2c678508c0b034a4434e56a16ae56f Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Wed, 1 Jul 2026 22:06:03 +0000 Subject: [PATCH] Fix denomination total wrong when loaded from DB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PostgreSQL NUMERIC columns return as strings in node-postgres. denomTotal was doing 0 + "40.00" + "30.00" → "040.0030.00", and parseFloat in fmtGBP read only the first portion, giving a wrong total (£40.00 instead of £78.80 etc). Fix: coerce total_amount and value_entered to numbers in applyLoaded; make denomTotal's reducer defensively use Number() so strings can't silently break the sum again. Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/pages/DailyCashUp.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/DailyCashUp.tsx b/frontend/src/pages/DailyCashUp.tsx index ae6a1c2..e63d743 100644 --- a/frontend/src/pages/DailyCashUp.tsx +++ b/frontend/src/pages/DailyCashUp.tsx @@ -26,7 +26,7 @@ function initMachines(): CardMachine[] { } function denomTotal(denoms: Denomination[]) { - return denoms.reduce((s, d) => s + d.total_amount, 0) + return denoms.reduce((s, d) => s + (Number(d.total_amount) || 0), 0) } interface Props { user: User } @@ -70,7 +70,12 @@ export function DailyCashUp({ user: _user }: Props) { s => s.count_type === ct && parseFloat(String(s.denomination_value)) === d.value ) return saved - ? { ...saved, denomination_value: d.value } + ? { + ...saved, + denomination_value: d.value, + total_amount: parseFloat(String(saved.total_amount)) || 0, + value_entered: saved.value_entered != null ? parseFloat(String(saved.value_entered)) : null, + } : { count_type: ct, denomination_type: d.type, denomination_value: d.value, quantity: null, value_entered: null, total_amount: 0 } })