Fixed when contract is archived all active field jobs for contract are cancaled
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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],
|
||||
|
||||
Reference in New Issue
Block a user