Fix denomination total wrong when loaded from DB
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 <noreply@anthropic.com>
This commit is contained in:
parent
4ea5238e62
commit
53c8938c2f
1 changed files with 7 additions and 2 deletions
|
|
@ -26,7 +26,7 @@ function initMachines(): CardMachine[] {
|
||||||
}
|
}
|
||||||
|
|
||||||
function denomTotal(denoms: Denomination[]) {
|
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 }
|
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
|
s => s.count_type === ct && parseFloat(String(s.denomination_value)) === d.value
|
||||||
)
|
)
|
||||||
return saved
|
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 }
|
: { count_type: ct, denomination_type: d.type, denomination_value: d.value, quantity: null, value_entered: null, total_amount: 0 }
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue