From a883662f0b35120dec2f98e166cf46e50820a165 Mon Sep 17 00:00:00 2001 From: "hoangvi.ng" Date: Wed, 25 Jun 2025 10:34:02 +0700 Subject: [PATCH] fix calculate onleave day --- .../Admin/app/Http/Controllers/TicketController.php | 6 ++---- .../Modules/Auth/app/Http/Controllers/UserController.php | 3 ++- BACKEND/app/Jobs/DeductLeaveDays.php | 7 ++++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/BACKEND/Modules/Admin/app/Http/Controllers/TicketController.php b/BACKEND/Modules/Admin/app/Http/Controllers/TicketController.php index df0e629..1f7ee90 100644 --- a/BACKEND/Modules/Admin/app/Http/Controllers/TicketController.php +++ b/BACKEND/Modules/Admin/app/Http/Controllers/TicketController.php @@ -553,7 +553,7 @@ class TicketController extends Controller // Ngày phép còn lại < ngày yêu cầu (Không đủ phép) else if ($remainingOnleaveDaysInMonth < $monthData['days_requested']) { // Vượt limit - if ($remainingOnleaveDaysInMonth >= $maxDaysPerMonth) { + if ($onleaveDaysInMonth >= $maxDaysPerMonth) { $hasInsufficientDays = true; $month_data_status = 'exceed_max_days'; $onleave_days_will_use = $maxDaysPerMonth - $onleaveDaysInMonth; @@ -708,7 +708,7 @@ class TicketController extends Controller ->first(); $totalAllocated = 0; - if ($leaveDaysInfo) { + if ($leaveDaysInfo && $user->is_permanent) { $currentMonth = Carbon::now()->month; $totalAllocated = $leaveDaysInfo->ld_day_total; @@ -738,8 +738,6 @@ class TicketController extends Controller $totalAllocated = $month; } } - } else { - Log::warning("No LeaveDays record found for user ID: {$user->id}, year: {$year}. Assuming 0 allocated days."); } $totalAllocated = $totalAllocated + $leaveDaysInfo->ld_additional_day + $leaveDaysInfo->ld_special_leave_day; return $totalAllocated; diff --git a/BACKEND/Modules/Auth/app/Http/Controllers/UserController.php b/BACKEND/Modules/Auth/app/Http/Controllers/UserController.php index ff84f4d..a53752e 100755 --- a/BACKEND/Modules/Auth/app/Http/Controllers/UserController.php +++ b/BACKEND/Modules/Auth/app/Http/Controllers/UserController.php @@ -63,9 +63,10 @@ class UserController extends Controller } $userLeaveDay->save(); } + + $payload['permanent_date'] = Carbon::now()->toDateString(); } - $payload['permanent_date'] = Carbon::now()->toDateString(); $user->update($payload); return response()->json(['data' => $user, 'status' => true, 'message' => 'Update successful']); } else { diff --git a/BACKEND/app/Jobs/DeductLeaveDays.php b/BACKEND/app/Jobs/DeductLeaveDays.php index b5f9571..e7e61b7 100644 --- a/BACKEND/app/Jobs/DeductLeaveDays.php +++ b/BACKEND/app/Jobs/DeductLeaveDays.php @@ -52,7 +52,12 @@ class DeductLeaveDays implements ShouldQueue ->where('n_reason', 'ONLEAVE') ->sum('categories.c_value'); - $existingData->ld_additional_day = $usedOnleaveDaysTotal ?? 0; + if($usedOnleaveDaysTotal) { + $existingData->ld_additional_day = $existingData->ld_additional_day >= $usedOnleaveDaysTotal ? $usedOnleaveDaysTotal : $existingData->ld_additional_day; + } else { + $existingData->ld_additional_day = 0; + } + $existingData->save(); } } -- 2.39.2