Commit Graph

26 Commits

Author SHA1 Message Date
JasonFraser 05c305d6ff Add category/project reassignment mapping, visible Budget copy, and Category Summary formatting to Financial Reports
- New category/project reassignment system: when a TB category or
  project has no home in the uploaded Budget file, two sequential
  review gates (category_mapping, then project_mapping) let the user
  fold it into an existing budget category/project (merging actuals
  into the target row, project code preserved) or explicitly leave it
  as-is - persisted to category_reassignment_map.csv/
  project_reassignment_map.csv, editable any time via a standalone
  Manage Mappings panel with inline dropdowns sourced from the stored
  Budget file's own real categories/projects per account.
- Accounts 79000/81000 (FX revaluation) always collapse every category
  under them into one fixed name, unconditionally.
- Fixed a live-formula bug the reassignment work exposed: Category
  Summary's SUMIFS criteria were built from reassigned/collapsed
  category text but pointed at the untouched raw TB sheets, so a
  merged row's formula would silently evaluate to zero in real Excel.
  Fixed by writing "Category (Applied)"/"Project (Applied)" columns
  onto the Revenue TB/Expense TB sheet copies and pointing formulas at
  those instead.
- A faithfully-styled, visible copy of the actual uploaded Budget file
  ("Budget (Original)") now replaces the old plain-data dump as what a
  person sees first; the plain-data "Budget" sheet still powers every
  live formula but is now hidden.
- Category Summary formatting: "Total Revenue"/"Project Costs"/"Net
  Revenues" moved to the Category column; each 68020-82000 account
  subtotal gets a "Total <name>" label; every major total/subtotal row
  gets a top+bottom border; the Variance column conditionally formats
  values below -$0.0001 in red.
- Two new reference sheets: "Reassignment Reference" (original-vs-
  shown-as text for every actual reassignment/forced collapse) and
  "GL Detail" (every GL Dump line tagged and sorted the same way
  Category Summary groups its own rows) - both purely additive, neither
  feeds any calculated figure.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HToTtpxzoxeugsa1Ve61gn
2026-10-01 20:02:13 -04:00
JasonFraser a5d1e50988 Add scratch/reference files from tool exploration (z_raw_tool_ideas/)
Design notes, sample output pages, and one-off check scripts used while
building the donor report, financial reports, payslip, and receipt
tools. Sample .xlsx/.csv files stay gitignored as usual.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HToTtpxzoxeugsa1Ve61gn
2026-10-01 20:01:52 -04:00
JasonFraser fc9d8f816d Update EIB merchant mappings/template and payslip tool styling
New merchant_lookup.csv entries and template updates from ongoing EIB
tool usage; payslip gets select-field styling, a removed footer, and
the default company name switched to Planeterra Foundation.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HToTtpxzoxeugsa1Ve61gn
2026-10-01 20:00:33 -04:00
JasonFraser 6d0e07ae78 Lift GL Dump helpers into app/common.py; add GL Analyzer, PDF Unlock, Summary Reconciliation Check, and Donor Report (GL Only) tools
Shared GL Dump loading/netting logic (find_gl_header_row, load_gl_dump,
reversed-by/FIFO/wash netting passes) now lives in app/common.py, used
by Donor Report's new GL-detail mode plus three new tools: Donor
Report (GL Only), GL Analyzer, and Summary Reconciliation Check.
PDF Unlock (via pikepdf) is unrelated but added alongside.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HToTtpxzoxeugsa1Ve61gn
2026-10-01 20:00:00 -04:00
JasonFraser a3196200de Add Receipt Generator tool
Same pattern as the Payslip Generator: self-contained, entirely
client-side (fill in details, live preview, download PDF), no server-
side logic, so no logic.py - just a route serving the page.

Applied the same fixes proactively, since it's the same design/PDF
pattern that had these exact issues:
- SRI-pinned standalone html2canvas + jsPDF instead of html2pdf.js,
  whose bundled html2canvas mis-renders shorter content on this kind
  of page (confirmed on the Payslip Generator via a controlled A/B
  test against the current standalone html2canvas).
- Page-fit math carried over: hotfixes:['px_scaling'], height clamped
  to >= width with explicit orientation:'portrait' (avoids jsPDF
  swapping width/height for landscape-shaped short content), +8px
  buffer against a sub-pixel-rounding extra-page bug.
- Header logo linked back to / (every other tool's header does this).
- Box-shadow stripped on capture - screen chrome, not part of the
  document.
- Wired into the platform: Blueprint at /receipt/, registered in
  main.py, landing-page card added.

Verified end-to-end (headless Chromium, real Download button) across
defaults, zero items, and a tall/complex receipt with discount/tax/
tip/cash payment - single page, fully rendered, no cropping.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-27 18:00:19 -04:00
JasonFraser 3336bf98bb Add Payslip Generator tool
A self-contained, entirely client-side tool (fill in details, live
preview, download PDF) - no server-side business logic, so unlike the
other tools there's no logic.py, just a route serving the page.

- Wired into the platform: Blueprint at /payslip/, registered in
  main.py, landing-page card added.
- Header logo linked back to / (every other tool's header does this;
  the original standalone page didn't).
- SRI-pinned the PDF-generation script tags so a compromised/MITM'd CDN
  response can't silently run in a page handling employee/contractor
  pay data.
- Earnings/deductions columns padded with blank filler rows so
  "Gross earnings" and "Total deductions" always land on the same
  line, regardless of how many rows either side has.
- Rewrote PDF generation to call html2canvas + jsPDF directly instead
  of through html2pdf.js: its bundled html2canvas mis-rendered (blank
  or truncated) shorter payslips, reproducible and confirmed via a
  controlled A/B test against the current standalone html2canvas.
  Direct usage also fixes page-fit (custom page size, hotfixes for
  correct px scaling, orientation/rounding handled explicitly) so the
  PDF matches the on-screen preview on a single page.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-27 17:41:52 -04:00
JasonFraser dfd3a710e0 Fix Category Summary/Balance Sheet reconciliation and account grouping
- Canonicalize category/project/account text before grouping so
  case-only variants (e.g. "OffSite Meetings" vs "Offsite Meetings")
  collapse to one row instead of producing two SUMIFS formulas that
  double-count each other under Excel/Sheets' case-insensitive text
  matching - this was the source of the reported mismatch.
- Add _assert_no_case_collisions as a build-time safety net; the old
  Python-only reconciliation check couldn't catch this class of bug
  since grouped-vs-source totals are mathematically equal regardless
  of labeling. routes.py now returns a clean 400 if it ever fires.
- Reposition 68020 out of the project-level (Account>Category>Project)
  section into the collapsed section with 70000+, so only 68010/68030
  remain above the Project Costs subtotal, matching the reference
  template.
- Rename the two output sheets to "1. Summary (Manual)" and
  "Balance Sheet (FS)", updating the cross-sheet Net Income formula
  reference to match.
- Explicitly set calcMode="auto" (in addition to openpyxl's default
  fullCalcOnLoad) so edits to the TB sheets keep recalculating
  dependent formulas after the first open, not just on it.
- Add a "Report vs. Source Files" comparison table to the results UI
  showing Total Income/Expenses/Surplus side by side against figures
  computed independently from the uploaded files.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-25 21:54:07 -04:00
JasonFraser e2a798600b Collapse 70000+ accounts to Account>Category, add Project Costs/Net Revenues
Two changes drawn from a closer re-read of the reference template's
expense section:

- Accounts 70000 and up (Wages, Benefits, Occupancy, Travel, etc.) no
  longer break out by Project Code - one row per category, combining
  every project it was posted against (2-criteria SUMIFS: Account +
  Category, no Project). The three "Project Costs" accounts
  (68010/68020/68030) keep the full Account -> Category -> Project
  Code breakdown, since those are the accounts genuinely tied to
  specific donor projects.
- "Project Costs" (68010+68020+68030's account subtotals) and "Net
  Revenues" (Total Revenue - Project Costs) are now inserted
  immediately after the 68030 block, matching the reference template.
  Neither feeds into the account-subtotal list Total Expenses sums
  from, so the three accounts aren't double-counted.

Verified: every pre-existing total is byte-for-byte unchanged (this is
a pure display/grouping change, not a data change) - revenue
5,338,866.02 / expense 3,743,572.26 / surplus 1,595,293.76 /
balance_check 0.00 - and the new Project Costs (2,990,695.99) / Net
Revenues (2,348,170.03) figures were independently resolved via the
SUMIFS/SUM simulator and check out arithmetically
(5,338,866.02 - 2,990,695.99 = 2,348,170.03).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-25 16:49:59 -04:00
JasonFraser 462e67af41 Nest Category Summary three levels: Account > Category > Project Code
Final structure, after two prior attempts (Account-only, then
Category-only) didn't match what was actually wanted: Account is now
the outer grouping (bold subtotal row, sorted ascending by account
number - resolving the "account sequence jumps around" issue directly,
since account is the primary sort key rather than something to
reorder categories by), Category is a second bold subtotal level
nested within each account (sorted alphabetically, SUMs its own detail
rows), and Project Code remains the leaf-level sort/display column. A
category spanning more than one account (e.g. "Planeterra Program
Costs - Administration" under both 68010 and 68030) now correctly gets
its own separate subtotal block under each account, rather than being
merged into one flat block.

Verified with the same SUMIFS/SUMIF simulator built for the previous
formula rewrite - resolved every formula against the actual embedded
source-sheet data, including account and category subtotals nesting
correctly. All totals unchanged (this is purely a row layout/grouping
change): revenue 5,338,866.02 / expense 3,743,572.26 /
surplus 1,595,293.76 / balance_check 0.00.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-25 16:38:33 -04:00
JasonFraser 091928eea0 Order categories by account number, not alphabetically
Within a category, rows were already ascending by account number, but
categories themselves were visited alphabetically - so the overall
account-number sequence down a section jumped around (e.g. 78000,
81000, 72400, 70000, 71060, 72600, 78000 again...) even though each
individual category block was internally ordered. Categories are now
visited in ascending order of their lowest account number (ties break
alphabetically), so the account-number sequence is monotonic across
the whole Revenue/Expenses section, not just within each category.

Verified: extracted the lead account code of every category block in
the Expenses section and confirmed the sequence is non-decreasing
end to end. Same totals as before (this only changes row order, not
values): revenue 5,338,866.02 / expense 3,743,572.26 /
balance_check 0.00.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-25 16:32:11 -04:00
JasonFraser d0ebc3f995 Category subtotal headings + live formulas against embedded source sheets
Two changes, confirmed with the user via concrete preview mockups
before building (avoiding a third wrong guess on the subtotal
structure after the account-grouping change):

- Reverted subtotal/heading grouping from Account back to Category
  (bold subtotal row per category, sorted alphabetically; within a
  category, detail rows sorted by account number then strategic area
  then full project code). Account still shows as the full unsplit
  "code:name" string on every detail row - that part of the account
  change stays, only the grouping key reverted.

- The two uploaded trial balance files are now embedded as their own
  sheets ("Revenue TB", "Expense TB") in the generated workbook, and
  every Category Summary/Balance Sheet cell is a live formula against
  them rather than a precomputed number - directly modeled on
  "1. Summary (Manual)"/"Balance Sheet (FS)"'s own SUMIFS/SUMIF
  formulas:
  - Category Summary detail rows: SUMIFS matching Account+Category+
    Project against the embedded sheet (blank category/project use ""
    criteria, mirroring the template's ISBLANK(...) branches).
  - Balance Sheet lines: SUMIF per mapped account code, wildcard-
    matched ("<code>:*") since the sheet stores code+name together.
    Totals (Total Current Assets, Total Assets, etc.) are formulas
    summing the line-item cells above them, not baked-in numbers.
  - Unrestricted (Net Assets) adds a live cross-sheet reference to
    Category Summary's own Total Revenue/Total Expenses cells for the
    period's Net Income, instead of a Python-computed literal.
  All formulas use only SUM/SUMIF/SUMIFS - no Excel-only functions -
  so the workbook is Google Sheets compatible, not just Excel.

Verified far more rigorously than a cross-check against my own Python
computation this time: wrote a SUMIFS/SUMIF simulator that evaluates
every formula against the actual embedded sheet data (not a
side-channel recomputation), recursively resolving subtotals, grand
totals, and the Balance Sheet's cross-sheet reference. Every result
matches exactly: revenue 5,338,866.02 / expense 3,743,572.26 /
surplus 1,595,293.76 / balance_check 0.00.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-25 16:23:22 -04:00
JasonFraser 8f1ffe57c6 Category Summary: group/sort by account number, show full account string
Two changes per closer re-reading of the reference template:

- "Account" column now shows the full raw Ledger Account string
  (e.g. "43000:Donation and Fundraising Revenue"), unsplit - same
  treatment as Project Code already gets, rather than parsing out just
  the name.
- Subtotal grouping switches from Category to Account, sorted by
  account number ascending (43000, 48000, then 68010..82000 in the
  Expenses section). String-sorting the full account value works here
  since every code in this chart of accounts is the same 5-digit
  width, so no separate numeric-sort key was needed. Within each
  account, detail rows are still sorted by strategic area (C&B, CTI,
  GCTN, General) then full project code. Category is now a plain
  column rather than a grouping level.

Purely a grouping/display change - re-verified end to end that every
total is unaffected: Category Summary reconciliation still MATCHES
exactly, Balance Sheet balance_check is still 0.00, and every Total
Revenue/Total Expenses/Surplus formula resolves to the same figures
as before (revenue 5,338,866.02 / expense 3,743,572.26 /
surplus 1,595,293.76).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-25 16:09:25 -04:00
JasonFraser c9fd95572a Add Financial Reports tool: Category Summary + Balance Sheet snapshot
New tool at /financial-reports/, same two-file trial balance upload as
the donor report, generating a workbook built fresh with openpyxl
(no bundled Excel template - the sheets are constructed to match
fs.xlsx's own structure/formatting rather than adjusting a copy of it):

- Category Summary: mirrors "1. Summary (Manual)" from the reference
  workbook - Account | Category | Project Code (full raw string,
  unsplit) | Canada YTD | US YTD | Consolidation Adjustments (blank) |
  Total YTD (formula) | Budget (header only, left blank for manual
  formulas). Category-level subtotal rows (SUM formulas), sorted within
  a category by strategic area then full project code. Total Revenue/
  Total Expenses/Surplus as formulas summing the category subtotals.
- Balance Sheet: single-period snapshot matching "Balance Sheet (FS)"'s
  labels/section order/Arial-11 formatting - the source file's
  month-over-month and prior-year columns are static historical
  snapshots that can't be regenerated from one trial balance upload, so
  this is one consolidated (Canada+US) column for the current period.
  Account-code-to-line-item mapping lives in
  balance_sheet_account_map.csv (bind-mounted, same pattern as the
  other tools' lookup tables), seeded from fs.xlsx's own N-S helper
  columns. Net Assets/Unrestricted = Retained Earnings (36000) + CTA
  (36300) + this period's computed Net Income - avoids needing prior-
  period data since 36000 already carries the cumulative prior position.
- Arithmetic check back to the uploaded files: every run independently
  re-sums Planeterra Foundation/Planeterra International Foundation Ltd
  across the filtered revenue+expense rows and compares against the
  Category Summary's own Canada/US totals, surfaced on both the results
  screen and embedded in the workbook. The Balance Sheet's own
  Assets-vs-Liabilities+NetAssets check is exposed the same way.
- UI: multi-file upload (auto-classifies revenue vs. expense by column
  headers), checkboxes for which sections to include, report date,
  report title, and a whole-dollars-vs-cents number format toggle.

Two real bugs found and fixed during testing, not just simplified logic:
- numpy.bool_ (from pandas comparisons) isn't JSON-serializable, unlike
  native Python bool - silently 500'd the endpoint until wrapped.
- compute_balance_sheet() was concatenating both uploaded files before
  summing Balance Sheet accounts - but both files are independently
  complete trial balance exports (same non-P&L rows in both, just
  tagged with a different category column), so this double-counted
  every single Balance Sheet account by exactly 2x. Caught via a
  balance_check that came out as -net_income instead of zero - too
  precise to be a coincidence, traced it back to the concat.

Verified end to end against the real trial balance files: Category
Summary Canada/US reconciliation both MATCH exactly, and the Balance
Sheet balance_check is exactly 0.00 (Assets = Liabilities + Net
Assets). Independently re-resolved every formula (including the
53-term Total Expenses SUM) and confirmed all totals match the API
response: revenue 5,338,866.02 / expense 3,743,572.26 /
surplus 1,595,293.76.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-25 15:49:12 -04:00
JasonFraser c32ab5984e Include the Planeterra International Foundation Ltd entity column
Amounts were only pulling from "Planeterra Foundation" (column D);
"Planeterra International Foundation Ltd" (column E) is now added in
too via a shared _entity_total() helper, used both for the per-row
amounts and the full-file balance integrity check. Eliminations
(column F) stays excluded - it's zero on every row in both sample
files, so D+E already equals the trial balance's own precomputed
"Total" (D+E+F) column; nothing currently depends on including it.

Verified against the real files: revenue moves from 4,384,170.35 to
5,338,866.02 (exactly sum(D)+sum(E) on the filtered rows) and expense
from 3,611,064.64 to 3,743,572.26, matching hand-calculated sums
before touching the report generator. Re-ran the full formula
verification (every Total Revenue/Expenses/Surplus cell across all 12
donor sheets plus the Summary sheet's cross-sheet references) with no
mismatches.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-25 13:57:01 -04:00
JasonFraser 65062f6f36 Add a Summary sheet listing Revenue/Expenses/Surplus by donor
New "Summary" sheet inserted at the front of the workbook: one row per
donor with Revenue, Expenses, and Surplus/(Deficit), each a live
formula referencing that donor's own Total Revenue/Total Expenses
cell (e.g. ='G Adventures'!B16) rather than a precomputed number, so
it can't drift out of sync if a donor sheet is edited later. A Total
row at the bottom sums all donors - this is the same figure the web
UI's result screen reports.

Verified by recursively resolving every formula (including the
cross-sheet references) independently of Excel: every donor row and
the grand total match the API's reported totals exactly
(revenue 4,384,170.35 / expense 3,611,064.64 / surplus 773,105.71).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-25 13:42:56 -04:00
JasonFraser 7cbd8ee7eb Drop subtotals, group revenue/expenses as a flat list by project code
Replaces the Account -> SLOB -> Category -> Subtotal hierarchy with a
single flat list per section, sorted by project code then category,
with no header or subtotal rows breaking it up - aimed at non-finance
readers who want to scan the numbers quickly, not a full accounting
breakdown (subtotals can be added manually for deeper analysis).

- Grouping is now (donor, project code, category) instead of (donor,
  account, project code, category) - dropping the Ledger Account
  dimension merges rows that were only "duplicated" because the same
  project code/category combination happened to post to two different
  GL accounts (e.g. the same spend category under two expense
  accounts), which would otherwise show as two near-identical rows.
- Total Revenue/Total Expenses are now a single SUM over each
  section's contiguous row range rather than a sum of subtotal cells.
- Fixed a bug introduced while removing the account-header rows: the
  template's own placeholder text ("Donations & Fundraising Revenue",
  "Disbursement to Projects") was bleeding through on each section's
  first row, because ws.cell(value=None) is a no-op in openpyxl rather
  than a clear - needed a direct .value = None assignment instead.

Re-verified: no stray placeholder text on any of the 12 donor sheets,
every Total Revenue/Total Expenses/Surplus formula independently
re-evaluated and matches the same grand totals as before this change
(revenue 4,384,170.35 / expense 3,611,064.64 / surplus 773,105.71).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-25 13:17:47 -04:00
JasonFraser 87ca8d585f Simplify donor sheet detail rows, drop redundant text in column A
Project code and category were already their own structured columns
(C, D), so repeating them as text in column A (a "  C&B" header row,
then "    Corporate Supporters" per category) was redundant. Detail
rows now leave column A blank; each project code's rows are followed
directly by its "<Project Code> Subtotal" row, one row shorter per
project code than before. Re-verified every formula in a full
regenerated report still resolves correctly and matches the same
grand totals as before this change.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-25 13:09:21 -04:00
JasonFraser 8d2da18bfb Add expense trial balance support to Donor Revenue Report
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>
2026-08-25 13:00:11 -04:00
JasonFraser a9f4b5a597 Add Donor Revenue Report tool
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>
2026-08-25 12:36:11 -04:00
JasonFraser e339b7147a Move merchant mapping to a bind-mounted CSV, add in-UI mapping flow
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>
2026-08-19 11:55:43 -04:00
JasonFraser 6590567c98 Update docs for the template-population features
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>
2026-08-18 16:13:58 -04:00
JasonFraser f89497b25d Add local generation of the Workday upload-ready EIB file
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>
2026-08-18 15:58:52 -04:00
JasonFraser a9df545952 Populate finance's EIB template instead of generating a fresh workbook
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>
2026-08-18 15:24:21 -04:00
JasonFraser bdfa244729 Add CLAUDE.md with architecture and project trajectory
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>
2026-08-18 11:29:54 -04:00
JasonFraser 04dabbdfab Restructure into a multi-tool platform with blueprints
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>
2026-08-18 11:25:13 -04:00
JasonFraser e4cef1faec Initial commit: EIB processor tool with new landing page preview
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>
2026-08-18 10:30:53 -04:00