feat: complete jobcard management workflows and UI
This commit is contained in:
@@ -26,6 +26,7 @@ final class TimeEntryCorrectionCommand
|
||||
if (array_key_exists($field, $changes) && $this->positiveId($changes[$field]) !== $this->positiveId($existing[$field] ?? null)) $errors[$field] = "{$field} cannot be changed during correction.";
|
||||
}
|
||||
$allowed = ['work_date', 'start_time', 'end_time', 'hours', 'notes', 'counts_toward_sla'];
|
||||
foreach (array_keys($changes) as $field) if (!in_array($field, $allowed, true) && !in_array($field, ['jobcard_id', 'technician_id'], true)) $errors[$field] = "{$field} cannot be changed during correction.";
|
||||
$payload = $existing;
|
||||
foreach ($allowed as $field) if (array_key_exists($field, $changes)) $payload[$field] = $changes[$field];
|
||||
$validated = ($this->entries ?? new TimeEntryCommand())->validate($payload);
|
||||
@@ -33,7 +34,8 @@ final class TimeEntryCorrectionCommand
|
||||
$entry = [...$payload, ...$validated];
|
||||
unset($entry['valid'], $entry['errors']);
|
||||
$entry['id'] = $id;
|
||||
return ['valid' => $errors === [], 'action' => 'correct', 'id' => $id, 'entry' => $entry, 'errors' => $errors];
|
||||
$changed = []; foreach ($allowed as $field) if (array_key_exists($field, $changes) && ($existing[$field] ?? null) !== ($entry[$field] ?? null)) $changed[] = $field;
|
||||
return ['valid' => $errors === [], 'action' => 'correct', 'id' => $id, 'entry' => $entry, 'errors' => $errors, 'audit' => ['event' => 'time_entry_corrected', 'entity_type' => 'time_entry', 'entity_id' => $id, 'changed_fields' => $changed, 'before' => $existing, 'after' => $entry]];
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
@@ -57,7 +59,7 @@ final class TimeEntryCorrectionCommand
|
||||
$reason = is_scalar($input['reason'] ?? null) ? trim((string)$input['reason']) : '';
|
||||
if ($reason === '') $errors['reason'] = 'A void reason is required.';
|
||||
elseif (mb_strlen($reason) > 1000) $errors['reason'] = 'Void reason must be 1000 characters or fewer.';
|
||||
return ['valid' => $errors === [], 'action' => 'void', 'id' => $id, 'void_reason' => $reason === '' ? null : $reason, 'entry' => $existing, 'errors' => $errors];
|
||||
return ['valid' => $errors === [], 'action' => 'void', 'id' => $id, 'void_reason' => $reason === '' ? null : $reason, 'entry' => $existing, 'errors' => $errors, 'audit' => $errors === [] ? ['event' => 'time_entry_voided', 'entity_type' => 'time_entry', 'entity_id' => $id, 'void_reason' => $reason] : null];
|
||||
}
|
||||
|
||||
public function void(array $existing, array $input = []): array
|
||||
|
||||
Reference in New Issue
Block a user