# AxisCFO implementation examples

Synthetic demonstration data.

Two runnable examples turn source CSVs into checked financial outputs, a source-linked exception queue and compact reports. Node.js 20 or later is sufficient. The package uses Node built-ins and runs offline.

## Run

From the repository root:

```sh
node site/implementation-examples/2026-10-29/run.mjs --example payout-reconciliation --output site/implementation-examples/2026-10-29/outputs/payout-reconciliation
node site/implementation-examples/2026-10-29/run.mjs --example variance-reporting --output site/implementation-examples/2026-10-29/outputs/variance-reporting
node site/implementation-examples/2026-10-29/verify.mjs
node --test site/implementation-examples/2026-10-29/tests/*.test.mjs
```

After downloading the complete package, open a terminal in its folder:

```sh
node run.mjs --example payout-reconciliation --output ../axiscfo-generated/payout-reconciliation
node run.mjs --example variance-reporting --output ../axiscfo-generated/variance-reporting
```

Use an output directory outside the downloaded package when running `verify.mjs`: verification checks the exact distributed file list. An extra generated directory inside the package changes that list.

Custom inputs use the same four filenames and CSV columns as the selected example:

```sh
node run.mjs --example variance-reporting --input /path/to/source-directory --output /path/to/report-directory
```

Default inputs resolve relative to this module, regardless of the terminal's current directory. `--input` and `--output` resolve relative to the terminal's directory. Paths with spaces need shell quotes. A populated output directory is accepted only when it contains recognized generated files for the same example. A source directory or its ancestor cannot be used as output. Invalid financial inputs cause a nonzero exit and no output writes; a previous valid report remains intact.

Successful stdout is one JSON line with `example`, `reviewStatus` and `files`. Financial exceptions stay in the output and keep review pending. Invalid inputs produce a JSON error on stderr with `code`, `message`, and `issues`; exit status is 1. Invalid CLI arguments use status 2. `--help` describes the command.

Each artifact is written to a fresh sibling temporary file and renamed over its destination, preserving external hardlinked backups. Replacement is atomic per artifact. A handled write/rename failure removes only the temporary file created by this process.

## Payout reconciliation

The selected population is payouts **sent during September 2026**, with bank receipts included **through 3 October 2026**. This is a payout settlement reconciliation, not a September bank statement or a general ledger close.

Processor lines are signed: charges positive, fees and refunds negative. The original charge is required for each refund, and cumulative refunds cannot exceed it. Bank receipts are positive credits linked by exact `payout_id`; multiple credits may settle one payout. There is no fuzzy amount/date match, FX conversion, bank debit handling or fallback guess.

The example produces six payout rows:

| Finding | Result | Sources |
| --- | --- | --- |
| Straight amount/date match | P-1001: $970 | PO-01, TX-01, TX-02, BK-01 |
| Refund and duplicate | P-1002: $660; $100 refund included; TX-06 excluded as duplicate of TX-03 | PO-02, TX-03–TX-06, BK-02 |
| Partial receipt | P-1003: $1,455 declared, $1,200 received, $255 open | PO-03, TX-07, TX-08, BK-03, BK-04 |
| Source mismatch | P-1004: $485 processor net vs $480 declared and received | PO-04, TX-09, TX-10, BK-05 |
| Missing bank receipt | P-1005: $582 open after expected 25 September | PO-05, TX-11, TX-12 |
| Late receipt | P-1006: $776 received 3 October vs expected 2 October | PO-06, TX-13, TX-14, BK-06 |

The open declared balance is **$837**. The **$5** processor/declaration difference and **$250** unassigned bank credit remain separate. TX-15 is an unassigned processor transaction of **$200**. Five payouts need review; seven exception records explain the findings. Three payouts match by amount; the late receipt and duplicate still require review.

Identical business IDs with identical normalized fields retain the first source row and flag later rows. Conflicting duplicates stop processing. Source IDs themselves must be unique across every input. If a payout lacks processor lines, it cannot appear matched merely because bank and declaration agree. A future bank receipt is excluded as of the cutoff. A missing receipt before its expected date is pending; after that date it is overdue. Overpayment remains a negative open balance and a separate exception.

## Same-period contribution and variance

The plan and actuals cover **1–30 September 2026**. Plan amounts and cost deductions are positive; actual refunds are negative revenue rows. Contribution is:

`gross sales − refunds − product cost − fulfillment − platform fees − advertising`

Fixed overhead, tax, financing and working-capital timing are excluded. This contribution measure is neither net profit nor cash flow. Missing channel/category records stop processing; a confirmed zero needs an explicit zero source row. All six plan metrics must exist once per channel and cover exactly the same dates.

| Channel | Plan contribution | Actual contribution | Change |
| --- | ---: | ---: | ---: |
| DTC | $3,540 | $3,160 | −$380 |
| Marketplace | $2,000 | $1,520 | −$480 |
| Total | $5,540 | $4,680 | −$860 |

The bridge is +$400 gross sales, −$300 refunds, −$300 product cost, −$150 fulfillment, −$10 fees and −$500 advertising. These sum to **−$860**. The source-linked bridge explains arithmetic drivers; it does not establish their cause. RV-07 is August revenue of $900 and CT-09 is October advertising of $500; both are excluded and listed in the exception file.

Actual net revenue is **$19,100** and contribution margin is **24.50%**, using contribution divided by net revenue. Source fractions remain in JSON. Only the displayed margin rounds to the nearest basis point, half away from zero; cents remain exact. A nonpositive net revenue returns an explicit null margin rather than NaN or infinity.

## Financial and source controls

`expected/answer-key.md` and the two expected JSON files were written before implementation. They contain hand-derived expected sums and exception identities. Tests compare against those independent literals and include changed money, refunds, duplicates, missing records, dates, period mismatches, currency mismatches, malformed CSVs, overflow, source protection and tampered downloads.

All input amounts are safe integer cents. Sums use `BigInt` and stop if an output would exceed the safe integer range. No financial result depends on an AI response. Every result row, aggregate, bridge component, exception and control has `sourceIds`; `result.sources` resolves them to the input filename, physical CSV starting line and original fields. `calculationSourceIds` and `excludedSourceIds` distinguish the records used in payout amounts from duplicates retained for review. CSV reports also carry source IDs.

`verify.mjs` is read-only. It checks the complete download registry, byte sizes and SHA-256 hashes, reruns both examples, compares every generated output byte, checks the pre-code answer keys, and verifies that public KPIs/tables match the processed reports. It rejects stale sources, altered outputs, altered UI figures and unsafe asset paths. It can verify an extracted package with `node verify.mjs --root /path/to/package`.

The package demonstrates **read → structure → calculate → explain → review**. An implementation project may add AI-assisted document extraction or explanation with a configured provider. This local process uses deterministic rules and does not call an external model or API. Source completeness, mappings and exceptions still need review before operational use.

## Integration for AX-04

Read `interface.json` and `pack.json`. Copy the files in `pack.json.assets` under `/assets/implementation-examples/2026-10-29/`, preserving relative paths; copy `pack.json` itself too. The manifest excludes its own hash to avoid a recursive hash dependency. Its hash is included in the verification receipt and integration handoff.

`pack.json.examples` provides service routes, descriptions, workflow stages, review actions, result paths, KPIs and tables. Render money from `valueCents` or the table's cent-valued field by dividing by 100. Percent KPIs provide percentage `value`, `basisPoints`, and the exact `ratio`. `resultPointer` resolves against that example's `result.json`. Use its `dataNotice` once per displayed example. Preserve exception and source access on narrow screens. Browser rendering and download publication belong to AX-04.

To intentionally regenerate the distributed outputs and manifest after an approved input/code change, run both CLI commands above, then:

```sh
node site/implementation-examples/2026-10-29/refresh-pack.mjs
node site/implementation-examples/2026-10-29/verify.mjs
node --test site/implementation-examples/2026-10-29/tests/*.test.mjs
```

## Download inventory

The machine-readable registry in `pack.json.assets` contains every file below, its exact URL, role, MIME type, byte size and SHA-256.

| Role | Files, relative to this package |
| --- | --- |
| Reconciliation inputs | `inputs/payout-reconciliation/config.json`, `payouts.csv`, `transactions.csv`, `bank.csv` in the same folder |
| Reconciliation outputs | `outputs/payout-reconciliation/result.json`, `payouts.csv`, `exceptions.csv`, `report.md` in the same folder |
| Variance inputs | `inputs/variance-reporting/config.json`, `plan.csv`, `revenue.csv`, `costs.csv` in the same folder |
| Variance outputs | `outputs/variance-reporting/result.json`, `contribution.csv`, `bridge.csv`, `exceptions.csv`, `report.md` in the same folder |
| Expected answers | `expected/answer-key.md`, `expected/payout-reconciliation.json`, `expected/variance-reporting.json` |
| Runnable source | `run.mjs`, `index.mjs`, `finance.mjs`, `io.mjs`, `manifest.mjs`, `refresh-pack.mjs`, `verify.mjs` |
| Tests | `tests/finance.test.mjs`, `tests/io.test.mjs`, `tests/package.test.mjs`, `tests/review.test.mjs`, `tests/atomic-write.test.mjs`, `tests/helpers.mjs` |
| Documentation and manifest | `README.md`, `interface.json`, `pack.json` |

The first reconciliation command reads `inputs/payout-reconciliation/` and writes only the selected output directory. The variance command does the same for `inputs/variance-reporting/`. The exact source schemas are the CSV headers; `finance.mjs` also exports `SCHEMAS` for tooling. The stable public exports from `index.mjs` are documented in `interface.json`.
