Function: recomputeDraftInvoice()
recomputeDraftInvoice(
companyId,invoiceId,actorId):Promise<{invoiceNumber:string;ok:true; } | {error:string; }>
Defined in: src/server/services/invoice/generate.ts:745
"Correct" an unsent (draft) invoice in place: recompute its lines from the current hours, swap the
line items atomically (recompute_draft_invoice RPC), and re-render the PDF — keeping the same
invoice number and NO "replaces" notice (unlike Void & correct, which reissues a new number).
Existing per-line reasons are preserved (matched by assignment_id). The recompute previews with
allowInactive so a draft for a since-deactivated facility can still be resolved.
Allowed only for a draft, app-origin invoice that has a billing week. A backfill-origin
(historical) invoice is edited via Correct-fields, not recomputed; a sent invoice must go through
reissue (Void & correct).
Side effect on PDF failure: because the total may have just changed, if the re-render fails the
stored pdf_storage_path is cleared so a later send cannot attach a PDF showing the old total —
the owner must Regenerate PDF before sending.
Parameters
companyId
string
Tenant scope.
invoiceId
string
The draft invoice to recompute.
actorId
string
User id recorded by the RPC as performing the correction (audit).
Returns
Promise<{ invoiceNumber: string; ok: true; } | { error: string; }>
{ ok: true, invoiceNumber } on success (PDF re-render is best-effort and does not fail
this call); otherwise { error } (not found, not a draft, backfill origin, no billing week, no
active assignments, or the RPC failed).