diff --git a/apps/hq/src/repos-payments.ts b/apps/hq/src/repos-payments.ts index 103cf84..36455d8 100644 --- a/apps/hq/src/repos-payments.ts +++ b/apps/hq/src/repos-payments.ts @@ -278,7 +278,7 @@ export async function clientLedger(db: DB, clientId: string): Promise 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 }) } } diff --git a/apps/hq/test/ledger-outstanding.test.ts b/apps/hq/test/ledger-outstanding.test.ts index 92f57bb..045bc9f 100644 --- a/apps/hq/test/ledger-outstanding.test.ts +++ b/apps/hq/test/ledger-outstanding.test.ts @@ -61,6 +61,17 @@ describe('clientLedger — outstanding + per-payment allocations', () => { 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 () => { const db = openDb(':memory:') const { clientId, inv, payment } = await buildFixture(db)