diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index cf7c2eb..7efbbc5 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -14,7 +14,6 @@ use App\Services\Sms\SmsService; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Schema; use Inertia\Inertia; use Inertia\Response; @@ -47,9 +46,9 @@ public function __invoke(SmsService $sms): Response return Account::whereHas('contract', function ($q) { $q->whereNull('deleted_at'); }) - ->whereNotNull('promise_date') - ->whereDate('promise_date', '>=', $today) - ->count(); + ->whereNotNull('promise_date') + ->whereDate('promise_date', '>=', $today) + ->count(); }); // Activities (limit 10) - cached @@ -120,20 +119,26 @@ public function __invoke(SmsService $sms): Response } } + if (! $contract) { + return null; + } + return [ 'id' => $fj->id, 'priority' => $fj->priority, 'assigned_at' => $fj->assigned_at?->toIso8601String(), 'created_at' => $fj->created_at?->toIso8601String(), - 'contract' => $contract ? [ + 'contract' => [ 'uuid' => $contract->uuid, 'reference' => $contract->reference, 'client_case_uuid' => optional($contract->clientCase)->uuid, 'person_full_name' => optional(optional($contract->clientCase)->person)->full_name, 'segment_id' => $segmentId, - ] : null, + ], ]; - }); + }) + ->filter() + ->values(); }); // System health for timestamp diff --git a/app/Services/DecisionEvents/Handlers/ArchiveContractHandler.php b/app/Services/DecisionEvents/Handlers/ArchiveContractHandler.php index 0d05e0c..241db69 100644 --- a/app/Services/DecisionEvents/Handlers/ArchiveContractHandler.php +++ b/app/Services/DecisionEvents/Handlers/ArchiveContractHandler.php @@ -36,6 +36,14 @@ public function handle(DecisionEventContext $context, array $config = []): void $setting->reactivate = (bool) $config['reactivate']; } + // Cancel all active FieldJobs for this contract before archiving (raw update to avoid boot-event side effects) + \DB::table('field_jobs') + ->where('contract_id', $contractId) + ->whereNull('completed_at') + ->whereNull('cancelled_at') + ->whereNull('deleted_at') + ->update(['cancelled_at' => now(), 'updated_at' => now()]); + $results = app(ArchiveExecutor::class)->executeSetting( $setting, ['contract_id' => $contractId], diff --git a/resources/js/Pages/Dashboard/Partials/FieldJobsAssignedToday.vue b/resources/js/Pages/Dashboard/Partials/FieldJobsAssignedToday.vue index a03e765..53985c2 100644 --- a/resources/js/Pages/Dashboard/Partials/FieldJobsAssignedToday.vue +++ b/resources/js/Pages/Dashboard/Partials/FieldJobsAssignedToday.vue @@ -73,31 +73,27 @@ function safeCaseHref(uuid, segment = null) { v-if="fieldJobsAssignedToday && fieldJobsAssignedToday.length > 0" >