Zeiterfassung update
* Autoausfüllen -> fertiggestellt * Überprüfungen Buchungsüberschneidungen ausgebaut * Abwesenheitskalender Mouseover eingebaut * Abwesenheiten ohne Ende Update -> Gesundmeldung generiert nun ein Update mit Ende auf die Abwesenheit
This commit is contained in:
@@ -37,6 +37,9 @@ class TimerecordingController extends mfBaseController
|
||||
case "getTimerecordings":
|
||||
$return = $this->getTimerecordingsApi($datatype, $dataweek, $datamonth, $datayear);
|
||||
break;
|
||||
case "fillWorkinghours":
|
||||
$return = $this->fillWorkinghours($dataweek);
|
||||
break;
|
||||
default:
|
||||
$return = false;
|
||||
}
|
||||
@@ -86,6 +89,9 @@ class TimerecordingController extends mfBaseController
|
||||
} else {
|
||||
$userid = $this->me->id;
|
||||
}
|
||||
if (!$endtime) {
|
||||
$endtime = strtotime(date("Y-m-d", $starttime) . " 23:59:00");
|
||||
}
|
||||
|
||||
$searchArray = ['user_id' => $userid, 'starttime' => $starttime, 'endtime' => $endtime];
|
||||
if ($id) {
|
||||
@@ -102,22 +108,67 @@ class TimerecordingController extends mfBaseController
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function updateOpenTimerecording()
|
||||
{
|
||||
$r = $this->request;
|
||||
$date = strtotime($r->date . " 23:59:00");
|
||||
if ($r->user_id) {
|
||||
$userid = $r->user_id;
|
||||
} else {
|
||||
$userid = $this->me->id;
|
||||
}
|
||||
$searchArray = ['user_id' => $userid, 'type' => 'opentimerecording'];
|
||||
$timerecordings = TimerecordingModel::search($searchArray);
|
||||
$timerecordingssave = new Timerecording($timerecordings[0]->id);
|
||||
|
||||
|
||||
$data = [];
|
||||
$data['end'] = $date;
|
||||
$timerecordingssave->update($data);
|
||||
$id = $timerecordingssave->save();
|
||||
if ($timerecordingssave->id) {
|
||||
if ($r->ajax == 1) {
|
||||
$message = "Buchung erfolgreich angelegt";
|
||||
$result['state'] = "success";
|
||||
$result['message'] = "$message";
|
||||
echo json_encode($result);
|
||||
die();
|
||||
}
|
||||
} else {
|
||||
if ($r->ajax == 1) {
|
||||
$message = "Buchung konnte nicht angelegt werden";
|
||||
$result['state'] = "error";
|
||||
$result['error'] = "$message";
|
||||
echo json_encode($result);
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function saveAction()
|
||||
{
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
$enddate = $r->enddate;
|
||||
if (!$enddate && $r->start && $r->end) {
|
||||
$hourday = $r->hourday;
|
||||
|
||||
if ($hourday == 4) {
|
||||
|
||||
$this->updateOpenTimerecording();
|
||||
}
|
||||
|
||||
if ($hourday == 1) {
|
||||
$starttime = strtotime($r->date . " " . $r->start . ":00");
|
||||
$endtime = strtotime($r->date . " " . $r->end . ":00");
|
||||
} elseif ($enddate) {
|
||||
} elseif ($hourday == 2) {
|
||||
$starttime = strtotime($r->date . " 00:00:00");
|
||||
$endtime = strtotime($enddate . " 23:59:00");
|
||||
} else if (!$enddate && !$r->start && !$r->end) {
|
||||
} else if ($hourday == 3) {
|
||||
$starttime = strtotime($r->date . " 00:00:00");
|
||||
$endtime = NULL;
|
||||
}
|
||||
|
||||
|
||||
$result = $this->checkTimerecording($starttime, $endtime, $id);
|
||||
if ($result['state'] == "error") {
|
||||
if ($r->ajax == 1) {
|
||||
@@ -289,6 +340,7 @@ class TimerecordingController extends mfBaseController
|
||||
$year = date('Y', $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");
|
||||
$lastdate = strtotime(date("Y-m-d", $timestamp_sonntag) . ' 23:59:59');
|
||||
$searchArray = ['user_id' => $this->me->id, 'start' => $timestamp_montag, 'end' => $lastdate];
|
||||
|
||||
@@ -367,7 +419,7 @@ class TimerecordingController extends mfBaseController
|
||||
$sum = sprintf("%02d", $hours) . ":" . sprintf("%02d", $minutes);
|
||||
$day = $daysgerm[date("w", $timerecording->start)];
|
||||
$isSeconds = $isSeconds + $seconds;
|
||||
} else if ($timerecording->timerecordingCategory->hourday == 2) {
|
||||
} else if ($timerecording->timerecordingCategory->hourday == 2 || ($timerecording->timerecordingCategory->hourday == 3 && $timerecording->end)) {
|
||||
$date = date("d.m.", $timerecording->start) . " - " . $daysgerm[date("w", $timerecording->end)] . " " . date("d.m.Y", $timerecording->end);
|
||||
$datadate = date("Y-m-d", $timerecording->start);
|
||||
$enddate = date("Y-m-d", $timerecording->end);
|
||||
@@ -380,23 +432,61 @@ class TimerecordingController extends mfBaseController
|
||||
} else {
|
||||
$endtimecalc = $timerecording->end;
|
||||
}
|
||||
if ($firstdate > $timerecording->start) {
|
||||
$starttimecalc = $firstdate;
|
||||
} else {
|
||||
$starttimecalc = $timerecording->start;
|
||||
}
|
||||
$summcounter = 0;
|
||||
for ($i = $timerecording->start; $i <= $endtimecalc; $i = $i + 86400) {
|
||||
$savecounter = 0;
|
||||
for ($i = $starttimecalc; $i <= $endtimecalc; $i = $i + 86400) {
|
||||
$holidaycounter = $workingHours[date("w", $i)];
|
||||
$isSeconds = $isSeconds + $holidaycounter;
|
||||
$summcounter = $summcounter + $holidaycounter;
|
||||
if ($savecounter == 1000) {
|
||||
echo $savecounter;
|
||||
die();
|
||||
}
|
||||
$savecounter++;
|
||||
}
|
||||
$seconds = $summcounter;
|
||||
$minutes = floor(($seconds % 3600) / 60);
|
||||
$hours = floor($seconds / 3600);
|
||||
$sum = sprintf("%02d", $hours) . ":" . sprintf("%02d", $minutes);
|
||||
|
||||
} else if ($timerecording->timerecordingCategory->hourday == 3 || $timerecording->timerecordingCategory->hourday == 4) {
|
||||
$date = date("d.m.Y", $timerecording->start);
|
||||
} else if ($timerecording->timerecordingCategory->hourday == 3 && !$timerecording->end) {
|
||||
$date = date("d.m.Y", $timerecording->start) . " - " . $daysgerm[date("w", time())] . " " . date("d.m.Y", time());;
|
||||
$datadate = date("Y-m-d", $timerecording->start);
|
||||
$start = "-";
|
||||
$end = "-";
|
||||
$day = $daysgerm[date("w", $timerecording->start)];
|
||||
if ($lastdate < $timerecording->end) {
|
||||
$endtimecalc = $lastdate;
|
||||
} else {
|
||||
$endtimecalc = $timerecording->end;
|
||||
}
|
||||
if ($firstdate > $timerecording->start) {
|
||||
$starttimecalc = $firstdate;
|
||||
} else {
|
||||
$starttimecalc = $timerecording->start;
|
||||
}
|
||||
$summcounter = 0;
|
||||
$savecounter = 0;
|
||||
for ($i = $starttimecalc; $i <= $endtimecalc; $i = $i + 86400) {
|
||||
$holidaycounter = $workingHours[date("w", $i)];
|
||||
$isSeconds = $isSeconds + $holidaycounter;
|
||||
$summcounter = $summcounter + $holidaycounter;
|
||||
if ($savecounter == 1000) {
|
||||
echo $savecounter;
|
||||
die();
|
||||
}
|
||||
$savecounter++;
|
||||
}
|
||||
$seconds = $summcounter;
|
||||
$minutes = floor(($seconds % 3600) / 60);
|
||||
$hours = floor($seconds / 3600);
|
||||
$sum = sprintf("%02d", $hours) . ":" . sprintf("%02d", $minutes);
|
||||
|
||||
}
|
||||
|
||||
if ($timerecording->timerecordingCategory->approval == 1 && $timerecording->approved == 0) {
|
||||
@@ -410,6 +500,10 @@ class TimerecordingController extends mfBaseController
|
||||
} else {
|
||||
$category = $timerecording->timerecordingCategory->name;
|
||||
}
|
||||
if ($timerecording->timerecordingCategory->hourday == 3 && !$timerecording->end) {
|
||||
$category = $category . "<span class='text-bold ml-2'>(offen)</span>";
|
||||
}
|
||||
|
||||
|
||||
if ($timerecording->completed == 0 && $timerecording->timerecordingCategory->only_admin == 0):
|
||||
if ($timerecording->approved == 0) :
|
||||
@@ -455,6 +549,74 @@ class TimerecordingController extends mfBaseController
|
||||
die();
|
||||
}
|
||||
|
||||
protected function fillWorkinghours($dataweek)
|
||||
{
|
||||
$dataweek = strtotime($dataweek);
|
||||
$employee = TimerecordingEmployeeModel::search(['user_id' => $this->me->id]);
|
||||
if ($employee) {
|
||||
$auto_workinghours = $employee[0]->auto_workinghours;
|
||||
}
|
||||
if ($auto_workinghours == 0) {
|
||||
$result['state'] = "error";
|
||||
$result['error'] = "Automatische Arbeitszeiten sind deaktiviert";
|
||||
echo json_encode($result);
|
||||
die();
|
||||
}
|
||||
|
||||
$workinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $this->me->id]);
|
||||
$holidays = TimerecordingHolidayModel::getAll();
|
||||
foreach ($workinghours as $workinghour) {
|
||||
$workingHours[$workinghour->day][] = array('start' => $workinghour->start, 'end' => $workinghour->end);
|
||||
}
|
||||
foreach ($holidays as $holiday) {
|
||||
$holiDay[date('Y-m-d', $holiday->timestamp)] = $holiday->timestamp;
|
||||
}
|
||||
|
||||
|
||||
$kw = date('W', $dataweek);
|
||||
$year = date('Y', $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");
|
||||
$lastdate = strtotime(date("Y-m-d", $timestamp_sonntag) . ' 23:59:59');
|
||||
|
||||
$searchArray = ['user_id' => $this->me->id, 'start' => $firstdate, 'end' => $lastdate];
|
||||
$timerecording = TimerecordingModel::search($searchArray);
|
||||
|
||||
|
||||
$daycounter = '0';
|
||||
|
||||
$timestamp = $timestamp_montag;
|
||||
for ($i = 1; $i <= 7; $i++) {
|
||||
$dDate = date('Y-m-d', $timestamp);
|
||||
$dDay = date('w', $timestamp);
|
||||
if (!$holiDay[$dDate]) {
|
||||
if ($workingHours[$dDay]) {
|
||||
foreach ($workingHours[$dDay] as $workingHour) {
|
||||
$starttime = strtotime($dDate . " " . $workingHour['start'] . ":00");
|
||||
$endtime = strtotime($dDate . " " . $workingHour['end'] . ":00");
|
||||
$check = $this->checkTimerecording($starttime, $endtime);
|
||||
if ($check['state'] == "success") {
|
||||
$data = [];
|
||||
$data['user_id'] = $this->me->id;
|
||||
$data['start'] = $starttime;
|
||||
$data['end'] = $endtime;
|
||||
$data['timerecordingCategory_id'] = 1;
|
||||
$data['comment'] = "Automatisch eingetragen";
|
||||
$data['businesstrip'] = 0;
|
||||
$data['businesstrip_info'] = NULL;
|
||||
$timerecordings = TimerecordingModel::create($data);
|
||||
$id = $timerecordings->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$timestamp = $timestamp + 86400;;
|
||||
}
|
||||
}
|
||||
|
||||
protected function deleteAction()
|
||||
{
|
||||
$id = $this->request->id;
|
||||
|
||||
Reference in New Issue
Block a user