Files
thetool/application/TimerecordingCar/TimerecordingCarController.php
Spitzer Daniel dec2e9f211 Zeiterfassungs Update
* neue Migration für Personaladministration (Aktive Verrechnung)
 * Verrechnung Anpassungen Black P.
 * superexpertEnabled Implementation Verrechnung/Personaladministration
 * Personaladministration (Aktive Verrechnung/Zeiterfassung Enddatum)
2024-04-04 18:12:14 +02:00

180 lines
5.4 KiB
PHP

<?php
class TimerecordingCarController extends mfBaseController
{
protected function init()
{
$this->needlogin = true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me", $me);
if (!$me->is(["Admin"])) {
$this->redirect("Dashboard");
}
}
protected function indexAction()
{
$this->layout()->setTemplate("TimerecordingCar/Index");
$timerecordingcars = TimerecordingCarModel::getAll();
$this->layout()->set("timerecordingcars", $timerecordingcars);
}
protected function detailAction()
{
$timerecordingcarid = $this->request->id;
$this->layout()->setTemplate("TimerecordingCar/Detail");
$timerecordingcar = TimerecordingCarModel::getOne($timerecordingcarid);
$this->layout()->set("timerecordingcar", $timerecordingcar);
$timerecordings = TimerecordingModel::search(["timerecordingCar_id_all" => $timerecordingcarid]);
$this->layout()->set("timerecordings", $timerecordings);
}
protected function addAction()
{
$timerecordingusers = UserModel::search(['employee' => 'true']);
$this->layout()->set("timerecordingusers", $timerecordingusers);
$this->layout()->setTemplate("TimerecordingCar/Form");
}
protected function editAction()
{
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Auto nicht gefunden", "error");
$this->redirect("TimerecordingCar");
}
$timerecordingcars = new TimerecordingCar($id);
if ($timerecordingcars->id != $id) {
$this->layout()->setFlash("Auto nicht gefunden", "error");
$this->redirect("TimerecordingCar");
}
$this->layout()->set("timerecordingcars", $timerecordingcars);
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";
$timerecordingcars = new TimerecordingCar($id);
if (!$timerecordingcars->id) {
$this->layout()->setFlash("Autos nicht gefunden", "error");
$this->redirect("TimerecordingCar");
}
} else {
$mode = "add";
}
$data = [];
$data['number_plate'] = trim($r->number_plate);
$data['user_id'] = trim($r->user_id);
$data['brand'] = trim($r->brand);
$data['model'] = trim($r->model);
$data['mileage'] = trim($r->mileage);
$data['initial_approval'] = strtotime($r->initial_approval);
$data['timerecording'] = $r->timerecording;
$data['first_approval'] = trim($r->first_approval);
if (!$data['user_id'] || $data['user_id'] == "-") {
$data['user_id'] = null;
}
if (!$data['initial_approval']) {
$data['initial_approval'] = null;
}
if (!$data['timerecording']) {
$data['timerecording'] = 0;
}
if (!$data['mileage']) {
$data['mileage'] = null;
}
if (!$data['first_approval'] || trim($data['first_approval']) == "") {
$data['first_approval'] = null;
}
if (!$data['number_plate']) {
$this->layout()->setFlash("Kennzeichen darf nicht leer sein", "error");
$this->redirect("TimerecordingCar");
}
if (!$data['brand']) {
$this->layout()->setFlash("Marke darf nicht leer sein", "error");
$this->redirect("TimerecordingCar");
}
if (!$data['model']) {
$this->layout()->setFlash("Model/Typ darf nicht leer sein", "error");
$this->redirect("TimerecordingCar");
}
// var_dump($_FILES);
// var_dump($upload);
// exit;
if ($mode == "edit") {
$timerecordingcars->update($data);
} else {
$timerecordingcars = TimerecordingCarModel::create($data);
}
// var_dump($filestore);
// exit;
$id = $timerecordingcars->save();
$returnUrl = "TimerecordingCar";
$returnAction = "Index";
$returnVariables = array();
$returnAnker = "";
if ($this->request->returnto == "detail") {
$returnUrl = "TimerecordingCar";
$returnAction = "detail";
$returnVariables = array("id" => $id);
}
TimerecordingCarModel::calcMileage();
if (!$id) {
$this->layout()->setFlash("Auto konnte nicht angelegt werden", "error");
$this->redirect("TimerecordingCar");
}
if ($mode == "edit") {
$this->layout()->setFlash("Auto erfolgreich geändert", "success");
} else if ($mode = "add") {
$this->layout()->setFlash("Auto erfolgreich angelegt", "success");
}
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
}
protected function deleteAction()
{
$id = $this->request->id;
$timerecordingcars = new TimerecordingCar($id);
if (!$timerecordingcars->id || $timerecordingcars->id != $id) {
$this->layout()->setFlash("Auto nicht gefunden.", "error");
$this->redirect("TimerecordingCar");
}
$timerecordingcars->delete();
$this->redirect("TimerecordingCar");
}
}