From 34b66986960c95aee19a8900a083d041093252e8 Mon Sep 17 00:00:00 2001 From: Truong Vo <41848815+vmtruong301296@users.noreply.github.com> Date: Wed, 16 Oct 2024 07:54:38 +0700 Subject: [PATCH] =?UTF-8?q?B=E1=BB=94=20SUNG=20CHECK=20TH=C3=8AM=20=C4=91i?= =?UTF-8?q?=E1=BB=81u=20ki=E1=BB=87n=20user=20ticket=20nguy=C3=AAn=20ng?= =?UTF-8?q?=C3=A0y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BACKEND/app/Jobs/CheckUserAttendanceJob.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/BACKEND/app/Jobs/CheckUserAttendanceJob.php b/BACKEND/app/Jobs/CheckUserAttendanceJob.php index 04ba727..52952dd 100644 --- a/BACKEND/app/Jobs/CheckUserAttendanceJob.php +++ b/BACKEND/app/Jobs/CheckUserAttendanceJob.php @@ -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