Files
Jorem Juárez 8004d51f7b Unify tables/orders/split: table accounts, batches, per-item delivery timers
Unifies the model: a table is ALWAYS one account; every active Order on a table
number is a subaccount (named or not) — no more 'normal vs split table'.

Total convergence (fixes the bug): the dashboard groups ALL active orders by
tableNumber into one card; two normal orders on the same table now share one table
card with two subaccounts. (POST /order already converges split too.)

Batches: items sent together share a batchId + batchAt; later additions form a new
batch. reconcileItems() carries id/batch/delivered for matched lines and opens one
new batch for new lines. (OrderItem is embedded JSON, so its new fields — id,
batchId, batchAt, delivered, deliveredAt — need no migration.)

Per-item timer + delivery: each item runs from its batch start; 'Entregado' freezes
that item's timer (deliveredAt) while siblings keep running. Color thresholds are
per-restaurant (timerGreenMax/timerYellowMax, migration 0011) and editable in the
Orders tab; each item colors green/yellow/red by its own minutes.

Independent states: delivered (per item, kitchen) vs paid (per subaccount, billing).
Admin can rename a subaccount inline (PATCH subaccountName). All live via SSE;
retention unchanged.

i18n es/en at parity. Glassmorphism/mobile-first/safe areas preserved. Cart,
maridajes and consultant untouched.

New: Restaurant.timerGreenMax/timerYellowMax (migration 0011); OrderItem JSON gains
id/batchId/batchAt/delivered/deliveredAt (no migration); PATCH orders/[id] gains
deliverItemId+delivered and subaccountName; settings + GET /orders carry thresholds.

Verified (build passes, all i18n present, migration 0011 applies):
1 two normal orders table 7 -> one card, two subaccounts;
2 lote A (30m ago) red + lote B (now) green, two batches;
3 deliver A1 -> frozen w/ deliveredAt, A2 keeps running;
4 thresholds 5/15 persist and return via GET /orders;
5 paid toggles independent of delivered (and vice versa);
6 rename '(table)' -> 'Juan' persists + SSE order-edit carries it.
2026-06-15 19:42:44 -06:00

119 lines
4.8 KiB
Plaintext

generator client {
provider = "prisma-client-js"
// native = host platform (builder/runner are both node:20-alpine = musl).
// The explicit musl target guards the runtime engine in the final image.
binaryTargets = ["native", "linux-musl-openssl-3.0.x"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Restaurant {
id String @id @default(cuid())
slug String @unique
name String
editorSecret String
username String
hashedPassword String
palette Json @default("{}")
qrConfig Json @default("{}") // artistic QR styling (qr-code-styling config)
ordersEnabled Boolean @default(false)
splitEnabled Boolean @default(false) // enables collaborative split-by-table accounts
orderRetentionHours Int @default(24) // completed orders older than this are pruned on read
timerGreenMax Int @default(10) // minutes: under this an item timer is green
timerYellowMax Int @default(20) // minutes: under this yellow, over this red
showMacros Boolean @default(false) // when false, the public menu hides all macro layers
pairings Json @default("{}") // precomputed cart suggestions { productId: [productId] }
bannerImage String? // wide brand banner (uploaded)
profileImage String? // circular logo/avatar (uploaded)
socialLinks Json @default("[]") // [{ platform, url }]
defaultLocale String @default("es")
active Boolean @default(true)
publishedVersionId String? @unique
createdAt DateTime @default(now())
publishedVersion MenuVersion? @relation("PublishedVersion", fields: [publishedVersionId], references: [id])
versions MenuVersion[] @relation("RestaurantVersions")
sections Section[]
products Product[]
orders Order[]
}
// Versioning system: a published snapshot of the whole menu.
model MenuVersion {
id String @id @default(cuid())
restaurantId String
versionName String
snapshot Json
publishedAt DateTime @default(now())
createdBy String?
restaurant Restaurant @relation("RestaurantVersions", fields: [restaurantId], references: [id], onDelete: Cascade)
publishedFor Restaurant? @relation("PublishedVersion")
@@index([restaurantId])
}
// Working DRAFT (not what the public sees).
model Section {
id String @id @default(cuid())
restaurantId String
name Json // { es, en }
order Int @default(0)
showMacros Boolean @default(true) // per-section override; only applies when Restaurant.showMacros is on
createdAt DateTime @default(now())
restaurant Restaurant @relation(fields: [restaurantId], references: [id], onDelete: Cascade)
products Product[]
@@index([restaurantId])
}
// Working DRAFT product.
model Product {
id String @id @default(cuid())
sectionId String
restaurantId String
name Json // { es, en }
description Json @default("{}") // { es, en }
price Decimal @default(0) @db.Decimal(10, 2)
order Int @default(0)
isActive Boolean @default(true)
allergens String[] @default([])
dietTags String[] @default([])
macros Json @default("{}") // { protein, carbs, sugar, fat, fiber, kcal }
media Json @default("[]") // [{ type, path, order }]
translationStatus Json @default("{}") // { en: auto|reviewed }
aiEstimated Json @default("{}") // { macros: bool, allergens: bool } — flags AI-inferred data to verify
createdAt DateTime @default(now())
section Section @relation(fields: [sectionId], references: [id], onDelete: Cascade)
restaurant Restaurant @relation(fields: [restaurantId], references: [id], onDelete: Cascade)
@@index([restaurantId])
@@index([sectionId])
}
model Order {
id String @id @default(cuid())
restaurantId String
tableNumber Int
items Json // [{ productId, name, qty, note?, price?, addedAt? }]
note String? // general note for the whole order
status String @default("active") // active | completed
// Split: each Order is one subaccount of a table. A table is "in split" when
// any active order for that tableNumber has split=true. Reuses table grouping.
split Boolean @default(false)
subaccountName String? // diner name for the subaccount (null = unnamed/"table")
paid Boolean @default(false) // restaurant marks a subaccount as paid
createdAt DateTime @default(now())
completedAt DateTime?
restaurant Restaurant @relation(fields: [restaurantId], references: [id], onDelete: Cascade)
@@index([restaurantId, status])
}