Restaurant mode Phase 2: menu depth — categories, stations, modifiers, courses
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:
isaacclad
2026-06-24 19:58:57 +00:00
co-authored by Claude Opus 4.8
parent d9e4b6e06e
commit 50b170b0af
21 changed files with 940 additions and 38 deletions
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
use App\Http\Controllers\Pos\Concerns\ScopesToAccount;
use App\Models\PosSale;
use App\Models\PosSaleLine;
use App\Models\PosStation;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
@@ -16,7 +17,9 @@ class KitchenController extends Controller
public function index(Request $request): View
{
return view('pos.kitchen.index');
return view('pos.kitchen.index', [
'stations' => PosStation::owned($this->ownerRef($request))->orderBy('name')->get(['id', 'name']),
]);
}
/**
@@ -29,7 +32,7 @@ class KitchenController extends Controller
$sales = PosSale::owned($owner)
->openTickets()
->where('kitchen_status', PosSale::KITCHEN_ACTIVE)
->with(['table', 'lines' => fn ($q) => $q->orderBy('position')])
->with(['table', 'lines' => fn ($q) => $q->orderBy('position')->with('modifiers', 'station')])
->orderBy('kitchen_sent_at')
->get();
@@ -57,6 +60,10 @@ class KitchenController extends Controller
'name' => $l->name,
'quantity' => $l->quantity,
'notes' => $l->notes,
'course' => $l->course,
'station' => $l->station?->name,
'station_id' => $l->station_id,
'modifiers' => $l->modifiers->map(fn ($m) => $m->name)->all(),
'state' => $l->kitchen_state,
])->all(),
];
+113
View File
@@ -0,0 +1,113 @@
<?php
namespace App\Http\Controllers\Pos;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Pos\Concerns\ScopesToAccount;
use App\Models\PosCategory;
use App\Models\PosModifier;
use App\Models\PosModifierGroup;
use App\Models\PosStation;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class MenuController extends Controller
{
use ScopesToAccount;
public function index(Request $request): View
{
$owner = $this->ownerRef($request);
return view('pos.menu.index', [
'categories' => PosCategory::owned($owner)->orderBy('position')->orderBy('name')->get(),
'stations' => PosStation::owned($owner)->orderBy('position')->orderBy('name')->get(),
'groups' => PosModifierGroup::owned($owner)->with('modifiers')->orderBy('position')->orderBy('name')->get(),
]);
}
public function storeCategory(Request $request): RedirectResponse
{
$data = $request->validate(['name' => ['required', 'string', 'max:80']]);
PosCategory::create(['owner_ref' => $this->ownerRef($request), 'name' => $data['name']]);
return back()->with('success', 'Category added.');
}
public function destroyCategory(Request $request, PosCategory $category): RedirectResponse
{
$this->authorizeOwner($request, $category);
$category->delete();
return back()->with('success', 'Category removed.');
}
public function storeStation(Request $request): RedirectResponse
{
$data = $request->validate(['name' => ['required', 'string', 'max:80']]);
PosStation::create(['owner_ref' => $this->ownerRef($request), 'name' => $data['name']]);
return back()->with('success', 'Station added.');
}
public function destroyStation(Request $request, PosStation $station): RedirectResponse
{
$this->authorizeOwner($request, $station);
$station->delete();
return back()->with('success', 'Station removed.');
}
public function storeGroup(Request $request): RedirectResponse
{
$data = $request->validate([
'name' => ['required', 'string', 'max:80'],
'min_select' => ['nullable', 'integer', 'min:0', 'max:20'],
'max_select' => ['nullable', 'integer', 'min:0', 'max:20'],
]);
PosModifierGroup::create([
'owner_ref' => $this->ownerRef($request),
'name' => $data['name'],
'min_select' => $data['min_select'] ?? 0,
'max_select' => $data['max_select'] ?: null,
]);
return back()->with('success', 'Modifier group added.');
}
public function destroyGroup(Request $request, PosModifierGroup $group): RedirectResponse
{
$this->authorizeOwner($request, $group);
$group->delete();
return back()->with('success', 'Modifier group removed.');
}
public function storeModifier(Request $request, PosModifierGroup $group): RedirectResponse
{
$this->authorizeOwner($request, $group);
$data = $request->validate([
'name' => ['required', 'string', 'max:80'],
'price_delta' => ['nullable', 'numeric', 'min:-9999', 'max:9999'],
]);
$group->modifiers()->create([
'owner_ref' => $group->owner_ref,
'name' => $data['name'],
'price_delta_minor' => (int) round(((float) ($data['price_delta'] ?? 0)) * 100),
]);
return back()->with('success', 'Option added.');
}
public function destroyModifier(Request $request, PosModifier $modifier): RedirectResponse
{
$this->authorizeOwner($request, $modifier);
$modifier->delete();
return back()->with('success', 'Option removed.');
}
}
+58 -7
View File
@@ -4,7 +4,12 @@ namespace App\Http\Controllers\Pos;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Pos\Concerns\ScopesToAccount;
use App\Models\PosCategory;
use App\Models\PosLocation;
use App\Models\PosModifierGroup;
use App\Models\PosProduct;
use App\Models\PosSaleLine;
use App\Models\PosStation;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
@@ -16,6 +21,7 @@ class ProductController extends Controller
public function index(Request $request): View
{
$products = PosProduct::owned($this->ownerRef($request))
->with('category')
->orderBy('name')
->paginate(30)
->withQueryString();
@@ -23,20 +29,25 @@ class ProductController extends Controller
return view('pos.products.index', compact('products'));
}
public function create(): View
public function create(Request $request): View
{
return view('pos.products.create', ['product' => new PosProduct([
'currency' => config('pos.default_currency', 'GHS'),
'is_active' => true,
])]);
return view('pos.products.create', [
'product' => new PosProduct([
'currency' => config('pos.default_currency', 'GHS'),
'is_active' => true,
]),
'selectedGroups' => [],
...$this->formOptions($request),
]);
}
public function store(Request $request): RedirectResponse
{
PosProduct::create([
$product = PosProduct::create([
...$this->validated($request),
'owner_ref' => $this->ownerRef($request),
]);
$product->modifierGroups()->sync($this->groupIds($request));
return redirect()->route('pos.products.index')->with('success', 'Product added.');
}
@@ -45,13 +56,18 @@ class ProductController extends Controller
{
$this->authorizeOwner($request, $product);
return view('pos.products.edit', compact('product'));
return view('pos.products.edit', [
'product' => $product,
'selectedGroups' => $product->modifierGroups()->pluck('pos_modifier_groups.id')->all(),
...$this->formOptions($request),
]);
}
public function update(Request $request, PosProduct $product): RedirectResponse
{
$this->authorizeOwner($request, $product);
$product->update($this->validated($request));
$product->modifierGroups()->sync($this->groupIds($request));
return redirect()->route('pos.products.index')->with('success', 'Product updated.');
}
@@ -64,23 +80,58 @@ class ProductController extends Controller
return redirect()->route('pos.products.index')->with('success', 'Product removed.');
}
/** @return array<string, mixed> */
private function formOptions(Request $request): array
{
$owner = $this->ownerRef($request);
return [
'restaurant' => PosLocation::owned($owner)->where('service_style', PosLocation::STYLE_RESTAURANT)->exists(),
'categories' => PosCategory::owned($owner)->orderBy('name')->get(),
'stations' => PosStation::owned($owner)->orderBy('name')->get(),
'modifierGroups' => PosModifierGroup::owned($owner)->orderBy('name')->get(),
];
}
/** @return list<int> */
private function groupIds(Request $request): array
{
$owner = $this->ownerRef($request);
$ids = array_map('intval', (array) $request->input('modifier_group_ids', []));
return PosModifierGroup::owned($owner)->whereIn('id', $ids)->pluck('id')->all();
}
/** @return array<string, mixed> */
private function validated(Request $request): array
{
$owner = $this->ownerRef($request);
$data = $request->validate([
'name' => ['required', 'string', 'max:200'],
'sku' => ['nullable', 'string', 'max:80'],
'price' => ['required', 'numeric', 'min:0.01'],
'currency' => ['nullable', 'string', 'size:3'],
'is_active' => ['sometimes', 'boolean'],
'category_id' => ['nullable', 'integer'],
'station_id' => ['nullable', 'integer'],
'course' => ['nullable', 'in:'.implode(',', array_keys(PosSaleLine::COURSES))],
]);
$categoryId = ($data['category_id'] ?? null) && PosCategory::owned($owner)->whereKey($data['category_id'])->exists()
? (int) $data['category_id'] : null;
$stationId = ($data['station_id'] ?? null) && PosStation::owned($owner)->whereKey($data['station_id'])->exists()
? (int) $data['station_id'] : null;
return [
'name' => $data['name'],
'sku' => $data['sku'] ?? null,
'price_minor' => (int) round(((float) $data['price']) * 100),
'currency' => strtoupper($data['currency'] ?? config('pos.default_currency', 'GHS')),
'is_active' => $request->boolean('is_active', true),
'category_id' => $categoryId,
'station_id' => $stationId,
'course' => $data['course'] ?? null,
];
}
}
+70 -7
View File
@@ -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();
}
+22
View File
@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class PosCategory extends Model
{
protected $fillable = ['owner_ref', 'name', 'position'];
public function products(): HasMany
{
return $this->hasMany(PosProduct::class, 'category_id');
}
public function scopeOwned(Builder $query, string $ownerRef): Builder
{
return $query->where('owner_ref', $ownerRef);
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PosModifier extends Model
{
protected $fillable = ['modifier_group_id', 'owner_ref', 'name', 'price_delta_minor', 'position'];
protected function casts(): array
{
return ['price_delta_minor' => 'integer'];
}
public function group(): BelongsTo
{
return $this->belongsTo(PosModifierGroup::class, 'modifier_group_id');
}
public function scopeOwned(Builder $query, string $ownerRef): Builder
{
return $query->where('owner_ref', $ownerRef);
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
class PosModifierGroup extends Model
{
protected $fillable = ['owner_ref', 'name', 'min_select', 'max_select', 'position'];
protected function casts(): array
{
return ['min_select' => 'integer', 'max_select' => 'integer'];
}
public function modifiers(): HasMany
{
return $this->hasMany(PosModifier::class, 'modifier_group_id')->orderBy('position')->orderBy('id');
}
public function products(): BelongsToMany
{
return $this->belongsToMany(PosProduct::class, 'pos_product_modifier_group', 'modifier_group_id', 'product_id');
}
public function scopeOwned(Builder $query, string $ownerRef): Builder
{
return $query->where('owner_ref', $ownerRef);
}
}
+19
View File
@@ -5,12 +5,16 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class PosProduct extends Model
{
protected $fillable = [
'owner_ref',
'location_id',
'category_id',
'station_id',
'course',
'name',
'sku',
'price_minor',
@@ -31,6 +35,21 @@ class PosProduct extends Model
return $this->belongsTo(PosLocation::class, 'location_id');
}
public function category(): BelongsTo
{
return $this->belongsTo(PosCategory::class, 'category_id');
}
public function station(): BelongsTo
{
return $this->belongsTo(PosStation::class, 'station_id');
}
public function modifierGroups(): BelongsToMany
{
return $this->belongsToMany(PosModifierGroup::class, 'pos_product_modifier_group', 'product_id', 'modifier_group_id');
}
public function scopeOwned(Builder $query, string $ownerRef): Builder
{
return $query->where('owner_ref', $ownerRef);
+20
View File
@@ -20,9 +20,18 @@ class PosSaleLine extends Model
/** States the KDS bump button cycles through, in order. */
public const KITCHEN_FLOW = [self::KITCHEN_QUEUED, self::KITCHEN_PREPARING, self::KITCHEN_READY, self::KITCHEN_SERVED];
/** Ordered courses for fire-by-course (key => label). */
public const COURSES = [
'starter' => 'Starter',
'main' => 'Main',
'dessert' => 'Dessert',
'drink' => 'Drink',
];
protected $fillable = [
'pos_sale_id',
'product_id',
'station_id',
'name',
'unit_price_minor',
'quantity',
@@ -30,6 +39,7 @@ class PosSaleLine extends Model
'position',
'kitchen_state',
'notes',
'course',
];
protected function casts(): array
@@ -51,4 +61,14 @@ class PosSaleLine extends Model
{
return $this->belongsTo(PosProduct::class, 'product_id');
}
public function station(): BelongsTo
{
return $this->belongsTo(PosStation::class, 'station_id');
}
public function modifiers(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(PosSaleLineModifier::class, 'pos_sale_line_id');
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PosSaleLineModifier extends Model
{
protected $fillable = ['pos_sale_line_id', 'modifier_id', 'name', 'price_delta_minor'];
protected function casts(): array
{
return ['price_delta_minor' => 'integer'];
}
public function line(): BelongsTo
{
return $this->belongsTo(PosSaleLine::class, 'pos_sale_line_id');
}
}
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class PosStation extends Model
{
protected $fillable = ['owner_ref', 'name', 'position'];
public function scopeOwned(Builder $query, string $ownerRef): Builder
{
return $query->where('owner_ref', $ownerRef);
}
}
+25 -6
View File
@@ -4,6 +4,7 @@ namespace App\Services\Pos;
use App\Models\PosSale;
use App\Models\PosSaleLine;
use App\Models\PosSaleLineModifier;
use App\Models\PosTable;
use App\Models\User;
use App\Services\Pay\PayClient;
@@ -113,7 +114,7 @@ class PosSaleService
}
/**
* @param array{product_id?: ?int, name: string, unit_price_minor: int, quantity?: int, notes?: ?string} $line
* @param array{product_id?: ?int, station_id?: ?int, course?: ?string, name: string, unit_price_minor: int, quantity?: int, notes?: ?string, modifiers?: list<array{modifier_id?: ?int, name: string, price_delta_minor?: int}>} $line
*/
public function addLine(PosSale $sale, array $line): PosSaleLine
{
@@ -130,6 +131,7 @@ class PosSaleService
$created = PosSaleLine::create([
'pos_sale_id' => $sale->id,
'product_id' => $line['product_id'] ?? null,
'station_id' => $line['station_id'] ?? null,
'name' => $name,
'unit_price_minor' => $unit,
'quantity' => $qty,
@@ -137,8 +139,22 @@ class PosSaleService
'position' => $position,
'kitchen_state' => PosSaleLine::KITCHEN_NEW,
'notes' => isset($line['notes']) ? trim((string) $line['notes']) ?: null : null,
'course' => $line['course'] ?? null,
]);
foreach (($line['modifiers'] ?? []) as $mod) {
$modName = trim((string) ($mod['name'] ?? ''));
if ($modName === '') {
continue;
}
PosSaleLineModifier::create([
'pos_sale_line_id' => $created->id,
'modifier_id' => $mod['modifier_id'] ?? null,
'name' => $modName,
'price_delta_minor' => (int) ($mod['price_delta_minor'] ?? 0),
]);
}
$this->recomputeTotals($sale);
return $created;
@@ -181,15 +197,18 @@ class PosSaleService
}
/**
* Fire all not-yet-sent lines to the kitchen.
* Fire not-yet-sent lines to the kitchen. Pass a course to fire just that course.
*
* @return int number of lines fired
*/
public function sendToKitchen(PosSale $sale): int
public function sendToKitchen(PosSale $sale, ?string $course = null): int
{
$fired = $sale->lines()
->where('kitchen_state', PosSaleLine::KITCHEN_NEW)
->update(['kitchen_state' => PosSaleLine::KITCHEN_QUEUED]);
$query = $sale->lines()->where('kitchen_state', PosSaleLine::KITCHEN_NEW);
if ($course !== null && $course !== '') {
$query->where('course', $course);
}
$fired = $query->update(['kitchen_state' => PosSaleLine::KITCHEN_QUEUED]);
if ($fired > 0) {
$sale->forceFill([
@@ -0,0 +1,91 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('pos_categories', function (Blueprint $table) {
$table->id();
$table->string('owner_ref')->index();
$table->string('name');
$table->unsignedInteger('position')->default(0);
$table->timestamps();
});
Schema::create('pos_stations', function (Blueprint $table) {
$table->id();
$table->string('owner_ref')->index();
$table->string('name');
$table->unsignedInteger('position')->default(0);
$table->timestamps();
});
Schema::create('pos_modifier_groups', function (Blueprint $table) {
$table->id();
$table->string('owner_ref')->index();
$table->string('name');
$table->unsignedSmallInteger('min_select')->default(0);
$table->unsignedSmallInteger('max_select')->nullable(); // null = unlimited
$table->unsignedInteger('position')->default(0);
$table->timestamps();
});
Schema::create('pos_modifiers', function (Blueprint $table) {
$table->id();
$table->foreignId('modifier_group_id')->constrained('pos_modifier_groups')->cascadeOnDelete();
$table->string('owner_ref')->index();
$table->string('name');
$table->integer('price_delta_minor')->default(0); // signed: add-ons positive, omissions negative
$table->unsignedInteger('position')->default(0);
$table->timestamps();
});
Schema::create('pos_product_modifier_group', function (Blueprint $table) {
$table->id();
$table->foreignId('product_id')->constrained('pos_products')->cascadeOnDelete();
$table->foreignId('modifier_group_id')->constrained('pos_modifier_groups')->cascadeOnDelete();
$table->unique(['product_id', 'modifier_group_id']);
});
Schema::create('pos_sale_line_modifiers', function (Blueprint $table) {
$table->id();
$table->foreignId('pos_sale_line_id')->constrained('pos_sale_lines')->cascadeOnDelete();
$table->unsignedBigInteger('modifier_id')->nullable(); // snapshot reference, plain
$table->string('name');
$table->integer('price_delta_minor')->default(0);
$table->timestamps();
});
// Plain columns (no ALTER-time FK — SQLite compat); resolved in app logic.
Schema::table('pos_products', function (Blueprint $table) {
$table->unsignedBigInteger('category_id')->nullable()->after('location_id')->index();
$table->unsignedBigInteger('station_id')->nullable()->after('category_id')->index();
$table->string('course')->nullable()->after('station_id');
});
Schema::table('pos_sale_lines', function (Blueprint $table) {
$table->unsignedBigInteger('station_id')->nullable()->after('product_id')->index();
$table->string('course')->nullable()->after('notes');
});
}
public function down(): void
{
Schema::table('pos_sale_lines', function (Blueprint $table) {
$table->dropColumn(['station_id', 'course']);
});
Schema::table('pos_products', function (Blueprint $table) {
$table->dropColumn(['category_id', 'station_id', 'course']);
});
Schema::dropIfExists('pos_sale_line_modifiers');
Schema::dropIfExists('pos_product_modifier_group');
Schema::dropIfExists('pos_modifiers');
Schema::dropIfExists('pos_modifier_groups');
Schema::dropIfExists('pos_stations');
Schema::dropIfExists('pos_categories');
}
};
+69 -5
View File
@@ -335,11 +335,63 @@ Alpine.data('posTicket', (config = {}) => ({
busy: false,
flash: '',
activeCategory: '',
picker: { open: false, product: null, groups: [], notes: '', course: '' },
courseLabels: config.courseLabels || {},
money(minor) { return this.currency + ' ' + ((minor || 0) / 100).toFixed(2); },
get hasNew() { return this.lines.some((l) => ! l.fired); },
get categories() {
const set = [];
this.products.forEach((p) => { if (p.category && ! set.includes(p.category)) set.push(p.category); });
return set;
},
get filteredProducts() {
const q = this.search.trim().toLowerCase();
return q ? this.products.filter((p) => p.name.toLowerCase().includes(q)) : this.products;
return this.products.filter((p) =>
(! this.activeCategory || p.category === this.activeCategory)
&& (! q || p.name.toLowerCase().includes(q)));
},
get newCourses() {
const s = [];
this.lines.forEach((l) => { if (! l.fired) { const c = l.course || ''; if (! s.includes(c)) s.push(c); } });
return s;
},
courseLabel(c) { return this.courseLabels[c] || 'No course'; },
// Modifier picker
tap(p) {
if (p.modifier_groups && p.modifier_groups.length) this.openPicker(p);
else this.addProduct(p, {});
},
openPicker(p) {
this.flash = '';
this.picker = {
open: true, product: p, notes: '', course: '',
groups: p.modifier_groups.map((g) => ({ ...g, selected: [] })),
};
},
closePicker() { this.picker.open = false; },
isSelected(g, m) { return g.selected.includes(m.id); },
toggleModifier(g, m) {
const i = g.selected.indexOf(m.id);
if (i >= 0) { g.selected.splice(i, 1); return; }
if (g.max === 1) { g.selected = [m.id]; return; }
if (g.max && g.selected.length >= g.max) return;
g.selected.push(m.id);
},
get pickerPrice() {
if (! this.picker.product) return 0;
let total = this.picker.product.price_minor;
this.picker.groups.forEach((g) => g.modifiers.forEach((m) => { if (g.selected.includes(m.id)) total += m.price_delta_minor; }));
return total;
},
get pickerValid() { return this.picker.groups.every((g) => g.selected.length >= (g.min || 0)); },
confirmPicker() {
if (! this.pickerValid) { this.flash = 'Choose the required options.'; return; }
const ids = this.picker.groups.flatMap((g) => g.selected);
this.addProduct(this.picker.product, { modifier_ids: ids, notes: this.picker.notes, course: this.picker.course });
this.closePicker();
},
async req(method, url, body) {
@@ -367,17 +419,21 @@ Alpine.data('posTicket', (config = {}) => ({
},
apply(data) { if (data) { this.lines = data.lines; this.totalMinor = data.total_minor; } },
async addProduct(p) {
async addProduct(p, opts = {}) {
this.apply(await this.req('POST', this.base + '/lines', {
product_id: p.id, name: p.name, unit_price_minor: p.price_minor, quantity: 1,
product_id: p.id,
quantity: 1,
modifier_ids: opts.modifier_ids || [],
notes: opts.notes || null,
course: opts.course || null,
}));
},
async setQty(line, qty) { this.apply(await this.req('PATCH', this.base + '/lines/' + line.id, { quantity: qty })); },
inc(line) { this.setQty(line, line.quantity + 1); },
dec(line) { this.setQty(line, line.quantity - 1); },
async remove(line) { this.apply(await this.req('DELETE', this.base + '/lines/' + line.id)); },
async send() {
const data = await this.req('POST', this.base + '/send', {});
async send(course = null) {
const data = await this.req('POST', this.base + '/send', { course });
this.apply(data);
if (data) this.flash = data.fired > 0 ? ('Sent ' + data.fired + ' item(s) to the kitchen.') : 'Nothing new to send.';
},
@@ -392,12 +448,20 @@ Alpine.data('posKitchen', (config = {}) => ({
csrf: config.csrf || document.querySelector('meta[name="csrf-token"]')?.content || '',
now: Date.now(),
loaded: false,
activeStation: '',
init() {
this.load();
setInterval(() => this.load(), 4000);
setInterval(() => { this.now = Date.now(); }, 1000);
},
get visibleTickets() {
if (! this.activeStation) return this.tickets;
const sid = String(this.activeStation);
return this.tickets
.map((t) => ({ ...t, lines: t.lines.filter((l) => String(l.station_id || '') === sid) }))
.filter((t) => t.lines.length);
},
async load() {
try {
const res = await fetch(this.feedUrl, { headers: { Accept: 'application/json', 'X-Requested-With': 'XMLHttpRequest' } });
@@ -23,6 +23,8 @@
'icon' => '<path stroke-linecap="round" stroke-linejoin="round" d="M3.75 6A2.25 2.25 0 0 1 6 3.75h2.25A2.25 2.25 0 0 1 10.5 6v2.25a2.25 2.25 0 0 1-2.25 2.25H6a2.25 2.25 0 0 1-2.25-2.25V6ZM3.75 15.75A2.25 2.25 0 0 1 6 13.5h2.25a2.25 2.25 0 0 1 2.25 2.25V18a2.25 2.25 0 0 1-2.25 2.25H6A2.25 2.25 0 0 1 3.75 18v-2.25ZM13.5 6a2.25 2.25 0 0 1 2.25-2.25H18A2.25 2.25 0 0 1 20.25 6v2.25A2.25 2.25 0 0 1 18 10.5h-2.25a2.25 2.25 0 0 1-2.25-2.25V6ZM13.5 15.75a2.25 2.25 0 0 1 2.25-2.25H18a2.25 2.25 0 0 1 2.25 2.25V18A2.25 2.25 0 0 1 18 20.25h-2.25A2.25 2.25 0 0 1 13.5 18v-2.25Z" />'],
['name' => 'Kitchen', 'route' => route('pos.kitchen'), 'active' => request()->routeIs('pos.kitchen'),
'icon' => '<path stroke-linecap="round" stroke-linejoin="round" d="M15.362 5.214A8.252 8.252 0 0 1 12 21 8.25 8.25 0 0 1 6.038 7.047 8.287 8.287 0 0 0 9 9.601a8.983 8.983 0 0 1 3.361-6.867 8.21 8.21 0 0 0 3 2.48Z" /><path stroke-linecap="round" stroke-linejoin="round" d="M12 18a3.75 3.75 0 0 0 .495-7.468 5.99 5.99 0 0 0-1.925 3.547 5.975 5.975 0 0 1-2.133-1.001A3.75 3.75 0 0 0 12 18Z" />'],
['name' => 'Menu setup', 'route' => route('pos.menu'), 'active' => request()->routeIs('pos.menu'),
'icon' => '<path stroke-linecap="round" stroke-linejoin="round" d="M3.75 12h16.5m-16.5 3.75h16.5M3.75 19.5h16.5M5.625 4.5h12.75a1.875 1.875 0 0 1 0 3.75H5.625a1.875 1.875 0 0 1 0-3.75Z" />'],
]);
}
@endphp
+20 -3
View File
@@ -12,14 +12,26 @@
<button type="button" @click="load()" class="rounded-xl border border-slate-200 bg-white px-3 py-2 text-sm font-medium text-slate-600 hover:bg-slate-50">Refresh</button>
</div>
<template x-if="loaded && tickets.length === 0">
@if($stations->isNotEmpty())
<div class="flex flex-wrap gap-1.5">
<button type="button" @click="activeStation = ''" :class="activeStation === '' ? 'bg-indigo-600 text-white' : 'bg-slate-100 text-slate-600'"
class="rounded-full px-3 py-1 text-xs font-medium">All stations</button>
@foreach($stations as $station)
<button type="button" @click="activeStation = '{{ $station->id }}'"
:class="activeStation === '{{ $station->id }}' ? 'bg-indigo-600 text-white' : 'bg-slate-100 text-slate-600'"
class="rounded-full px-3 py-1 text-xs font-medium">{{ $station->name }}</button>
@endforeach
</div>
@endif
<template x-if="loaded && visibleTickets.length === 0">
<div class="rounded-2xl border border-dashed border-slate-200 bg-white px-6 py-16 text-center">
<p class="text-sm text-slate-500">No active tickets. Fired orders will appear here.</p>
</div>
</template>
<div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
<template x-for="t in tickets" :key="t.id">
<template x-for="t in visibleTickets" :key="t.id">
<div class="flex flex-col overflow-hidden rounded-2xl border border-slate-200 bg-white">
<div class="flex items-center justify-between border-b border-slate-100 bg-slate-50 px-4 py-2.5">
<div>
@@ -37,8 +49,13 @@
<span x-text="line.quantity + '×'"></span>
<span x-text="line.name"></span>
</p>
<p x-show="line.modifiers.length" x-cloak class="text-xs text-slate-500" x-text="line.modifiers.join(', ')"></p>
<p x-show="line.notes" x-cloak class="text-xs text-rose-600" x-text="line.notes"></p>
<p class="text-[11px] uppercase tracking-wide text-slate-400" x-text="line.state"></p>
<div class="mt-0.5 flex items-center gap-1.5">
<span x-show="line.course" x-cloak class="rounded bg-slate-100 px-1.5 text-[10px] font-medium text-slate-500" x-text="line.course"></span>
<span x-show="line.station" x-cloak class="rounded bg-indigo-50 px-1.5 text-[10px] font-medium text-indigo-600" x-text="line.station"></span>
<span class="text-[11px] uppercase tracking-wide text-slate-400" x-text="line.state"></span>
</div>
</div>
<button type="button" @click="bump(line)"
class="shrink-0 rounded-lg border border-slate-200 bg-white px-2.5 py-1.5 text-xs font-semibold text-slate-700 hover:bg-slate-50"
+128
View File
@@ -0,0 +1,128 @@
<x-app-layout title="Menu setup">
<div class="mx-auto max-w-3xl space-y-6">
<div>
<h1 class="text-lg font-semibold text-slate-900">Menu setup</h1>
<p class="mt-1 text-sm text-slate-500">Categories, kitchen stations, and modifier options for your products.</p>
</div>
<div class="grid gap-6 sm:grid-cols-2">
{{-- Categories --}}
<section class="rounded-2xl border border-slate-200 bg-white p-5">
<h2 class="text-sm font-semibold text-slate-900">Categories</h2>
<p class="mt-1 text-xs text-slate-400">Group products on the register (e.g. Coffee, Food).</p>
<form method="POST" action="{{ route('pos.menu.categories.store') }}" class="mt-3 flex gap-2">
@csrf
<input type="text" name="name" placeholder="New category" required
class="flex-1 rounded-xl border-slate-300 text-sm focus:border-indigo-500 focus:ring-indigo-500">
<button class="btn-primary">Add</button>
</form>
<ul class="mt-3 divide-y divide-slate-100">
@forelse ($categories as $category)
<li class="flex items-center justify-between py-2 text-sm">
<span class="text-slate-800">{{ $category->name }}</span>
<form method="POST" action="{{ route('pos.menu.categories.destroy', $category) }}" onsubmit="return confirm('Remove category?');">
@csrf @method('DELETE')
<button class="text-xs font-medium text-red-500 hover:text-red-700">Remove</button>
</form>
</li>
@empty
<li class="py-2 text-xs text-slate-400">No categories yet.</li>
@endforelse
</ul>
</section>
{{-- Stations --}}
<section class="rounded-2xl border border-slate-200 bg-white p-5">
<h2 class="text-sm font-semibold text-slate-900">Kitchen stations</h2>
<p class="mt-1 text-xs text-slate-400">Route items to a prep station (e.g. Kitchen, Bar).</p>
<form method="POST" action="{{ route('pos.menu.stations.store') }}" class="mt-3 flex gap-2">
@csrf
<input type="text" name="name" placeholder="New station" required
class="flex-1 rounded-xl border-slate-300 text-sm focus:border-indigo-500 focus:ring-indigo-500">
<button class="btn-primary">Add</button>
</form>
<ul class="mt-3 divide-y divide-slate-100">
@forelse ($stations as $station)
<li class="flex items-center justify-between py-2 text-sm">
<span class="text-slate-800">{{ $station->name }}</span>
<form method="POST" action="{{ route('pos.menu.stations.destroy', $station) }}" onsubmit="return confirm('Remove station?');">
@csrf @method('DELETE')
<button class="text-xs font-medium text-red-500 hover:text-red-700">Remove</button>
</form>
</li>
@empty
<li class="py-2 text-xs text-slate-400">No stations yet.</li>
@endforelse
</ul>
</section>
</div>
{{-- Modifier groups --}}
<section class="rounded-2xl border border-slate-200 bg-white p-5">
<div class="flex items-start justify-between gap-3">
<div>
<h2 class="text-sm font-semibold text-slate-900">Modifier groups</h2>
<p class="mt-1 text-xs text-slate-400">Options like Size or Add-ons. Attach groups to products on the product form.</p>
</div>
</div>
<form method="POST" action="{{ route('pos.menu.groups.store') }}" class="mt-3 grid gap-2 sm:grid-cols-[1fr_6rem_6rem_auto]">
@csrf
<input type="text" name="name" placeholder="Group name (e.g. Size)" required
class="rounded-xl border-slate-300 text-sm focus:border-indigo-500 focus:ring-indigo-500">
<input type="number" name="min_select" value="0" min="0" max="20" title="Minimum to choose"
class="rounded-xl border-slate-300 text-sm focus:border-indigo-500 focus:ring-indigo-500" placeholder="Min">
<input type="number" name="max_select" min="0" max="20" title="Maximum to choose (blank = any)"
class="rounded-xl border-slate-300 text-sm focus:border-indigo-500 focus:ring-indigo-500" placeholder="Max">
<button class="btn-primary">Add</button>
</form>
<div class="mt-4 space-y-4">
@forelse ($groups as $group)
<div class="rounded-xl border border-slate-200 p-4">
<div class="flex items-center justify-between">
<p class="text-sm font-semibold text-slate-900">
{{ $group->name }}
<span class="ml-1 text-xs font-normal text-slate-400">
choose {{ $group->min_select }}{{ $group->max_select ?? 'any' }}
</span>
</p>
<form method="POST" action="{{ route('pos.menu.groups.destroy', $group) }}" onsubmit="return confirm('Remove group and its options?');">
@csrf @method('DELETE')
<button class="text-xs font-medium text-red-500 hover:text-red-700">Remove group</button>
</form>
</div>
<ul class="mt-2 divide-y divide-slate-100">
@foreach ($group->modifiers as $modifier)
<li class="flex items-center justify-between py-1.5 text-sm">
<span class="text-slate-700">
{{ $modifier->name }}
@if ($modifier->price_delta_minor !== 0)
<span class="text-xs text-slate-400">({{ $modifier->price_delta_minor > 0 ? '+' : '' }}{{ number_format($modifier->price_delta_minor / 100, 2) }})</span>
@endif
</span>
<form method="POST" action="{{ route('pos.menu.modifiers.destroy', $modifier) }}">
@csrf @method('DELETE')
<button class="text-xs text-red-500 hover:text-red-700">×</button>
</form>
</li>
@endforeach
</ul>
<form method="POST" action="{{ route('pos.menu.modifiers.store', $group) }}" class="mt-2 flex gap-2">
@csrf
<input type="text" name="name" placeholder="Option (e.g. Large)" required
class="flex-1 rounded-lg border-slate-300 text-sm focus:border-indigo-500 focus:ring-indigo-500">
<input type="number" name="price_delta" step="0.01" placeholder="±price"
class="w-24 rounded-lg border-slate-300 text-sm focus:border-indigo-500 focus:ring-indigo-500">
<button class="rounded-lg border border-slate-200 px-3 py-1.5 text-sm font-medium text-slate-700 hover:bg-slate-50">Add option</button>
</form>
</div>
@empty
<p class="text-xs text-slate-400">No modifier groups yet.</p>
@endforelse
</div>
</section>
</div>
</x-app-layout>
@@ -21,3 +21,57 @@
class="rounded border-slate-300 text-indigo-600 focus:ring-indigo-500">
<label for="is_active" class="text-sm text-slate-700">Show on register</label>
</div>
@if (($restaurant ?? false))
<div class="space-y-4 rounded-xl border border-slate-200 bg-slate-50/60 p-4">
<p class="text-xs font-semibold uppercase tracking-wide text-slate-400">Restaurant</p>
<div class="grid gap-4 sm:grid-cols-3">
<div>
<label for="category_id" class="text-sm font-medium text-slate-700">Category</label>
<select id="category_id" name="category_id" class="mt-1.5 block w-full rounded-xl border-slate-300 text-sm focus:border-indigo-500 focus:ring-indigo-500">
<option value=""></option>
@foreach (($categories ?? []) as $category)
<option value="{{ $category->id }}" @selected((int) old('category_id', $product->category_id) === $category->id)>{{ $category->name }}</option>
@endforeach
</select>
</div>
<div>
<label for="station_id" class="text-sm font-medium text-slate-700">Kitchen station</label>
<select id="station_id" name="station_id" class="mt-1.5 block w-full rounded-xl border-slate-300 text-sm focus:border-indigo-500 focus:ring-indigo-500">
<option value=""></option>
@foreach (($stations ?? []) as $station)
<option value="{{ $station->id }}" @selected((int) old('station_id', $product->station_id) === $station->id)>{{ $station->name }}</option>
@endforeach
</select>
</div>
<div>
<label for="course" class="text-sm font-medium text-slate-700">Default course</label>
<select id="course" name="course" class="mt-1.5 block w-full rounded-xl border-slate-300 text-sm focus:border-indigo-500 focus:ring-indigo-500">
<option value=""></option>
@foreach (\App\Models\PosSaleLine::COURSES as $key => $label)
<option value="{{ $key }}" @selected(old('course', $product->course) === $key)>{{ $label }}</option>
@endforeach
</select>
</div>
</div>
@if (! empty($modifierGroups) && count($modifierGroups))
<div>
<p class="text-sm font-medium text-slate-700">Modifier groups</p>
<div class="mt-2 grid gap-2 sm:grid-cols-2">
@foreach ($modifierGroups as $group)
<label class="flex items-center gap-2 rounded-lg border border-slate-200 bg-white px-3 py-2 text-sm">
<input type="checkbox" name="modifier_group_ids[]" value="{{ $group->id }}"
@checked(in_array($group->id, old('modifier_group_ids', $selectedGroups ?? []) ?: [], false))
class="rounded border-slate-300 text-indigo-600 focus:ring-indigo-500">
<span class="text-slate-700">{{ $group->name }}</span>
</label>
@endforeach
</div>
</div>
@else
<p class="text-xs text-slate-400">Add modifier groups under Menu setup to attach options here.</p>
@endif
</div>
@endif
+88 -8
View File
@@ -2,9 +2,10 @@
<div x-data="posTicket(@js([
'base' => route('pos.tickets.show', $sale),
'lines' => $lines,
'products' => $products->map(fn ($p) => ['id' => $p->id, 'name' => $p->name, 'price_minor' => $p->price_minor])->values()->all(),
'products' => $products,
'totalMinor' => $sale->total_minor,
'currency' => $sale->currency,
'courseLabels' => $courses,
]))" class="space-y-4">
<div class="flex flex-wrap items-center justify-between gap-3">
@@ -27,12 +28,23 @@
<div class="rounded-2xl border border-slate-200 bg-white p-4">
<input type="search" x-model="search" placeholder="Search items…"
class="mb-3 w-full rounded-xl border-slate-200 text-sm focus:border-indigo-500 focus:ring-indigo-500">
<div x-show="categories.length" class="mb-3 flex flex-wrap gap-1.5">
<button type="button" @click="activeCategory = ''" :class="activeCategory === '' ? 'bg-indigo-600 text-white' : 'bg-slate-100 text-slate-600'"
class="rounded-full px-3 py-1 text-xs font-medium">All</button>
<template x-for="c in categories" :key="c">
<button type="button" @click="activeCategory = c" :class="activeCategory === c ? 'bg-indigo-600 text-white' : 'bg-slate-100 text-slate-600'"
class="rounded-full px-3 py-1 text-xs font-medium" x-text="c"></button>
</template>
</div>
<div class="grid grid-cols-2 gap-2 sm:grid-cols-3">
<template x-for="p in filteredProducts" :key="p.id">
<button type="button" @click="addProduct(p)" :disabled="busy"
<button type="button" @click="tap(p)" :disabled="busy"
class="rounded-xl border border-slate-200 p-3 text-left transition hover:border-indigo-300 hover:bg-indigo-50/50 disabled:opacity-50">
<span class="block text-sm font-medium text-slate-900" x-text="p.name"></span>
<span class="mt-1 block text-xs text-slate-500" x-text="money(p.price_minor)"></span>
<span x-show="p.modifier_groups.length" class="mt-1 inline-block text-[10px] font-medium text-indigo-500">options</span>
</button>
</template>
<template x-if="filteredProducts.length === 0">
@@ -52,8 +64,12 @@
<div class="flex items-start justify-between gap-2">
<div class="min-w-0">
<p class="truncate text-sm font-medium text-slate-900" x-text="line.name"></p>
<p class="text-xs text-slate-400" x-text="money(line.unit_price_minor)"></p>
<span x-show="line.fired" x-cloak class="mt-1 inline-block rounded-full bg-amber-50 px-1.5 py-0.5 text-[10px] font-medium text-amber-700">In kitchen</span>
<p x-show="line.modifiers.length" x-cloak class="text-xs text-slate-500" x-text="line.modifiers.join(', ')"></p>
<p x-show="line.notes" x-cloak class="text-xs text-rose-600" x-text="line.notes"></p>
<div class="mt-1 flex items-center gap-1.5">
<span x-show="line.course" x-cloak class="rounded-full bg-slate-100 px-1.5 py-0.5 text-[10px] font-medium text-slate-500" x-text="courseLabel(line.course)"></span>
<span x-show="line.fired" x-cloak class="rounded-full bg-amber-50 px-1.5 py-0.5 text-[10px] font-medium text-amber-700">In kitchen</span>
</div>
</div>
<div class="text-right">
<p class="text-sm font-semibold text-slate-900" x-text="money(line.line_total_minor)"></p>
@@ -74,10 +90,22 @@
<span x-text="money(totalMinor)"></span>
</div>
<button type="button" @click="send()" :disabled="busy || ! hasNew"
class="mb-2 w-full rounded-xl border border-amber-300 bg-amber-50 px-4 py-2.5 text-sm font-semibold text-amber-800 transition hover:bg-amber-100 disabled:opacity-40">
Send to kitchen
</button>
{{-- Fire to kitchen (all, or by course when more than one course is waiting) --}}
<div x-show="hasNew" x-cloak class="mb-2 space-y-1.5">
<button type="button" @click="send()" :disabled="busy"
class="w-full rounded-xl border border-amber-300 bg-amber-50 px-4 py-2.5 text-sm font-semibold text-amber-800 transition hover:bg-amber-100 disabled:opacity-40">
Send all to kitchen
</button>
<template x-if="newCourses.length > 1">
<div class="flex flex-wrap gap-1.5">
<template x-for="c in newCourses" :key="c">
<button type="button" @click="send(c)" :disabled="busy"
class="rounded-lg border border-amber-200 bg-white px-2.5 py-1 text-xs font-medium text-amber-700 hover:bg-amber-50"
x-text="'Fire ' + courseLabel(c)"></button>
</template>
</div>
</template>
</div>
<form method="post" action="{{ route('pos.tickets.settle', $sale) }}" class="space-y-2">
@csrf
@@ -93,5 +121,57 @@
</div>
</div>
</div>
{{-- Modifier picker --}}
<div x-show="picker.open" x-cloak class="fixed inset-0 z-50 flex items-end justify-center bg-slate-900/40 p-0 sm:items-center sm:p-4" @click.self="closePicker()">
<div class="w-full max-w-md overflow-hidden rounded-t-2xl bg-white shadow-xl sm:rounded-2xl">
<div class="flex items-center justify-between border-b border-slate-100 px-5 py-3">
<p class="text-sm font-semibold text-slate-900" x-text="picker.product?.name"></p>
<button @click="closePicker()" class="rounded-lg p-1.5 text-slate-400 hover:bg-slate-100">
<svg class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12"/></svg>
</button>
</div>
<div class="max-h-[60vh] space-y-4 overflow-y-auto px-5 py-4">
<template x-for="g in picker.groups" :key="g.id">
<div>
<p class="text-xs font-semibold text-slate-600">
<span x-text="g.name"></span>
<span class="font-normal text-slate-400" x-text="'(choose ' + g.min + (g.max ? '' + g.max : '+') + ')'"></span>
</p>
<div class="mt-2 flex flex-wrap gap-2">
<template x-for="m in g.modifiers" :key="m.id">
<button type="button" @click="toggleModifier(g, m)"
:class="isSelected(g, m) ? 'border-indigo-500 bg-indigo-50 text-indigo-700' : 'border-slate-200 text-slate-600'"
class="rounded-lg border px-3 py-1.5 text-sm font-medium">
<span x-text="m.name"></span>
<span x-show="m.price_delta_minor" class="text-xs opacity-70"
x-text="(m.price_delta_minor > 0 ? ' +' : ' ') + money(m.price_delta_minor).replace(currency + ' ', '')"></span>
</button>
</template>
</div>
</div>
</template>
<div>
<label class="text-xs font-semibold text-slate-600">Course</label>
<select x-model="picker.course" class="mt-1 w-full rounded-xl border-slate-200 text-sm focus:border-indigo-500 focus:ring-indigo-500">
<option value="">No course</option>
@foreach($courses as $key => $label)
<option value="{{ $key }}">{{ $label }}</option>
@endforeach
</select>
</div>
<div>
<label class="text-xs font-semibold text-slate-600">Notes</label>
<input type="text" x-model="picker.notes" maxlength="200" placeholder="e.g. no onions"
class="mt-1 w-full rounded-xl border-slate-200 text-sm focus:border-indigo-500 focus:ring-indigo-500">
</div>
</div>
<div class="flex items-center justify-between gap-3 border-t border-slate-100 px-5 py-3">
<span class="text-sm font-semibold text-slate-900" x-text="money(pickerPrice)"></span>
<button type="button" @click="confirmPicker()" :disabled="! pickerValid || busy" class="btn-primary disabled:opacity-40">Add to ticket</button>
</div>
</div>
</div>
</div>
</x-app-layout>
+12
View File
@@ -4,6 +4,7 @@ use App\Http\Controllers\Auth\SsoLoginController;
use App\Http\Controllers\Pos\AiController;
use App\Http\Controllers\Pos\DashboardController;
use App\Http\Controllers\Pos\KitchenController;
use App\Http\Controllers\Pos\MenuController;
use App\Http\Controllers\Pos\ProductController;
use App\Http\Controllers\Pos\RegisterController;
use App\Http\Controllers\Pos\SaleController;
@@ -61,6 +62,17 @@ Route::middleware(['auth', 'platform.session'])->group(function () {
Route::get('/kitchen/feed', [KitchenController::class, 'feed'])->name('pos.kitchen.feed');
Route::post('/kitchen/lines/{line}/bump', [KitchenController::class, 'bump'])->name('pos.kitchen.bump');
// Menu depth — categories, kitchen stations, and modifier groups/options.
Route::get('/menu', [MenuController::class, 'index'])->name('pos.menu');
Route::post('/menu/categories', [MenuController::class, 'storeCategory'])->name('pos.menu.categories.store');
Route::delete('/menu/categories/{category}', [MenuController::class, 'destroyCategory'])->name('pos.menu.categories.destroy');
Route::post('/menu/stations', [MenuController::class, 'storeStation'])->name('pos.menu.stations.store');
Route::delete('/menu/stations/{station}', [MenuController::class, 'destroyStation'])->name('pos.menu.stations.destroy');
Route::post('/menu/groups', [MenuController::class, 'storeGroup'])->name('pos.menu.groups.store');
Route::delete('/menu/groups/{group}', [MenuController::class, 'destroyGroup'])->name('pos.menu.groups.destroy');
Route::post('/menu/groups/{group}/modifiers', [MenuController::class, 'storeModifier'])->name('pos.menu.modifiers.store');
Route::delete('/menu/modifiers/{modifier}', [MenuController::class, 'destroyModifier'])->name('pos.menu.modifiers.destroy');
Route::get('/products', [ProductController::class, 'index'])->name('pos.products.index');
Route::get('/products/create', [ProductController::class, 'create'])->name('pos.products.create');
Route::post('/products', [ProductController::class, 'store'])->name('pos.products.store');
+43
View File
@@ -4,9 +4,12 @@ namespace Tests\Feature;
use App\Http\Middleware\EnsurePlatformSession;
use App\Models\PosLocation;
use App\Models\PosModifier;
use App\Models\PosModifierGroup;
use App\Models\PosProduct;
use App\Models\PosSale;
use App\Models\PosSaleLine;
use App\Models\PosStation;
use App\Models\PosTable;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -113,6 +116,46 @@ class PosRestaurantTest extends TestCase
$this->assertNull($table->fresh()->current_sale_id);
}
public function test_modifiers_course_and_station_routing(): void
{
$user = $this->user();
[, , $product] = $this->restaurant($user);
$station = PosStation::create(['owner_ref' => $user->public_id, 'name' => 'Bar']);
$group = PosModifierGroup::create(['owner_ref' => $user->public_id, 'name' => 'Size', 'min_select' => 1, 'max_select' => 1]);
$large = PosModifier::create(['modifier_group_id' => $group->id, 'owner_ref' => $user->public_id, 'name' => 'Large', 'price_delta_minor' => 1000]);
$product->update(['station_id' => $station->id, 'course' => 'drink']);
$product->modifierGroups()->sync([$group->id]);
// Open a takeaway ticket.
$this->actingAs($user)->post(route('pos.tickets.open'), ['order_type' => 'takeaway'])->assertRedirect();
$sale = PosSale::where('owner_ref', $user->public_id)->firstOrFail();
// Add the product with the Large modifier — price = base 2500 + 1000.
$this->actingAs($user)->postJson(route('pos.tickets.lines.add', $sale), [
'product_id' => $product->id,
'modifier_ids' => [$large->id],
'quantity' => 1,
])->assertOk()->assertJsonPath('total_minor', 3500);
$line = $sale->lines()->firstOrFail();
$this->assertSame(3500, $line->unit_price_minor);
$this->assertSame($station->id, $line->station_id);
$this->assertSame('drink', $line->course);
$this->assertSame('Large', $line->modifiers()->value('name'));
// Fire only the "drink" course.
$this->actingAs($user)->postJson(route('pos.tickets.send', $sale), ['course' => 'drink'])
->assertOk()->assertJsonPath('fired', 1);
// KDS feed carries the station + modifier.
$this->actingAs($user)->getJson(route('pos.kitchen.feed'))
->assertOk()
->assertJsonPath('tickets.0.lines.0.station', 'Bar')
->assertJsonPath('tickets.0.lines.0.modifiers.0', 'Large');
}
public function test_cannot_open_two_tabs_on_one_table(): void
{
$user = $this->user();