@@ -0,0 +1,726 @@
< ? 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\Presentation\Livewire\Concerns\DescribesMaintenance ;
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 , counter
* readings 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 = '' ;
/**
* @ var array < int , string >
*/
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 < QueueRow >
*/
#[ 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 < 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 -> 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
< div wire : poll . 30 s = " 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 >
< 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 >
< 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 ())
< p class = " font-semibold " > {{ __ ( 'machines.show.order' ) }} </ p >
@ 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 . 300 ms = " 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.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 >
< 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 >
< div class = " min-w-40 flex-1 " >
< x - input
id = " console-reading- { { $counter->id }} "
wire : model = " readings. { { $counter->id }} "
inputmode = " decimal "
: label = " $counter->name .' ('.__('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 >
</ 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 >
@ 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
< 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 >
</ div >