Merge pull request 'fix calculate onleave day' (#126) from vi.ticket-email into dev

Reviewed-on: #126
This commit is contained in:
joseph 2025-06-25 13:37:41 +10:00
commit b1e7aaa1ea
3 changed files with 10 additions and 6 deletions

View File

@ -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;

View File

@ -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 {

View File

@ -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();
}
}