diff --git a/app/Modules/Inventory/Application/Contracts/StockQueries.php b/app/Modules/Inventory/Application/Contracts/StockQueries.php
index 0f0a52f..d2f6b9c 100644
--- a/app/Modules/Inventory/Application/Contracts/StockQueries.php
+++ b/app/Modules/Inventory/Application/Contracts/StockQueries.php
@@ -58,6 +58,14 @@ interface StockQueries
*/
public function taskSuggestions(int $taskId): array;
+ /**
+ * Items used most often on the machine in the last 90 days, then the
+ * ones used most recently, for the machine console (spec 19.6).
+ *
+ * @return array{frequent: list, recent: list}
+ */
+ public function machineFavourites(int $machineId, int $limit = 8): array;
+
/**
* The private-disk path of the item's image or its thumbnail.
*/
diff --git a/app/Modules/Inventory/Infrastructure/Persistence/Repositories/EloquentStockQueries.php b/app/Modules/Inventory/Infrastructure/Persistence/Repositories/EloquentStockQueries.php
index 164b2c9..9b7249f 100644
--- a/app/Modules/Inventory/Infrastructure/Persistence/Repositories/EloquentStockQueries.php
+++ b/app/Modules/Inventory/Infrastructure/Persistence/Repositories/EloquentStockQueries.php
@@ -130,6 +130,22 @@ class EloquentStockQueries implements StockQueries
->all();
}
+ public function machineFavourites(int $machineId, int $limit = 8): array
+ {
+ $uses = StockMovementModel::query()
+ ->where('machine_id', $machineId)
+ ->whereIn('kind', ['consumption', 'write_off'])
+ ->whereNull('reverses_movement_id')
+ ->where('recorded_at', '>=', now()->subDays(90))
+ ->orderByDesc('id')
+ ->get(['id', 'stock_item_id']);
+
+ $frequent = $uses->countBy('stock_item_id')->sortDesc()->keys()->take($limit)->map(fn ($id): int => (int) $id)->values()->all();
+ $recent = $uses->pluck('stock_item_id')->unique()->take($limit)->map(fn ($id): int => (int) $id)->values()->all();
+
+ return ['frequent' => $frequent, 'recent' => $recent];
+ }
+
public function imagePathOf(int $itemId, bool $thumbnail): ?string
{
$model = StockItemModel::query()->find($itemId, ['id', 'image_path', 'thumbnail_path']);
diff --git a/app/Modules/Machines/Presentation/Livewire/⚡console.blade.php b/app/Modules/Machines/Presentation/Livewire/⚡console.blade.php
new file mode 100644
index 0000000..394ea08
--- /dev/null
+++ b/app/Modules/Machines/Presentation/Livewire/⚡console.blade.php
@@ -0,0 +1,726 @@
+
+ */
+ #[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 = '';
+
+ /**
+ * @var array
+ */
+ public array $readings = [];
+
+ #[Locked]
+ public ?int $recordingItemId = null;
+
+ public string $recordReading = '';
+
+ #[Locked]
+ public string $message = '';
+
+ #[Locked]
+ public string $refreshMessage = '';
+
+ 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
+ */
+ #[Computed]
+ public function rows(): array
+ {
+ return app(MachineQueries::class)->rowsOn($this->machineId, $this->day(), $this->today);
+ }
+
+ #[Computed]
+ public function selectedRow(): ?QueueRow
+ {
+ return $this->selectedEntryId === null ? null : collect($this->rows)->firstWhere('entryId', $this->selectedEntryId);
+ }
+
+ /**
+ * @return list
+ */
+ #[Computed]
+ public function maintenance(): array
+ {
+ return app(MaintenanceQueries::class)->itemsOf($this->machineId);
+ }
+
+ /**
+ * @return list
+ */
+ #[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
+ */
+ #[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->hours = '';
+ }
+
+ public function saveReading(int $counterId, MachineMaintenance $maintenance): void
+ {
+ $this->authorize('machines.use');
+ $this->resetErrorBag('readings.'.$counterId);
+
+ $counter = collect($this->machine->counters)->firstWhere('id', $counterId) ?? abort(404);
+
+ try {
+ $milli = $maintenance->recordReading($counterId, $this->readings[$counterId] ?? '', (int) auth()->id());
+ } catch (DomainException) {
+ $this->addError('readings.'.$counterId, __('machines.maintenance.errors.reading'));
+
+ 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);
+ }
+
+ 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->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(), $item->counterId === null ? '' : $this->recordReading);
+ } catch (DomainException) {
+ $this->addError('recordReading', __('machines.maintenance.errors.reading'));
+
+ return;
+ }
+
+ $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);
+
+ $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
+
+
+
+
+
{{ $machine->name }}
+
{{ __('machines.console.user', ['name' => auth()->user()?->name]) }}
+
+
+
+
+
+
{{ $refreshMessage }}
+
{{ $message }}
+
+
+ @if ($lateMaintenance !== [])
+
+ @foreach ($lateMaintenance as $late)
+
+
+ {{ __('machines.console.maintenance_late', ['name' => $late->name]) }}
+
+ @endforeach
+
+ @endif
+
+
+
+ {{ $nextDay ? __('machines.console.next_list', ['date' => $this->dateLabel($this->day())]) : __('machines.console.today_list') }}
+
+
+
+
+
+ @if ($this->rows === [])
+ {{ __('machines.show.none') }}
+ @else
+
+ @foreach ($this->rows as $row)
+ @php($task = $row->task)
+ -
+ @if ($this->nextEntryId() === $row->entryId)
+
{{ __('machines.console.next') }}
+ @endif
+ @if ($row->isOrder())
+ {{ __('machines.show.order') }}
+ @elseif ($task !== null)
+ {{ $task->title }}
+ {{ $task->jobNumber }} {{ $task->jobName }} · {{ $task->customerName }}
+
+ {{ __('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
+
+ @endif
+ @if ($row->isLate)
+
+
+ {{ __('machines.show.late', ['date' => CarbonImmutable::parse($row->plannedOn)->format('j.n.')]) }}
+
+ @endif
+ @if ($task !== null)
+
+
+ @if ($this->canFinish($row))
+
+
+
+ @endif
+
+ @endif
+
+ @endforeach
+
+ @endif
+
+ @if ($this->selectedRow?->task !== null)
+ @php($selected = $this->selectedRow->task)
+
+
{{ __('machines.console.selected', ['title' => $selected->title]) }}
+ @if ($selected->instructions !== null)
+
+
{{ __('machines.show.instructions') }}
+
{{ $selected->instructions }}
+
+ @endif
+ @if ($selected->description !== null)
+
+
{{ __('machines.show.description') }}
+
{{ $selected->description }}
+
+ @endif
+ @can('time.book', $selected->jobId)
+
+ @endcan
+
+ @endif
+
+
+ @can('inventory.record-use')
+
+ {{ __('machines.console.material') }}
+
+ {{ $this->selectedRow?->task !== null ? __('machines.console.material_for', ['title' => $this->selectedRow->task->title]) : __('machines.console.material_without_task') }}
+
+
+
+
+ @if ($this->groups !== [])
+
+ @foreach ($this->groups as $group)
+
+ @endforeach
+
+ @endif
+
+ {{ trim($search) === '' && $groupId === null ? __('machines.console.favourites') : trans_choice('inventory.task.results', count($this->items), ['count' => count($this->items)]) }}
+
+
+ @foreach ($this->items as $item)
+ -
+
+
+ @endforeach
+
+
+ @if ($this->selectedItem !== null)
+
+ @endif
+
+ @if ($lastMovementId !== null)
+
+ @endif
+
+ @endcan
+
+
+
+ {{ __('machines.console.counters_and_maintenance') }}
+
+
+ @foreach ($machine->counters as $counter)
+
+ @endforeach
+
+
+
+
+
diff --git a/app/Modules/Machines/Presentation/Livewire/⚡index.blade.php b/app/Modules/Machines/Presentation/Livewire/⚡index.blade.php
index ea87091..2b1d510 100644
--- a/app/Modules/Machines/Presentation/Livewire/⚡index.blade.php
+++ b/app/Modules/Machines/Presentation/Livewire/⚡index.blade.php
@@ -128,6 +128,7 @@ new class extends Component
@endunless
+ {{ __('machines.index.console_named', ['name' => $machine->name]) }}
@endforeach
diff --git a/app/Modules/Machines/Presentation/Livewire/⚡show.blade.php b/app/Modules/Machines/Presentation/Livewire/⚡show.blade.php
index c3d4c9e..8ceb00f 100644
--- a/app/Modules/Machines/Presentation/Livewire/⚡show.blade.php
+++ b/app/Modules/Machines/Presentation/Livewire/⚡show.blade.php
@@ -257,9 +257,12 @@ new class extends Component
@if ($machine->description !== null)
{{ $machine->description }}
@endif
- @can('machines.manage')
-
- @endcan
+
+
+ @can('machines.manage')
+
+ @endcan
+
{{ $message }}
diff --git a/app/Modules/Machines/Presentation/Routes/web.php b/app/Modules/Machines/Presentation/Routes/web.php
index 1f6ae29..2aecc7c 100644
--- a/app/Modules/Machines/Presentation/Routes/web.php
+++ b/app/Modules/Machines/Presentation/Routes/web.php
@@ -16,4 +16,5 @@ Route::middleware(['web', 'auth', 'can:machines.use'])
});
Route::livewire('/{machine}', 'machines::show')->whereNumber('machine')->name('show');
+ Route::livewire('/{machine}/console', 'machines::console')->whereNumber('machine')->name('console');
});
diff --git a/app/Modules/Users/Presentation/Http/Controllers/LogoutController.php b/app/Modules/Users/Presentation/Http/Controllers/LogoutController.php
index 52aad30..6884950 100644
--- a/app/Modules/Users/Presentation/Http/Controllers/LogoutController.php
+++ b/app/Modules/Users/Presentation/Http/Controllers/LogoutController.php
@@ -6,12 +6,14 @@ use App\Modules\Users\Presentation\Http\Middleware\SetLocale;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Str;
class LogoutController
{
public function __invoke(Request $request): RedirectResponse
{
$locale = app()->getLocale();
+ $returnTo = $this->returnTo($request);
Auth::guard('web')->logout();
$request->session()->invalidate();
@@ -20,6 +22,23 @@ class LogoutController
// The login page stays in the language the user had chosen.
$request->session()->put(SetLocale::SESSION_KEY, $locale);
+ // "Change user" on a machine console: the next user signs in back to the console.
+ if ($returnTo !== null) {
+ $request->session()->put('url.intended', $returnTo);
+ }
+
return redirect()->route('login')->with('status', __('auth.logged_out'));
}
+
+ /**
+ * A page of this application to return to after the next login, never
+ * another site.
+ */
+ private function returnTo(Request $request): ?string
+ {
+ $returnTo = (string) $request->input('return_to', '');
+ $base = rtrim(url('/'), '/').'/';
+
+ return $returnTo !== '' && Str::startsWith($returnTo, $base) && ! Str::contains($returnTo, ['\\', '@']) ? $returnTo : null;
+ }
}
diff --git a/lang/en/machines.php b/lang/en/machines.php
index 96b43a7..0a0e467 100644
--- a/lang/en/machines.php
+++ b/lang/en/machines.php
@@ -32,6 +32,7 @@ return [
'responsible' => 'Responsible: :name',
'open' => 'Work list and details',
'open_named' => 'Work list and details of :name',
+ 'console_named' => 'Machine console: :name',
],
'form' => [
@@ -220,6 +221,49 @@ return [
'reading' => 'Enter a reading of zero or more, at most three decimals.',
],
],
+ 'console' => [
+ 'title' => 'Machine console: :name',
+ 'user' => 'User: :name',
+ 'refresh' => 'Refresh',
+ 'refreshed' => 'Refreshed at :time.',
+ 'new_rows' => '{0} No new rows.|{1} 1 new row on the work list.|[2,*] :count new rows on the work list.',
+ 'change_user' => 'Change user',
+ 'back' => 'To the normal view',
+ 'maintenance_late' => 'Maintenance late: :name',
+ 'today_list' => 'Today\'s work list',
+ 'next_list' => 'Work list :date (viewing)',
+ 'next' => 'Next',
+ 'select' => 'Select',
+ 'select_named' => 'Select task :title',
+ 'start' => 'Start',
+ 'start_named' => 'Start: :title',
+ 'review' => 'To review',
+ 'review_named' => 'To review: :title',
+ 'finish' => 'Done',
+ 'finish_named' => 'Done: :title',
+ 'status_changed' => ':title: status now :status.',
+ 'finished' => ':title marked done and removed from the work list.',
+ 'selected' => 'Selected task: :title',
+ 'hours' => 'Hours today (h)',
+ 'save_hours' => 'Record hours',
+ 'hours_saved' => ':hours h recorded on :title. Day total :total h.',
+ 'hours_error' => 'The hours could not be recorded. Check the amount (in steps of 0.25 h) and that the day\'s hours are not approved yet.',
+ 'hours_note' => 'Machine :machine',
+ 'material' => 'Material used',
+ 'material_for' => 'Recorded on task :title.',
+ 'material_without_task' => 'No task selected: the use is recorded on the machine. You can give a reason (e.g. a test run) or select a task from the work list.',
+ 'search' => 'Search material',
+ 'favourites' => 'The items used most often and most recently on this machine.',
+ 'less' => 'Less',
+ 'more' => 'More',
+ 'record_material' => 'Record use',
+ 'material_recorded' => 'Recorded :item :quantity. Balance now :balance.',
+ 'material_undone' => 'The latest record was undone.',
+ 'undo' => 'Undo the latest record',
+ 'reason_required' => 'Give a reason when no task is selected.',
+ 'counters_and_maintenance' => 'Counters and maintenance',
+ 'latest' => 'Latest reading :reading',
+ ],
'errors' => [
'name' => 'Enter a name (1–150 characters).',
'name_taken' => 'The name is already in use.',
diff --git a/lang/fi/machines.php b/lang/fi/machines.php
index 75b29dd..ce5b054 100644
--- a/lang/fi/machines.php
+++ b/lang/fi/machines.php
@@ -32,6 +32,7 @@ return [
'responsible' => 'Vastuuhenkilö: :name',
'open' => 'Työlista ja tiedot',
'open_named' => 'Koneen :name työlista ja tiedot',
+ 'console_named' => 'Konekäyttöliittymä: :name',
],
'form' => [
@@ -220,6 +221,49 @@ return [
'reading' => 'Anna lukema nollana tai suurempana lukuna, enintään kolme desimaalia.',
],
],
+ 'console' => [
+ 'title' => 'Konekäyttöliittymä: :name',
+ 'user' => 'Käyttäjä: :name',
+ 'refresh' => 'Päivitä',
+ 'refreshed' => 'Päivitetty klo :time.',
+ 'new_rows' => '{0} Ei uusia rivejä.|{1} 1 uusi rivi työlistalla.|[2,*] :count uutta riviä työlistalla.',
+ 'change_user' => 'Vaihda käyttäjä',
+ 'back' => 'Tavalliseen näkymään',
+ 'maintenance_late' => 'Huolto myöhässä: :name',
+ 'today_list' => 'Tämän päivän työlista',
+ 'next_list' => 'Työlista :date (katselu)',
+ 'next' => 'Seuraavana',
+ 'select' => 'Valitse',
+ 'select_named' => 'Valitse tehtävä :title',
+ 'start' => 'Aloita',
+ 'start_named' => 'Aloita: :title',
+ 'review' => 'Tarkastettavaksi',
+ 'review_named' => 'Tarkastettavaksi: :title',
+ 'finish' => 'Valmis',
+ 'finish_named' => 'Valmis: :title',
+ 'status_changed' => ':title: tila nyt :status.',
+ 'finished' => ':title merkitty valmiiksi ja poistettu työlistalta.',
+ 'selected' => 'Valittu tehtävä: :title',
+ 'hours' => 'Tämän päivän tunnit (h)',
+ 'save_hours' => 'Kirjaa tunnit',
+ 'hours_saved' => 'Tunnit :hours h kirjattu tehtävälle :title. Päivän yhteensä :total h.',
+ 'hours_error' => 'Tunteja ei voitu kirjata. Tarkista määrä (0,25 h tarkkuudella), ja ettei päivän tunteja ole jo hyväksytty.',
+ 'hours_note' => 'Kone :machine',
+ 'material' => 'Materiaalin kirjaus',
+ 'material_for' => 'Kirjataan tehtävälle :title.',
+ 'material_without_task' => 'Ei valittua tehtävää: käyttö kirjataan koneelle. Voit antaa syyn (esim. koeajo) tai valita tehtävän työlistalta.',
+ 'search' => 'Hae materiaali',
+ 'favourites' => 'Tämän koneen yleisimmät ja viimeksi käytetyt nimikkeet.',
+ 'less' => 'Vähemmän',
+ 'more' => 'Enemmän',
+ 'record_material' => 'Kirjaa käyttö',
+ 'material_recorded' => 'Kirjattu :item :quantity. Saldo nyt :balance.',
+ 'material_undone' => 'Viimeisin kirjaus peruttu.',
+ 'undo' => 'Peru viimeisin kirjaus',
+ 'reason_required' => 'Anna syy, kun tehtävää ei ole valittu.',
+ 'counters_and_maintenance' => 'Laskurit ja huollot',
+ 'latest' => 'Viimeisin lukema :reading',
+ ],
'errors' => [
'name' => 'Anna nimi (1–150 merkkiä).',
'name_taken' => 'Nimi on jo käytössä.',
diff --git a/resources/views/layouts/console.blade.php b/resources/views/layouts/console.blade.php
new file mode 100644
index 0000000..129cc7e
--- /dev/null
+++ b/resources/views/layouts/console.blade.php
@@ -0,0 +1,54 @@
+
+{{--
+ Full-screen layout of the machine console (spec 19.6) for the tablet or
+ touch screen next to a machine: no main menu, large text. The page's own
+ header has the machine's name, the user, Refresh, Change user and the
+ way back. The theme follows the stored choice like the main layout.
+--}}
+
+
+
+
+
+ {{ $title ?? config('app.name') }}
+
+
+
+
+
+
+ @include('partials.tallstackui-script')
+ @livewireStyles
+ @vite(['resources/css/app.css', 'resources/js/app.js'])
+
+
+
+ {{ __('layout.skip_to_content') }}
+
+
+
+ {{ $slot }}
+
+
+ @livewireScripts
+
+
diff --git a/tests/Browser/MachinesAccessibilityTest.php b/tests/Browser/MachinesAccessibilityTest.php
index 15a4c39..54a18e4 100644
--- a/tests/Browser/MachinesAccessibilityTest.php
+++ b/tests/Browser/MachinesAccessibilityTest.php
@@ -84,3 +84,30 @@ it('records maintenance done with the keyboard', function () {
->assertSee('Kunnossa')
->assertNoAccessibilityIssues(level: 2);
});
+
+it('has no accessibility issues on the machine console', function (string $device, string $colorScheme) {
+ $visit = visit(route('machines.console', $this->machine->id));
+ $visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
+ $visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
+
+ $visit->assertSee('Banderolli')
+ ->assertSee(__('machines.console.maintenance_late', ['name' => 'Pään puhdistus']))
+ ->assertNoJavaScriptErrors()
+ ->assertNoAccessibilityIssues(level: 2);
+})->with([
+ 'desktop, light' => ['desktop', 'light'],
+ 'desktop, dark' => ['desktop', 'dark'],
+ 'mobile, light' => ['mobile', 'light'],
+ 'mobile, dark' => ['mobile', 'dark'],
+]);
+
+it('refreshes the console on a tablet and keeps focus on the button', function () {
+ visit(route('machines.console', $this->machine->id))
+ ->resize(1024, 768)
+ ->click('#console-refresh')
+ ->assertSee('Päivitetty klo')
+ ->assertScript('document.activeElement.id', 'console-refresh')
+ ->click('[aria-label="'.__('machines.console.select_named', ['title' => 'Banderolli']).'"]')
+ ->assertSee(__('machines.console.selected', ['title' => 'Banderolli']))
+ ->assertNoAccessibilityIssues(level: 2);
+});
diff --git a/tests/Feature/Modules/Machines/ConsoleTest.php b/tests/Feature/Modules/Machines/ConsoleTest.php
new file mode 100644
index 0000000..a0da817
--- /dev/null
+++ b/tests/Feature/Modules/Machines/ConsoleTest.php
@@ -0,0 +1,132 @@
+travelTo(now()->setTimezone(config('app.business_timezone'))->setTime(10, 0));
+ $this->employee = User::factory()->employee()->create(['name' => 'Eero Työntekijä']);
+ $this->actingAs($this->employee);
+
+ $print = ServiceUnitModel::query()->where('name', 'Painotuotanto')->sole();
+ $print->update(['uses_stock' => true]);
+ $this->machine = MachineModel::factory()->inUnits([$print->id])->create(['name' => 'Suurkuvatulostin']);
+
+ $this->job = CustomerJobModel::factory()->create(['name' => 'Messut', 'status' => 'order', 'instructions' => 'Kiiltävä laminointi']);
+ DB::table('customer_job_service_unit')->where('customer_job_id', $this->job->id)->update(['service_unit_id' => $print->id]);
+ $this->task = TaskModel::factory()->create([
+ 'customer_job_id' => $this->job->id,
+ 'work_type_id' => WorkTypeModel::query()->where('name', 'painotyö')->value('id'),
+ 'title' => 'Banderolli',
+ ]);
+ app(MachineWorkList::class)->planTask($this->task->id, $this->machine->id, null);
+
+ $papers = StockItemGroupModel::factory()->create(['name' => 'Paperit']);
+ $this->paper = StockItemModel::factory()->create(['stock_item_group_id' => $papers->id, 'name' => 'Bannerikangas', 'unit' => 'square_metre']);
+});
+
+function console(object $test): mixed
+{
+ return Livewire::test('machines::console', ['machine' => $test->machine->id]);
+}
+
+it('opens without the main menu and shows today\'s work list', function () {
+ $this->get(route('machines.console', $this->machine->id))
+ ->assertOk()
+ ->assertSee('Suurkuvatulostin')
+ ->assertSee('Banderolli')
+ ->assertSee(__('machines.console.refresh'))
+ ->assertDontSee(__('layout.main_menu'));
+
+ $this->actingAs(User::factory()->subcontractor()->create());
+ $this->get(route('machines.console', $this->machine->id))->assertForbidden();
+});
+
+it('records material on the selected task, undoes it, and records hours', function () {
+ console($this)
+ ->call('selectRow', MachineQueueEntryModel::query()->sole()->id)
+ ->assertSee('Kiiltävä laminointi')
+ ->call('chooseGroup', StockItemGroupModel::query()->value('id'))
+ ->assertSee('Bannerikangas')
+ ->call('selectItem', $this->paper->id)
+ ->call('changeQuantity', 1)
+ ->assertSet('quantity', '2')
+ ->call('recordMaterial')
+ ->assertHasNoErrors()
+ ->assertSet('message', "Kirjattu Bannerikangas 2\u{00A0}m². Saldo nyt -2\u{00A0}m².")
+ ->call('undoLast')
+ ->assertSet('message', __('machines.console.material_undone'))
+ ->set('hours', '1,5')
+ ->call('saveHours')
+ ->assertHasNoErrors();
+
+ $use = StockMovementModel::query()->where('kind', 'consumption')->sole();
+
+ expect($use->only(['task_id', 'machine_id', 'quantity_milli']))->toBe(['task_id' => $this->task->id, 'machine_id' => $this->machine->id, 'quantity_milli' => -2_000])
+ ->and((float) TimeEntryModel::query()->sole()->hours)->toBe(1.5);
+
+ // Frequent items come first without a search.
+ console($this)->assertSee('Bannerikangas');
+});
+
+it('records material without a task on the machine, with an optional reason', function () {
+ console($this)
+ ->set('search', 'banneri')
+ ->call('selectItem', $this->paper->id)
+ ->set('reason', 'Koeajo')
+ ->call('recordMaterial')
+ ->assertHasNoErrors();
+
+ expect(StockMovementModel::query()->sole()->only(['task_id', 'machine_id', 'reason']))
+ ->toBe(['task_id' => null, 'machine_id' => $this->machine->id, 'reason' => 'Koeajo']);
+});
+
+it('finishes a task from the console, which marks it done', function () {
+ $entry = MachineQueueEntryModel::query()->sole();
+
+ console($this)
+ ->call('setStatus', $entry->id, 'in_progress')
+ ->assertSet('message', 'Banderolli: tila nyt Työn alla.')
+ ->call('finish', $entry->id)
+ ->assertSet('message', __('machines.console.finished', ['title' => 'Banderolli']))
+ ->assertDontSee(__('machines.console.finish_named', ['title' => 'Banderolli']));
+
+ expect($this->task->fresh()->status->value)->toBe('done');
+});
+
+it('announces new rows when refreshed', function () {
+ $component = console($this);
+
+ $other = TaskModel::factory()->create(['customer_job_id' => $this->job->id, 'work_type_id' => $this->task->work_type_id, 'title' => 'Juliste']);
+ app(MachineWorkList::class)->planTask($other->id, $this->machine->id, null);
+
+ $component->call('refresh')
+ ->assertSet('refreshMessage', fn (string $message) => str_contains($message, '1 uusi rivi työlistalla.'))
+ ->assertSee('Juliste')
+ ->call('showDay', true)
+ ->assertDontSee('Juliste');
+});
+
+it('returns to the console after changing user', function () {
+ $this->post(route('logout'), ['return_to' => route('machines.console', $this->machine->id)])->assertRedirect(route('login'));
+ expect(session('url.intended'))->toBe(route('machines.console', $this->machine->id));
+
+ $this->actingAs($this->employee);
+ $this->post(route('logout'), ['return_to' => 'https://example.com/phish']);
+ expect(session('url.intended'))->toBeNull();
+});