Zeiterfassung Anpassungen
This commit is contained in:
@@ -18,13 +18,38 @@ class TimerecordingController extends mfBaseController
|
||||
|
||||
protected function indexAction()
|
||||
{
|
||||
$this->layout()->setTemplate("Timerecording/Index");
|
||||
$timerecordingCategoriess = TimerecordingCategoryModel::getAll();
|
||||
$this->layout()->set("timerecordingCategoriess", $timerecordingCategoriess);
|
||||
$timerecordings = TimerecordingModel::search(['user_id' => $this->me->id]);
|
||||
$this->layout()->set("timerecordings", $timerecordings);
|
||||
$this->layout()->setTemplate("Timerecording/Index");
|
||||
}
|
||||
|
||||
protected function apiAction()
|
||||
{
|
||||
$do = $this->request->do;
|
||||
$datatype = $this->request->datatype;
|
||||
$dataweek = $this->request->dataweek;
|
||||
$datamonth = $this->request->datamonth;
|
||||
|
||||
$data = [];
|
||||
|
||||
switch ($do) {
|
||||
case "getTimerecordings":
|
||||
$return = $this->getTimerecordingsApi($datatype, $dataweek, $datamonth);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
protected function addAction()
|
||||
{
|
||||
$timerecordingCategoriess = TimerecordingCategoryModel::getAll();
|
||||
@@ -52,6 +77,22 @@ class TimerecordingController extends mfBaseController
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
protected function checkTimerecording($starttime, $endtime, $id = NULL)
|
||||
{
|
||||
$searchArray = ['user_id' => $this->me->id, 'starttime' => $starttime, 'endtime' => $endtime];
|
||||
if ($id) {
|
||||
$searchArray['id'] = $id;
|
||||
}
|
||||
$timerecordings = TimerecordingModel::search($searchArray);
|
||||
if ($timerecordings) {
|
||||
$result['state'] = "error";
|
||||
$result['error'] = "Zeitüberschneidung mit anderer Buchung";
|
||||
} else {
|
||||
$result['state'] = "success";
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function saveAction()
|
||||
{
|
||||
$r = $this->request;
|
||||
@@ -68,6 +109,17 @@ class TimerecordingController extends mfBaseController
|
||||
$endtime = NULL;
|
||||
}
|
||||
|
||||
$result = $this->checkTimerecording($starttime, $endtime, $id);
|
||||
if ($result['state'] == "error") {
|
||||
if ($r->ajax == 1) {
|
||||
echo json_encode($result);
|
||||
die();
|
||||
}
|
||||
$this->layout()->setFlash($result['error'], "error");
|
||||
$this->redirect("Timerecording");
|
||||
|
||||
}
|
||||
|
||||
if (is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$timerecordings = new Timerecording($id);
|
||||
@@ -110,25 +162,204 @@ class TimerecordingController extends mfBaseController
|
||||
|
||||
} else {
|
||||
$timerecordings = TimerecordingModel::create($data);
|
||||
|
||||
}
|
||||
// var_dump($filestore);
|
||||
// exit;
|
||||
$id = $timerecordings->save();
|
||||
|
||||
if (!$id) {
|
||||
$this->layout()->setFlash("Buchung konnte nicht angelegt werden", "error");
|
||||
$message = "Buchung konnte nicht angelegt werden";
|
||||
if ($r->ajax == 1) {
|
||||
$result['state'] = "error";
|
||||
$result['error'] = $message;
|
||||
echo json_encode($result);
|
||||
die();
|
||||
}
|
||||
$this->layout()->setFlash($message, "error");
|
||||
$this->redirect("Timerecording");
|
||||
|
||||
}
|
||||
if ($id) {
|
||||
$timerecordingCategoriess = TimerecordingCategoryModel::search(['id' => $data['timerecordingCategory_id']]);
|
||||
if ($timerecordingCategoriess[0]->approval == "1") {
|
||||
$body = 'Beantrag von: ' . $this->me->name . '
|
||||
';
|
||||
$body .= 'Buchungsart: ' . $timerecordingCategoriess[0]->name . '
|
||||
';
|
||||
if ($timerecordingCategoriess[0]->hourday == "1") {
|
||||
$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']);
|
||||
}
|
||||
$email = new Emailnotification();
|
||||
$email->setSubject('Antrag für ' . $timerecordingCategoriess[0]->name . ' erstellt');
|
||||
$email->setBody($body);
|
||||
$email->setFrom('zeiterfassung@xinon.at', 'Xinon Zeiterfassung');
|
||||
$email->setTo('daniel.spitzer@inode.at');
|
||||
$email->send();
|
||||
}
|
||||
}
|
||||
|
||||
if ($mode == "edit") {
|
||||
$this->layout()->setFlash("Buchung erfolgreich geändert", "success");
|
||||
$message = "Buchung erfolgreich geändert";
|
||||
} else if ($mode = "add") {
|
||||
$this->layout()->setFlash("Buchung erfolgreich angelegt", "success");
|
||||
$message = "Buchung erfolgreich angelegt";
|
||||
}
|
||||
if ($r->ajax == 1) {
|
||||
$result['state'] = "success";
|
||||
$result['message'] = "$message";
|
||||
echo json_encode($result);
|
||||
die();
|
||||
}
|
||||
$this->layout()->setFlash($message, "success");
|
||||
$this->redirect("Timerecording");
|
||||
}
|
||||
|
||||
|
||||
protected function getTimerecordingsApi($datatype, $dataweek, $datamonth)
|
||||
{
|
||||
$mustSeconds = 0;
|
||||
$isSeconds=0;
|
||||
$rows = [];
|
||||
$workinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $this->me->id]);
|
||||
$holidays= TimerecordingHolidayModel::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->day]) {
|
||||
$workingHours[$workinghour->day] = $whend - $whstart;
|
||||
} else {
|
||||
$workingHours[$workinghour->day] = $workingHours[$workinghour->day] + $whend - $whstart;
|
||||
}
|
||||
}
|
||||
foreach ($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");
|
||||
$timestamp_sonntag = strtotime(date("Y-m-d", $timestamp_sonntag) . ' 23:59:59');
|
||||
$searchArray = ['user_id' => $this->me->id, 'start' => $timestamp_montag, 'end' => $timestamp_sonntag];
|
||||
|
||||
$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 = ['user_id' => $this->me->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");
|
||||
$timerecordingCategoriess = TimerecordingCategoryModel::getAll();
|
||||
$timerecordings = TimerecordingModel::search($searchArray);
|
||||
$responsecount = count($timerecordings);
|
||||
foreach ($timerecordings as $timerecording):
|
||||
$state = "";
|
||||
$enddate = "";
|
||||
$sum = "-";
|
||||
$day = "";
|
||||
$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) {
|
||||
$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)];
|
||||
// echo $enddate-$datadate."<br>";
|
||||
} else if ($timerecording->timerecordingCategory->hourday == 3 || $timerecording->timerecordingCategory->hourday == 4) {
|
||||
$date = date("d.m.Y", $timerecording->start);
|
||||
$datadate = date("Y-m-d", $timerecording->start);
|
||||
$start = "-";
|
||||
$end = "-";
|
||||
$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->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-commend="' . $timerecording->commend . '"
|
||||
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;
|
||||
|
||||
$rows[] = array(
|
||||
'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),
|
||||
'category' => array('category' => $timerecording->timerecordingCategory->name, 'order' => $timerecording->timerecordingCategory->name),
|
||||
'commend' => array('commend' => $timerecording->commend, 'order' => $timerecording->commend),
|
||||
'edit' => array('edit' => $edit, 'order' => $edit),
|
||||
);
|
||||
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['data'] = $rows;
|
||||
$json['recordsFiltered'] = $responsecount;
|
||||
$json['recordsTotal'] = $responsecount;
|
||||
$json = json_encode($json);
|
||||
echo trim($json);
|
||||
die();
|
||||
}
|
||||
|
||||
protected function deleteAction()
|
||||
{
|
||||
$id = $this->request->id;
|
||||
@@ -139,6 +370,9 @@ class TimerecordingController extends mfBaseController
|
||||
}
|
||||
|
||||
$timerecordings->delete();
|
||||
if ($this->request->ajax == 1) {
|
||||
die();
|
||||
}
|
||||
$this->redirect("Timerecording");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user