Merge branch 'master' of https://gitea.nswteam.net/joseph/ManagementSystem into vi
This commit is contained in:
commit
d7b7a61511
|
|
@ -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
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class AddMonthlyLeaveDays implements ShouldQueue
|
|||
->where('ld_year', $this->year)
|
||||
->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
|
||||
// Số ngày phép bằng với tháng hiện tại
|
||||
$leaveDay = new LeaveDays([
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ class InitializeLeaveDays implements ShouldQueue
|
|||
$ld_note = '';
|
||||
|
||||
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) {
|
||||
$join->on('notes.n_time_type', '=', 'categories.c_code')
|
||||
->where('categories.c_type', 'TIME_TYPE');
|
||||
|
|
|
|||
Loading…
Reference in New Issue