From c2ab162870346928d1ab85c46c32cb2d716b6cf8 Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Thu, 2 Jul 2026 21:06:13 +0000 Subject: [PATCH] Cashup: add 'Load last count' receipts button on petty cash form MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fetches receipts from the most recent petty cash count and populates the current form — for when the tin hasn't been replenished and slips carry over. Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/pages/FloatManagement.tsx | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/FloatManagement.tsx b/frontend/src/pages/FloatManagement.tsx index ed49cd0..ba7eff0 100644 --- a/frontend/src/pages/FloatManagement.tsx +++ b/frontend/src/pages/FloatManagement.tsx @@ -220,6 +220,7 @@ export function FloatCountForm({ type }: { type: CountType }) { const [receipts, setReceipts] = useState>([]) const [notes, setNotes] = useState('') const [saving, setSaving] = useState(false) + const [loadingLast, setLoadingLast] = useState(false) const [error, setError] = useState(null) const [savedRecord, setSavedRecord] = useState(null) const [changeTinTargets, setChangeTinTargets] = useState>({}) @@ -278,6 +279,21 @@ export function FloatCountForm({ type }: { type: CountType }) { } } + async function loadLastReceipts() { + setLoadingLast(true) + try { + const list = await api.get<{ rows: FloatCount[] }>('/floats?type=petty_cash&offset=0&limit=1') + if (!list.rows.length) { setError('No previous petty cash count found.'); return } + const detail = await api.get(`/floats/${list.rows[0].id}`) + if (!detail.receipts.length) { setError('Last count had no receipts.'); return } + setReceipts(detail.receipts.map(r => ({ amount: String(r.receipt_value), description: r.receipt_description || '' }))) + } catch { + setError('Could not load last count.') + } finally { + setLoadingLast(false) + } + } + function reset() { setSavedRecord(null) setDenomQtys({}) @@ -338,7 +354,12 @@ export function FloatCountForm({ type }: { type: CountType }) {

RECEIPTS

- setReceipts(r => [...r, { amount: '', description: '' }])}>+ Add +
+ + {loadingLast ? 'Loading…' : 'Load last count'} + + setReceipts(r => [...r, { amount: '', description: '' }])}>+ Add +
{receipts.map((r, i) => (