feat: implement multi-branch attendance tracking and filter updates

This commit is contained in:
2026-05-25 11:34:04 +08:00
parent 9235ddbff5
commit 33a2dbed16
6 changed files with 102 additions and 4 deletions

View File

@@ -53,8 +53,15 @@ class AttendanceRecordController extends Controller
// Handle branch filter
if ($request->has('branch_id') && ! empty($request->branch_id) && $request->branch_id !== 'all') {
$query->whereHas('employee', function ($subQ) use ($request) {
$subQ->where('branch_id', $request->branch_id);
$branchId = $request->branch_id;
$query->where(function ($q) use ($branchId) {
$q->where('attendance_records.branch_id', $branchId)
->orWhere(function ($subQ) use ($branchId) {
$subQ->whereNull('attendance_records.branch_id')
->whereHas('employee.employee', function ($empQ) use ($branchId) {
$empQ->where('branch_id', $branchId);
});
});
});
}
@@ -868,8 +875,15 @@ class AttendanceRecordController extends Controller
}
if ($branch_id) {
$query->whereHas('employee', function($q) use ($branch_id) {
$q->where('branch_id', $branch_id);
$query->where(function ($q) use ($branch_id, $startDate, $endDate) {
$q->whereHas('employee', function ($subQ) use ($branch_id) {
$subQ->where('branch_id', $branch_id);
})->orWhereIn('id', function ($subQ) use ($branch_id, $startDate, $endDate) {
$subQ->select('employee_id')
->from('attendance_records')
->where('branch_id', $branch_id)
->whereBetween('date', [$startDate->format('Y-m-d'), $endDate->format('Y-m-d')]);
});
});
}