72 lines
2.4 KiB
PHP
72 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Machines\Presentation\Livewire\Concerns;
|
|
|
|
use App\Modules\Machines\Application\DTOs\MaintenanceItemStatus;
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
}
|