Add more permissions
This commit is contained in:
@@ -1778,7 +1778,31 @@ public function sendSmsToPhone(ClientCase $clientCase, Request $request, int $ph
|
||||
return back()->with('error', 'Unable to verify SMS credits.');
|
||||
}
|
||||
|
||||
// Queue the SMS send; activity will be created in the job on success if a template is provided
|
||||
// Create an activity before sending
|
||||
$activityNote = sprintf('Št: %s | Telo: %s', (string) $phone->nu, (string) $validated['message']);
|
||||
$activityData = [
|
||||
'note' => $activityNote,
|
||||
'user_id' => optional($request->user())->id,
|
||||
];
|
||||
// If template provided, attach its action/decision to the activity
|
||||
if (! empty($validated['template_id'])) {
|
||||
$tpl = \App\Models\SmsTemplate::find((int) $validated['template_id']);
|
||||
if ($tpl) {
|
||||
$activityData['action_id'] = $tpl->action_id;
|
||||
$activityData['decision_id'] = $tpl->decision_id;
|
||||
}
|
||||
}
|
||||
// Attach contract_id if contract_uuid is provided and belongs to this case
|
||||
if (! empty($validated['contract_uuid'])) {
|
||||
$contract = $clientCase->contracts()->where('uuid', $validated['contract_uuid'])->first();
|
||||
if ($contract) {
|
||||
$activityData['contract_id'] = $contract->id;
|
||||
}
|
||||
}
|
||||
|
||||
$activity = $clientCase->activities()->create($activityData);
|
||||
|
||||
// Queue the SMS send; pass activity_id so the job can update note on failure and skip creating a new activity
|
||||
\App\Jobs\SendSmsJob::dispatch(
|
||||
profileId: $profile->id,
|
||||
to: (string) $phone->nu,
|
||||
@@ -1790,6 +1814,7 @@ public function sendSmsToPhone(ClientCase $clientCase, Request $request, int $ph
|
||||
templateId: $validated['template_id'] ?? null,
|
||||
clientCaseId: $clientCase->id,
|
||||
userId: optional($request->user())->id,
|
||||
activityId: $activity?->id,
|
||||
);
|
||||
|
||||
return back()->with('success', 'SMS je bil dodan v čakalno vrsto.');
|
||||
|
||||
Reference in New Issue
Block a user