Fix reseller package selection when older batches are exhausted
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-02-06 12:01:43 +01:00
parent 61d1bbc707
commit fa114ac0dc
5 changed files with 45 additions and 7 deletions

View File

@@ -233,10 +233,18 @@ class Tenant extends Model
public function getActiveResellerPackage(): ?TenantPackage
{
return $this->activeResellerPackage()->with('package')->first();
return $this->getActiveResellerPackageFor(null);
}
public function getActiveResellerPackageFor(?string $includedPackageSlug): ?TenantPackage
{
$candidates = $this->activeResellerPackagesQuery($includedPackageSlug)->get();
return $candidates->first(fn (TenantPackage $package) => $package->canCreateEvent())
?? $candidates->first();
}
private function activeResellerPackagesQuery(?string $includedPackageSlug): HasMany
{
$query = $this->tenantPackages()
->with('package')
@@ -258,7 +266,7 @@ class Tenant extends Model
});
}
return $query->first();
return $query;
}
public function activeSubscription(): Attribute