Deploy Ladill Frontdesk / deploy (push) Successful in 44s
Host alerts use email/phone on the host record without requiring a Ladill account link; SMS and over-quota emails debit the org wallet at platform rates. Co-authored-by: Cursor <cursoragent@cursor.com>
95 lines
3.2 KiB
PHP
95 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Frontdesk;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Frontdesk\Concerns\ScopesToAccount;
|
|
use App\Models\Branch;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
class BranchController extends Controller
|
|
{
|
|
use ScopesToAccount;
|
|
|
|
public function index(Request $request): View
|
|
{
|
|
$this->authorizeAbility($request, 'admin.branches.view');
|
|
$organization = $this->organization($request);
|
|
|
|
$branches = Branch::owned($this->ownerRef($request))
|
|
->where('organization_id', $organization->id)
|
|
->withCount(['buildings'])
|
|
->orderBy('name')
|
|
->get();
|
|
|
|
return view('frontdesk.admin.branches.index', compact('branches', 'organization'));
|
|
}
|
|
|
|
public function create(Request $request): View
|
|
{
|
|
$this->authorizeAbility($request, 'admin.branches.manage');
|
|
return view('frontdesk.admin.branches.create', ['organization' => $this->organization($request)]);
|
|
}
|
|
|
|
public function store(Request $request): RedirectResponse
|
|
{
|
|
$this->authorizeAbility($request, 'admin.branches.manage');
|
|
$organization = $this->organization($request);
|
|
|
|
$currentCount = Branch::owned($this->ownerRef($request))
|
|
->where('organization_id', $organization->id)
|
|
->count();
|
|
|
|
if (! app(\App\Services\Frontdesk\PlanService::class)->canAddBranch($organization, $currentCount)) {
|
|
return back()->withInput()->with('error', 'Your plan allows one branch. Upgrade to Frontdesk Pro for unlimited branches.');
|
|
}
|
|
|
|
$validated = $request->validate([
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'code' => ['nullable', 'string', 'max:50'],
|
|
'address' => ['nullable', 'string', 'max:500'],
|
|
'phone' => ['nullable', 'string', 'max:50'],
|
|
]);
|
|
|
|
Branch::create([
|
|
'owner_ref' => $this->ownerRef($request),
|
|
'organization_id' => $organization->id,
|
|
...$validated,
|
|
'is_active' => true,
|
|
]);
|
|
|
|
return redirect()->route('frontdesk.branches.index')->with('success', 'Branch created.');
|
|
}
|
|
|
|
public function edit(Request $request, Branch $branch): View
|
|
{
|
|
$this->authorizeAbility($request, 'admin.branches.manage');
|
|
$this->authorizeOwner($request, $branch);
|
|
|
|
return view('frontdesk.admin.branches.edit', compact('branch'));
|
|
}
|
|
|
|
public function update(Request $request, Branch $branch): RedirectResponse
|
|
{
|
|
$this->authorizeAbility($request, 'admin.branches.manage');
|
|
$this->authorizeOwner($request, $branch);
|
|
|
|
$validated = $request->validate([
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'code' => ['nullable', 'string', 'max:50'],
|
|
'address' => ['nullable', 'string', 'max:500'],
|
|
'phone' => ['nullable', 'string', 'max:50'],
|
|
'is_active' => ['boolean'],
|
|
]);
|
|
|
|
$branch->update([
|
|
...$validated,
|
|
'is_active' => $request->boolean('is_active'),
|
|
]);
|
|
|
|
return redirect()->route('frontdesk.branches.index')->with('success', 'Branch updated.');
|
|
}
|
|
}
|