Add multi-branch POS with team roles and branch-scoped cashiers.
Deploy Ladill POS / deploy (push) Successful in 1m58s
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>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\PosLocation;
|
||||
use App\Models\User;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -26,6 +27,8 @@ class SetActingAccount
|
||||
}
|
||||
}
|
||||
|
||||
$accountId = $this->preferEmployerAccount($request, $user, $accountId);
|
||||
|
||||
$account = $accountId === $user->id ? $user : (User::find($accountId) ?? $user);
|
||||
|
||||
$request->attributes->set('actingAccount', $account);
|
||||
@@ -38,4 +41,31 @@ class SetActingAccount
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
private function preferEmployerAccount(Request $request, User $user, int $accountId): int
|
||||
{
|
||||
if ($accountId !== $user->id) {
|
||||
return $accountId;
|
||||
}
|
||||
|
||||
if (PosLocation::owned($user->public_id)->exists()) {
|
||||
return $accountId;
|
||||
}
|
||||
|
||||
$membership = $user->posMemberships()->first();
|
||||
if (! $membership) {
|
||||
return $accountId;
|
||||
}
|
||||
|
||||
$employer = User::where('public_id', $membership->owner_ref)->first();
|
||||
if ($employer && $user->canAccessAccount($employer->id)) {
|
||||
if (! $request->is('api/*')) {
|
||||
$request->session()->put('ladill_account', $employer->id);
|
||||
}
|
||||
|
||||
return $employer->id;
|
||||
}
|
||||
|
||||
return $accountId;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user