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), ]); } }