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:
@@ -17,6 +17,7 @@ class PosLocation extends Model
|
||||
'owner_ref',
|
||||
'name',
|
||||
'currency',
|
||||
'is_default',
|
||||
'service_style',
|
||||
'receipt_footer',
|
||||
'receipt_header',
|
||||
@@ -28,6 +29,7 @@ class PosLocation extends Model
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_default' => 'boolean',
|
||||
'printer_paper_mm' => 'integer',
|
||||
'printer_auto_print' => 'boolean',
|
||||
];
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class PosMember extends Model
|
||||
{
|
||||
public const ROLE_ADMIN = 'admin';
|
||||
|
||||
public const ROLE_MANAGER = 'manager';
|
||||
|
||||
public const ROLE_CASHIER = 'cashier';
|
||||
|
||||
protected $fillable = [
|
||||
'owner_ref',
|
||||
'user_ref',
|
||||
'role',
|
||||
'location_id',
|
||||
];
|
||||
|
||||
public function location(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PosLocation::class, 'location_id');
|
||||
}
|
||||
|
||||
public function hasRole(string ...$roles): bool
|
||||
{
|
||||
return in_array($this->role, $roles, true);
|
||||
}
|
||||
|
||||
public function scopeOwned(Builder $query, string $ownerRef): Builder
|
||||
{
|
||||
return $query->where('owner_ref', $ownerRef);
|
||||
}
|
||||
}
|
||||
+24
-4
@@ -37,18 +37,38 @@ class User extends Authenticatable
|
||||
->where('status', QrTeamMember::STATUS_ACTIVE);
|
||||
}
|
||||
|
||||
public function posMemberships(): HasMany
|
||||
{
|
||||
return $this->hasMany(PosMember::class, 'user_ref', 'public_id');
|
||||
}
|
||||
|
||||
public function canAccessAccount(int $accountId): bool
|
||||
{
|
||||
return $accountId === $this->id
|
||||
|| $this->memberships()->where('account_id', $accountId)->exists();
|
||||
if ($accountId === $this->id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->memberships()->where('account_id', $accountId)->exists()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$account = self::find($accountId);
|
||||
|
||||
return $account !== null
|
||||
&& $this->posMemberships()->where('owner_ref', $account->public_id)->exists();
|
||||
}
|
||||
|
||||
/** @return Collection<int, User> */
|
||||
public function accessibleAccounts(): Collection
|
||||
{
|
||||
$ids = $this->memberships()->pluck('account_id')->all();
|
||||
$qrIds = $this->memberships()->pluck('account_id')->all();
|
||||
$posOwnerRefs = $this->posMemberships()->pluck('owner_ref')->all();
|
||||
|
||||
return collect([$this])->merge(self::whereIn('id', $ids)->get())->unique('id')->values();
|
||||
return collect([$this])
|
||||
->merge(self::whereIn('id', $qrIds)->get())
|
||||
->merge(self::whereIn('public_id', $posOwnerRefs)->get())
|
||||
->unique('id')
|
||||
->values();
|
||||
}
|
||||
|
||||
public function avatarUrl(): ?string
|
||||
|
||||
Reference in New Issue
Block a user