This commit is contained in:
Truong Vo 2025-12-30 10:08:18 +07:00
parent 9f921750fc
commit 7e369785d5
1 changed files with 41 additions and 1 deletions

View File

@ -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
*
* @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
{
@ -746,6 +780,12 @@ class TicketController extends Controller
->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) {