Phase 4 work order profile depth
This commit is contained in:
@@ -10,7 +10,9 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
#[Fillable([
|
||||
'job_post_id', 'buyer_id', 'provider_id', 'accepted_quote_id', 'status',
|
||||
'status_history', 'agreed_terms', 'deliverables_checklist', 'completion_notes',
|
||||
'status_history', 'agreed_terms', 'deliverables_checklist', 'scheduled_at',
|
||||
'appointment_window', 'checklist_items', 'checklist_completed', 'required_evidence',
|
||||
'evidence_rules', 'change_requests', 'completion_notes',
|
||||
'en_route_at', 'on_site_at', 'started_at', 'completed_at', 'approved_at', 'closed_at',
|
||||
])]
|
||||
class WorkOrder extends Model
|
||||
@@ -36,6 +38,11 @@ class WorkOrder extends Model
|
||||
{
|
||||
return [
|
||||
'status_history' => 'array',
|
||||
'scheduled_at' => 'datetime',
|
||||
'checklist_items' => 'array',
|
||||
'checklist_completed' => 'array',
|
||||
'evidence_rules' => 'array',
|
||||
'change_requests' => 'array',
|
||||
'en_route_at' => 'datetime',
|
||||
'on_site_at' => 'datetime',
|
||||
'started_at' => 'datetime',
|
||||
@@ -94,4 +101,39 @@ class WorkOrder extends Model
|
||||
{
|
||||
return in_array($status, self::ALLOWED_TRANSITIONS[$this->status] ?? [], true);
|
||||
}
|
||||
|
||||
public function checklistItems(): array
|
||||
{
|
||||
if (is_array($this->checklist_items) && $this->checklist_items !== []) {
|
||||
return array_values(array_filter($this->checklist_items));
|
||||
}
|
||||
|
||||
return collect(preg_split('/\r\n|\r|\n/', (string) $this->deliverables_checklist))
|
||||
->map(fn (string $item): string => trim($item, " \t\n\r\0\x0B-[]"))
|
||||
->filter()
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
public function checklistCompleted(): array
|
||||
{
|
||||
return is_array($this->checklist_completed) ? $this->checklist_completed : [];
|
||||
}
|
||||
|
||||
public function checklistProgress(): array
|
||||
{
|
||||
$items = $this->checklistItems();
|
||||
$completed = $this->checklistCompleted();
|
||||
$done = collect($items)->filter(fn (string $item): bool => (bool) ($completed[$item] ?? false))->count();
|
||||
|
||||
return [
|
||||
'done' => $done,
|
||||
'total' => count($items),
|
||||
];
|
||||
}
|
||||
|
||||
public function changeRequests(): array
|
||||
{
|
||||
return is_array($this->change_requests) ? array_values($this->change_requests) : [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user