Commit Graph

5 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 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 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 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