Document Engine
Professional document generation built into Delivery Hub. Generate invoices, status reports, client agreements, and contractor agreements directly from your Salesforce data. Full version history, invoice approval and dispute workflows, PDF email delivery with one click, payment tracking, a complete accounts receivable ledger, and token-based native e-signature with a SHA-256 hash chain audit trail — all automatically.
Key Features
Invoice Generation
Select an entity and date range, and the engine snapshots all work items, time logs, and rates into a frozen document record. Zero-hour work items are automatically filtered out so only billable entries appear on the invoice. Rates cascade: WorkRequest rate > WorkItem rate > Entity default rate. The snapshot is immutable — editing the source data after generation does not change the invoice.
PDF Rendering
Professional Visualforce-rendered PDF with company header, sold-to section, work items table, time log detail, A/R summary, and payment footer with a cloudnimbusllc.com link. Each work item line includes a clickable hyperlink to its Salesforce record. Runtime namespace detection replaces %%%NAMESPACE_PREFIX%%% tokens automatically in both managed and unmanaged contexts. Proper CSS page breaks for multi-page invoices. Rendered server-side via Salesforce's Flying Saucer engine with inline styles for pixel-perfect output.
White-Label Branding
The PDF header, footer, and email automatically pull from the vendor NetworkEntity record. Any subscriber's vendor entity auto-brands their documents — zero configuration needed. Your company name, address, and contact info appear on every document.
Email Delivery
Send the invoice as a PDF email attachment with configurable CC. Status auto-transitions to Sent, and the due date is calculated from payment terms (Net 30, Net 15, or Due on Receipt). One click from preview to delivered.
Payment Tracking
Record payments against invoices with amount, date, and note. The engine auto-marks an invoice as Paid when payments fully cover the total. Prior balance auto-calculates from all unpaid invoices and carries forward to the next invoice.
DefaultBillingEntityId
Configure a default billing entity in DeliveryHubSettings__c so the document generation form auto-selects the correct NetworkEntity. Eliminates the most common support question (“which entity do I pick?”) and speeds up invoice generation for orgs with a single billing entity.
A/R Summary
Each invoice includes an Accounts Receivable Summary table showing all unpaid prior invoices with period, amount invoiced, amount paid, outstanding balance, and status. Gives your client a complete picture of their account in every document.
Multiple Rate Support
Three-tier rate cascade — WorkRequest hourly rate overrides WorkItem billable rate, which overrides the Entity default rate. Different work items can have different rates on the same invoice, and the engine resolves each line item independently.
Document Versioning
Regenerate an invoice or agreement and the engine creates a new version linked to the original via PreviousVersionId__c, preserving the complete audit trail. Each version gets an auto-incremented VersionNumber__c and retains its own frozen JSON snapshot for side-by-side comparison. The latest version is always the active one, but prior versions remain accessible via GET /v1/api/documents/:id/versions for reference and compliance.
Invoice Approval & Dispute Flow
Invoices go through an approval workflow before being sent. Clients can approve for payment or flag a dispute with comments stored in DisputeReasonTxt__c. Disputed invoices route back to the vendor for resolution. Status flow: Draft > Pending Approval > Approved / Disputed > Sent > Paid. The DeliveryDocEvent__e platform event fires on every status transition. Powers the portal approval experience via POST /v1/api/documents/:id/approve.
5 Document Templates Out of the Box
Invoice, Status Report, Client Agreement, Contractor Agreement, and Security Audit — all driven by DocumentTemplate__mdt custom metadata. Subscribers can add new templates without code changes. Each template defines its own fields, layout hints, AI prompt, and generation logic. The Security Audit template ships in v0.155+ and powers the Permission Analyzer's exportable security report.
E-Signature (v0.116)
Token-based document signing built directly into Delivery Hub — no DocuSign, no per-envelope fees, no external accounts. Send a document for signature, the counterparty opens a public link, draws their signature on a canvas, and clicks Sign. The signature image is stored as a ContentVersion, a DocumentAction__c record captures IP, user-agent, and consent timestamp, and every state transition writes an ActivityLog__c entry linked into a SHA-256 hash chain for tamper-evident audit. ESIGN/UETA compliant. Signed PDFs are generated server-side and available via the same token URL. Multi-party signing works because each party gets their own signing token and the document only finalizes when every party has signed.
How It Works
Four steps from raw data to a paid invoice. The engine handles snapshotting, rendering, delivery, and reconciliation.
Generate
Click "Generate Document" on the entity record. Apex queries all WorkItems, WorkLogs, and WorkRequests for the entity and period, freezes everything into a JSON snapshot, and creates a DeliveryDocument__c record with a public access token.
Preview
The LWC viewer shows the document inline with a status badge, work items table, time log detail, and A/R totals. Review everything before sending.
Send
Click "Send Email." Apex generates the PDF via the Visualforce page, attaches it to an email, sends to the recipient with CC, and marks the document as Sent with a calculated due date.
Record Payment
Click "Record Payment" and enter the amount, date, and an optional note. The engine auto-marks the invoice as Paid when the payment covers the total, and reduces the prior balance on the next invoice.
Rate Cascade
Each line item on an invoice resolves its hourly rate through a three-tier cascade. The most specific rate wins.
Technical Details
The Document Engine is built entirely on native Salesforce — Apex controllers, Visualforce PDF rendering, Lightning Web Components, and Custom Metadata Types.
| Component | Details |
|---|---|
| DeliveryDocumentController.cls | 770 lines, 8 @AuraEnabled methods (generate, send, payment, templates, status) |
| DeliveryDocumentPdfController.cls | 400+ lines, VF controller parsing JSON snapshots into typed wrapper properties with runtime namespace detection |
| DeliveryDocumentPdf.page | Visualforce PDF template with inline styles (Flying Saucer compatible), page breaks, record hyperlinks, and cloudnimbusllc.com footer link |
| deliveryDocumentViewer LWC | Full UI: generate form, preview, send modal, payment modal, PDF download |
| DocumentTemplate__mdt | 5 records out of the box — Invoice, Status Report, Client Agreement, Contractor Agreement, Security Audit |
| DeliveryTransaction__c | Dedicated ledger object — multiple payments per invoice, 5 transaction types, 5 payment methods |
| Test Coverage | 21 test methods across 2 test classes |
Payment & Transaction Ledger
Payments are not fields on an invoice — they are first-class records in a dedicated DeliveryTransaction__c object. This gives you a complete financial ledger with full audit trail.
Multiple Payments per Invoice
A single invoice can have any number of transactions. Record partial payments, split payments across methods (check + wire), or apply credits and adjustments independently. Each transaction is a separate record linked to the parent document.
Transaction Types
Five transaction types cover every billing scenario: Payment, Credit, Refund, Adjustment, and Write-Off. Each type affects the invoice balance calculation differently, and all are tracked in the A/R ledger.
Payment Methods
Record exactly how each payment was received: Check, Wire Transfer, ACH, Credit Card, or Cash. Payment method is stored on every transaction for reconciliation and reporting.
Automatic Paid Status
When the sum of payments on an invoice equals or exceeds the invoice total, the engine automatically marks the invoice as Paid. No manual status changes needed — the ledger is the source of truth.
Full A/R Audit Trail
Every transaction records the amount, date, method, type, and an optional reference note. The A/R Summary on each invoice reflects all transactions across all invoices for that entity — giving your client a complete account history in every document.
v0.116 — E-Signature
Delivery Hub now signs documents natively. No DocuSign envelopes, no per-signature fees, no external accounts for counterparties. Built in a single afternoon for a real-world lease signing. Read the story.
Token-Based Signing Links
Every signer on a document gets their own 64-character signing token stored on a DocumentAction__c record. Send the link directly or drop the signer into the public route at /portal/sign/<token>?direct=1. No login. No signup. No app to download. The counterparty opens the link, reads the document, draws their signature on a canvas, and clicks Sign.
Drawn Signatures on Canvas
Signatures are drawn with a finger or mouse on an HTML canvas and captured as a PNG. The image is uploaded as a ContentVersion and linked to the DocumentAction__c record. Works on touch devices, tablets, and desktops.
SHA-256 Hash Chain Audit Trail
Every state transition — document created, sent for signature, opened, signed, finalized — writes an ActivityLog__c entry. Each entry stores a SHA-256 hash of the prior entry plus its own payload, forming a tamper-evident chain: change any past entry and every downstream hash breaks. The chain captures IP address, user-agent, consent timestamp, and the signing token used, which is exactly what ESIGN and UETA require to hold up as an enforceable electronic signature.
Multi-Party Signing
A document can require signatures from any number of parties. Each party gets their own token and signs independently. The document only moves to Fully Executed when every required signer has completed their action. Real-time updates show each party the current state of co-signers so a lease or agreement can be countersigned in minutes rather than days.
Template-Aware Rendering
The signing page uses a React LeaseDocument component that reads the document's template type and renders the correct layout. New templates plug in without touching the signing pipeline — add a new DocumentTemplate__mdt record, register a renderer, and it's available for signing. Signed PDFs are generated server-side and downloadable from the same token URL for both parties to archive.
ESIGN / UETA Compliance
The combination of captured consent, tracked IP and user-agent, a hash-chain audit trail, and a frozen document snapshot satisfies the core requirements of the federal ESIGN Act and state UETA statutes: intent to sign, consent to electronic records, signature attribution, and record integrity. The audit record is exportable directly from Salesforce for legal review or litigation support.
v0.114 Improvements
Document Versioning
Documents now support full version history via three new fields: VersionNumber__c (auto-incremented), PreviousVersionId__c (links to prior version), and the existing JSON snapshot. Regenerate an invoice or agreement and the engine creates a new version linked to the original, preserving the complete audit trail. Each version retains its own frozen JSON snapshot, enabling side-by-side comparison between any two versions. The latest version is always the active one, but prior versions are accessible via GET /v1/api/documents/:id/versions.
Invoice Approval & Dispute Flow
Invoices can now go through an approval workflow before being sent. Clients reviewing an invoice in the portal can approve it for payment or flag a dispute with comments stored in DisputeReasonTxt__c. Disputed invoices route back to the vendor with the dispute reason for resolution. Status flow: Draft → Pending Approval → Approved / Disputed → Sent → Paid. The DeliveryDocEvent__e platform event fires on every status transition. The POST /v1/api/documents/:id/approve endpoint powers the portal approval experience.
PDF Hyperlink Fixes
PDF invoice line items now include fully clickable hyperlinks that open the corresponding Salesforce record in a new tab. The hyperlinks resolve correctly across both managed package and unmanaged contexts using runtime namespace detection. Previously, hyperlinks only worked in unmanaged orgs.
v0.105 Improvements
Zero-Hour Filtering
Work items with zero logged hours are automatically excluded from invoices. Only billable entries appear on the generated document, eliminating manual cleanup before sending.
PDF Record Hyperlinks
Each work item line in the PDF now includes a clickable hyperlink back to the Salesforce record. Invoice reviewers can click directly from the PDF to view full work item details, comments, and time logs in Salesforce.
Runtime Namespace Detection
The Visualforce PDF controller now auto-detects the runtime namespace instead of relying on %%%NAMESPACE_PREFIX%%% merge tokens. PDFs render correctly in both managed package installs and unmanaged development orgs with zero configuration.
Page Break Fix & Footer Link
Multi-page invoices now break correctly between sections. The invoice footer includes a branded cloudnimbusllc.com link for professional presentation.
Document Viewer on Record Pages
The deliveryDocumentViewer LWC is now placed directly on DeliveryDocument record pages, giving users inline preview, email delivery, and payment recording without navigating away from the record.
Also in v0.104
Sync Fix: WorkLog Error Surfacing
The WorkLog ingestor now throws an explicit SyncException when the parent WorkItem cannot be resolved, instead of silently failing. This surfaces the error for retry and makes sync chain debugging significantly easier.
Activity Feed Dedup
Disabled redundant field tracking for stage changes. The dedicated Stage_Change handler already logs these transitions, so the generic field change tracker was creating duplicate entries. Cleaner activity feed with no information loss.
Ready to generate your first invoice?
The Document Engine is included in every Delivery Hub installation. No additional configuration required — just navigate to a Network Entity record and click Generate Document.