Fix HR branch isolation for leave balances and attendance records, and separate My Attendance

This commit is contained in:
2026-07-06 12:50:37 +08:00
parent 91adb44439
commit 755650c3b3
416 changed files with 14578 additions and 14536 deletions

View File

@@ -21,6 +21,15 @@ class LeaveBalanceController extends Controller
->where(function ($q) {
if (Auth::user()->can('manage-any-leave-balances')) {
$q->whereIn('created_by', getCompanyAndUsersId());
} elseif (Auth::user()->can('manage-leave-balances')) {
$branchId = Auth::user()->employee->branch_id ?? null;
if ($branchId) {
$q->whereHas('employee', function ($eq) use ($branchId) {
$eq->where('branch_id', $branchId);
});
} else {
$q->where('created_by', Auth::id())->orWhere('employee_id', Auth::id());
}
} elseif (Auth::user()->can('manage-own-leave-balances') || Auth::user()->can('view-leave-balances') || Auth::user()->type === 'employee') {
$q->where('created_by', Auth::id())->orWhere('employee_id', Auth::id());
} else {
@@ -115,7 +124,16 @@ class LeaveBalanceController extends Controller
// Get employees for filter dropdown (compatible with getFilteredEmployees logic)
$employeeQuery = Employee::whereIn('created_by', getCompanyAndUsersId());
if ((Auth::user()->can('manage-own-leave-balances') || Auth::user()->can('view-leave-balances') || Auth::user()->type === 'employee') && !Auth::user()->can('manage-any-leave-balances')) {
if (Auth::user()->can('manage-leave-balances') && !Auth::user()->can('manage-any-leave-balances')) {
$branchId = Auth::user()->employee->branch_id ?? null;
if ($branchId) {
$employeeQuery->where('branch_id', $branchId);
} else {
$employeeQuery->where(function ($q) {
$q->where('created_by', Auth::id())->orWhere('user_id', Auth::id());
});
}
} elseif ((Auth::user()->can('manage-own-leave-balances') || Auth::user()->can('view-leave-balances') || Auth::user()->type === 'employee') && !Auth::user()->can('manage-any-leave-balances')) {
$employeeQuery->where(function ($q) {
$q->where('created_by', Auth::id())->orWhere('user_id', Auth::id());
});