943 lines
43 KiB
PHP
943 lines
43 KiB
PHP
<?php
|
|
|
|
class TimerecordingReportController extends mfBaseController
|
|
{
|
|
private $holidays;
|
|
|
|
protected function init()
|
|
{
|
|
$this->needlogin = true;
|
|
$me = new User();
|
|
$me->loadMe();
|
|
$this->me = $me;
|
|
$this->layout()->set("me", $me);
|
|
|
|
if (!$me->is(["employee"])) {
|
|
$this->redirect("Dashboard");
|
|
}
|
|
$this->holidays = TimerecordingHolidayModel::getAll();
|
|
}
|
|
|
|
protected function indexAction()
|
|
{
|
|
$this->layout()->setTemplate("TimerecordingReport/Index");
|
|
$timerecordingCategoriess = TimerecordingCategoryModel::getAll();
|
|
$this->layout()->set("timerecordingCategoriess", $timerecordingCategoriess);
|
|
$timerecordingusers = UserModel::search(['employee' => 'true']);
|
|
$this->layout()->set("timerecordingusers", $timerecordingusers);
|
|
$timerecordings = TimerecordingModel::getAll();
|
|
$this->layout()->set("timerecordings", $timerecordings);
|
|
$timerecordingCars = TimerecordingCarModel::search(['timerecording' => 1]);
|
|
$this->layout()->set("timerecordingCars", $timerecordingCars);
|
|
}
|
|
|
|
protected function apiAction()
|
|
{
|
|
$do = $this->request->do;
|
|
$datatype = $this->request->datatype;
|
|
$dataweek = $this->request->dataweek;
|
|
$datamonth = $this->request->datamonth;
|
|
$datayear = $this->request->datayear;
|
|
$data = [];
|
|
|
|
switch ($do) {
|
|
case "getTimerecordings":
|
|
$return = $this->getTimerecordingsApi($datatype, $dataweek, $datamonth, $datayear);
|
|
break;
|
|
case "getTimerecordingsTimes":
|
|
$return = $this->getTimerecordingsTimes($datatype, $dataweek, $datamonth, $datayear);
|
|
break;
|
|
default:
|
|
$return = false;
|
|
}
|
|
|
|
if (!is_array($return) || !count($return)) {
|
|
$data = ["status" => "error"];
|
|
$this->returnJson($data);
|
|
}
|
|
$data['status'] = "OK";
|
|
$data['result'] = $return;
|
|
$this->returnJson($data);
|
|
}
|
|
|
|
public function getTimerecordingsApi($datatype, $dataweek, $datamonth, $datayear)
|
|
{
|
|
$mustSeconds = 0;
|
|
$isSeconds = 0;
|
|
$holiDays = 0;
|
|
$plusHours = 0;
|
|
|
|
$rows = [];
|
|
$employee = TimerecordingEmployeeModel::getAll();
|
|
if ($employee) {
|
|
$holiDays = $employee[0]->holidays;
|
|
$plusHours = $employee[0]->plushours;
|
|
|
|
}
|
|
$workinghours = TimerecordingEmployeeWorkingHourModel::getAll();
|
|
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->user_id][$workinghour->day]) {
|
|
$workingHours[$workinghour->user_id][$workinghour->day] = $whend - $whstart;
|
|
} else {
|
|
$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;
|
|
}
|
|
|
|
if ($datatype == 1) {
|
|
$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 = ['start' => $timestamp_montag, 'end' => $lastdate];
|
|
|
|
$daycounter = '0';
|
|
|
|
$timestamp = $timestamp_montag;
|
|
for ($i = 1; $i <= 7; $i++) {
|
|
$dDate = date('Y-m-d', $timestamp);
|
|
$dDay = date('w', $timestamp);
|
|
if (!$holiDay[$dDate]) {
|
|
// $mustSeconds = $mustSeconds + $workingHours[$dDay];
|
|
}
|
|
|
|
$timestamp = $timestamp + 86400;
|
|
}
|
|
} else if ($datatype == 2) {
|
|
$firstdate = strtotime(date("Y-m-01", $datamonth));
|
|
$lastdate = strtotime(date("Y-m-t", $datamonth));
|
|
$daycount = date("t", $datamonth);
|
|
$lastdate = strtotime(date("Y-m-d", $lastdate) . ' 23:59:59');
|
|
$searchArray = ['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]) {
|
|
// $mustSeconds = $mustSeconds + $workingHours[$dDay];
|
|
}
|
|
$timestamp = $timestamp + 86400;
|
|
}
|
|
} else if ($datatype == 3) {
|
|
$firstdate = strtotime(date("Y-01-01", $datayear));
|
|
$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 = ['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]) {
|
|
//$mustSeconds = $mustSeconds + $workingHours[$dDay];
|
|
}
|
|
|
|
$timestamp = $timestamp + 86400;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
$daysgerm = array("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa");
|
|
$timerecordingcategories = TimerecordingCategoryModel::getAll();
|
|
|
|
$timerecordings = TimerecordingModel::search($searchArray);
|
|
$responsecount = count($timerecordings);
|
|
foreach ($timerecordings as $timerecording):
|
|
$hiderecording = 0;
|
|
$state = "";
|
|
$enddate = "";
|
|
$sum = "-";
|
|
$day = "";
|
|
$enddatecend = "";
|
|
$orderdate = $timerecording->start;
|
|
if ($timerecording->timerecordingCategory->hourday == 1) {
|
|
$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->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;
|
|
} else if ($timerecording->timerecordingCategory->hourday == 2 || ($timerecording->timerecordingCategory->hourday == 3 && $timerecording->end)) {
|
|
|
|
$datadate = date("Y-m-d", $timerecording->start);
|
|
$enddate = date("Y-m-d", $timerecording->end + 7200);
|
|
$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;
|
|
$sumdays = 0;
|
|
// echo $starttimecalc."<br>";
|
|
$hidedate = "<span class='d-none'>";
|
|
$hcounter = 0;
|
|
for ($i = $starttimecalc; $i <= $endtimecalc; $i = $i + 86400) {
|
|
$hidedate .= date("d.m.Y", $i) . " ";
|
|
|
|
$holidaycounter = $workingHours[$timerecording->user_id][date("w", $i)];
|
|
$daycheck = date("Y-m-d", $i);
|
|
if (!$holiDay[$daycheck]) {
|
|
if ($holidaycounter) {
|
|
$isSeconds = $isSeconds + $holidaycounter;
|
|
$summcounter = $summcounter + $holidaycounter;
|
|
$sumdays++;
|
|
}
|
|
}
|
|
if ($savecounter == 1000) {
|
|
echo $savecounter;
|
|
die();
|
|
}
|
|
$savecounter++;
|
|
$hcounter++;
|
|
}
|
|
$hidedate .= "</span>";
|
|
$date = date("d.m.", $timerecording->start) . " - " . $daysgerm[date("w", $timerecording->end)] . " " . date("d.m.Y", $timerecording->end) . $hidedate;
|
|
$seconds = $summcounter;
|
|
$minutes = floor(($seconds % 3600) / 60);
|
|
$hours = floor($seconds / 3600);
|
|
// $sum = sprintf("%02d", $hours) . ":" . sprintf("%02d", $minutes);
|
|
if ($sumdays == 1 || $sumdays == 0) {
|
|
$sum = $sumdays . " Tag";
|
|
} else if ($sumdays > 1) {
|
|
$sum = $sumdays . " Tage";
|
|
}
|
|
|
|
} else if ($timerecording->timerecordingCategory->hourday == 3 && !$timerecording->end) {
|
|
|
|
$datadate = date("Y-m-d", $timerecording->start);
|
|
$enddatetemp = date("Y-m-d", time());
|
|
$enddatetemp = strtotime($enddatetemp . " 23:59:59");
|
|
$enddate = date("Y-m-d", $enddatetemp + 7200);
|
|
$enddatecend = date("Y-m-d", $enddatetemp + 1216800);
|
|
$start = "-";
|
|
$end = "-";
|
|
$day = $daysgerm[date("w", $timerecording->start)];
|
|
|
|
if ($lastdate < time()) {
|
|
$endtimecalc = $lastdate;
|
|
} else {
|
|
$endtimecalc = time();
|
|
}
|
|
$summcounter = 0;
|
|
if ($firstdate > $timerecording->start) {
|
|
$starttimecalc = $firstdate;
|
|
} else {
|
|
$starttimecalc = $timerecording->start;
|
|
}
|
|
$summcounter = 0;
|
|
$savecounter = 0;
|
|
// echo $starttimecalc."<br>";
|
|
$hidedate = "<span class='d-none'>";
|
|
$hcounter = 0;
|
|
for ($i = $starttimecalc; $i <= $endtimecalc; $i = $i + 86400) {
|
|
$hidedate .= date("d.m.Y", $i) . " ";
|
|
$holidaycounter = $workingHours[$timerecording->user_id][date("w", $i)];
|
|
$daycheck = date("Y-m-d", $i);
|
|
if (!$holiDay[$daycheck]) {
|
|
$isSeconds = $isSeconds + $holidaycounter;
|
|
$summcounter = $summcounter + $holidaycounter;;
|
|
}
|
|
if ($savecounter == 1000) {
|
|
echo $savecounter;
|
|
die();
|
|
}
|
|
$savecounter++;
|
|
$hcounter++;
|
|
}
|
|
$hidedate .= "</span>";
|
|
$date = date("d.m", $timerecording->start) . " - " . $daysgerm[date("w", time())] . " " . date("d.m.Y", time()) . $hidedate;;
|
|
if ($timerecording->start > $lastdate) {
|
|
$hiderecording = 1;
|
|
}
|
|
$seconds = $summcounter;
|
|
$minutes = floor(($seconds % 3600) / 60);
|
|
$hours = floor($seconds / 3600);
|
|
$sum = sprintf("%02d", $hours) . ":" . sprintf("%02d", $minutes);
|
|
|
|
} else if ($timerecording->timerecordingCategory->hourday == 5) {
|
|
$date = date("d.m.Y", $timerecording->start);
|
|
$start = "-";
|
|
$end = "-";
|
|
$datadate = date("Y-m-d", $timerecording->start);
|
|
$day = $daysgerm[date("w", $timerecording->start)];
|
|
if ($timerecording->days > 0) {
|
|
if ($timerecording->days == 1) {
|
|
$sum = "+" . $timerecording->days . " Tag";
|
|
} else {
|
|
$sum = "+" . $timerecording->days . " Tage";
|
|
}
|
|
} else {
|
|
if ($timerecording->days == -1) {
|
|
$sum = $timerecording->days . " Tag";
|
|
} else {
|
|
$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;
|
|
} else if ($timerecording->timerecordingCategory->hourday == 7) {
|
|
$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->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)];
|
|
}
|
|
|
|
if ($timerecording->timerecordingCategory->approval == 1 && $timerecording->approved == 0) {
|
|
$state = '<i class="fa-regular fa-clock mr-1"></i>';
|
|
} else if ($timerecording->timerecordingCategory->approval == 1 && $timerecording->approved == 1) {
|
|
$state = '<i class="fa-regular fa-circle-check mr-1"></i>';
|
|
}
|
|
$edit = "";
|
|
if ($timerecording->timerecordingCategory->hourday == 7) {
|
|
$distance = $timerecording->mileage_end - $timerecording->mileage_start;
|
|
$category = "<span>" . $timerecording->timerecordingCategory->name . "</span><span class='text-bold ml-1'>(" . $timerecording->timerecordingCar->number_plate . " " . $distance . "KM) (Zielort: " . $timerecording->businesstrip_info . ")</span>";
|
|
} else if ($timerecording->businesstrip == 1) {
|
|
if ($timerecording->timerecordingCar) {
|
|
$distance = $timerecording->mileage_end - $timerecording->mileage_start;
|
|
$car = " (" . $timerecording->timerecordingCar->number_plate . " " . $distance . "KM)";
|
|
} else {
|
|
$car = "";
|
|
}
|
|
$category = "<span>" . $timerecording->timerecordingCategory->name . "</span><span class='text-bold ml-1'>$car (Dienstreise: " . $timerecording->businesstrip_info . ")</span>";
|
|
} else if ($timerecording->homeoffice == 1) {
|
|
$category = "<span>" . $timerecording->timerecordingCategory->name . "</span><span class='text-bold ml-1'> (Homeoffice)</span>";
|
|
} else {
|
|
$category = $timerecording->timerecordingCategory->name;
|
|
}
|
|
if ($timerecording->timerecordingCategory->hourday == 3 && !$timerecording->end) {
|
|
$category = $category . " <span class='text-bold ml-1'>(Offen)</span>";
|
|
}
|
|
|
|
|
|
if ($timerecording->completed == 0):
|
|
if ($timerecording->approved == 0) :
|
|
$edit = '<i class="far fa-edit edit-button" data-id="' . $timerecording->id . '"
|
|
data-date="' . $datadate . '"
|
|
data-category="' . $timerecording->timerecordingCategory->id . '"
|
|
data-start="' . $start . '"
|
|
data-end="' . $end . '"
|
|
data-enddate="' . $enddate . '"
|
|
data-comment="' . $timerecording->comment . '"
|
|
data-userid="' . $timerecording->user_id . '"
|
|
data-businesstrip="' . $timerecording->businesstrip . '"
|
|
data-businesstripinfo="' . $timerecording->businesstrip_info . '"
|
|
data-homeoffice="' . $timerecording->homeoffice . '"
|
|
data-days="' . $timerecording->days . '"
|
|
data-car="' . $timerecording->timerecordingCar_id . '"
|
|
data-mileagestart="' . $timerecording->mileage_start . '"
|
|
data-mileageend="' . $timerecording->mileage_end . '"
|
|
title="Bearbeiten"></i>';
|
|
else :
|
|
$edit .= '<div class="edit-placeholder"></div>';
|
|
endif;
|
|
$edit .= '<i data-id="' . $timerecording->id . '" class="fas fa-trash text-danger delete-item" ></i>';
|
|
endif;
|
|
if ($datatype == 3 && ($timerecording->timerecordingCategory->hourday == 1 || $timerecording->timerecordingCategory->hourday == 7 || $timerecording->timerecordingCategory->hourday == 5)) {
|
|
} else if ($hiderecording == 1) {
|
|
} else {
|
|
if (!$enddatecend) {
|
|
$enddatecend = $enddate;
|
|
}
|
|
|
|
$rows[] = array(
|
|
'user' => array('user' => $timerecording->user->name, 'order' => $timerecording->user->name),
|
|
'date' => array('date' => $state . $day . " " . $date, 'order' => $orderdate),
|
|
'start' => array('start' => $start, 'order' => $start),
|
|
'end' => array('end' => $end, 'order' => $end),
|
|
'sum' => array('sum' => $sum, 'order' => $sum),
|
|
'cstart' => array('cstart' => $datadate, 'order' => $datadate),
|
|
'cend' => array('cend' => $enddatecend, 'order' => $enddatecend),
|
|
'ccategory' => array('ccategory' => $timerecording->timerecordingCategory->name, 'order' => $timerecording->timerecordingCategory->name),
|
|
'category' => array('category' => $category, 'order' => $timerecording->timerecordingCategory->name),
|
|
'comment' => array('comment' => $timerecording->comment, 'order' => $timerecording->comment),
|
|
'edit' => array('edit' => $edit, 'order' => $edit),
|
|
'hourday' => array('hourday' => $timerecording->timerecordingCategory->hourday, 'order' => $timerecording->timerecordingCategory->hourday),
|
|
|
|
);
|
|
}
|
|
endforeach;
|
|
$json['success'] = true;
|
|
$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($plusHours / 60 % 60));
|
|
$json['data'] = $rows;
|
|
$json['recordsFiltered'] = $responsecount;
|
|
$json['recordsTotal'] = $responsecount;
|
|
$json = json_encode($json);
|
|
echo trim($json);
|
|
die();
|
|
}
|
|
|
|
private function checkOvertime($timerecording)
|
|
{
|
|
$start = $timerecording->start;
|
|
$end = $timerecording->end;
|
|
$O50free = 0;
|
|
$O50pfl = 0;
|
|
$O100free = 0;
|
|
$O100pfl = 0;
|
|
$O100end = strtotime(date('Y-m-d', $start) . " 06:00:00");
|
|
$O100start = strtotime(date('Y-m-d', $start) . " 22:00:00");
|
|
|
|
|
|
foreach ($this->holidays as $holiday) {
|
|
$holiDay[date('Y-m-d', $holiday->timestamp)] = $holiday->timestamp;
|
|
}
|
|
$start = $timerecording->start;
|
|
$end = $timerecording->end;
|
|
$startday = date('Y-m-d', $start);
|
|
|
|
if (date('w', $start) == 0 || $holiDay[$startday]) {
|
|
$O100free = $O100free + $timerecording->end - $timerecording->start;
|
|
} else {
|
|
if ($start < $O100end || $start > $O100start || $end < $O100end || $end > $O100start) {
|
|
$sum = $end - $start;
|
|
if ($sum >= 10800) {
|
|
if ($start < $O100end) {
|
|
$O100free = $O100free + $O100end - $start;
|
|
}
|
|
if ($end >= $O100start) {
|
|
$O100free = $O100free + $end - $O100start;
|
|
}
|
|
//sind nun Mehrstunden
|
|
// if (date('w', $start) == 6) {
|
|
// if ($sum != $O100free) {
|
|
// $O50free = $O50free + $sum - $O100free;
|
|
// }
|
|
// }
|
|
|
|
}
|
|
// else {
|
|
// if ($start < $O100end) {
|
|
// $O100pfl = $O100pfl + $O100end - $start;
|
|
// }
|
|
// if ($end >= $O100start) {
|
|
// $O100pfl = $O100pfl + $end - $O100start;
|
|
// }
|
|
// if (date('w', $start) == 6) {
|
|
// if ($sum != $O100free) {
|
|
// $O50free = $O50free + $sum - $O100free;
|
|
// }
|
|
// }
|
|
// }
|
|
} else {
|
|
// if (date('w', $start) == 6) {
|
|
// $O50free = $O50free + $end - $start;
|
|
// }
|
|
}
|
|
}
|
|
$response['O100free'] = $O100free;
|
|
$response['O100pfl'] = $O100pfl;
|
|
$response['O50free'] = $O50free;
|
|
$response['O50pfl'] = $O50pfl;
|
|
$response['sum'] = $O100free + $O100pfl + $O50free + $O50pfl;
|
|
return $response;
|
|
}
|
|
|
|
public function getTimerecordingsTimes($datatype, $dataweek, $datamonth, $datayear, $user_id = NULL, $ajax = 1)
|
|
{
|
|
$r = $this->request;
|
|
$mustSeconds = 0;
|
|
$isSeconds = 0;
|
|
$isSecondscleanarray = array();
|
|
$holiDays = 0;
|
|
$plusHours = 0;
|
|
$nlzTimes = array();
|
|
$daysum = array();
|
|
if (!$user_id) {
|
|
$user_id = $r->user_id;
|
|
}
|
|
|
|
|
|
$rows = [];
|
|
$employee = TimerecordingEmployeeModel::search(['user_id' => $user_id]);
|
|
if ($employee) {
|
|
$holiDays = $employee[0]->holidays;
|
|
$plusHours = $employee[0]->plushours;
|
|
$plusHours_now = $employee[0]->plushours_now;
|
|
$overtime_now = $employee[0]->overtime_now;
|
|
$auto_workinghours = $employee[0]->auto_workinghours;
|
|
$startdate = $employee[0]->startdate;
|
|
if ($employee[0]->enddate) {
|
|
$enddate = strtotime(date('Y-m-d', $employee[0]->enddate) . " 23:59:59");
|
|
} else {
|
|
$enddate = 2208985200;
|
|
}
|
|
$bpahours = $employee[0]->bpahours;
|
|
}
|
|
$workinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $user_id]);
|
|
|
|
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;
|
|
}
|
|
}
|
|
foreach ($this->holidays as $holiday) {
|
|
$holiDay[date('Y-m-d', $holiday->timestamp)] = $holiday->timestamp;
|
|
}
|
|
|
|
if ($datatype == 1) {
|
|
$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' => $user_id, 'start' => $timestamp_montag, 'end' => $lastdate];
|
|
|
|
$daycounter = '0';
|
|
|
|
$timestamp = $timestamp_montag;
|
|
for ($i = 1; $i <= 7; $i++) {
|
|
$dDate = date('Y-m-d', $timestamp);
|
|
$dDay = date('w', $timestamp);
|
|
|
|
if (!$holiDay[$dDate] && $dDate >= date('Y-m-d', $startdate) && $dDate <= date('Y-m-d', $enddate)) {
|
|
$mustSeconds = $mustSeconds + $workingHours[$dDay];
|
|
}
|
|
|
|
$timestamp = $timestamp + 86400;
|
|
}
|
|
} else if ($datatype == 2) {
|
|
$firstdate = strtotime(date("Y-m-01", $datamonth));
|
|
$lastdate = strtotime(date("Y-m-t", $datamonth));
|
|
$daycount = date("t", $datamonth);
|
|
$lastdate = strtotime(date("Y-m-d", $lastdate) . ' 23:59:59');
|
|
//Lastdate staticmust deleted
|
|
// $lastdate = strtotime("2024-03-22 23:59:59");
|
|
// $daycount=22;
|
|
|
|
$searchArray = ['user_id' => $user_id, '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] && $dDate >= date('Y-m-d', $startdate) && $dDate <= date('Y-m-d', $enddate)) {
|
|
$mustSeconds = $mustSeconds + $workingHours[$dDay];
|
|
}
|
|
|
|
$timestamp = $timestamp + 86400;
|
|
}
|
|
|
|
|
|
} else if ($datatype == 3) {
|
|
$firstdate = strtotime(date("Y-01-01", $datayear));
|
|
$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' => $user_id, '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]) {
|
|
$mustSeconds = $mustSeconds + $workingHours[$dDay];
|
|
}
|
|
|
|
$timestamp = $timestamp + 86400;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
$daysgerm = array("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa");
|
|
$timerecordingcategories = TimerecordingCategoryModel::getAll();
|
|
|
|
$timerecordings = TimerecordingModel::search($searchArray);
|
|
|
|
$responsecount = count($timerecordings);
|
|
$oldday = "";
|
|
$homeoffice = false;
|
|
$homeofficesum = 0;
|
|
$dietsum = 0;
|
|
$diet = 0;
|
|
$dietbase = TimerecordingBillingModel::$dieatBase;
|
|
$O100free = 0;
|
|
$O100pfl = 0;
|
|
$O50free = 0;
|
|
$O50pfl = 0;
|
|
$Osum = 0;
|
|
foreach ($timerecordings as $timerecording):
|
|
|
|
$state = "";
|
|
$enddate = "";
|
|
$sum = "-";
|
|
$day = "";
|
|
$orderdate = $timerecording->start;
|
|
if ($oldday != date('Y-m-d', $timerecording->start)) {
|
|
|
|
if ($homeoffice == 1) {
|
|
$homeofficesum++;
|
|
$homeoffice = false;
|
|
}
|
|
$homeoffice = false;
|
|
if ($diet > 10800) {
|
|
if ($diet >= 43200) {
|
|
$diet = 43200;
|
|
}
|
|
$calcdiet = $dietbase / 12;
|
|
$calcdiet = ($diet / 3600) * $calcdiet;
|
|
$dietsum = $dietsum + $calcdiet;
|
|
}
|
|
$diet = 0;
|
|
|
|
}
|
|
|
|
if ($timerecording->homeoffice == 1 && (!$homeoffice || $homeoffice == 1)) {
|
|
$homeoffice = 1;
|
|
} else if ($timerecording->timerecordingCategory_id != '9') { //Speziallösung für Arztbesuch (zusätzlich Homeoffice erlaubt)
|
|
$homeoffice = 'NOK';
|
|
}
|
|
|
|
if ($timerecording->businesstrip == 1 && $timerecording->timerecordingCategory->hourday == 1) {
|
|
$diet = $diet + $timerecording->end - $timerecording->start;
|
|
}
|
|
|
|
if ($timerecording->timerecordingCategory->hourday == 1) {
|
|
|
|
$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->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 ($isSecondscleanarray[$timerecording->timerecordingCategory->short]) {
|
|
$isSecondscleanarray[$timerecording->timerecordingCategory->short] = $isSecondscleanarray[$timerecording->timerecordingCategory->short] + $seconds;
|
|
} else {
|
|
$isSecondscleanarray[$timerecording->timerecordingCategory->short] = $seconds;
|
|
}
|
|
|
|
if ($timerecording->timerecordingCategory->short != "1000,1200,1400") {
|
|
if (!$daysum[$timerecording->timerecordingCategory->name]) {
|
|
$daysum[$timerecording->timerecordingCategory->name] = $seconds;
|
|
} else {
|
|
$daysum[$timerecording->timerecordingCategory->name] = $daysum[$timerecording->timerecordingCategory->name] + $seconds;
|
|
}
|
|
|
|
$nlzTimes[$timerecording->id]['start'] = date("d.m.Y", $timerecording->start);
|
|
$nlzTimes[$timerecording->id]['end'] = date("d.m.Y", $timerecording->end);
|
|
$nlzTimes[$timerecording->id]['minutes'] = $seconds / 60;
|
|
$nlzTimes[$timerecording->id]['unpaid'] = $timerecording->timerecordingCategory->unpaid;
|
|
$nlzTimes[$timerecording->id]['category'] = $timerecording->timerecordingCategory->name;
|
|
$nlzTimes[$timerecording->id]['categoryshort'] = $timerecording->timerecordingCategory->short;
|
|
} else {
|
|
$overtimes = $this->checkOvertime($timerecording);
|
|
$isSecondscleanarray[$timerecording->timerecordingCategory->short] = $isSecondscleanarray[$timerecording->timerecordingCategory->short] - $overtimes['sum'];
|
|
$isSeconds = $isSeconds - $overtimes['sum'];
|
|
$O100pfl = $O100pfl + $overtimes['O100pfl'];
|
|
$O100free = $O100free + $overtimes['O100free'];
|
|
$O50free = $O50free + $overtimes['O50free'];
|
|
$O50pfl = $O50pfl + $overtimes['O50pfl'];
|
|
$Osum = $Osum + $overtimes['sum'];
|
|
}
|
|
} 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);
|
|
$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;
|
|
$sumdays = 0;
|
|
|
|
for ($i = $starttimecalc; $i <= $endtimecalc; $i = $i + 86400) {
|
|
$holidaycounter = $workingHours[date("w", $i)];
|
|
$daycheck = date("Y-m-d", $i);
|
|
if (!$holiDay[$daycheck]) {
|
|
if ($holidaycounter) {
|
|
$isSeconds = $isSeconds + $holidaycounter;
|
|
$summcounter = $summcounter + $holidaycounter;
|
|
$sumdays++;
|
|
}
|
|
}
|
|
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 ($sumdays == 1 || $sumdays == 0) {
|
|
$sum = $sumdays . " Tag";
|
|
} else if ($sumdays > 1) {
|
|
$sum = $sumdays . " Tage";
|
|
}
|
|
|
|
if (!$daysum[$timerecording->timerecordingCategory->name]) {
|
|
$daysum[$timerecording->timerecordingCategory->name] = $sumdays;
|
|
} else {
|
|
$daysum[$timerecording->timerecordingCategory->name] = $daysum[$timerecording->timerecordingCategory->name] + $sumdays;
|
|
}
|
|
$nlzTimes[$timerecording->id]['start'] = date("d.m.Y", $timerecording->start);
|
|
$nlzTimes[$timerecording->id]['end'] = date("d.m.Y", $timerecording->end);
|
|
$nlzTimes[$timerecording->id]['days'] = $sumdays;
|
|
$nlzTimes[$timerecording->id]['unpaid'] = $timerecording->timerecordingCategory->unpaid;
|
|
$nlzTimes[$timerecording->id]['category'] = $timerecording->timerecordingCategory->name;
|
|
$nlzTimes[$timerecording->id]['categoryshort'] = $timerecording->timerecordingCategory->short;
|
|
|
|
} 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);
|
|
|
|
} else if ($timerecording->timerecordingCategory->hourday == 5) {
|
|
$date = date("d.m.Y", $timerecording->start);
|
|
$datadate = date("Y-m-d", $timerecording->start);
|
|
$start = "-";
|
|
$end = "-";
|
|
$day = $daysgerm[date("w", $timerecording->start)];
|
|
$sum = $timerecording->days . " Tage";
|
|
if (!$daysum[$timerecording->timerecordingCategory->name]) {
|
|
$daysum[$timerecording->timerecordingCategory->name] = $timerecording->days;
|
|
} else {
|
|
$daysum[$timerecording->timerecordingCategory->name] = $daysum[$timerecording->timerecordingCategory->name] + $timerecording->days;
|
|
}
|
|
$nlzTimes[$timerecording->id]['start'] = date("d.m.Y", $timerecording->start);
|
|
$nlzTimes[$timerecording->id]['end'] = date("d.m.Y", $timerecording->end);
|
|
$nlzTimes[$timerecording->id]['days'] = $sumdays;
|
|
$nlzTimes[$timerecording->id]['unpaid'] = $timerecording->timerecordingCategory->unpaid;
|
|
$nlzTimes[$timerecording->id]['category'] = $timerecording->timerecordingCategory->name;
|
|
$nlzTimes[$timerecording->id]['categoryshort'] = '99';
|
|
} 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) {
|
|
$state = '<i class="fa-regular fa-clock mr-1"></i>';
|
|
} else if ($timerecording->timerecordingCategory->approval == 1 && $timerecording->approved == 1) {
|
|
$state = '<i class="fa-regular fa-circle-check mr-1"></i>';
|
|
}
|
|
$edit = "";
|
|
if ($timerecording->businesstrip == 1) {
|
|
$category = "<span>" . $timerecording->timerecordingCategory->name . "</span><span class='text-bold ml-2'> (Dienstreise: " . $timerecording->businesstrip_info . ")</span>";
|
|
} 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) :
|
|
$edit = '<i class="far fa-edit edit-button" data-id="' . $timerecording->id . '"
|
|
data-date="' . $datadate . '"
|
|
data-category="' . $timerecording->timerecordingCategory->id . '"
|
|
data-start="' . $start . '"
|
|
data-end="' . $end . '"
|
|
data-enddate="' . $enddate . '"
|
|
data-comment="' . $timerecording->comment . '"
|
|
data-businesstrip="' . $timerecording->businesstrip . '"
|
|
data-businesstripinfo="' . $timerecording->businesstrip_info . '"
|
|
title="Bearbeiten"></i>';
|
|
else :
|
|
$edit .= '<div class="edit-placeholder"></div>';
|
|
endif;
|
|
$edit .= '<i data-id="' . $timerecording->id . '" class="fas fa-trash text-danger delete-item" ></i>';
|
|
endif;
|
|
if ($datatype == 3 && $timerecording->timerecordingCategory->hourday == 1) {
|
|
} else {
|
|
|
|
}
|
|
$oldday = date('Y-m-d', $timerecording->start);
|
|
endforeach;
|
|
if ($homeoffice == 1) {
|
|
$homeofficesum++;
|
|
}
|
|
if ($diet > 10800) {
|
|
if ($diet >= 43200) {
|
|
$diet = 43200;
|
|
}
|
|
$calcdiet = $dietbase / 12;
|
|
$calcdiet = ($diet / 3600) * $calcdiet;
|
|
$dietsum = $dietsum + $calcdiet;
|
|
}
|
|
|
|
$summseconds = $isSeconds - $mustSeconds;
|
|
$isorder = $isSeconds;
|
|
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));
|
|
}
|
|
$summsecondsorder = $summseconds;
|
|
if ($summseconds < 0) {
|
|
$summseconds = $summseconds * -1;
|
|
$summseconds = "-" . sprintf('%02dh:%02dm', floor($summseconds / 3600), floor($summseconds / 60 % 60));
|
|
} else {
|
|
$summseconds = sprintf('%02dh:%02dm', floor($summseconds / 3600), floor($summseconds / 60 % 60));
|
|
}
|
|
$plusHours_noworder = $plusHours_now;
|
|
if ($plusHours_now < 0) {
|
|
$plusHours_now = $plusHours_now * -1;
|
|
$plusHours_now = "-" . sprintf('%02dh:%02dm', floor($plusHours_now / 3600), floor($plusHours_now / 60 % 60));
|
|
} else {
|
|
$plusHours_now = sprintf('%02dh:%02dm', floor($plusHours_now / 3600), floor($plusHours_now / 60 % 60));
|
|
}
|
|
|
|
$json['success'] = true;
|
|
$json['time']['auto_workinghours'] = $auto_workinghours;
|
|
$json['time']['is'] = $isSeconds;
|
|
$json['time']['isorder'] = $isorder;
|
|
$json['time']['isclean'] = $isSecondscleanarray;
|
|
$json['time']['must'] = sprintf('%02dh:%02dm', floor($mustSeconds / 3600), floor($mustSeconds / 60 % 60));
|
|
$json['time']['mustorder'] = $mustSeconds;
|
|
$json['time']['holidays'] = $holiDays;
|
|
$json['time']['plushours'] = sprintf('%02dh:%02dm', floor($plusHours / 3600), floor($plusHours / 60 % 60));
|
|
$json['time']['plushours_now'] = $plusHours_now;
|
|
$json['time']['plushours_noworder'] = $plusHours_noworder;
|
|
$json['time']['bpahours'] = sprintf('%02dh:%02dm', floor($bpahours / 3600), floor($bpahours / 60 % 60));
|
|
|
|
$json['time']['overtime_now'] = sprintf('%02dh:%02dm', floor($overtime_now / 3600), floor($overtime_now / 60 % 60));
|
|
$json['time']['overtime_noworder'] = $overtime_now;
|
|
$json['time']['homeoffice'] = $homeofficesum;
|
|
$json['time']['summseconds'] = $summseconds;
|
|
$json['time']['summsecondsorder'] = $summsecondsorder;
|
|
$json['time']['nlztimes'] = $nlzTimes;
|
|
$json['time']['diet'] = $dietsum;
|
|
$json['time']['daysum'] = $daysum;
|
|
$json['recordsFiltered'] = $responsecount;
|
|
$json['recordsTotal'] = $responsecount;
|
|
$json['time']['overtimes'] = ['O100free' => $O100free, 'O100pfl' => $O100pfl, 'O50free' => $O50free, 'O50pfl' => $O50pfl, 'Osum' => $Osum];
|
|
|
|
if ($ajax == 1) {
|
|
$json = json_encode($json);
|
|
echo trim($json);
|
|
die();
|
|
} else {
|
|
return $json;
|
|
}
|
|
}
|
|
|
|
protected function addAction()
|
|
{
|
|
|
|
|
|
}
|
|
|
|
protected function editAction()
|
|
{
|
|
|
|
}
|
|
|
|
protected function saveAction()
|
|
{
|
|
}
|
|
|
|
|
|
protected function deleteAction()
|
|
{
|
|
|
|
}
|
|
|
|
}
|