Merge branch 'spidev' into 'master'

Zeiterfassung Fahrzeugverwaltung neue Features:

See merge request fronk/thetool!1114
This commit is contained in:
Daniel Spitzer
2025-03-13 20:28:59 +00:00
15 changed files with 1237 additions and 234 deletions
@@ -56,10 +56,14 @@ class TimerecordingCarController extends mfBaseController
protected function detailAction()
{
$timerecordingcarid = $this->request->id;
$timeRecordingCarMileageHistory = TimerecordingCarMileageHistoryModel::search(["timerecordingCar_id" => $timerecordingcarid]);
$timerecordingCarJournal=TimerecordingCarJournalModel::search(["timerecordingCar_id" => $timerecordingcarid]);
$mimetypes = TimerecordingCarDocumentsModel::$mimetypes;
$timerecordingcarDokuments = TimerecordingCarDocumentsModel::search(["timerecordingCar_id" => $timerecordingcarid]);
$this->layout()->set("mimetypes", $mimetypes);
$this->layout()->set("timerecordingcarDokuments", $timerecordingcarDokuments);
$this->layout()->set("timeRecordingCarMileageHistory", $timeRecordingCarMileageHistory);
$this->layout()->set("timerecordingCarJournal", $timerecordingCarJournal);
$this->layout()->setTemplate("TimerecordingCar/Detail");
$timerecordingcar = TimerecordingCarModel::getOne($timerecordingcarid);
$this->layout()->set("timerecordingcar", $timerecordingcar);
@@ -127,6 +131,7 @@ class TimerecordingCarController extends mfBaseController
protected function saveAction()
{
$r = $this->request;
$journal = trim($r->journal);
$id = $r->id;
//var_dump($r->get());exit;
if (is_numeric($id) && $id > 0) {
@@ -143,6 +148,12 @@ class TimerecordingCarController extends mfBaseController
$data = [];
$data['number_plate'] = trim($r->number_plate);
$data['user_id'] = trim($r->user_id);
$data['service_interval'] = trim($r->service_interval);
$data['tires_at'] = trim($r->tires_at);
$data['summer_tires'] = trim($r->summer_tires);
$data['winter_tires'] = trim($r->winter_tires);
$data['oil_type'] = trim($r->oil_type);
$data['service_station'] = trim($r->service_station);
$data['type'] = trim($r->type);
$data['brand'] = trim($r->brand);
$data['model'] = trim($r->model);
@@ -157,6 +168,24 @@ class TimerecordingCarController extends mfBaseController
if (!$data['user_id'] || $data['user_id'] == "-") {
$data['user_id'] = null;
}
if (!$data['service_interval']) {
$data['service_interval'] = null;
}
if (!$data['tires_at']) {
$data['tires_at'] = null;
}
if (!$data['summer_tires']) {
$data['summer_tires'] = null;
}
if (!$data['winter_tires']) {
$data['winter_tires'] = null;
}
if (!$data['oil_type']) {
$data['oil_type'] = null;
}
if (!$data['service_station']) {
$data['service_station'] = null;
}
if (!$data['initial_approval']) {
$data['initial_approval'] = null;
}
@@ -193,17 +222,51 @@ class TimerecordingCarController extends mfBaseController
// var_dump($upload);
// exit;
if ($mode == "edit") {
if ($timerecordingcars->mileage_now != $data['mileage']) {
$mileage_timestamp = $r->mileage_timestamp;
if (!$mileage_timestamp) {
$data['mileage_timestamp'] = time();
} else {
$data['mileage_timestamp'] = strtotime($mileage_timestamp);
}
$datamileageHistory = [];
$datamileageHistory['timerecordingCar_id'] = $timerecordingcars->id;
$datamileageHistory['mileage'] = $timerecordingcars->mileage_now;
if ($timerecordingcars->mileage_timestamp) {
$datamileageHistory['mileage_timestamp'] = $timerecordingcars->mileage_timestamp;
} else {
$datamileageHistory['mileage_timestamp'] = $timerecordingcars->edit;
}
$timerecordingcarsMilageHistory = TimerecordingCarMileageHistoryModel::create($datamileageHistory);
$timerecordingcarsMilageHistory->save();
}
$timerecordingcars->update($data);
} else {
if ($data['mileage'] != null) {
$data['mileage_timestamp'] = time();
}
$timerecordingcars = TimerecordingCarModel::create($data);
}
// var_dump($filestore);
// exit;
$id = $timerecordingcars->save();
if ($journal) {
$journal_timestamp = $r->journal_timestamp;
$dataJournal = [];
$dataJournal['timerecordingCar_id'] = $id;
$dataJournal['journal'] = $journal;
if ($journal_timestamp) {
$dataJournal['timestamp'] = strtotime($journal_timestamp);
} else {
$dataJournal['timestamp'] = time();
}
$timerecordingcarJournal = TimerecordingCarJournalModel::create($dataJournal);
$timerecordingcarJournal->save();
}
$returnUrl = "TimerecordingCar";
$returnAction = "Index";
$returnVariables = array();
@@ -216,8 +279,7 @@ class TimerecordingCarController extends mfBaseController
$returnVariables['hash'] = $this->request->hash;
}
} else
{
} else {
if ($this->request->hash) {
$returnAnker = $this->request->hash;
@@ -15,6 +15,12 @@ class TimerecordingCarModel
private $first_approval;
private $timerecording;
private $retired;
private $service_interval;
private $tires_at;
private $summer_tires;
private $winter_tires;
private $oil_type;
private $service_station;
private $retired_date;
private $edit_by;
@@ -0,0 +1,60 @@
<?php
class TimerecordingCarJournal extends mfBaseModel
{
private $editor;
private $creator;
private $TimerecordingCar;
public function getProperty($name)
{
if ($this->$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;
}
}
@@ -0,0 +1,131 @@
<?php
class TimerecordingCarJournalController 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("TimerecordingCarJournal/Index");
$timerecordingcarjournals = TimerecordingCarJournalModel::getAll();
$this->layout()->set("timerecordingcarjournals", $timerecordingcarjournals);
}
protected function addAction()
{
$TimerecordingCars=TimerecordingCarModel::getAll();
$this->layout()->set("TimerecordingCars", $TimerecordingCars);
$this->layout()->setTemplate("TimerecordingCarJournal/Form");
}
protected function editAction()
{
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("g nicht gefunden", "error");
$this->redirect("TimerecordingCarJournal");
}
$timerecordingcarjournals = new TimerecordingCarJournal($id);
if ($timerecordingcarjournals->id != $id) {
$this->layout()->setFlash("g nicht gefunden", "error");
$this->redirect("TimerecordingCarJournal");
}
$this->layout()->set("timerecordingcarjournals", $timerecordingcarjournals);
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";
$timerecordingcarjournals = new TimerecordingCarJournal($id);
if (!$timerecordingcarjournals->id) {
$this->layout()->setFlash("g nicht gefunden", "error");
$this->redirect("TimerecordingCarJournal");
}
} else {
$mode = "add";
}
$data = [];
$data['TimerecordingCar_id'] = trim($r->TimerecordingCar_id);
$data['journal'] = trim($r->journal);
$data['timestamp'] = trim($r->timestamp);
if (!$data['TimerecordingCar_id']) {
$data['TimerecordingCar_id']=NULL;
}
if (!$data['journal']) {
$data['journal']=NULL;
}
if (!$data['timestamp']) {
$data['timestamp']=NULL;
}
// var_dump($_FILES);
// var_dump($upload);
// exit;
if ($mode == "edit") {
$timerecordingcarjournals->update($data);
} else {
$timerecordingcarjournals = TimerecordingCarJournalModel::create($data);
}
// var_dump($filestore);
// exit;
$id = $timerecordingcarjournals->save();
if (!$id) {
$this->layout()->setFlash("g konnte nicht angelegt werden", "error");
$this->redirect("TimerecordingCarJournal");
}
if ($mode == "edit") {
$this->layout()->setFlash("g erfolgreich geändert", "success");
} else if ($mode = "add") {
$this->layout()->setFlash("g erfolgreich angelegt", "success");
}
$this->redirect("TimerecordingCarJournal");
}
protected function deleteAction()
{
$id = $this->request->id;
$timerecordingcarjournals = new TimerecordingCarJournal($id);
if (!$timerecordingcarjournals->id || $timerecordingcarjournals->id != $id) {
$this->layout()->setFlash("g nicht gefunden.", "error");
$this->redirect("TimerecordingCarJournal");
}
$timerecordingcarjournals->delete();
$this->redirect("TimerecordingCarJournal");
}
}
@@ -0,0 +1,127 @@
<?php
class TimerecordingCarJournalModel
{
private $timerecordingCar_id;
private $journal;
private $timestamp;
public static function find($data)
{
}
public static function create(array $data)
{
$model = new TimerecordingCarJournal();
foreach ($data as $field => $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("TimerecordingCarJournal", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new TimerecordingCarJournal($data);
}
return $item;
}
public static function getAll()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("TimerecordingCarJournal", "*", "1=1");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new TimerecordingCarJournal($data);
}
}
return $items;
}
public static function getFirst()
{
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("TimerecordingCarJournal", "*", "$where ");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new TimerecordingCarJournal($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("TimerecordingCarJournal", "*", "$where ORDER by timestamp DESC");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new TimerecordingCarJournal($data);
}
}
return $items;
}
private static function getSqlFilter($filter)
{
$where = "1=1 ";
//var_dump($filter);exit;
if (array_key_exists("timerecordingCar_id", $filter)) {
$timerecordingCar_id = $filter['timerecordingCar_id'];
if (is_numeric($timerecordingCar_id)) {
$where .= " AND timerecordingCar_id=$timerecordingCar_id";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}
@@ -0,0 +1,60 @@
<?php
class TimerecordingCarMileageHistory extends mfBaseModel
{
private $editor;
private $creator;
private $TimerecordingCar;
public function getProperty($name)
{
if ($this->$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;
}
}
@@ -0,0 +1,129 @@
<?php
class TimerecordingCarMileageHistoryController 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("TimerecordingCarMileageHistory/Index");
$timerecordingcarmileagehistorys = TimerecordingCarMileageHistoryModel::getAll();
$this->layout()->set("timerecordingcarmileagehistorys", $timerecordingcarmileagehistorys);
}
protected function addAction()
{
$TimerecordingCars=TimerecordingCarModel::getAll();
$this->layout()->set("TimerecordingCars", $TimerecordingCars);
$this->layout()->setTemplate("TimerecordingCarMileageHistory/Form");
}
protected function editAction()
{
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Kilometer History nicht gefunden", "error");
$this->redirect("TimerecordingCarMileageHistory");
}
$timerecordingcarmileagehistorys = new TimerecordingCarMileageHistory($id);
if ($timerecordingcarmileagehistorys->id != $id) {
$this->layout()->setFlash("Kilometer History nicht gefunden", "error");
$this->redirect("TimerecordingCarMileageHistory");
}
$this->layout()->set("timerecordingcarmileagehistorys", $timerecordingcarmileagehistorys);
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";
$timerecordingcarmileagehistorys = new TimerecordingCarMileageHistory($id);
if (!$timerecordingcarmileagehistorys->id) {
$this->layout()->setFlash("Kilometer History nicht gefunden", "error");
$this->redirect("TimerecordingCarMileageHistory");
}
} else {
$mode = "add";
}
$data = [];
$data['TimerecordingCar_id'] = trim($r->TimerecordingCar_id);
$data['mileage'] = trim($r->mileage);
if (!$data['TimerecordingCar_id']) {
$this->layout()->setFlash("Fahrzeug darf nicht leer sein", "error");
$this->redirect("TimerecordingCarMileageHistory");
}
if (!$data['mileage']) {
$this->layout()->setFlash("Kilometer darf nicht leer sein", "error");
$this->redirect("TimerecordingCarMileageHistory");
}
// var_dump($_FILES);
// var_dump($upload);
// exit;
if ($mode == "edit") {
$timerecordingcarmileagehistorys->update($data);
} else {
$timerecordingcarmileagehistorys = TimerecordingCarMileageHistoryModel::create($data);
}
// var_dump($filestore);
// exit;
$id = $timerecordingcarmileagehistorys->save();
if (!$id) {
$this->layout()->setFlash("Kilometer History konnte nicht angelegt werden", "error");
$this->redirect("TimerecordingCarMileageHistory");
}
if ($mode == "edit") {
$this->layout()->setFlash("Kilometer History erfolgreich geändert", "success");
} else if ($mode = "add") {
$this->layout()->setFlash("Kilometer History erfolgreich angelegt", "success");
}
$this->redirect("TimerecordingCarMileageHistory");
}
protected function deleteAction()
{
$id = $this->request->id;
$timerecordingcarmileagehistorys = new TimerecordingCarMileageHistory($id);
if (!$timerecordingcarmileagehistorys->id || $timerecordingcarmileagehistorys->id != $id) {
$this->layout()->setFlash("Kilometer History nicht gefunden.", "error");
$this->redirect("TimerecordingCarMileageHistory");
}
$timerecordingcarmileagehistorys->delete();
$this->redirect("TimerecordingCarMileageHistory");
}
}
@@ -0,0 +1,131 @@
<?php
class TimerecordingCarMileageHistoryModel
{
private $timerecordingCar_id;
private $mileage;
private $mileage_timestamp;
private $create_by;
private $edit_by;
private $create;
private $edit;
public static function find($data)
{
}
public static function create(array $data)
{
$model = new TimerecordingCarMileageHistory();
foreach ($data as $field => $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("TimerecordingCarMileageHistory", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new TimerecordingCarMileageHistory($data);
}
return $item;
}
public static function getAll()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("TimerecordingCarMileageHistory", "*", "1=1");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new TimerecordingCarMileageHistory($data);
}
}
return $items;
}
public static function getFirst()
{
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("TimerecordingCarMileageHistory", "*", "$where ");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new TimerecordingCarMileageHistory($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("TimerecordingCarMileageHistory", "*", "$where ORDER by mileage_timestamp DESC");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new TimerecordingCarMileageHistory($data);
}
}
return $items;
}
private static function getSqlFilter($filter)
{
$where = "1=1 ";
//var_dump($filter);exit;
if (array_key_exists("timerecordingCar_id", $filter)) {
$timerecordingCar_id = $filter['timerecordingCar_id'];
if (is_numeric($timerecordingCar_id)) {
$where .= " AND timerecordingCar_id=$timerecordingCar_id";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}