fix: report billing counts only sent/paid invoices as Invoiced
Draft invoices and orphaned invoice line items (invoice deleted → null) no longer count as Invoiced on the billing report, matching what the Finances page shows as issued. Not-invoiced/invoiced/paid buckets still sum to total version rows. No-op on current data (no drafts/orphans); guards future drafts. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -15,8 +15,12 @@ function fmtVersion(versionNumber) {
|
||||
}
|
||||
|
||||
function billingStatusFromInvoices(items = []) {
|
||||
if (!items.length) return 'not_started';
|
||||
if (items.some((item) => item.invoice?.status === 'paid')) return 'paid';
|
||||
// Only a sent or paid invoice counts as billed. Draft invoices and orphaned
|
||||
// line items (invoice deleted → invoice null) are treated as Not Invoiced,
|
||||
// matching what the Finances page actually shows as issued.
|
||||
const issued = items.filter((item) => item.invoice?.status === 'sent' || item.invoice?.status === 'paid');
|
||||
if (!issued.length) return 'not_started';
|
||||
if (issued.some((item) => item.invoice?.status === 'paid')) return 'paid';
|
||||
return 'invoiced';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user