5.5 KiB
EIB Processor — How It Works
EIB Processor — a small internal tool built by "Undo Designs" for Planeterra International Foundation. It converts a raw Equals Money card-spend export into Workday-ready Excel output, and can cross-check the result against bank/card statements to flag discrepancies before finance re-keys the numbers.
It's one tool hosted inside a small internal-tools platform — see CLAUDE.md for the platform-level architecture (landing page, tool registry, the Blueprint-per-tool convention). This doc is a deeper, narrative write-up of just the EIB tool itself, which lives at app/tools/eib/ and is served at /eib/.
Stack
- Backend: Python 3.11 + Flask Blueprint (
app/tools/eib/routes.pyfor request handling,app/tools/eib/logic.pyfor the actual data-processing/Excel logic — deliberately Flask-free), pandas/openpyxl for data wrangling. - Frontend:
templates/eib/index.html— a dark navy/cyan-themed single-page UI with drag-and-drop upload zones, no JS framework, plainfetch()calls polling a status endpoint for progress. - PDF parsing: a second container running Docling (
quay.io/docling-project/docling-serve), called over HTTP to OCR/convert PDF bank statements into markdown. - Storage: no database — everything is file-based (
/uploads,/outputs), plus two module-level dicts inroutes.py(PROCESS_STATUSfor progress polling,LAST_RESULTholding the most recently processed output) — both explicitly single-job/single-user shortcuts, not safe for concurrent runs.
Core workflow
- Upload a raw Equals Money
.xlsxexport. process_raw()classifies each transaction row (Card, Exchange, Cash withdrawal, Fee, Credit, Refund, etc.) using a fairly intricate rules engine that:- Drops non-expense rows (credits, refunds, internal FX "From" legs, auto-exchange).
- Collapses ATM cash-withdrawal + FX-exchange + fee row groups into a single clean "Cash withdrawal" / "Cash withdrawal fee" line.
- Maps raw merchant description strings to clean names via a hardcoded
MERCHANT_LOOKUPdict (~50 entries); anything unmapped halts processing and reports back to the UI for the merchant to be added manually.
- Optional audit, two modes:
- CSV mode (
run_audit): upload a combined card-statement CSV; per cardholder, checkssum(EIB Converted Amount) == sum(statement Total debited). - PDF mode (
run_audit_pdf): upload per-person PDF statements; Docling converts each to markdown,extract_balances_from_markdown()parses the opening/credit/debit/closing balance table, and a 4-layer audit runs (raw-vs-PDF totals → EIB value fidelity → structural "every excluded row is zero-impact" check → statement arithmetic identity), producing a much more detailed reconciliation with human-readable failure explanations.
- CSV mode (
populate_template()writesEIB_Processed[_Audited]_<date>.xlsxby loading finance's owneib_pre_template.xlsxand writing the processed rows into itsFinal Sheet(columns A:I), leaving finance's own corporate-card-ID lookup formulas (J:M) and a legacy block (N:Y) untouched, plus the audit table starting at column AA. The template file itself is never modified — every run saves a fresh dated copy. This is the file downloaded from the main "Download EIB File" button.populate_upload_template()— a second, on-demand output. A "Generate EIB File (for Upload)" button (shown after a successful run) reuses that same run's data to populateplaneterra_equals_cards_transactions_eib_v45.xlsx, the actual Workday EIB import template ("Expense Credit Card Transaction" + "Credit Card Transaction Header" sheets). Corporate-card identifiers here are resolved by readingeib_pre_template.xlsx's "Equals Card IDs" sheet directly, so both output files always agree on the same mapping without duplicating it.- Frontend polls
/eib/api/process/statusfor live progress text/log while processing runs, then offers both downloads.
There's also a diagnostic-only /eib/api/debug/probe-pdf endpoint that dumps raw Docling responses to outputs/_debug_markdown/*.PROBE.json for troubleshooting extraction logic, unrelated to the main flow.
The two bundled Excel templates
Both live in app/tools/eib/ and are tracked in git despite the repo's blanket *.xlsx gitignore rule (each has an explicit ! exception) — they're finance-owned reference files, not generated output:
eib_pre_template.xlsx— finance's working file. ItsFinal Sheethas our 9 output columns (A:I), finance's own VLOOKUP formulas resolving corporate-card identifiers per row (J:M, keyed off cardholder name against theEquals Card IDssheet), and a legacy static block (O:Y) that predates automation and is left alone. Populated bypopulate_template().planeterra_equals_cards_transactions_eib_v45.xlsx— the actual Workday EIB "Credit Card Transaction Header" + "Expense Credit Card Transaction" import template (fixed schema, Required/Optional/Format rows baked in). Populated bypopulate_upload_template().
Notable characteristics
- Heavily domain-specific: the transaction-classification logic encodes many real-world Equals Money quirks (ATM fee/exchange grouping, FX top-up over/under-funding detection, refund matching by description+amount+currency tuples).
- No auth, no database — designed as a trusted, local/single-user tool.
uploads/currently has dozens of leftover UUID-prefixed files from prior runs (PDFs, CSVs, xlsx) — this is working/scratch data, not part of the app itself.