The console under console/ has its own session cookie and console guard (UseConsoleSession), so signing out or changing user there leaves the normal interface alone. Links open it in a new window through a one-time handoff key; a signed-out console asks for a PIN code or password on its own login page. Users set their 4-6 digit PIN on the profile's PIN page, and the console's change user dialog takes it on a keypad; five wrong PINs lock PIN sign-in for 15 minutes. Machine counters are cumulative: users record how much a job used and it is added to the latest reading. A maintenance record restarts the whole counter interval from the reading at the record. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
911 lines
44 KiB
PHP
911 lines
44 KiB
PHP
<?php
|
||
|
||
use App\Modules\Inventory\Application\Contracts\StockQueries;
|
||
use App\Modules\Inventory\Application\DTOs\StockGroupSummary;
|
||
use App\Modules\Inventory\Application\DTOs\StockItemSummary;
|
||
use App\Modules\Inventory\Application\DTOs\StockUseData;
|
||
use App\Modules\Inventory\Application\UseCases\RecordStockUse;
|
||
use App\Modules\Inventory\Application\UseCases\ReverseStockMovement;
|
||
use App\Modules\Inventory\Domain\Services\StockSearch;
|
||
use App\Modules\Inventory\Domain\ValueObjects\StockQuantity;
|
||
use App\Modules\Inventory\Presentation\Livewire\Concerns\FormatsStock;
|
||
use App\Modules\Machines\Application\Contracts\MachineQueries;
|
||
use App\Modules\Machines\Application\Contracts\MachineTasks;
|
||
use App\Modules\Machines\Application\Contracts\MaintenanceQueries;
|
||
use App\Modules\Machines\Application\DTOs\MachineSummary;
|
||
use App\Modules\Machines\Application\DTOs\MaintenanceItemStatus;
|
||
use App\Modules\Machines\Application\DTOs\QueueRow;
|
||
use App\Modules\Machines\Application\UseCases\MachineMaintenance;
|
||
use App\Modules\Machines\Application\UseCases\MachineWorkList;
|
||
use App\Modules\Machines\Domain\Enums\CounterUnit;
|
||
use App\Modules\Machines\Domain\ValueObjects\Reading;
|
||
use App\Modules\Machines\Presentation\Livewire\Concerns\DescribesMaintenance;
|
||
use App\Modules\Sales\Application\Contracts\QuickSaleOrderQueries;
|
||
use App\Modules\Sales\Application\DTOs\OrderLineSummary;
|
||
use App\Modules\Sales\Application\UseCases\QuickSaleOrders;
|
||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||
use App\Modules\TimeTracking\Application\UseCases\AddTaskHours;
|
||
use App\Modules\Users\Application\Contracts\Clock;
|
||
use Carbon\CarbonImmutable;
|
||
use Illuminate\Support\Facades\Gate;
|
||
use Livewire\Attributes\Computed;
|
||
use Livewire\Attributes\Layout;
|
||
use Livewire\Attributes\Locked;
|
||
use Livewire\Component;
|
||
|
||
/**
|
||
* The machine console (konekäyttöliittymä, spec 19.6): a full-screen view
|
||
* for the tablet or touch screen next to a machine. It shows today's work
|
||
* list (late rows of earlier days included; the next day can be viewed),
|
||
* lets the user start and finish tasks, record the material used with
|
||
* large item buttons, frequent items first, record today's hours (which
|
||
* are suggested as the usage of the machine's hour counters), counter
|
||
* usage and maintenance. Touch targets are at least 44 × 44 px. The
|
||
* view refreshes itself, and the Refresh button fetches the latest state
|
||
* at once and tells what changed.
|
||
*/
|
||
new #[Layout('layouts.console')] class extends Component
|
||
{
|
||
use DescribesMaintenance;
|
||
use FormatsStock {
|
||
FormatsStock::dateLabel insteadof DescribesMaintenance;
|
||
}
|
||
|
||
public const int ITEM_LIMIT = 24;
|
||
|
||
#[Locked]
|
||
public int $machineId;
|
||
|
||
#[Locked]
|
||
public bool $nextDay = false;
|
||
|
||
#[Locked]
|
||
public ?int $selectedEntryId = null;
|
||
|
||
/**
|
||
* Rows already seen, to tell how many are new after a refresh.
|
||
*
|
||
* @var list<int>
|
||
*/
|
||
#[Locked]
|
||
public array $knownEntryIds = [];
|
||
|
||
public string $search = '';
|
||
|
||
#[Locked]
|
||
public ?int $groupId = null;
|
||
|
||
#[Locked]
|
||
public ?int $selectedItemId = null;
|
||
|
||
public string $quantity = '1';
|
||
|
||
public string $reason = '';
|
||
|
||
#[Locked]
|
||
public ?int $lastMovementId = null;
|
||
|
||
public string $hours = '';
|
||
|
||
/**
|
||
* Usage typed, by counter id.
|
||
*
|
||
* @var array<int, string>
|
||
*/
|
||
public array $usage = [];
|
||
|
||
#[Locked]
|
||
public ?int $recordingItemId = null;
|
||
|
||
#[Locked]
|
||
public string $message = '';
|
||
|
||
#[Locked]
|
||
public string $refreshMessage = '';
|
||
|
||
#[Locked]
|
||
public ?int $completingEntryId = null;
|
||
|
||
/**
|
||
* Material used per stock item while completing an order's step.
|
||
*
|
||
* @var array<int, string>
|
||
*/
|
||
public array $orderUsed = [];
|
||
|
||
public string $moveToMachineId = '';
|
||
|
||
public function mount(int $machine): void
|
||
{
|
||
$this->authorize('machines.use');
|
||
|
||
$this->machineId = (app(MachineQueries::class)->findMachine($machine) ?? abort(404))->id;
|
||
$this->knownEntryIds = array_map(fn (QueueRow $row): int => $row->entryId, $this->rows);
|
||
}
|
||
|
||
#[Computed]
|
||
public function machine(): MachineSummary
|
||
{
|
||
return app(MachineQueries::class)->findMachine($this->machineId) ?? abort(404);
|
||
}
|
||
|
||
#[Computed]
|
||
public function today(): string
|
||
{
|
||
return app(Clock::class)->today()->format('Y-m-d');
|
||
}
|
||
|
||
public function day(): string
|
||
{
|
||
return $this->nextDay ? CarbonImmutable::parse($this->today)->addDay()->format('Y-m-d') : $this->today;
|
||
}
|
||
|
||
/**
|
||
* @return list<QueueRow>
|
||
*/
|
||
#[Computed]
|
||
public function rows(): array
|
||
{
|
||
return app(MachineQueries::class)->rowsOn($this->machineId, $this->day(), $this->today);
|
||
}
|
||
|
||
/**
|
||
* The quick sale order lines on the list, by line id.
|
||
*
|
||
* @return array<int, OrderLineSummary>
|
||
*/
|
||
#[Computed]
|
||
public function orderLines(): array
|
||
{
|
||
$ids = array_values(array_filter(array_map(fn (QueueRow $row): ?int => $row->orderLineId, $this->rows)));
|
||
|
||
return app(QuickSaleOrderQueries::class)->lines($ids);
|
||
}
|
||
|
||
/**
|
||
* Machines of the same type to move an order's step to.
|
||
*
|
||
* @return list<MachineSummary>
|
||
*/
|
||
#[Computed]
|
||
public function sameTypeMachines(): array
|
||
{
|
||
return array_values(array_filter(
|
||
app(MachineQueries::class)->machines(),
|
||
fn (MachineSummary $machine): bool => $machine->type === $this->machine->type && $machine->id !== $this->machineId,
|
||
));
|
||
}
|
||
|
||
public function startOrderComplete(int $entryId): void
|
||
{
|
||
$this->authorize('sales.use');
|
||
|
||
$row = $this->row($entryId);
|
||
$line = $this->orderLines[$row->orderLineId] ?? abort(404);
|
||
$this->completingEntryId = $entryId;
|
||
$this->orderUsed = [];
|
||
|
||
foreach ($line->currentMaterials as $material) {
|
||
$this->orderUsed[$material['stockItemId']] = StockQuantity::inputValue($material['quantityMilli'] * $line->quantity);
|
||
}
|
||
|
||
$this->js("setTimeout(() => document.getElementById('order-complete-{$entryId}')?.focus())");
|
||
}
|
||
|
||
public function changeOrderUsed(int $itemId, int $step): void
|
||
{
|
||
$current = StockQuantity::parse($this->orderUsed[$itemId] ?? '0')?->milli ?? 0;
|
||
$this->orderUsed[$itemId] = StockQuantity::inputValue(max(0, $current + $step * 1000));
|
||
}
|
||
|
||
public function completeOrder(QuickSaleOrders $orders): void
|
||
{
|
||
$this->authorize('sales.use');
|
||
|
||
$row = $this->row((int) $this->completingEntryId);
|
||
$line = $this->orderLines[$row->orderLineId] ?? abort(404);
|
||
$used = [];
|
||
|
||
foreach ($this->orderUsed as $itemId => $value) {
|
||
try {
|
||
$used[(int) $itemId] = StockQuantity::parse($value)?->milli ?? 0;
|
||
} catch (DomainException) {
|
||
$this->addError('orderUsed.'.$itemId, __('inventory.errors.quantity'));
|
||
|
||
return;
|
||
}
|
||
}
|
||
|
||
try {
|
||
$orders->completeStep($line->id, (int) $row->stepPosition, (int) auth()->id(), $used);
|
||
} catch (DomainException) {
|
||
$this->message = __('sales.orders.errors.step');
|
||
$this->completingEntryId = null;
|
||
$this->reload();
|
||
|
||
return;
|
||
}
|
||
|
||
$this->message = __('machines.console.order_done', ['number' => $line->pickupNumber, 'product' => $line->productName]);
|
||
$this->completingEntryId = null;
|
||
$this->reload();
|
||
$this->js("document.getElementById('console-status')?.focus()");
|
||
}
|
||
|
||
public function moveOrder(int $entryId, MachineWorkList $workList): void
|
||
{
|
||
$this->authorize('machines.use');
|
||
|
||
$row = $this->row($entryId);
|
||
$line = $this->orderLines[$row->orderLineId] ?? abort(404);
|
||
|
||
try {
|
||
$workList->moveOrderLine($entryId, (int) $this->moveToMachineId);
|
||
} catch (DomainException) {
|
||
$this->addError('moveToMachineId', __('machines.errors.machine'));
|
||
|
||
return;
|
||
}
|
||
|
||
$this->message = __('machines.console.order_moved', ['number' => $line->pickupNumber, 'machine' => app(MachineQueries::class)->findMachine((int) $this->moveToMachineId)->name ?? '']);
|
||
$this->moveToMachineId = '';
|
||
$this->reload();
|
||
}
|
||
|
||
#[Computed]
|
||
public function selectedRow(): ?QueueRow
|
||
{
|
||
return $this->selectedEntryId === null ? null : collect($this->rows)->firstWhere('entryId', $this->selectedEntryId);
|
||
}
|
||
|
||
/**
|
||
* @return list<MaintenanceItemStatus>
|
||
*/
|
||
#[Computed]
|
||
public function maintenance(): array
|
||
{
|
||
return app(MaintenanceQueries::class)->itemsOf($this->machineId);
|
||
}
|
||
|
||
/**
|
||
* @return list<StockGroupSummary>
|
||
*/
|
||
#[Computed]
|
||
public function groups(): array
|
||
{
|
||
return app(StockQueries::class)->groups(includeInactive: false);
|
||
}
|
||
|
||
/**
|
||
* Items to show as buttons: the search or group results, or else this
|
||
* machine's frequent and recent items.
|
||
*
|
||
* @return list<StockItemSummary>
|
||
*/
|
||
#[Computed]
|
||
public function items(): array
|
||
{
|
||
$stock = app(StockQueries::class);
|
||
$search = trim($this->search);
|
||
|
||
if ($search !== '' || $this->groupId !== null) {
|
||
return array_slice($stock->items($search === '' ? null : $search, $this->groupId), 0, self::ITEM_LIMIT);
|
||
}
|
||
|
||
$favourites = $stock->machineFavourites($this->machineId);
|
||
$ids = array_values(array_unique([...$favourites['frequent'], ...$favourites['recent']]));
|
||
$items = $stock->itemsByIds($ids);
|
||
|
||
return array_values(array_filter(array_map(fn (int $id): ?StockItemSummary => $items[$id] ?? null, $ids), fn ($item): bool => $item !== null && $item->isActive));
|
||
}
|
||
|
||
#[Computed]
|
||
public function selectedItem(): ?StockItemSummary
|
||
{
|
||
return $this->selectedItemId === null ? null : app(StockQueries::class)->findItem($this->selectedItemId);
|
||
}
|
||
|
||
/**
|
||
* The polled refresh: new rows are announced, the rest updates quietly.
|
||
*/
|
||
public function refreshList(): void
|
||
{
|
||
$this->authorize('machines.use');
|
||
|
||
$new = $this->reload();
|
||
|
||
if ($new > 0) {
|
||
$this->refreshMessage = trans_choice('machines.console.new_rows', $new, ['count' => $new]);
|
||
}
|
||
}
|
||
|
||
public function refresh(Clock $clock): void
|
||
{
|
||
$this->authorize('machines.use');
|
||
|
||
$new = $this->reload();
|
||
$this->refreshMessage = __('machines.console.refreshed', ['time' => $clock->now()->setTimezone(new DateTimeZone((string) config('app.business_timezone')))->format('H.i')])
|
||
.' '.trans_choice('machines.console.new_rows', $new, ['count' => $new]);
|
||
}
|
||
|
||
public function showDay(bool $next): void
|
||
{
|
||
$this->authorize('machines.use');
|
||
|
||
$this->nextDay = $next;
|
||
$this->selectedEntryId = null;
|
||
unset($this->rows);
|
||
}
|
||
|
||
public function selectRow(int $entryId): void
|
||
{
|
||
$this->authorize('machines.use');
|
||
|
||
$this->selectedEntryId = $this->selectedEntryId === $entryId ? null : $entryId;
|
||
$this->hours = '';
|
||
unset($this->selectedRow);
|
||
|
||
if ($this->selectedEntryId !== null) {
|
||
$this->js("setTimeout(() => document.getElementById('selected-task')?.focus())");
|
||
}
|
||
}
|
||
|
||
public function setStatus(int $entryId, string $status, MachineTasks $tasks): void
|
||
{
|
||
$this->authorize('machines.use');
|
||
abort_unless(in_array($status, ['in_progress', 'in_review'], true), 404);
|
||
|
||
$row = $this->row($entryId);
|
||
abort_if($row->task === null || ! $this->canFinish($row), 403);
|
||
$this->authorize('jobs.update-task-status', $row->task->jobId);
|
||
|
||
$tasks->changeStatus((int) $row->taskId, $status);
|
||
$this->message = __('machines.console.status_changed', ['title' => $row->task->title, 'status' => __('jobs.tasks.statuses.'.$status)]);
|
||
unset($this->rows, $this->selectedRow);
|
||
}
|
||
|
||
public function finish(int $entryId, MachineWorkList $workList): void
|
||
{
|
||
$this->authorize('machines.use');
|
||
|
||
$row = $this->row($entryId);
|
||
abort_if($row->task === null || ! $this->canFinish($row), 403);
|
||
$this->authorize('jobs.update-task-status', $row->task->jobId);
|
||
|
||
try {
|
||
$workList->finish($entryId, (int) auth()->id());
|
||
} catch (DomainException) {
|
||
$this->message = __('machines.errors.not_found');
|
||
$this->reload();
|
||
|
||
return;
|
||
}
|
||
|
||
$this->message = __('machines.console.finished', ['title' => $row->task->title]);
|
||
$this->selectedEntryId = $this->selectedEntryId === $entryId ? null : $this->selectedEntryId;
|
||
$this->reload();
|
||
$this->js("document.getElementById('console-status')?.focus()");
|
||
}
|
||
|
||
public function chooseGroup(?int $groupId): void
|
||
{
|
||
$this->authorize('inventory.record-use');
|
||
|
||
$this->groupId = $this->groupId === $groupId ? null : $groupId;
|
||
$this->selectedItemId = null;
|
||
unset($this->items);
|
||
}
|
||
|
||
public function selectItem(int $itemId): void
|
||
{
|
||
$this->authorize('inventory.record-use');
|
||
|
||
$this->selectedItemId = $itemId;
|
||
$this->quantity = '1';
|
||
$this->resetErrorBag();
|
||
unset($this->selectedItem);
|
||
$this->js("setTimeout(() => document.getElementById('material-quantity')?.focus())");
|
||
}
|
||
|
||
public function changeQuantity(int $step): void
|
||
{
|
||
$current = StockQuantity::parse($this->quantity)?->milli ?? 0;
|
||
$next = max(1000, intdiv($current, 1000) * 1000 + $step * 1000);
|
||
$this->quantity = StockQuantity::inputValue($next);
|
||
}
|
||
|
||
public function recordMaterial(RecordStockUse $recordUse): void
|
||
{
|
||
$this->authorize('inventory.record-use');
|
||
$this->resetErrorBag();
|
||
|
||
$item = $this->selectedItem ?? abort(404);
|
||
$row = $this->selectedRow;
|
||
$task = $row?->task;
|
||
|
||
try {
|
||
$result = $recordUse->execute(new StockUseData(
|
||
$item->id,
|
||
$this->quantity,
|
||
taskId: $task?->taskId,
|
||
jobId: $task?->jobId,
|
||
machineId: $this->machineId,
|
||
reason: $task === null ? $this->reason : null,
|
||
), (int) auth()->id());
|
||
} catch (DomainException $exception) {
|
||
$this->addError($exception instanceof App\Modules\Inventory\Domain\Exceptions\StockReasonRequired ? 'reason' : 'quantity', __(match (true) {
|
||
$exception instanceof App\Modules\Inventory\Domain\Exceptions\StockReasonRequired => 'machines.console.reason_required',
|
||
$exception instanceof App\Modules\Inventory\Domain\Exceptions\StockItemInactive => 'inventory.errors.inactive',
|
||
default => 'inventory.errors.quantity',
|
||
}));
|
||
|
||
return;
|
||
}
|
||
|
||
$this->lastMovementId = $result->movementId;
|
||
$this->message = __('machines.console.material_recorded', [
|
||
'item' => $result->itemName,
|
||
'quantity' => $this->quantity($result->quantityMilli, $item->unit),
|
||
'balance' => $this->quantity($result->balanceMilli, $item->unit),
|
||
]);
|
||
$this->selectedItemId = null;
|
||
$this->quantity = '1';
|
||
unset($this->items, $this->selectedItem);
|
||
$this->js("document.getElementById('console-status')?.focus()");
|
||
}
|
||
|
||
public function undoLast(ReverseStockMovement $reverse): void
|
||
{
|
||
$this->authorize('inventory.record-use');
|
||
|
||
if ($this->lastMovementId === null) {
|
||
return;
|
||
}
|
||
|
||
try {
|
||
$reverse->execute($this->lastMovementId, (int) auth()->id(), Gate::allows('inventory.reverse-any'));
|
||
$this->message = __('machines.console.material_undone');
|
||
} catch (DomainException) {
|
||
$this->message = __('inventory.errors.reversal_not_allowed');
|
||
}
|
||
|
||
$this->lastMovementId = null;
|
||
unset($this->items);
|
||
$this->js("document.getElementById('console-status')?.focus()");
|
||
}
|
||
|
||
public function saveHours(AddTaskHours $addHours, Clock $clock): void
|
||
{
|
||
$this->authorize('time.use');
|
||
|
||
$task = $this->selectedRow?->task ?? abort(404);
|
||
$this->authorize('time.book', $task->jobId);
|
||
|
||
try {
|
||
$total = $addHours->execute((int) auth()->id(), $task->taskId, $clock->today()->format('Y-m-d'), $this->hours, __('machines.console.hours_note', ['machine' => $this->machine->name]));
|
||
} catch (DomainException) {
|
||
$this->addError('hours', __('machines.console.hours_error'));
|
||
|
||
return;
|
||
}
|
||
|
||
$this->message = __('machines.console.hours_saved', ['hours' => $this->hours, 'title' => $task->title, 'total' => $total]);
|
||
$this->suggestHourCounters($this->hours);
|
||
$this->hours = '';
|
||
}
|
||
|
||
/**
|
||
* Hours just booked on the machine are suggested as the usage of its
|
||
* hour counters; nothing is recorded until the user saves the counter.
|
||
*/
|
||
private function suggestHourCounters(string $hours): void
|
||
{
|
||
$milli = Reading::parse($hours);
|
||
|
||
if ($milli === null || $milli <= 0) {
|
||
return;
|
||
}
|
||
|
||
foreach ($this->machine->counters as $counter) {
|
||
if ($counter->unit === CounterUnit::Hour) {
|
||
$this->usage[$counter->id] = str_replace("\u{00A0}", '', $this->reading($milli));
|
||
$this->message .= ' '.__('machines.console.hour_suggestion', ['hours' => $this->reading($milli), 'counter' => $counter->name]);
|
||
}
|
||
}
|
||
}
|
||
|
||
public function saveUsage(int $counterId, MachineMaintenance $maintenance): void
|
||
{
|
||
$this->authorize('machines.use');
|
||
$this->resetErrorBag('usage.'.$counterId);
|
||
|
||
$counter = collect($this->machine->counters)->firstWhere('id', $counterId) ?? abort(404);
|
||
$usage = $this->usage[$counterId] ?? '';
|
||
|
||
try {
|
||
$milli = $maintenance->recordUsage($counterId, $usage, (int) auth()->id());
|
||
} catch (DomainException) {
|
||
$this->addError('usage.'.$counterId, __('machines.maintenance.errors.usage'));
|
||
|
||
return;
|
||
}
|
||
|
||
$this->message = $this->usageSaved($counter, $usage, $milli);
|
||
unset($this->usage[$counterId], $this->machine, $this->maintenance);
|
||
}
|
||
|
||
public function startMaintenance(int $itemId): void
|
||
{
|
||
$this->authorize('machines.use');
|
||
|
||
$this->recordingItemId = (collect($this->maintenance)->firstWhere('id', $itemId) ?? abort(404))->id;
|
||
$this->js("setTimeout(() => document.getElementById('maintenance-confirm')?.focus())");
|
||
}
|
||
|
||
public function recordMaintenance(MachineMaintenance $maintenance): void
|
||
{
|
||
$this->authorize('machines.use');
|
||
|
||
$item = collect($this->maintenance)->firstWhere('id', $this->recordingItemId) ?? abort(404);
|
||
|
||
try {
|
||
$result = $maintenance->recordMaintenance($item->id, (int) auth()->id());
|
||
} catch (DomainException) {
|
||
abort(404);
|
||
}
|
||
|
||
$this->message = __('machines.maintenance.recorded', ['name' => $item->name]).($result['stockRecorded'] ? '' : ' '.__('machines.maintenance.stock_not_recorded'));
|
||
$this->recordingItemId = null;
|
||
unset($this->maintenance);
|
||
$this->js("document.getElementById('console-status')?.focus()");
|
||
}
|
||
|
||
/**
|
||
* Rows of today and late rows are made; the next day's are only shown.
|
||
*/
|
||
public function canFinish(QueueRow $row): bool
|
||
{
|
||
return ! $this->nextDay;
|
||
}
|
||
|
||
/**
|
||
* The first open task row of today: marked as next with text.
|
||
*/
|
||
public function nextEntryId(): ?int
|
||
{
|
||
if ($this->nextDay) {
|
||
return null;
|
||
}
|
||
|
||
foreach ($this->rows as $row) {
|
||
return $row->entryId;
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
public function render(): mixed
|
||
{
|
||
return $this->view()->title(__('machines.console.title', ['name' => $this->machine->name]));
|
||
}
|
||
|
||
/**
|
||
* @return int How many rows are new since the last look.
|
||
*/
|
||
private function reload(): int
|
||
{
|
||
unset($this->rows, $this->maintenance, $this->items, $this->selectedRow, $this->machine, $this->orderLines);
|
||
|
||
$ids = array_map(fn (QueueRow $row): int => $row->entryId, $this->rows);
|
||
$new = count(array_diff($ids, $this->knownEntryIds));
|
||
$this->knownEntryIds = array_values(array_unique([...$this->knownEntryIds, ...$ids]));
|
||
|
||
if ($this->selectedEntryId !== null && ! in_array($this->selectedEntryId, $ids, true)) {
|
||
$this->selectedEntryId = null;
|
||
}
|
||
|
||
return $new;
|
||
}
|
||
|
||
private function row(int $entryId): QueueRow
|
||
{
|
||
return collect($this->rows)->firstWhere('entryId', $entryId) ?? abort(404);
|
||
}
|
||
};
|
||
?>
|
||
|
||
@php
|
||
$touch = 'inline-flex min-h-11 min-w-11 items-center justify-center gap-2 rounded-lg px-4 py-2 font-medium focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:focus-visible:outline-blue-400';
|
||
$primary = $touch.' bg-primary-600 text-white hover:bg-primary-700';
|
||
$secondary = $touch.' border border-zinc-500 bg-white text-zinc-900 hover:bg-zinc-100 dark:border-zinc-400 dark:bg-zinc-900 dark:text-zinc-100 dark:hover:bg-zinc-700';
|
||
$machine = $this->machine;
|
||
$lateMaintenance = array_values(array_filter($this->maintenance, fn ($item) => $item->level->value === 'overdue'));
|
||
@endphp
|
||
|
||
<div wire:poll.30s="refreshList" class="mx-auto max-w-6xl space-y-6 p-3 sm:p-4">
|
||
<header class="flex flex-wrap items-center justify-between gap-3 rounded-lg bg-zinc-800 p-3 text-zinc-100 dark">
|
||
<div class="min-w-0">
|
||
<h1 class="text-2xl font-semibold break-words">{{ $machine->name }}</h1>
|
||
<p class="text-base">{{ __('machines.console.user', ['name' => auth()->user()?->name]) }}</p>
|
||
</div>
|
||
<div class="flex flex-wrap gap-2">
|
||
<button type="button" id="console-refresh" wire:click="refresh" class="{{ $touch }} bg-white text-lg text-zinc-900 hover:bg-zinc-200">
|
||
<x-icon name="arrow-path" class="size-6" aria-hidden="true" />
|
||
{{ __('machines.console.refresh') }}
|
||
</button>
|
||
<livewire:users::pin-switch :return-to="route('machines.console', $machine->id)" />
|
||
{{-- The normal user interface has a session of its own (Users' UseConsoleSession). --}}
|
||
<a href="{{ route('machines.show', $machine->id) }}" class="{{ $touch }} border border-zinc-300 text-zinc-100 hover:bg-zinc-700">
|
||
<x-icon name="arrow-left" class="size-6" aria-hidden="true" />
|
||
{{ __('machines.console.back') }}
|
||
</a>
|
||
</div>
|
||
</header>
|
||
|
||
<div class="space-y-1">
|
||
<p role="status" aria-live="polite" class="font-medium">{{ $refreshMessage }}</p>
|
||
<p id="console-status" tabindex="-1" role="status" aria-live="polite" class="font-medium focus:outline-none">{{ $message }}</p>
|
||
</div>
|
||
|
||
@if ($lateMaintenance !== [])
|
||
<div class="space-y-1 rounded-lg border-2 border-red-700 p-3 dark:border-red-400">
|
||
@foreach ($lateMaintenance as $late)
|
||
<p wire:key="late-{{ $late->id }}" class="flex items-center gap-2 font-semibold text-red-700 dark:text-red-400">
|
||
<x-icon name="exclamation-triangle" class="size-6 shrink-0" aria-hidden="true" />
|
||
{{ __('machines.console.maintenance_late', ['name' => $late->name]) }}
|
||
</p>
|
||
@endforeach
|
||
</div>
|
||
@endif
|
||
|
||
<div class="grid gap-6 lg:grid-cols-2">
|
||
<section aria-labelledby="console-list-heading" class="space-y-3">
|
||
<h2 id="console-list-heading" class="text-xl font-semibold">{{ $nextDay ? __('machines.console.next_list', ['date' => $this->dateLabel($this->day())]) : __('machines.console.today_list') }}</h2>
|
||
<div class="flex flex-wrap gap-2" role="group" aria-label="{{ __('machines.show.day_navigation') }}">
|
||
<button type="button" wire:click="showDay(false)" class="{{ $nextDay ? $secondary : $primary }}" @unless ($nextDay) aria-pressed="true" @else aria-pressed="false" @endunless>{{ __('machines.show.today') }}</button>
|
||
<button type="button" wire:click="showDay(true)" class="{{ $nextDay ? $primary : $secondary }}" @if ($nextDay) aria-pressed="true" @else aria-pressed="false" @endif>{{ __('machines.show.next_day') }}</button>
|
||
</div>
|
||
|
||
@if ($this->rows === [])
|
||
<p>{{ __('machines.show.none') }}</p>
|
||
@else
|
||
<ol class="space-y-3">
|
||
@foreach ($this->rows as $row)
|
||
@php($task = $row->task)
|
||
<li wire:key="console-row-{{ $row->entryId }}" class="space-y-2 rounded-lg border-2 p-3 {{ $selectedEntryId === $row->entryId ? 'border-primary-600 dark:border-primary-400' : 'border-zinc-300 dark:border-zinc-600' }}">
|
||
@if ($this->nextEntryId() === $row->entryId)
|
||
<p class="text-base font-semibold">{{ __('machines.console.next') }}</p>
|
||
@endif
|
||
@if ($row->isOrder())
|
||
@php($line = $this->orderLines[$row->orderLineId] ?? null)
|
||
<p class="flex items-center gap-2 font-semibold">
|
||
<x-icon name="user" class="size-5" aria-hidden="true" />
|
||
{{ __('machines.show.order') }}
|
||
</p>
|
||
@if ($line !== null)
|
||
<p class="text-4xl font-bold">{{ __('sales.orders.pickup', ['number' => $line->pickupNumber]) }}</p>
|
||
<p class="text-xl font-semibold">{{ $line->quantity }} × {{ $line->productName }}</p>
|
||
<p class="text-base">
|
||
{{ $line->customerName ?? __('sales.anonymous') }} · {{ __('machines.console.ordered_at', ['time' => substr($line->orderedAt, 11)]) }}
|
||
@if (count($line->stepMachineIds) > 1)
|
||
· {{ __('machines.console.order_step', ['step' => (int) $row->stepPosition + 1, 'steps' => count($line->stepMachineIds)]) }}
|
||
@endif
|
||
</p>
|
||
@if (! $nextDay)
|
||
@if ($completingEntryId === $row->entryId)
|
||
@php($items = app(\App\Modules\Inventory\Application\Contracts\StockQueries::class)->itemsByIds(array_map(fn ($material) => $material['stockItemId'], $line->currentMaterials)))
|
||
<form wire:submit="completeOrder" class="space-y-3 rounded-lg border border-zinc-300 p-3 dark:border-zinc-600" novalidate>
|
||
<p id="order-complete-{{ $row->entryId }}" tabindex="-1" class="font-semibold focus:outline-none">{{ __('machines.console.order_materials') }}</p>
|
||
@foreach ($line->currentMaterials as $material)
|
||
@php($item = $items[$material['stockItemId']] ?? null)
|
||
<div wire:key="order-material-{{ $material['stockItemId'] }}" class="flex flex-wrap items-end gap-2">
|
||
<button type="button" wire:click="changeOrderUsed({{ $material['stockItemId'] }}, -1)" class="{{ $secondary }} text-2xl" aria-label="{{ __('machines.console.less_of', ['item' => $item->name ?? '']) }}">−</button>
|
||
<div class="w-40">
|
||
<x-input id="order-used-{{ $material['stockItemId'] }}" wire:model="orderUsed.{{ $material['stockItemId'] }}" inputmode="decimal" :label="($item->name ?? '').' ('.__('inventory.units.'.($item->unit->value ?? 'piece')).')'" autocomplete="off" />
|
||
</div>
|
||
<button type="button" wire:click="changeOrderUsed({{ $material['stockItemId'] }}, 1)" class="{{ $secondary }} text-2xl" aria-label="{{ __('machines.console.more_of', ['item' => $item->name ?? '']) }}">+</button>
|
||
</div>
|
||
@endforeach
|
||
<p class="text-base">{{ __('sales.orders.complete_hint') }}</p>
|
||
<button type="submit" class="{{ $primary }} w-full text-xl">{{ __('machines.console.confirm_order') }}</button>
|
||
</form>
|
||
@else
|
||
<div class="flex flex-wrap items-end gap-2">
|
||
<button type="button" wire:click="startOrderComplete({{ $row->entryId }})" class="{{ $primary }} text-xl" aria-label="{{ __('machines.console.order_finish_named', ['number' => $line->pickupNumber]) }}">
|
||
<x-icon name="check" class="size-6" aria-hidden="true" />
|
||
{{ __('machines.console.finish') }}
|
||
</button>
|
||
@if ($this->sameTypeMachines !== [])
|
||
<form wire:submit="moveOrder({{ $row->entryId }})" class="flex flex-wrap items-end gap-2">
|
||
<div class="min-w-40">
|
||
<x-select.native id="move-order-{{ $row->entryId }}" wire:model="moveToMachineId" :label="__('machines.console.move_to')" :aria-label="__('machines.console.move_to_named', ['number' => $line->pickupNumber])">
|
||
<option value="">{{ __('machines.task.choose_machine') }}</option>
|
||
@foreach ($this->sameTypeMachines as $other)
|
||
<option value="{{ $other->id }}">{{ $other->name }}</option>
|
||
@endforeach
|
||
</x-select.native>
|
||
</div>
|
||
<button type="submit" class="{{ $secondary }}">{{ __('machines.console.move') }}</button>
|
||
</form>
|
||
@endif
|
||
</div>
|
||
@endif
|
||
@endif
|
||
@endif
|
||
@elseif ($task !== null)
|
||
<p class="text-xl font-semibold break-words">{{ $task->title }}</p>
|
||
<p class="text-base">{{ $task->jobNumber }} {{ $task->jobName }} · {{ $task->customerName }}</p>
|
||
<p class="text-base">
|
||
{{ __('machines.show.status', ['status' => __('jobs.tasks.statuses.'.$task->status)]) }}
|
||
· {{ __('machines.show.priority', ['priority' => __('jobs.priorities.'.$task->priority)]) }}
|
||
@if ($task->dueOn !== null)
|
||
· {{ __('machines.show.due', ['date' => $this->dateLabel($task->dueOn)]) }}
|
||
@endif
|
||
</p>
|
||
@endif
|
||
@if ($row->isLate)
|
||
<p class="flex items-center gap-1 text-base font-semibold text-red-700 dark:text-red-400">
|
||
<x-icon name="exclamation-triangle" class="size-5" aria-hidden="true" />
|
||
{{ __('machines.show.late', ['date' => CarbonImmutable::parse($row->plannedOn)->format('j.n.')]) }}
|
||
</p>
|
||
@endif
|
||
@if ($task !== null)
|
||
<div class="flex flex-wrap gap-2">
|
||
<button type="button" wire:click="selectRow({{ $row->entryId }})" class="{{ $selectedEntryId === $row->entryId ? $primary : $secondary }}" aria-pressed="{{ $selectedEntryId === $row->entryId ? 'true' : 'false' }}" aria-label="{{ __('machines.console.select_named', ['title' => $task->title]) }}">
|
||
{{ __('machines.console.select') }}
|
||
</button>
|
||
@if ($this->canFinish($row))
|
||
<button type="button" wire:click="setStatus({{ $row->entryId }}, 'in_progress')" class="{{ $secondary }}" aria-label="{{ __('machines.console.start_named', ['title' => $task->title]) }}">{{ __('machines.console.start') }}</button>
|
||
<button type="button" wire:click="setStatus({{ $row->entryId }}, 'in_review')" class="{{ $secondary }}" aria-label="{{ __('machines.console.review_named', ['title' => $task->title]) }}">{{ __('machines.console.review') }}</button>
|
||
<button type="button" wire:click="finish({{ $row->entryId }})" class="{{ $primary }}" aria-label="{{ __('machines.console.finish_named', ['title' => $task->title]) }}">
|
||
<x-icon name="check" class="size-5" aria-hidden="true" />
|
||
{{ __('machines.console.finish') }}
|
||
</button>
|
||
@endif
|
||
</div>
|
||
@endif
|
||
</li>
|
||
@endforeach
|
||
</ol>
|
||
@endif
|
||
|
||
@if ($this->selectedRow?->task !== null)
|
||
@php($selected = $this->selectedRow->task)
|
||
<div id="selected-task" tabindex="-1" class="space-y-3 rounded-lg border border-zinc-300 bg-white p-3 focus:outline-none dark:border-zinc-600 dark:bg-zinc-900">
|
||
<h3 class="text-lg font-semibold">{{ __('machines.console.selected', ['title' => $selected->title]) }}</h3>
|
||
@if ($selected->instructions !== null)
|
||
<div>
|
||
<p class="font-medium">{{ __('machines.show.instructions') }}</p>
|
||
<p class="whitespace-pre-line">{{ $selected->instructions }}</p>
|
||
</div>
|
||
@endif
|
||
@if ($selected->description !== null)
|
||
<div>
|
||
<p class="font-medium">{{ __('machines.show.description') }}</p>
|
||
<p class="whitespace-pre-line">{{ $selected->description }}</p>
|
||
</div>
|
||
@endif
|
||
@can('time.book', $selected->jobId)
|
||
<form wire:submit="saveHours" class="flex flex-wrap items-end gap-2" novalidate>
|
||
<div class="w-40">
|
||
<x-input id="console-hours" wire:model="hours" inputmode="decimal" :label="__('machines.console.hours')" autocomplete="off" />
|
||
</div>
|
||
<button type="submit" class="{{ $primary }}">{{ __('machines.console.save_hours') }}</button>
|
||
</form>
|
||
@endcan
|
||
</div>
|
||
@endif
|
||
</section>
|
||
|
||
@can('inventory.record-use')
|
||
<section aria-labelledby="console-material-heading" class="space-y-3">
|
||
<h2 id="console-material-heading" class="text-xl font-semibold">{{ __('machines.console.material') }}</h2>
|
||
<p class="text-base">
|
||
{{ $this->selectedRow?->task !== null ? __('machines.console.material_for', ['title' => $this->selectedRow->task->title]) : __('machines.console.material_without_task') }}
|
||
</p>
|
||
|
||
<x-input id="console-search" wire:model.live.debounce.300ms="search" type="search" icon="magnifying-glass" :label="__('machines.console.search')" :hint="__('inventory.task.search_hint')" autocomplete="off" />
|
||
|
||
@if ($this->groups !== [])
|
||
<div class="flex flex-wrap gap-2" role="group" aria-label="{{ __('inventory.index.group') }}">
|
||
@foreach ($this->groups as $group)
|
||
<button type="button" wire:key="group-{{ $group->id }}" wire:click="chooseGroup({{ $group->id }})" class="{{ $groupId === $group->id ? $primary : $secondary }}" aria-pressed="{{ $groupId === $group->id ? 'true' : 'false' }}">{{ $group->name }}</button>
|
||
@endforeach
|
||
</div>
|
||
@endif
|
||
|
||
<p class="text-base">{{ trim($search) === '' && $groupId === null ? __('machines.console.favourites') : trans_choice('inventory.task.results', count($this->items), ['count' => count($this->items)]) }}</p>
|
||
|
||
<ul class="grid grid-cols-2 gap-2 sm:grid-cols-3">
|
||
@foreach ($this->items as $item)
|
||
<li wire:key="console-item-{{ $item->id }}">
|
||
<button
|
||
type="button"
|
||
wire:click="selectItem({{ $item->id }})"
|
||
class="flex h-full min-h-24 w-full flex-col items-start gap-1 rounded-lg border-2 p-2 text-left focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 {{ $selectedItemId === $item->id ? 'border-primary-600 dark:border-primary-400' : 'border-zinc-300 bg-white hover:bg-zinc-100 dark:border-zinc-600 dark:bg-zinc-900 dark:hover:bg-zinc-700' }}"
|
||
aria-label="{{ __('inventory.task.choose', ['item' => $item->name, 'balance' => $this->quantity($item->balanceMilli, $item->unit)]) }}"
|
||
>
|
||
@if ($item->hasImage)
|
||
<img src="{{ route('inventory.items.console-image', [$item->id, 'thumbnail']) }}" alt="" class="h-14 w-full rounded object-cover" />
|
||
@endif
|
||
<span class="font-semibold break-words">{{ $item->name }}</span>
|
||
<span class="text-base">{{ $this->quantity($item->balanceMilli, $item->unit) }}</span>
|
||
</button>
|
||
</li>
|
||
@endforeach
|
||
</ul>
|
||
|
||
@if ($this->selectedItem !== null)
|
||
<form wire:submit="recordMaterial" class="space-y-3 rounded-lg border border-zinc-300 bg-white p-3 dark:border-zinc-600 dark:bg-zinc-900" novalidate>
|
||
<p class="font-semibold">{{ $this->selectedItem->name }} ({{ __('inventory.task.balance', ['balance' => $this->quantity($this->selectedItem->balanceMilli, $this->selectedItem->unit)]) }})</p>
|
||
<div class="flex flex-wrap items-end gap-2">
|
||
<button type="button" wire:click="changeQuantity(-1)" class="{{ $secondary }} text-2xl" aria-label="{{ __('machines.console.less') }}">−</button>
|
||
<div class="w-32">
|
||
<x-input id="material-quantity" wire:model="quantity" inputmode="decimal" :label="__('inventory.task.quantity', ['unit' => __('inventory.units.'.$this->selectedItem->unit->value)])" autocomplete="off" />
|
||
</div>
|
||
<button type="button" wire:click="changeQuantity(1)" class="{{ $secondary }} text-2xl" aria-label="{{ __('machines.console.more') }}">+</button>
|
||
</div>
|
||
@if ($this->selectedRow?->task === null)
|
||
<x-input id="material-reason" wire:model="reason" :label="__('inventory.use.reason')" autocomplete="off" maxlength="255" />
|
||
@endif
|
||
<button type="submit" class="{{ $primary }} w-full text-xl">{{ __('machines.console.record_material') }}</button>
|
||
</form>
|
||
@endif
|
||
|
||
@if ($lastMovementId !== null)
|
||
<button type="button" wire:click="undoLast" class="{{ $secondary }}">
|
||
<x-icon name="arrow-uturn-left" class="size-5" aria-hidden="true" />
|
||
{{ __('machines.console.undo') }}
|
||
</button>
|
||
@endif
|
||
</section>
|
||
@endcan
|
||
</div>
|
||
|
||
@if ($machine->counters !== [] || $this->maintenance !== [])
|
||
<section aria-labelledby="console-maintenance-heading" class="space-y-3">
|
||
<h2 id="console-maintenance-heading" class="text-xl font-semibold">{{ __('machines.console.counters_and_maintenance') }}</h2>
|
||
|
||
<div class="grid gap-3 md:grid-cols-2">
|
||
@foreach ($machine->counters as $counter)
|
||
<form wire:key="console-counter-{{ $counter->id }}" wire:submit="saveUsage({{ $counter->id }})" class="flex flex-wrap items-end gap-2 rounded-lg border border-zinc-300 p-3 dark:border-zinc-600" novalidate>
|
||
<div class="min-w-40 flex-1">
|
||
<x-input
|
||
id="console-usage-{{ $counter->id }}"
|
||
wire:model="usage.{{ $counter->id }}"
|
||
inputmode="decimal"
|
||
:label="__('machines.console.usage', ['counter' => $counter->name, 'unit' => __('machines.counter_units.'.$counter->unit->value)])"
|
||
:hint="$counter->readingMilli === null ? __('machines.maintenance.no_reading') : __('machines.console.latest', ['reading' => $this->reading($counter->readingMilli)])"
|
||
autocomplete="off"
|
||
/>
|
||
</div>
|
||
<button type="submit" class="{{ $primary }}" aria-label="{{ __('machines.maintenance.save_usage_named', ['counter' => $counter->name]) }}">{{ __('machines.maintenance.save_usage') }}</button>
|
||
</form>
|
||
@endforeach
|
||
</div>
|
||
|
||
<ul class="grid gap-3 md:grid-cols-2">
|
||
@foreach ($this->maintenance as $item)
|
||
<li wire:key="console-maintenance-{{ $item->id }}" class="space-y-2 rounded-lg border border-zinc-300 p-3 dark:border-zinc-600">
|
||
<p class="font-semibold">{{ $item->name }}</p>
|
||
<p class="flex items-center gap-2 text-base font-medium @if ($item->level->value === 'overdue') text-red-700 dark:text-red-400 @elseif ($item->level->value === 'approaching') text-amber-800 dark:text-amber-300 @endif">
|
||
<x-icon :name="$this->levelIcon($item)" class="size-5" aria-hidden="true" />
|
||
{{ $this->levelLabel($item) }}@if ($this->stateText($item) !== ''): {{ $this->stateText($item) }}@endif
|
||
</p>
|
||
@if ($recordingItemId === $item->id)
|
||
<form wire:submit="recordMaintenance" class="flex flex-wrap items-end gap-2" novalidate>
|
||
<button type="submit" id="maintenance-confirm" class="{{ $primary }}">{{ __('machines.maintenance.confirm_done') }}</button>
|
||
</form>
|
||
@else
|
||
<button type="button" wire:click="startMaintenance({{ $item->id }})" class="{{ $secondary }}" aria-label="{{ __('machines.maintenance.done_named', ['name' => $item->name]) }}">
|
||
<x-icon name="wrench" class="size-5" aria-hidden="true" />
|
||
{{ __('machines.maintenance.done') }}
|
||
</button>
|
||
@endif
|
||
</li>
|
||
@endforeach
|
||
</ul>
|
||
</section>
|
||
@endif
|
||
</div>
|