How to build prepaid calculations using Claude

- You need
- Prepaid invoices with service start and end dates, as one CSV file
- Tested with
- Claude Sonnet 5.5, made-up data, 3 Nov 2026
- Result
- 180 of 180 schedule cells matched our reference program
Before you start
Spreading a prepaid invoice over its service months is often a spreadsheet job done by hand each month.
Writing a program for it used to need a developer who knew the policy. On 3 Nov 2026 we gave Claude six policy rules and one file, and it wrote the program.
The arithmetic is days. Take the amount, multiply by the days in the month, divide by the days in the service. Twelve invoices are easy.
A bigger file brings cases that our 12 invoices only sample: a three year retainer that crosses a leap day, invoices that arrive after the service has started, credit notes, service that begins next year, and several entities that each keep their own prepaid and expense accounts.
Some companies spread by whole months or half months instead of days, which changes the rules.
We would not run this in house at a mid size or large company. Prepaid schedules run on exceptions: the cancelled contract, the amended renewal, the invoice split across cost centres. Each one changes how the application behaves and needs somebody to decide the treatment.
The build took one session. We expect the upkeep to take longer: a new exception, a changed account code, a new close calendar, each needing the test run again. We did not test that. For the build or buy trade-off, read Build vs Buy: Finance AI Agents in 2026.
What you need
An ERP connection
The input is the list of invoices with a prepaid element, and the output is a schedule you post as journals. The hard part is the service dates.
Some ERPs hold a start and end date on the invoice line, and others keep them in a custom field, on the PO or in a contract. Find where yours live before you promise anything.
If your ERP has a mature, documented REST API for AP invoices and journals you can build the read and the posting yourself. Check its API terms before you connect an AI tool to it.
ChatFin's build or buy page says ChatFin runs on the ERP and version you already have and writes back only drafts that a person approves through the official API. Our script used a CSV file and posts nothing.
The data points
| Column | What the script does with it |
|---|---|
invoice_id | Row key. Must be unique |
invoice_date | Decides the invoice month and when a balance starts |
amount | Negative for a credit note |
service_start, service_end | Both days count as service days |
vendor, description, expense_account, prepaid_account | Must be present. The script ignores them |
A plan, broken into steps
Attach prepaid_invoices.csv and paste this. The policy is in the prompt, and Claude still had to assume several things.
I work in the accounting team. I want a small tool that works out our prepaid expenses. I have one file, prepaid_invoices.csv (invoice_id, vendor, description, invoice_date, amount, service_start, service_end, expense_account, prepaid_account). Each row is a vendor invoice for a service we pay for in advance. For every invoice the tool should give me the expense for each month of 2026 (January to December), and the prepaid balance at 1 Jan 2026, at 31 Oct 2026 and at 31 Dec 2026. Our policy: 1. Spread each invoice over its service period by days. A month's expense is the amount times the days of service in that month, divided by the total days of service. 2. Round each month to the cent. The last month of the service takes whatever is left, so the months add up to the invoice exactly. 3. An invoice under 1,000 in absolute value is not prepaid. Expense all of it in the month of the invoice date. 4. If the service started before the invoice date, the months before the invoice month are expensed in the invoice month. 5. The prepaid balance at a date is the invoice amount minus the expense recognised up to that date. Before the invoice month there is no balance. 6. Credit notes are negative invoices and follow the same rules. Do not write code yet. Break the job into numbered steps. For each step say what could go wrong. Then list anything in the policy that is unclear.
Claude answered with ten steps.
Four of them carry the job: count service days with both end dates included, so 1 Jan to 31 Dec 2026 comes to 365; split the days by calendar month over the whole service period, not only 2026; move months before the invoice month into the invoice month; and work out three balances from the invoice amount minus the expense so far.
For each step it said what could go wrong.
For the day count it gave its own check: PP-001 runs 1 Jan to 31 Dec 2026 and has to come to 365 days.
It also listed ten points where the policy is silent. Several changed a number, and three are below:
- Does "under 1,000" include 1,000? Claude read it as strictly under, and by absolute value.
- When months before the invoice month are folded into the invoice month, are they rounded one by one or as a lump? Claude rounded each month, then added.
- Is the balance at 31 Oct before or after October's expense? Claude took it after, since 31 Oct is a month end.
Open for your controller. We did not answer them. We told Claude to use its plan and it applied its own reading of each. A one cent question in rule 4 is below. Your controller settles these before you rely on the output.
Ask Claude to build it
Good. Use that plan. Write one Python script, standard library only, that reads the file and writes prepaid_schedule.csv with one row per invoice: invoice_id, the twelve monthly expense columns named 2026-01 to 2026-12, opening_2026-01-01, balance_2026-10-31 and balance_2026-12-31. Use exact decimal arithmetic for money. Never change my file. Run it, then show me the total prepaid balance at 31 Oct 2026, and the row for any invoice where the service starts after 31 Oct 2026 or the invoice is under 1,000.
Claude Sonnet 5.5 (claude-sonnet-5-5) ran both prompts in Claude Code on 3 Nov 2026, in one session that held both messages and played the two turns in order.
We did not run them in the chat app. The result was a 214 line Python script, standard library only, with money in Decimal. It read 12 invoices and wrote one row each.
The total prepaid balance at 31 Oct 2026 came to 67,454.84, against 31,180.28 at 1 Jan and 51,971.24 at 31 Dec. Claude showed three of these rows (PP-005, PP-006 and PP-012). We added PP-007 and PP-010:
| Invoice | What is special | Balance | What the schedule did |
|---|---|---|---|
| PP-005 | Invoiced 5 Oct, service starts 15 Nov | 12,000.00 at 31 Oct | Full amount on the balance sheet at 31 Oct. November gets 16 of 365 days, 526.03. |
| PP-006 | 800.00, under the 1,000 limit | 0.00 at all three dates | All 800.00 expensed in May, the invoice month. |
| PP-007 | Exactly 1,000.00 | 328.78 at 31 Dec | Treated as prepaid. The policy says "under 1,000", so 1,000 is not under. |
| PP-010 | Credit note, -2,000.00 | -334.28 at 31 Oct | January's share lands in February, -323.28, and it pulls the 31 Oct total down. |
| PP-012 | Invoiced 30 Sep, service starts in 2027 | 15,000.00 at 31 Oct and 31 Dec | Nothing expensed in 2026. |
Claude also pointed out the cent. The credit note PP-010 has January's share moved into February. Rounded month by month, February is -323.28. Rounded as one lump it would be -323.29. The policy does not say which, and the answer is yours to choose.
Where to run it
This is a monthly job on a file you hand it, so a laptop is enough to start.
To use it at close you need it scheduled, reading invoices from the ERP, writing the schedule where the accountant reviews it and producing a journal that someone approves. A hosting service such as Vercel is one option. Nothing here was hosted.
If you would rather buy it
ChatFin's build or buy page says it runs on the ERP and version you already have, with no database credentials and no migration. We did not run this policy through ChatFin. ChatFin also has a page titled Rolling Forward Prepaid Schedules Without a Single Formula.
Test it before you trust it
1. Check the arithmetic against a second implementation
For this process the right answer is a calculation, so we wrote our own reference program from the same six rules and used its output as the key. Claude's schedule matched it in all 180 cells: 12 invoices, 12 months and three balances.
We did not give Claude the reference. The reference shares our readings of the policy, and the file's descriptions hint at its edge cases, so this is an easier match than a real file would give.
Same authors. A match means two programs agree on the policy as we wrote it. It does not tell you whether the policy is right, and the reference is ours.
2. Try the boundaries
We sent single invoices on the edges of the policy and compared each with the reference.
| What we sent | What the script did |
|---|---|
| A 1,000.00 invoice, and 999.99, -999.99 and -1,000.00 | The limit works on the absolute value, and 1,000 itself is prepaid |
| Service for one day | Whole amount in one month |
| Invoice dated after the service ended | Everything expensed in the invoice month |
| Invoice dated 1 Nov for service that started in August | No balance at 31 Oct, the catch-up lands in November |
| A three year service that includes 29 Feb 2028 | Same as the reference, to the cent |
| Service that started in 2024, invoiced in 2026 | Same as the reference, to the cent |
| Invoice dated in 2027 | Nothing in 2026 and a zero balance |
All thirteen cases matched the reference. The table covers ten of them. The others were an invoice dated 31 Oct, a leap day inside the service and a half cent.
We then made 3,000 invoices with random amounts, dates and service lengths, credit notes included. The script took under a second and matched the reference on every row.
3. Feed it bad data
| What we sent | What the script did |
|---|---|
| Service end before service start | Stopped, "line 2: service_end is before service_start", no output file |
Blank amount, 5,000.00 with a comma, or $5000.00 | Stopped, names the line and the amount, no output file |
Date written 01/03/2026 | Stopped, names the line and the date |
| The same invoice_id twice | Stopped, "invoice_id X5 appears more than once" |
| An amount of 0.00 | Accepted, zero in every column |
That was seven bad files. Six stopped the run at the line with the problem, and none of those wrote an output file. The zero amount went through as a row of zeros. Decide whether a zero invoice should stop the run, then add it to the prompt.
4. Take the choices to your controller
The policy says nothing about an invoice that is cancelled midway, a service period amended after posting, or foreign currency. Add what you want to the prompt and run the same test again.
Where ChatFin fits
The script does the part that is arithmetic. A close needs the other parts too: reading invoices and service dates from the ERP, a screen where the accountant reviews the schedule, a posted journal that a person approves, and a record of who changed what.
ChatFin's own build or buy page lists the governed connection, the approval workflow and an audit trail from prompt to prepared payload as what you get when you buy (Build vs Buy: Finance AI Agents in 2026).
ChatFin also has a page titled Prepaid Expense Amortization: Schedules and Entries.