Fixed when contract is archived all active field jobs for contract are cancaled

This commit is contained in:
Simon Pocrnjič 2026-04-16 21:52:17 +02:00
parent 7881508a7b
commit 187cb4f127
3 changed files with 41 additions and 32 deletions

View File

@ -14,7 +14,6 @@
use App\Services\Sms\SmsService; use App\Services\Sms\SmsService;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Inertia\Inertia; use Inertia\Inertia;
use Inertia\Response; use Inertia\Response;
@ -120,20 +119,26 @@ public function __invoke(SmsService $sms): Response
} }
} }
if (! $contract) {
return null;
}
return [ return [
'id' => $fj->id, 'id' => $fj->id,
'priority' => $fj->priority, 'priority' => $fj->priority,
'assigned_at' => $fj->assigned_at?->toIso8601String(), 'assigned_at' => $fj->assigned_at?->toIso8601String(),
'created_at' => $fj->created_at?->toIso8601String(), 'created_at' => $fj->created_at?->toIso8601String(),
'contract' => $contract ? [ 'contract' => [
'uuid' => $contract->uuid, 'uuid' => $contract->uuid,
'reference' => $contract->reference, 'reference' => $contract->reference,
'client_case_uuid' => optional($contract->clientCase)->uuid, 'client_case_uuid' => optional($contract->clientCase)->uuid,
'person_full_name' => optional(optional($contract->clientCase)->person)->full_name, 'person_full_name' => optional(optional($contract->clientCase)->person)->full_name,
'segment_id' => $segmentId, 'segment_id' => $segmentId,
] : null, ],
]; ];
}); })
->filter()
->values();
}); });
// System health for timestamp // System health for timestamp

View File

@ -36,6 +36,14 @@ public function handle(DecisionEventContext $context, array $config = []): void
$setting->reactivate = (bool) $config['reactivate']; $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( $results = app(ArchiveExecutor::class)->executeSetting(
$setting, $setting,
['contract_id' => $contractId], ['contract_id' => $contractId],

View File

@ -73,13 +73,8 @@ function safeCaseHref(uuid, segment = null) {
v-if="fieldJobsAssignedToday && fieldJobsAssignedToday.length > 0" v-if="fieldJobsAssignedToday && fieldJobsAssignedToday.length > 0"
> >
<div class="flex flex-col gap-1 px-1"> <div class="flex flex-col gap-1 px-1">
<Item <template v-for="f in fieldJobsAssignedToday" :key="f.id">
v-for="f in fieldJobsAssignedToday" <Item v-if="f.contract" variant="outline" size="sm" as-child>
:key="f.id"
variant="outline"
size="sm"
as-child
>
<a :href="safeCaseHref(f.contract.client_case_uuid, f.contract.segment_id)"> <a :href="safeCaseHref(f.contract.client_case_uuid, f.contract.segment_id)">
<ItemMedia> <ItemMedia>
<span class="w-2 h-2 mt-2 rounded-full bg-primary" /> <span class="w-2 h-2 mt-2 rounded-full bg-primary" />
@ -98,6 +93,7 @@ function safeCaseHref(uuid, segment = null) {
</ItemActions> </ItemActions>
</a> </a>
</Item> </Item>
</template>
</div> </div>
</ScrollArea> </ScrollArea>
<div <div