Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions docs/architecture/order-lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ Everything monetary is resolved server-side inside one transaction:
- The unit price comes from the catalog: `products.price`, or the variant price for an order with an
`online_platform`. A client-sent price is never read.
- Quantity rules are checked per sale unit, including fractional and weight-precision products.
- Each line copies `products.requires_kitchen` onto `order_items.requires_kitchen`. A ready-made line
(`0`) is inserted as `served`, so the status-based kitchen consumers ignore it, and the explicit
flag keeps it off the KDS, the kitchen board order list, the customer display board, and
order-status derivation. Later catalog edits never rewrite existing lines. See
[ready-made items](../reference/product-invariants.md#ready-made-items-never-reach-the-kitchen).
- Stock deduction and recipe depletion are written in the same transaction for immediate orders
(scheduled orders defer stock and recipe depletion until kitchen release), so the order and its
inventory effects commit together.
Expand Down Expand Up @@ -332,7 +337,7 @@ Two gates sit between a valid request and the write:
re-read with the same key after its shift closed. A cash ledger line records the open
`cash_session_id`.
- **Kitchen-delivery gate.** When `require_kitchen_delivered_before_settlement` is on, `kds_enabled`
is not `false`, and `billing_type` is not `prepaid`, paying while kitchen items are undelivered
is not `false`, and the order is not prepaid, paying while kitchen items are undelivered
is a `409` with code `KITCHEN_ITEMS_UNDELIVERED` unless a manager PIN is supplied as `override_pin`.
When an approver is explicitly supplied (`approver_id`, `manager_id`, or `user_id`), PIN
verification is restricted to that active manager without falling back to scanning other managers.
Expand Down Expand Up @@ -370,7 +375,7 @@ When a discount, an order mutation (`syncUnpaidBillsForOrder`), or a `POST /api/
re-sync reduces the remaining balance of a partially paid bill to exactly zero (where collected funds
equal the updated payable total), auto-settlement to `paid` is gated by kitchen delivery status. When
`require_kitchen_delivered_before_settlement` is enabled, `kds_enabled` is not `false`, and
`billing_type` is not `prepaid`:
the order is not prepaid:

- If kitchen items remain undelivered (`pending`, `preparing`, or `ready`), auto-settlement is held:
the discount applies and reduces the balance to zero, but the bill remains in `partial` status
Expand Down Expand Up @@ -408,7 +413,7 @@ whenever KDS item statuses change (`PATCH /api/order-items/:id/status`, embedded
order items are appended, cancelled, edited, refunded, or restored:

- Live items are non-terminal (`cancelled`, `voided`, `void_adjustment`, and `refunded` excluded)
positive-quantity lines across the full order, unfiltered by caller station or category scope
positive-quantity kitchen lines (`requires_kitchen` not `0`) across the full order, unfiltered by caller station or category scope
([`shared/order-item-status.ts`](../../shared/order-item-status.ts)).
- Starting kitchen work (`preparing`, `ready`, `served`, or `completed` on any live item while
unfinished items remain) promotes `pending` to `preparing` and sets `cooking_started_at`.
Expand Down
8 changes: 4 additions & 4 deletions docs/reference/api.md

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions docs/reference/product-invariants.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,43 @@ rename catalog items or create duplicate categories and add-ons during CSV impor

---

## Ready-made items never reach the kitchen

**Rule:** A catalog item can be marked as not going to the kitchen (`products.requires_kitchen = 0`).
Each order line copies the flag into `order_items.requires_kitchen` when it is created, and a
ready-made line is inserted as `served`. Such a line is priced, taxed, stock-tracked, receipted,
reported, and refundable like any other, but it never appears on the KDS or the kitchen board, never
prints on a kitchen ticket, never holds back kitchen-delivery settlement or order completion, and
never drives order-status derivation. An order made only of ready-made lines has no kitchen work and
is absent from the kitchen board and the customer display. Editing the catalog flag never changes an
existing line, and `requires_kitchen` defaults to `1`, so existing items behave as before.

When `service_model` is `hybrid`, payment timing follows the order: `dine_in` orders are paid after
service and every other order type is prepaid. `billing_type` governs every other service model.

**Reason:** A counter selling bottled drinks and a dining room serving cooked dishes run side by side.
Neither section may force the other into its mode, and an item that is handed over immediately must
not wait for a kitchen that never sees it.

**Enforced by:** `main/routes/orders.ts` (`insertOrderItems` and `POST /api/orders` set the status and
the snapshot), `main/db.ts` (`orderHasKitchenWorkSql`, `ACTIVE_RELEASED_KDS_ORDER_IDS_SQL`),
`main/routes/kds.ts`, `main/services/kds.ts`, `main/routes/kitchen.ts`,
`main/services/customer-display-tokens.ts`, `shared/order-item-status.ts` (`isKitchenItem`), and
`main/services/service-model.ts` (`isOrderPrepaid`).

**How to verify:**

```sh
npm run test:hybrid-service-model
npm run test:upgrade-path
```

**Change policy:** a new consumer of kitchen work must filter on `requires_kitchen` or the item status.
Marking ready-made lines as anything other than `served` at creation requires re-checking every
kitchen consumer listed above.

---

## Multi-counter ordering and prepayment lifecycle

**Rule:** Multi-counter ordering separates order capture ("Send to payment") from cashier settlement:
Expand Down
2 changes: 1 addition & 1 deletion frontend/e2e/database-export-import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ test.describe('Database Settings JSON Export and Import', () => {

const contaminatedPayload = {
app: 'FloDesktop',
schema_version: '125',
schema_version: '126',
data: {
settings: [],
categories: [],
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/app/(dashboard)/pos/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useAuthStore } from '@/store/auth';
import { getSessionBoundaryEpoch } from '@/store/session-events';
import { useCartStore } from '@/store/cart';
import { useHeldOrdersStore } from '@/store/held-orders';
import { usePosSettingsStore } from '@/store/pos-settings';
import { isPrepaidBilling, normalizeServiceModel, usePosSettingsStore } from '@/store/pos-settings';
import { useSidebar } from '@/components/ui/sidebar';
import toast from 'react-hot-toast';
import { ShoppingCart, X } from 'lucide-react';
Expand Down Expand Up @@ -286,9 +286,11 @@ export default function POSPage() {
autoPrintKot,
autoPrintBill,
billingType,
serviceModel,
tablesRequired,
kotPrintingEnabled,
setBillingType,
setServiceModel,
setTablesRequired,
setKotPrintingEnabled,
setAutoPrintKot,
Expand Down Expand Up @@ -1226,7 +1228,7 @@ export default function POSPage() {
getCountryByCode(currentTenant?.country ?? '')?.locale,
);
const { printBill, printKot } = usePrinterStore();
const billingIsPrepaid = billingType === 'prepaid';
const billingIsPrepaid = isPrepaidBilling(billingType, serviceModel, cart.orderType);
const shouldTakePaymentNow = billingIsPrepaid;

const printKotIfEnabled = async (order: Order, originContext?: SupportErrorContextSnapshot) => {
Expand Down Expand Up @@ -1617,6 +1619,7 @@ export default function POSPage() {
setStoreTimezone(d.timezone.trim());
}
setBillingType(d.billing_type === 'prepaid' ? 'prepaid' : 'postpaid');
setServiceModel(normalizeServiceModel(d.service_model));
const isTablesRequired = typeof d.tables_required === 'boolean' ? d.tables_required : true;
setTablesRequired(isTablesRequired);

Expand Down Expand Up @@ -1694,6 +1697,7 @@ export default function POSPage() {
}, [
isRestaurant,
setBillingType,
setServiceModel,
setTablesRequired,
setKotPrintingEnabled,
setAutoPrintKot,
Expand Down Expand Up @@ -3952,7 +3956,7 @@ export default function POSPage() {
cart.orderType === 'dine_in' &&
cart.tableId &&
cart.items.length > 0 &&
billingType === 'postpaid'
!billingIsPrepaid
) {
const tableName = tables.find((t) => t.id === cart.tableId)?.name || cart.tableId;
heldOrders
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/app/(dashboard)/products/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export default function ProductsPage() {
barcode: '',
sale_unit: 'each' as Product['sale_unit'],
allow_fractional_quantity: false,
requires_kitchen: true,
weight_precision: '3',
inventory_product_id: '',
inventory_deduction_quantity: '1',
Expand Down Expand Up @@ -419,6 +420,7 @@ export default function ProductsPage() {
barcode: '',
sale_unit: 'each',
allow_fractional_quantity: false,
requires_kitchen: true,
weight_precision: '3',
inventory_product_id: '',
inventory_deduction_quantity: '1',
Expand Down Expand Up @@ -482,6 +484,7 @@ export default function ProductsPage() {
barcode: product.barcode || '',
sale_unit: product.sale_unit || 'each',
allow_fractional_quantity: !!product.allow_fractional_quantity,
requires_kitchen: product.requires_kitchen !== false,
weight_precision: String(product.weight_precision ?? 3),
inventory_product_id: product.inventory_product_id || '',
inventory_deduction_quantity: String(product.inventory_deduction_quantity ?? 1),
Expand Down Expand Up @@ -596,6 +599,7 @@ export default function ProductsPage() {
barcode: form.barcode || null,
sale_unit: form.sale_unit,
allow_fractional_quantity: form.allow_fractional_quantity,
requires_kitchen: form.requires_kitchen,
weight_precision: Number(form.weight_precision),
...(form.inventory_product_id
? {
Expand Down Expand Up @@ -1579,6 +1583,24 @@ export default function ProductsPage() {
/>
<p className="text-xs text-gray-400 mt-1">{t('fieldBarcodeHint')}</p>
</div>
{isRestaurant && (
<div>
<label className="flex items-center gap-2">
<input
type="checkbox"
checked={form.requires_kitchen}
onChange={(e) =>
setForm({ ...form, requires_kitchen: e.target.checked })
}
className="rounded border-gray-300 dark:border-border text-brand focus:ring-brand"
/>
<span className="text-sm font-medium text-foreground">
{t('fieldGoesToKitchen')}
</span>
</label>
<p className="text-xs text-gray-400 mt-1">{t('fieldGoesToKitchenHint')}</p>
</div>
)}
<div className="grid grid-cols-3 gap-4">
<div>
<label className="block text-sm font-medium text-foreground mb-1">
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/app/(dashboard)/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1996,6 +1996,7 @@ export default function SettingsPage() {
businessDayStartTime: '00:00',
currency: '',
billingType: 'postpaid',
serviceModel: 'finedine',
tablesRequired: true,
taxRegistered: false,
taxRegistrationNumber: '',
Expand Down Expand Up @@ -2249,6 +2250,8 @@ export default function SettingsPage() {
businessDayStartTime: d.business_day_start_time || '00:00',
currency: d.currency || '',
billingType: d.billing_type === 'prepaid' ? 'prepaid' : 'postpaid',
serviceModel:
d.service_model === 'qsr' || d.service_model === 'hybrid' ? d.service_model : 'finedine',
tablesRequired: typeof d.tables_required === 'boolean' ? d.tables_required : true,
taxRegistered:
d.tax_registered === 'true' || d.tax_registered === true || d.tax_registered === 1,
Expand Down Expand Up @@ -2599,6 +2602,10 @@ export default function SettingsPage() {
businessDayStartTime: d.business_day_start_time || '00:00',
currency: d.currency || '',
billingType: d.billing_type === 'prepaid' ? 'prepaid' : 'postpaid',
serviceModel:
d.service_model === 'qsr' || d.service_model === 'hybrid'
? d.service_model
: 'finedine',
tablesRequired: typeof d.tables_required === 'boolean' ? d.tables_required : true,
taxRegistered:
d.tax_registered === 'true' || d.tax_registered === true || d.tax_registered === 1,
Expand Down Expand Up @@ -4137,6 +4144,7 @@ export default function SettingsPage() {
currency: form.currency,
country: form.countryCode,
billing_type: form.billingType,
service_model: form.serviceModel,
tables_required: form.tablesRequired,
tax_registered: form.taxRegistered,
tax_registration_number: form.taxRegistrationNumber,
Expand Down Expand Up @@ -4206,6 +4214,7 @@ export default function SettingsPage() {
business_address: form.businessAddress,
business_phone: normalizedBusinessPhone,
billing_type: form.billingType,
service_model: form.serviceModel,
tables_required: form.tablesRequired,
receipt_logo: form.receiptLogo || '',
receipt_logo_raster: form.receiptLogoRaster || '',
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/app/setup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ import { useConfirm } from '@/hooks/use-confirm';
import { RESTORE_FROM_FILE_EVENT } from '@/components/layout/MenuActionHandler';

type SetupProfile = 'empty' | 'express' | 'demo';
type ServiceModel = 'qsr' | 'finedine';
type ServiceModel = 'qsr' | 'finedine' | 'hybrid';

const SETUP_PROFILES: Array<{ value: SetupProfile; badge?: 'express' | null }> = [
{ value: 'empty' },
{ value: 'express', badge: 'express' },
{ value: 'demo' },
];

const SERVICE_MODELS: Array<{ value: ServiceModel }> = [{ value: 'qsr' }, { value: 'finedine' }];
const SERVICE_MODELS: Array<{ value: ServiceModel }> = [
{ value: 'qsr' },
{ value: 'finedine' },
{ value: 'hybrid' },
];

// Typed message keys for setup profile and service model cards.
type SetupKey = keyof AppConfig['Messages']['setup'];
Expand All @@ -63,6 +67,7 @@ const SETUP_PROFILE_KEYS = {
const SERVICE_MODEL_KEYS = {
qsr: { label: 'qsrLabel', desc: 'qsrDesc', details: 'qsrDetails' },
finedine: { label: 'finedineLabel', desc: 'finedineDesc', details: 'finedineDetails' },
hybrid: { label: 'hybridLabel', desc: 'hybridDesc', details: 'hybridDetails' },
} as const satisfies Record<ServiceModel, { label: SetupKey; desc: SetupKey; details: SetupKey }>;

// Registry-derived selectable languages (derived from LANGUAGES registry where selectable: true).
Expand Down Expand Up @@ -1182,7 +1187,7 @@ export default function SetupPage() {
<p className="text-muted-foreground text-sm">{t('flowSubtitle')}</p>
</div>

<div className="grid gap-4 md:grid-cols-2">
<div className="grid gap-4 md:grid-cols-3">
{SERVICE_MODELS.map((item) => {
const selected = serviceModel === item.value;
return (
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/components/pos/CartPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type { CustomPaymentMethod } from '@/lib/payment-methods';
import { useCartStore } from '@/store/cart';
import { useHeldOrdersStore } from '@/store/held-orders';
import { useAuthStore } from '@/store/auth';
import { usePosSettingsStore } from '@/store/pos-settings';
import { isPrepaidBilling, usePosSettingsStore } from '@/store/pos-settings';
import { useTranslations } from 'use-intl';
import toast from 'react-hot-toast';
import type { Table, Order, OrderItem, CartItem } from '@/lib/types';
Expand Down Expand Up @@ -254,6 +254,7 @@ export default function CartPanel({
return () => onModalOpenChange?.(false);
}, [priceOverrideOpen, effectiveDetailsDrawerOpen, onModalOpenChange]);
const billingType = usePosSettingsStore((s) => s.billingType);
const serviceModel = usePosSettingsStore((s) => s.serviceModel);
const t = useTranslations('pos');
const tCommon = useTranslations('common');
const tOrders = useTranslations('orders');
Expand Down Expand Up @@ -396,7 +397,7 @@ export default function CartPanel({
cart.orderType === 'dine_in' &&
cart.tableId &&
cart.items.length > 0 &&
billingType === 'postpaid';
!isPrepaidBilling(billingType, serviceModel, cart.orderType);

const isDeliveryOrder = cart.orderType === 'delivery';
const [customPaymentMethods, setCustomPaymentMethods] = useState<CustomPaymentMethod[]>([]);
Expand Down Expand Up @@ -952,6 +953,11 @@ export default function CartPanel({
</div>
<div className="mt-0.5 flex items-center justify-between gap-2">
<div className="min-w-0 flex-1">
{item.product.requires_kitchen === false && (
<p className="text-xs text-muted-foreground leading-snug">
{t('readyMadeNoKitchen')}
</p>
)}
{item.price_override && (
<p className="text-xs text-amber-600 dark:text-amber-400 leading-snug break-words">
{tOrders('priceOverriddenMenu', {
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/components/pos/ProductGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,11 @@ export default function ProductGrid({
<h3 className="font-medium text-foreground text-sm line-clamp-2 leading-snug">
{product.name}
</h3>
{product.requires_kitchen === false && (
<p className="text-[11px] text-muted-foreground leading-snug">
{t('readyMadeNoKitchen')}
</p>
)}
<div className="flex items-center justify-between mt-1">
<p className="text-brand font-bold">{fmt(Number(product.price))}</p>
<div className="flex items-center gap-1 shrink-0">
Expand Down
Loading
Loading