fix calculate onleave day #126
			
				
			
		
		
		
	| 
						 | 
					@ -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)
 | 
					            // Ngày phép còn lại < ngày yêu cầu (Không đủ phép)
 | 
				
			||||||
            else if ($remainingOnleaveDaysInMonth < $monthData['days_requested']) {
 | 
					            else if ($remainingOnleaveDaysInMonth < $monthData['days_requested']) {
 | 
				
			||||||
                // Vượt limit
 | 
					                // Vượt limit
 | 
				
			||||||
                if ($remainingOnleaveDaysInMonth >= $maxDaysPerMonth) {
 | 
					                if ($onleaveDaysInMonth >= $maxDaysPerMonth) {
 | 
				
			||||||
                    $hasInsufficientDays = true;
 | 
					                    $hasInsufficientDays = true;
 | 
				
			||||||
                    $month_data_status = 'exceed_max_days';
 | 
					                    $month_data_status = 'exceed_max_days';
 | 
				
			||||||
                    $onleave_days_will_use = $maxDaysPerMonth - $onleaveDaysInMonth;
 | 
					                    $onleave_days_will_use = $maxDaysPerMonth - $onleaveDaysInMonth;
 | 
				
			||||||
| 
						 | 
					@ -708,7 +708,7 @@ class TicketController extends Controller
 | 
				
			||||||
            ->first();
 | 
					            ->first();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $totalAllocated = 0;
 | 
					        $totalAllocated = 0;
 | 
				
			||||||
        if ($leaveDaysInfo) {
 | 
					        if ($leaveDaysInfo && $user->is_permanent) {
 | 
				
			||||||
            $currentMonth = Carbon::now()->month;
 | 
					            $currentMonth = Carbon::now()->month;
 | 
				
			||||||
            $totalAllocated = $leaveDaysInfo->ld_day_total;
 | 
					            $totalAllocated = $leaveDaysInfo->ld_day_total;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -738,8 +738,6 @@ class TicketController extends Controller
 | 
				
			||||||
                    $totalAllocated = $month;
 | 
					                    $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;
 | 
					        $totalAllocated = $totalAllocated + $leaveDaysInfo->ld_additional_day + $leaveDaysInfo->ld_special_leave_day;
 | 
				
			||||||
        return $totalAllocated;
 | 
					        return $totalAllocated;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,9 +63,10 @@ class UserController extends Controller
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    $userLeaveDay->save();
 | 
					                    $userLeaveDay->save();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                $payload['permanent_date'] = Carbon::now()->toDateString();
 | 
					                $payload['permanent_date'] = Carbon::now()->toDateString();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $user->update($payload);
 | 
					            $user->update($payload);
 | 
				
			||||||
            return response()->json(['data' => $user, 'status' => true, 'message' => 'Update successful']);
 | 
					            return response()->json(['data' => $user, 'status' => true, 'message' => 'Update successful']);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -52,7 +52,12 @@ class DeductLeaveDays implements ShouldQueue
 | 
				
			||||||
                ->where('n_reason', 'ONLEAVE')
 | 
					                ->where('n_reason', 'ONLEAVE')
 | 
				
			||||||
                ->sum('categories.c_value');
 | 
					                ->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();
 | 
					            $existingData->save();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue