Initial Ladill Queue release — enterprise QMS standalone app.
Deploy Ladill Queue / deploy (push) Successful in 56s
Deploy Ladill Queue / deploy (push) Successful in 56s
Phases 1–6: tickets, counters, displays, appointments, workflows, rules, analytics, reports, feedback, admin, device API, and Gitea deploy workflow for queue.ladill.com. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
<?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();
|
||||
|
||||
return view('qms.workflows.index', compact('workflows', 'organization'));
|
||||
}
|
||||
|
||||
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.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user