Gate Care branch management behind Pro like Frontdesk.
Deploy Ladill Care / deploy (push) Successful in 1m25s
Deploy Ladill Care / deploy (push) Successful in 1m25s
Free plans keep a single setup branch but get an upgrade screen for Branches; Pro/Enterprise unlock multi-branch management via plan features.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Care;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Care\Concerns\RequiresPlanFeature;
|
||||
use App\Http\Controllers\Care\Concerns\ScopesToAccount;
|
||||
use App\Models\Branch;
|
||||
use App\Services\Care\AuditLogger;
|
||||
@@ -13,11 +14,26 @@ use Illuminate\View\View;
|
||||
|
||||
class BranchController extends Controller
|
||||
{
|
||||
use RequiresPlanFeature;
|
||||
use ScopesToAccount;
|
||||
|
||||
private const FEATURE = 'branches';
|
||||
|
||||
private const UPGRADE_MESSAGE = 'Multi-branch management requires Care Pro.';
|
||||
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$this->authorizeAbility($request, 'admin.branches.view');
|
||||
|
||||
if ($upgrade = $this->proFeatureUpgradeView(
|
||||
$request,
|
||||
self::FEATURE,
|
||||
'Branches',
|
||||
'Manage clinic locations and sites with Care Pro. Free plans include one branch created during setup.',
|
||||
)) {
|
||||
return $upgrade;
|
||||
}
|
||||
|
||||
$organization = $this->organization($request);
|
||||
|
||||
$branches = Branch::owned($this->ownerRef($request))
|
||||
@@ -39,12 +55,26 @@ class BranchController extends Controller
|
||||
{
|
||||
$this->authorizeAbility($request, 'admin.branches.manage');
|
||||
|
||||
if ($upgrade = $this->proFeatureUpgradeView(
|
||||
$request,
|
||||
self::FEATURE,
|
||||
'Branches',
|
||||
'Add and manage multiple clinic locations with Care Pro.',
|
||||
)) {
|
||||
return $upgrade;
|
||||
}
|
||||
|
||||
return view('care.admin.branches.create', ['organization' => $this->organization($request)]);
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$this->authorizeAbility($request, 'admin.branches.manage');
|
||||
|
||||
if ($deny = $this->denyWithoutFeature($request, self::FEATURE, self::UPGRADE_MESSAGE)) {
|
||||
return $deny;
|
||||
}
|
||||
|
||||
$organization = $this->organization($request);
|
||||
$owner = $this->ownerRef($request);
|
||||
|
||||
@@ -83,6 +113,15 @@ class BranchController extends Controller
|
||||
$this->authorizeAbility($request, 'admin.branches.manage');
|
||||
$this->authorizeOwner($request, $branch);
|
||||
|
||||
if ($upgrade = $this->proFeatureUpgradeView(
|
||||
$request,
|
||||
self::FEATURE,
|
||||
'Branches',
|
||||
'Edit clinic locations with Care Pro. Free plans include one branch created during setup.',
|
||||
)) {
|
||||
return $upgrade;
|
||||
}
|
||||
|
||||
return view('care.admin.branches.edit', compact('branch'));
|
||||
}
|
||||
|
||||
@@ -91,6 +130,10 @@ class BranchController extends Controller
|
||||
$this->authorizeAbility($request, 'admin.branches.manage');
|
||||
$this->authorizeOwner($request, $branch);
|
||||
|
||||
if ($deny = $this->denyWithoutFeature($request, self::FEATURE, self::UPGRADE_MESSAGE)) {
|
||||
return $deny;
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'code' => ['nullable', 'string', 'max:50'],
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Care\Concerns;
|
||||
|
||||
use App\Services\Care\PlanService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
trait RequiresPlanFeature
|
||||
{
|
||||
/**
|
||||
* For page views: return an upgrade screen when the org lacks the feature.
|
||||
*/
|
||||
protected function proFeatureUpgradeView(
|
||||
Request $request,
|
||||
string $feature,
|
||||
string $title,
|
||||
string $description,
|
||||
): ?View {
|
||||
$organization = $this->organization($request);
|
||||
$plans = app(PlanService::class);
|
||||
|
||||
if ($plans->hasFeature($organization, $feature)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return view('care.settings.pro-feature', [
|
||||
'organization' => $organization,
|
||||
'title' => $title,
|
||||
'description' => $description,
|
||||
'proPriceMinor' => $plans->proPricePerBranchMinor(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* For mutations: redirect free-plan orgs to the plans page.
|
||||
*/
|
||||
protected function denyWithoutFeature(
|
||||
Request $request,
|
||||
string $feature,
|
||||
string $message,
|
||||
): ?RedirectResponse {
|
||||
$organization = $this->organization($request);
|
||||
if (app(PlanService::class)->hasFeature($organization, $feature)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->route('care.pro.index')
|
||||
->with('upsell', $message);
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,6 @@ class SettingsController extends Controller
|
||||
->count();
|
||||
|
||||
$plans = app(PlanService::class);
|
||||
$hasPaidPlan = $plans->hasPaidPlan($organization);
|
||||
|
||||
return view('care.settings.edit', [
|
||||
'organization' => $organization,
|
||||
@@ -42,7 +41,7 @@ class SettingsController extends Controller
|
||||
'branchCount' => $branchCount,
|
||||
'canViewBranches' => $permissions->can($member, 'admin.branches.view'),
|
||||
'canViewTeam' => $permissions->can($member, 'admin.members.view'),
|
||||
'hasPaidPlan' => $hasPaidPlan,
|
||||
'hasBranchesFeature' => $plans->hasFeature($organization, 'branches'),
|
||||
'canUseQueueIntegration' => $plans->canUseQueueIntegration($organization),
|
||||
'messagingSmsReady' => $credential->hasValidSms(),
|
||||
'messagingEmailReady' => $credential->hasValidBird(),
|
||||
|
||||
Reference in New Issue
Block a user