# Rehearse a billing migration

> Validate a legacy export, re-bill closed cycles locally and trace differences between legacy invoices and telco in the Desk.


A legacy invoice and its telco equivalent can have the same total even when two charges differ. In the worked November invoice, €3 moves between the base charge and the router. The gross total stays at €30.35. Use the shadow run to find those changes before deciding whether to switch systems.

## Run the example

Run these commands from a checkout with the telco CLI installed. The example covers one account and two closed cycles, with a pinned fibre tariff, usage, prior charges and opening financial controls.

```sh
telco migration validate samples/migration/package.json
telco migration shadow samples/migration/package.json > shadow.json
telco migration verify samples/migration/package.json shadow.json
telco migration reconcile samples/migration/package.json samples/migration/register.json > control.json
```

Open **Umstieg** in the Desk and select `shadow.json`. The report is processed in the browser. Select an account and period to see the old and calculated net, VAT and gross amounts, then inspect individual lines. A missing legacy invoice has its own status. A missing mapping needs investigation even if the invoice total agrees.

## Check the invoice population

Ask finance for the issued-invoice register from the legacy billing system, using the same cutoff, cohort and months as the migration snapshot. Export it separately. Generating it from the migration package would repeat any omissions in that package.

Open `control.json` alongside `shadow.json` in **Umstieg**. November’s source register has one invoice for €30.35 and December’s has one for €29.97. Both headers agree with the snapshot. The €3 November line differences still need their own review. [Sample shadow report](../examples/migration-report.json) · [Sample register](../examples/migration-register.json) · [Sample control](../examples/migration-control.json)

| Exit | Result |
|---:|---|
| 0 | Every expected account and period has matching legacy invoice identity, net, VAT and gross. |
| 1 | The result identifies affected months and counts. Use `telco migration reconcile package.json register.json --details > findings.json` in the restricted working directory to locate the account and invoice keys. |
| 2 | The input was refused. Check its format, source, snapshot, periods and duplicate identifiers. |

Monthly totals can agree despite offsetting errors. Reconciliation checks each account-period individually. A zero invoice requires an issued document with zero amounts. If both exports omit an account outside the declared cohort, only the source owner can identify that omission.

## Prepare an operator export

Use opaque source IDs for customers, accounts and subscriptions. Include the original dated tariff assignments, the usage from the period billed in arrears and the charges already billed in advance. The rating engine uses these prior charges when composing corrections. Keep the exact input bytes, including the tariff files, in the operator’s restricted working directory. The report contains account references and financial data. [Package format](../docs/migration-format/) · [Synthetic package](../examples/migration-package.json)

`validate` checks cross-record references, date ranges, monetary controls and tariff hashes. A failure returns a nonzero exit code and JSON diagnostics. Use the record type, source identifier and field to locate the source problem. For an invalid JSON document or a value of the wrong type, start with the reported line and column.

## Review the differences

- **Amounts** are in EUR. A positive line delta means telco calculates a higher gross charge. Inspect net and VAT even when gross agrees.
- **Mapping** connects the legacy item and VAT rate to a rated line. Supply a specific charge ID where multiple lines share that pair. Keep unmatched and ambiguous items visible until the operator has evidence for a mapping.
- **Corrections** depend on what was already billed. A second cycle can expose a wrong prior charge even when the current plan price agrees.
- **Residual** is the invoice gross difference less the sum of reported line differences. Investigate a nonzero residual before relying on the comparison.

The CLI includes the snapshot’s SHA-256 and compiled tariff hashes in the report. `verify` recalculates the comparison using the exact package and checks the saved report against it. Preserve the original generated report when recording review notes separately. Successful verification establishes reproducibility. The operator still needs to establish the provenance of the original export.

## From rehearsal to cutover

The rehearsal commands issue no invoices, post no balances and reserve no numbers. Once the operator has reviewed the differences, the deployment tool accepts a separate approval for a named destination. [Cut over to the first live invoice](../docs/cutover/)
