From 6ed34fe676204807d36c4ca3a9c5809d6441fcd3 Mon Sep 17 00:00:00 2001 From: Daniel Spitzer Date: Sat, 8 Feb 2025 20:56:29 +0100 Subject: [PATCH] =?UTF-8?q?Zeiterfassung=20=20*=20Feature=20Implementation?= =?UTF-8?q?=20Arbeitszeit=C3=A4nderungen=20mit=20History=20f=C3=BCr=20alle?= =?UTF-8?q?=20m=C3=B6glichen=20historischen=20Berechnungen=20und=20Auswert?= =?UTF-8?q?ung=20fertigstellung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Timerecording/TimerecordingController.php | 120 ++++++++++++++++++ .../TimerecordingEmployeeController.php | 4 + .../TimerecordingReportController.php | 74 ++++++++++- 3 files changed, 197 insertions(+), 1 deletion(-) diff --git a/application/Timerecording/TimerecordingController.php b/application/Timerecording/TimerecordingController.php index e28d7a9ac..db4bcde7e 100644 --- a/application/Timerecording/TimerecordingController.php +++ b/application/Timerecording/TimerecordingController.php @@ -528,8 +528,36 @@ class TimerecordingController extends mfBaseController $workingHours[$workinghour->day] = $workingHours[$workinghour->day] + $whend - $whstart; } } + $workinghourshistory = TimerecordingEmployeeWorkingHourHistoryModel::search(['user_id' => $userid]); + if ($workinghourshistory) { + $workingHoursHistory[2147483500]=$workingHours; + foreach ($workinghourshistory as $workinghourhistory) { + $whenddate = $workinghourhistory->enddate; + $workinghourhistoryhours = json_decode($workinghourhistory->workinghours, true); + foreach ($workinghourhistoryhours as $workinghourhistoryhour) { + $whstart = strtotime(date('Y-m-d', time()) . " " . $workinghourhistoryhour['start'] . ":00"); + $whend = strtotime(date('Y-m-d', time()) . " " . $workinghourhistoryhour['end'] . ":00"); + if (!$workingHoursHistory[$whenddate][$workinghourhistoryhour['day']]) { + $workingHoursHistory[$whenddate][$workinghourhistoryhour['day']] = $whend - $whstart; + } else { + $workingHoursHistory[$whenddate][$workinghourhistoryhour['day']] = $workingHoursHistory[$whenddate][$workinghourhistoryhour['day']] + $whend - $whstart; + } + } + } + } //check if holiday is already in the list foreach ($holidayDays as $key => $holidayDay) { + if ($workingHoursHistory) + { + foreach ($workingHoursHistory as $whkey => $whdata) { + $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); + $timestamp = strtotime($key); + if ($whtimestamp >= $timestamp) + { + $workingHours = $whdata; + } + } + } if (($realholiDay[$key])) { } else if ($workingHours[date('w', strtotime($key))]) { @@ -605,6 +633,7 @@ class TimerecordingController extends mfBaseController if ($plushours_timestamp > 0) { $return = $this->getTimerecordingsApi(5, null, null, null, $plushours_timestamp, $endtime, $userid); +// echo $return['is'] ." ". $return['must'].PHP_EOL; $diffTime = $return['is'] - $return['must']; $plushours_now = $plushours_now + $diffTime; } else { @@ -681,6 +710,25 @@ class TimerecordingController extends mfBaseController $workingHours[$workinghour->day] = $workingHours[$workinghour->day] + $whend - $whstart; } } + + $workinghourshistory = TimerecordingEmployeeWorkingHourHistoryModel::search(['user_id' => $userid]); + if ($workinghourshistory) { + $workingHoursHistory[2147483500]=$workingHours; + foreach ($workinghourshistory as $workinghourhistory) { + $whenddate = $workinghourhistory->enddate; + $workinghourhistoryhours = json_decode($workinghourhistory->workinghours, true); + foreach ($workinghourhistoryhours as $workinghourhistoryhour) { + $whstart = strtotime(date('Y-m-d', time()) . " " . $workinghourhistoryhour['start'] . ":00"); + $whend = strtotime(date('Y-m-d', time()) . " " . $workinghourhistoryhour['end'] . ":00"); + if (!$workingHoursHistory[$whenddate][$workinghourhistoryhour['day']]) { + $workingHoursHistory[$whenddate][$workinghourhistoryhour['day']] = $whend - $whstart; + } else { + $workingHoursHistory[$whenddate][$workinghourhistoryhour['day']] = $workingHoursHistory[$whenddate][$workinghourhistoryhour['day']] + $whend - $whstart; + } + } + } + } + foreach ($holidays as $holiday) { $holiDay[date('Y-m-d', $holiday->timestamp)] = $holiday->description; } @@ -704,6 +752,18 @@ class TimerecordingController extends mfBaseController } $dDate = date('Y-m-d', $timestamp + $WintertimeCompensation); $dDay = date('w', $timestamp + $WintertimeCompensation); + if ($workingHoursHistory) + { + foreach ($workingHoursHistory as $whkey => $whdata) { + $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); + if ($whtimestamp >= $timestamp) + { + unset($workingHours); + $workingHours = $whdata; + } + } + } + if (!$holiDay[$dDate] && $dDate >= date('Y-m-d', $startdate) && $dDate <= date('Y-m-d', $enddate)) { $mustSeconds = $mustSeconds + $workingHours[$dDay]; } elseif ($holiDay[$dDate]) { @@ -727,6 +787,18 @@ class TimerecordingController extends mfBaseController } $dDate = date('Y-m-d', $timestamp + $WintertimeCompensation); $dDay = date('w', $timestamp + $WintertimeCompensation); + if ($workingHoursHistory) + { + foreach ($workingHoursHistory as $whkey => $whdata) { + $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); + if ($whtimestamp >= $timestamp) + { + unset($workingHours); + $workingHours = $whdata; + } + } + } + if (!$holiDay[$dDate] && $dDate >= date('Y-m-d', $startdate) && $dDate <= date('Y-m-d', $enddate)) { $mustSeconds = $mustSeconds + $workingHours[$dDay]; } elseif ($holiDay[$dDate]) { @@ -749,6 +821,18 @@ class TimerecordingController extends mfBaseController } $dDate = date('Y-m-d', $timestamp + $WintertimeCompensation); $dDay = date('w', $timestamp + $WintertimeCompensation); + if ($workingHoursHistory) + { + foreach ($workingHoursHistory as $whkey => $whdata) { + $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); + if ($whtimestamp >= $timestamp) + { + unset($workingHours); + $workingHours = $whdata; + } + } + } + if (!$holiDay[$dDate] && $dDate >= date('Y-m-d', $startdate) && $dDate <= date('Y-m-d', $enddate)) { $mustSeconds = $mustSeconds + $workingHours[$dDay]; } elseif ($holiDay[$dDate]) { @@ -770,9 +854,23 @@ class TimerecordingController extends mfBaseController if (date('I', $timestamp) == 0) { $WintertimeCompensation = 3600; } + if ($workingHoursHistory) + { + foreach ($workingHoursHistory as $whkey => $whdata) { + $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); + if ($whtimestamp >= $timestamp) + { + unset($workingHours); + $workingHours = $whdata; +// echo date('Y-m-d 23:59:59', $whkey).PHP_EOL; + } + } + } + $dDate = date('Y-m-d', $timestamp + $WintertimeCompensation); $dDay = date('w', $timestamp + $WintertimeCompensation); if (!$holiDay[$dDate]) { + $mustSeconds = $mustSeconds + $workingHours[$dDay]; } @@ -828,6 +926,17 @@ class TimerecordingController extends mfBaseController $savecounter = 0; $sumdays = 0; for ($i = $starttimecalc; $i <= $endtimecalc; $i = $i + 86400) { + if ($workingHoursHistory) + { + foreach ($workingHoursHistory as $whkey => $whdata) { + $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); + if ($whtimestamp >= $i) + { + unset($workingHours); + $workingHours = $whdata; + } + } + } $holidaycounter = $workingHours[date("w", $i)]; $daycheck = date("Y-m-d", $i); if (!$holiDay[$daycheck]) { @@ -877,6 +986,17 @@ class TimerecordingController extends mfBaseController $savecounter = 0; // echo $starttimecalc."
"; for ($i = $starttimecalc; $i <= $endtimecalc; $i = $i + 86400) { + if ($workingHoursHistory) + { + foreach ($workingHoursHistory as $whkey => $whdata) { + $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); + if ($whtimestamp >= $i) + { + unset($workingHours); + $workingHours = $whdata; + } + } + } $holidaycounter = $workingHours[$timerecording->user_id][date("w", $i)]; $daycheck = date("Y-m-d", $i); if (!$holiDay[$daycheck]) { diff --git a/application/TimerecordingEmployee/TimerecordingEmployeeController.php b/application/TimerecordingEmployee/TimerecordingEmployeeController.php index cd51e7a93..07c679399 100644 --- a/application/TimerecordingEmployee/TimerecordingEmployeeController.php +++ b/application/TimerecordingEmployee/TimerecordingEmployeeController.php @@ -245,6 +245,8 @@ class TimerecordingEmployeeController extends mfBaseController } else if ($mode = "add") { $this->layout()->setFlash("Personaladministration erfolgreich angelegt", "success"); } + $employee = new TimerecordingController(); + $employee->updatePlushours($r->user_id); $this->redirect("TimerecordingEmployee"); } @@ -281,6 +283,8 @@ class TimerecordingEmployeeController extends mfBaseController $result[$value->enddate]['workingtime'] = $secondcounter; $result[$value->enddate]['id'] = $value->id; } + $employee = new TimerecordingController(); + $employee->updatePlushours($userid); return $result; } diff --git a/application/TimerecordingReport/TimerecordingReportController.php b/application/TimerecordingReport/TimerecordingReportController.php index bbaf8a881..ee53f8ac6 100644 --- a/application/TimerecordingReport/TimerecordingReportController.php +++ b/application/TimerecordingReport/TimerecordingReportController.php @@ -95,6 +95,8 @@ class TimerecordingReportController extends mfBaseController $workingHours[$workinghour->user_id][$workinghour->day] = $workingHours[$workinghour->user_id][$workinghour->day] + $whend - $whstart; } } + + foreach ($this->holidays as $holiday) { $holiDay[date('Y-m-d', $holiday->timestamp)] = $holiday->timestamp; } @@ -556,13 +558,32 @@ class TimerecordingReportController extends mfBaseController $workingHours[$workinghour->day] = $workingHours[$workinghour->day] + $whend - $whstart; } } + + $workinghourshistory = TimerecordingEmployeeWorkingHourHistoryModel::search(['user_id' => $user_id]); + if ($workinghourshistory) { + $workingHoursHistory[9732489200]=$workingHours; + foreach ($workinghourshistory as $workinghourhistory) { + $whenddate = $workinghourhistory->enddate; + $workinghourhistoryhours = json_decode($workinghourhistory->workinghours, true); + foreach ($workinghourhistoryhours as $workinghourhistoryhour) { + $whstart = strtotime(date('Y-m-d', time()) . " " . $workinghourhistoryhour['start'] . ":00"); + $whend = strtotime(date('Y-m-d', time()) . " " . $workinghourhistoryhour['end'] . ":00"); + if (!$workingHoursHistory[$whenddate][$workinghourhistoryhour['day']]) { + $workingHoursHistory[$whenddate][$workinghourhistoryhour['day']] = $whend - $whstart; + } else { + $workingHoursHistory[$whenddate][$workinghourhistoryhour['day']] = $workingHoursHistory[$whenddate][$workinghourhistoryhour['day']] + $whend - $whstart; + } + } + } + } + foreach ($this->holidays as $holiday) { $holiDay[date('Y-m-d', $holiday->timestamp)] = $holiday->timestamp; } if ($datatype == 1) { $kw = date('W', $dataweek); - $year = date(o, $dataweek); + $year = date('o', $dataweek); $timestamp_montag = strtotime("{$year}-W{$kw}"); $timestamp_sonntag = strtotime("{$year}-W{$kw}-7"); $firstdate = strtotime(date("Y-m-d", $timestamp_montag) . " 00:00:00"); @@ -579,6 +600,16 @@ class TimerecordingReportController extends mfBaseController } $dDate = date('Y-m-d', $timestamp + $WintertimeCompensation); $dDay = date('w', $timestamp + $WintertimeCompensation); + if ($workingHoursHistory) + { + foreach ($workingHoursHistory as $whkey => $whdata) { + $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); + if ($whtimestamp >= $timestamp) + { + $workingHours = $whdata; + } + } + } if (!$holiDay[$dDate] && $dDate >= date('Y-m-d', $startdate) && $dDate <= date('Y-m-d', $enddate)) { $mustSeconds = $mustSeconds + $workingHours[$dDay]; @@ -605,6 +636,17 @@ class TimerecordingReportController extends mfBaseController } $dDate = date('Y-m-d', $timestamp + $WintertimeCompensation); $dDay = date('w', $timestamp + $WintertimeCompensation); + if ($workingHoursHistory) + { + foreach ($workingHoursHistory as $whkey => $whdata) { + $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); + if ($whtimestamp >= $timestamp) + { + $workingHours = $whdata; + } + } + } + if (!$holiDay[$dDate] && $dDate >= date('Y-m-d', $startdate) && $dDate <= date('Y-m-d', $enddate)) { $mustSeconds = $mustSeconds + $workingHours[$dDay]; } @@ -628,6 +670,16 @@ class TimerecordingReportController extends mfBaseController } $dDate = date('Y-m-d', $timestamp + $WintertimeCompensation); $dDay = date('w', $timestamp + $WintertimeCompensation); + if ($workingHoursHistory) + { + foreach ($workingHoursHistory as $whkey => $whdata) { + $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); + if ($whtimestamp >= $timestamp) + { + $workingHours = $whdata; + } + } + } if (!$holiDay[$dDate]) { $mustSeconds = $mustSeconds + $workingHours[$dDay]; } @@ -756,6 +808,16 @@ class TimerecordingReportController extends mfBaseController $sumdays = 0; for ($i = $starttimecalc; $i <= $endtimecalc; $i = $i + 86400) { + if ($workingHoursHistory) + { + foreach ($workingHoursHistory as $whkey => $whdata) { + $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); + if ($whtimestamp >= $i) + { + $workingHours = $whdata; + } + } + } $holidaycounter = $workingHours[date("w", $i)]; $daycheck = date("Y-m-d", $i); if (!$holiDay[$daycheck]) { @@ -812,6 +874,16 @@ class TimerecordingReportController extends mfBaseController $summcounter = 0; $savecounter = 0; for ($i = $starttimecalc; $i <= $endtimecalc; $i = $i + 86400) { + if ($workingHoursHistory) + { + foreach ($workingHoursHistory as $whkey => $whdata) { + $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); + if ($whtimestamp >= $i) + { + $workingHours = $whdata; + } + } + } $holidaycounter = $workingHours[date("w", $i)]; $isSeconds = $isSeconds + $holidaycounter; $summcounter = $summcounter + $holidaycounter;