Reception create form omitted service point; catch that as validation and require a desk/room when the queue uses assigned routing. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Qms;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Qms\Concerns\ScopesToAccount;
|
||||
use App\Models\Counter;
|
||||
use App\Models\ServiceQueue;
|
||||
use App\Models\Ticket;
|
||||
use App\Services\Qms\QueueEngine;
|
||||
@@ -57,6 +58,10 @@ class TicketController extends Controller
|
||||
$queues = ServiceQueue::owned($owner)
|
||||
->where('organization_id', $organization->id)
|
||||
->where('is_active', true)
|
||||
->with([
|
||||
'branch',
|
||||
'counters' => fn ($q) => $q->where('is_active', true)->orderBy('name'),
|
||||
])
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
@@ -70,6 +75,7 @@ class TicketController extends Controller
|
||||
|
||||
$validated = $request->validate([
|
||||
'service_queue_id' => ['required', 'exists:queue_service_queues,id'],
|
||||
'assigned_counter_id' => ['nullable', 'exists:queue_counters,id'],
|
||||
'customer_name' => ['nullable', 'string', 'max:255'],
|
||||
'customer_phone' => ['nullable', 'string', 'max:50'],
|
||||
'priority' => ['nullable', 'string', 'in:'.implode(',', array_keys(config('qms.ticket_priorities')))],
|
||||
@@ -78,11 +84,31 @@ class TicketController extends Controller
|
||||
$queue = ServiceQueue::findOrFail($validated['service_queue_id']);
|
||||
$this->authorizeOwner($request, $queue);
|
||||
|
||||
$ticket = $this->engine->issueTicket($queue, $owner, [
|
||||
...$validated,
|
||||
'source' => 'reception',
|
||||
'actor_ref' => $owner,
|
||||
]);
|
||||
if ($queue->usesAssignedOnlyRouting() && empty($validated['assigned_counter_id'])) {
|
||||
return back()
|
||||
->withInput()
|
||||
->withErrors(['assigned_counter_id' => 'Select a service point for this queue.']);
|
||||
}
|
||||
|
||||
if (! empty($validated['assigned_counter_id'])) {
|
||||
$counter = Counter::query()->findOrFail($validated['assigned_counter_id']);
|
||||
$this->authorizeOwner($request, $counter);
|
||||
if (! $queue->counters()->where('queue_counters.id', $counter->id)->exists()) {
|
||||
return back()
|
||||
->withInput()
|
||||
->withErrors(['assigned_counter_id' => 'That service point is not linked to this queue.']);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$ticket = $this->engine->issueTicket($queue, $owner, [
|
||||
...$validated,
|
||||
'source' => 'reception',
|
||||
'actor_ref' => $owner,
|
||||
]);
|
||||
} catch (\RuntimeException $e) {
|
||||
return back()->withInput()->withErrors(['service_queue_id' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
return redirect()->route('qms.tickets.show', $ticket)->with('success', 'Ticket issued.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user