BỔ SUNG CHECK THÊM điều kiện user ticket nguyên ngày #96

Merged
joseph merged 1 commits from Truong-CreateAutoTicketKPhep into master 2024-10-16 11:57:28 +11:00
1 changed files with 10 additions and 3 deletions

View File

@ -39,7 +39,7 @@ class CheckUserAttendanceJob implements ShouldQueue
// Lấy tất cả người dùng
$users = User::where('permission', 'not like', '%admin%')->get();
foreach ($users as $key => $user) {
// if ($user->id != 2) {
// if ($user->id != 4) {
// continue;
// }
// Kiểm tra dựa trên period (Sáng 'S' hoặc Chiều 'C')
@ -72,11 +72,18 @@ class CheckUserAttendanceJob implements ShouldQueue
// Kiểm tra nếu đã có ticket chờ xử lý hoặc đã được xác nhận
$existingTicket = Ticket::where('user_id', $userId)
->where('start_date', $today->format('Y-m-d'))
->where('start_period', $periodCode)
->where('end_date', $today->format('Y-m-d'))
->where('end_period', $periodCode)
->where(function ($query) use ($periodCode) {
$query->where('start_period', $periodCode) // Check the current period (S or C)
->orWhere(function ($query) {
// Check if there's a ticket for both morning and afternoon
$query->where('start_period', 'S')
->where('end_period', 'C');
});
})
->whereIn('status', ['WAITING', 'CONFIRMED'])
->first();
$type = 'ONLEAVE';
$reason = 'KHONG PHEP';
// Nếu không có check-in hoặc check-out, và chưa có ticket, tạo ticket mới