import type { PostgresJsDatabase } from "drizzle-orm/postgres-js"; export interface BookingRow { id: string; booking_number: string; status: string; created_at: string | Date | null; paid_at: string | Date | null; contact_first_name: string | null; contact_last_name: string | null; contact_email: string | null; contact_phone: string | null; sell_currency: string | null; pax: number | null; sell_amount_cents: number | null; invoice_total_cents: number | null; invoice_paid_cents: number | null; schedules_paid_cents: number | null; } export type AllocationPaymentStatus = "paid" | "partial" | "unpaid"; /** * Roll up a booking's payment state into a single paid / partial / unpaid * status for the allocation chip's color coding. Signals checked in order: * * 1. Free booking (`sell_amount_cents <= 0`) -> `paid` (nothing owed). * 2. `bookings.paid_at` is set -> `paid` (operator marked the booking * settled; this is authoritative regardless of invoice plumbing). * 3. Sum of `booking_payment_schedules.amount_cents WHERE status='paid'` * covers `sell_amount_cents` -> `paid` (deposit-milestone flows that * never run a final invoice). * 4. That schedule sum is positive -> `partial`. * 5. No invoices issued (`invoice_total_cents = 0`) -> `unpaid`. * 6. `invoice_paid_cents <= 0` -> `unpaid`. * 7. `invoice_paid_cents >= invoice_total_cents` -> `paid`. * 8. Otherwise -> `partial`. * * The schedule and `paid_at` checks were added because the invoice-only * rule mis-colored booked-and-settled trips as red whenever the operator * billed via schedules without issuing an invoice, or recorded settlement * on the schedule rather than a `payments` row (issue #1079). */ export declare function derivePaymentStatus(row: BookingRow): AllocationPaymentStatus; /** * Settled-amount counterpart to `derivePaymentStatus`. Returns the best * available signal of how much has actually been collected for the * booking -- the larger of schedule and invoice settlement, plus the full * sell amount when the operator has flagged `paid_at` (since that's an * explicit override). Capped at `sell_amount_cents` so partial-overpay * scenarios don't distort slot totals. */ export declare function derivePaidAmountCents(row: BookingRow): number; interface TravelerRow { id: string; booking_id: string; first_name: string; last_name: string; email: string | null; phone: string | null; is_primary: boolean; participant_type: string; traveler_category: string | null; is_lead_traveler: boolean | null; sharing_group_id: string | null; room_type_id: string | null; bed_preference: string | null; allocations: unknown; has_accessibility_needs: boolean; has_dietary_requirements: boolean; } interface BookingUnitRow { booking_id: string; option_id: string | null; option_unit_id: string | null; option_unit_code: string | null; } export declare function loadSlotBookingRows(db: PostgresJsDatabase, slotId: string): Promise; export declare function loadSlotTravelerRows(db: PostgresJsDatabase, bookingIds: string[]): Promise; export declare function loadSlotBookingUnitRows(db: PostgresJsDatabase, slotId: string, bookingIds: string[]): Promise; export declare function normalizeAllocationMap(value: unknown): Record; export declare function serializeSlot(slot: { id: string; productId: string | null; startsAt: Date; endsAt: Date | null; }): { id: string; productId: string | null; startsAt: string | null; endsAt: string | null; }; export {};