BuildContractArtifacts / buildContractContext assemble the substitution context (builder branding from invoice_settings, customer from form_data, project from the estimate snapshot, money from the snapshot and job_meta) and return both the rendered body and the frozen required-sections manifest. Three callers use it: first generation on form submit, template switching, and pulling a contract to the live estimate.
Also called: auto-generate contract · contract from estimate · estimate to contract · no retyping
- 1Load the org's active contract template (seeding the default if none exists, so the tenant's contracts share one template id for audit).
- 2Pull builder branding from invoice_settings.
- 3Compose the context: dates, customer identity, project address and schedule, estimate totals, payment schedule, line-item table, governing-law state and notice.
- 4renderTemplate() substitutes the tokens; extractRequiredSections() derives the initials manifest from numbered headings.
- 5Freeze rendered_body + required_sections on the contracts row.
The shared-generator design is a direct response to drift between render paths: 'Keeping this in one place means the per-contract template picker produces byte-identical output to the original generation — same estimate table, payment schedule, governing-law clause, and initials manifest.' The alternative — a second, slightly different renderer for re-renders — is how two copies of the same contract end up disagreeing.
- Divergence between the estimate the customer approved and the contract they sign
- Multiple render paths producing subtly different documents
See it on your own jobs
Twenty minutes, your numbers, no slide deck. We’ll build one of your real buildings in front of you and send you the estimate link at the end — yours to keep either way.
or keep browsing features →