Add public token-gated kitchen display for POS devices.
Deploy Ladill POS / deploy (push) Successful in 46s

Kitchen display devices open a full-screen KDS without staff login,
with feed/stream/bump over the device token. Shared kitchen board
logic is extracted so the signed-in Kitchen page stays in sync.
This commit is contained in:
isaacclad
2026-07-15 22:52:28 +00:00
parent c01518b0ee
commit ede4aaa10c
8 changed files with 425 additions and 78 deletions
+7 -76
View File
@@ -4,12 +4,10 @@ namespace App\Http\Controllers\Pos;
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 App\Services\Pos\KitchenBoardService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\View\View;
use Symfony\Component\HttpFoundation\StreamedResponse;
@@ -17,10 +15,12 @@ class KitchenController extends Controller
{
use ScopesToAccount;
public function __construct(private KitchenBoardService $board) {}
public function index(Request $request): View
{
return view('pos.kitchen.index', [
'stations' => PosStation::owned($this->ownerRef($request))->orderBy('name')->get(['id', 'name']),
'stations' => $this->board->stations($this->ownerRef($request)),
]);
}
@@ -30,7 +30,7 @@ class KitchenController extends Controller
*/
public function feed(Request $request): JsonResponse
{
return response()->json($this->payload($this->ownerRef($request)));
return response()->json($this->board->payload($this->ownerRef($request)));
}
/**
@@ -54,7 +54,7 @@ class KitchenController extends Controller
$lastHash = null;
while (true) {
$payload = $this->payload($owner);
$payload = $this->board->payload($owner);
$json = json_encode($payload);
$hash = md5((string) $json);
@@ -82,80 +82,11 @@ class KitchenController extends Controller
return $response;
}
/** @return array{tickets: \Illuminate\Support\Collection, server_time: string} */
private function payload(string $owner): array
{
return ['tickets' => $this->buildTickets($owner), 'server_time' => now()->toIso8601String()];
}
private function buildTickets(string $owner): Collection
{
// Payment-agnostic: dine-in tabs (pending) and paid online orders both
// sit on the board while the kitchen is still working them.
$sales = PosSale::owned($owner)
->where('kitchen_status', PosSale::KITCHEN_ACTIVE)
->with(['table', 'lines' => fn ($q) => $q->orderBy('position')->with('modifiers', 'station')])
->orderBy('kitchen_sent_at')
->get();
return $sales->map(function (PosSale $sale) {
$lines = $sale->lines
->filter(fn (PosSaleLine $l) => in_array($l->kitchen_state, [
PosSaleLine::KITCHEN_QUEUED,
PosSaleLine::KITCHEN_PREPARING,
PosSaleLine::KITCHEN_READY,
], true))
->values();
if ($lines->isEmpty()) {
return null;
}
return [
'id' => $sale->id,
'reference' => $sale->reference,
'order_type' => $sale->order_type,
'table' => $sale->table?->label,
'sent_at' => optional($sale->kitchen_sent_at)->toIso8601String(),
'lines' => $lines->map(fn (PosSaleLine $l) => [
'id' => $l->id,
'name' => $l->name,
'quantity' => $l->quantity,
'notes' => $l->notes,
'course' => $l->course,
'station' => $l->station?->name,
'station_id' => $l->station_id,
'source' => $l->source,
'modifiers' => $l->modifiers->map(fn ($m) => $m->name)->all(),
'state' => $l->kitchen_state,
])->all(),
];
})->filter()->values();
}
/**
* Advance one line to the next kitchen state (queued preparing ready served).
*/
public function bump(Request $request, PosSaleLine $line): JsonResponse
{
$owner = $this->ownerRef($request);
abort_unless($line->sale && $line->sale->owner_ref === $owner, 404);
$flow = PosSaleLine::KITCHEN_FLOW;
$idx = array_search($line->kitchen_state, $flow, true);
$next = $idx === false ? PosSaleLine::KITCHEN_PREPARING : ($flow[$idx + 1] ?? PosSaleLine::KITCHEN_SERVED);
$line->forceFill(['kitchen_state' => $next])->save();
// When every fired line is served, the ticket leaves the kitchen board.
$sale = $line->sale;
$remaining = $sale->lines()
->whereIn('kitchen_state', [PosSaleLine::KITCHEN_QUEUED, PosSaleLine::KITCHEN_PREPARING, PosSaleLine::KITCHEN_READY])
->count();
if ($remaining === 0) {
$sale->forceFill(['kitchen_status' => PosSale::KITCHEN_SERVED])->save();
}
return response()->json(['state' => $next]);
return response()->json($this->board->bumpLine($line, $this->ownerRef($request)));
}
}