Give the machine console its own session with PIN sign-in, make counters cumulative

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]>
This commit is contained in:
2026-11-29 09:58:11 +02:00
co-authored by Claude Sonnet 5.5
parent 87e38260dc
commit 32c33e2a64
55 changed files with 1660 additions and 194 deletions
@@ -17,6 +17,8 @@ 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;
@@ -36,8 +38,9 @@ use Livewire\Component;
* 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, counter
* readings and maintenance. Touch targets are at least 44 × 44 px. The
* 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.
*/
@@ -85,15 +88,15 @@ new #[Layout('layouts.console')] class extends Component
public string $hours = '';
/**
* Usage typed, by counter id.
*
* @var array<int, string>
*/
public array $readings = [];
public array $usage = [];
#[Locked]
public ?int $recordingItemId = null;
public string $recordReading = '';
#[Locked]
public string $message = '';
@@ -487,35 +490,55 @@ new #[Layout('layouts.console')] class extends Component
}
$this->message = __('machines.console.hours_saved', ['hours' => $this->hours, 'title' => $task->title, 'total' => $total]);
$this->suggestHourCounters($this->hours);
$this->hours = '';
}
public function saveReading(int $counterId, MachineMaintenance $maintenance): void
/**
* 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('readings.'.$counterId);
$this->resetErrorBag('usage.'.$counterId);
$counter = collect($this->machine->counters)->firstWhere('id', $counterId) ?? abort(404);
$usage = $this->usage[$counterId] ?? '';
try {
$milli = $maintenance->recordReading($counterId, $this->readings[$counterId] ?? '', (int) auth()->id());
$milli = $maintenance->recordUsage($counterId, $usage, (int) auth()->id());
} catch (DomainException) {
$this->addError('readings.'.$counterId, __('machines.maintenance.errors.reading'));
$this->addError('usage.'.$counterId, __('machines.maintenance.errors.usage'));
return;
}
$this->message = __('machines.maintenance.reading_saved', ['counter' => $counter->name, 'reading' => $this->reading($milli), 'unit' => __('machines.counter_units.'.$counter->unit->value)]);
unset($this->readings[$counterId], $this->machine, $this->maintenance);
$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');
$item = collect($this->maintenance)->firstWhere('id', $itemId) ?? abort(404);
$this->recordingItemId = $itemId;
$this->recordReading = $item->readingMilli === null ? '' : str_replace("\u{00A0}", '', $this->reading($item->readingMilli));
$this->recordingItemId = (collect($this->maintenance)->firstWhere('id', $itemId) ?? abort(404))->id;
$this->js("setTimeout(() => document.getElementById('maintenance-confirm')?.focus())");
}
@@ -526,11 +549,9 @@ new #[Layout('layouts.console')] class extends Component
$item = collect($this->maintenance)->firstWhere('id', $this->recordingItemId) ?? abort(404);
try {
$result = $maintenance->recordMaintenance($item->id, (int) auth()->id(), $item->counterId === null ? '' : $this->recordReading);
$result = $maintenance->recordMaintenance($item->id, (int) auth()->id());
} catch (DomainException) {
$this->addError('recordReading', __('machines.maintenance.errors.reading'));
return;
abort(404);
}
$this->message = __('machines.maintenance.recorded', ['name' => $item->name]).($result['stockRecorded'] ? '' : ' '.__('machines.maintenance.stock_not_recorded'));
@@ -612,14 +633,8 @@ new #[Layout('layouts.console')] class extends Component
<x-icon name="arrow-path" class="size-6" aria-hidden="true" />
{{ __('machines.console.refresh') }}
</button>
<form method="POST" action="{{ route('logout') }}">
@csrf
<input type="hidden" name="return_to" value="{{ route('machines.console', $machine->id) }}">
<button type="submit" class="{{ $touch }} border border-zinc-300 text-zinc-100 hover:bg-zinc-700">
<x-icon name="user-circle" class="size-6" aria-hidden="true" />
{{ __('machines.console.change_user') }}
</button>
</form>
<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') }}
@@ -811,7 +826,7 @@ new #[Layout('layouts.console')] class extends Component
aria-label="{{ __('inventory.task.choose', ['item' => $item->name, 'balance' => $this->quantity($item->balanceMilli, $item->unit)]) }}"
>
@if ($item->hasImage)
<img src="{{ route('inventory.items.image', [$item->id, 'thumbnail']) }}" alt="" class="h-14 w-full rounded object-cover" />
<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>
@@ -847,23 +862,24 @@ new #[Layout('layouts.console')] class extends Component
@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="saveReading({{ $counter->id }})" class="flex flex-wrap items-end gap-2 rounded-lg border border-zinc-300 p-3 dark:border-zinc-600" novalidate>
<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-reading-{{ $counter->id }}"
wire:model="readings.{{ $counter->id }}"
id="console-usage-{{ $counter->id }}"
wire:model="usage.{{ $counter->id }}"
inputmode="decimal"
:label="$counter->name.' ('.__('machines.counter_units.'.$counter->unit->value).')'"
: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_reading_named', ['counter' => $counter->name]) }}">{{ __('machines.maintenance.save_reading') }}</button>
<button type="submit" class="{{ $primary }}" aria-label="{{ __('machines.maintenance.save_usage_named', ['counter' => $counter->name]) }}">{{ __('machines.maintenance.save_usage') }}</button>
</form>
@endforeach
</div>
@@ -878,11 +894,6 @@ new #[Layout('layouts.console')] class extends Component
</p>
@if ($recordingItemId === $item->id)
<form wire:submit="recordMaintenance" class="flex flex-wrap items-end gap-2" novalidate>
@if ($item->counterId !== null)
<div class="w-40">
<x-input id="maintenance-reading" wire:model="recordReading" inputmode="decimal" :label="__('machines.maintenance.reading_at', ['counter' => (string) $item->counterName])" autocomplete="off" />
</div>
@endif
<button type="submit" id="maintenance-confirm" class="{{ $primary }}">{{ __('machines.maintenance.confirm_done') }}</button>
</form>
@else
@@ -895,4 +906,5 @@ new #[Layout('layouts.console')] class extends Component
@endforeach
</ul>
</section>
@endif
</div>