# Invoice sync - ops handover Version 0.9.1 · Written 2026-10-23 · Escalation: raise a ticket in the **RPA Support** queue ## 1. What the bot does Every hour, the bot takes the approved invoices in the finance export file (`data/input/invoices.csv`) and creates each one in the billing system through the billing system's web API. It has no window and drives no desktop app or website. It only talks to the billing API in the background. For each run it writes one report file to `data/output/`, with one line per invoice saying what happened to it. ## 2. How it works ``` Windows Task Scheduler (every hour) └─ starts → Invoice sync (no window) ──sends each invoice──> Billing API │ ├─ reads → data/input/invoices.csv ├─ writes → data/output/sync_report_.csv (ops can open) └─ writes → logs/sync.log (dev only) ``` - **Windows Task Scheduler** starts the bot at the top of every hour. Nobody clicks anything. - **Invoice sync** is a background program. It has no screen. - **Billing API** is the billing system. Invoices the bot creates appear there. - **The input file** is the finance export. The bot never moves or empties it, so every run reads the whole file again. - **The report file** is the only record ops can open. Each run makes a new file, named after the date and time the run started, for example `sync_report_20261023_1400.csv` for the 14:00 run. - **The log** holds one line per invoice (number and status only) plus an end-of-run line. Ops has no access to it. **One run, step by step:** 1. Task Scheduler starts the bot. 2. The bot creates a new, empty report file in `data/output/`. 3. For each line of the input file, in order: 1. It checks the line: invoice number, customer ID, amount and currency must be filled in, and the amount must be a number above 0. If the line fails the check, the bot marks it **Invalid** and moves on without sending it. 2. It sends the invoice to billing. 3. If billing gives no clear answer, it asks billing "does this invoice exist now?". If yes, it marks the invoice **Synced**. If not, it waits and tries again, up to 5 times (section 8). 4. It writes the result as one line in the report. 4. When every line is done, it writes "run done" to the log. Ops cannot see this. To check a run finished, see section 5. ## 3. Before a run - [ ] The folder `data/output/` exists next to the bot. **The bot does not create it.** If it is missing, every run stops at once and no report appears. - [ ] The folder `logs/` exists next to the bot. If it is missing, the bot stops at once. - [ ] The settings file (`.env`) with the billing address and key is next to the bot. If it is missing or the key has expired, every invoice ends **Failed** after about a minute of retries each (E09). - [ ] The input file is at `data/input/invoices.csv` and keeps its header line exactly: `invoice_no, customer_id, customer_name, amount, currency`. - [ ] Input rules, one line per invoice: | Field | Rule | Bad | Good | |---|---|---|---| | invoice_no, customer_id, currency | Must not be empty | (blank) | `INV-1001` | | amount | A plain number above 0. No currency sign, no thousands separator. | `$1,200.50`, `0`, `-5` | `1200.50` | | File format | Save as **CSV UTF-8** without the "BOM" marker. Some Excel "CSV UTF-8" exports add an invisible marker at the start, and then **every** line comes back **Invalid - missing invoice_no** (E04). | Excel "CSV UTF-8" with marker | Plain CSV / UTF-8 without marker | - [ ] Only one copy of the bot is scheduled. Nothing stops two runs from overlapping (section 4). ## 4. During a run - There is nothing to watch. The bot has no window. Leave the input file alone while a run is going. Don't open it in Excel and save over it at the top of the hour. - **To stop the bot:** whoever has access to the bot machine ends the "Invoice sync" task in Task Scheduler, and disables it to stop future runs. Ops has no access to that machine, so raise a ticket. Stopping mid-run is safe: invoices already created come back as **Duplicate** on the next run, not as second copies. - **A run looks stuck or unfinished when:** - the newest report has fewer lines than the input file (not counting the header) more than an hour after it started, or - no new report appears for an hour. - The bot has no watchdog. Each invoice can take up to about **6 minutes** when billing is slow or down: 5 tries, each waiting up to 30 s to send and 30 s to check, plus 62 s of pauses. A run that is behind can still be going when the next hourly run starts. Both then write their own report. ## 5. Where to look when something goes wrong Ops can open only the `data/output/` folder and its report files. The bot has no screens. | Question | Where to look | |---|---| | Did the run start? | `data/output/` has a `sync_report__