From cc00f70cd694b99031efaf6cea76f9d39aee51b5 Mon Sep 17 00:00:00 2001 From: Spitzer Daniel Date: Mon, 4 Mar 2024 11:51:19 +0100 Subject: [PATCH] =?UTF-8?q?Zeiterfassung=20Update=20=20*=20Soll=20zeiten?= =?UTF-8?q?=20nun=20vom=20Startdatum=20abh=C3=A4ngig=20=20*=20Neue=20Summi?= =?UTF-8?q?erung=20der=20Sollzeiten=20in=20der=20Personalverwaltung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/TimerecordingEmployee/Index.php | 25 ++++++++-- .../Timerecording/TimerecordingController.php | 36 ++++++++------ .../TimerecordingEmployeeWorkingHourModel.php | 49 ++++++++++++++++++- .../TimerecordingReportController.php | 7 +-- 4 files changed, 92 insertions(+), 25 deletions(-) diff --git a/Layout/default/TimerecordingEmployee/Index.php b/Layout/default/TimerecordingEmployee/Index.php index db7d108cd..6d4534690 100644 --- a/Layout/default/TimerecordingEmployee/Index.php +++ b/Layout/default/TimerecordingEmployee/Index.php @@ -5,6 +5,14 @@ $type[3] = "Lehrling"; ?> +
@@ -71,6 +79,14 @@ $type[3] = "Lehrling"; } else { $sum = ""; } + if ($timerecordingemployees[$timerecordinguser->id]['plushours_now'] < 0) { + $plusHours = $timerecordingemployees[$timerecordinguser->id]['plushours_now'] * -1; + $plusHours = "-" . sprintf('%02dh:%02dm', floor($plusHours / 3600), floor($plusHours / 60 % 60)); + + } else { + $plusHours = $timerecordingemployees[$timerecordinguser->id]['plushours_now']; + $plusHours = sprintf('%02dh:%02dm', floor($plusHours / 3600), floor($plusHours / 60 % 60)); + } ?> @@ -79,9 +95,10 @@ $type[3] = "Lehrling"; id]['startdate']) ? date("d.m.Y", $timerecordingemployees[$timerecordinguser->id]['startdate']) : "-" ?> id]['datetimetext'] : "" ?> - id]['plushours_now']/ 3600),($timerecordingemployees[$timerecordinguser->id]['plushours_now']/ 60 % 60)) ?> - id]['overtime_now']/ 3600),($timerecordingemployees[$timerecordinguser->id]['overtime_now']/ 60 % 60)) ?> - id]['holidays_now']) ? $timerecordingemployees[$timerecordinguser->id]['holidays_now'].' Tage' : '' ?> + + id]['overtime_now'] / 3600), floor($timerecordingemployees[$timerecordinguser->id]['overtime_now'] / 60 % 60)) ?> + id]['holidays_now']) ? $timerecordingemployees[$timerecordinguser->id]['holidays_now'] . ' Tage' : '' ?> id]['auto_workinghours'] == '1') ? 'Ja' : 'Nein' ?> $timerecordingemployees[$timerecordinguser->id]['id'], "userid" => $timerecordinguser->id]) ?>"> - var hidesearch = [3,4,5,6,7,9]; + var hidesearch = [3, 4, 5, 6, 7, 9]; $(document).ready(function () { diff --git a/application/Timerecording/TimerecordingController.php b/application/Timerecording/TimerecordingController.php index 248b6f1ea..0c5af6a36 100644 --- a/application/Timerecording/TimerecordingController.php +++ b/application/Timerecording/TimerecordingController.php @@ -369,7 +369,7 @@ class TimerecordingController extends mfBaseController } } - protected function updatePlushours($userid) + public function updatePlushours($userid) { $employee = TimerecordingEmployeeModel::search(['user_id' => $userid]); if ($employee) { @@ -386,7 +386,7 @@ class TimerecordingController extends mfBaseController $endtime = strtotime($endtime . " 23:59:00"); if ($plushours_timestamp > 0) { - $return = $this->getTimerecordingsApi(5, null, null, null, $plushours_timestamp, $endtime); + $return = $this->getTimerecordingsApi(5, null, null, null, $plushours_timestamp, $endtime, $userid); $diffTime = $return['is'] - $return['must']; $plushours_now = $plushours_now + $diffTime; } else { @@ -402,22 +402,25 @@ class TimerecordingController extends mfBaseController } } - protected function getTimerecordingsApi($datatype, $dataweek, $datamonth, $datayear, $startime = null, $endtime = null) + protected function getTimerecordingsApi($datatype, $dataweek, $datamonth, $datayear, $startime = null, $endtime = null, $userid = null) { $mustSeconds = 0; $isSeconds = 0; $holiDays = 0; $plusHours = 0; - + $startdate=time(); + if (!$userid) { + $userid = $this->me->id; + } $rows = []; - $employee = TimerecordingEmployeeModel::search(['user_id' => $this->me->id]); + $employee = TimerecordingEmployeeModel::search(['user_id' => $userid]); if ($employee) { $holiDays = $employee[0]->holidays_now; $plusHours = $employee[0]->plushours_now; $auto_workinghours = $employee[0]->auto_workinghours; - + $startdate = $employee[0]->startdate; } - $workinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $this->me->id]); + $workinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $userid]); $holidays = TimerecordingHolidayModel::getAll(); foreach ($workinghours as $workinghour) { @@ -440,7 +443,7 @@ class TimerecordingController extends mfBaseController $timestamp_sonntag = strtotime("{$year}-W{$kw}-7"); $firstdate = strtotime(date("Y-m-d", $timestamp_montag) . " 00:00:00"); $lastdate = strtotime(date("Y-m-d", $timestamp_sonntag) . ' 23:59:59'); - $searchArray = ['user_id' => $this->me->id, 'start' => $timestamp_montag, 'end' => $lastdate]; + $searchArray = ['user_id' => $userid, 'start' => $timestamp_montag, 'end' => $lastdate]; $daycounter = '0'; @@ -448,7 +451,7 @@ class TimerecordingController extends mfBaseController for ($i = 1; $i <= 7; $i++) { $dDate = date('Y-m-d', $timestamp); $dDay = date('w', $timestamp); - if (!$holiDay[$dDate]) { + if (!$holiDay[$dDate] && $dDate >= date('Y-m-d', $startdate)) { $mustSeconds = $mustSeconds + $workingHours[$dDay]; } @@ -459,13 +462,13 @@ class TimerecordingController extends mfBaseController $lastdate = strtotime(date("Y-m-t", $datamonth)); $daycount = date("t", $datamonth); $lastdate = strtotime(date("Y-m-d", $lastdate) . ' 23:59:59'); - $searchArray = ['user_id' => $this->me->id, 'start' => $firstdate, 'end' => $lastdate]; + $searchArray = ['user_id' => $userid, 'start' => $firstdate, 'end' => $lastdate]; $timestamp = $firstdate; for ($i = 1; $i <= $daycount; $i++) { $dDate = date('Y-m-d', $timestamp); $dDay = date('w', $timestamp); - if (!$holiDay[$dDate]) { + if (!$holiDay[$dDate] && $dDate >= date('Y-m-d', $startdate)) { $mustSeconds = $mustSeconds + $workingHours[$dDay]; } @@ -478,7 +481,7 @@ class TimerecordingController extends mfBaseController $lastdate = strtotime(date("Y-12-31 23:59:59", $datayear)); $daycount = date("t", $datamonth); $lastdate = strtotime(date("Y-m-d", $lastdate) . ' 23:59:59'); - $searchArray = ['user_id' => $this->me->id, 'start' => $firstdate, 'end' => $lastdate]; + $searchArray = ['user_id' => $userid, 'start' => $firstdate, 'end' => $lastdate]; $timestamp = $firstdate; for ($i = 1; $i <= $daycount; $i++) { @@ -498,7 +501,7 @@ class TimerecordingController extends mfBaseController $timediff = $lastdate - $firstdate; $daycount = $timediff / 86400; $daycount = round($daycount, 0, PHP_ROUND_HALF_DOWN); - $searchArray = ['user_id' => $this->me->id, 'start' => $firstdate, 'end' => $lastdate]; + $searchArray = ['user_id' => $userid, 'start' => $firstdate, 'end' => $lastdate]; $timestamp = $firstdate; for ($i = 1; $i <= $daycount; $i++) { @@ -672,9 +675,10 @@ class TimerecordingController extends mfBaseController return $response; } else { if ($plusHours < 0) { - $plusHoursMinutes = $plusHours * -1; + $plusHours = $plusHours * -1; + $plusHours = "-" . sprintf('%02dh:%02dm', floor($plusHours / 3600), floor($plusHours / 60 % 60)); } else { - $plusHoursMinutes = $plusHours; + $plusHours = sprintf('%02dh:%02dm', floor($plusHours / 3600), floor($plusHours / 60 % 60)); } $json['success'] = true; @@ -682,7 +686,7 @@ class TimerecordingController extends mfBaseController $json['time']['is'] = sprintf('%02dh:%02dm', floor($isSeconds / 3600), floor($isSeconds / 60 % 60)); $json['time']['must'] = sprintf('%02dh:%02dm', floor($mustSeconds / 3600), floor($mustSeconds / 60 % 60)); $json['time']['holidays'] = $holiDays; - $json['time']['plushours'] = sprintf('%02dh:%02dm', floor($plusHours / 3600), floor($plusHoursMinutes / 60 % 60)); + $json['time']['plushours'] = $plusHours; $json['data'] = $rows; $json['recordsFiltered'] = $responsecount; $json['recordsTotal'] = $responsecount; diff --git a/application/TimerecordingEmployeeWorkingHour/TimerecordingEmployeeWorkingHourModel.php b/application/TimerecordingEmployeeWorkingHour/TimerecordingEmployeeWorkingHourModel.php index 4ea253a79..593f2a8ad 100644 --- a/application/TimerecordingEmployeeWorkingHour/TimerecordingEmployeeWorkingHourModel.php +++ b/application/TimerecordingEmployeeWorkingHour/TimerecordingEmployeeWorkingHourModel.php @@ -103,6 +103,8 @@ class TimerecordingEmployeeWorkingHourModel $secondcounter = 0; while ($data = $db->fetch_array($res)) { + $dayHours[$data['user_id']][$data['day']][] = $data['start'] . " - " . $data['end']; + if ($olduser != $data['user_id']) { if ($counter > 0) { $secondcounter = 0; @@ -121,7 +123,6 @@ class TimerecordingEmployeeWorkingHourModel if (!$datetimetext) { $datetimetext = $daysshort[$data['day']]; } - echo $oldstart . $data['start']; if (($oldstart != $data['start'] || $oldend != $data['end']) && $oldend) { $datetimetext .= " - " . $daysshort[$oldday] . " " . $oldstart . " - " . $oldend; $datetimetext .= "
" . $daysshort[$data['day']]; @@ -139,6 +140,51 @@ class TimerecordingEmployeeWorkingHourModel $datetimetext = TimerecordingEmployeeWorkingHourModel::cleardays($datetimetext); $items[$olduser]['datetimetext'] = $datetimetext; } + foreach ($dayHours as $key => $dayHour) { + foreach ($dayHour as $key2 => $dayHour2) { + $dayhours[$key][$key2] = implode("
", $dayHour2); + } + } + foreach ($dayhours as $key => $dayhour) { + $oldday = false; + $oldstring = false; + $counter = 0; + $oldkey = false; + $oldkey2 = false; + foreach ($dayhour as $key2 => $dayhour2) { + if ($oldday != $key2) { + if ($oldstring != $dayhour2 || $key2!=$oldkey2+1) { + if ($oldkey2) { + $daysitems[$key][$counter]['end'] = $oldkey2; + $counter++; + } + $daysitems[$key][$counter]['start'] = $key2; + } + + $daysitems[$key][$counter]['string'] = $dayhour2; + } + $oldkey2 = $key2; + $oldkey = $key; + $oldstring = $dayhour2; + + } + $daysitems[$key][$counter]['end'] = $key2; + + } + + foreach ($daysitems as $key => $daysitem) { + $datetimetext = ""; + foreach ($daysitem as $key2 => $daysItem) { + if ($daysItem['start'] != $daysItem['end']) { + $datetimetext .= '
' . $daysshort[$daysItem['start']] . "-" . $daysshort[$daysItem['end']] . '
' . $daysItem['string'] . '
'; + } else { + $datetimetext .= '
' . $daysshort[$daysItem['start']] . '
' . $daysItem['string'] . '
'; + } + } + $items[$key]['datetimetext'] = $datetimetext; + } + + return $items; } @@ -153,7 +199,6 @@ class TimerecordingEmployeeWorkingHourModel public static function getFirst() { $db = FronkDB::singleton(); - $where = self::getSqlFilter($filter); $res = $db->select("TimerecordingEmployeeWorkingHour", "*", "$where "); if ($db->num_rows($res)) { diff --git a/application/TimerecordingReport/TimerecordingReportController.php b/application/TimerecordingReport/TimerecordingReportController.php index 923b37fbf..57b4b8273 100644 --- a/application/TimerecordingReport/TimerecordingReportController.php +++ b/application/TimerecordingReport/TimerecordingReportController.php @@ -331,7 +331,7 @@ class TimerecordingReportController extends mfBaseController $holiDays = $employee[0]->holidays; $plusHours = $employee[0]->plushours; $auto_workinghours = $employee[0]->auto_workinghours; - + $startdate = $employee[0]->startdate; } $workinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $r->user_id]); $holidays = TimerecordingHolidayModel::getAll(); @@ -364,7 +364,8 @@ class TimerecordingReportController extends mfBaseController for ($i = 1; $i <= 7; $i++) { $dDate = date('Y-m-d', $timestamp); $dDay = date('w', $timestamp); - if (!$holiDay[$dDate]) { + + if (!$holiDay[$dDate] && $dDate >= date('Y-m-d', $startdate)) { $mustSeconds = $mustSeconds + $workingHours[$dDay]; } @@ -381,7 +382,7 @@ class TimerecordingReportController extends mfBaseController for ($i = 1; $i <= $daycount; $i++) { $dDate = date('Y-m-d', $timestamp); $dDay = date('w', $timestamp); - if (!$holiDay[$dDate]) { + if (!$holiDay[$dDate] && $dDate >= date('Y-m-d', $startdate)) { $mustSeconds = $mustSeconds + $workingHours[$dDay]; }