Zeiterfassung

* Feature Implementation Arbeitszeitänderungen mit History für alle möglichen historischen Berechnungen und Auswertung
 * neue Migration
This commit is contained in:
Daniel Spitzer
2025-02-07 12:27:19 +01:00
parent 3c4cba8562
commit c38a9919b6
6 changed files with 603 additions and 2 deletions
@@ -16,6 +16,47 @@ class TimerecordingEmployeeController extends mfBaseController
}
}
protected function apiAction()
{
$do = $this->request->do;
$r = $this->request;
$data = [];
switch ($do) {
case "saveWorkingHours":
$userid = $r->userid;
$enddate = $r->enddate;
$workinghours = $r->workingHours;
$data = [];
$data['user_id'] = $userid;
$data['enddate'] = strtotime($enddate) + 10800;
$data['workinghours'] = json_encode($workinghours);
$timerecordingemployeesworkinghoursHistory = TimerecordingEmployeeWorkingHourHistoryModel::create($data);
$timerecordingemployeesworkinghoursHistory->save();
break;
case "deleteWorkingHours":
$id = $r->id;
$timerecordingemployeesworkinghoursHistory = new TimerecordingEmployeeWorkingHourHistory($id);
if (!$timerecordingemployeesworkinghoursHistory->id || $timerecordingemployeesworkinghoursHistory->id != $id) {
$data = ["status" => "error"];
$this->returnJson($data);
}
$timerecordingemployeesworkinghoursHistory->delete();
break;
default:
$data = ["status" => "error"];
$this->returnJson($data);
}
if (!is_array($return) || !count($return)) {
$data = ["status" => "error"];
$this->returnJson($data);
}
$data['status'] = "OK";
$data['result'] = $return;
$this->returnJson($data);
}
protected function indexAction()
{
@@ -56,6 +97,8 @@ class TimerecordingEmployeeController extends mfBaseController
$this->layout()->set("timerecordingemployees", $timerecordingemployees);
}
$timerecordingworkinghourshistory = $this->generateWorkingHoursHistory($userid);
$this->layout()->set("timerecordingworkinghourshistory", $timerecordingworkinghourshistory);
$timerecordinguser = UserModel::search(['worker_id' => $userid]);
$this->layout()->set("timerecordinguser", $timerecordinguser);
return $this->addAction();
@@ -219,4 +262,26 @@ class TimerecordingEmployeeController extends mfBaseController
$this->redirect("TimerecordingEmployee");
}
protected function generateWorkingHoursHistory($userid)
{
$days_short = TimerecordingEmployeeWorkingHourModel::$days_short;
$TimerecordingEmployeeWorkingHourHistory = TimerecordingEmployeeWorkingHourHistoryModel::search(['user_id' => $userid]);
foreach ($TimerecordingEmployeeWorkingHourHistory as $key => $value) {
$workinghours = json_decode($value->workinghours, true);
$datetimetext = "";
$secondcounter = "";
foreach ($workinghours as $key2 => $data) {
$secondcounter = $secondcounter + strtotime(date("Y-m-d " . $data['end'] . ":00")) - strtotime(date("Y-m-d " . $data['start'] . ":00"));
$datetimetext .= $days_short[$data['day']] . " " . $data['start'] . " - " . $data['end'] . "<br>";
$datetimetext = TimerecordingEmployeeWorkingHourModel::cleardays($datetimetext);
}
$result[$value->enddate]['workinghours'] = $datetimetext;
$result[$value->enddate]['workingtime'] = $secondcounter;
$result[$value->enddate]['id'] = $value->id;
}
return $result;
}
}