Skip to content

Commit 1092d51

Browse files
feat: accounting ledgers, house accounts, groups/allotment, reservation ops + AI (#102)
* chore: harden .gitignore for private research/planning artifacts Add patterns so private domain/research planning files can never be accidentally tracked, alongside the existing proprietary kb/ and briefs/ exclusions. https://claude.ai/code/session_01Jq85xVJDW1NpvxQrnEdFdt * feat(accounting): deposit ledger, A/R, cash drawer, trial balance, GL codes Add a Tier-1 accounting layer that makes HAIP financials correct by construction: - Deposit Ledger: advance deposits tracked as a liability with a full held -> applied/refunded/forfeited recognition lifecycle - Accounts Receivable: named A/R ledgers, folio->A/R transfer-to-zero, audit-safe reverse transfers, A/R payments, aging buckets - Cash Drawer & cashiering: drawers, shift sessions, cash movements, shift close with expected-vs-counted variance, cashier report - Daily Trial Balance report across deposit/guest/A/R ledgers - Custom transaction + GL accounting codes New accounting + cashier NestJS modules; 4 schema files (+7 tables, 6 enums) with idempotent migrations; 11 new webhook events (48 total); 27 new endpoints (~125 total). 605 tests across 50 files, all passing. All new tables enforce property_id multi-tenancy; money via decimal.js. Updates README and adds CHANGELOG. https://claude.ai/code/session_01Jq85xVJDW1NpvxQrnEdFdt * feat(agent): T1 AI hooks — A/R collections agent, cash-variance + deposit-risk Layer AI onto the new accounting features: - A/R Collections Prioritization agent (new agent_type 'ar_collections'): ranks open A/R ledgers by balance x days-overdue x open-transfer count into low/medium/high tiers with a recommended collections action - Night Audit Anomaly agent: new 'cash_variance_outlier' anomaly type — flags over/short variances on closed cashier shifts (11 types total) - Cancellation Prediction agent: additive deposit-forfeit risk scoring on held deposits (likely-forfeit vs likely-refund exposure) Adds agent_type enum values 'ar_collections' and 'deposit_risk' with idempotent ALTER TYPE migrations. 10 built-in agents now (was 9). 624 tests across 51 files, all passing. Updates README + CHANGELOG. https://claude.ai/code/session_01Jq85xVJDW1NpvxQrnEdFdt * feat(folio): house accounts, split-folio routing, payment correction matrix Tier 2 — extend the billing layer: - House Accounts: non-guest ledger (walk-in retail, bar, vendor, internal) with open/close lifecycle and a products catalog; charges/payments share the unified ledger via a nullable house_account_id (folio_id now nullable — a ledger row belongs to either a folio or a house account) - Split Folio: config-driven routing rules + move-transactions between folios (by id or charge type); night-audit-locked charges protected - Payment Correction Matrix: correctPayment() enforces void (uncaptured auth / same-day cash) vs refund (captured card) vs compensating adjustment; illegal overrides rejected New house-account NestJS module; 3 new tables (house_accounts, products, folio_routing_rules), 3 enums; 7 new webhook events (55 total); 15 new endpoints (~140 total). 643 tests across 53 files, all passing. All new tables enforce property_id; money via decimal.js. Updates README + CHANGELOG. https://claude.ai/code/session_01Jq85xVJDW1NpvxQrnEdFdt * feat(groups): allotment blocks, pickup, rooming lists, group folio + AI Tier 3 — Groups & Allotment engine (largest net-new surface): - Group profiles (corporate/TA/wholesale/event) with optional master/group folio and computed group invoices - Allotment blocks: per-date/room-type inventory validated against live availability (no over-allotment), cutoff/shoulder dates, Min/Max LOS - Cutoff & auto-release: per-block release + process-cutoffs sweep that frees unsold rooms back to general inventory (endpoint-triggered, no cron lib) - Pickup tracking (allotted vs picked up per date/room-type) - Rooming-list batch import: creates+links member reservations, per-row success/error, increments pickup - Group Pickup Forecasting agent (new agent_type group_pickup): projects pickup vs wash, recommends hold/partial-release/full-release New groups NestJS module; 4 tables + reservations.group_profile_id; 3 enums; 6 webhook events (61 total); 16 endpoints (~155 total); 11 agents now. 672 tests across 57 files, all passing. All tables enforce property_id; linkReservation scoped by request propertyId (no confused-deputy). Updates README + CHANGELOG. https://claude.ai/code/session_01Jq85xVJDW1NpvxQrnEdFdt * feat(reservation): notes, bulk actions, messaging, unassigned finder, import Tier 4 — reservation operations polish: - Bulk actions: multi check-in/out/cancel with per-id success/error results - Reservation notes with active-count tracking - Guest messaging from a reservation (GDPR marketing opt-out enforced) - Unassigned-reservation finder (confirmed/assigned, no room, date window) - Batch reservation import with per-row error handling Deliberately NOT implemented: reservation status reversion ('un-cancel') — a payment-integrity hazard per KB 14.8; enforced by a regression test and a code comment. Create a new reservation instead. New reservation_notes table; 3 webhook events (64 total); 8 endpoints (~165 total). All within the reservation module; EmailService wired locally. 691 tests across 61 files, all passing. All new queries enforce property_id. Updates README + CHANGELOG. https://claude.ai/code/session_01Jq85xVJDW1NpvxQrnEdFdt * docs(changelog): note automated versioning, correct baseline to v1.2.5 The release workflow assigns version numbers/tags on merge, so the CHANGELOG keeps an [Unreleased] section and points the prior baseline at the real git-tag history (v1.0.0 → v1.2.5) instead of a placeholder. https://claude.ai/code/session_01Jq85xVJDW1NpvxQrnEdFdt --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c2de47b commit 1092d51

113 files changed

Lines changed: 10193 additions & 41 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ drizzle/meta/
3434
kb/
3535
briefs/
3636
instructions/
37+
# Private research & planning artifacts (belt-and-suspenders, never tracked)
38+
**/research/
39+
*.private.md
3740

3841
# Logs
3942
*.log

CHANGELOG.md

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Changelog
2+
3+
All notable changes to HAIP are documented here. This project adheres to
4+
[Semantic Versioning](https://semver.org/).
5+
6+
## [Unreleased]
7+
8+
> Version numbers and release tags are assigned automatically by the release
9+
> workflow on merge — this section is intentionally left as _Unreleased_.
10+
11+
### Added — Reservation Operations
12+
13+
- **Bulk actions** — check-in / check-out / cancel across many reservations in
14+
one call, with per-reservation success/error results (never aborts the batch).
15+
- **Reservation notes** — notes per reservation with active-count tracking.
16+
- **Guest messaging** — compose and send a message to a reservation's guest;
17+
marketing messages respect the guest's GDPR opt-out.
18+
- **Unassigned-reservation finder** — list confirmed/assigned reservations that
19+
have no room assigned, in a date window.
20+
- **Batch reservation import** — create many reservations from pre-parsed rows
21+
with per-row error handling.
22+
- New `reservation.*` ops webhook events; `reservation_notes` table.
23+
- **Deliberate non-feature:** reservation status reversion ("un-cancel") is
24+
intentionally NOT implemented (payment-integrity hazard, KB §14.8) — enforced
25+
by a regression test.
26+
27+
### Added — Groups & Allotment Engine
28+
29+
- **Group profiles** for corporate / travel-agent / wholesale / event business,
30+
with an optional group (master) folio and computed group invoices.
31+
- **Allotment blocks** — hold rooms per date and room type at negotiated rates,
32+
with cutoff dates, shoulder dates, and Min/Max LOS. Inventory is validated
33+
against live availability to prevent over-allotment.
34+
- **Cutoff & auto-release**`POST /groups/blocks/:id/release` plus a
35+
`POST /groups/blocks/process-cutoffs` sweep that frees unsold rooms from all
36+
expired auto-release blocks back to general inventory (endpoint-triggered; no
37+
in-process cron, per repo convention).
38+
- **Pickup tracking** — rooms allotted vs. picked up per date/room-type.
39+
- **Rooming lists** — batch import that creates and links member reservations
40+
with per-row success/error handling.
41+
- **Group Pickup Forecasting agent** (new agent type `group_pickup`, 11 agents
42+
total) — projects final pickup vs. wash and recommends hold / partial-release
43+
/ full-release ahead of cutoff.
44+
- New `group.*` webhook events; `reservations.group_profile_id` added.
45+
46+
### Added — Split Folios & House Accounts
47+
48+
- **House Accounts** — a non-guest ledger for walk-in retail, bar/restaurant,
49+
vendor, or internal sales not tied to any reservation. Open/close lifecycle,
50+
a `products` retail catalog, and charge/payment posting on the same unified
51+
ledger as folios. New `/house-accounts` + `/products` endpoints and
52+
`houseaccount.*` webhook events.
53+
- **Split Folio** — multiple folios per reservation with config-driven routing
54+
rules (room & tax → company, incidentals → guest) and move-transactions
55+
between folios (individually or by charge type; night-audit-locked charges are
56+
protected). New `/folios/routing-rules` and `/folios/:id/move-transactions`
57+
endpoints.
58+
- **Payment Correction Matrix**`POST /payments/:id/correct` picks the safe
59+
operation by payment state: **void** uncaptured authorizations (and same-day
60+
cash), **refund** captured cards, or post a compensating **adjustment**.
61+
Illegal overrides (e.g. voiding a captured card) are rejected.
62+
- Schema: `charges`/`payments` now belong to **either** a folio **or** a house
63+
account (`folio_id` nullable + nullable `house_account_id`).
64+
65+
### Added — AI Intelligence Layer (accounting)
66+
67+
AI on top of the new accounting layer — a differentiator with no equivalent in
68+
the baseline feature set. HAIP now ships **10 built-in agents** (was 9).
69+
70+
- **A/R Collections Prioritization agent** (new agent type `ar_collections`) —
71+
ranks open Accounts Receivable ledgers by collection priority (balance × days
72+
overdue beyond terms × open-transfer count) into low/medium/high tiers with a
73+
recommended action.
74+
- **Cash-variance anomaly detection** — the Night Audit Anomaly agent now scans
75+
closed cashier shifts and flags over/short drawer variances
76+
(`cash_variance_outlier`, 11 anomaly types total).
77+
- **Deposit-forfeit risk scoring** — the Cancellation Prediction agent now scores
78+
held deposits as likely-forfeit vs. likely-refund with exposure amounts
79+
(additive `depositRisk` on each reservation score).
80+
81+
### Added — Accounting & Cashiering
82+
83+
A new accounting layer that makes HAIP's financials correct-by-construction,
84+
not just functional.
85+
86+
- **Deposit Ledger** — advance deposits are now tracked as a **liability**, not
87+
revenue, with a full recognition lifecycle: `held → applied → refunded /
88+
forfeited`, including refundable vs. non-refundable handling and
89+
status-transition guards. New `/deposits` endpoints and `deposit.*` webhook
90+
events.
91+
- **Accounts Receivable (A/R)** — named A/R ledgers for post-stay direct billing.
92+
Transfer an outstanding folio balance to A/R (zeroing the folio), record A/R
93+
payments, reverse transfers with a preserved audit trail, and view aging
94+
buckets (0–30 / 31–60 / 61–90 / 90+). New `/ar/*` endpoints and `ar.*` webhook
95+
events.
96+
- **Cash Drawer & Cashiering** — per-drawer cash tracking with shift sessions,
97+
cash movements (payment, refund, paid-out, drop), shift close with
98+
expected-vs-counted **variance** detection, and a cashier's report. New
99+
`/cash/*` endpoints and `cashdrawer.*` webhook events.
100+
- **Daily Trial Balance** — reconciliation across the Deposit, Guest, and A/R
101+
ledgers. New `GET /reports/trial-balance` endpoint.
102+
- **Custom Accounting Codes** — user-defined transaction and General Ledger (GL)
103+
codes for export to external accounting systems. New `/accounting/codes`
104+
endpoints.
105+
106+
### Changed
107+
- API surface grew to ~165 endpoints (+66: 20 accounting, 7 cashier, 11 house
108+
accounts/products, 3 split-folio, 16 groups/allotment, 8 reservation-ops, plus
109+
payment-correct and the trial-balance report).
110+
- Webhook catalog grew to **64 event types** (+27: 11 accounting, 7 house-account
111+
& folio, 6 groups, 3 reservation-ops).
112+
- Test suite: **691 tests across 61 files** (was 551 across 45), all passing —
113+
140 new tests across the accounting, AI-hook, house-account, split-folio,
114+
payment-correction, groups/allotment, and reservation-ops features.
115+
- No manual version bumps — the release workflow tags the next version on merge.
116+
117+
### Notes
118+
- All new property-scoped tables enforce `property_id` multi-tenancy: every
119+
read/update/delete filters by both `id` and `propertyId`.
120+
- Money math uses `decimal.js` with `numeric(12,2)` storage throughout.
121+
- 7 new tables and 6 new enums, added to the idempotent `push-schema.ts`
122+
migration.
123+
- The A/R transfer-to-zero is a ledger move (reuses the folio adjustment path),
124+
not a payment, per the deposit/A/R domain rules.
125+
126+
## [1.2.5] and earlier
127+
128+
Prior baseline (released via git tags v1.0.0 → v1.2.5): reservations, folios,
129+
rate plans, rooms, guests, housekeeping, night audit, reports, channel manager,
130+
payments (Stripe), tax engine, webhooks, Connect API, and the 9-agent AI
131+
framework. See GitHub Releases for the per-tag history.

0 commit comments

Comments
 (0)