Zeiterfassungs Update
* Neuer Buchungszeitraum bei den Buchungskategorien ZA Uhrzeit (von/bis) * Überprüfungen/Berechungen/Errorhandling ZAs * Anpassungen Freigaben nun mit Standartfilter Offen
This commit is contained in:
@@ -33,6 +33,7 @@ class TimerecordingController extends mfBaseController
|
||||
$dataweek = $this->request->dataweek;
|
||||
$datamonth = $this->request->datamonth;
|
||||
$datayear = $this->request->datayear;
|
||||
$ajax = $this->request->ajax;
|
||||
|
||||
$data = [];
|
||||
|
||||
@@ -43,10 +44,13 @@ class TimerecordingController extends mfBaseController
|
||||
case "fillWorkinghours":
|
||||
$return = $this->fillWorkinghours($dataweek);
|
||||
break;
|
||||
case "checkWorkinghours":
|
||||
$return = $this->checkWorkingHours($ajax);
|
||||
break;
|
||||
default:
|
||||
$return = false;
|
||||
}
|
||||
|
||||
echo $do;
|
||||
if (!is_array($return) || !count($return)) {
|
||||
$data = ["status" => "error"];
|
||||
$this->returnJson($data);
|
||||
@@ -148,6 +152,108 @@ class TimerecordingController extends mfBaseController
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkWorkingHours($ajax = 0)
|
||||
{
|
||||
|
||||
$r = $this->request;
|
||||
|
||||
$starttime = strtotime($r->date . " " . $r->start . ":00");
|
||||
$endtime = strtotime($r->date . " " . $r->end . ":00");
|
||||
$date = $r->date;
|
||||
|
||||
if ($r->user_id) {
|
||||
$userid = $r->user_id;
|
||||
} else {
|
||||
$userid = $this->me->id;
|
||||
}
|
||||
|
||||
$workinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $userid]);
|
||||
$realHolidays = TimerecordingHolidayModel::getAll();
|
||||
foreach ($realHolidays as $realHoliday) {
|
||||
$realholiDay[date('Y-m-d', $realHoliday->timestamp)] = $realHoliday->timestamp;
|
||||
}
|
||||
if ($realholiDay[$date]) {
|
||||
$result['state'] = "error";
|
||||
$result['error'] = "Kein Zeitausgleich an einem Feiertag möglich";
|
||||
echo json_encode($result);
|
||||
die();
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (!$workingHours[date("w", $starttime)]) {
|
||||
$result['state'] = "error";
|
||||
$result['error'] = "Kein Zeitausgleich außerhalb der Arbeitszeiten möglich";
|
||||
echo json_encode($result);
|
||||
die();
|
||||
}
|
||||
|
||||
|
||||
$maxTime = $workingHours[date("w", $starttime)];
|
||||
$isTime = $endtime - $starttime;
|
||||
$cleanTime = $isTime;
|
||||
if ($maxTime < $isTime) {
|
||||
$result['state'] = "error";
|
||||
$result['error'] = "Zeitausgleich kann maximal " . sprintf('%02dh:%02dm', floor($maxTime / 3600), floor($maxTime / 60 % 60)) . " an diesem Tag betragen.";
|
||||
echo json_encode($result);
|
||||
die();
|
||||
}
|
||||
$employee = TimerecordingEmployeeModel::search(['user_id' => $userid]);
|
||||
|
||||
$plushours = $employee[0]->plushours_now * 1.25;
|
||||
$overtime = $employee[0]->overtime * 1.5;
|
||||
$overtimesum = $plushours + $overtime;
|
||||
if ($overtimesum < $isTime) {
|
||||
if ($overtimesum < 0) {
|
||||
$overtimesum = 0;
|
||||
}
|
||||
|
||||
$result['state'] = "error";
|
||||
$result['error'] = "Maximal verfügbarer ZA: " . sprintf('%02dh:%02dm', floor($overtimesum / 3600), floor($overtimesum / 60 % 60)) . ".";
|
||||
echo json_encode($result);
|
||||
die();
|
||||
}
|
||||
if ($plushours >= $isTime) {
|
||||
$isTime = $isTime * 0.8;
|
||||
$return['hours'] = $isTime;
|
||||
} elseif ($plushours <= 0) {
|
||||
$isTime = $isTime * 0.66666666666666666666666666666667;
|
||||
$return ['hours_overtime'] = $isTime;
|
||||
} else {
|
||||
$isTime25 = $plushours;
|
||||
$isTime50 = $isTime - $plushours;
|
||||
$isTime25 = $isTime25 * 0.8;
|
||||
$isTime50 = $isTime50 * 0.66666666666666666666666666666667;
|
||||
$isTime = $isTime25 + $isTime50;
|
||||
$return['hours'] = $isTime25;
|
||||
$return['hours_overtime'] = $isTime50;
|
||||
}
|
||||
if ($ajax == 1) {
|
||||
if ($r->ajax == 1) {
|
||||
if ($isTime<0) {
|
||||
$isTime = 0;
|
||||
}
|
||||
if ($cleanTime<0) {
|
||||
$cleanTime = 0;
|
||||
}
|
||||
$result['state'] = "success";
|
||||
$result['message'] = "<span class='text-bold'>Abzug:</span> " . sprintf('%02dh:%02dm', floor($isTime / 3600), floor($isTime / 60 % 60)) . " <span class='text-bold ml-1'>Zeitwert:</span> " . sprintf('%02dh:%02dm', floor($cleanTime / 3600), floor($cleanTime / 60 % 60));
|
||||
echo json_encode($result);
|
||||
die();
|
||||
}
|
||||
} else {
|
||||
return $return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function saveAction()
|
||||
{
|
||||
$r = $this->request;
|
||||
@@ -159,10 +265,13 @@ class TimerecordingController extends mfBaseController
|
||||
|
||||
$this->updateOpenTimerecording();
|
||||
}
|
||||
|
||||
if ($hourday == 1) {
|
||||
$data = [];
|
||||
if ($hourday == 1 || $hourday == 6) {
|
||||
$starttime = strtotime($r->date . " " . $r->start . ":00");
|
||||
$endtime = strtotime($r->date . " " . $r->end . ":00");
|
||||
if ($hourday == 6) {
|
||||
$data = $this->checkWorkingHours();
|
||||
}
|
||||
} elseif ($hourday == 2) {
|
||||
$starttime = strtotime($r->date . " 00:00:00");
|
||||
$endtime = strtotime($enddate . " 23:59:00");
|
||||
@@ -198,7 +307,7 @@ class TimerecordingController extends mfBaseController
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
if ($r->user_id) {
|
||||
$data['user_id'] = $r->user_id;
|
||||
} else {
|
||||
@@ -225,7 +334,7 @@ class TimerecordingController extends mfBaseController
|
||||
}
|
||||
if ($r->businesstrip == 1 && !$r->businesstrip_info) {
|
||||
$result['state'] = "error";
|
||||
$result['error'] = "Geschäftsreiseinformationen darf nicht leer sein";
|
||||
$result['error'] = "Dienstreiseort darf nicht leer sein";
|
||||
echo json_encode($result);
|
||||
die();
|
||||
}
|
||||
@@ -307,6 +416,8 @@ class TimerecordingController extends mfBaseController
|
||||
$body .= 'von: ' . date("d.m.Y H:i", $data['start']) . ' bis: ' . date("H:i", $data['end']);
|
||||
} else if ($timerecordingCategoriess[0]->hourday == "2") {
|
||||
$body .= 'von: ' . date("d.m.Y", $data['start']) . ' bis: ' . date("d.m.Y", $data['end']);
|
||||
} else if ($timerecordingCategoriess[0]->hourday == "6") {
|
||||
$body .= 'von: ' . date("d.m.Y H:i", $data['start']) . ' bis: ' . date("H:i", $data['end']);
|
||||
}
|
||||
$email = new Emailnotification();
|
||||
$email->setSubject('Antrag für ' . $timerecordingCategoriess[0]->name . ' erstellt');
|
||||
@@ -415,9 +526,18 @@ class TimerecordingController extends mfBaseController
|
||||
$plushours = $employee->plushours;
|
||||
$plushours_now = $employee->plushours_now;
|
||||
$plushours_timestamp = $employee->plushours_timestamp;
|
||||
$overtime = $employee->overtime;
|
||||
$overtime_now = $employee->overtime_now;
|
||||
$overtime_timestamp = $employee->overtime_timestamp;
|
||||
|
||||
if (!$plushours_timestamp) {
|
||||
$plushours_timestamp = $employee->startdate;
|
||||
$plushours_now = $plushours;
|
||||
|
||||
}
|
||||
if (!$overtime_timestamp) {
|
||||
$overtime_timestamp = $employee->startdate;
|
||||
$overtime_now = $overtime;
|
||||
}
|
||||
$endtime = time() - 86400;
|
||||
$endtime = date("Y-m-d", $endtime);
|
||||
@@ -430,10 +550,27 @@ class TimerecordingController extends mfBaseController
|
||||
} else {
|
||||
$diffTime = 0;
|
||||
}
|
||||
if ($employee->plushours_now != $diffTime) {
|
||||
$minushours = 0;
|
||||
$minushoursovertime = 0;
|
||||
$timerecordings = TimerecordingModel::search(['user_id' => $userid, 'start' => $plushours_timestamp, 'hours' => 1]);
|
||||
foreach ($timerecordings as $timerecording) {
|
||||
if ($timerecording->hours) {
|
||||
$timediff = $timerecording->hours;
|
||||
$minushours = $minushours + $timediff;
|
||||
}
|
||||
if ($timerecording->hours_overtime) {
|
||||
$timediffovertime = $timerecording->hours_overtime;
|
||||
$minushoursovertime = $minushoursovertime + $timediffovertime;
|
||||
}
|
||||
}
|
||||
$plushours_now = $plushours_now - $minushours;
|
||||
$diffTime = $diffTime - $minushours;
|
||||
$overtime_now = $overtime_now - $minushoursovertime;
|
||||
if ($employee->plushours_now != $plushours_now || $employee->overtime_now != $overtime_now) {
|
||||
$employeeupdate = new TimerecordingEmployee($employee->id);
|
||||
$data = [];
|
||||
$data['plushours_now'] = $plushours_now;
|
||||
$data['overtime_now'] = $overtime_now;
|
||||
$employeeupdate->update($data);
|
||||
$employeeupdate->save();
|
||||
}
|
||||
@@ -457,7 +594,7 @@ class TimerecordingController extends mfBaseController
|
||||
$plusHours = $employee[0]->plushours_now;
|
||||
$auto_workinghours = $employee[0]->auto_workinghours;
|
||||
$startdate = $employee[0]->startdate;
|
||||
$overtime = $employee[0]->overtime;
|
||||
$overtime = $employee[0]->overtime_now;
|
||||
}
|
||||
$workinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $userid]);
|
||||
$holidays = TimerecordingHolidayModel::getAll();
|
||||
@@ -680,6 +817,18 @@ class TimerecordingController extends mfBaseController
|
||||
$sum = $timerecording->days . " Tage";
|
||||
}
|
||||
}
|
||||
} else if ($timerecording->timerecordingCategory->hourday == 6) {
|
||||
$date = date("d.m.Y", $timerecording->start);
|
||||
$datadate = date("Y-m-d", $timerecording->start);
|
||||
$start = date("H:i", $timerecording->start);
|
||||
$end = date("H:i", $timerecording->end);
|
||||
// $seconds = $timerecording->hours;
|
||||
$seconds = $timerecording->end - $timerecording->start;
|
||||
$minutes = floor(($seconds % 3600) / 60);
|
||||
$hours = floor($seconds / 3600);
|
||||
$sum = "-" . sprintf("%02d", $hours) . ":" . sprintf("%02d", $minutes);
|
||||
$day = $daysgerm[date("w", $timerecording->start)];
|
||||
$isSeconds = $isSeconds + $seconds;
|
||||
}
|
||||
|
||||
if ($timerecording->timerecordingCategory->approval == 1 && $timerecording->approved == 0) {
|
||||
@@ -743,10 +892,17 @@ class TimerecordingController extends mfBaseController
|
||||
} else {
|
||||
$plusHours = sprintf('%02dh:%02dm', floor($plusHours / 3600), floor($plusHours / 60 % 60));
|
||||
}
|
||||
if ($isSeconds < 0) {
|
||||
$isSeconds = $isSeconds * -1;
|
||||
$isSeconds = "-" . sprintf('%02dh:%02dm', floor($isSeconds / 3600), floor($isSeconds / 60 % 60));
|
||||
} else {
|
||||
$isSeconds = sprintf('%02dh:%02dm', floor($isSeconds / 3600), floor($isSeconds / 60 % 60));
|
||||
}
|
||||
|
||||
|
||||
$json['success'] = true;
|
||||
$json['time']['auto_workinghours'] = $auto_workinghours;
|
||||
$json['time']['is'] = sprintf('%02dh:%02dm', floor($isSeconds / 3600), floor($isSeconds / 60 % 60));
|
||||
$json['time']['is'] = $isSeconds;
|
||||
$json['time']['must'] = sprintf('%02dh:%02dm', floor($mustSeconds / 3600), floor($mustSeconds / 60 % 60));
|
||||
$json['time']['holidays'] = $holiDays;
|
||||
$json['time']['plushours'] = $plusHours;
|
||||
|
||||
Reference in New Issue
Block a user