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; } }