feat: named registers, X/Z reports, daily rollup, fix drawerSessionId

Registers:
- New register table with location association
- CRUD service + API routes (POST/GET/PATCH/DELETE /registers)
- Drawer sessions now link to a register via registerId
- Register ID persisted in localStorage per device

X/Z Reports:
- ReportService with getDrawerReport() (X or Z depending on session state)
- Z report auto-displayed on drawer close in the drawer dialog
- X report (Current Shift Report) button on open drawer view
- Report shows: sales summary, payment breakdown, discounts, cash accountability, adjustments

Daily Rollup:
- ReportService.getDailyReport() aggregates all sessions at a location for a date
- New /reports/daily endpoint with locationId + date params
- Frontend daily report page with date picker, location selector, session breakdown

Critical Fix:
- drawerSessionId is now populated on transactions when completing (was never set before)
- This enables accurate per-drawer reporting and cash accountability

Migration 0044: register table, drawer_session.register_id column

Tests: 14 new (register CRUD, drawer report X/Z, drawerSessionId population, daily rollup, register-drawer link)
Full suite: 367 passed

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
ryan
2026-04-05 02:21:55 +00:00
parent be8cc0ad8b
commit 7d9aeaf188
17 changed files with 1062 additions and 6 deletions

View File

@@ -0,0 +1,12 @@
-- Named registers for POS terminals
CREATE TABLE IF NOT EXISTS register (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
location_id UUID NOT NULL REFERENCES location(id),
name VARCHAR(100) NOT NULL,
is_active BOOLEAN NOT NULL DEFAULT true,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
-- Link drawer sessions to registers
ALTER TABLE drawer_session ADD COLUMN IF NOT EXISTS register_id UUID REFERENCES register(id);

View File

@@ -316,6 +316,13 @@
"when": 1775680000000,
"tag": "0043_repair-pos-consumable",
"breakpoints": true
},
{
"idx": 44,
"version": "7",
"when": 1775770000000,
"tag": "0044_registers-reports",
"breakpoints": true
}
]
}

View File

@@ -70,9 +70,21 @@ export const discounts = pgTable('discount', {
export const adjustmentTypeEnum = pgEnum('adjustment_type', ['cash_in', 'cash_out'])
export const registers = pgTable('register', {
id: uuid('id').primaryKey().defaultRandom(),
locationId: uuid('location_id')
.notNull()
.references(() => locations.id),
name: varchar('name', { length: 100 }).notNull(),
isActive: boolean('is_active').notNull().default(true),
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
})
export const drawerSessions = pgTable('drawer_session', {
id: uuid('id').primaryKey().defaultRandom(),
locationId: uuid('location_id').references(() => locations.id),
registerId: uuid('register_id').references(() => registers.id),
openedBy: uuid('opened_by')
.notNull()
.references(() => users.id),