update: latest changes to multi-tenant branch

This commit is contained in:
2026-08-12 18:44:24 +08:00
parent 80c0a2ea42
commit 3e8abf59f9
486 changed files with 28968 additions and 15306 deletions

View File

@@ -11,19 +11,20 @@ class ShiftController extends Controller
{
public function index(Request $request)
{
if (Auth::user()->can('manage-shifts')) {
$query = Shift::with(['creator'])->where(function ($q) {
if (Auth::user()->can('manage-any-shifts')) {
$q->whereIn('created_by', getCompanyAndUsersId());
$user = Auth::user();
if ($user->type === 'company' || $user->can('manage-shifts') || $user->can('view-shifts') || $user->can('create-shifts')) {
$query = Shift::with(['creator'])->where(function ($q) use ($user) {
if ($user->type === 'company' || $user->can('manage-any-shifts') || $user->can('manage-shifts') || $user->can('view-shifts')) {
$q->whereIn('created_by', getCompanyAndUsersId());
} else {
$branchId = Auth::user()->branch_id ?? Auth::user()->employee->branch_id ?? null;
$branchId = $user->branch_id ?? $user->employee->branch_id ?? null;
if ($branchId) {
$q->where(function($q2) use ($branchId) {
$q2->where('branch_id', $branchId)
->orWhereNull('branch_id'); // company wide shifts
})->whereIn('created_by', getCompanyAndUsersId());
} else {
$q->whereIn('created_by', getCompanyAndUsersId());
$q->whereIn('created_by', getCompanyAndUsersId());
}
}
});