# Canadian finance workflows by Flowgrammer

Version 1.0.0 · 29 October 2026 · Free original templates · MIT licence

These are importable n8n workflows with deterministic review logic, a private PostgreSQL queue, and optional approved delivery. They are setup-required starting points. They have not been run against your n8n instance, live books, SMTP server, or source applications. They do not perform OCR, retrieve Gmail attachments, synchronize bank feeds, calculate payroll deductions, determine tax eligibility, file returns, or pay bills. Supply reviewed structured exports through the input contract below. No AI service receives records.

## Package contents

| File | Purpose |
|---|---|
| 01-invoice-review.json | Check extracted invoice/receipt fields and calculate Canadian standard-rate tax; optionally prepare a sales invoice for QuickBooks or Xero |
| 02-overdue-reminders.json | Prepare reminders from outstanding CAD invoices at 3/7/14 days; respect disputes, suppression and recorded reminder history |
| 03-missing-documents.json | Compare an approved tax-year checklist with received documents; prepare a secure-portal request |
| 04-reconciliation.json | Propose matches by reference, date and amount; flag ambiguous or missing matches |
| 05-payroll-checks.json | Flag duplicate identifiers, unusual gross pay and hours inconsistencies; review only |
| 06-financial-report.json | Summarize reviewed CAD revenue, expenses, budget variance and a simple tax-reserve estimate |
| 07-deadline-alerts.json | Prepare alerts from a reviewer-confirmed date and authority URL; no inferred CRA deadlines |
| 08-timesheet-reminders.json | Prepare reminders for missing timesheets after a confirmed period end |
| 9/10/11 approved dispatch | Deliver one separately approved QuickBooks invoice, Xero draft, or SMTP reminder per manual execution |
| 12-error-alert.json | Notify an internal owner when a linked production workflow fails |
| queue.sql | Private queue, immutable prepared results, audit history, approval and atomic dispatch functions |
| sample-inputs.sql | Synthetic inputs for all eight preparation workflows |

## Install and test

1. Use an isolated test PostgreSQL database and a supported n8n instance with Code, Set, Schedule Trigger, Postgres v2, HTTP Request, Wait and Send Email nodes. Import each JSON separately through n8n's **Import from file** command. Leave them inactive. Inspect node-version compatibility in your installed n8n release before testing.
2. Run `queue.sql` once as the database administrator in that private database. It deliberately fails on an existing schema/role rather than overwriting anything. Do not run it in the Flowgrammer website database or a public Data API schema. The package creates two NOLOGIN group roles; create distinct login users with passwords in your own secret manager. Grant `fg_finance_runner` to the n8n login and `fg_finance_reviewer` to the human reviewer login. Do not grant admin, table-owner, reviewer, or schema-create rights to the runner. Use a separate database and runner login per client. Restrict network access and use TLS.
3. Connect the runner's n8n Postgres credential to every Postgres node. Credentials stay in n8n; none are shipped. Load `sample-inputs.sql` using the database administrator. Source adapters insert normalized input rows using their own restricted ingestion login; do not grant ingestion or review privileges to the runner.
4. Configure the **Settings** node in each workflow you import. Keep `dry_run: true` and `dispatch_enabled: false`. Set the client ID consistently. Generate a UUID once for this client database and set `idempotency_namespace` to it in all dispatchers; keep it stable across reruns and unique across databases. Set the province, tax components, inclusive/exclusive flag, reviewed date window, thresholds, cadence and file limits. Set the actual internal error recipient and sender in the error workflow. Replace example addresses before activation. The workflows and date logic use `America/Toronto`; if changing it, change both Settings and workflow timezone and retest DST/date boundaries.
5. Run preparation workflows manually against synthetic inputs. They write decisions and audit rows to the isolated database, including in dry run, but send or post nothing. Inspect `fg_finance.decisions` and `fg_finance.audit` using the reviewer login. A malformed item becomes an exception without stopping valid items. A database outage stops the workflow; it must not be treated as success.
6. Import and save `12-error-alert.json`, attach its SMTP credential, configure its Settings, then select it in **Workflow Settings → Error workflow** on each of the other eleven imports. IDs are generated by your instance, so this link cannot be preassigned in a portable download. Test a deliberate failure in an activated test workflow: n8n's automatic error workflow is not triggered by ordinary manual test runs. Monitor n8n failures separately if SMTP or the error workflow itself fails.
7. Before live use, connect your own source adapters and map their exports into the documented payloads. The sample loader is not a production connector. Use client-approved document access, retention, secure upload, and logging policies. Verify the actual file bytes, MIME signature and page count in the source adapter before extraction. The metadata check here is a second check, not a file scanner. Keep SINs, bank numbers and document contents out of alerts and ordinary logs.
8. Test in QuickBooks sandbox or a Xero demo organisation and a test SMTP inbox. Check the imported nodes' parameters, tax codes, line rounding and authentication. Run failure, duplicate and concurrent-dispatch tests. Only then change preparation `dry_run` to false. Existing dry runs do not suppress live preparation. Production schedules remain inactive until you enable them deliberately.

## Human approval and delivery

The runner cannot approve rows. A separately authenticated reviewer checks the source document, date, tax treatment, exact body, destination tenant, contact/customer and current outstanding balance. All outbound reminders, including final notices, require approval. Payroll and reconciliation remain review-only. To correct an immutable decision, have the database administrator reject it with an audited reason and submit a corrected input; never change a previously approved body in place.

Using the separate reviewer login, inspect a pending row and approve its exact stored result:

```sql
SELECT id, client_id, status, result FROM fg_finance.decisions WHERE status='pending';
SELECT fg_finance.approve(123, 'Checked original invoice, tax code, tenant and totals; source is current.');
```

Approval expires after 24 hours if unclaimed. Review stale approvals again. Delivery workflow Settings must have `dry_run: false` and `dispatch_enabled: true`. Connect the corresponding QuickBooks OAuth2, Xero OAuth2 or SMTP credential, then execute the appropriate dispatcher manually. It atomically reserves **one** approved item per run and waits between deliveries. A second concurrent run cannot claim the same row. Preparation batch size is capped at 100. Run dispatcher manually again for the next approved item; no send loop is hidden in the package.

QuickBooks delivery creates a **sales invoice**, not a supplier bill or payment, and does not email it. It defaults to sandbox. Customer, product/service item and Canadian tax-code IDs are organisation-specific; configure them before preparing the invoice. Xero delivery creates an **ACCREC DRAFT** with explicit account and tax type; verify those codes in your organisation. A receipt intended as an expense stays `destination: "review"`; do not map expenses to sales invoices. Match returned provider totals against the approved source before releasing anything further.

Database operations and internal error email use bounded retries. Ledger writes and customer email deliberately do not retry automatically. Each claimed decision changes to `dispatching` **before** the external request. A timeout, crash or missing acknowledgement is `uncertain` (or stays `dispatching` if the run stops before recording the outcome). Inspect all dispatching rows older than five minutes and all uncertain rows. Reconcile them against the destination before an administrator records a resolution. Never reset and replay blindly. Provider keys (client database UUID plus decision ID) add protection; they do not replace reconciliation or guarantee exactly-once delivery. SMTP partial acceptance is uncertain. Update the source reminder history after confirmed delivery before ingesting further snapshots.

## Canadian tax settings

Rates checked 29 October 2026. Default reviewed transaction window: calendar 2026. These settings calculate standard-rated examples only. A qualified reviewer must confirm registration, place of supply, effective date, product/service taxability, exemptions, zero-rating, special rules and input-tax-credit eligibility. The client's office province does not by itself determine the transaction's tax. PST provinces are held for custom review in this version. Historical/future transactions outside the reviewed date window stop for review.

| Province/territory | `tax_components` | `tax_regime` label |
|---|---|---|
| Ontario | `[["HST",0.13]]` | HST-ON |
| Nova Scotia | `[["HST",0.14]]` | HST-NS |
| New Brunswick, Newfoundland and Labrador, Prince Edward Island | `[["HST",0.15]]` | HST-NB / HST-NL / HST-PE |
| Québec | `[["GST",0.05],["QST",0.09975]]` | GST-QST |
| Alberta, Northwest Territories, Nunavut, Yukon | `[["GST",0.05]]` | GST |
| British Columbia, Saskatchewan, Manitoba | Held for accountant-reviewed PST rules | Custom review |

QST is calculated on the selling price excluding GST. Example: CAD 100 before tax in Québec gives GST 5.00 and QST 9.98 with this package's per-line cent rounding, total CAD 114.98. Inclusive amounts are backed out using the combined applicable rate, then components are rounded independently. A discrepancy greater than `amount_tolerance_cents` goes to exceptions. Source-document and provider rounding can differ; reconcile them. Non-CAD records are rejected, not silently converted. Mixed rates, rebates, discounts, credit notes and negative transactions require a custom mapping. `tax_regime` is a display label; `tax_components` drives the calculation and is validated against the supported province.

## Input contract

The administrator or a restricted source adapter inserts `client_id`, `kind`, `source_id`, `revision` and a JSON `payload` into `fg_finance.inputs`. Use immutable IDs from the source and a stable revision or event ID. Replaying identical identity fields is rejected by the database. Use one reminder input per source invoice snapshot; stage keys suppress repeat reminders across revisions. Use a source ID unique to the tax-year/checklist cycle, pay period, report period or filing obligation for the other kinds. Do not reuse a source ID for unrelated periods. Inputs for all eight kinds are included in `sample-inputs.sql`.

Amounts are numeric dollars, nonnegative, at most CAD 1 billion per value; dates are `YYYY-MM-DD`; money calculations use integer cents. Financial-report row fields are `revenue`, `expense`, `tax_collected`, `tax_paid` and `budget`. The reserve is a simple estimate, not net tax payable. Reconciliation assumes positive, same-direction amounts and exact reference/date matching; split, refund and FX matches need human review. No AI model decides tax, approval, collection escalation or ledger posting.

## Sources and provenance

- CRA rates: https://www.canada.ca/en/revenue-agency/services/tax/businesses/topics/gst-hst-businesses/charge-collect-which-rate/calculator.html
- Revenu Québec GST/QST: https://www.revenuquebec.ca/en/businesses/consumption-taxes/gsthst-and-qst/basic-rules-for-applying-the-gsthst-and-qst/
- n8n error workflow setup: https://docs.n8n.io/build/flow-logic/handle-errors-gracefully.md
- Intuit invoice API: https://developer.intuit.com/docs/api/accounting/invoice
- Xero invoices: https://developer.xero.com/documentation/api/accounting/invoices
- Xero idempotency: https://developer.xero.com/documentation/guides/idempotent-requests/idempotency/

These original files were written from Flowgrammer's requirements and official documentation. The 25 October review of 23 community templates informed the requirements; their source JSON is not redistributed. Verification receipts are retained in the site's `docs/n8n-canadian-finance/` folder. Import and provider execution validation remain environment-specific acceptance steps.
