Cashup: add 'Load last count' receipts button on petty cash form

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 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-02 21:06:13 +00:00
parent 5fe8fe2814
commit c2ab162870

View file

@ -220,6 +220,7 @@ export function FloatCountForm({ type }: { type: CountType }) {
const [receipts, setReceipts] = useState<Array<{ amount: string; description: string }>>([])
const [notes, setNotes] = useState('')
const [saving, setSaving] = useState(false)
const [loadingLast, setLoadingLast] = useState(false)
const [error, setError] = useState<string | null>(null)
const [savedRecord, setSavedRecord] = useState<DetailRecord | null>(null)
const [changeTinTargets, setChangeTinTargets] = useState<Record<string, number>>({})
@ -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<DetailRecord>(`/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 }) {
<Card style={{ marginBottom: '1rem' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '0.75rem' }}>
<h2 style={{ fontSize: '0.875rem', fontWeight: 700, color: 'var(--text-mid)' }}>RECEIPTS</h2>
<Btn small variant="ghost" onClick={() => setReceipts(r => [...r, { amount: '', description: '' }])}>+ Add</Btn>
<div style={{ display: 'flex', gap: '0.5rem' }}>
<Btn small variant="ghost" disabled={loadingLast} onClick={loadLastReceipts}>
{loadingLast ? 'Loading…' : 'Load last count'}
</Btn>
<Btn small variant="ghost" onClick={() => setReceipts(r => [...r, { amount: '', description: '' }])}>+ Add</Btn>
</div>
</div>
{receipts.map((r, i) => (
<div key={i} style={{ display: 'grid', gridTemplateColumns: '100px 1fr 32px', gap: '0.4rem', marginBottom: '0.35rem', alignItems: 'center' }}>