Documents
Document routes list, count, sum, view, create, edit, and delete customer documents and business documents when the user has document permission.
Customer Documents
- Use customer_id to list, count, or sum documents connected to one customer.
- Documents may include invoices, agreements, generated files, uploaded files, and other account document records.
- Keep document_id from list/add responses for view, edit, and delete actions.
Customer Product Tab
- Use Documents.Products with customer_id to load the same product line-item list as the dashboard customer Product tab (product_invoice_html).
- Rows come from document items on purchase orders, order proposals, GI IR, donation receipts, and selected invoices.
- This is not Products.List (catalog). Pagination is by documents; each document can return multiple product rows.
Totals / Sum
- Use Documents.Sum to get the sum of documents.total / final_amount for a customer, company (invoice_setting_id), type/types, and optional date range.
- Default type=net (or omit type/types) uses: invoice + receipt_tax_invoice - credit_invoice.
- Send types as an array, for example ["invoice","credit_invoice"]. invoice and receipt_tax_invoice are added; credit_invoice is subtracted when mixed with other types.
- If only one type is requested, its total is returned for that type. If only credit_invoice is requested, its total is returned as-is.
- Draft documents are excluded unless include_drafts=1.
Create / Edit
- Document add/edit can include document type, customer, items, totals, notes, and folder data depending on the route.
- Complex document generation can trigger document creation logic, signing, PDF generation, or file-server storage depending on document type.
- Use route-specific help because required fields change by document type.
Files
- Documents that create files should return a file-server path that the UI can use.
- User-selected display names can be saved, but stored files should use system-generated safe names.
PDF Templates
- Open DocumentsTemplates for the full PDF template guide, including placeholders, loops, filters, CSS, RTL, payment links, and safety rules.
- Users can create custom HTML/CSS document PDF templates from Settings > Document PDF Templates.
- Templates are saved per document type, tested with mock data, activated by version, and can be set as defaults per account/company/document type.
- When creating a document, send pdf_template_id to use a specific active template. If it is empty, the default active custom template is used when one exists.
- Send pdf_template_strict=1 when the UI should fail if the selected template is invalid or cannot render. Without strict mode, document creation can fall back to the standard PDF design.
- Templates support placeholders, item loops, category filters, simple if blocks, math, money formatting, payment links, RTL/LTR output, repeated headers/footers, and page numbers.
- Templates block unsafe HTML such as scripts, iframes, forms, JavaScript event attributes, PHP tags, and untrusted external images.
Common Flow
- Load document permissions from User.Basic.
- Use Documents.List and Documents.Count for customer document screens.
- Use Documents.Products with customer_id for the customer Product tab line-item list.
- Use Documents.Sum for totals: customer_id + optional type/types + invoice_setting_id + from_date/to_date + include_drafts.
- Use Documents.View/Get with the saved document_id.
- Use Add/Edit/Delete only when the route help and permissions allow it.
- For custom PDF design, create and test the template in settings first, then use Documents.Add with pdf_template_id or rely on the configured default template.
Routes In This Category
Banks.CountBanks.GetBanks.ListDocumentStatuses.AddDocumentStatuses.CountDocumentStatuses.DeleteDocumentStatuses.EditDocumentStatuses.GetDocumentStatuses.ListDocumentStatuses.RemoveDocumentStatuses.ReorderDocumentStatuses.UpdateDocuments.AddDocuments.BusinessListDocuments.CountDocuments.DeleteDocuments.EditDocuments.ListDocuments.ProductsDocuments.SumDocuments.ViewDocumentsTemplates