Track machine counters and maintenance with counter and time intervals
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user