Harden per-branch billing with seat caps and mid-cycle expansion.
Deploy Ladill Frontdesk / deploy (push) Successful in 55s
Deploy Ladill Frontdesk / deploy (push) Successful in 55s
Enforce billed_branches when adding or reactivating branches, charge wallet for extra seats mid-cycle, fix Settings for Enterprise, and cover multi-branch checkout and renewal amounts in tests.
This commit is contained in:
@@ -65,11 +65,53 @@ class PlanService
|
||||
->count();
|
||||
}
|
||||
|
||||
/** Seat allotment purchased for the current paid period; 0 when free or unset. */
|
||||
public function billedBranches(Organization $organization): int
|
||||
{
|
||||
return max(0, (int) (($organization->settings ?? [])['billed_branches'] ?? 0));
|
||||
}
|
||||
|
||||
public function canAddBranch(Organization $organization, int $currentCount): bool
|
||||
{
|
||||
$limit = config('frontdesk.plans.'.$this->planKey($organization).'.max_branches');
|
||||
if ($limit !== null) {
|
||||
return $currentCount < (int) $limit;
|
||||
}
|
||||
|
||||
return $limit === null || $currentCount < (int) $limit;
|
||||
// Paid plans with a purchased seat allotment cannot exceed it until they expand.
|
||||
$billed = $this->billedBranches($organization);
|
||||
if ($this->hasPaidPlan($organization) && $billed > 0) {
|
||||
return $this->activeBranchCount($organization) < $billed;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canActivateBranch(Organization $organization): bool
|
||||
{
|
||||
$limit = config('frontdesk.plans.'.$this->planKey($organization).'.max_branches');
|
||||
if ($limit !== null) {
|
||||
return $this->activeBranchCount($organization) < (int) $limit;
|
||||
}
|
||||
|
||||
$billed = $this->billedBranches($organization);
|
||||
if ($this->hasPaidPlan($organization) && $billed > 0) {
|
||||
return $this->activeBranchCount($organization) < $billed;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function branchLimitMessage(Organization $organization): string
|
||||
{
|
||||
if ($this->hasPaidPlan($organization) && $this->billedBranches($organization) > 0) {
|
||||
$n = $this->billedBranches($organization);
|
||||
|
||||
return "Your plan is billed for {$n} active ".str('branch')->plural($n)
|
||||
.'. Increase your branch allotment on the Plans page before adding more.';
|
||||
}
|
||||
|
||||
return 'Your plan allows one branch. Upgrade to Frontdesk Pro for more branches.';
|
||||
}
|
||||
|
||||
public function canAddKiosk(Organization $organization): bool
|
||||
|
||||
Reference in New Issue
Block a user