Zeiterfassung neues Feature:
Features für Project 7832: * Das Pickerldatum Zusatzfeld * Auftrennen PKW und Anhänger * Dokumente Upload * Standardsortierung * Ausgeschieden Flag mit Datum * zusätzliche migration
This commit is contained in:
@@ -16,6 +16,34 @@ class TimerecordingCarController extends mfBaseController
|
||||
}
|
||||
}
|
||||
|
||||
protected function apiAction()
|
||||
{
|
||||
$do = $this->request->do;
|
||||
|
||||
|
||||
switch ($do) {
|
||||
case "uploadDocuments":
|
||||
|
||||
$return = $this->uploadDocument();
|
||||
break;
|
||||
case "getDocuments":
|
||||
$return = $this->getDocuments();
|
||||
break;
|
||||
case "deleteDocument":
|
||||
$return = $this->deleteDocument();
|
||||
break;
|
||||
default:
|
||||
$return = false;
|
||||
}
|
||||
if (!is_array($return) || !count($return)) {
|
||||
$data = ["status" => "error"];
|
||||
$this->returnJson($data);
|
||||
}
|
||||
$data['status'] = "OK";
|
||||
$data['result'] = $return;
|
||||
$this->returnJson($data);
|
||||
}
|
||||
|
||||
protected function indexAction()
|
||||
{
|
||||
|
||||
@@ -28,6 +56,10 @@ class TimerecordingCarController extends mfBaseController
|
||||
protected function detailAction()
|
||||
{
|
||||
$timerecordingcarid = $this->request->id;
|
||||
$mimetypes = TimerecordingCarDocumentsModel::$mimetypes;
|
||||
$timerecordingcarDokuments = TimerecordingCarDocumentsModel::search(["timerecordingCar_id" => $timerecordingcarid]);
|
||||
$this->layout()->set("mimetypes", $mimetypes);
|
||||
$this->layout()->set("timerecordingcarDokuments", $timerecordingcarDokuments);
|
||||
$this->layout()->setTemplate("TimerecordingCar/Detail");
|
||||
$timerecordingcar = TimerecordingCarModel::getOne($timerecordingcarid);
|
||||
$this->layout()->set("timerecordingcar", $timerecordingcar);
|
||||
@@ -54,16 +86,44 @@ class TimerecordingCarController extends mfBaseController
|
||||
}
|
||||
|
||||
$timerecordingcars = new TimerecordingCar($id);
|
||||
$mimetypes = TimerecordingCarDocumentsModel::$mimetypes;
|
||||
$timerecordingcarDokuments = TimerecordingCarDocumentsModel::search(["timerecordingCar_id" => $id]);
|
||||
if ($timerecordingcars->id != $id) {
|
||||
$this->layout()->setFlash("Auto nicht gefunden", "error");
|
||||
$this->redirect("TimerecordingCar");
|
||||
}
|
||||
|
||||
|
||||
$this->layout()->set("mimetypes", $mimetypes);
|
||||
$this->layout()->set("timerecordingcarDokuments", $timerecordingcarDokuments);
|
||||
$this->layout()->set("timerecordingcars", $timerecordingcars);
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
protected function retireAction()
|
||||
{
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
$retired_date = $r->retired_date;
|
||||
if (is_numeric($id) && $id > 0) {
|
||||
$timerecordingcars = new TimerecordingCar($id);
|
||||
if (!$timerecordingcars->id) {
|
||||
$this->layout()->setFlash("Fahrzeug nicht gefunden", "error");
|
||||
$this->redirect("TimerecordingCar");
|
||||
}
|
||||
} else {
|
||||
$this->layout()->setFlash("Fahrzeug nicht gefunden", "error");
|
||||
$this->redirect("TimerecordingCar");
|
||||
}
|
||||
$data = [];
|
||||
$data['retired'] = 1;
|
||||
$data['retired_date'] = strtotime($retired_date);
|
||||
$data['edit_by'] = $this->me->id;
|
||||
$timerecordingcars->update($data);
|
||||
$timerecordingcars->save();
|
||||
$this->layout()->setFlash("Fahrzeug erfolgreich ausgeschieden", "success");
|
||||
$this->redirect("TimerecordingCar");
|
||||
}
|
||||
|
||||
protected function saveAction()
|
||||
{
|
||||
$r = $this->request;
|
||||
@@ -83,12 +143,15 @@ class TimerecordingCarController extends mfBaseController
|
||||
$data = [];
|
||||
$data['number_plate'] = trim($r->number_plate);
|
||||
$data['user_id'] = trim($r->user_id);
|
||||
$data['type'] = trim($r->type);
|
||||
$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);
|
||||
$data['override_approval'] = strtotime(trim($r->override_approval));
|
||||
$data['edit_by'] = $this->me->id;
|
||||
|
||||
|
||||
if (!$data['user_id'] || $data['user_id'] == "-") {
|
||||
@@ -97,6 +160,9 @@ class TimerecordingCarController extends mfBaseController
|
||||
if (!$data['initial_approval']) {
|
||||
$data['initial_approval'] = null;
|
||||
}
|
||||
if (!$data['override_approval']) {
|
||||
$data['override_approval'] = null;
|
||||
}
|
||||
|
||||
if (!$data['timerecording']) {
|
||||
$data['timerecording'] = 0;
|
||||
@@ -176,4 +242,64 @@ class TimerecordingCarController extends mfBaseController
|
||||
$this->redirect("TimerecordingCar");
|
||||
}
|
||||
|
||||
protected function uploadDocument()
|
||||
{
|
||||
$r = $this->request;
|
||||
if (array_key_exists("timeRecordingCar", $_FILES) && !$_FILES['timeRecordingCar']['error']) {
|
||||
$upload_error = false;
|
||||
$upload = new mfUpload("timeRecordingCar");
|
||||
$upload->setSavepath(MFUPLOAD_FILE_SAVE_PATH . "/timeRecordingCar");
|
||||
if (!$upload->getSize()) {
|
||||
die();
|
||||
}
|
||||
$upload->save();
|
||||
$file_data = [];
|
||||
$file_data['name'] = $upload->getOriginalFilename();
|
||||
$file_data['filename'] = ($r->file_filename) ? $r->file_filename : $upload->getOriginalFilename();
|
||||
$file_data['subfolder'] = "timeRecordingCar";
|
||||
$file_data['store_filename'] = $upload->getFilename();
|
||||
$file_data['orig_filename'] = $upload->getOriginalFilename();
|
||||
|
||||
$file = FileModel::create($file_data);
|
||||
$file_id = $file->save();
|
||||
if (!$file_id) {
|
||||
die();
|
||||
} else {
|
||||
$data = [];
|
||||
$data['file_id'] = $file_id;
|
||||
$data['file_size'] = $upload->getSize();
|
||||
$data['timerecordingCar_id'] = $r->timerecordingCar_id;
|
||||
$data['name'] = $upload->getOriginalFilename();
|
||||
$timerecordingcardocumentss = TimerecordingCarDocumentsModel::create($data);
|
||||
$id = $timerecordingcardocumentss->save();
|
||||
}
|
||||
$result['success'] = true;
|
||||
$result['data']['file_id'] = $file_id;
|
||||
$result['data']['id'] = $id;
|
||||
} else {
|
||||
echo "error";
|
||||
}
|
||||
echo json_encode($result);
|
||||
die();
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function getDocuments()
|
||||
{
|
||||
$r = $this->request;
|
||||
$file_name = $r->file_name;
|
||||
$timerecordingCarDokument = TimerecordingCarDocumentsModel::search(["file_name" => $file_name]);
|
||||
return $timerecordingCarDokument->file_id;
|
||||
}
|
||||
|
||||
protected function deleteDocument()
|
||||
{
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
$timerecordingCarDokument = new TimerecordingCarDocuments($id);
|
||||
$timerecordingCarDokument->file->delete();
|
||||
$timerecordingCarDokument->delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
class TimerecordingCarModel
|
||||
{
|
||||
private $user_id;
|
||||
private $type;
|
||||
private $number_plate;
|
||||
private $brand;
|
||||
private $model;
|
||||
@@ -10,8 +11,19 @@ class TimerecordingCarModel
|
||||
private $mileage_now;
|
||||
private $mileage_timestamp;
|
||||
private $initial_approval;
|
||||
private $override_approval;
|
||||
private $first_approval;
|
||||
private $timerecording;
|
||||
private $retired;
|
||||
private $retired_date;
|
||||
private $edit_by;
|
||||
|
||||
|
||||
public static $carTypes = [
|
||||
"1" => "PKW",
|
||||
"2" => "Anhänger"
|
||||
];
|
||||
|
||||
|
||||
|
||||
public static function find($data)
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
class TimerecordingCarDocuments extends mfBaseModel
|
||||
{
|
||||
private $editor;
|
||||
private $creator;
|
||||
private $file;
|
||||
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,145 @@
|
||||
<?php
|
||||
|
||||
class TimerecordingCarDocumentsController 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("TimerecordingCarDocuments/Index");
|
||||
$timerecordingcardocumentss = TimerecordingCarDocumentsModel::getAll();
|
||||
$this->layout()->set("timerecordingcardocumentss", $timerecordingcardocumentss);
|
||||
|
||||
}
|
||||
|
||||
protected function addAction()
|
||||
{
|
||||
$files=FileModel::getAll();
|
||||
$this->layout()->set("files", $files);
|
||||
$timerecordingCars=TimerecordingCarModel::getAll();
|
||||
$this->layout()->set("timerecordingCars", $timerecordingCars);
|
||||
|
||||
$this->layout()->setTemplate("TimerecordingCarDocuments/Form");
|
||||
|
||||
}
|
||||
|
||||
protected function editAction()
|
||||
{
|
||||
$id = $this->request->id;
|
||||
|
||||
if (!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("bla nicht gefunden", "error");
|
||||
$this->redirect("TimerecordingCarDocuments");
|
||||
}
|
||||
|
||||
$timerecordingcardocumentss = new TimerecordingCarDocuments($id);
|
||||
if ($timerecordingcardocumentss->id != $id) {
|
||||
$this->layout()->setFlash("bla nicht gefunden", "error");
|
||||
$this->redirect("TimerecordingCarDocuments");
|
||||
}
|
||||
|
||||
$this->layout()->set("timerecordingcardocumentss", $timerecordingcardocumentss);
|
||||
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";
|
||||
$timerecordingcardocumentss = new TimerecordingCarDocuments($id);
|
||||
if (!$timerecordingcardocumentss->id) {
|
||||
$this->layout()->setFlash("gg nicht gefunden", "error");
|
||||
$this->redirect("TimerecordingCarDocuments");
|
||||
}
|
||||
} else {
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['file_id'] = trim($r->file_id);
|
||||
$data['file_size'] = trim($r->file_size);
|
||||
$data['timerecordingCar_id'] = trim($r->timerecordingCar_id);
|
||||
$data['name'] = trim($r->name);
|
||||
$data['description'] = trim($r->description);
|
||||
$data['sort'] = trim($r->sort);
|
||||
|
||||
|
||||
if (!$data['file_id']) {
|
||||
$data['file_id']=NULL;
|
||||
}
|
||||
if (!$data['file_size']) {
|
||||
$data['file_size']=NULL;
|
||||
}
|
||||
if (!$data['timerecordingCar_id']) {
|
||||
$data['timerecordingCar_id']=NULL;
|
||||
}
|
||||
if (!$data['name']) {
|
||||
$data['name']=NULL;
|
||||
}
|
||||
if (!$data['description']) {
|
||||
$data['description']=NULL;
|
||||
}
|
||||
if (!$data['sort']) {
|
||||
$data['sort']=NULL;
|
||||
}
|
||||
|
||||
|
||||
// var_dump($_FILES);
|
||||
// var_dump($upload);
|
||||
// exit;
|
||||
|
||||
|
||||
if ($mode == "edit") {
|
||||
$timerecordingcardocumentss->update($data);
|
||||
|
||||
} else {
|
||||
$timerecordingcardocumentss = TimerecordingCarDocumentsModel::create($data);
|
||||
}
|
||||
// var_dump($filestore);
|
||||
// exit;
|
||||
$id = $timerecordingcardocumentss->save();
|
||||
|
||||
if (!$id) {
|
||||
$this->layout()->setFlash("bla konnte nicht angelegt werden", "error");
|
||||
$this->redirect("TimerecordingCarDocuments");
|
||||
}
|
||||
|
||||
if ($mode == "edit") {
|
||||
$this->layout()->setFlash("bla erfolgreich geändert", "success");
|
||||
} else if ($mode = "add") {
|
||||
$this->layout()->setFlash("bla erfolgreich angelegt", "success");
|
||||
}
|
||||
$this->redirect("TimerecordingCarDocuments");
|
||||
}
|
||||
|
||||
|
||||
protected function deleteAction()
|
||||
{
|
||||
$id = $this->request->id;
|
||||
$timerecordingcardocumentss = new TimerecordingCarDocuments($id);
|
||||
if (!$timerecordingcardocumentss->id || $timerecordingcardocumentss->id != $id) {
|
||||
$this->layout()->setFlash("bla nicht gefunden.", "error");
|
||||
$this->redirect("TimerecordingCarDocuments");
|
||||
}
|
||||
|
||||
$timerecordingcardocumentss->delete();
|
||||
$this->redirect("TimerecordingCarDocuments");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
class TimerecordingCarDocumentsModel
|
||||
{
|
||||
private $file_id;
|
||||
private $file_size;
|
||||
private $timerecordingCar_id;
|
||||
private $name;
|
||||
private $description;
|
||||
private $sort;
|
||||
|
||||
public static $mimetypes = [
|
||||
'application/pdf' => 'fa-file-pdf',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'fa-file-doc',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'fa-file-xls',
|
||||
'application/octet-stream' => 'fa-file-csv',
|
||||
'text/csv' => 'fa-file-csv',
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'fa-file-ppt',
|
||||
'application/zip' => 'fa-file-zip',
|
||||
'application/x-zip-compressed' => 'fa-file-zip',
|
||||
'application/x-rar-compressed' => 'fa-file-archive',
|
||||
'application/x-7z-compressed' => 'fa-file-archive',
|
||||
'application/x-tar' => 'fa-file-archive',
|
||||
'application/x-gzip' => 'fa-file-archive',
|
||||
'application/x-bzip2' => 'fa-file-archive',
|
||||
'text/xml' => 'fa-file-xml',
|
||||
'application/xml' => 'fa-file-xml',
|
||||
'audio/mpeg' => 'fa-file-mp3',
|
||||
'image/png' => 'fa-file-png',
|
||||
'image/jpeg' => 'fa-file-jpg',
|
||||
];
|
||||
|
||||
public static function find($data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function create(array $data)
|
||||
{
|
||||
$model = new TimerecordingCarDocuments();
|
||||
|
||||
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("TimerecordingCarDocuments", "*", "id=$id LIMIT 1");
|
||||
if ($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new TimerecordingCarDocuments($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("TimerecordingCarDocuments", "*", "1=1");
|
||||
if ($db->num_rows($res)) {
|
||||
while ($data = $db->fetch_object($res)) {
|
||||
$items[] = new TimerecordingCarDocuments($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst()
|
||||
{
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("TimerecordingCarDocuments", "*", "$where ");
|
||||
if ($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new TimerecordingCarDocuments($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("TimerecordingCarDocuments", "*", "$where");
|
||||
if ($db->num_rows($res)) {
|
||||
while ($data = $db->fetch_object($res)) {
|
||||
$items[] = new TimerecordingCarDocuments($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter)
|
||||
{
|
||||
$where = "1=1 ";
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if (array_key_exists("file_name", $filter)) {
|
||||
$file_name = $filter['file_name'];
|
||||
$where .= " AND file_name=$file_name";
|
||||
}
|
||||
|
||||
if (array_key_exists("timerecordingCar_id", $filter)) {
|
||||
$timerecordingCar_id = $filter['timerecordingCar_id'];
|
||||
$where .= " AND timerecordingCar_id=$timerecordingCar_id";
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user