Deploy Ladill Queue / deploy (push) Successful in 36s
Introduce shared x-qms.page-hero with summary stats across queues, tickets, counters, admin pages, and insights; remove bordered cards on Analytics, Reports, Feedback, and Branches list views. Co-authored-by: Cursor <cursoragent@cursor.com>
169 lines
6.4 KiB
PHP
169 lines
6.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Qms;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Qms\Concerns\ScopesToAccount;
|
|
use App\Models\Branch;
|
|
use App\Models\ServiceQueue;
|
|
use App\Models\Workflow;
|
|
use App\Models\WorkflowStep;
|
|
use App\Services\Qms\AuditLogger;
|
|
use App\Services\Qms\WorkflowService;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
class WorkflowController extends Controller
|
|
{
|
|
use ScopesToAccount;
|
|
|
|
public function __construct(
|
|
protected WorkflowService $workflows,
|
|
) {}
|
|
|
|
public function index(Request $request): View
|
|
{
|
|
$this->authorizeAbility($request, 'workflows.view');
|
|
$owner = $this->ownerRef($request);
|
|
$organization = $this->organization($request);
|
|
|
|
$workflows = Workflow::owned($owner)
|
|
->where('organization_id', $organization->id)
|
|
->withCount('steps')
|
|
->orderBy('name')
|
|
->get();
|
|
|
|
$heroStats = [
|
|
'total' => $workflows->count(),
|
|
'active' => $workflows->where('is_active', true)->count(),
|
|
'steps' => $workflows->sum('steps_count'),
|
|
];
|
|
|
|
return view('qms.workflows.index', compact('workflows', 'organization', 'heroStats'));
|
|
}
|
|
|
|
public function create(Request $request): View
|
|
{
|
|
$this->authorizeAbility($request, 'workflows.manage');
|
|
$owner = $this->ownerRef($request);
|
|
$organization = $this->organization($request);
|
|
|
|
return view('qms.workflows.create', [
|
|
'organization' => $organization,
|
|
'branches' => Branch::owned($owner)->where('organization_id', $organization->id)->orderBy('name')->get(),
|
|
'queues' => ServiceQueue::owned($owner)->where('organization_id', $organization->id)->orderBy('name')->get(),
|
|
'templates' => config('qms.industry_templates'),
|
|
'workflowTemplates' => config('qms.workflow_templates'),
|
|
]);
|
|
}
|
|
|
|
public function store(Request $request): RedirectResponse
|
|
{
|
|
$this->authorizeAbility($request, 'workflows.manage');
|
|
$owner = $this->ownerRef($request);
|
|
$organization = $this->organization($request);
|
|
|
|
$validated = $request->validate([
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'description' => ['nullable', 'string'],
|
|
'branch_id' => ['nullable', 'exists:queue_branches,id'],
|
|
'industry_template' => ['nullable', 'string'],
|
|
'steps' => ['required', 'array', 'min:1'],
|
|
'steps.*.name' => ['required', 'string', 'max:255'],
|
|
'steps.*.service_queue_id' => ['nullable', 'exists:queue_service_queues,id'],
|
|
]);
|
|
|
|
$workflow = Workflow::create([
|
|
'owner_ref' => $owner,
|
|
'organization_id' => $organization->id,
|
|
'name' => $validated['name'],
|
|
'description' => $validated['description'] ?? null,
|
|
'branch_id' => $validated['branch_id'] ?? null,
|
|
'industry_template' => $validated['industry_template'] ?? null,
|
|
'is_active' => true,
|
|
]);
|
|
|
|
foreach ($validated['steps'] as $i => $step) {
|
|
WorkflowStep::create([
|
|
'workflow_id' => $workflow->id,
|
|
'name' => $step['name'],
|
|
'service_queue_id' => $step['service_queue_id'] ?? null,
|
|
'sort_order' => $i + 1,
|
|
]);
|
|
}
|
|
|
|
AuditLogger::record($owner, 'workflow.created', $organization->id, $owner, Workflow::class, $workflow->id);
|
|
|
|
return redirect()->route('qms.workflows.index')->with('success', 'Workflow created.');
|
|
}
|
|
|
|
public function show(Request $request, Workflow $workflow): View
|
|
{
|
|
$this->authorizeAbility($request, 'workflows.view');
|
|
$this->authorizeOwner($request, $workflow);
|
|
$workflow->load(['steps.serviceQueue', 'branch']);
|
|
|
|
return view('qms.workflows.show', compact('workflow'));
|
|
}
|
|
|
|
public function edit(Request $request, Workflow $workflow): View
|
|
{
|
|
$this->authorizeAbility($request, 'workflows.manage');
|
|
$this->authorizeOwner($request, $workflow);
|
|
$owner = $this->ownerRef($request);
|
|
|
|
return view('qms.workflows.edit', [
|
|
'workflow' => $workflow->load('steps'),
|
|
'branches' => Branch::owned($owner)->where('organization_id', $workflow->organization_id)->orderBy('name')->get(),
|
|
'queues' => ServiceQueue::owned($owner)->where('organization_id', $workflow->organization_id)->orderBy('name')->get(),
|
|
]);
|
|
}
|
|
|
|
public function update(Request $request, Workflow $workflow): RedirectResponse
|
|
{
|
|
$this->authorizeAbility($request, 'workflows.manage');
|
|
$this->authorizeOwner($request, $workflow);
|
|
|
|
$validated = $request->validate([
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'description' => ['nullable', 'string'],
|
|
'branch_id' => ['nullable', 'exists:queue_branches,id'],
|
|
'is_active' => ['boolean'],
|
|
'steps' => ['required', 'array', 'min:1'],
|
|
'steps.*.name' => ['required', 'string', 'max:255'],
|
|
'steps.*.service_queue_id' => ['nullable', 'exists:queue_service_queues,id'],
|
|
]);
|
|
|
|
$workflow->update([
|
|
'name' => $validated['name'],
|
|
'description' => $validated['description'] ?? null,
|
|
'branch_id' => $validated['branch_id'] ?? null,
|
|
'is_active' => $request->boolean('is_active', $workflow->is_active),
|
|
]);
|
|
|
|
$workflow->steps()->delete();
|
|
foreach ($validated['steps'] as $i => $step) {
|
|
WorkflowStep::create([
|
|
'workflow_id' => $workflow->id,
|
|
'name' => $step['name'],
|
|
'service_queue_id' => $step['service_queue_id'] ?? null,
|
|
'sort_order' => $i + 1,
|
|
]);
|
|
}
|
|
|
|
AuditLogger::record($this->ownerRef($request), 'workflow.updated', $workflow->organization_id, $this->ownerRef($request), Workflow::class, $workflow->id);
|
|
|
|
return redirect()->route('qms.workflows.show', $workflow)->with('success', 'Workflow updated.');
|
|
}
|
|
|
|
public function destroy(Request $request, Workflow $workflow): RedirectResponse
|
|
{
|
|
$this->authorizeAbility($request, 'workflows.manage');
|
|
$this->authorizeOwner($request, $workflow);
|
|
$workflow->delete();
|
|
|
|
return redirect()->route('qms.workflows.index')->with('success', 'Workflow removed.');
|
|
}
|
|
}
|