Post #11 Companion — The CFO & AI Series

The Agent That Ranks Which Invoice
Gets Paid First

A small script that scores each open invoice by more than its due date — and prints the payment order it actually suggests, before anyone works through the pile by hand.

Boris Dračka · September 2026 · Companion demo

This is a personal, non-commercial side project I put together to learn — not a product or service, and not connected to any company I work with.

Post #11 asked a simple question: if payment order isn't really decided by due date, what else is doing the deciding — and can a rule capture it? Below is a small prototype that answers that with sample data.

8
Sample invoices scored
2 of 8
Reordered ahead of an older invoice because of a critical-vendor flag
€8,750
Invoice kept near the front for a 2%-in-10-days discount most payment runs miss

The script doesn't decide who's important. It just writes down, in one place, the same signals someone was already weighing invoice by invoice — a due date, a discount window, a flag for a critical vendor.

The sample data

Eight open invoices, each with a due date, an amount, whether a discount applies, and whether the vendor is flagged as critical. Two of them move ahead of an older invoice once those signals are counted.

  open_invoices.csv — sample data
IDVendorAmountDue inDiscountCriticalRankStatus
INV-03Freight Carrier€8,7501 day2%/10No1
INV-07Utility Provider€1,8502 days—No2
INV-01Packaging Supplier€12,4003 days—No3
INV-06Marketing Agency€5,1004 days—No4
INV-05Contract Manufacturer€41,0006 days—Yes5
INV-02Core SaaS Platform€3,2009 days—Yes6
INV-08Legal Services€9,30011 days—No7
INV-04Office Supplies€64014 days—No8
Sorted by printed due date

How it works

1
Load the invoicesReads a CSV with one row per invoice: vendor, amount, due date, discount terms, critical-vendor flag.
2
Compute days to dueFor each invoice, calculates how many days remain until the printed due date.
3
Apply priority signalsChecks two overrides: an active early-payment discount window, and a critical-vendor flag.
4
Re-rank the queueInvoices carrying a priority signal move to the front; everything else keeps its due-date order.
5
Print the suggested runLists the invoices in suggested payment order, flagging which ones moved.

Try it yourself

1 — Clone the repository

# same personal, non-commercial repo as the earlier demos in this series git clone https://github.com/LuliBobo/cfo-agents.git cd cfo-agents

2 — Add your own invoices (optional)

invoice_id,vendor,amount,due_in_days,discount_terms,critical_vendor INV-05,Contract Manufacturer,41000,6,,true INV-02,Core SaaS Platform,3200,9,,true # ...add as many rows as you have open invoices

3 — Run it

python invoice_priority_agent.py data/open_invoices.csv

4 — Read the output

================================================================ Invoice Priority Agent — Suggested Payment Order ================================================================ [Step 1] Loaded 8 open invoice(s) from CSV [Step 2] Calculated days-to-due for each invoice [Step 3] Checking for discount windows and critical-vendor flags INV-05 Contract Manufacturer 41,000 due in 6d CRITICAL ⚠ REORDERED → #1 INV-02 Core SaaS Platform 3,200 due in 9d CRITICAL ⚠ REORDERED → #2 [Step 4] 2 of 8 invoice(s) reordered ahead of an older invoice [Step 5] Suggested payment order printed above — due-date order alone would have missed both

What it's built from

Data source

A plain CSV of open invoices — no ERP connection, no live banking access, nothing beyond sample data.

Calculation

Standard Python, no external dependencies — a days-to-due calculation and two flag checks.

Configurable signals

Which flags count as "critical" and the discount threshold are command-line arguments, not hardcoded.

Read-only by design

The script only reads and reports. It doesn't schedule or send a single payment on its own.

What's in the repository

The same personal, non-commercial repository as the earlier demos in this series:

View on GitHub Back to Post #11

Follow the series

Post #12 moves to the other side of that same ledger: money owed to the company, and why some collection reminders get paid within days while others get ignored for months.

Subscribe free
No spam. One post per week. Unsubscribe any time.