Commit Graph

27 Commits

Author SHA1 Message Date
admin fbc5019730 Accounting: fix cross-page account-picker cache collisions + allow equity on bills
Root cause of filters conflicting between pages: many accounting pages shared
the same React Query keys (['accounts',cid], ['bank-accounts',cid],
['deposit-accounts',cid]) while running DIFFERENT queries, so whichever page
loaded first poisoned the others' cache (e.g. bill payment picker showing
banks-only with no equity; archived accounts leaking from the CoA list).

- Give every account read query a unique key discriminator per page/purpose;
  ['accounts',cid] / ['bank-accounts',cid] / ['deposit-accounts',cid] stay as
  invalidation prefixes (React Query partial match) so cross-page refresh still works
- Bill line-item category picker now includes expense + asset + equity + liability
  (was expense-only) — fixes 11 bills/13 lines categorized to equity (reserve-funded)
  that showed blank/—; and lets you assign an equity account to a bill
- Payment account picker (bills + expenses) reliably shows banks + equity now that
  it no longer collides with the banks-only deposit/receive-payment pickers

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-12 23:54:38 -04:00
admin 8a57f53317 Accounting report batches: saved per-association packets → one combined PDF
- accounting.report_batches (name + ordered report_ids per company, member RLS)
- batchReports.ts engine: cover page + each report on a fresh page + one global
  Page X/Y footer. Financial four reuse the page's fetchReportData/buildFinancial
  (injected to avoid an import cycle); Trial Balance, General Ledger, Cash
  Disbursement, AR Aging, Pre-Paid, Reserve Fund built from the same source data
- Reports page: Report Batches dialog (name, ordered report checklist, saved
  batches load/delete, Save, Generate PDF); page now defaults to This Month
- reportPdf.appendStructuredReportPdf used for the financial sections

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-12 22:57:12 -04:00
admin 920def8826 Reports: archived accounts hidden everywhere except the General Ledger
- fetchAllGLLines filters accounts.is_archived=false, covering P&L, Balance
  Sheet, Cash Flow, Movement of Equity and Income Statement in one place
- Trial Balance, Reserve Fund Schedule and Budget vs Actuals account lists
  exclude archived; Banking page hides archived accounts from cards/pickers
- General Ledger report intentionally keeps archived accounts (history)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-12 20:27:18 -04:00
admin e510a76dfc Accounting reports: AR Aging (Property), Pre-Paid Homeowners, Cash Disbursement
Buildium-style reports built on the owner ledger and GL:
- AR Aging (Property): FIFO-aged buckets (0-30/over 30/60/90) per unit with
  charge-type breakdown, collection status, summary + distribution bar
- Pre-Paid Homeowners: units with net credit balances as of a date
- Cash Disbursement: bank-credit GL entries grouped by bank account with
  check#/vendor/invoice enrichment from the banking register and GL line detail
All with branded PDF/CSV exports; shared owner-ledger helpers in lib/ownerLedger.ts

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-12 17:26:30 -04:00
admin 4f0ac97e83 Income Statement: Buildium-style category subgroups
Group the multi-period Income Statement by account category (Operating Income,
Administration, Utilities, Reserves Budget, …) with "Total for <category>"
subtotals, matching the Buildium layout, in the on-screen table, PDF, and CSV.

- New accounting.accounts.category column (nullable; null = ungrouped), seeded
  from the local chart_of_accounts parent hierarchy.
- Editable in Chart of Accounts: single-edit (with datalist autocomplete) and
  bulk-edit (blank = no change, __clear__ to unset).
- buildium-account-categories edge function pulls each account's parent-GL
  category from Buildium (matched by code, fallback name) and backfills
  accounting.accounts.category; idempotent and re-runnable.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10 22:34:58 -04:00
admin cb8a29696f Accounting reports: add multi-period Income Statement
New "Income Statement" report with a By Month/Quarter/Year selector that lays
out income/expense accounts in period columns plus a Total column, with Total
Income / Total Expense / Net Income rows. Built from the GL over the selected
range; includes branded PDF and CSV export. Accounts are listed flat under
Income/Expense for now (category subgroups to follow once accounts are
categorized).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10 21:04:49 -04:00
admin bd4c385478 Accounting reports: page through all GL lines (fix 1000-row truncation)
PostgREST caps each response at 1000 rows. The P&L and Balance Sheet
fetch every journal_entry_line for the company and aggregate client-side,
so any association with >1000 GL lines (e.g. an imported Buildium GL) only
saw the first 1000 — accounts whose activity fell past that point read as
$0 and were hidden, making reports look empty/out-of-balance. Fetch the GL
in 1000-row pages ordered by a stable key so every line is included.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-09 01:23:57 -04:00
admin 8a2ea60824 Accounting: editable journal entries + Reports refresh button
- Journal Entries: add Edit (row + detail drawer) that loads an entry into the
  form and saves changes (updates the entry and replaces its lines). Warns when
  editing an auto-generated entry (may be overwritten by its source sync).
- Reports: add a Refresh button that re-fetches the underlying data so the
  report reflects the latest GL.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 19:33:39 -04:00
admin aa94622a78 Opening Balances: fix duplicate earnings accounts; recognize name variants
The auto-provision effect could fire twice and create duplicate "Current Year
Earnings" accounts (seen on Village Grove). Use the idempotent
coa_get_or_create RPC with a once-per-company ref guard, and match existing
name variants (Current Year Income / Net Income / Retained Earnings) so it
won't create redundant accounts. Balance sheet now also folds
"Current Year Income"/"Net Income" equity accounts into the Net Income line.
Removed the existing Village Grove duplicate (zero activity).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 19:04:51 -04:00
admin 7fd8ad2c52 Opening Balances: allow entering Retained Earnings + Current Year Earnings
Auto-provision "Retained Earnings" and "Current Year Earnings" equity accounts
per company so they appear as inputtable rows in the Chart of Accounts Opening
Balances grid. The Balance Sheet folds the posted "Current Year Earnings"
account into the Net Income line (already did this for Retained Earnings), so a
mid-year import can seed both equity figures without entering income/expense
detail, and Total Equity stays balanced.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 18:11:01 -04:00
admin 5aa03d1cd6 Balance Sheet: fold posted Retained Earnings account into the prior-years line
A real "Retained Earnings" equity account is postable via journal entries, but
the balance sheet listed it separately from the calculated "Retained Earnings
(prior years)" line, so JE adjustments looked like they had no effect there.
Now the posted RE-account balance is added into the "Retained Earnings (prior
years)" line (and removed from the generic equity list). Total Equity is
unchanged — it already included that account.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 13:26:13 -04:00
admin 8f14877274 Balance Sheet: label the YTD earnings equity line "Net Income"
The equity section already carried a permanent current-year earnings line
(income − expenses for the fiscal year to date); rename it from "Current Year
Earnings" to "Net Income" to match the Movement of Equity report and the
requested terminology. No calc change — still YTD income minus expenses,
included in Total Equity.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 13:00:24 -04:00
admin d82466f826 Accounting: Sales Receipts, COA sync to dashboard, vendor-expense recognition
- Add Sales Receipts page (dashboard/accounting/sales-receipts): records a
  cash sale (name, address, income account, price, qty) — deposits and books
  income in one step via a transaction. New accounting.sales_receipts table.
- Sync chart of accounts to the accounting dashboard: mirror accounting.accounts
  into public.chart_of_accounts for platform associations (one-way, same id) so
  Bill Approvals and every COA consumer use the dashboard's accounts. Legacy
  rows hidden; Bill Approvals made system-aware.
- Vendor-expense recognition: a vendor payment with no bill now books the
  expense directly (Dr Expense / Cr Bank) on the payment date instead of going
  to A/P; payments against open bills still clear A/P (applied FIFO). Backfill
  reclassifies unbilled payments stuck in A/P. Expense Summary report made
  GL-driven so it follows the same rule.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-04 10:01:18 -04:00
admin c3d1d86b07 Reports: account drill-down to GL; bids/quotes PDF attachments
- P&L and Balance Sheet account rows are now clickable and open the
  General Ledger filtered to that account (its transaction list for the COA).
  Adds StructuredRow.accountId, threaded from the report builders, with a
  clickable row in StructuredTable and an initialAccountId prop on
  GeneralLedgerReport.
- Bids/Quotes: PDF upload on the New Bid/Quote dialog (bid-attachments
  bucket + document_url/document_name columns), shown as a link on the
  bid Details dialog.

Migration applied: bids_quotes_pdf_attachments.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-03 00:47:11 -04:00
admin e302fb91f0 Accounting platform: remove Zoho, unify reports, board access, vendor sharing
- Remove the Zoho Books integration (edge functions, sync libs, settings,
  reports/overview, banking links, fees tab, import dialog); preserve fee
  rules as a standalone FeesTab and the COA accounting_system classification.
- Financial Overview/Reports (staff + board) render the Accounting dashboard
  and reports; board reports mirror the rich Accounting Reports.
- New Reserve Fund Schedule report + an is_reserve flag on accounts.
- Unify all report exports to a branded format (logo + centered header +
  footer): shared ReportSheet (on-screen) and reportHeader (PDF). Budget vs
  Actuals and Bank Reconciliation PDFs now match the reference layout.
- Render financial reports inline (no preview pop-up).
- Budget Management mirrors Accounting Budgeting (staff-accessible) with SPA
  navigation; editable bills in the Accounting Bills page.
- Negative opening balances flow through to the GL and reports (allow negative
  input; keep non-zero on save; signed CSV import).
- Upload a per-account trial balance via CSV on Opening Balances.
- Board members: read-only RLS access to their association's accounting ledger;
  editable board-members panel on the association page; share vendor contacts
  with the board (toggle + directory section).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 18:29:31 -04:00
admin db20226d62 Movement of Equity GL-consistent; wire reconciliation checks R3/R5 (+R6/R9)
The Movement of Equity derived net income from sub-ledgers (calcNetIncome over
invoices/expenses/bills), while the P&L and Balance Sheet use the GL. With any
direct bank-categorized income/expense the two disagreed — Ashley Manor's SCE
was off from the Balance Sheet equity by 9,257.44. Rebuild Movement of Equity
from the GL (current-year earnings + GL equity balances) so all three statements
tie by construction.

Complete the §9 reconciliation matrix: R3 (P&L net income == raw-GL period net
income — guards the P&L builder) and R5 (Movement of Equity ending == Balance
Sheet total equity) are now computed by cross-checking the report builders against
the raw GL; checks render in numeric order. R6 (GL == TB/BS, satisfied by
construction) and R9 (direct vs indirect CFO, only indirect built) shown as N/A
for matrix completeness. Adds 5 reconcile unit tests (12 total).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 12:52:05 -04:00
admin 96de47496a Reconcile imported-GL companies: Bridgewater opening equity + scope R7/R8
Bridgewater's GL was imported as single-sided postings missing its opening fund
balance, leaving the trial balance off by 130,348.76 with an abnormal debit
equity balance. Record the gap as an Opening Fund Balance equity credit (migration
20260602150000); R1 and the Balance Sheet now tie out exactly.

A/R-A/P sub-ledger checks (R7/R8) only apply to platform-managed companies whose
invoices/bills post to the GL. Imported-GL companies (Bent Oak, Bridgewater) keep
their own AR/AP, so scope R7/R8 to gl_managed companies (new arApApplicable flag
on reconcile + gl_auto_post surfaced in useReportData). Every company now passes
the Reconciliation report.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 02:14:25 -04:00
admin 3d11980b8c Part B: Δ/Δ% columns, Balance Sheet comparison, Budget vs Actuals comparison
- StructuredTable now renders Comparative + Change + Change % columns when a
  comparison period is on (P&L, Cash Flow, Movement of Equity, Balance Sheet).
- Balance Sheet supports an as-of comparison period (prior as-of balances per
  account + totals); comparison toggle enabled for it (buildBalanceSheet takes
  prior dataset). Current Year Earnings stays independently computed.
- Budget vs Actuals: optional "Compare to" date range adds Compare + Δ-vs-Compare
  columns; actuals computation factored into a shared helper for both windows.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 01:49:47 -04:00
admin 5383404bb0 Part B: Cash Flow comparison period + Budget vs Actuals proration
- Cash Flow Statement now supports a comparison period (prior-period/prior-year/
  custom): refactored into computeCashFlow() and renders the comparison column
  for Net Income, CFO/CFI/CFF, beginning/ending cash. Previously it ignored the
  compare toggle. (P&L and Movement of Equity already had comparison.)
- Budget vs Actuals: budget is now pro-rated to the selected actuals window
  (sum each budget period weighted by overlap with the range) instead of always
  using the full annual figure — honors monthly/quarterly/annual period_type.
  Noted in the on-screen card and the PDF header (B4).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 01:22:35 -04:00
admin f74c61c9df Budget vs Actuals: custom actuals comparison date range
Add From/To date inputs to the Budget vs Actuals report (Accounting section
Reports) so actuals can be compared to the budget over any custom range,
independent of the page period preset. Defaults to the report period; drives
the actuals queries and CSV/PDF export labels.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 00:54:54 -04:00
admin 7a7435a8ee Cash Flow indirect method (R4) + reconciliation library & test suite
In the Accounting section Reports (AccountingReportsPage):
- Rebuild the Cash Flow Statement as an indirect-method report derived from the
  GL: Net Income + working-capital/non-cash movements, classified into
  CFO/CFI/CFF, with Beginning/Ending Cash. Ties to the change in Balance Sheet
  cash by construction (R4); surfaces an explicit residual row if it ever doesn't.
- Add R4 to the Reconciliation Checks report.
- Extract the reconciliation matrix into a pure, tested library
  (lib/reconcile.ts) and route the Reconciliation report through it.
- Add §10 synthetic-ledger vitest suite (lib/reconcile.test.ts): empty, single
  balanced entry, full period, partial settlement (open vs gross §1.5), and
  fault ledgers (single-sided → R1; payment-not-applied → R7). Verified R4 ties
  for Ashley Manor ($35,727.08 = ΔCash).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 00:07:16 -04:00
admin 03286f865a Conform reports to financial spec: A/R open-balance + reconciliation checks
Per the Financial Reports Master Spec:
- §1.5 A/R fix: invoice settlements now post to the GL (Dr Undeposited / Cr A/R
  from invoice.paid_amount); payments are the cash sub-ledger only and no longer
  separately credit A/R (avoids double-count). A/R control = open balance, so
  recon R7 passes for managed companies (Ashley Manor 39,248 -> 0). Bills already
  settled (R8 ok). Migration applied + backfilled managed companies.
- §9/§10: add a "Reconciliation Checks" report that surfaces R1/R2/R7/R8
  residuals (never plugged) so imbalances are visible — e.g. Bridgewater's
  imported GL is unbalanced (R1) and its sub-ledgers don't tie (R7/R8).

Imported companies (Bridgewater/Bent Oak) left untouched per decision; their
residuals now surface in the Reconciliation report.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-01 23:55:18 -04:00
admin 2fd311c8a2 Opening balances post to GL; unify all reports on the general ledger
- Opening balances now post a single "Opening Balances" journal entry to the GL
  (migration applied to prod), scoped to managed companies (imported-GL
  associations already carry theirs). Triggers on opening_balances /
  opening_balances_setup keep it in sync; Ashley Manor backfilled.
- Balance Sheet: read balances from the GL only (drop the separate opening add,
  which also double-counted imported companies).
- Trial Balance: compute balances from journal_entry_lines as of the report date
  (was accounts.balance).
- General Ledger report: read from journal_entry_lines (was transactions); opening
  rolls in from the GL.

All four reports now share one source. Verified Ashley Manor TB balances
(debits = credits = $90,073.23) with opening cash (BOA +$47,304.31) flowing through.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-01 23:06:00 -04:00
admin 57a9a1022e Remove cover sheet from financial reports; nest Budget vs Actuals accounts
- Drop the branded cover page from all financial/accounting report exports
  (P&L, Balance Sheet, Cash Flow, Movement of Equity, AR/AP flats, Trial
  Balance, General Ledger, Budget vs Actuals, and the Zoho/Board financial
  reports). The general Report Generator's own cover is unchanged.
- Budget vs Actuals now orders accounts as a parent→child tree with
  indentation (on screen and in CSV/PDF) instead of flat by account number.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-01 22:26:05 -04:00
admin b77860772e Fix report exports: Budget vs Actuals + branded cover everywhere
- Budget vs Actuals now exports (CSV + branded PDF); previously the page's
  export buttons were disabled for it. Wired into hasOwnExport with its own
  buttons in the report.
- Apply the shared branded cover page to the remaining PDF exports so they
  match the main scheme: homeowner account Statement (AccountingCustomer
  DetailPage), Trial Balance, and General Ledger.

Note: payments already render on the accounting customer ledger/statement
via payments_received (phase 3+4).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-01 22:00:57 -04:00
admin 8360363a15 Unify financial report styling with branded cover page
Extract the general Report Generator's branded cover (cover image/band,
logo, title, prepared-for/by) into shared src/lib/reportCover.ts. Financial
reports now open with the same cover: platform AccountingReportsPage via new
renderReportPdfWithCover(), and the Zoho/Board financial reports
(zohoFinancialReportPdf generators). ReportGeneratorPage refactored to use
the shared module (removes duplicated cover code).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-01 21:49:34 -04:00
admin 183fe0a93c Add ACMCC app source, Supabase backend, and project config
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-01 20:19:26 -04:00