From 7e369785d592d2f19ab1df57a4afd668c65c33e6 Mon Sep 17 00:00:00 2001 From: Truong Vo <41848815+vmtruong301296@users.noreply.github.com> Date: Tue, 30 Dec 2025 10:08:18 +0700 Subject: [PATCH 1/3] fix --- .../app/Http/Controllers/TicketController.php | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/BACKEND/Modules/Admin/app/Http/Controllers/TicketController.php b/BACKEND/Modules/Admin/app/Http/Controllers/TicketController.php index 6488e7a..19b4ca4 100644 --- a/BACKEND/Modules/Admin/app/Http/Controllers/TicketController.php +++ b/BACKEND/Modules/Admin/app/Http/Controllers/TicketController.php @@ -726,6 +726,40 @@ class TicketController extends Controller ]; } + /** + * Khởi tạo dữ liệu ngày phép cho user nếu chưa có + * + * @param UserModel $user + * @param int $year + * @return LeaveDays|null + */ + private function initializeLeaveDaysForYear($user, int $year): ?LeaveDays + { + // Nếu là nhân viên chưa chính thức, ko cộng phép + if (!$user->is_permanent) { + return null; + } + + // Nếu là nhân viên nghỉ việc, ko cộng phép + if ($user->is_separated) { + return null; + } + + // Nếu chưa có dữ liệu năm hiện tại, tạo mới + // Số ngày phép bằng với tháng hiện tại + $leaveDaysInfo = new LeaveDays([ + 'ld_user_id' => $user->id, + 'ld_day_total' => 1, + 'ld_year' => $year, + 'ld_additional_day' => 0, + 'ld_note' => 'Khởi tạo ngày phép tháng 1 khi tạo ticket cho năm sau', + 'ld_special_leave_day' => 0, + ]); + $leaveDaysInfo->save(); + + return $leaveDaysInfo; + } + //Tính tổng số ngày nghỉ có phép đến tháng hiện tại private function getTotalLeaveDaysInMonthToMonth($user, int $year, int $month): float { @@ -745,7 +779,13 @@ class TicketController extends Controller $leaveDaysInfo = LeaveDays::where('ld_user_id', $user->id) ->where('ld_year', $year) ->first(); - + + if (!$leaveDaysInfo) { + $leaveDaysInfo = $this->initializeLeaveDaysForYear($user, $year); + if (!$leaveDaysInfo) { + return 0; + } + } $totalAllocated = 0; // Xử lý gửi ticket sau tháng hiện tại if ($leaveDaysInfo && $user->is_permanent) { From a0bfb19a34ebbbf1159b12d1d811b1ad1dd95fc5 Mon Sep 17 00:00:00 2001 From: Truong Vo <41848815+vmtruong301296@users.noreply.github.com> Date: Fri, 2 Jan 2026 08:18:29 +0700 Subject: [PATCH 2/3] =?UTF-8?q?B=E1=BB=95=20sung=20+=20th=C3=AAm=20ph?= =?UTF-8?q?=C3=A9p=20=C4=91=E1=BA=B7c=20bi=E1=BB=87t=20khi=20chuy=E1=BB=83?= =?UTF-8?q?n=20ph=C3=A9p=20t=E1=BB=AB=20n=C4=83m=20c=C5=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BACKEND/app/Jobs/InitializeLeaveDays.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BACKEND/app/Jobs/InitializeLeaveDays.php b/BACKEND/app/Jobs/InitializeLeaveDays.php index 5f40b47..ea79ed4 100644 --- a/BACKEND/app/Jobs/InitializeLeaveDays.php +++ b/BACKEND/app/Jobs/InitializeLeaveDays.php @@ -61,7 +61,7 @@ class InitializeLeaveDays implements ShouldQueue $ld_note = ''; if ($previousYearData) { - $ld_additional_day = $previousYearData->ld_day_total + $previousYearData->ld_additional_day; + $ld_additional_day = $previousYearData->ld_day_total + $previousYearData->ld_additional_day + $previousYearData->ld_special_leave_day; $totalLeaveDaysByMonth = Notes::join('categories', function ($join) { $join->on('notes.n_time_type', '=', 'categories.c_code') ->where('categories.c_type', 'TIME_TYPE'); From 8f30081e55691a3a73008a8d6e5ab8380458d733 Mon Sep 17 00:00:00 2001 From: Truong Vo <41848815+vmtruong301296@users.noreply.github.com> Date: Mon, 5 Jan 2026 08:20:01 +0700 Subject: [PATCH 3/3] =?UTF-8?q?fix=20ng=C3=A0y=20ph=C3=A9p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BACKEND/app/Jobs/AddMonthlyLeaveDays.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BACKEND/app/Jobs/AddMonthlyLeaveDays.php b/BACKEND/app/Jobs/AddMonthlyLeaveDays.php index e70192b..c63d683 100644 --- a/BACKEND/app/Jobs/AddMonthlyLeaveDays.php +++ b/BACKEND/app/Jobs/AddMonthlyLeaveDays.php @@ -46,7 +46,7 @@ class AddMonthlyLeaveDays implements ShouldQueue ->where('ld_year', $this->year) ->first(); - if (!$leaveDay) { + if (!$leaveDay && $this->month > 1) { // Nếu chưa có dữ liệu năm hiện tại, tạo mới // Số ngày phép bằng với tháng hiện tại $leaveDay = new LeaveDays([