fix
This commit is contained in:
parent
9f921750fc
commit
7e369785d5
|
|
@ -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 có
|
||||||
|
*
|
||||||
|
* @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
|
||||||
{
|
{
|
||||||
|
|
@ -745,7 +779,13 @@ class TicketController extends Controller
|
||||||
$leaveDaysInfo = LeaveDays::where('ld_user_id', $user->id)
|
$leaveDaysInfo = LeaveDays::where('ld_user_id', $user->id)
|
||||||
->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) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue