From 025522a740bdd594361801a498bebb4815099214 Mon Sep 17 00:00:00 2001 From: Spitzer Daniel Date: Tue, 26 Mar 2024 08:08:01 +0100 Subject: [PATCH] Zeiterfassungs Update * Implementerung Fahrzeugverwaltung * neue Buchungsart Fahrtenbuch * Diverse Bugfixes --- Layout/default/Timerecording/Index.php | 27 ++- Layout/default/TimerecordingCar/Detail.php | 199 ++++++++++++++++++ Layout/default/TimerecordingCar/Form.php | 151 +++++++++++++ Layout/default/TimerecordingCar/Index.php | 120 +++++++++++ Layout/default/TimerecordingReport/Index.php | 29 ++- Layout/default/menu.php | 5 + application/Timerecording/Timerecording.php | 3 +- .../Timerecording/TimerecordingController.php | 53 ++++- .../Timerecording/TimerecordingModel.php | 17 ++ .../TimerecordingCar/TimerecordingCar.php | 59 ++++++ .../TimerecordingCarController.php | 173 +++++++++++++++ .../TimerecordingCarModel.php | 156 ++++++++++++++ .../TimerecordingCategoryModel.php | 2 +- .../TimerecordingReportController.php | 102 +++++++-- .../20240317165103_timerecording_car.php | 40 ++++ ...317171644_timerecording_add_fields_car.php | 36 ++++ public/js/pages/timerecording/index.js | 91 +++++++- public/js/pages/timerecordingReport/index.js | 80 ++++++- 18 files changed, 1305 insertions(+), 38 deletions(-) create mode 100644 Layout/default/TimerecordingCar/Detail.php create mode 100644 Layout/default/TimerecordingCar/Form.php create mode 100644 Layout/default/TimerecordingCar/Index.php create mode 100644 application/TimerecordingCar/TimerecordingCar.php create mode 100644 application/TimerecordingCar/TimerecordingCarController.php create mode 100644 application/TimerecordingCar/TimerecordingCarModel.php create mode 100644 db/migrations/20240317165103_timerecording_car.php create mode 100644 db/migrations/20240317171644_timerecording_add_fields_car.php diff --git a/Layout/default/Timerecording/Index.php b/Layout/default/Timerecording/Index.php index 921c0cbd9..cc6c94328 100644 --- a/Layout/default/Timerecording/Index.php +++ b/Layout/default/Timerecording/Index.php @@ -13,7 +13,6 @@ $monthger[10] = "Oktober"; $monthger[11] = "November"; $monthger[12] = "Dezember"; $time = time(); - for ($i = 1; $i <= 25; $i++) { $kw = date('W', $time); $year = date('Y', $time); @@ -196,7 +195,7 @@ $years[time() - 31536000] = date('Y', time() - 31536000); -
+
+ + +
diff --git a/Layout/default/TimerecordingCar/Detail.php b/Layout/default/TimerecordingCar/Detail.php new file mode 100644 index 000000000..023e4cf51 --- /dev/null +++ b/Layout/default/TimerecordingCar/Detail.php @@ -0,0 +1,199 @@ +initial_approval); +$initialApprovalMonth = date("m", $timerecordingcar->initial_approval); +$firstApproval = strtotime('+' . $timerecordingcar->first_approval . 'years', strtotime($initialApproval)); +if ($firstApproval < time()) { + $firstApproval = strtotime(date("Y-$initialApprovalMonth-01", time())); + if ($firstApproval < time()) { + $firstApproval = strtotime(date("Y-$initialApprovalMonth-01", strtotime('+1 year'))); + } +} +$approval = date("m/Y", $firstApproval); +?> + + + +
+
+
+
+ +
+

brand . "/" . $timerecordingcar->model . " (" . $timerecordingcar->number_plate . ")" ?> + Detail + + $timerecordingcar->id, 'returnto' => "detail"]) ?>"> + + + +

+
+
+
+ + +
+
+
+
+
+

Fahrzeug Informationen

+ +
+
+ + + + + + + + + + + + + + + + + + + + +
Markebrand ?>
Model/Typmodel ?>
Erste §57a nachfirst_approval) ? $timerecordingcar->first_approval . " Jahr(en)" : "-" ?>
Fahrtenbuchtimerecording) ? "Ja" : "Nein" ?>
+
+ + +
+
+
+

 

+ +
+
+ + + + + + + + + + + + + + + + + + +
Erstzulassunginitial_approval) ? date("m/Y", $timerecordingcar->initial_approval) : "-" ?>
Nächste $57ainitial_approval) ? $approval : "-" ?>
Kilometerstandmileage_now) ? $timerecordingcar->mileage_now . " KM" : "-" ?>
+
+ + +
+
+
+
+ + +
+
+
+
+
+

Fahrtenbuch

+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
StartkilometerEndkilometerKilometerFahrerDatumZeitOrt
mileage_start ?> KMmileage_end ?> KMmileage_end - $timerecording->mileage_start ?>KM + user->name ?>start) ?>start) . " - " . date("H:i", $timerecording->end) ?>businesstrip_info ?> + + $timerecordingcar->id]) ?> + + + $timerecordingcar->id]) ?> + + +
+ +
+
+ +
+
+ + + + + + + \ No newline at end of file diff --git a/Layout/default/TimerecordingCar/Form.php b/Layout/default/TimerecordingCar/Form.php new file mode 100644 index 000000000..070fdd9b9 --- /dev/null +++ b/Layout/default/TimerecordingCar/Form.php @@ -0,0 +1,151 @@ + $timerecordingcars->id]); +} else { + $cancelUrl = self::getUrl("TimerecordingCar"); +} +?> + + +
+
+
+
+ +
+

id) ? "Fahrzeug bearbeiten" : "Neues Fahrzeug" ?>

+
+
+
+ +
+
+ +
+
+

id) ? "Fahrzeug bearbeiten" : "Neues Fahrzeug" ?>

+ +
$_GET["returnto"]]) ?>"> +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ "/> +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ timerecording) ? 'checked="checked"' : '' ?> + type="checkbox" name="timerecording" value="1"/> +
+
+
+
+
+
+ +
+ + + + +
+
+ + +
+
+
+ +
+
+ + + + \ No newline at end of file diff --git a/Layout/default/TimerecordingCar/Index.php b/Layout/default/TimerecordingCar/Index.php new file mode 100644 index 000000000..746bf1f7f --- /dev/null +++ b/Layout/default/TimerecordingCar/Index.php @@ -0,0 +1,120 @@ + + + + +
+
+
+
+ +
+

Fahrzeuge

+
+
+
+ + + +
+
+
+
+
+

Liste aller Fahrzeuge

+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + initial_approval); + $initialApprovalMonth = date("m", $timerecordingcar->initial_approval); + $firstApproval = strtotime('+' . $timerecordingcar->first_approval . 'years', strtotime($initialApproval)); + if ($firstApproval < time()) { + $firstApproval = strtotime(date("Y-$initialApprovalMonth-01", time())); + if ($firstApproval < time()) { + $firstApproval = strtotime(date("Y-$initialApprovalMonth-01", strtotime('+1 year'))); + } + } + $approval = date("m/Y", $firstApproval); + + ?> + + + + + + + + + + + + +
KennzeichenMarkeModel/TypErstzulassssung$57aFahrtenbuchKilometerstand
+ $timerecordingcar->id]) ?>"> number_plate ?> + brand ?>model ?>initial_approval) ? date("m/Y", $timerecordingcar->initial_approval) : "-" ?>initial_approval) ? $approval : "-" ?>timerecording) ? "Ja" : "Nein" ?>mileage_now) ? number_format($timerecordingcar->mileage_now, 0, ',', '.')." KM" : "-" ?> + + $timerecordingcar->id]) ?>"> + $timerecordingcar->id]) ?>" + onclick="if(!confirm('Fahrzeug wirklich löschen?')) return false;" class="text-danger" + title="Löschen"> +
+ +
+
+ +
+ + + + + + + + \ No newline at end of file diff --git a/Layout/default/TimerecordingReport/Index.php b/Layout/default/TimerecordingReport/Index.php index 1e782aa51..8d5b70464 100644 --- a/Layout/default/TimerecordingReport/Index.php +++ b/Layout/default/TimerecordingReport/Index.php @@ -121,7 +121,7 @@ $years[time() - 31536000] = date('Y', time() - 31536000);
- +
+ + +
diff --git a/Layout/default/menu.php b/Layout/default/menu.php index eaaf84f64..d9abd36ee 100644 --- a/Layout/default/menu.php +++ b/Layout/default/menu.php @@ -40,9 +40,11 @@ can('Fibu')): ?>
  • "> Freigaben
  • "> Auswertung/Korrektur
  • +
  • "> Verrechnung
  • "> Buchungsarten
  • "> Feiertage
  • "> Personaladministration
  • +
  • "> Fahrzeugverwaltung
  • @@ -96,6 +98,9 @@ is(["Admin","netowner","lineplanner","lineworker"]) && $me->can("Linework")): ?>
  • "> Leitungsbau
  • is(["Admin","netowner","netoperator","lineworker"]) && $me->can("Patching")): ?>
  • "> Patchungen
  • is(["Admin","netowner","pipeplanner","lineplanner","pipeworker","netoperator","lineworker"]) && $me->can("Filestore")): ?>
  • "> Dateiablage
  • +is(["Admin","netowner","pipeplanner","pipeplanner"]) && $me->is("employee")): ?> +is(["Admin","netowner","lineplanner","lineworker"]) && $me->is("employee")): ?> +is(["Admin","netowner","lineplanner","lineworker"]) && $me->is("employee")): ?> diff --git a/application/Timerecording/Timerecording.php b/application/Timerecording/Timerecording.php index 86c9aeade..e6cfdbb8e 100644 --- a/application/Timerecording/Timerecording.php +++ b/application/Timerecording/Timerecording.php @@ -6,7 +6,8 @@ class Timerecording extends mfBaseModel private $creator; private $user; private $timerecordingCategory; - + private $timerecordingCar; + public function getProperty($name) diff --git a/application/Timerecording/TimerecordingController.php b/application/Timerecording/TimerecordingController.php index 187a0c421..20b4889a0 100644 --- a/application/Timerecording/TimerecordingController.php +++ b/application/Timerecording/TimerecordingController.php @@ -22,7 +22,9 @@ class TimerecordingController extends mfBaseController $this->updateHolidays($this->me->id); $timerecordingCategoriess = TimerecordingCategoryModel::getAll(); + $timerecordingCars = TimerecordingCarModel::search(['timerecording' => 1]); $this->layout()->set("timerecordingCategoriess", $timerecordingCategoriess); + $this->layout()->set("timerecordingCars", $timerecordingCars); $this->layout()->setTemplate("Timerecording/Index"); } @@ -206,13 +208,12 @@ class TimerecordingController extends mfBaseController $employee = TimerecordingEmployeeModel::search(['user_id' => $userid]); $plushours = $employee[0]->plushours_now * 1.25; - $overtime = $employee[0]->overtime * 1.5; + $overtime = $employee[0]->overtime_now * 1.5; $overtimesum = $plushours + $overtime; if ($overtimesum < $isTime) { if ($overtimesum < 0) { $overtimesum = 0; } - $result['state'] = "error"; $result['error'] = "Maximal verfügbarer ZA: " . sprintf('%02dh:%02dm', floor($overtimesum / 3600), floor($overtimesum / 60 % 60)) . "."; echo json_encode($result); @@ -221,7 +222,7 @@ class TimerecordingController extends mfBaseController if ($plushours >= $isTime) { $isTime = $isTime * 0.8; $return['hours'] = $isTime; - } elseif ($plushours <= 0) { + } elseif ($plushours == 0) { $isTime = $isTime * 0.66666666666666666666666666666667; $return ['hours_overtime'] = $isTime; } else { @@ -265,7 +266,7 @@ class TimerecordingController extends mfBaseController $this->updateOpenTimerecording(); } $data = []; - if ($hourday == 1 || $hourday == 6) { + if ($hourday == 1 || $hourday == 6 || $hourday == 7) { $starttime = strtotime($r->date . " " . $r->start . ":00"); $endtime = strtotime($r->date . " " . $r->end . ":00"); if ($hourday == 6) { @@ -282,7 +283,7 @@ class TimerecordingController extends mfBaseController $endtime = strtotime($r->date . " 23:59:00"); } - if ($hourday != 5) { + if ($hourday != 5 && $hourday != 7) { $result = $this->checkTimerecording($starttime, $endtime, $id); } if ($result['state'] == "error") { @@ -321,6 +322,19 @@ class TimerecordingController extends mfBaseController $data['businesstrip_info'] = $r->businesstrip_info; $data['homeoffice'] = $r->homeoffice; $data['days'] = $r->days; + $data['timerecordingCar_id'] = $r->timerecordingCar_id; + $data['mileage_start'] = $r->mileage_start; + $data['mileage_end'] = $r->mileage_end; + + if (!$data['timerecordingCar_id']) { + $data['timerecordingCar_id'] = NULL; + } + if (!$data['mileage_start']) { + $data['mileage_start'] = NULL; + } + if (!$data['mileage_end']) { + $data['mileage_end'] = NULL; + } if (!$data['businesstrip'] || $data['businesstrip'] == "false") { $data['businesstrip'] = 0; @@ -436,6 +450,7 @@ class TimerecordingController extends mfBaseController $this->updateHolidays($data['user_id']); } $this->updatePlushours($data['user_id']); + TimerecordingCarModel::calcMileage(); } if ($mode == "edit") { @@ -828,6 +843,16 @@ class TimerecordingController extends mfBaseController $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) { @@ -836,8 +861,17 @@ class TimerecordingController extends mfBaseController $state = ''; } $edit = ""; - if ($timerecording->businesstrip == 1) { - $category = "" . $timerecording->timerecordingCategory->name . " (Dienstreise: " . $timerecording->businesstrip_info . ")"; + if ($timerecording->timerecordingCategory->hourday == 7) { + $distance = $timerecording->mileage_end - $timerecording->mileage_start; + $category = "" . $timerecording->timerecordingCategory->name . "(" . $timerecording->timerecordingCar->number_plate . " " . $distance . "KM) (Zielort: " . $timerecording->businesstrip_info . ")"; + } 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 = "" . $timerecording->timerecordingCategory->name . "$car (Dienstreise: " . $timerecording->businesstrip_info . ")"; } else if ($timerecording->homeoffice == 1) { $category = "" . $timerecording->timerecordingCategory->name . " (Homeoffice)"; } else { @@ -860,13 +894,16 @@ class TimerecordingController extends mfBaseController data-businesstrip="' . $timerecording->businesstrip . '" data-businesstripinfo="' . $timerecording->businesstrip_info . '" data-homeoffice="' . $timerecording->homeoffice . '" + data-car="' . $timerecording->timerecordingCar_id . '" + data-mileagestart="' . $timerecording->mileage_start . '" + data-mileageend="' . $timerecording->mileage_end . '" title="Bearbeiten">'; else : $edit .= '
    '; endif; $edit .= ''; endif; - if ($datatype == 3 && $timerecording->timerecordingCategory->hourday == 1) { + if ($datatype == 3 && ($timerecording->timerecordingCategory->hourday == 1 || $timerecording->timerecordingCategory->hourday == 7 || $timerecording->timerecordingCategory->hourday == 5)) { } else { $rows[] = array( 'date' => array('date' => $state . $day . " " . $date, 'order' => $orderdate), diff --git a/application/Timerecording/TimerecordingModel.php b/application/Timerecording/TimerecordingModel.php index a777b5c9f..e95ad81a0 100644 --- a/application/Timerecording/TimerecordingModel.php +++ b/application/Timerecording/TimerecordingModel.php @@ -11,6 +11,10 @@ class TimerecordingModel private $timerecordingCategory_id; private $businesstrip; private $businesstrip_info; + private $timerecordingCar_id; + private $mileage_start; + private $mileage_end; + private $homeoffice; private $comment; private $approved; @@ -174,7 +178,20 @@ class TimerecordingModel $where .= " AND `start` >= $start AND `days` !=0 ORDER by start ASC"; } } + if (array_key_exists("timerecordingCar_id", $filter)) { + $timerecordingCar = $filter['timerecordingCar_id']; + if (is_numeric($timerecordingCar)) { + $where .= " AND `timerecordingCar_id` = $timerecordingCar ORDER by mileage_end DESC LIMIT 1"; + } + } + if (array_key_exists("timerecordingCar_id_all", $filter)) { + $timerecordingCar = $filter['timerecordingCar_id_all']; + + if (is_numeric($timerecordingCar)) { + $where .= " AND `timerecordingCar_id` = $timerecordingCar ORDER by mileage_start ASC"; + } + } if (array_key_exists("starttime", $filter) && array_key_exists("endtime", $filter)) { $starttime = $filter['starttime']; diff --git a/application/TimerecordingCar/TimerecordingCar.php b/application/TimerecordingCar/TimerecordingCar.php new file mode 100644 index 000000000..be5ba62f2 --- /dev/null +++ b/application/TimerecordingCar/TimerecordingCar.php @@ -0,0 +1,59 @@ +$name == null) { + + if (!$this->id) { + return null; + } + + if ($name == "creator") { + $this->creator = mfValuecache::singleton()->get("Worker-id-" . $this->create_by); + if ($this->creator === null) { + $this->creator = new User($this->create_by); + if ($this->creator->id) { + mfValuecache::singleton()->set("Worker-id-" . $this->create_by, $this->creator); + } + } + return $this->creator; + } + + if ($name == "editor") { + $this->editor = mfValuecache::singleton()->get("Worker-id-" . $this->edit_by); + if ($this->editor === null) { + $this->editor = new User($this->edit_by); + if ($this->editor->id) { + mfValuecache::singleton()->set("Worker-id-" . $this->edit_by, $this->editor); + } + } + return $this->editor; + } + + $classname = ucfirst($name); + $idfield = $name . "_id"; + $this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-" . $this->$idfield); + if (!$this->$name) { + $this->$name = new $classname($this->$idfield); + } + + if ($this->$name->id) { + mfValuecache::singleton()->set("mfObjectmodel-$name-" . $this->$name->id, $this->$name); + return $this->$name; + } else { + return null; + } + + } + + return $this->$name; +} + +} \ No newline at end of file diff --git a/application/TimerecordingCar/TimerecordingCarController.php b/application/TimerecordingCar/TimerecordingCarController.php new file mode 100644 index 000000000..548f92b2a --- /dev/null +++ b/application/TimerecordingCar/TimerecordingCarController.php @@ -0,0 +1,173 @@ +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() + { + + $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['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['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"); + } + +} diff --git a/application/TimerecordingCar/TimerecordingCarModel.php b/application/TimerecordingCar/TimerecordingCarModel.php new file mode 100644 index 000000000..ad78e52d8 --- /dev/null +++ b/application/TimerecordingCar/TimerecordingCarModel.php @@ -0,0 +1,156 @@ + $value) { + if (property_exists(get_called_class(), $field)) { + if (substr($field, 0, 5) == "vlan_" && !$value) { + $model->$field = null; + continue; + } + $model->$field = $value; + } + } + + $me = mfValuecache::singleton()->get("me"); + if (!$me) { + $me = new User(); + $me->loadMe(); + mfValuecache::singleton()->set("me", $me); + } + + if ($model->create_by === null) { + $model->create_by = $me->id; + } + if ($model->edit_by === null) { + $model->edit_by = $me->id; + } + + return $model; + } + + public static function getOne($id) + { + if (!is_numeric($id) || !$id) { + throw new Exception("Invalid number", 400); + } + $item = []; + $db = FronkDB::singleton(); + + $res = $db->select("TimerecordingCar", "*", "id=$id LIMIT 1"); + if ($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new TimerecordingCar($data); + } + return $item; + } + + public static function calcMileage() + { + $TimerecordingCars = self::getAll(); + foreach ($TimerecordingCars as $TimerecordingCar) { + $timerecording = TimerecordingModel::search(["timerecordingCar_id" => $TimerecordingCar->id]); + if (!$timerecording) { + if ($TimerecordingCar->mileage_now != $TimerecordingCar->mileage) { + $TimerecordingCar->mileage_now = $TimerecordingCar->mileage; + $TimerecordingCar->save(); + } + } else { + if (!$TimerecordingCar->mileage_now || $TimerecordingCar->mileage_now < $timerecording[0]->mileage_end) { + $TimerecordingCar->mileage_now = $timerecording[0]->mileage_end; + $TimerecordingCar->save(); + } else if ($timerecording[0]->mileage_end < $TimerecordingCar->mileage) { + $TimerecordingCar->mileage_now = $TimerecordingCar->mileage; + $TimerecordingCar->save(); + } + } + } + + } + + public static function getAll() + { + $items = []; + + $db = FronkDB::singleton(); + + $res = $db->select("TimerecordingCar", "*", "1=1"); + if ($db->num_rows($res)) { + while ($data = $db->fetch_object($res)) { + $items[] = new TimerecordingCar($data); + } + } + return $items; + + } + + public static function getFirst() + { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("TimerecordingCar", "*", "$where "); + if ($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new TimerecordingCar($data); + if ($item->id) { + return $item; + } else { + return null; + } + } + return null; + } + + public static function search($filter) + { + $items = []; + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("TimerecordingCar", "*", "$where"); + if ($db->num_rows($res)) { + while ($data = $db->fetch_object($res)) { + $items[] = new TimerecordingCar($data); + } + } + return $items; + } + + private static function getSqlFilter($filter) + { + $where = "1=1 "; + + //var_dump($filter);exit; + if (array_key_exists("timerecording", $filter)) { + $timerecording = $filter['timerecording']; + if (is_numeric($timerecording)) { + $where .= " AND timerecording=$timerecording"; + } + } + + //var_dump($filter, $where);exit; + return $where; + } + +} diff --git a/application/TimerecordingCategory/TimerecordingCategoryModel.php b/application/TimerecordingCategory/TimerecordingCategoryModel.php index 1d343e2d2..437cf93dc 100644 --- a/application/TimerecordingCategory/TimerecordingCategoryModel.php +++ b/application/TimerecordingCategory/TimerecordingCategoryModel.php @@ -9,7 +9,7 @@ class TimerecordingCategoryModel private $require_comment; private $only_admin; private $businesstrip; - public static $hourday_definition = array(1 => "Uhrzeit (von/bis)", 2 => "Tage (von/bis)", 3 => "Startdatum", 4 => "Enddatum", 5 => "Anzahl Tage", 6 => "ZA Uhrzeit (von/bis)"); + public static $hourday_definition = array(1 => "Uhrzeit (von/bis)", 2 => "Tage (von/bis)", 3 => "Startdatum", 4 => "Enddatum", 5 => "Anzahl Tage", 6 => "ZA Uhrzeit (von/bis)", 7 => "Fahrtenbuch (von/bis)"); public static $approval_definition = array(0 => "Nein", 1 => "Ja"); public static $require_comment_definition = array(0 => "Nein", 1 => "Ja"); public static $businesstrip_definition = array(0 => "Nein", 1 => "Ja"); diff --git a/application/TimerecordingReport/TimerecordingReportController.php b/application/TimerecordingReport/TimerecordingReportController.php index 8c4722f1f..7c2e3bc14 100644 --- a/application/TimerecordingReport/TimerecordingReportController.php +++ b/application/TimerecordingReport/TimerecordingReportController.php @@ -25,6 +25,8 @@ class TimerecordingReportController extends mfBaseController $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() @@ -57,7 +59,7 @@ class TimerecordingReportController extends mfBaseController $this->returnJson($data); } - protected function getTimerecordingsApi($datatype, $dataweek, $datamonth, $datayear) + public function getTimerecordingsApi($datatype, $dataweek, $datamonth, $datayear) { $mustSeconds = 0; $isSeconds = 0; @@ -290,6 +292,16 @@ class TimerecordingReportController extends mfBaseController $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) { @@ -298,8 +310,17 @@ class TimerecordingReportController extends mfBaseController $state = ''; } $edit = ""; - if ($timerecording->businesstrip == 1) { - $category = "" . $timerecording->timerecordingCategory->name . " (Dienstreise: " . $timerecording->businesstrip_info . ")"; + if ($timerecording->timerecordingCategory->hourday == 7) { + $distance = $timerecording->mileage_end - $timerecording->mileage_start; + $category = "" . $timerecording->timerecordingCategory->name . "(" . $timerecording->timerecordingCar->number_plate . " " . $distance . "KM) (Zielort: " . $timerecording->businesstrip_info . ")"; + } 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 = "" . $timerecording->timerecordingCategory->name . "$car (Dienstreise: " . $timerecording->businesstrip_info . ")"; } else if ($timerecording->homeoffice == 1) { $category = "" . $timerecording->timerecordingCategory->name . " (Homeoffice)"; } else { @@ -322,15 +343,18 @@ class TimerecordingReportController extends mfBaseController data-userid="' . $timerecording->user_id . '" data-businesstrip="' . $timerecording->businesstrip . '" data-businesstripinfo="' . $timerecording->businesstrip_info . '" - data-homeoffice="' . $timerecording->homeoffice . '" - data-days="' . $timerecording->days . '" + 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">'; else : $edit .= '
    '; endif; $edit .= ''; endif; - if ($datatype == 3 && $timerecording->timerecordingCategory->hourday == 1) { + if ($datatype == 3 && ($timerecording->timerecordingCategory->hourday == 1 || $timerecording->timerecordingCategory->hourday == 7 || $timerecording->timerecordingCategory->hourday == 5)) { } else { $rows[] = array( 'user' => array('user' => $timerecording->user->name, 'order' => $timerecording->user->name), @@ -363,23 +387,28 @@ class TimerecordingReportController extends mfBaseController } - protected function getTimerecordingsTimes($datatype, $dataweek, $datamonth, $datayear) + public function getTimerecordingsTimes($datatype, $dataweek, $datamonth, $datayear, $user_id = NULL, $ajax = 1) { $r = $this->request; $mustSeconds = 0; $isSeconds = 0; $holiDays = 0; $plusHours = 0; + $daysum = array(); + if (!$user_id) { + $user_id = $r->user_id; + } + $rows = []; - $employee = TimerecordingEmployeeModel::search(['user_id' => $r->user_id]); + $employee = TimerecordingEmployeeModel::search(['user_id' => $user_id]); if ($employee) { $holiDays = $employee[0]->holidays; $plusHours = $employee[0]->plushours; $auto_workinghours = $employee[0]->auto_workinghours; $startdate = $employee[0]->startdate; } - $workinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $r->user_id]); + $workinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $user_id]); $holidays = TimerecordingHolidayModel::getAll(); foreach ($workinghours as $workinghour) { @@ -402,7 +431,7 @@ class TimerecordingReportController extends mfBaseController $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' => $r->user_id, 'start' => $timestamp_montag, 'end' => $lastdate]; + $searchArray = ['user_id' => $user_id, 'start' => $timestamp_montag, 'end' => $lastdate]; $daycounter = '0'; @@ -422,7 +451,7 @@ class TimerecordingReportController extends mfBaseController $lastdate = strtotime(date("Y-m-t", $datamonth)); $daycount = date("t", $datamonth); $lastdate = strtotime(date("Y-m-d", $lastdate) . ' 23:59:59'); - $searchArray = ['user_id' => $r->user_id, 'start' => $firstdate, 'end' => $lastdate]; + $searchArray = ['user_id' => $user_id, 'start' => $firstdate, 'end' => $lastdate]; $timestamp = $firstdate; for ($i = 1; $i <= $daycount; $i++) { @@ -441,7 +470,7 @@ class TimerecordingReportController extends mfBaseController $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' => $r->user_id, 'start' => $firstdate, 'end' => $lastdate]; + $searchArray = ['user_id' => $user_id, 'start' => $firstdate, 'end' => $lastdate]; $timestamp = $firstdate; for ($i = 1; $i <= $daycount; $i++) { @@ -462,6 +491,7 @@ class TimerecordingReportController extends mfBaseController $timerecordingcategories = TimerecordingCategoryModel::getAll(); $timerecordings = TimerecordingModel::search($searchArray); + $responsecount = count($timerecordings); foreach ($timerecordings as $timerecording): $state = ""; @@ -500,10 +530,18 @@ class TimerecordingReportController extends mfBaseController } $summcounter = 0; $savecounter = 0; + $sumdays = 0; + for ($i = $starttimecalc; $i <= $endtimecalc; $i = $i + 86400) { $holidaycounter = $workingHours[date("w", $i)]; - $isSeconds = $isSeconds + $holidaycounter; - $summcounter = $summcounter + $holidaycounter; + $daycheck = date("Y-m-d", $i); + if (!$holiDay[$daycheck]) { + if ($holidaycounter) { + $isSeconds = $isSeconds + $holidaycounter; + $summcounter = $summcounter + $holidaycounter; + $sumdays++; + } + } if ($savecounter == 1000) { echo $savecounter; die(); @@ -513,8 +551,18 @@ class TimerecordingReportController extends mfBaseController $seconds = $summcounter; $minutes = floor(($seconds % 3600) / 60); $hours = floor($seconds / 3600); - $sum = sprintf("%02d", $hours) . ":" . sprintf("%02d", $minutes); +// $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->short]) { + $daysum[$timerecording->timerecordingCategory->short] = $sumdays; + } else { + $daysum[$timerecording->timerecordingCategory->short] = $daysum[$timerecording->timerecordingCategory->short] + $sumdays; + } } 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); @@ -554,6 +602,18 @@ class TimerecordingReportController extends mfBaseController $end = "-"; $day = $daysgerm[date("w", $timerecording->start)]; $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; } if ($timerecording->timerecordingCategory->approval == 1 && $timerecording->approved == 0) { @@ -600,11 +660,17 @@ class TimerecordingReportController extends mfBaseController $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['time']['daysum'] = $daysum; $json['recordsFiltered'] = $responsecount; $json['recordsTotal'] = $responsecount; - $json = json_encode($json); - echo trim($json); - die(); + + if ($ajax == 1) { + $json = json_encode($json); + echo trim($json); + die(); + } else { + return $json; + } } protected function addAction() diff --git a/db/migrations/20240317165103_timerecording_car.php b/db/migrations/20240317165103_timerecording_car.php new file mode 100644 index 000000000..a96d000e1 --- /dev/null +++ b/db/migrations/20240317165103_timerecording_car.php @@ -0,0 +1,40 @@ +getEnvironment() == "thetool") { + $table = $this->table("TimerecordingCar", ["signed" => true]); + $table->addColumn("number_plate", "string", ["null" => false]); + $table->addColumn("brand", "text", ["null" => true]); + $table->addColumn("model", "text", ["null" => true]); + $table->addColumn("mileage", "integer", ["null" => true]); + $table->addColumn("mileage_now", "integer", ["null" => true]); + $table->addColumn("mileage_timestamp", "integer", ["null" => true]); + $table->addColumn("initial_approval", "integer", ["null" => true]); + $table->addColumn("timerecording", "integer", ["default" => 1]); + $table->addColumn("create_by", "integer", ["null" => false]); + $table->addColumn("edit_by", "integer", ["null" => false]); + $table->addColumn("create", "integer", ["null" => false]); + $table->addColumn("edit", "integer", ["null" => false]); + $table->save(); + } + + if ($this->getEnvironment() == "addressdb") { + + } + } + + public function down(): void + { + if ($this->getEnvironment() == "thetool") { + $this->table("TimerecordingCar")->drop()->save(); + } + if ($this->getEnvironment() == "addressdb") { + } + } +} +?> \ No newline at end of file diff --git a/db/migrations/20240317171644_timerecording_add_fields_car.php b/db/migrations/20240317171644_timerecording_add_fields_car.php new file mode 100644 index 000000000..e05f488af --- /dev/null +++ b/db/migrations/20240317171644_timerecording_add_fields_car.php @@ -0,0 +1,36 @@ +getEnvironment() == "thetool") { + $table = $this->table("Timerecording", ["signed" => true]); + $table->addColumn("timerecordingCar_id", "integer", ["null" => true, "default" => NULL, "after" => "businesstrip_info"]); + $table->addColumn("mileage_start", "integer", ["null" => true, "default" => NULL, "after" => "timerecordingCar"]); + $table->addColumn("mileage_end", "integer", ["null" => true, "default" => NULL, "after" => "mileage_start"]); + $table->update(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } + + public function down(): void + { + if ($this->getEnvironment() == "thetool") { + $this->table("Timerecording")->removeColumn("timerecordingCar")->save(); + $this->table("Timerecording")->removeColumn("mileage_start")->save(); + $this->table("Timerecording")->removeColumn("mileage_end")->save(); + } + + + if($this->getEnvironment() == "addressdb") { + + } + } +} diff --git a/public/js/pages/timerecording/index.js b/public/js/pages/timerecording/index.js index ad7b846a1..f901b09cf 100644 --- a/public/js/pages/timerecording/index.js +++ b/public/js/pages/timerecording/index.js @@ -223,7 +223,25 @@ $(document).ready(function () { $(this).prop("min", ''); $(this).val(''); }) + } else if (parseInt($(this).find(':selected').data('hourday')) === 7) { + $("#endtime-div").show(); + $("#endtime-div").find('input').each(function () { + $(this).prop("required", true); + $(this).prop("disabled", false); + }); + $("#enddate-div").hide(); + $("#enddate-div").find('input').each(function () { + $(this).prop("required", false); + $(this).prop("min", ''); + $(this).val(''); + }) + $('#businesstrip_info').val(''); + $('#businesstrip_info').show(); + $('.car-div-car').show(); + } + + if (parseInt($(this).find(':selected').data('comment')) === 1) { $('#comment').prop("required", true); } else { @@ -235,11 +253,28 @@ $(document).ready(function () { $('#businesstrip').prop("checked", false); $('#businesstrip_info').val(''); $('#businesstrip_info').hide(); + $('.car-div').find('input').prop("required", false); + $('.car-div').find('input').val(''); + $('#timerecordingCar_id').val('').change(); + $('.car-div').hide(); + } else if (parseInt($(this).find(':selected').data('hourday')) === 7) { + $('.businesstrip-div').show(); + $('.businesstrip-check-div').hide(); + $('#businesstrip').prop("checked", true); + $('#businesstrip_info').show(); + $('#businesstrip_info').prop('required', true); + $('#homeoffice-div').hide(); } else { $('.businesstrip-div').hide(); $('#businesstrip').prop("checked", false); $('#businesstrip_info').val(''); + $('#timerecordingCar_id').val('').change(); + $('.car-div').find('input').prop("required", false); + $('.car-div').find('input').val(''); + $('.car-div').hide(); + $('#businesstrip_info').hide(); + } if (parseInt($(this).find(':selected').data('homeoffice')) === 1) { @@ -306,12 +341,25 @@ $(document).ready(function () { $('#businesstrip_info').show(); $('#businesstrip_info').prop('required', true); $('#homeoffice-div').hide(); + $('#timerecordingCar_id').val('').change(); } if ($(this).data('homeoffice') == 1) { $('.businesstrip-div').hide(); $('#homeoffice').prop("checked", true); $('#homeoffice-div').show(); } + if ($(this).data('car')) { + + $('#timerecordingCar_id').val($(this).data('car')).change(); + if ($(this).data('mileagestart')) { + $('.car-div').show(); + $('.car-div').find('input').prop("required", true); + $('#mileage_start').val($(this).data('mileagestart')); + $('#mileage_end').val($(this).data('mileageend')); + } else { + + } + } $('.alert-success').remove(); window.scrollTo(0, 0); }); @@ -324,8 +372,14 @@ $(document).ready(function () { $('#businesstrip').prop("checked", false); $('#businesstrip_info').val(''); $('#businesstrip_info').hide(); + $('#businesstrip_info').prop("required", false); $('#homeoffice').prop("checked", false); + $('.car-div').hide(); + $('.car-div').find('input').val(''); + $('.car-div').find('input').prop("required", false); + $('#timerecordingCar_id').val('').change(); $('#timerecordingCategory_id').change(); + }); $("body").on("change", "#dataweek,#datamonth,#datayear", function () { @@ -362,7 +416,7 @@ $(document).ready(function () { $('#businesstrip_info').prop('required', true); $('#homeoffice').prop('checked', false); $('#homeoffice-div').hide(); - + $('.car-div-car').show(); } else { $('#businesstrip_info').hide(); $('#businesstrip_info').val(''); @@ -376,6 +430,10 @@ $(document).ready(function () { if ($(this).prop('checked') == true) { $('#businesstrip').prop('checked', false); $('.businesstrip-div').hide(); + $('#timerecordingCar_id').val(''); + $('.car-div').find('input').prop("required", false); + $('.car-div').find('input').val(''); + $('.car-div').hide(); $('#businesstrip_info').hide(); $('#businesstrip_info').val(''); $('#businesstrip_info').prop('required', false); @@ -414,6 +472,19 @@ $(document).ready(function () { }); + $("body").on("change", "#timerecordingCar_id", function () { + if ($('#timerecordingCar_id').val() == "") { + $('.car-div').find('input').prop("required", false); + $('.car-div').find('input').val(''); + $('.car-div').hide(); + $('.car-div-car').show(); + } else { + $('.car-div').show(); + $('.car-div').find('input').prop("required", true); + $('#mileage_start').val($(this).find(':selected').data('mileagenow')); + } + }); + $("body").on("click", ".delete-item", function () { if (confirm('Buchung wirklich löschen?')) { $.post(deleteUrl, { @@ -430,12 +501,16 @@ $(document).ready(function () { $('#alert-box').remove(); var businesstrip = false; var homeoffice = false; + var car = false; if ($('#businesstrip').prop('checked') == true) { businesstrip = 1; } if ($('#homeoffice').prop('checked') == true) { homeoffice = 1; } + if ($.trim($('#timerecordingCar_id').val())) { + car = 1; + } $.post(insertUrl, { id: $.trim($('#id').val()), timerecordingCategory_id: $.trim($('#timerecordingCategory_id').val()), @@ -446,6 +521,9 @@ $(document).ready(function () { comment: $.trim($('#comment').val()), businesstrip: businesstrip, businesstrip_info: $.trim($('#businesstrip_info').val()), + timerecordingCar_id: $.trim($('#timerecordingCar_id').val()), + mileage_start: $.trim($('#mileage_start').val()), + mileage_end: $.trim($('#mileage_end').val()), homeoffice: homeoffice, hourday: $.trim($('#timerecordingCategory_id').find(':selected').data('hourday')), ajax: 1 @@ -459,10 +537,13 @@ $(document).ready(function () {
    Erfolgreich
    ` + result.message + `
    `); - $('#businesstrip').prop('checked', false); - $('#businesstrip_info').hide(); - $('#businesstrip_info').val(''); - $('#businesstrip_info').prop('required', false); + if ($.trim($('#mileage_start').val())) { + $('#timerecordingCar_id').find(':selected').data('mileagenow', $.trim($('#mileage_end').val())); + } + if (car == 1) { + $('#timerecordingCar_id').val('').change(); + } + } if (result.state === "error") { $('.wrapper .container-fluid').prepend(`
    diff --git a/public/js/pages/timerecordingReport/index.js b/public/js/pages/timerecordingReport/index.js index 92396fffd..c4f89993a 100644 --- a/public/js/pages/timerecordingReport/index.js +++ b/public/js/pages/timerecordingReport/index.js @@ -250,6 +250,22 @@ $(document).ready(function () { $('#days-div').show(); $('#days').prop("required", true); + } else if (parseInt($(this).find(':selected').data('hourday')) === 7) { + $("#endtime-div").show(); + $("#endtime-div").find('input').each(function () { + $(this).prop("required", true); + $(this).prop("disabled", false); + }); + $("#enddate-div").hide(); + $("#enddate-div").find('input').each(function () { + $(this).prop("required", false); + $(this).prop("min", ''); + $(this).val(''); + }) + $('#businesstrip_info').val(''); + $('#businesstrip_info').show(); + $('.car-div-car').show(); + } if (parseInt($(this).find(':selected').data('comment')) === 1) { $('#comment').prop("required", true); @@ -262,10 +278,25 @@ $(document).ready(function () { $('#businesstrip').prop("checked", false); $('#businesstrip_info').val(''); $('#businesstrip_info').hide(); + $('.car-div').find('input').prop("required", false); + $('.car-div').find('input').val(''); + $('#timerecordingCar_id').val('').change(); + $('.car-div').hide(); + } else if (parseInt($(this).find(':selected').data('hourday')) === 7) { + $('.businesstrip-div').show(); + $('.businesstrip-check-div').hide(); + $('#businesstrip').prop("checked", true); + $('#businesstrip_info').show(); + $('#businesstrip_info').prop('required', true); + $('#homeoffice-div').hide(); } else { $('.businesstrip-div').hide(); $('#businesstrip').prop("checked", false); $('#businesstrip_info').val(''); + $('#timerecordingCar_id').val('').change(); + $('.car-div').find('input').prop("required", false); + $('.car-div').find('input').val(''); + $('.car-div').hide(); $('#businesstrip_info').hide(); } @@ -342,12 +373,25 @@ $(document).ready(function () { $('#businesstrip_info').show(); $('#businesstrip_info').prop('required', true); $('#homeoffice-div').hide(); + $('#timerecordingCar_id').val('').change(); } if ($(this).data('homeoffice') == 1) { $('.businesstrip-div').hide(); $('#homeoffice').prop("checked", true); $('#homeoffice-div').show(); } + if ($(this).data('car')) { + + $('#timerecordingCar_id').val($(this).data('car')).change(); + if ($(this).data('mileagestart')) { + $('.car-div').show(); + $('.car-div').find('input').prop("required", true); + $('#mileage_start').val($(this).data('mileagestart')); + $('#mileage_end').val($(this).data('mileageend')); + } else { + + } + } $('.alert-success').remove(); window.scrollTo(0, 0); }); @@ -365,6 +409,10 @@ $(document).ready(function () { $('#businesstrip_info').val(''); $('#businesstrip_info').hide(); $('#homeoffice').prop("checked", false); + $('.car-div').hide(); + $('.car-div').find('input').val(''); + $('.car-div').find('input').prop("required", false); + $('#timerecordingCar_id').val('').change(); $('#timerecordingCategory_id').change(); }); @@ -431,7 +479,7 @@ $(document).ready(function () { $('#businesstrip_info').prop('required', true); $('#homeoffice').prop('checked', false); $('#homeoffice-div').hide(); - + $('.car-div-car').show(); } else { $('#businesstrip_info').hide(); $('#businesstrip_info').val(''); @@ -445,6 +493,10 @@ $(document).ready(function () { if ($(this).prop('checked') == true) { $('#businesstrip').prop('checked', false); $('.businesstrip-div').hide(); + $('#timerecordingCar_id').val(''); + $('.car-div').find('input').prop("required", false); + $('.car-div').find('input').val(''); + $('.car-div').hide(); $('#businesstrip_info').hide(); $('#businesstrip_info').val(''); $('#businesstrip_info').prop('required', false); @@ -456,6 +508,19 @@ $(document).ready(function () { }); + $("body").on("change", "#timerecordingCar_id", function () { + if ($('#timerecordingCar_id').val() == "") { + $('.car-div').find('input').prop("required", false); + $('.car-div').find('input').val(''); + $('.car-div').hide(); + $('.car-div-car').show(); + } else { + $('.car-div').show(); + $('.car-div').find('input').prop("required", true); + $('#mileage_start').val($(this).find(':selected').data('mileagenow')); + } + }); + $("body").on("click", ".delete-item", function () { if (confirm('Buchung wirklich löschen?')) { $.post(deleteUrl, { @@ -474,12 +539,16 @@ $(document).ready(function () { userid = $('#user_id_select').val(); var businesstrip = false; var homeoffice = false; + var car = false; if ($('#businesstrip').prop('checked') == true) { businesstrip = 1; } if ($('#homeoffice').prop('checked') == true) { homeoffice = 1; } + if ($.trim($('#timerecordingCar_id').val())) { + car = 1; + } $.post(insertUrl, { id: $.trim($('#id').val()), user_id: userid, @@ -492,6 +561,9 @@ $(document).ready(function () { comment: $.trim($('#comment').val()), businesstrip: businesstrip, businesstrip_info: $.trim($('#businesstrip_info').val()), + timerecordingCar_id: $.trim($('#timerecordingCar_id').val()), + mileage_start: $.trim($('#mileage_start').val()), + mileage_end: $.trim($('#mileage_end').val()), homeoffice: homeoffice, hourday: $.trim($('#timerecordingCategory_id').find(':selected').data('hourday')), ajax: 1 @@ -505,6 +577,12 @@ $(document).ready(function () {
    Erfolgreich
    ` + result.message + `
    `); + if ($.trim($('#mileage_start').val())) { + $('#timerecordingCar_id').find(':selected').data('mileagenow', $.trim($('#mileage_end').val())); + } + if (car == 1) { + $('#timerecordingCar_id').val('').change(); + } $('#businesstrip').prop('checked', false); $('#businesstrip_info').hide(); $('#businesstrip_info').val('');