needlogin = true; $me = new User(); $me->loadMe(); $this->me = $me; $this->layout()->set("me", $me); if (!$me->can(["Fibu"])) { $this->redirect("Dashboard"); } } 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() { $this->layout()->setTemplate("TimerecordingEmployee/Index"); $timerecordingemployees = TimerecordingEmployeeModel::getAllArray(); $timerecordingusers = UserModel::search(['employee' => 'true']); $timerecordingworkinghours = TimerecordingEmployeeWorkingHourModel::getAllArray(); $this->layout()->set("timerecordingemployees", $timerecordingemployees); $this->layout()->set("timerecordingworkinghours", $timerecordingworkinghours); $this->layout()->set("timerecordingusers", $timerecordingusers); } protected function addAction() { $id = $this->request->id; $userid = $this->request->userid; $days = TimerecordingEmployeeWorkingHourModel::$days_definition; $timerecordingworkinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $userid]); $this->layout()->set("days", $days); $this->layout()->set("timerecordingworkinghours", $timerecordingworkinghours); $this->layout()->setTemplate("TimerecordingEmployee/Form"); } protected function editAction() { $id = $this->request->id; $userid = $this->request->userid; if (!is_numeric($id) || !$id) { } else { $timerecordingemployees = new TimerecordingEmployee($id); if ($timerecordingemployees->id != $id) { $this->layout()->setFlash("Personaladministration nicht gefunden", "error"); $this->redirect("TimerecordingEmployee"); } $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(); } protected function saveAction() { $r = $this->request; $id = $r->id; //var_dump($r->get());exit; if (is_numeric($id) && $id > 0) { $mode = "edit"; $timerecordingemployees = new TimerecordingEmployee($id); if (!$timerecordingemployees->id) { $this->layout()->setFlash("Personaladministration nicht gefunden", "error"); $this->redirect("TimerecordingEmployee"); } } else { $mode = "add"; } TimerecordingEmployeeWorkingHourModel::deleteUserHours($r->user_id); if ($r->day) { foreach ($r->day as $key => $day) { unset($dataWorkHours); $dataWorkHours = []; $starttime = $r->timestart[$key]; $endtime = $r->timeend[$key]; if ($starttime && $endtime) { $dataWorkHours['user_id'] = $r->user_id; $dataWorkHours['day'] = $day; $dataWorkHours['start'] = $starttime; $dataWorkHours['end'] = $endtime; $timerecordingemployeesworkinghours = TimerecordingEmployeeWorkingHourModel::create($dataWorkHours); $timerecordingemployeesworkinghours->save(); } } } $plushours = $r->plushours; if ($plushours) { $plushours = str_replace(',', '.', $plushours); if (is_numeric($plushours)) { $plushours = $plushours * 3600; } else { $plushours = 0; } } else { $plushours = 0; } $overtime = $r->overtime; if ($overtime) { $overtime = str_replace(',', '.', $overtime); if (is_numeric($overtime)) { $overtime = $overtime * 3600; } else { $overtime = 0; } } else { $overtime = 0; } $data = []; $data['user_id'] = trim($r->user_id); $data['auto_workinghours'] = trim($r->auto_workinghours); $data['jobbike'] = trim($r->jobbike); $data['night_allowance'] = trim($r->night_allowance); $data['holidays'] = trim($r->holidays); $data['plushours'] = $plushours; $data['startdate'] = strtotime($r->startdate); $data['enddate'] = strtotime($r->enddate); $data['type'] = trim($r->type); $data['bmd_active'] = trim($r->bmd_active); $data['overtime'] = $overtime; if (!$data['holidays']) { $data['holidays'] = 0; } if ($r->bpahours) { $bpahours = $r->bpahours; $bpahours = str_replace(',', '.', $bpahours); if (is_numeric($bpahours)) { $bpahours = $bpahours * 3600; $data['bpahours'] = $bpahours; } } if ($r->bpahours_value) { $bpahours_value = $r->bpahours_value; $bpahours_value = str_replace(',', '.', $bpahours_value); if (is_numeric($bpahours_value)) { $data['bpahours_value'] = $bpahours_value; } } if ($this->me->superexpertEnabled()) { if ($r->only_admin) { $data['only_admin'] = $r->only_admin; } else { $data['only_admin'] = 0; } } if (!$data['overtime']) { $data['overtime'] = 0; } if (!$data['bmd_active']) { $data['bmd_active'] = 0; } if (!$data['enddate']) { $data['enddate'] = null; } if ($r->birthday) { $data['birthday'] = strtotime($r->birthday); } else { $data['birthday'] = null; } if ($r->insurance_number) { $data['insurance_number'] = $r->insurance_number; } else { $data['insurance_number'] = null; } if (!$data['user_id']) { $this->layout()->setFlash("Mitarbeiter darf nicht leer sein", "error"); $this->redirect("TimerecordingEmployee"); } if (!$data['auto_workinghours']) { $data['auto_workinghours'] = 0; } if (!$data['jobbike']) { $data['jobbike'] = 0; } if (!$data['night_allowance']) { $data['night_allowance'] = 0; } if ($mode == "edit") { $timerecordingemployees->update($data); } else { $timerecordingemployees = TimerecordingEmployeeModel::create($data); } $id = $timerecordingemployees->save(); if (!$id) { $this->layout()->setFlash("Personaladministration konnte nicht angelegt werden", "error"); $this->redirect("TimerecordingEmployee"); } if ($mode == "edit") { $this->layout()->setFlash("Personaladministration erfolgreich geƤndert", "success"); } else if ($mode = "add") { $this->layout()->setFlash("Personaladministration erfolgreich angelegt", "success"); } $employee = new TimerecordingController(); $employee->updatePlushours($r->user_id); $this->redirect("TimerecordingEmployee"); } protected function deleteAction() { $id = $this->request->id; $timerecordingemployees = new TimerecordingEmployee($id); if (!$timerecordingemployees->id || $timerecordingemployees->id != $id) { $this->layout()->setFlash("Personaladministration nicht gefunden.", "error"); $this->redirect("TimerecordingEmployee"); } $timerecordingemployees->delete(); $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 = 0; 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'] . "
"; $datetimetext = TimerecordingEmployeeWorkingHourModel::cleardays($datetimetext); } $result[$value->enddate]['workinghours'] = $datetimetext; $result[$value->enddate]['workingtime'] = $secondcounter; $result[$value->enddate]['id'] = $value->id; } $employee = new TimerecordingController(); $employee->updatePlushours($userid); return $result; } }