This commit is contained in:
Nguyễn Hoàng Vĩ 2026-01-06 15:59:54 +07:00
commit d7b7a61511
3 changed files with 43 additions and 3 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 //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 private function getTotalLeaveDaysInMonthToMonth($user, int $year, int $month): float
{ {
@ -746,6 +780,12 @@ class TicketController extends Controller
->where('ld_year', $year) ->where('ld_year', $year)
->first(); ->first();
if (!$leaveDaysInfo) {
$leaveDaysInfo = $this->initializeLeaveDaysForYear($user, $year);
if (!$leaveDaysInfo) {
return 0;
}
}
$totalAllocated = 0; $totalAllocated = 0;
// Xử lý gửi ticket sau tháng hiện tại // Xử lý gửi ticket sau tháng hiện tại
if ($leaveDaysInfo && $user->is_permanent) { if ($leaveDaysInfo && $user->is_permanent) {

View File

@ -46,7 +46,7 @@ class AddMonthlyLeaveDays implements ShouldQueue
->where('ld_year', $this->year) ->where('ld_year', $this->year)
->first(); ->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 // 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 // Số ngày phép bằng với tháng hiện tại
$leaveDay = new LeaveDays([ $leaveDay = new LeaveDays([

View File

@ -61,7 +61,7 @@ class InitializeLeaveDays implements ShouldQueue
$ld_note = ''; $ld_note = '';
if ($previousYearData) { 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) { $totalLeaveDaysByMonth = Notes::join('categories', function ($join) {
$join->on('notes.n_time_type', '=', 'categories.c_code') $join->on('notes.n_time_type', '=', 'categories.c_code')
->where('categories.c_type', 'TIME_TYPE'); ->where('categories.c_type', 'TIME_TYPE');