Multi-file upload (auto-classifies each uploaded file as revenue or
expense by column headers - "Revenue Category" vs "Spend Category" -
so the order doesn't matter), with a clear prompt if only one file is
uploaded or a role is duplicated/unrecognized.
- logic.py: process_revenue()/process_expense() share one
_process_side() implementation (revenue flips sign, expense doesn't -
expense accounts are already debit-normal). EXPENSE_ACCOUNT_CODES
covers all 19 P&L expense accounts (68010-82000), not just the
"Disbursements to Projects" ones - real per-donor Project attribution
turned out to be present across nearly all of them (salaries, travel,
currency gain/loss, etc.), confirmed against the actual sample data.
full_file_balance() checks each uploaded file's raw, unfiltered total
nets to ~zero - a basic trial-balance integrity check independent of
the revenue/expense filtering - and blocks processing if not.
- Donor sheets now write both Revenue and Expenses sections (same
Account -> SLOB -> Category -> Subtotal hierarchy for both), and
every subtotal/total/surplus cell is a real Excel SUM/subtraction
formula rather than a precomputed value, so the numbers are
auditable directly in the workbook.
- Fixed a latent bug found while adding the Expenses section: the
previous row-insert logic could leave a stale duplicate "Total
Revenue" label when a donor had fewer lines than the template
reserves. _adjust_block() now inserts OR deletes rows symmetrically
so the template's own total labels always land exactly where
expected - no more relying on need >= the template's reserved slack.
- routes.py: /api/process now accepts trial_balance_file_0.. (multiple),
classifies each by its columns, and returns total_revenue,
total_expense, and surplus_deficit alongside the existing donor count.
- templates/donor_report/index.html: multi-file drop zone (mirroring
the EIB tool's PDF upload pattern) and two more stat boxes (Total
Expense, Surplus/(Deficit), red/green colored).
- Added "Easyjet" (lowercase) to the donor merge map - a variant not
present in the revenue file, found only once the expense file was
processed.
Verified end to end: every SLOB subtotal, Total Revenue, Total
Expenses, and Surplus/(Deficit) formula in the generated workbook was
independently re-evaluated (recursively resolving formula-to-formula
references) and cross-checked against the API's reported totals -
exact match on all 12 donor sheets and the grand total
(revenue 4,384,170.35 / expense 3,611,064.64 / surplus 773,105.71).
Also verified the zero-revenue and zero-expense edge cases produce no
duplicate total labels.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
New Blueprint at app/tools/donor_report/ (registered on the platform
home page), following the eib tool's conventions:
- logic.py: parse_project() splits "<Company> - <SLOB> - <Donor...>"
with the join-back fix for hyphenated donor names; donor merge map is
a bind-mounted CSV (donor_merge_map.csv, same pattern as
merchant_lookup.csv) covering the confirmed G Adventures/EasyJet/
TruTravels/IGF spelling variants. Per stakeholder direction, any row
with no real donor segment (blank Project, or a 2-part Project with
no donor at the end) and any row whose donor segment is literally
"General" both collapse into one unified "General" report.
- Aggregation groups to (donor, account, slob, category) and sums -
since this is a trial balance, groups that net to exactly zero are
real (reclassifications, offsetting entries) rather than bugs, so
they're simply not displayed rather than needing special-case
duplicate detection. Verified the grand total across all donors
matches summing the raw filtered rows directly.
- build_donor_workbook() copies report_summary_template.xlsx per donor,
expanding the template's fixed 5-row detail area via insert_rows() to
fit each donor's actual row count (1-30+), writing Category -> SLOB
subtotal -> Account header -> Total Revenue, with the Expenses
section shifted down accordingly and left unpopulated per the current
scope (revenue only).
- routes.py: /donor-report/api/process (single synchronous call, no
progress polling needed - unlike the eib tool there's no slow
external step) and /api/download/<filename>.
- templates/donor_report/index.html: single-upload page in the same
theme as the platform shell.
Verified end to end against the real sample trial balance: 10 donor
sheets generated, all merge-map variants resolved correctly, no empty
sheets for accounts that fully net to zero, and the total revenue
figure matches an independent manual calculation from the raw file
(4,384,170.35).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
MERCHANT_LOOKUP was a hardcoded dict in logic.py, so adding a merchant
meant editing Python and rebuilding the Docker image just to add one
row of data. Replaces it with:
- app/tools/eib/merchant_lookup.csv (raw_description,clean_name),
bind-mounted in docker-compose.yml so edits (by hand or via the app)
take effect on the next run — no rebuild, no restart.
- logic.py: _load_merchant_lookup() reads it fresh on every
process_raw() call; add_merchant_mappings() rewrites it with new
entries merged in.
- routes.py: new POST /api/merchant-mappings endpoint.
- templates/eib/index.html: the unmapped-merchant panel is now a form
(raw name -> editable clean-name input per merchant, prefilled with
the raw name) with a "Save & Continue Processing" button. Saving
posts the mappings, then automatically resubmits the same in-browser
File object to /api/process — no re-upload needed to resume.
Verified end to end: removed a known mapping to trigger the unmapped
path with zero rebuild (confirming the bind mount), saved it back via
curl, confirmed the CSV was updated on the host, and confirmed
reprocessing succeeded immediately after.
Also includes the user's own edits to eib_pre_template.xlsx and
planeterra_equals_cards_transactions_eib_v45.xlsx made directly in
Excel/Numbers outside this session.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
eib-processor_how-it-works.md still described the pre-restructure
single-file app; corrected paths and added the two-output-file workflow
(eib_pre_template.xlsx vs. planeterra_equals_cards_transactions_eib_v45.xlsx).
CLAUDE.md gains populate_upload_template()/LAST_RESULT/the generate-upload
route, and a trajectory entry for how both template features were built.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
New "Generate EIB File (for Upload)" button, shown after a successful
process run, populates planeterra_equals_cards_transactions_eib_v45.xlsx
(the Workday EIB "Expense Credit Card Transaction" import template)
directly from that run's output, without a re-upload:
- app/tools/eib/logic.py: populate_upload_template() writes Header Key,
Line Key, Transaction Number/Date, Amount, currencies, description and
merchant name into the "Expense Credit Card Transaction" sheet, plus a
per-file metadata row into "Credit Card Transaction Header" (Header
Key, Credit Card Type, an auto-generated File Name covering the run's
date range, and today's date). Corporate-card identifiers
(AK/AM/AN) are resolved by reading eib_pre_template.xlsx's "Equals
Card IDs" sheet at generation time rather than duplicating that
mapping, so both output files always agree.
- app/tools/eib/routes.py: new /api/generate-upload route, backed by a
small module-level "last processed output" holder (same single-user
pattern as PROCESS_STATUS) so the button can reuse the prior run's
data.
- templates/eib/index.html: the new button + status note in the result
panel.
- .gitignore: exception for the new template, same as eib_pre_template.xlsx.
Also includes the user's own edit to eib_pre_template.xlsx (J:M formula
fill range manually extended from row 699 to row 2000).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Replace build_excel() with populate_template(): loads
app/tools/eib/eib_pre_template.xlsx fresh each run, writes EIB rows into
Final Sheet A2:I<n+1> (clearing prior run's rows first) and the audit
table starting at column AA, then saves a dated copy into outputs/ —
the template itself is never mutated. Columns J:Y (finance's own
corporate-card-ID lookup formulas and a legacy static block) are never
written to; _extend_formulas_down() only fills in a missing J:M formula
within the new data range (the template's formula rows turned out to be
non-contiguous, leftover from old manual test batches) without ever
touching a row that already has one.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Documents the platform-shell/tool-blueprint convention, the EIB tool's
mechanics, and the two-step path (landing page preview, then blueprint
restructuring) so future sessions can pick up without re-deriving it.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Split the EIB tool into app/tools/eib/ (routes.py for Flask glue,
logic.py for Flask-free business logic), registered as a Blueprint
under /eib with its own namespaced /eib/api/* routes. The home page
now renders a tool registry (app/main.py TOOLS list) instead of the
temporary /home-preview route, so future tools plug in the same way.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Single-tool Flask app (Equals Money -> Workday EIB conversion + audit)
plus a new /home-preview landing page in preparation for turning this
into a multi-tool platform.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>