Commit Graph

18 Commits

Author SHA1 Message Date
admin 8f1cbcd3af Accounting: selectable-source / multi-line manual deposits
Deposits no longer force the credit side through Undeposited Funds — the
structural cause of negative Undeposited balances. A deposit can now credit any
account(s): interest income, a refund, an insurance reimbursement, cash straight
to the bank, etc.

- Schema: add accounting.deposit_lines (deposit_id, company_id, account_id,
  amount, memo) for the credit side, plus deposits.source_account_id as a
  single-source fallback. RLS mirrors deposits (staff + company member).
- post_deposit_gl: Dr bank for the total; Cr each deposit_lines row's account
  for its amount; no lines -> Cr source_account_id; neither -> Cr Undeposited
  Funds (backward compatible — existing deposits stay Dr Bank / Cr Undeposited).
  Remainder safety net keeps the entry balanced. New trg_acct_deposit_line_gl
  re-posts when lines change (header trigger fires before lines exist).
- Make Deposit page: GL-driven submit writes the deposit header + deposit_lines
  and marks selected payments deposited. Adds an "Other deposit lines" grid
  (account + amount + memo) alongside the existing Undeposited selection, with a
  running grand total and a soft guard against over-crediting Undeposited.
  Drops the old bank/Undeposited register-transaction inserts and manual balance
  pokes (never exercised in production; carried a money-in sign bug). Deposits
  are GL-only, consistent with the sync-created deposits already in the DB.

Verified Dr/Cr for single-source and multi-line scenarios against the live GL.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-04 13:00:41 -04:00
admin 7464d55b6c Accounting: enforce accrual A/P on bill payments (match rule + guard + cleanup)
Under accrual, a vendor expense is recognized once — when the bill is entered
(Dr Expense / Cr A/P). Paying a bill must only relieve the liability
(Dr A/P / Cr Bank) and never re-hit the expense account. This hardens the
existing Pay Bills flow against re-recognition and double counting.

- Strict bill matching: extract a pure, dependency-free matcher into
  lib/billMatch.ts (debitMatchesBill/matchOpenBills) — same vendor, status
  open/overdue/partially_paid, amount within $0.01 of remaining (or <= remaining
  for partials), debit date within ±30 days of due/issue date. Unit-tested in
  billMatch.test.ts (covers the identical-recurring-charge regression).
- AccountingBankingPage.saveTx uses the strict rule (was "any open bill"), so a
  thrice-paid identical charge only clears the in-window bill.
- Bank-feed categorizer (bulkSetCategory) matches open bills before assigning an
  expense COA: single match clears A/P + links the bill; multi-match is skipped
  with a prompt to resolve in Pay Bills; no match categorizes as a direct expense.
- DB guard: add accounting.transactions.bill_id (FK -> bills) and CHECK
  chk_bill_payment_no_coa (bill_id IS NULL OR coa_account_id IS NULL) so a
  bill-linked payment can never carry an expense category. Both writers set
  bill_id on single-bill payments; partial payments now write partially_paid.
- One-time cleanup: clear coa_account_id on Ashley Manor's 8 double-counted bill
  payments ($2,198.98) so the GL reposts them as Dr A/P / Cr Bank.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-04 12:30:44 -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 bd5caf5415 Merge pull request #3 from renee-png/email-cutover-and-accrual
Migrate email pipeline off Lovable + branded auth emails
2026-06-03 02:40:35 -04:00
admin f7dc5d8177 Buildium -> Accounting: auto-provision companies + opening-balance migration
- buildium-sync now ensures every active association has an accounting company
  after syncing associations. Once it exists, the existing DB triggers flow
  units -> customers, owner ledger -> A/R + income, and bills -> A/P + expense
  into Accounting automatically (closing the gap where Buildium synced only the
  main dashboard, not Accounting).
- New buildium-opening-balances function: fetches an association's Buildium GL
  trial balance as of a cutoff (default 2025-12-31, Accrual), maps GL accounts
  to accounting accounts (flagging bank accounts), rolls prior-year P&L into
  Retained Earnings, writes accounting.opening_balances, and posts the opening
  GL entry. Idempotent; service-role gated.

Applied to 6 Buildium associations (opening balances + 2026 activity); all
balance. New columns/data applied to the project directly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-03 02:31:21 -04:00
admin b1486a0b2a Migrate email pipeline off Lovable + branded auth emails
Replace Lovable-bound email transport and auth webhook so the platform
sends all automated email through its own infrastructure.

- process-email-queue: drop sendLovableEmail/LOVABLE_API_KEY; send via the
  Hostinger Email API (primary) with automatic SMTP fallback. Shared
  transports added in _shared/hostinger-mail.ts and _shared/smtp-send.ts.
- auth-email-hook: verify Supabase's native Send Email hook signature
  (Standard Webhooks via SEND_EMAIL_HOOK_SECRET) instead of Lovable's libs;
  build the GoTrue verify URL; keep enqueue → process-email-queue.
- Recreate the 6 auth email templates under _shared/email-templates/ that
  previously only existed in the deployed function.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 23:07:26 -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 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 21224e400d A5 expense classification + A/P overpayment fix
- post_transaction_gl counter priority fixed: customer->A/R, then coa->that
  account (direct categorized expense/income), then uncategorized vendor->A/P.
  Previously any vendor payment went to A/P, driving A/P negative and hiding the
  real expense account. The 38 direct vendor payments now post to their expense
  accounts; A/P went from -5,895.79 to +3,099.29 (real open payables).
- sync_public_bill now maps the public bill's expense_account_id to the matching
  accounting expense account (by name) on the bill line item, so synced bills
  stop defaulting to "Administrative". Expenses now spread across Attorneys Fees,
  Electric, Lawn Service, Management Fees, Water, etc.
- Verified managed companies: R1=0, R7=0. R8 surfaces a real $1,029.17 residual
  (bills marked paid whose payments were entered as direct expenses, not A/P
  settlements) — surfaced in the Reconciliation report, not plugged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 01:16:58 -04:00
admin f9c1b8af44 Fix balance sheet: recognize transfers & deposits (unify cash on bank register)
Root cause: accounting.transactions (deposits, transfers, bank payments) never
posted to the GL, and the GL's cash came only from synthesized legs that
hard-coded Undeposited Funds. So the balance sheet ignored transfers (#1) and
showed directly-deposited funds as Undeposited (#2), with banks going negative.

- Post the bank register to the GL: customer receipt -> Dr bank/Cr A/R, vendor
  payment -> Dr A/P/Cr bank, categorized -> Dr/Cr bank+COA, transfer -> Dr dest/
  Cr source, deposit -> Dr bank/Cr Undeposited; payments_received -> Undeposited.
  Retire the synthesized invoice/bill cash legs (acmacc_invpay/billpay) so cash is
  sourced once, from the register. Triggers on transactions/deposits keep it live.
- Fix gl_managed: make it an explicit accounting.companies.gl_auto_post flag
  instead of inferring from null-source journal entries (a single manual journal
  entry had silently disabled all automation for Ashley Manor).

Verified (Ashley Manor): transfer reflected (Cogent +47,127 vs prior -3,521),
deposits land in BOA (Undeposited cleared), R1=0, R7=0, no negative banks.
Imported companies (Bridgewater/Bent Oak) untouched; their residuals stay
surfaced in the Reconciliation report.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 01:08:37 -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 a3a0b706a1 Board-member upload permission for documents & bids/quotes
Add a "Allow document & bid/quote uploads" toggle on board member profiles
(board_members.can_upload). When enabled, that board member can upload
association documents and create/manage bids & quotes for their association(s);
otherwise the board portal stays read-only for them.

- Migration (prod): board_members.can_upload column; tighten the documents
  insert + storage 'files' upload policies to require can_upload; add a
  bids_quotes board policy gated on can_upload.
- BoardMembersPage: permission switch (load/save).
- BoardAssociationContext: expose canUpload for the selected association.
- DocumentsPage: board upload gated by the flag (was always-on for board).
- BidsQuotesPage: permitted board members can add/manage bids (was hidden);
  board inserts target the board's association.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-01 23:33:09 -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 04d1bdfb49 Post AR/AP sub-ledgers to the general ledger (fix empty P&L/Balance Sheet)
The P&L and Balance Sheet are GL-driven, but invoices/payments/bills never
posted to journal_entries (the referenced syncBillsInvoicesToLedger was never
built), so accounts with no GL activity showed $0 and were hidden.

Adds an idempotent GL posting engine (migration applied to prod), scoped to
companies whose GL is "managed" (no imported/foreign journal entries) to avoid
double-counting Bridgewater/Bent Oak:
- invoice  -> Dr Accounts Receivable / Cr income (keyword-mapped, default Assessment Fees)
- payment  -> Dr Undeposited Funds   / Cr Accounts Receivable
- bill     -> Dr expense (bill_items) / Cr Accounts Payable (+ paid leg to bank)
Auto-creates AR (1100) / AP (2000) where missing. AFTER triggers on
invoices/payments_received/bills keep the GL in sync; existing docs backfilled.
Verified debits=credits and the balance-sheet invariant holds.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-01 22:39:07 -04:00
admin 3c32f8ac47 Bidirectional bill sync between app and Accounting
Migration applied to prod: approved/paid public.bills mirror into
accounting.bills (Payables) with find-or-create vendor + line item
(external_source='acmacc_bill'/'acmacc_vendor'). When an accounting bill is
marked paid (paid_amount>=total), the linked public.bills is set status=paid
(+paid_date, amount_paid) and its bill_approvals marked paid. Loop-guarded
with is-distinct-from. Backfilled 370 bills/45 vendors; totals reconcile.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-01 21:41:51 -04:00
admin 2d216e24c9 Sync owner ledger + payments into Accounting
DB triggers on public.owner_ledger_entries (migration applied to prod):
charges (debit) -> accounting.invoices; payments (credit) ->
accounting.payments_received (deposited=false, Undeposited Funds). Customer
balance recomputed authoritatively from the source ledger; ledger payments
FIFO-applied to ledger invoices. Keyed external_source='acmacc_ledger'.
Backfilled 6,756 invoices + 4,253 payments; balances reconcile exactly.

Frontend: customer Ledger tab now renders real payments_received credits
(true dates/amounts); Make Deposit page surfaces undeposited payments_received
alongside Undeposited Funds transactions and deposits both.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-01 21:36:55 -04:00
admin c124397a97 Sync accounting Homeowners from Units & Owners per association
Adds DB triggers + backfill so accounting.customers is driven by the
public units/owners roster: one customer per unit, all owners combined,
Units/Owners as source of truth for contact fields. Balances and ledger
links (invoices, payments_received, transactions, work_orders, estimates)
are always preserved. Scoped to associations with an accounting company.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-01 20:57:01 -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