diff --git a/application/TimerecordingBilling/TimerecordingBillingController.php b/application/TimerecordingBilling/TimerecordingBillingController.php index 4a159d00c..ce4b9ae42 100644 --- a/application/TimerecordingBilling/TimerecordingBillingController.php +++ b/application/TimerecordingBilling/TimerecordingBillingController.php @@ -606,6 +606,10 @@ class TimerecordingBillingController extends mfBaseController } if ($timerecording['daysum']) { $data['nlz'] = $timerecording['daysum']; + if (strpos($data['nlz'],"Urlaub aufbuchen") !== false) { + $holidays=$this->getholidays($timerecording['user_id'], $enddate); + $data['holidays'] = $holidays; + } } if ($timerecording['homeoffice']) { $data['homeoffice'] = $timerecording['homeoffice']; @@ -807,4 +811,72 @@ class TimerecordingBillingController extends mfBaseController echo json_encode($response); die(); } + + protected function getholidays($userid, $enddate) + { +// $enddate = strtotime("01." . $date); +// $enddate = strtotime("last day of this month", $enddate); +// $enddate = strtotime("23:59:59", $enddate); + + $employee = TimerecordingEmployeeModel::search(['user_id' => $userid]); + + if ($employee) { + $employee = $employee[0]; + $holidays = $employee->holidays; + $holidays_now = $employee->holidays_now; + $holidays_timestamp = $employee->holidays_timestamp; + $workinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $userid]); + $realHolidays = TimerecordingHolidayModel::getAll(); + foreach ($realHolidays as $realHoliday) { + $realholiDay[date('Y-m-d', $realHoliday->timestamp)] = $realHoliday->timestamp; + } + if (!$holidays_timestamp) { + //$holidays_timestamp = $employee->startdate; + $holidays_timestamp = strtotime('2024-01-01 00:00:00'); + $holidays_now = $holidays; + } + $timerecordings = TimerecordingModel::search(['user_id' => $userid, 'start' => $holidays_timestamp, 'timerecordingCategory_id' => 3]); + $timerecordingscorrections = TimerecordingModel::search(['user_id' => $userid, 'start' => $holidays_timestamp, 'days' => 1]); + foreach ($timerecordings as $timerecording) { + + if ($timerecording->end > $enddate) { + $timerecording->end = $enddate; + } + $daycounter = ($timerecording->end - $timerecording->start) / 86400; + $daycounter = intval(round($daycounter, 0, PHP_ROUND_HALF_DOWN)); + $daycounter = $daycounter * 86400; + if (is_int($daycounter)) { + for ($i = 86400; $i <= $daycounter; $i = $i + 86400) { + $holidayDays[date("Y-m-d", $timerecording->start + $i - 86400)] = 1; + } + } + } + + + foreach ($workinghours as $workinghour) { + + $whstart = strtotime(date('Y-m-d', time()) . " " . $workinghour->start . ":00"); + $whend = strtotime(date('Y-m-d', time()) . " " . $workinghour->end . ":00"); + if (!$workingHours[$workinghour->day]) { + $workingHours[$workinghour->day] = $whend - $whstart; + } else { + $workingHours[$workinghour->day] = $workingHours[$workinghour->day] + $whend - $whstart; + } + } + //check if holiday is already in the list + foreach ($holidayDays as $key => $holidayDay) { + if (($realholiDay[$key])) { + + } else if ($workingHours[date('w', strtotime($key))]) { + $holidays_now--; + } + } + foreach ($timerecordingscorrections as $timerecordingscorrection) { + $holidays_now = $holidays_now + $timerecordingscorrection->days; + } + + } + + return $holidays_now; + } }