Restaurant mode Phase 2: menu depth — categories, stations, modifiers, courses
Deploy Ladill POS / deploy (push) Successful in 35s
Deploy Ladill POS / deploy (push) Successful in 35s
Builds on Phase 1 with the menu structure restaurants need: - Menu setup page (restaurant mode): categories, kitchen stations, and modifier groups with options (price deltas). - Products gain category, kitchen station, default course, and attached modifier groups (managed on the product form). - Ordering: the ticket groups the catalog by category and, when a product has modifier groups, opens a picker (respects min/max select) for options + notes + course before adding. Effective price = base + modifier deltas (resolved server-side; client prices are never trusted). - Fire-by-course: send the whole tab or just one course to the kitchen. - KDS: filter by station; each item shows its station, course, modifiers and notes. Schema additive (pos_categories, pos_stations, pos_modifier_groups, pos_modifiers, product↔group pivot, pos_sale_line_modifiers; category/station/course columns on products and lines). PosRestaurantTest covers modifiers, course and station routing; suite green (11 passed). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
d9e4b6e06e
commit
50b170b0af
@@ -58,11 +58,29 @@ class TicketController extends Controller
|
||||
$owner = $this->ownerRef($request);
|
||||
$sale->load('lines', 'table');
|
||||
|
||||
$products = PosProduct::owned($owner)->active()->orderBy('name')->get();
|
||||
$products = PosProduct::owned($owner)->active()
|
||||
->with(['category', 'modifierGroups.modifiers'])
|
||||
->orderBy('name')->get();
|
||||
|
||||
return view('pos.tickets.show', [
|
||||
'sale' => $sale,
|
||||
'products' => $products,
|
||||
'products' => $products->map(fn (PosProduct $p) => [
|
||||
'id' => $p->id,
|
||||
'name' => $p->name,
|
||||
'price_minor' => $p->price_minor,
|
||||
'category' => $p->category?->name,
|
||||
'modifier_groups' => $p->modifierGroups->map(fn ($g) => [
|
||||
'id' => $g->id,
|
||||
'name' => $g->name,
|
||||
'min' => $g->min_select,
|
||||
'max' => $g->max_select,
|
||||
'modifiers' => $g->modifiers->map(fn ($m) => [
|
||||
'id' => $m->id, 'name' => $m->name, 'price_delta_minor' => $m->price_delta_minor,
|
||||
])->values()->all(),
|
||||
])->values()->all(),
|
||||
])->values()->all(),
|
||||
'categories' => $products->pluck('category.name')->filter()->unique()->values()->all(),
|
||||
'courses' => PosSaleLine::COURSES,
|
||||
'lines' => $this->lineData($sale),
|
||||
]);
|
||||
}
|
||||
@@ -73,14 +91,53 @@ class TicketController extends Controller
|
||||
|
||||
$data = $request->validate([
|
||||
'product_id' => ['nullable', 'integer'],
|
||||
'name' => ['required', 'string', 'max:200'],
|
||||
'unit_price_minor' => ['required', 'integer', 'min:1'],
|
||||
'name' => ['nullable', 'string', 'max:200'],
|
||||
'unit_price_minor' => ['nullable', 'integer', 'min:1'],
|
||||
'quantity' => ['nullable', 'integer', 'min:1', 'max:999'],
|
||||
'notes' => ['nullable', 'string', 'max:200'],
|
||||
'course' => ['nullable', 'in:'.implode(',', array_keys(PosSaleLine::COURSES))],
|
||||
'modifier_ids' => ['nullable', 'array'],
|
||||
'modifier_ids.*' => ['integer'],
|
||||
]);
|
||||
|
||||
$payload = [
|
||||
'quantity' => $data['quantity'] ?? 1,
|
||||
'notes' => $data['notes'] ?? null,
|
||||
'course' => $data['course'] ?? null,
|
||||
];
|
||||
|
||||
if (! empty($data['product_id'])) {
|
||||
$product = PosProduct::owned($this->ownerRef($request))
|
||||
->with('modifierGroups.modifiers')
|
||||
->find($data['product_id']);
|
||||
|
||||
if (! $product) {
|
||||
return response()->json(['message' => 'Unknown product.'], 422);
|
||||
}
|
||||
|
||||
// Only modifiers that belong to this product's groups count.
|
||||
$allowed = $product->modifierGroups->flatMap->modifiers->keyBy('id');
|
||||
$chosen = collect($data['modifier_ids'] ?? [])
|
||||
->map(fn ($id) => $allowed->get((int) $id))
|
||||
->filter()
|
||||
->values();
|
||||
|
||||
$payload['product_id'] = $product->id;
|
||||
$payload['name'] = $product->name;
|
||||
$payload['station_id'] = $product->station_id;
|
||||
$payload['course'] = $payload['course'] ?? $product->course;
|
||||
$payload['unit_price_minor'] = max(1, $product->price_minor + (int) $chosen->sum('price_delta_minor'));
|
||||
$payload['modifiers'] = $chosen->map(fn ($m) => [
|
||||
'modifier_id' => $m->id, 'name' => $m->name, 'price_delta_minor' => $m->price_delta_minor,
|
||||
])->all();
|
||||
} else {
|
||||
// Custom (open-price) line.
|
||||
$payload['name'] = (string) ($data['name'] ?? '');
|
||||
$payload['unit_price_minor'] = (int) ($data['unit_price_minor'] ?? 0);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->sales->addLine($sale, $data);
|
||||
$this->sales->addLine($sale, $payload);
|
||||
} catch (RuntimeException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
@@ -117,7 +174,11 @@ class TicketController extends Controller
|
||||
{
|
||||
$this->authorizeOpen($request, $sale);
|
||||
|
||||
$fired = $this->sales->sendToKitchen($sale);
|
||||
$data = $request->validate([
|
||||
'course' => ['nullable', 'in:'.implode(',', array_keys(PosSaleLine::COURSES))],
|
||||
]);
|
||||
|
||||
$fired = $this->sales->sendToKitchen($sale, $data['course'] ?? null);
|
||||
$sale->refresh();
|
||||
|
||||
return response()->json([
|
||||
@@ -189,7 +250,7 @@ class TicketController extends Controller
|
||||
/** @return list<array<string,mixed>> */
|
||||
private function lineData(PosSale $sale): array
|
||||
{
|
||||
return $sale->lines()->orderBy('position')->get()->map(fn (PosSaleLine $l) => [
|
||||
return $sale->lines()->with('modifiers')->orderBy('position')->get()->map(fn (PosSaleLine $l) => [
|
||||
'id' => $l->id,
|
||||
'product_id' => $l->product_id,
|
||||
'name' => $l->name,
|
||||
@@ -198,6 +259,8 @@ class TicketController extends Controller
|
||||
'line_total_minor' => $l->line_total_minor,
|
||||
'kitchen_state' => $l->kitchen_state,
|
||||
'notes' => $l->notes,
|
||||
'course' => $l->course,
|
||||
'modifiers' => $l->modifiers->map(fn ($m) => $m->name)->all(),
|
||||
'fired' => $l->kitchen_state !== PosSaleLine::KITCHEN_NEW,
|
||||
])->all();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user