From 8b2dc4ad78ecf42d9745bc4ec337885615410f9c Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Tue, 7 Jul 2026 11:38:12 +0000 Subject: [PATCH] Cashup: preserve orphaned card machine data when settings name is removed applyLoaded now appends any DB machines whose name is no longer in the current settings list, rather than silently dropping them. This prevents their amounts being deleted from the database the next time the record is saved (backend does DELETE + re-insert on every save). Orphaned machines render with a red 'Removed from settings' badge, a pink border, and read-only inputs so the data is visible but can't be accidentally edited. They are still included in totalPdq and the save payload, so nothing is lost. Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/pages/DailyCashUp.tsx | 38 +++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/frontend/src/pages/DailyCashUp.tsx b/frontend/src/pages/DailyCashUp.tsx index 35bcce0..07b5f4a 100644 --- a/frontend/src/pages/DailyCashUp.tsx +++ b/frontend/src/pages/DailyCashUp.tsx @@ -92,7 +92,14 @@ export function DailyCashUp({ user }: Props) { setFloat(rebuild('float')) if (data.card_machines.length) { - setMachines(machineNamesRef.current.map(name => { + const settingsNames = machineNamesRef.current + // Any DB machine whose name is no longer in settings — keep it visible and in + // the save payload so its data isn't silently deleted when the record is re-saved. + const orphanedNames = data.card_machines + .map(m => m.machine_name) + .filter(n => !settingsNames.includes(n)) + const allNames = [...settingsNames, ...orphanedNames] + setMachines(allNames.map(name => { const m = data.card_machines.find(c => c.machine_name === name) if (!m) return { machine_name: name, total_amount: 0, amex_amount: 0, visa_mc_amount: 0 } return { @@ -398,21 +405,33 @@ export function DailyCashUp({ user }: Props) { Total: {fmtGBP(totalPdq)}
- {machines.map((m, i) => ( + {machines.map((m, i) => { + const isOrphaned = !machineNamesRef.current.includes(m.machine_name) + const inputDisabled = isFinal || isOrphaned + return (
{/* Left: amount inputs */}
-

- {m.machine_name} -

+
+

+ {m.machine_name} +

+ {isOrphaned && ( + + Removed from settings + + )} +
updateMachine(i, 'total_amount', v)} disabled={isFinal} /> + onChange={v => updateMachine(i, 'total_amount', v)} disabled={inputDisabled} /> updateMachine(i, 'amex_amount', v)} disabled={isFinal} /> + onChange={v => updateMachine(i, 'amex_amount', v)} disabled={inputDisabled} />
Visa / MC {fmtGBP(m.visa_mc_amount)} @@ -441,7 +460,8 @@ export function DailyCashUp({ user }: Props) { )}
- ))} + ) + })}