Implement business logic changes: deposits, no-shows, reservations, approval workflow

CHANGES:
Phase 1: Schema
- Change deposits_required default from 3 to 0 for new users
- Add forgiven_no_shows table to track forgiven no-show bookings

Phase 2: No-Show Logic (manage.go)
- CountUnforgivenNoShows(): Count unforgiven no-shows in 6-month period
- ApplyDepositsIfNeeded(): Auto-apply 3 deposits if 2+ no-shows detected
- ForgiveNoShowsForUser(): Clear no-shows and reset deposits on full payment

Phase 3: Slot Reservation System
- Add CleanupOldReservations() to delete 1h+ old reservation blockers
- Call cleanup in GetAvailableHours() on each availability check
- Delete existing user reservation before creating new booking

Phase 4: Minimum Advance Time
- Changed from 48h (deposit-only) to 1h (all users)
- Now universally enforced at booking creation time

Phase 5: Notes-Based Approval Workflow
- If booking has notes (not empty) → status = 'pending' (needs approval)
- If no notes → status = 'confirmed' (auto-approved)
- Uses CASE statement in INSERT for status determination

Phase 6: Late Night Lock
- After 22:00, non-admin users cannot book next morning before 11:00
- Implemented in GetAvailableHours() via artificial blocker subtraction
- Admin users see all times (no restriction)

Phase 7: Admin Notifications
- Notify admin if booking has notes OR is for same day
- All qualifying bookings trigger notification for admin review

VERIFICATION:
✓ Build passes: go build -tags dev ./main.go succeeds
✓ All 7 phases implemented as per dev-approved plan
✓ No breaking changes to existing schemas
✓ Backward compatible with existing booking flow
This commit is contained in:
2026-03-07 16:38:23 +00:00
parent 2c6dcc066d
commit faa4d89152
5 changed files with 173 additions and 9 deletions
+13 -1
View File
@@ -110,7 +110,7 @@ CREATE TABLE users (
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
-- Deposit tracking: remaining deposits needed (0-3). Reduces by 1 when booking with payment completes.
deposits_required INT NOT NULL DEFAULT 3,
deposits_required INT NOT NULL DEFAULT 0,
-- staff fields
notes TEXT
);
@@ -333,6 +333,18 @@ CREATE TABLE time_blockers (
CREATE INDEX idx_time_blockers_start_time ON time_blockers(start_time);
CREATE INDEX idx_time_blockers_cron ON time_blockers(cron_expression) WHERE cron_expression IS NOT NULL;
-- =======================================
-- FORGIVEN NO-SHOWS TABLE
-- =======================================
-- Tracks which no-shows have been forgiven (by full deposit payment)
CREATE TABLE forgiven_no_shows (
id CHAR(12) PRIMARY KEY DEFAULT generate_short_id('forgiven_no_shows'),
booking_id CHAR(12) NOT NULL UNIQUE REFERENCES bookings(id) ON DELETE CASCADE,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX idx_forgiven_no_shows_booking_id ON forgiven_no_shows(booking_id);
-- =======================================
-- PAYMENTS TABLE