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]>
87 lines
3.0 KiB
PHP
87 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Machines\Presentation\Livewire\Concerns;
|
|
|
|
use App\Modules\Machines\Application\DTOs\CounterSummary;
|
|
use App\Modules\Machines\Application\DTOs\MaintenanceItemStatus;
|
|
use App\Modules\Machines\Domain\ValueObjects\Reading;
|
|
|
|
/**
|
|
* Texts of a maintenance item's state, shared by the machine page and the
|
|
* machine console: the level, the counter amount left and the due day.
|
|
*/
|
|
trait DescribesMaintenance
|
|
{
|
|
use FormatsMachines;
|
|
|
|
public function levelLabel(MaintenanceItemStatus $item): string
|
|
{
|
|
return __('machines.maintenance.levels.'.$item->level->value);
|
|
}
|
|
|
|
public function levelIcon(MaintenanceItemStatus $item): string
|
|
{
|
|
return match ($item->level->value) {
|
|
'overdue' => 'exclamation-triangle',
|
|
'approaching' => 'clock',
|
|
default => 'check-circle',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* E.g. "jäljellä 1 200 kpl, erääntyy 30.11.2026".
|
|
*/
|
|
public function stateText(MaintenanceItemStatus $item): string
|
|
{
|
|
$parts = [];
|
|
|
|
if ($item->remainingMilli !== null && $item->counterUnit !== null) {
|
|
$unit = __('machines.counter_units.'.$item->counterUnit->value);
|
|
$parts[] = $item->remainingMilli >= 0
|
|
? __('machines.maintenance.remaining', ['amount' => $this->reading($item->remainingMilli), 'unit' => $unit])
|
|
: __('machines.maintenance.over', ['amount' => $this->reading(-$item->remainingMilli), 'unit' => $unit]);
|
|
}
|
|
|
|
if ($item->dueOn !== null) {
|
|
$parts[] = __($item->level->value === 'overdue' ? 'machines.maintenance.was_due' : 'machines.maintenance.due', ['date' => $this->dateLabel($item->dueOn)]);
|
|
}
|
|
|
|
return implode(', ', $parts);
|
|
}
|
|
|
|
/**
|
|
* E.g. "20 000 tulosteet" or "joka 2. viikko".
|
|
*/
|
|
public function intervalText(MaintenanceItemStatus $item): string
|
|
{
|
|
$parts = [];
|
|
|
|
if ($item->intervalMilli !== null && $item->counterUnit !== null) {
|
|
$parts[] = __('machines.maintenance.every_amount', [
|
|
'amount' => $this->reading($item->intervalMilli),
|
|
'unit' => __('machines.counter_units.'.$item->counterUnit->value),
|
|
'counter' => (string) $item->counterName,
|
|
]);
|
|
}
|
|
|
|
if ($item->period !== null) {
|
|
$parts[] = trans_choice('machines.maintenance.every_period.'.$item->period->value, $item->periodCount, ['count' => $item->periodCount]);
|
|
}
|
|
|
|
return implode(__('machines.maintenance.or'), $parts);
|
|
}
|
|
|
|
/**
|
|
* E.g. "Laskuriin Tulosteet lisätty 350 kpl, laskuri nyt 20 350 kpl."
|
|
*/
|
|
public function usageSaved(CounterSummary $counter, string $usage, int $readingMilli): string
|
|
{
|
|
return __('machines.maintenance.usage_saved', [
|
|
'counter' => $counter->name,
|
|
'usage' => $this->reading((int) Reading::parse($usage)),
|
|
'reading' => $this->reading($readingMilli),
|
|
'unit' => __('machines.counter_units.'.$counter->unit->value),
|
|
]);
|
|
}
|
|
}
|