fix(payments): exclude draft proformas from outstanding (owner decision)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
main
Thomas Joise 2 days ago
parent 9d3087c1fe
commit 8c653eb41a

@ -278,7 +278,7 @@ export async function clientLedger(db: DB, clientId: string): Promise<ClientLedg
if (d.docType === 'INVOICE' && d.docNo !== null) { if (d.docType === 'INVOICE' && d.docNo !== null) {
const out = await outstandingPaise(db, d.id) const out = await outstandingPaise(db, d.id)
if (out > 0) outstanding.push({ docId: d.id, docNo: d.docNo, docType: d.docType, label: await moduleName(d), outstandingPaise: out }) if (out > 0) outstanding.push({ docId: d.id, docNo: d.docNo, docType: d.docType, label: await moduleName(d), outstandingPaise: out })
} else if (d.docType === 'PROFORMA' && (d.status === 'sent' || d.status === 'accepted' || d.status === 'draft')) { } else if (d.docType === 'PROFORMA' && (d.status === 'sent' || d.status === 'accepted')) {
outstanding.push({ docId: d.id, docNo: d.docNo, docType: d.docType, label: await moduleName(d), outstandingPaise: d.payablePaise }) outstanding.push({ docId: d.id, docNo: d.docNo, docType: d.docType, label: await moduleName(d), outstandingPaise: d.payablePaise })
} }
} }

@ -61,6 +61,17 @@ describe('clientLedger — outstanding + per-payment allocations', () => {
expect(led.outstanding.find((o) => o.docId === inv.id)).toBeUndefined() expect(led.outstanding.find((o) => o.docId === inv.id)).toBeUndefined()
}) })
it('excludes a draft proforma from outstanding but still includes a sent one', async () => {
const db = openDb(':memory:')
const { clientId, inv, pf } = await buildFixture(db)
const draftPf = await createDraft(db, 'u1', {
docType: 'PROFORMA', clientId, lines: [{ moduleId: inv.payload.lines[0]!.itemId, qty: 1, kind: 'yearly' }],
}) // left as 'draft' — never issued/sent
const led = await clientLedger(db, clientId)
expect(led.outstanding.find((o) => o.docId === draftPf.id)).toBeUndefined()
expect(led.outstanding.find((o) => o.docId === pf.id)).toMatchObject({ docId: pf.id, docNo: pf.docNo })
})
it('attaches allocations to each payment', async () => { it('attaches allocations to each payment', async () => {
const db = openDb(':memory:') const db = openDb(':memory:')
const { clientId, inv, payment } = await buildFixture(db) const { clientId, inv, payment } = await buildFixture(db)

Loading…
Cancel
Save