Added option: Both tires changed

This commit is contained in:
marijo 2026-06-26 06:05:45 +00:00
parent a1984033bb
commit 10c9496f9a

View file

@ -149,6 +149,7 @@ $types = [
'oil_change' => 'Oil change', 'oil_change' => 'Oil change',
'front_tyre_change' => 'Front tyre changed', 'front_tyre_change' => 'Front tyre changed',
'rear_tyre_change' => 'Rear tyre changed', 'rear_tyre_change' => 'Rear tyre changed',
'both_tires_change' => 'Both tires changed',
'shaft_oil_change' => 'Drive shaft oil change', 'shaft_oil_change' => 'Drive shaft oil change',
'brake_pads' => 'Brake pads', 'brake_pads' => 'Brake pads',
'registration' => 'Registration / insurance', 'registration' => 'Registration / insurance',
@ -177,9 +178,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
'cost' => $cost === '' ? null : $cost, 'cost' => $cost === '' ? null : $cost,
'note' => $note, 'note' => $note,
]; ];
if (array_key_exists($type, $state['last'])) { $serviceKeys = $type === 'both_tires_change' ? ['front_tyre_change', 'rear_tyre_change'] : [$type];
$prev = $state['last'][$type] ?? null; foreach ($serviceKeys as $serviceKey) {
if (!is_array($prev) || $km >= (int)($prev['km'] ?? 0)) $state['last'][$type] = $event; if (array_key_exists($serviceKey, $state['last'])) {
$prev = $state['last'][$serviceKey] ?? null;
if (!is_array($prev) || $km >= (int)($prev['km'] ?? 0)) $state['last'][$serviceKey] = $event;
}
} }
$event['summary'] = $types[$type] . ' @ ' . $km . ' km' . ($note ? ' - ' . $note : ''); $event['summary'] = $types[$type] . ' @ ' . $km . ' km' . ($note ? ' - ' . $note : '');
$state['latest_event'] = $event; $state['latest_event'] = $event;
@ -195,7 +199,7 @@ function event_class(?string $type): string {
return match ($type) { return match ($type) {
'odometer' => 'event-odometer', 'odometer' => 'event-odometer',
'oil_change' => 'event-oil', 'oil_change' => 'event-oil',
'front_tyre_change', 'rear_tyre_change' => 'event-tyre', 'front_tyre_change', 'rear_tyre_change', 'both_tires_change' => 'event-tyre',
'shaft_oil_change' => 'event-shaft', 'shaft_oil_change' => 'event-shaft',
'brake_pads' => 'event-brakes', 'brake_pads' => 'event-brakes',
'registration' => 'event-registration', 'registration' => 'event-registration',