Deploy Ladill POS / deploy (push) Successful in 1m58s
Pro and Business users can manage branches, invite cashiers with branch assignment, and switch registers; sales and register flows respect acting location. Co-authored-by: Cursor <cursoragent@cursor.com>
65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Pos;
|
|
|
|
use App\Models\PosMember;
|
|
use App\Models\User;
|
|
|
|
class PosMemberResolver
|
|
{
|
|
public function isAccountOwner(User $actor, string $ownerRef): bool
|
|
{
|
|
return $actor->public_id === $ownerRef;
|
|
}
|
|
|
|
public function memberFor(User $actor, string $ownerRef): ?PosMember
|
|
{
|
|
if ($this->isAccountOwner($actor, $ownerRef)) {
|
|
return null;
|
|
}
|
|
|
|
return PosMember::query()
|
|
->where('owner_ref', $ownerRef)
|
|
->where('user_ref', $actor->public_id)
|
|
->first();
|
|
}
|
|
|
|
/** Location ID the member may access; null = all branches. */
|
|
public function locationScope(?PosMember $member, string $ownerRef, User $actor): ?int
|
|
{
|
|
if ($this->isAccountOwner($actor, $ownerRef)) {
|
|
return null;
|
|
}
|
|
|
|
if ($member === null) {
|
|
abort(403, 'You do not have access to this POS account.');
|
|
}
|
|
|
|
if ($member->role === PosMember::ROLE_CASHIER) {
|
|
abort_unless($member->location_id, 403, 'Your cashier account is not assigned to a branch.');
|
|
|
|
return (int) $member->location_id;
|
|
}
|
|
|
|
return $member->location_id ? (int) $member->location_id : null;
|
|
}
|
|
|
|
public function canManageBranches(?PosMember $member, string $ownerRef, User $actor): bool
|
|
{
|
|
if ($this->isAccountOwner($actor, $ownerRef)) {
|
|
return true;
|
|
}
|
|
|
|
return $member?->hasRole(PosMember::ROLE_ADMIN, PosMember::ROLE_MANAGER) ?? false;
|
|
}
|
|
|
|
public function canManageTeam(?PosMember $member, string $ownerRef, User $actor): bool
|
|
{
|
|
if ($this->isAccountOwner($actor, $ownerRef)) {
|
|
return true;
|
|
}
|
|
|
|
return $member?->hasRole(PosMember::ROLE_ADMIN) ?? false;
|
|
}
|
|
}
|