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;
@ -47,9 +46,9 @@ public function __invoke(SmsService $sms): Response
return Account::whereHas('contract', function ($q) { return Account::whereHas('contract', function ($q) {
$q->whereNull('deleted_at'); $q->whereNull('deleted_at');
}) })
->whereNotNull('promise_date') ->whereNotNull('promise_date')
->whereDate('promise_date', '>=', $today) ->whereDate('promise_date', '>=', $today)
->count(); ->count();
}); });
// Activities (limit 10) - cached // Activities (limit 10) - cached
@ -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,31 +73,27 @@ 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" <a :href="safeCaseHref(f.contract.client_case_uuid, f.contract.segment_id)">
variant="outline" <ItemMedia>
size="sm" <span class="w-2 h-2 mt-2 rounded-full bg-primary" />
as-child </ItemMedia>
> <ItemContent>
<a :href="safeCaseHref(f.contract.client_case_uuid, f.contract.segment_id)"> <ItemTitle>
<ItemMedia> <span>{{ f.contract.person_full_name }}</span>
<span class="w-2 h-2 mt-2 rounded-full bg-primary" /> </ItemTitle>
</ItemMedia> <ItemDescription class="flex gap-1">
<ItemContent> <Badge>{{ f.contract.reference }}</Badge>
<ItemTitle> <Badge variant="outline">{{ formatJobTime(f.created_at) }}</Badge>
<span>{{ f.contract.person_full_name }}</span> </ItemDescription>
</ItemTitle> </ItemContent>
<ItemDescription class="flex gap-1"> <ItemActions>
<Badge>{{ f.contract.reference }}</Badge> <ChevronRightIcon class="size-4" />
<Badge variant="outline">{{ formatJobTime(f.created_at) }}</Badge> </ItemActions>
</ItemDescription> </a>
</ItemContent> </Item>
<ItemActions> </template>
<ChevronRightIcon class="size-4" />
</ItemActions>
</a>
</Item>
</div> </div>
</ScrollArea> </ScrollArea>
<div <div