Merge branch 'master' into fronkdev

This commit is contained in:
Frank Schubert
2024-04-18 14:05:22 +02:00
106 changed files with 10509 additions and 211 deletions

View File

@@ -43,6 +43,7 @@ class DeviceController extends mfBaseController
$this->layout()->setTemplate("Device/Detail");
$devicesconfig = DeviceModel::getconifg($id);
$devices = DeviceModel::getOne($id);
$devicesall= DeviceModel::getAll();
if ($devices->devicetype->olt == "1") {
$customer = DeviceModel::getOltCustomer($device->ip);
@@ -52,6 +53,7 @@ class DeviceController extends mfBaseController
$this->layout()->set("devicesconfig", $devicesconfig);
$this->layout()->set("devices", $devices);
$this->layout()->set("devicesall", $devicesall);
$this->layout()->set("customer", $customer);
}
@@ -61,6 +63,7 @@ class DeviceController extends mfBaseController
$this->layout()->setTemplate("Device/Form");
$this->layout()->set("devicetypes", DevicetypeModel::getAll());
$this->layout()->set("pops", PopModel::getAll());
$this->layout()->set("devices", DeviceModel::getAll());
}
@@ -102,6 +105,7 @@ class DeviceController extends mfBaseController
$data = [];
$data['name'] = trim($r->name);
$data['devicetype_id'] = $r->devicetype_id;
$data['parent_id'] = $r->parent_id;
$data['autobackup'] = trim($r->autobackup);
if (trim($r->pop_id) == "0") {
@@ -132,6 +136,9 @@ class DeviceController extends mfBaseController
if ($data['autobackup'] != "1") {
$data['autobackup'] = "0";
}
if (!$data['parent_id']) {
$data['parent_id'] = NULL;
}
$data['ip'] = $r->ip;
$data['mac'] = $r->mac;
$data['serial'] = $r->serial;

View File

@@ -8,6 +8,7 @@ class DeviceModel
public $serial = null;
public $comment = null;
public $devicetype_id = null;
public $parent_id = null;
public $pop_id = null;
public $addr_street = null;
public $addr_number = null;

View File

@@ -0,0 +1,9 @@
<?php
/**
* @property mixed|null $name
*/
class Domain extends mfBaseModel
{
}

View File

@@ -0,0 +1,200 @@
<?php
class DomainController extends mfBaseController {
private User $me;
private string $INWX_USER = INWX_USER;
private string $INWX_PASS = INWX_PASS;
private string $PLESK_USER = PLESK_HOST;
private string $PLESK_AUTH = PLESK_AUTH;
private Inwx $inwx;
private Plesk $plesk;
protected function init(): void {
$me = new User();
$me->loadMe();
$this->layout()->set("me", $me);
$this->me = $me;
if (!$this->me->isAdmin()) {
$this->redirect("dashboard");
}
$this->inwx = new Inwx($this->INWX_USER, $this->INWX_PASS);
$this->plesk = new Plesk($this->PLESK_USER, $this->PLESK_AUTH);
}
protected function indexAction(): void {
$this->layout()->setTemplate("Domain/Index");
}
protected function apiAction() {
$do = $this->request->do;
if ($do !== "getConfig" && !$this->me->is("employee")) {
$this->redirect("dashboard");
}
switch ($do) {
case "importAllDomains":
$return = $this->importAllDomains();
break;
case "getDomains":
$return = $this->getAllDomains();
break;
case "getDomainContacts":
$return = $this->getDomainContacts();
break;
case "getDnsRecords":
$return = $this->getDnsRecords();
break;
case "checkDomain":
$return = $this->checkDomain();
break;
default:
$return = false;
break;
}
if (!$return) {
$return = [
"status" => "error",
"message" => "Invalid request."
];
}
die(json_encode($return));
}
protected function importDomain(): void {
// use plesk api to get all domains
}
protected function importAllDomains(): array {
try {
$inwxContact = $this->inwx->contactList();
$pleskDomains = $this->plesk->getAllDomains();
$inwxDomains = $this->inwx->domainList();
$domains = [];
$pleskDomainsArray = [];
foreach ($pleskDomains as $pleskDomain) {
$pleskDomainsArray[$pleskDomain['name']] = $pleskDomain;
}
foreach ($inwxDomains as $inwxDomain) {
if (isset($pleskDomainsArray[$inwxDomain['domain']])) {
$inwxDomain['plesk'] = [
"id" => $pleskDomainsArray[$inwxDomain['domain']]['id'],
"hosting_type" => $pleskDomainsArray[$inwxDomain['domain']]['hosting_type'],
"created" => strtotime($pleskDomainsArray[$inwxDomain['domain']]['created'])
];
}
$domains[] = $inwxDomain;
}
$domainsImport = DomainModel::importDomains($domains);
$contactsImport = DomainContactModel::importDomainContacts($inwxContact);
return [
"status" => "success",
"importMessages" => [
$domainsImport['message'],
$contactsImport['message']
],
];
} catch (Exception $e) {
$this->log->error("Error while importing domains: " . $e->getMessage());
return [
"status" => "error",
"message" => "Error while importing domains: " . $e->getMessage()
];
}
}
private function getAllDomains(): array {
$json = json_decode(file_get_contents('php://input'), true);
$filters = $json['filters'] ?? [];
$page = $json['pagination']['page'] ?? 1;
$perPage = $json['pagination']['per_page'] ?? 10;
$domains = DomainModel::getAllDomains($filters, $perPage, $perPage * $page - $perPage);
$totalRows = DomainModel::countDomains($filters);
return [
"rows" => $domains,
"pagination" => [
"page" => $page,
"total_pages" => ceil($totalRows / $perPage),
"per_page" => $perPage,
"total_rows" => intval($totalRows)
]
];
}
private function getDnsRecords() {
if (!empty($this->request->domain)) {
return ["status" => "error", "message" => "No domain specified."];
}
$domain = $this->request->domain;
return array_merge(
dns_get_record($domain, DNS_TXT),
dns_get_record($domain, DNS_A),
dns_get_record($domain, DNS_CNAME),
dns_get_record($domain, DNS_MX),
dns_get_record($domain, DNS_NS),
dns_get_record($domain, DNS_SOA),
dns_get_record($domain, DNS_SRV),
dns_get_record($domain, DNS_AAAA),
);
}
private function getDomainContacts(): array {
$domainContacts = [];
$dbDomainContacts = DomainContactModel::getAllDomainContacts();
foreach ($dbDomainContacts as $dbDomainContact) {
$domainContacts[$dbDomainContact['inwxRoId']] = $dbDomainContact;
}
return $domainContacts;
}
private function checkDomain(): array {
$domain = $this->request->domain;
if(empty($domain)) {
return ["status" => "error", "message" => "No domain or tld specified."];
}
try {
$domainCheck = $this->inwx->domainCheck($domain);
if($domainCheck['domain'][0]['status'] === "free") {
$domainPrice = $this->inwx->domainGetDomainPrice($domain, "reg");
} else {
$domainPrice = $this->inwx->domainGetDomainPrice($domain, "transfer");
}
$domainCheck['domain'][0]['price'] = $domainPrice;
return $domainCheck['domain'][0];
} catch (Exception $e) {
$this->log->error("Error while checking domain: " . $e->getMessage());
return ["status" => "error", "message" => "Error while checking domain: " . $e->getMessage()];
}
}
}

View File

@@ -0,0 +1,133 @@
<?php
class DomainModel {
public $inwxRoId;
public $domain;
public $period;
public $crDate;
public $exDate;
public $reDate;
public $upDate;
public $transferLock;
public $status;
public $authCode;
public $registrant;
public $admin;
public $tech;
public $billing;
public $ns;
public $pleskId;
public $pleskHostingType;
public $pleskCreated;
public function __construct($data = []) {
foreach ($data as $field => $value) {
if (property_exists(get_called_class(), $field)) {
$this->$field = $value;
}
}
}
public static function importDomains($domains): array {
$db = FronkDB::singleton();
$db->query("TRUNCATE TABLE `Domain`");
$sql = /** @lang text */
"INSERT INTO `Domain` (`inwxRoId`, `domain`, `period`, `crDate`, `exDate`, `reDate`, `upDate`, `transferLock`, `status`, `authCode`, `registrant`, `admin`, `tech`, `billing`, `ns`, `pleskId`, `pleskHostingType`, `pleskCreated`) VALUES ";
$values = [];
foreach ($domains as $domain) {
$valueStr = "(" .
$domain['roId'] . ", '" .
$domain['domain'] . "', '" .
$domain['period'] . "', " .
$domain['crDate']['timestamp'] . ", " .
(isset($domain['reDate']) ? $domain['reDate']['timestamp'] : "NULL") . ", " .
(isset($domain['reDate']) ? $domain['reDate']['timestamp'] : "NULL") . ", " .
$domain['upDate']['timestamp'] . ", " .
($domain['transferLock'] ? 1 : 0) . ", '" .
$domain['status'] . "', '" .
$domain['authCode'] . "', " .
$domain['registrant'] . ", " .
$domain['admin'] . ", " .
$domain['tech'] . ", " .
$domain['billing'] . ", '" .
implode(", ", $domain['ns']) . "', ";
// Check if 'pleskId' is set
if (isset($domain['plesk']) && is_array($domain['plesk'])) {
$valueStr .= $domain['plesk']['id'] . ", ";
$valueStr .= "'" . $domain['plesk']['hosting_type'] . "', ";
$valueStr .= $domain['plesk']['created'];
} else {
$valueStr .= "NULL, NULL, NULL";
}
$values[] = $valueStr . ")";
}
$sql .= implode(", ", $values);
$db->query($sql);
return [
"message" => "Imported " . count($domains) . " domains."
];
}
/**
* Generate SQL Filter condition (space separated) for a given column.
*
* @param string|null $filterValue The filter value to match against.
* @param string $columnName The name of the column in the database table.
* @return string The SQL condition generated based on the filter value and column name.
*/
public static function generateFilterCondition(?string $filterValue, string $columnName): string {
$sql = "";
if (!empty($filterValue)) {
$filterItems = explode(" ", $filterValue);
foreach ($filterItems as $item) {
$sql .= " AND `$columnName` LIKE '%" . $item . "%'";
}
}
return $sql;
}
public static function getSqlFilter($filters): string {
$sql = isset($filters['domain']) ? self::generateFilterCondition($filters['domain'], "domain") : "";
$sql .= isset($filters['crDate']) ? " AND `crDate` = " . $filters['crDate'] : "";
$sql .= isset($filters['exDate']) ? " AND `exDate` = " . $filters['exDate'] : "";
$sql .= isset($filters['reDate']) ? " AND `reDate` = " . $filters['reDate'] : "";
$sql .= isset($filters['upDate']) ? " AND `upDate` = " . $filters['upDate'] : "";
$sql .= isset($filters['status']) ? " AND `status` = '" . $filters['status'] . "'" : "";
$sql .= isset($filters['transferLock']) && $filters['transferLock'] == 1 ? " AND `transferLock` = true" : "";
$sql .= isset($filters['authCode']) ? self::generateFilterCondition($filters['authCode'], "authCode") : "";
$sql .= isset($filters['registrant']) && $filters['registrant'] !== 'all' ? " AND `registrant` = " . $filters['registrant'] : "";
$sql .= isset($filters['admin']) && $filters['admin'] !== 'all' ? " AND `admin` = " . $filters['admin'] : "";
$sql .= isset($filters['tech']) && $filters['tech'] !== 'all' ? " AND `tech` = " . $filters['tech'] : "";
$sql .= isset($filters['billing']) && $filters['billing'] !== 'all' ? " AND `billing` = " . $filters['billing'] : "";
$sql .= isset($filters['ns']) ? self::generateFilterCondition($filters['ns'], "ns") : "";
return $sql;
}
public static function getAllDomains($filters, $limit = null, $offset = 0): array {
$db = FronkDB::singleton();
$sql = "SELECT * FROM `Domain` WHERE 1 " . self::getSqlFilter($filters);
$sql .= $limit === null ? "" : " LIMIT " . $limit . " OFFSET " . $offset;
$result = $db->query($sql);
$rows = [];
while ($row = $result->fetch_assoc()) {
$rows[] = new DomainModel($row);
}
return $rows;
}
public static function countDomains($filters) {
$db = FronkDB::singleton();
$sql = "SELECT COUNT(*) as `total_rows` FROM `Domain` WHERE 1 " . self::getSqlFilter($filters);
$result = $db->query($sql);
return $result->fetch_assoc()['total_rows'];
}
}

View File

@@ -0,0 +1,8 @@
<?php
/**
* @property mixed|null $name
*/
class DomainContact extends mfBaseModel {
}

View File

@@ -0,0 +1,121 @@
<?php
class DomainContactModel {
public $id;
public $roId;
public $type;
public $name;
public $street;
public $city;
public $pc;
public $cc;
public $voice;
public $email;
public $protection;
public $usedCount;
public $verificationStatus;
public function __construct($data = []) {
foreach ($data as $field => $value) {
if (property_exists(get_called_class(), $field)) {
$this->$field = $value;
}
}
}
public static function importDomainContacts($domainContacts): array {
$db = FronkDB::singleton();
$db->query("TRUNCATE TABLE `DomainContact`");
$sql = /** @lang text */
"INSERT INTO `DomainContact` (`inwxRoId`, `type`, `name`, `street`, `city`, `pc`, `cc`, `voice`, `email`, `protection`, `verificationStatus`, `usedCount`) VALUES ";
$values = [];
foreach ($domainContacts as $domainContact) {
$valueStr = "(" .
$domainContact['roId'] . ", '" .
$domainContact['type'] . "', '" .
$domainContact['name'] . "', '" .
$domainContact['street'] . "', '" .
$domainContact['city'] . "', '" .
$domainContact['pc'] . "', '" .
$domainContact['cc'] . "', '" .
$domainContact['voice'] . "', '" .
$domainContact['email'] . "', " .
($domainContact['protection'] ? 1 : 0) . ", '" .
$domainContact['verificationStatus'] . "', ";
$valueStr .= $domainContact['usedCount'] ?? "NULL";
$valueStr .= ")";
$values[] = $valueStr;
}
$sql .= implode(", ", $values);
$db->query($sql);
return [
"message" => "Imported " . count($domainContacts) . " domain contacts."
];
}
/**
* Generate SQL Filter condition (space separated) for a given column.
*
* @param string|null $filterValue The filter value to match against.
* @param string $columnName The name of the column in the database table.
* @return string The SQL condition generated based on the filter value and column name.
*/
public static function generateFilterCondition(?string $filterValue, string $columnName): string {
$sql = "";
if (!empty($filterValue)) {
$filterItems = explode(" ", $filterValue);
foreach ($filterItems as $item) {
$sql .= " AND `$columnName` LIKE '%" . $item . "%'";
}
}
return $sql;
}
public static function getSqlFilter($filters): string {
$sql = isset($filters['roId']) ? " AND `inwxRoId` = " . $filters['roId'] : "";
$sql .= isset($filters['type']) ? " AND `type` = '" . $filters['type'] . "'" : "";
$sql .= isset($filters['name']) ? self::generateFilterCondition($filters['name'], "name") : "";
$sql .= isset($filters['street']) ? self::generateFilterCondition($filters['street'], "street") : "";
$sql .= isset($filters['city']) ? self::generateFilterCondition($filters['city'], "city") : "";
$sql .= isset($filters['pc']) ? " AND `pc` = " . $filters['pc'] : "";
$sql .= isset($filters['cc']) ? " AND `cc` = " . $filters['cc'] : "";
$sql .= isset($filters['voice']) ? " AND `voice` = " . $filters['voice'] : "";
$sql .= isset($filters['email']) ? self::generateFilterCondition($filters['email'], "email") : "";
$sql .= isset($filters['protection']) ? " AND `protection` = " . $filters['protection'] : "";
$sql .= isset($filters['usedCount']) ? " AND `usedCount` = " . $filters['usedCount'] : "";
$sql .= isset($filters['verificationStatus']) ? " AND `verificationStatus` = '" . $filters['verificationStatus'] . "'" : "";
return $sql;
}
public static function getAllDomainContacts($filters = null, $limit = null, $offset = 0, $raw_array = true): array {
$db = FronkDB::singleton();
$sql = "SELECT * FROM `DomainContact` WHERE 1 ";
$sql .= $filters === null ? "" : self::getSqlFilter($filters);
$sql .= $limit === null ? "" : " LIMIT " . $limit . " OFFSET " . $offset;
$result = $db->query($sql);
$rows = [];
while ($row = $result->fetch_assoc()) {
$rows[] = $raw_array ? $row : new DomainContactModel($row);
}
return $rows;
}
public static function countDomainContacts($filters) {
$db = FronkDB::singleton();
$sql = "SELECT COUNT(*) as `total_rows` FROM `DomainContact` WHERE 1 " . self::getSqlFilter($filters);
$result = $db->query($sql);
return $result->fetch_assoc()['total_rows'];
}
}

View File

@@ -0,0 +1,59 @@
<?php
class FiberPlanDispatcher extends mfBaseModel
{
private $editor;
private $network;
private $creator;
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;
}
}

View File

@@ -0,0 +1,182 @@
<?php
class FiberPlanDispatcherController 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("FiberPlanDispatcher/Index");
$fiberplandispatchers = FiberPlanDispatcherModel::getAll();
$this->layout()->set("fiberplandispatchers", $fiberplandispatchers);
}
protected function addAction()
{
$this->layout()->setTemplate("FiberPlanDispatcher/Form");
$networks = NetworkModel::getAll();
$this->layout()->set("networks", $networks);
$networkaddresses = NetworkAddressModel::getAll();
$this->layout()->set("networkaddresses", $networkaddresses);
}
protected function editAction()
{
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Verteiler/Schacht nicht gefunden", "error");
$this->redirect("FiberPlanDispatcher");
}
$fiberplandispatchers = new FiberPlanDispatcher($id);
if ($fiberplandispatchers->id != $id) {
$this->layout()->setFlash("Verteiler/Schacht nicht gefunden", "error");
$this->redirect("FiberPlanDispatcher");
}
$this->layout()->set("fiberplandispatchers", $fiberplandispatchers);
if ($fiberplandispatchers->object_type == "2") {
$sleeves = FiberPlanDispatchersleeveModel::getAllbyDispatcher($id);
$this->layout()->set("sleeves", $sleeves);
}
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";
$fiberplandispatcher = new FiberPlanDispatcher($id);
if (!$fiberplandispatcher->id) {
$this->layout()->setFlash("Verteiler/Schacht nicht gefunden", "error");
$this->redirect("FiberPlanDispatcher");
}
} else {
$mode = "add";
}
$data = [];
$data['network_id'] = trim($r->network_id);
$data['object_type'] = trim($r->object_type);
$data['description'] = trim($r->description);
if ($r->type) {
$data['type'] = trim($r->type);
}
if ($r->gps_lat) {
$data['gps_lat'] = trim($r->gps_lat);
}
if ($r->gps_long) {
$data['gps_long'] = trim($r->gps_long);
}
if ($r->comment) {
$data['comment'] = trim($r->comment);
}
if (!$data['network_id']) {
$this->layout()->setFlash("Netzgebiet darf nicht leer sein", "error");
$this->redirect("FiberPlanDispatcher");
}
if (!$data['object_type']) {
$this->layout()->setFlash("Objekt Typ darf nicht leer sein", "error");
$this->redirect("FiberPlanDispatcher");
}
if (!$data['description']) {
$this->layout()->setFlash("Beschreibung darf nicht leer sein", "error");
$this->redirect("FiberPlanDispatcher");
}
// var_dump($_FILES);
// var_dump($upload);
// exit;
if ($mode == "edit") {
$fiberplandispatcher->update($data);
} else {
$fiberplandispatcher = FiberPlanDispatcherModel::create($data);
}
// var_dump($filestore);
// exit;
$id = $fiberplandispatcher->save();
if ($mode == "edit") {
if ($data['object_type'] == "2") {
FiberPlanDispatchersleeveModel::deletebyDispatcher($id);
$sleeves = $r->sleeves;
$sleevedata = [];
if (is_array($sleeves)) {
foreach ($sleeves as $sleeve) {
$sleevedata['name'] = trim($sleeve);
$sleevedata['fiberPlanDispatcher_id'] = $id;
$fiberplandispatchersleeve = FiberPlanDispatchersleeveModel::create($sleevedata);
$fiberplandispatchersleeve->save();
}
}
}
} else {
if ($data['object_type'] == "2") {
$sleeves = $r->sleeves;
$sleevedata = [];
if (is_array($sleeves)) {
foreach ($sleeves as $sleeve) {
$sleevedata['name'] = trim($sleeve);
$sleevedata['fiberPlanDispatcher_id'] = $id;
$fiberplandispatchersleeve = FiberPlanDispatchersleeveModel::create($sleevedata);
$fiberplandispatchersleeve->save();
}
}
}
}
if (!$id) {
$this->layout()->setFlash("Verteiler/Schacht konnte nicht angelegt werden", "error");
$this->redirect("FiberPlanDispatcher");
}
if ($mode == "edit") {
$this->layout()->setFlash("Verteiler/Schacht erfolgreich geändert", "success");
} else if ($mode = "add") {
$this->layout()->setFlash("Verteiler/Schacht erfolgreich angelegt", "success");
}
$this->redirect("FiberPlanDispatcher");
}
protected function deleteAction()
{
$id = $this->request->id;
$fiberplandispatcher = new FiberPlanDispatcher($id);
if (!$fiberplandispatcher->id || $fiberplandispatcher->id != $id) {
$this->layout()->setFlash("Verteiler/Schacht nicht gefunden.", "error");
$this->redirect("FiberPlanDispatcher");
}
$fiberplandispatcher->delete();
$this->redirect("FiberPlanDispatcher");
}
}

View File

@@ -0,0 +1,137 @@
<?php
class FiberPlanDispatcherModel
{
public $network_id = null;
public $object_type = null;
public $price = null;
public $gps_lat = null;
public $gps_long = null;
public $type = null;
public $comment = null;
public $description = null;
public $create_by = null;
public $edit_by = null;
public $create = null;
public $edit = null;
public static function find($data)
{
}
public static function create(array $data)
{
$model = new FiberPlanDispatcher();
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("Devicetype", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Devicetype($data);
}
return $item;
}
public static function getAll()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("FiberPlanDispatcher", "*", "1=1 ORDER BY network_id");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanDispatcher($data);
}
}
return $items;
}
public static function getFirst()
{
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("Devicetype", "*", "$where ORDER BY name, network_id");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Devicetype($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("Devicetype", "*", "$where ORDER BY name, network_id");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new Devicetype($data);
}
}
return $items;
}
private static function getSqlFilter($filter)
{
$where = "1=1 ";
//var_dump($filter);exit;
if (array_key_exists("network_id", $filter)) {
$networkid = $filter['network_id'];
if (is_numeric($networkid)) {
$where .= " AND network_id=$networkid";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -0,0 +1,60 @@
<?php
class FiberPlanDispatchersleeve extends mfBaseModel
{
private $editor;
private $creator;
private $fiberPlanDispatcher;
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;
}
}

View File

@@ -0,0 +1,127 @@
<?php
class FiberPlanDispatchersleeveController 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("FiberPlanDispatchersleeve/Index");
$fiberplandispatchersleeves = FiberPlanDispatchersleeveModel::getAll();
$this->layout()->set("fiberplandispatchersleeves", $fiberplandispatchersleeves);
}
protected function addAction()
{
$fiberPlanDispatchers=FiberPlanDispatcherModel::getAll();
$this->layout()->set("fiberPlanDispatchers", $fiberPlanDispatchers);
$this->layout()->setTemplate("FiberPlanDispatchersleeve/Form");
}
protected function editAction()
{
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Muffen nicht gefunden", "error");
$this->redirect("FiberPlanDispatchersleeve");
}
$fiberplandispatchersleeves = new FiberPlanDispatchersleeve($id);
if ($fiberplandispatchersleeves->id != $id) {
$this->layout()->setFlash("Muffen nicht gefunden", "error");
$this->redirect("FiberPlanDispatchersleeve");
}
$this->layout()->set("fiberplandispatchersleeves", $fiberplandispatchersleeves);
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";
$fiberplandispatchersleeves = new FiberPlanDispatchersleeve($id);
if (!$fiberplandispatchersleeves->id) {
$this->layout()->setFlash("Muffe nicht gefunden", "error");
$this->redirect("FiberPlanDispatchersleeve");
}
} else {
$mode = "add";
}
$data = [];
$data['fiberPlanDispatcher_id'] = trim($r->fiberPlanDispatcher_id);
$data['name'] = trim($r->name);
if (!$data['fiberPlanDispatcher_id']) {
$data['fiberPlanDispatcher_id']=NULL;
}
if (!$data['name']) {
$data['name']=NULL;
}
// var_dump($_FILES);
// var_dump($upload);
// exit;
if ($mode == "edit") {
$fiberplandispatchersleeves->update($data);
} else {
$fiberplandispatchersleeves = FiberPlanDispatchersleeveModel::create($data);
}
// var_dump($filestore);
// exit;
$id = $fiberplandispatchersleeves->save();
if (!$id) {
$this->layout()->setFlash("Muffen konnte nicht angelegt werden", "error");
$this->redirect("FiberPlanDispatchersleeve");
}
if ($mode == "edit") {
$this->layout()->setFlash("Muffen erfolgreich geändert", "success");
} else if ($mode = "add") {
$this->layout()->setFlash("Muffen erfolgreich angelegt", "success");
}
$this->redirect("FiberPlanDispatchersleeve");
}
protected function deleteAction()
{
$id = $this->request->id;
$fiberplandispatchersleeves = new FiberPlanDispatchersleeve($id);
if (!$fiberplandispatchersleeves->id || $fiberplandispatchersleeves->id != $id) {
$this->layout()->setFlash("Muffen nicht gefunden.", "error");
$this->redirect("FiberPlanDispatchersleeve");
}
$fiberplandispatchersleeves->delete();
$this->redirect("FiberPlanDispatchersleeve");
}
}

View File

@@ -0,0 +1,153 @@
<?php
class FiberPlanDispatchersleeveModel
{
private $fiberPlanDispatcher_id;
private $name;
public static function find($data)
{
}
public static function create(array $data)
{
$model = new FiberPlanDispatchersleeve();
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("FiberPlanDispatchersleeve", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new FiberPlanDispatchersleeve($data);
}
return $item;
}
public static function getAll()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("FiberPlanDispatchersleeve", "*", "1=1");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanDispatchersleeve($data);
}
}
return $items;
}
public static function getFirst()
{
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("FiberPlanDispatchersleeve", "*", "$where ");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new FiberPlanDispatchersleeve($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("FiberPlanDispatchersleeve", "*", "$where");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanDispatchersleeve($data);
}
}
return $items;
}
private static function getSqlFilter($filter)
{
$where = "1=1 ";
//var_dump($filter);exit;
if (array_key_exists("network_id", $filter)) {
$networkid = $filter['network_id'];
if (is_numeric($networkid)) {
$where .= " AND network_id=$networkid";
}
}
//var_dump($filter, $where);exit;
return $where;
}
public static function getAllbyDispatcher($dispatcher_id)
{
$items = [];
$db = FronkDB::singleton();
$sql = "SELECT `id`, `fiberPlanDispatcher_id`, `name` FROM `FiberPlanDispatchersleeve`
WHERE `fiberPlanDispatcher_id`='" . $dispatcher_id . "'";
$res = $db->query($sql);
if ($db->num_rows($res)) {
$oldrackid = "";
$counter = -1;
while ($data = $db->fetch_array($res)) {
$items[] = $data;
}
return $items;
}
}
public static function deletebyDispatcher($dispatcher_id)
{
$db = FronkDB::singleton();
$sql = "DELETE FROM `FiberPlanDispatchersleeve` WHERE `fiberPlanDispatcher_id`='" . $dispatcher_id . "'";
$db->query($sql);
}
}

View File

@@ -0,0 +1,62 @@
<?php
class FiberPlanPipe extends mfBaseModel
{
private $editor;
private $creator;
private $network;
private $fiberPlanPipeManufacturer;
private $fiberPlanPipeTemplate;
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;
}
}

View File

@@ -0,0 +1,281 @@
<?php
class FiberPlanPipeController 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()
{
$networks = NetworkModel::getAll();
$this->layout()->setTemplate("FiberPlanPipe/Index");
$fiberplanpipes = FiberPlanPipeModel::getAll();
$pipworkeraddresses = FiberPlanPipeModel::getPipeworkerAddresses();
$buildings = FiberPlanPipeModel::getBuildingInfoAll();
$this->layout()->set("networks", $networks);
$this->layout()->set("buildings", $buildings);
$this->layout()->set("pipworkeraddresses", $pipworkeraddresses);
$this->layout()->set("fiberplanpipes", $fiberplanpipes);
}
protected function addAction()
{
$networks = NetworkModel::getAll();
$fiberplanpipetemplates = FiberPlanPipeModel::getTemplates();
$pipworkeraddresses = FiberPlanPipeModel::getPipeworkerAddresses();
$this->layout()->set("networks", $networks);
$this->layout()->set("pipworkeraddresses", $pipworkeraddresses);
$this->layout()->set("fiberplanpipetemplates", $fiberplanpipetemplates);
$this->layout()->setTemplate("FiberPlanPipe/Form");
}
protected function apiAction()
{
$do = $this->request->do;
$network = $this->request->network_id;
$bdtype = $this->request->bdtype;
switch ($do) {
case "getBuildingInfo":
$return = $this->getBuildingInfo($network, $bdtype);
break;
case "getPops":
$return = $this->getPops($network);
break;
default:
$return = false;
}
}
protected function detailAction()
{
$id = $this->request->id;
$networks = NetworkModel::getAll();
$this->layout()->setTemplate("FiberPlanPipe/Detail");
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Rohrverzeichnis nicht gefunden", "error");
$this->redirect("FiberPlanPipe");
}
$fiberplanpipes = new FiberPlanPipe($id);
if ($fiberplanpipes->id != $id) {
$this->layout()->setFlash("Rohrverzeichnis nicht gefunden", "error");
$this->redirect("FiberPlanPipe");
}
$this->layout()->set("fiberplanpipes", $fiberplanpipes);
$pipworkeraddresses = FiberPlanPipeModel::getPipeworkerAddresses();
$buildings = FiberPlanPipeModel::getBuildingInfoAll();
$fiberplanpipeendpoints = FiberPlanPipeEndpointModel::search(['fiberPlanPipe_id' => $id]);
$this->layout()->set("networks", $networks);
$this->layout()->set("buildings", $buildings);
$this->layout()->set("pipworkeraddresses", $pipworkeraddresses);
$this->layout()->set("fiberplanpipeendpoints", $fiberplanpipeendpoints);
}
protected function editAction()
{
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Rohrverzeichnis nicht gefunden", "error");
$this->redirect("FiberPlanPipe");
}
$fiberplanpipes = new FiberPlanPipe($id);
if ($fiberplanpipes->id != $id) {
$this->layout()->setFlash("Rohrverzeichnis nicht gefunden", "error");
$this->redirect("FiberPlanPipe");
}
$fiberplanpipeendpoints = FiberPlanPipeEndpointModel::search(['fiberPlanPipe_id' => $id]);
$this->layout()->set("fiberplanpipeendpoints", $fiberplanpipeendpoints);
$this->layout()->set("fiberplanpipes", $fiberplanpipes);
return $this->addAction();
}
protected function saveAction()
{
$r = $this->request;
$id = $r->id;
var_dump($r->get());
die();
if (is_numeric($id) && $id > 0) {
$mode = "edit";
$fiberplanpipes = new FiberPlanPipe($id);
if (!$fiberplanpipes->id) {
$this->layout()->setFlash("Rohrverzeichnisse nicht gefunden", "error");
$this->redirect("FiberPlanPipe");
}
} else {
$mode = "add";
}
$data = [];
$data['description'] = trim($r->description);
$data['gisid'] = trim($r->gisid);
$data['type'] = trim($r->type);
$data['type_description'] = trim($r->type_description);
$data['fiberplanpipetemplate_id'] = trim($r->fiberplanpipetemplate_id);
$data['length'] = trim($r->length);
$data['status'] = trim($r->status);
$data['responsible'] = trim($r->responsible);
$data['responsible_text'] = trim($r->responsible_text);
$data['address_id'] = trim($r->address_id);
$data['comment'] = trim($r->comment);
$returnUrl = "FiberPlanPipe";
$returnAction = "Index";
$returnVariables = array();
$returnAnker = "";
if ($this->request->returnto) {
if (strpos($this->request->returnto, "-") !== false) {
$urls = explode('-', $this->request->returnto);
$urlCounter = 0;
$returnUrlGen = "";
foreach ($urls as $url) {
if ($urlCounter > 0) {
$returnUrlGen .= "/";
$returnUrlGen .= ucfirst($url);
} else {
$returnUrlGen .= 'FiberPlanPipe';
}
$urlCounter++;
}
$returnAction = "";
$returnVariables['id'] = $id;
$returnUrl = $returnUrlGen;
} else {
$returnUrl = ucfirst($this->request->returnto);
}
}
if (!$data['description']) {
$this->layout()->setFlash("Bezeichnung darf nicht leer sein", "error");
$this->redirect("FiberPlanPipe");
}
if (!$data['type']) {
$data['type'] = NULL;
}
if (!$data['gisid']) {
$data['gisid'] = NULL;
}
if (!$data['responsible_text']) {
$data['responsible_text'] = NULL;
}
if (!$data['address_id']) {
$data['address_id'] = NULL;
}
if (!$data['type_description']) {
$data['type_description'] = NULL;
}
if (!$data['fiberplanpipetemplate_id']) {
$data['fiberplanpipetemplate_id'] = NULL;
}
if (!$data['length']) {
$data['length'] = NULL;
}
if (!$data['startpoint']) {
$data['startpoint'] = NULL;
}
if (!$data['endpoint']) {
$data['endpoint'] = NULL;
}
if (!$data['status']) {
$data['status'] = NULL;
}
if (!$data['responsible']) {
$data['responsible'] = NULL;
}
if (!$data['comment']) {
$data['comment'] = NULL;
}
// var_dump($_FILES);
// var_dump($upload);
// exit;
if ($mode == "edit") {
$fiberplanpipes->update($data);
} else {
$fiberplanpipes = FiberPlanPipeModel::create($data);
}
// var_dump($filestore);
// exit;
$id = $fiberplanpipes->save();
$endpoint_id = $r->endpointid;
$endpoint_type = $r->endpoint_type;
$endpoint = $r->endpoint;
if (!empty($endpoint)) {
$counter = 1;
foreach ($endpoint as $key => $Endpoint) {
if ($endpoint_type[$key] == 4) {
$endpointarray['fiberPlanDispatcher_id'] = $Endpoint;
} else if ($endpoint_type[$key] == 2) {
$endpointarray['pop_id'] = $Endpoint;
}
$endpointarray['fiberPlanPipe_id'] = $id;
$endpointarray['sort'] = $counter;
if ($endpoint_id[$key]) {
$fiberplanpipeendpoint = new FiberPlanPipeEndpoint($id);
$fiberplanpipeendpoint->update($endpointarray);
} else {
$fiberplanpipeendpoint = FiberPlanPipeEndpointModel::create($endpointarray);
}
$fiberplanpipeendpoint->save();
$counter++;
}
}
if (!$id) {
$this->layout()->setFlash("Rohrverzeichnis konnte nicht angelegt werden", "error");
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
}
if ($mode == "edit") {
$this->layout()->setFlash("Rohrverzeichnis erfolgreich geändert", "success");
} else if ($mode = "add") {
$this->layout()->setFlash("Rohrverzeichnis erfolgreich angelegt", "success");
}
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
}
protected function deleteAction()
{
$id = $this->request->id;
$fiberplanpipes = new FiberPlanPipe($id);
if (!$fiberplanpipes->id || $fiberplanpipes->id != $id) {
$this->layout()->setFlash("Rohrverzeichnis nicht gefunden.", "error");
$this->redirect("FiberPlanPipe");
}
$fiberplanpipes->delete();
$this->redirect("FiberPlanPipe");
}
protected function getBuildingInfo($network, $bdtype)
{
FiberPlanPipeModel::getBuildingInfo($network, $bdtype);
}
}

View File

@@ -0,0 +1,376 @@
<?php
class FiberPlanPipeModel
{
private $network_id;
private $description;
private $gisid;
private $type;
private $type_description;
private $fiberplanpipetemplate_id;
private $length;
private $startpoint_type;
private $startpoint_network_id;
private $startpoint;
private $midpoint;
private $endpoint_network_id;
private $entpoint_type;
private $endpoint;
private $status;
private $responsible;
private $responsible_text;
private $address_id;
private $comment;
public static $type_descrition_definition = array(1 => "MR7", 2 => "MR14", 3 => "MR16", 4 => "MR20", 5 => "PE32", 6 => "PE40", 7 => "PE50", 8 => "KSR50", 9 => "KSR80", 10 => "KSR100");
public static $type_definition = array(1 => "Enzel", 2 => "Schutzrohr", 3 => "Verband");
public static function find($data)
{
}
public static function create(array $data)
{
$model = new FiberPlanPipe();
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("FiberPlanPipe", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new FiberPlanPipe($data);
}
return $item;
}
public static function getAll()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("FiberPlanPipe", "*", "1=1");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanPipe($data);
}
}
return $items;
}
public static function getAllPipeManufacturer()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("FiberPlanPipeManufacturer", "*", "1=1");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanPipe($data);
}
}
return $items;
}
public static function getAllPipe()
{
$items = [];
$db = FronkDB::singleton();
$sql = "SELECT `FiberPlanPipe`.`id`,`FiberPlanPipe`.`description`,`FiberPlanPipe`.`type`,`FiberPlanPipe`.`type_description`,`FiberPlanPipe`.`startpoint_network_id`, `FiberPlanPipe`.`endpoint_network_id`,`FiberPlanPipeTemplate`. `fiberPlanPipeManufacturer_id`,`FiberPlanPipeTemplate`.`pipe7x4`,`FiberPlanPipeTemplate`.`pipe14x10` FROM `FiberPlanPipe`
LEFT JOIN `FiberPlanPipeTemplate` ON `FiberPlanPipe`.`fiberPlanPipeTemplate_id`=`FiberPlanPipeTemplate`.id";
$res = $db->query($sql);
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanPipe($data);
}
}
return $items;
}
public static function getFirst()
{
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("FiberPlanPipe", "*", "$where ");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new FiberPlanPipe($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("FiberPlanPipe", "*", "$where");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanPipe($data);
}
}
return $items;
}
private static function getSqlFilter($filter)
{
$where = "1=1 ";
//var_dump($filter);exit;
if (array_key_exists("network_id", $filter)) {
$networkid = $filter['network_id'];
if (is_numeric($networkid)) {
$where .= " AND network_id=$networkid";
}
}
//var_dump($filter, $where);exit;
return $where;
}
public static function getTemplates()
{
$items = [];
$db = FronkDB::singleton();
$sql = "SELECT `FiberPlanPipeTemplate`.id,FiberPlanPipeTemplate.pipe7x4,FiberPlanPipeTemplate.pipe14x10,FiberPlanPipeManufacturer.name FROM `FiberPlanPipeTemplate` INNER JOIN FiberPlanPipeManufacturer ON FiberPlanPipeManufacturer.id=FiberPlanPipeTemplate.fiberPlanPipeManufacturer_id ";
$res = $db->query($sql);
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanPipe($data);
}
}
return $items;
}
public static function getPipeworkerAddresses()
{
$items = [];
$db = FronkDB::singleton();
$sql = "SELECT `Addresstype`.`id`,`Address`.`company` FROM `Addresstype`
INNER JOIN `Address` ON (`Address`.`id`=`Addresstype`.`address_id`)
WHERE `type` = 'pipeworker' ORDER by `Address`.`company` ";
$res = $db->query($sql);
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanPipe($data);
}
}
return $items;
}
public static function getBuildingInfo($network, $bdtype, $api = 1)
{
$items = [];
$db = FronkDB::singleton();
if ($bdtype == "1") {
$sql = "SELECT `id`,`description` `name` FROM `FiberPlanDispatcher` WHERE network_id='" . $network . "' AND `object_type`='3' ";
} else if ($bdtype == "2") {
$sql = "SELECT `Pop`.`id`,`Pop`.`name` FROM `PopNetwork`
INNER JOIN `Pop` ON (`Pop`.`id`=`PopNetwork`.`pop_id`)
WHERE `PopNetwork`.`network_id`='" . $network . "'";
} else if ($bdtype == "3") {
$sql = "SELECT `id`,`code` ,`street`, `zip`, `city` name FROM Building WHERE network_id='" . $network . "' ORDER by street";
} else if ($bdtype == "4") {
$sql = "SELECT `id`,`description` `name` FROM `FiberPlanDispatcher` WHERE network_id='" . $network . "' AND (`object_type`='1' OR `object_type`='2') ";
}
$res = $db->query($sql);
if ($db->num_rows($res)) {
$counter = 0;
while ($data = $db->fetch_array($res)) {
$items[$counter]['id'] = $data['id'];
if ($bdtype == "3") {
$items[$counter]['name'] = $data['street'] . " " . $data['zip'] . " " . $data['city'];
} else {
$items[$counter]['name'] = $data['name'];
}
$counter++;
}
}
if ($api === 1) {
echo json_encode($items);
exit;
} else {
return $items;
}
}
public static function getBuildingInfoAll()
{
$items = [];
$db = FronkDB::singleton();
$sql = "SELECT `id`, `fiberPlanDispatcher_id`, `name` FROM `FiberPlanDispatchersleeve` ORDER by id";
$res = $db->query($sql);
if ($db->num_rows($res)) {
while ($data = $db->fetch_array($res)) {
$sleeves[$data['fiberPlanDispatcher_id']][$data['id']] = $data['name'];
}
}
$sql = "SELECT '1' as `type`,'Greenfield' as `typename`,`id`,`description` as `name`,`gps_lat`,`gps_long` FROM `FiberPlanDispatcher` WHERE `object_type`='3'
UNION
SELECT '2' as `type`,'Pop' as `typename`,`id`,`name`,`gps_lat`,`gps_long` FROM `Pop`
UNION
SELECT '3' as `type`,'Building' as `typename`,`id`,CONCAT_WS(' ',`street`, `zip`, `city`) as name,`gps_lat`,`gps_long` FROM Building
UNION
SELECT '4' as `type`,'Schacht-Verteiler' as `typename`,`id`,`description` as `name`,`gps_lat`,`gps_long` FROM `FiberPlanDispatcher` WHERE (`object_type`='1' OR `object_type`='2')";
$res = $db->query($sql);
if ($db->num_rows($res)) {
while ($data = $db->fetch_array($res)) {
$items[$data['type']][$data['id']] = $data;
if ($data['type'] == 4) {
$items[$data['type']][$data['id']]['sleeves'] = $sleeves[$data['id']];
}
}
}
return $items;
}
public static function generateEndpoints($endpoints, $networks)
{
foreach ($networks as $network) {
$Network[$network->id] = $network->name;
}
$counter = 1;
$endpointuparrow = "";
$typeArray[1] = 'Greenfield';
$typeArray[2] = 'POP';
$typeArray[3] = 'Building';
$typeArray[4] = 'Schacht-Verteiler';
// print_r($buildings);
$counter = 1;
foreach ($endpoints as $Endpoint) {
if ($Endpoint->pop_id) {
$networkid = $Endpoint->pop->network_id;
$endpointid = $Endpoint->pop->id;
$endpointtype = 2;
} else if ($Endpoint->fiberPlanDispatcher_id) {
$networkid = $Endpoint->fiberPlanDispatcher->network_id;
$endpointid = $Endpoint->fiberPlanDispatcher->id;
if ($Endpoint->fiberPlanDispatcher->object_type == 3) {
$endpointtype = 1;
} else {
$endpointtype = 4;
}
} else if ($Endpoint->building_id) {
$networkid = $Endpoint->building->network_id;
$endpointid = $Endpoint->building->id;
$endpointtype = 3;
}
$randid = rand(1000, 10000);
if ($counter > 1) {
$Endpointuparrow = '<i title="nach oben verschieben" class="fa-sharp fa-solid fa-up move-endpoint-up"></i>';
}
if ($counter == 1) {
$endpointType = "Startpunkt";
$endpointsymbol = '<span class="endpointsymbol"><i id="add-endpoint" class="fa-regular fa-circle-plus"></i></span>';
}
else if (count($endpoints)==2)
{
$endpointcount = $counter - 1;
$endpointType = "Standort " . $endpointcount;
$endpointsymbol='<span class="endpointsymbol">';
}
else {
$endpointcount = $counter - 1;
$endpointType = "Standort " . $endpointcount;
$endpointsymbol = '<span class="endpointsymbol"><i class="fa-regular fa-circle-minus remove-endpoint"></i></span>';
}
$html = '<div class="form-group row endpoint-maindiv">
<label class="col-lg-2 col-form-label endpoint-label" for="' . $randid . '_endpoint_network_id"><span class="label-text">' . $endpointType . ' * </span>' . $Endpointuparrow . $endpointsymbol . '</label>
<div class="col-lg-2"><select id="' . $randid . '_endpoint_network_id" required="required" name="endpoint_network_id[]" class="select2 form-control endpoint_network_id">';
foreach ($networks as $network) {
if ($network->id == $networkid) {
$html .= '<option selected="selected" value="' . $network->id . '">' . $network->name . '</option>';
} else {
$html .= '<option value="' . $network->id . '">' . $network->name . '</option>';
}
}
$html .= '</select></div>
<div class="col-lg-2 ">
<select id="' . $randid . '_endpoint_type" name="endpoint_type[]" required="required" class="select2 form-control endpoint_type" >';
foreach ($typeArray as $key => $type) {
if ($key == $endpointtype) {
$html .= '<option selected="selected" value="' . $key . '">' . $type . '</option>';
} else {
$html .= '<option value="' . $key . '">' . $type . '</option>';
}
}
$html .= '</select></div>
<div class="col-lg-2" id="' . $randid . '_end-point-building">
<select id=' . $randid . '_endpoint" required="required" name="endpoint[]" class="select2 form-control">';
$buildings = FiberPlanPipeModel::getBuildingInfo($networkid, $endpointtype, 0);
foreach ($buildings as $key => $building) {
if ($building['id'] == $endpointid) {
$html .= '<option selected="selected" value="' . $building['id'] . '">' . $building['name'] . '</option>';
} else {
$html .= '<option value="' . $building['id'] . '">' . $building['name'] . '</option>';
}
}
$html .= '</select><input type="hidden" name="endpointid[]" value="' . $Endpoint->id . '" ></div></div>';
echo $html;
$counter++;
}
}
}

View File

@@ -0,0 +1,64 @@
<?php
class FiberPlanPipeEndpoint extends mfBaseModel
{
private $editor;
private $creator;
private $fiberPlanPipe;
private $pop;
private $fiberPlanDispatcher;
private $building;
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;
}
}

View File

@@ -0,0 +1,145 @@
<?php
class FiberPlanPipeEndpointController 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("FiberPlanPipeEndpoint/Index");
$fiberplanpipeendpoints = FiberPlanPipeEndpointModel::getAll();
$this->layout()->set("fiberplanpipeendpoints", $fiberplanpipeendpoints);
}
protected function addAction()
{
$fiberPlanPipes=FiberPlanPipeModel::getAll();
$this->layout()->set("fiberPlanPipes", $fiberPlanPipes);
$pops=PopModel::getAll();
$this->layout()->set("pops", $pops);
$fiberPlanDispatchers=FiberPlanDispatcherModel::getAll();
$this->layout()->set("fiberPlanDispatchers", $fiberPlanDispatchers);
$buildings=BuildingModel::getAll();
$this->layout()->set("buildings", $buildings);
$this->layout()->setTemplate("FiberPlanPipeEndpoint/Form");
}
protected function editAction()
{
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("dfsdf nicht gefunden", "error");
$this->redirect("FiberPlanPipeEndpoint");
}
$fiberplanpipeendpoints = new FiberPlanPipeEndpoint($id);
if ($fiberplanpipeendpoints->id != $id) {
$this->layout()->setFlash("dfsdf nicht gefunden", "error");
$this->redirect("FiberPlanPipeEndpoint");
}
$this->layout()->set("fiberplanpipeendpoints", $fiberplanpipeendpoints);
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";
$fiberplanpipeendpoints = new FiberPlanPipeEndpoint($id);
if (!$fiberplanpipeendpoints->id) {
$this->layout()->setFlash("sdfsdf nicht gefunden", "error");
$this->redirect("FiberPlanPipeEndpoint");
}
} else {
$mode = "add";
}
$data = [];
$data['fiberPlanPipe_id'] = trim($r->fiberPlanPipe_id);
$data['pop_id'] = trim($r->pop_id);
$data['fiberPlanDispatcher_id'] = trim($r->fiberPlanDispatcher_id);
$data['building_id'] = trim($r->building_id);
$data['sort'] = trim($r->sort);
if (!$data['fiberPlanPipe_id']) {
$data['fiberPlanPipe_id']=NULL;
}
if (!$data['pop_id']) {
$data['pop_id']=NULL;
}
if (!$data['fiberPlanDispatcher_id']) {
$data['fiberPlanDispatcher_id']=NULL;
}
if (!$data['building_id']) {
$data['building_id']=NULL;
}
if (!$data['sort']) {
$data['sort']=NULL;
}
// var_dump($_FILES);
// var_dump($upload);
// exit;
if ($mode == "edit") {
$fiberplanpipeendpoints->update($data);
} else {
$fiberplanpipeendpoints = FiberPlanPipeEndpointModel::create($data);
}
// var_dump($filestore);
// exit;
$id = $fiberplanpipeendpoints->save();
if (!$id) {
$this->layout()->setFlash("dfsdf konnte nicht angelegt werden", "error");
$this->redirect("FiberPlanPipeEndpoint");
}
if ($mode == "edit") {
$this->layout()->setFlash("dfsdf erfolgreich geändert", "success");
} else if ($mode = "add") {
$this->layout()->setFlash("dfsdf erfolgreich angelegt", "success");
}
$this->redirect("FiberPlanPipeEndpoint");
}
protected function deleteAction()
{
$id = $this->request->id;
$fiberplanpipeendpoints = new FiberPlanPipeEndpoint($id);
if (!$fiberplanpipeendpoints->id || $fiberplanpipeendpoints->id != $id) {
$this->layout()->setFlash("dfsdf nicht gefunden.", "error");
$this->redirect("FiberPlanPipeEndpoint");
}
$fiberplanpipeendpoints->delete();
$this->redirect("FiberPlanPipeEndpoint");
}
}

View File

@@ -0,0 +1,129 @@
<?php
class FiberPlanPipeEndpointModel
{
private $fiberPlanPipe_id;
private $pop_id;
private $fiberPlanDispatcher_id;
private $building_id;
private $sort;
public static function find($data)
{
}
public static function create(array $data)
{
$model = new FiberPlanPipeEndpoint();
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("FiberPlanPipeEndpoint", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new FiberPlanPipeEndpoint($data);
}
return $item;
}
public static function getAll()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("FiberPlanPipeEndpoint", "*", "1=1");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanPipeEndpoint($data);
}
}
return $items;
}
public static function getFirst()
{
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("FiberPlanPipeEndpoint", "*", "$where ");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new FiberPlanPipeEndpoint($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("FiberPlanPipeEndpoint", "*", "$where ORDER by sort");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanPipeEndpoint($data);
}
}
return $items;
}
private static function getSqlFilter($filter)
{
$where = "1=1 ";
//var_dump($filter);exit;
if (array_key_exists("fiberPlanPipe_id", $filter)) {
$fiberPlanPipe_id = $filter['fiberPlanPipe_id'];
if (is_numeric($fiberPlanPipe_id)) {
$where .= " AND fiberPlanPipe_id=$fiberPlanPipe_id";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -0,0 +1,42 @@
<?php
class FiberPlanPipeManufacturer extends mfBaseModel
{
private $editor;
private $creator;
public function getProperty($name)
{
if ($this->$name == null) {
if (!$this->id) {
return null;
}
if ($name == "creator") {
$this->creator = new User($this->create_by);
return $this->creator;
}
if ($name == "editor") {
$this->editor = new User($this->edit_by);
return $this->editor;
}
$classname = ucfirst($name);
$idfield = $name . "_id";
$this->$name = new $classname($this->$idfield);
if ($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}

View File

@@ -0,0 +1,126 @@
<?php
class FiberPlanPipeManufacturerModel
{
private $name;
private $colors;
public static function find($data)
{
}
public static function create(array $data)
{
$model = new FiberPlanPipeManufacturer();
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("FiberPlanPipeManufacturer", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new FiberPlanPipeManufacturer($data);
}
return $item;
}
public static function getAll()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("FiberPlanPipeManufacturer", "*", "1=1");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanPipeManufacturer($data);
}
}
return $items;
}
public static function getFirst()
{
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("FiberPlanPipeManufacturer", "*", "$where ");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new FiberPlanPipeManufacturer($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("FiberPlanPipeManufacturer", "*", "$where");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanPipeManufacturer($data);
}
}
return $items;
}
private static function getSqlFilter($filter)
{
$where = "1=1 ";
//var_dump($filter);exit;
if (array_key_exists("network_id", $filter)) {
$networkid = $filter['network_id'];
if (is_numeric($networkid)) {
$where .= " AND network_id=$networkid";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -0,0 +1,43 @@
<?php
class FiberPlanPipeTemplate extends mfBaseModel
{
private $editor;
private $creator;
private $fiberPlanPipeManufacturer;
public function getProperty($name)
{
if ($this->$name == null) {
if (!$this->id) {
return null;
}
if ($name == "creator") {
$this->creator = new User($this->create_by);
return $this->creator;
}
if ($name == "editor") {
$this->editor = new User($this->edit_by);
return $this->editor;
}
$classname = ucfirst($name);
$idfield = $name . "_id";
$this->$name = new $classname($this->$idfield);
if ($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}

View File

@@ -0,0 +1,127 @@
<?php
class FiberPlanPipeTemplateModel
{
private $fiberplanpipemanufacturer_id;
private $pipe7x4;
private $pipe14x10;
public static function find($data)
{
}
public static function create(array $data)
{
$model = new FiberPlanPipeTemplate();
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("FiberPlanPipeTemplate", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new FiberPlanPipeTemplate($data);
}
return $item;
}
public static function getAll()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("FiberPlanPipeTemplate", "*", "1=1");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanPipeTemplate($data);
}
}
return $items;
}
public static function getFirst()
{
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("FiberPlanPipeTemplate", "*", "$where ");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new FiberPlanPipeTemplate($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("FiberPlanPipeTemplate", "*", "$where");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new FiberPlanPipeTemplate($data);
}
}
return $items;
}
private static function getSqlFilter($filter)
{
$where = "1=1 ";
//var_dump($filter);exit;
if (array_key_exists("network_id", $filter)) {
$networkid = $filter['network_id'];
if (is_numeric($networkid)) {
$where .= " AND network_id=$networkid";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -0,0 +1,9 @@
<?php
/**
* @property mixed|null $name
*/
class HistoricTicket extends mfBaseModel
{
}

View File

@@ -0,0 +1,103 @@
<?php
class HistoricTicketController extends mfBaseController {
private User $me;
protected function init(): void {
$me = new User();
$me->loadMe();
$this->layout()->set("me", $me);
$this->me = $me;
}
protected function indexAction(): void {
if (!$this->me->is("employee")) {
$this->redirect("dashboard");
}
$this->layout()->setTemplate("HistoricTicket/Index");
}
protected function apiAction() {
$do = $this->request->do;
if ($do !== "getConfig" && !$this->me->is("employee")) {
$this->redirect("dashboard");
}
switch ($do) {
case "getHistoricTickets":
$return = $this->getHistoricTickets();
break;
case "getHistoricTicketMessages":
$return = $this->getHistoricTicketMessages();
break;
case "findHistoricTicket":
$return = $this->findHistoricTicket();
break;
default:
$return = false;
break;
}
if (!$return) {
$return = [
"status" => "error",
"message" => "Invalid request."
];
}
die(json_encode($return));
}
private function getHistoricTickets(): array {
$json = json_decode(file_get_contents('php://input'), true);
$filters = $json['filters'] ?? [];
$page = $json['pagination']['page'] ?? 1;
$perPage = $json['pagination']['per_page'] ?? 10;
$historicTickets = HistoricTicketModel::getAllHistoricTickets($filters, $perPage, ($page - 1) * $perPage);
$total = HistoricTicketModel::countHistoricTickets($filters);
return [
"rows" => $historicTickets,
"pagination" => [
"page" => $page,
"total_pages" => ceil($total / $perPage),
"per_page" => $perPage,
"total_rows" => intval($total)
]
];
}
private function getHistoricTicketMessages(): array {
$json = json_decode(file_get_contents('php://input'), true);
$ticketNumber = $json['ticketNumber'];
return HistoricTicketModel::findHistoricTicket($ticketNumber);
}
private function findHistoricTicket(): array {
$query = $this->request->query;
if (empty($query)) {
return [
"status" => "error",
"message" => "No query provided."
];
}
$rows = HistoricTicketModel::findTicket($query);
return [
"rows" => $rows,
"pagination" => [
"page" => 1,
"total_pages" => 1,
"per_page" => count($rows),
"total_rows" => count($rows)
]
];
}
}

View File

@@ -0,0 +1,183 @@
<?php
class HistoricTicketModel {
public $id;
public $ticket_number;
public $ticket_verifier;
public $priority;
public $status_id;
public $status;
public $type_id;
public $type;
public $user_id;
public $agent_id;
public $contact_id;
public $company;
public $company_id;
public $first_name;
public $middle_name;
public $last_name;
public $email;
public $phone;
public $subject;
public $ctime;
public $mtime;
public $muser_id;
public $files_folder_id;
public $unseen;
public $group_id;
public $order_id;
public $last_response_time;
public $cc_addresses;
public function __construct($data = []) {
foreach ($data as $field => $value) {
if (property_exists(get_called_class(), $field)) {
$this->$field = $value;
}
}
}
public static function generateFilterCondition(?string $filterValue, string $columnName): string {
$sql = "";
if (!empty($filterValue)) {
$filterItems = explode(" ", $filterValue);
foreach ($filterItems as $item) {
$sql .= " AND `$columnName` LIKE '%" . $item . "%'";
}
}
return $sql;
}
public static function getSqlFilter($filters): string {
$sql = isset($filters['subject']) ? self::generateFilterCondition($filters['subject'], "subject") : "";
$sql .= isset($filters['ticket_number']) ? self::generateFilterCondition($filters['ticket_number'], "ticket_number") : "";
$sql .= isset($filters['priority']) ? " AND `priority` = " . $filters['priority'] : "";
$sql .= isset($filters['status']) ? self::generateFilterCondition($filters['status'], "status") : "";
$sql .= isset($filters['status_id']) ? " AND `status_id` = " . $filters['status_id'] : "";
$sql .= isset($filters['type']) ? self::generateFilterCondition($filters['type'], "type") : "";
$sql .= isset($filters['type_id']) ? " AND `type_id` = " . $filters['type_id'] : "";
$sql .= isset($filters['user_id']) ? " AND `user_id` = " . $filters['user_id'] : "";
$sql .= isset($filters['agent_id']) ? " AND `agent_id` = " . $filters['agent_id'] : "";
$sql .= isset($filters['contact_id']) ? " AND `contact_id` = " . $filters['contact_id'] : "";
$sql .= isset($filters['company']) ? self::generateFilterCondition($filters['company'], "company") : "";
$sql .= isset($filters['company_id']) ? " AND `company_id` = " . $filters['company_id'] : "";
$sql .= isset($filters['middle_name']) ? self::generateFilterCondition($filters['middle_name'], "middle_name") : "";
$sql .= isset($filters['last_name']) ? self::generateFilterCondition($filters['last_name'], "last_name") : "";
$sql .= isset($filters['email']) ? " AND `email` LIKE '%" . $filters['email'] . "%'" : "";
$sql .= isset($filters['phone']) ? " AND `phone` LIKE '%" . $filters['phone'] . "%'" : "";
$sql .= isset($filters['ctime']) ? " AND `ctime` = " . $filters['ctime'] : "";
$sql .= isset($filters['mtime']) ? " AND `mtime` = " . $filters['mtime'] : "";
$sql .= isset($filters['muser_id']) ? " AND `muser_id` = " . $filters['muser_id'] : "";
$sql .= isset($filters['files_folder_id']) ? " AND `files_folder_id` = " . $filters['files_folder_id'] : "";
$sql .= isset($filters['unseen']) ? " AND `unseen` = " . $filters['unseen'] : "";
$sql .= isset($filters['group_id']) ? " AND `group_id` = " . $filters['group_id'] : "";
$sql .= isset($filters['order_id']) ? " AND `order_id` = " . $filters['order_id'] : "";
$sql .= isset($filters['last_response_time']) ? " AND `last_response_time` = " . $filters['last_response_time'] : "";
$sql .= isset($filters['cc_addresses']) ? self::generateFilterCondition($filters['cc_addresses'], "cc_addresses") : "";
if (isset($filters['first_name'])) {
$filterItems = explode(" ", $filters['first_name']);
foreach ($filterItems as $item) {
$sql .= " AND (`first_name` LIKE '%" . $item . "%' OR `middle_name` LIKE '%" . $item . "%' OR `last_name` LIKE '%" . $item . "%')";
}
}
return $sql;
}
public static function getAllHistoricTickets($filters, $limit = null, $offset = 0): array {
$db = FronkDB::singleton();
$sql = "SELECT * FROM `HistoricTicket` WHERE 1 " . self::getSqlFilter($filters) . " ORDER BY `ticket_number` DESC";
$sql .= $limit === null ? "" : " LIMIT " . $limit . " OFFSET " . $offset;
$result = $db->query($sql);
$rows = [];
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}
public static function countHistoricTickets($filters) {
$db = FronkDB::singleton();
$sql = "SELECT COUNT(*) as `total_rows` FROM `HistoricTicket` WHERE 1 " . self::getSqlFilter($filters);
$result = $db->query($sql);
return $result->fetch_assoc()['total_rows'];
}
public static function findHistoricTicket($ticketNumber): array {
$db = FronkDB::singleton();
$ticketSql = "SELECT * FROM `HistoricTicket` WHERE `ticket_number` = " . $ticketNumber;
$ticketResult = $db->query($ticketSql);
$ticket = $ticketResult->fetch_assoc();
$messagesSql = "SELECT * FROM `HistoricTicketMessage` WHERE `ticket_id` = " . $ticket["id"];
$messagesResult = $db->query($messagesSql);
$messages = [];
while ($message = $messagesResult->fetch_assoc()) {
$messages[] = $message;
}
return [
"ticket" => $ticket,
"messages" => $messages
];
}
public static function findTicket($query): array {
$db = FronkDB::singleton();
$ticketSql = "SELECT * FROM `HistoricTicket` WHERE `ticket_number` LIKE '%" . $query . "%' OR `subject` LIKE '%" . $query . "%' OR `first_name` LIKE '%" . $query . "%' OR `last_name` LIKE '%" . $query . "%'";
$ticketResult = $db->query($ticketSql);
$tickets = [];
while ($ticket = $ticketResult->fetch_assoc()) {
$tickets[] = $ticket;
}
//explore $query by space and add each word to the sql query with and
$query = explode(" ", $query);
$whereStr = "";
foreach ($query as $word) {
$whereStr .= " AND `content` LIKE '%" . $word . "%'";
}
$messagesSql = "SELECT * FROM `HistoricTicketMessage`
LEFT JOIN `HistoricTicket` ON `HistoricTicket`.`id` = `HistoricTicketMessage`.`ticket_id`
WHERE 1 AND `content` " . $whereStr;
$messagesResult = $db->query($messagesSql);
$messages = [];
while ($message = $messagesResult->fetch_assoc()) {
$messages[] = $message;
}
$return = [];
foreach ($tickets as $ticket) {
$return[] = [
"table_entry" => "ticket",
"ticket_id" => $ticket["id"],
"ticket_number" => $ticket["ticket_number"],
"ctime" => $ticket["ctime"],
"ticket_subject" => $ticket["subject"],
];
}
foreach ($messages as $message) {
$return[] = [
"table_entry" => "message",
"ticket_id" => $message["ticket_id"],
"ticket_number" => $message["ticket_number"],
"ticket_subject" => $message["subject"],
"ctime" => $message["ctime"],
"ticket_message" => $message["content"],
];
}
return $return;
}
}

View File

@@ -6,7 +6,8 @@ class Timerecording extends mfBaseModel
private $creator;
private $user;
private $timerecordingCategory;
private $timerecordingCar;
public function getProperty($name)

View File

@@ -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 = '<i class="fa-regular fa-circle-check mr-1"></i>';
}
$edit = "";
if ($timerecording->businesstrip == 1) {
$category = "<span>" . $timerecording->timerecordingCategory->name . "</span><span class='text-bold ml-1'> (Dienstreise: " . $timerecording->businesstrip_info . ")</span>";
if ($timerecording->timerecordingCategory->hourday == 7) {
$distance = $timerecording->mileage_end - $timerecording->mileage_start;
$category = "<span>" . $timerecording->timerecordingCategory->name . "</span><span class='text-bold ml-1'>(" . $timerecording->timerecordingCar->number_plate . " " . $distance . "KM) (Zielort: " . $timerecording->businesstrip_info . ")</span>";
} 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 = "<span>" . $timerecording->timerecordingCategory->name . "</span><span class='text-bold ml-1'>$car (Dienstreise: " . $timerecording->businesstrip_info . ")</span>";
} else if ($timerecording->homeoffice == 1) {
$category = "<span>" . $timerecording->timerecordingCategory->name . "</span><span class='text-bold ml-1'> (Homeoffice)</span>";
} 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"></i>';
else :
$edit .= '<div class="edit-placeholder"></div>';
endif;
$edit .= '<i data-id="' . $timerecording->id . '" class="fas fa-trash text-danger delete-item" ></i>';
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),

View File

@@ -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;
@@ -151,7 +155,7 @@ class TimerecordingModel
$start = $filter['start'];
$end = $filter['end'];
if (is_numeric($start) && is_numeric($end)) {
$where .= " AND ((`start` >= $start AND `start` <= $end) OR (`end` >= $start AND `end` <= $end) OR `end` is NULL) ORDER by user_id ASC";
$where .= " AND ((`start` >= $start AND `start` <= $end) OR (`end` >= $start AND `end` <= $end) OR `end` is NULL) ORDER by user_id,start ASC";
}
}
if (array_key_exists("start", $filter) && array_key_exists("timerecordingCategory_id", $filter)) {
@@ -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'];
@@ -182,11 +199,11 @@ class TimerecordingModel
$id = $filter['id'];
if (is_numeric($starttime) && is_numeric($endtime)) {
if ($id && is_numeric($id)) {
$where .= " AND `id` != $id";
$where .= " AND `id` != $id ";
}
$where .= " AND (((`start` <= $starttime AND `end` > $starttime ) OR (`start` > $endtime AND `end` < $endtime) OR (`start` > $starttime AND `end` > $starttime AND `start` <= $endtime AND `end` <= $endtime) OR (`start` > $starttime AND `end` > $starttime AND `start` < $endtime AND `end` > $endtime) OR (`start` = $starttime AND `end` = $endtime )) OR ( `start` <= $starttime AND `end` IS NULL)) ORDER by user_id ASC";
$where .= " AND (((`start` <= $starttime AND `end` > $starttime ) OR (`start` > $endtime AND `end` < $endtime) OR (`start` > $starttime AND `end` > $starttime AND `start` <= $endtime AND `end` <= $endtime) OR (`start` > $starttime AND `end` > $starttime AND `start` < $endtime AND `end` > $endtime) OR (`start` = $starttime AND `end` = $endtime )) OR ( `start` <= $starttime AND `end` IS NULL)) AND `days` = 0 ORDER by user_id,start ASC";
//var_dump($where);exit;
//echo ($where);die();
}
}
if (array_key_exists("type", $filter)) {

View File

@@ -0,0 +1,60 @@
<?php
class TimerecordingBilling extends mfBaseModel
{
private $editor;
private $creator;
private $timerecordingEmployee;
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;
}
}

View File

@@ -0,0 +1,557 @@
<?php
class TimerecordingBillingController extends mfBaseController
{
protected function init()
{
$this->needlogin = true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me", $me);
if (!$me->can(["Fibu"])) {
$this->redirect("Dashboard");
}
}
protected function indexAction()
{
$startdate = 1709254800;
$today = time();
$months = [];
$month = $startdate;
while ($month < $today) {
$months[] = date("m.Y", $month);
$month = strtotime("+1 month", $month);
}
$timerecordingBillings = TimerecordingBillingModel::getAll();
foreach ($timerecordingBillings as $timerecordingBilling) {
$timerecordingbillings[$timerecordingBilling->month] = $timerecordingBilling;
echo $timerecordingBilling->month;
}
$this->layout()->set("months", $months);
$this->layout()->set("timerecordingbillings", $timerecordingbillings);
$this->layout()->setTemplate("TimerecordingBilling/Index");
}
protected function detailClosedAction($timerecordingBilling)
{
$r = $this->request;
$month = $r->get("month");
$month = strtotime("01." . $month);
$timerecordings = TimerecordingBillingEmployeeModel::search(["timerecordingBilling_id" => $timerecordingBilling[0]->id]);
$this->layout()->setTemplate("TimerecordingBilling/DetailClosed");
$this->layout()->set("month", date("m.Y", $month));
$this->layout()->set("timerecordings", $timerecordings);
}
protected function detailAction()
{
$r = $this->request;
$month = $r->get("month");
if (!$month) {
$this->redirect("TimerecordingBilling");
}
$timerecordingBilling = TimerecordingBillingModel::search(["month" => $month]);
if ($timerecordingBilling) {
$this->detailclosedAction($timerecordingBilling);
} else {
$month = strtotime("01." . $month);
$timerecordingsEmolyees = TimerecordingEmployeeModel::getAll();
foreach ($timerecordingsEmolyees as $timerecordingsEmolyee) {
if ($timerecordingsEmolyee->bmd_active == 0) continue;
$user = new User($timerecordingsEmolyee->user_id);
$employee_number = (string)$user->getFlag('employee_number');
$timerecordingReport = new TimerecordingReportController();
$timerecordings[$timerecordingsEmolyee->user_id]['user_id'] = $timerecordingsEmolyee->user_id;
$timerecordings[$timerecordingsEmolyee->user_id]['user_name'] = $timerecordingsEmolyee->user->name;
$timerecordings[$timerecordingsEmolyee->user_id]['employee_number'] = $employee_number;
$timerecordings[$timerecordingsEmolyee->user_id]['data'] = $timerecordingReport->getTimerecordingsTimes('2', $month, $month, $month, $timerecordingsEmolyee->user_id, 0);
}
$this->layout()->set("timerecordings", $timerecordings);
$this->layout()->setTemplate("TimerecordingBilling/Detail");
$this->layout()->set("month", date("m.Y", $month));
}
}
protected function apiAction()
{
$do = $this->request->do;
$month = $this->request->month;
$data = [];
switch ($do) {
case "generatebmdexport":
$return = $this->generateBmdExport($month);
break;
case "generatebmdexportnlz":
$return = $this->generateBmdExport($month, 1);
break;
case "generatebmdexportclosed":
$return = $this->generateBmdExportClosed($month);
break;
case "generatebmdexportnlzclosed":
$return = $this->generateBmdExportClosed($month, 1);
break;
case "completemonth":
$return = $this->completemonth($month);
break;
case "saveovertime":
$return = $this->saveovertime();
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 addAction()
{
}
protected function editAction()
{
}
protected function saveAction()
{
$r = $this->request;
$id = $r->id;
//var_dump($r->get());exit;
if (is_numeric($id) && $id > 0) {
$mode = "edit";
$timerecordingbillings = new TimerecordingBilling($id);
if (!$timerecordingbillings->id) {
$this->layout()->setFlash("Timerecording nicht gefunden", "error");
$this->redirect("TimerecordingBilling");
}
} else {
$mode = "add";
}
$data = [];
$data['month'] = trim($r->month);
$data['closetime'] = time();
if (!$data['month']) {
$data['month'] = NULL;
}
if (!$data['closetime']) {
$data['closetime'] = NULL;
}
// var_dump($_FILES);
// var_dump($upload);
// exit;
if ($mode == "edit") {
$timerecordingbillings->update($data);
} else {
$timerecordingbillings = TimerecordingBillingModel::create($data);
}
// var_dump($filestore);
// exit;
$id = $timerecordingbillings->save();
if (!$id) {
$this->layout()->setFlash("Timerecording konnte nicht angelegt werden", "error");
$this->redirect("TimerecordingBilling");
}
if ($mode == "edit") {
// $this->layout()->setFlash("Timerecording erfolgreich geändert", "success");
} else if ($mode = "add") {
// $this->layout()->setFlash("Timerecording erfolgreich angelegt", "success");
}
return $id;
}
protected function deleteAction()
{
$id = $this->request->id;
$timerecordingbillings = new TimerecordingBilling($id);
if (!$timerecordingbillings->id || $timerecordingbillings->id != $id) {
$this->layout()->setFlash("Timerecording nicht gefunden.", "error");
$this->redirect("TimerecordingBilling");
}
$timerecordingbillings->delete();
$this->redirect("TimerecordingBilling");
}
protected function generateBmdLine()
{
}
protected function generateBmdExportClosed($month, $nlz = 0)
{
$filename = "import_bmd_" . $month . ".csv";
$file = fopen("php://output", 'w');
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=' . $filename);
$monthbmd = date("n", strtotime("01." . $month));
$companybmd = "1";
if ($nlz == 0) {
$headerarray = ["Monat", "Firma", "Mitarbeiter", "Lohnart", "Menge", "Satz", "Betrag", "Kostenstelle", "NLZ-Kennzeichen", "NLZ Von-Datum", "NLZ Bis-Datum"];
fputcsv($file, $headerarray, ";");
} else {
$headerarray = ["Firma", "Mitarbeiter", "DV-Nr", "Art", "Sonderzeit", "Verarbeitungs-KZ", "Von", "Bis", "Verwaltung", "Bezahlt"];
fputcsv($file, $headerarray, ";");
}
$billing = TimerecordingBillingModel::search(["month" => $month]);
$timerecordingBillingEmployees = TimerecordingBillingEmployeeModel::search(["timerecordingBilling_id" => $billing[0]->id]);
foreach ($timerecordingBillingEmployees as $timerecordingBillingEmployee) {
if ($timerecordingBillingEmployee->timerecordingEmployee->bmd_active == 0) continue;
$user = new User($timerecordingBillingEmployee->timerecordingEmployee->user_id);
$employee_number = (string)$user->getFlag('employee_number');
$employeetypesbmd = TimerecordingEmployeeModel::$employeetypesbmd;
$employee_type = $employeetypesbmd[$timerecordingBillingEmployee->timerecordingEmployee->type];
$overtimebase = 0;
if ($nlz == 0) {
$hours = $timerecordingBillingEmployee->ishours / 3600;
$hours = round($hours, 2);
$hours = str_replace(".", ",", $hours);
if ($hours > 0) {
$bodyarray = [$monthbmd, "1", $employee_number, $employee_type, $hours, "", "", "", "", "", ""];
fputcsv($file, $bodyarray, ";");
}
if ($timerecordingBillingEmployee->overtime50free > 0) {
$overtime50free = $timerecordingBillingEmployee->overtime50free / 3600;
$overtime50free = round($overtime50free, 2);
$overtimebase = $overtimebase + $overtime50free;
$overtime50free = str_replace(".", ",", $overtime50free);
$bodyarray = [$monthbmd, "1", $employee_number, "3110", $overtime50free, "", "", "", "", "", ""];
fputcsv($file, $bodyarray, ";");
}
if ($timerecordingBillingEmployee->overtime100free > 0) {
$overtime100free = $timerecordingBillingEmployee->overtime100free / 3600;
$overtime100free = round($overtime100free, 2);
$overtimebase = $overtimebase + $overtime100free;
$overtime100free = str_replace(".", ",", $overtime100free);
$bodyarray = [$monthbmd, "1", $employee_number, "3160", $overtime100free, "", "", "", "", "", ""];
fputcsv($file, $bodyarray, ";");
}
if ($overtimebase > 0) {
$overtimebase = str_replace(".", ",", $overtimebase);
$bodyarray = [$monthbmd, "1", $employee_number, "3100", $overtimebase, "", "", "", "", "", ""];
fputcsv($file, $bodyarray, ";");
}
if ($timerecordingBillingEmployee->homeoffice > 0) {
$homeoffice = $timerecordingBillingEmployee->homeoffice;
$homeoffice = round($homeoffice, 2);
$homeoffice = str_replace(".", ",", $homeoffice);
$bodyarray = [$monthbmd, "1", $employee_number, "7590", $homeoffice, "", "", "", "", "", ""];
fputcsv($file, $bodyarray, ";");
}
} else {
if ($timerecordingBillingEmployee->nlz_detail) {
foreach (json_decode($timerecordingBillingEmployee->nlz_detail, true) as $nlztime) {
$bodyarray = [$companybmd, $employee_number, 1, $nlztime['categoryshort'], $nlztime['catExtended'], "3", $nlztime['start'], $nlztime['end'], $nlztime['time'], $nlztime['pay']];
fputcsv($file, $bodyarray, ";");
}
}
}
if ($timerecordingBillingEmployee->diet > 0 && $nlz == 0) {
$dietsum = round($timerecordingBillingEmployee->diet, 2);
$dietsum = str_replace(".", ",", $dietsum);
$bodyarray = [$monthbmd, $companybmd, $employee_number, "2500", "", "", $dietsum, "", "", "", ""];
fputcsv($file, $bodyarray, ";");
}
}
fclose($file);
exit;
}
protected function generateBmdExport($month, $nlz = 0, $export = 1)
{
//create and download csv file
if ($export == 1) {
$filename = "import_bmd_" . $month . ".csv";
$file = fopen("php://output", 'w');
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=' . $filename);
}
if ($export == 1) {
if ($nlz == 0) {
$headerarray = ["Monat", "Firma", "Mitarbeiter", "Lohnart", "Menge", "Satz", "Betrag", "Kostenstelle", "NLZ-Kennzeichen", "NLZ Von-Datum", "NLZ Bis-Datum"];
fputcsv($file, $headerarray, ";");
} else {
$headerarray = ["Firma", "Mitarbeiter", "DV-Nr", "Art", "Sonderzeit", "Verarbeitungs-KZ", "Von", "Bis", "Verwaltung", "Bezahlt"];
fputcsv($file, $headerarray, ";");
}
}
$month = strtotime("01." . $month);
//last of month
$monthend = date("Y-m-d", strtotime("last day of this month", $month));
$monthend = strtotime($monthend . " 23:59:59");
$monthbmd = date("n", $month);
$companybmd = "1";
$timerecordingsEmolyees = TimerecordingEmployeeModel::getAll();
foreach ($timerecordingsEmolyees as $timerecordingsEmolyee) {
if ($timerecordingsEmolyee->bmd_active == 0) continue;
$user = new User($timerecordingsEmolyee->user_id);
$employee_number = (string)$user->getFlag('employee_number');
$employeetypesbmd = TimerecordingEmployeeModel::$employeetypesbmd;
$employee_type = $employeetypesbmd[$timerecordingsEmolyee->type];
$timerecordingReport = new TimerecordingReportController();
$timerecording = $timerecordingReport->getTimerecordingsTimes('2', $month, $month, $month, $timerecordingsEmolyee->user_id, 0);
if ($export == 0) {
$reponse[$employee_number]['employee_id'] = $timerecordingsEmolyee->id;
$reponse[$employee_number]['homeoffice'] = $timerecording['time']['homeoffice'];
$reponse[$employee_number]['istimeall'] = $timerecording['time']['isorder'];
$reponse[$employee_number]['musttime'] = $timerecording['time']['mustorder'];
}
foreach ($timerecording['time']['isclean'] as $key => $value) {
$hours = $value;
//calc ishours in hours
$hours = $hours / 3600;
$hours = round($hours, 2);
$hours = str_replace(".", ",", $hours);
if (strpos($key, ',') !== false && $nlz == 0) {
if ($export == 1) {
$bodyarray = [$monthbmd, $companybmd, $employee_number, $employee_type, $hours, "", "", "", "", "", ""];
fputcsv($file, $bodyarray, ";");
} else {
$reponse[$employee_number]['istime'] = $value;
}
} else if (strpos($key, ',') === false && $nlz == 1) {
}
}
if ($timerecording['time']['diet'] > 0 && $nlz == 0) {
$dietsum = round($timerecording['time']['diet'], 2);
if ($export == 1) {
$dietsum = str_replace(".", ",", $dietsum);
$bodyarray = [$monthbmd, $companybmd, $employee_number, "2500", "", "", $dietsum, "", "", "", ""];
fputcsv($file, $bodyarray, ";");
} else {
$reponse[$employee_number]['diet'] = $dietsum;
}
}
if (!empty($timerecording['time']['nlztimes']) && ($nlz == 1 || $export == 0)) {
foreach ($timerecording['time']['nlztimes'] as $nlztime) {
if (strtotime($nlztime['start']) < $month) {
$nlztime['start'] = date("d.m.Y", $month);
}
if ((strtotime($nlztime['end']) + 84599) > $monthend) {
$nlztime['end'] = date("d.m.Y", $monthend);
}
if (strpos($nlztime['categoryshort'], '6-') !== false) {
$catExtended = explode("-", $nlztime['categoryshort']);
$catExtended = $catExtended[1];
$nlztime['categoryshort'] = "6";
} else {
$catExtended = "";
}
if ($nlztime['minutes']) {
$timesecounds = $nlztime['minutes'];
$time = $nlztime['minutes'] / 60;
$time = round($time, 2);
$time = str_replace(".", ",", $time);
if ($nlztime['unpaid'] == "0") {
$pay = $time;
} else {
$pay = 0;
}
} else {
if (empty($catExtended)) {
$time = "";
$timesecounds = "";
$pay = "";
} else {
//calc days from $nlztime['start'] to $nlztime['end']
$start = strtotime($nlztime['start']);
$end = strtotime($nlztime['end']);
$time = ($end - $start);
$timesecounds = $time;
$time = $time / 86400 + 1;
$time = round($time, 0);
if ($nlztime['unpaid'] == "0") {
$pay = $time;
} else {
$pay = 0;
}
}
}
if ($export == 1) {
$bodyarray = [$companybmd, $employee_number, 1, $nlztime['categoryshort'], $catExtended, "3", $nlztime['start'], $nlztime['end'], $time, $pay];
fputcsv($file, $bodyarray, ";");
} else {
$reponse[$employee_number]['nlz'][] = array("categoryshort" => $nlztime['categoryshort'], "catExtended" => $catExtended, "start" => $nlztime['start'], "end" => $nlztime['end'], "time" => $time, "pay" => $pay);
}
}
if ($export == 0) {
$reponse[$employee_number]['daysum'] = json_encode($timerecording['time']['daysum']);
}
}
}
if ($export == 1) {
fclose($file);
exit;
} else {
return $reponse;
}
}
protected function completemonth($month)
{
$id = $this->saveAction();
$user = new User($timerecordingsEmolyee->user_id);
$employee_number = (string)$user->getFlag('employee_number');
$timerecordings = $this->generateBmdExport($month, 0, 0);
foreach ($timerecordings as $employeenumber => $timerecording) {
$data = [];
$data['timerecordingBilling_id'] = $id;
$data['timerecordingEmployee_id'] = $timerecording['employee_id'];
$data['musthours'] = $timerecording['musttime'];
if ($timerecording['istime']) {
$data['ishours'] = $timerecording['istime'];
} else {
$data['ishours'] = 0;
}
$data['ishourssum'] = $timerecording['istimeall'];
$data['diet'] = $timerecording['diet'];
if ($timerecording['nlz']) {
$data['nlz_detail'] = json_encode($timerecording['nlz']);
}
if ($timerecording['daysum']) {
$data['nlz'] = $timerecording['daysum'];
}
if ($timerecording['homeoffice']) {
$data['homeoffice'] = $timerecording['homeoffice'];
}
if (!$data['diet']) {
$data['diet'] = 0;
}
$timerecordingbillingemployee = TimerecordingBillingEmployeeModel::create($data);
$timerecordingbillingemployee->save();
}
$result['state'] = "success";
echo json_encode($result);
die();
}
protected function saveovertime()
{
$id = $this->request->id;
$type = $this->request->type;
$timerecordingbillingsemployee = new TimerecordingBillingEmployee($id);
if ($type == "overtime") {
$sum = 0;
$data = [];
if ($this->request->overtime50) {
$data['overtime50free'] = $timerecordingbillingsemployee->overtime50free + $this->request->overtime50 * 3600;
$sum += $this->request->overtime50 * 3600;
}
if ($this->request->overtime100) {
$data['overtime100free'] = $timerecordingbillingsemployee->overtime100free + $this->request->overtime100 * 3600;
$sum += $this->request->overtime100 * 3600;
}
if ($this->request->overtimebpa) {
$timerecordingbillingsemployee->timerecordingEmployee->id;
$timerecordingEmployee = new TimerecordingEmployee($timerecordingbillingsemployee->timerecordingEmployee->id);
$dataemployee = [];
$dataemployee['bpahours'] = $timerecordingEmployee->bpahours + $this->request->overtimebpa * 3600;
$sum += $this->request->overtimebpa * 3600;
$timerecordingEmployee->update($dataemployee);
$timerecordingEmployee->save();
}
if ($data) {
$timerecordingbillingsemployee->update($data);
$timerecordingbillingsemployee->save();
$timerecordingbillingsemployee->timerecordingEmployee->id;
$timerecordingEmployee = new TimerecordingEmployee($timerecordingbillingsemployee->timerecordingEmployee->id);
$dataemployee = [];
$dataemployee['overtime_now'] = $timerecordingEmployee->overtime_now - $sum;
$dataemployee['overtime'] = $timerecordingEmployee->overtime - $sum;
$timerecordingEmployee->update($dataemployee);
$timerecordingEmployee->save();
}
} else if ($type == "difference") {
$sum = 0;
$data = [];
if ($this->request->overtime50) {
$data['overtime50free'] = $timerecordingbillingsemployee->overtime50free + $this->request->overtime50 * 3600;
$sum += $this->request->overtime50 * 3600;
}
if ($this->request->overtime100) {
$data['overtime100free'] = $timerecordingbillingsemployee->overtime100free + $this->request->overtime100 * 3600;
$sum += $this->request->overtime100 * 3600;
}
if ($this->request->overtimebpa) {
$timerecordingbillingsemployee->timerecordingEmployee->id;
$timerecordingEmployee = new TimerecordingEmployee($timerecordingbillingsemployee->timerecordingEmployee->id);
$dataemployee = [];
$dataemployee['bpahours'] = $timerecordingEmployee->bpahours + $this->request->overtimebpa * 3600;
$sum += $this->request->overtimebpa * 3600;
$timerecordingEmployee->update($dataemployee);
$timerecordingEmployee->save();
}
if ($sum > 0) {
$data['ishourssum'] = $timerecordingbillingsemployee->ishourssum - $sum;
$timerecordingbillingsemployee->update($data);
$timerecordingbillingsemployee->save();
}
}
$response['state'] = "success";
echo json_encode($response);
die();
}
}

View File

@@ -0,0 +1,128 @@
<?php
class TimerecordingBillingModel
{
public static $dieatBase = 26.4;
public static $excludeEmployees = [1000, 1001, 9999, 4, 5, 6, 7, 8, 9, 10];
private $month;
private $closetime;
public static function find($data)
{
}
public static function create(array $data)
{
$model = new TimerecordingBilling();
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("TimerecordingBilling", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new TimerecordingBilling($data);
}
return $item;
}
public static function getAll()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("TimerecordingBilling", "*", "1=1");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new TimerecordingBilling($data);
}
}
return $items;
}
public static function getFirst()
{
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("TimerecordingBilling", "*", "$where ");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new TimerecordingBilling($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("TimerecordingBilling", "*", "$where");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new TimerecordingBilling($data);
}
}
return $items;
}
private static function getSqlFilter($filter)
{
$where = "1=1 ";
//var_dump($filter);exit;
if (array_key_exists("month", $filter)) {
$month = $filter['month'];
if ($month) {
$where .= " AND month=$month";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -0,0 +1,61 @@
<?php
class TimerecordingBillingEmployee extends mfBaseModel
{
private $editor;
private $creator;
private $timerecordingBilling;
private $timerecordingEmployee;
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;
}
}

View File

@@ -0,0 +1,172 @@
<?php
class TimerecordingBillingEmployeeController 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("TimerecordingBillingEmployee/Index");
$timerecordingbillingemployees = TimerecordingBillingEmployeeModel::getAll();
$this->layout()->set("timerecordingbillingemployees", $timerecordingbillingemployees);
}
protected function addAction()
{
$timerecordingBillingEmployees = TimerecordingBillingEmployeeModel::getAll();
$this->layout()->set("timerecordingBillingEmployees", $timerecordingBillingEmployees);
$timerecordingEmployees = TimerecordingEmployeeModel::getAll();
$this->layout()->set("timerecordingEmployees", $timerecordingEmployees);
$this->layout()->setTemplate("TimerecordingBillingEmployee/Form");
}
protected function editAction()
{
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("fdfsdf nicht gefunden", "error");
$this->redirect("TimerecordingBillingEmployee");
}
$timerecordingbillingemployees = new TimerecordingBillingEmployee($id);
if ($timerecordingbillingemployees->id != $id) {
$this->layout()->setFlash("fdfsdf nicht gefunden", "error");
$this->redirect("TimerecordingBillingEmployee");
}
$this->layout()->set("timerecordingbillingemployees", $timerecordingbillingemployees);
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";
$timerecordingbillingemployees = new TimerecordingBillingEmployee($id);
if (!$timerecordingbillingemployees->id) {
$this->layout()->setFlash("dfsdfsdfds nicht gefunden", "error");
$this->redirect("TimerecordingBillingEmployee");
}
} else {
$mode = "add";
}
$data = [];
$data['timerecordingBillingEmployee_id'] = trim($r->timerecordingBillingEmployee_id);
$data['timerecordingEmployee_id'] = trim($r->timerecordingEmployee_id);
$data['type'] = trim($r->type);
$data['ishours'] = trim($r->ishours);
$data['overtime25'] = trim($r->overtime25);
$data['plushours50'] = trim($r->plushours50);
$data['plushours50free'] = trim($r->plushours50free);
$data['plushours100'] = trim($r->plushours100);
$data['plushours100free'] = trim($r->plushours100free);
$data['homeoffice'] = trim($r->homeoffice);
$data['diet'] = trim($r->diet);
$data['nlz'] = trim($r->nlz);
$data['nlz_detail'] = trim($r->nlz_detail);
if (!$data['timerecordingBillingEmployee_id']) {
$data['timerecordingBillingEmployee_id'] = NULL;
}
if (!$data['timerecordingEmployee_id']) {
$data['timerecordingEmployee_id'] = NULL;
}
if (!$data['type']) {
$data['type'] = NULL;
}
if (!$data['ishours']) {
$data['ishours'] = NULL;
}
if (!$data['overtime25']) {
$data['overtime25'] = NULL;
}
if (!$data['plushours50']) {
$data['plushours50'] = NULL;
}
if (!$data['plushours50free']) {
$data['plushours50free'] = NULL;
}
if (!$data['plushours100']) {
$data['plushours100'] = NULL;
}
if (!$data['plushours100free']) {
$data['plushours100free'] = NULL;
}
if (!$data['homeoffice']) {
$data['homeoffice'] = NULL;
}
if ($data['diet'] == NULL) {
$data['diet'] = 0;
}
if (!$data['nlz']) {
$data['nlz'] = NULL;
}
if (!$data['nlz_detail']) {
$data['nlz_detail'] = NULL;
}
// var_dump($_FILES);
// var_dump($upload);
// exit;
if ($mode == "edit") {
$timerecordingbillingemployees->update($data);
} else {
$timerecordingbillingemployees = TimerecordingBillingEmployeeModel::create($data);
}
// var_dump($filestore);
// exit;
$id = $timerecordingbillingemployees->save();
if (!$id) {
$this->layout()->setFlash("fdfsdf konnte nicht angelegt werden", "error");
$this->redirect("TimerecordingBillingEmployee");
}
if ($mode == "edit") {
$this->layout()->setFlash("fdfsdf erfolgreich geändert", "success");
} else if ($mode = "add") {
$this->layout()->setFlash("fdfsdf erfolgreich angelegt", "success");
}
$this->redirect("TimerecordingBillingEmployee");
}
protected function deleteAction()
{
$id = $this->request->id;
$timerecordingbillingemployees = new TimerecordingBillingEmployee($id);
if (!$timerecordingbillingemployees->id || $timerecordingbillingemployees->id != $id) {
$this->layout()->setFlash("fdfsdf nicht gefunden.", "error");
$this->redirect("TimerecordingBillingEmployee");
}
$timerecordingbillingemployees->delete();
$this->redirect("TimerecordingBillingEmployee");
}
}

View File

@@ -0,0 +1,139 @@
<?php
class TimerecordingBillingEmployeeModel
{
private $timerecordingBilling_id;
private $timerecordingEmployee_id;
private $musthours;
private $type;
private $ishours;
private $ishourssum;
private $overtime25;
private $plushours50;
private $plushours50free;
private $plushours100;
private $plushours100free;
private $homeoffice;
private $diet;
private $nlz;
private $nlz_detail;
public static function find($data)
{
}
public static function create(array $data)
{
$model = new TimerecordingBillingEmployee();
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("TimerecordingBillingEmployee", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new TimerecordingBillingEmployee($data);
}
return $item;
}
public static function getAll()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("TimerecordingBillingEmployee", "*", "1=1");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new TimerecordingBillingEmployee($data);
}
}
return $items;
}
public static function getFirst()
{
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("TimerecordingBillingEmployee", "*", "$where ");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new TimerecordingBillingEmployee($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("TimerecordingBillingEmployee", "*", "$where");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new TimerecordingBillingEmployee($data);
}
}
return $items;
}
private static function getSqlFilter($filter)
{
$where = "1=1 ";
//var_dump($filter);exit;
if (array_key_exists("timerecordingBilling_id", $filter)) {
$timerecordingBilling_id = $filter['timerecordingBilling_id'];
if (is_numeric($timerecordingBilling_id)) {
$where .= " AND timerecordingBilling_id='$timerecordingBilling_id'";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -0,0 +1,60 @@
<?php
class TimerecordingCar extends mfBaseModel
{
private $user;
private $editor;
private $creator;
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;
}
}

View File

@@ -0,0 +1,179 @@
<?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");
}
}

View File

@@ -0,0 +1,157 @@
<?php
class TimerecordingCarModel
{
private $user_id;
private $number_plate;
private $brand;
private $model;
private $mileage;
private $mileage_now;
private $mileage_timestamp;
private $initial_approval;
private $first_approval;
private $timerecording;
public static function find($data)
{
}
public static function create(array $data)
{
$model = new TimerecordingCar();
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("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;
}
}

View File

@@ -87,6 +87,7 @@ class TimerecordingCategoryController extends mfBaseController
$data['require_comment'] = trim($r->require_comment);
$data['only_admin'] = trim($r->only_admin);
$data['businesstrip'] = trim($r->businesstrip);
$data['unpaid'] = trim($r->unpaid);
if (!$data['name']) {
@@ -107,6 +108,9 @@ class TimerecordingCategoryController extends mfBaseController
if (!$data['businesstrip']) {
$data['businesstrip'] = 0;
}
if (!$data['unpaid']) {
$data['unpaid'] = 0;
}
// var_dump($_FILES);
// var_dump($upload);
// exit;

View File

@@ -9,7 +9,8 @@ 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)");
private $unpaid;
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");

View File

@@ -114,13 +114,21 @@ class TimerecordingEmployeeController extends mfBaseController
$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['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);

View File

@@ -16,7 +16,10 @@ class TimerecordingEmployeeModel
private $overtime_timestamp;
private $bpahours;
private $startdate;
private $enddate;
private $bmd_active;
private $birthday;
public static $employeetypesbmd = array('1' => '1000', '2' => '1200', '3' => '1400');
public static function find($data)

View File

@@ -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 = '<i class="fa-regular fa-circle-check mr-1"></i>';
}
$edit = "";
if ($timerecording->businesstrip == 1) {
$category = "<span>" . $timerecording->timerecordingCategory->name . "</span><span class='text-bold ml-1'> (Dienstreise: " . $timerecording->businesstrip_info . ")</span>";
if ($timerecording->timerecordingCategory->hourday == 7) {
$distance = $timerecording->mileage_end - $timerecording->mileage_start;
$category = "<span>" . $timerecording->timerecordingCategory->name . "</span><span class='text-bold ml-1'>(" . $timerecording->timerecordingCar->number_plate . " " . $distance . "KM) (Zielort: " . $timerecording->businesstrip_info . ")</span>";
} 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 = "<span>" . $timerecording->timerecordingCategory->name . "</span><span class='text-bold ml-1'>$car (Dienstreise: " . $timerecording->businesstrip_info . ")</span>";
} else if ($timerecording->homeoffice == 1) {
$category = "<span>" . $timerecording->timerecordingCategory->name . "</span><span class='text-bold ml-1'> (Homeoffice)</span>";
} 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"></i>';
else :
$edit .= '<div class="edit-placeholder"></div>';
endif;
$edit .= '<i data-id="' . $timerecording->id . '" class="fas fa-trash text-danger delete-item" ></i>';
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,33 @@ 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;
$isSecondscleanarray = array();
$holiDays = 0;
$plusHours = 0;
$nlzTimes = array();
$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;
$plusHours_now = $employee[0]->plushours_now;
$overtime_now = $employee[0]->overtime_now;
$auto_workinghours = $employee[0]->auto_workinghours;
$startdate = $employee[0]->startdate;
$bpahours = $employee[0]->bpahours;
}
$workinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $r->user_id]);
$workinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $user_id]);
$holidays = TimerecordingHolidayModel::getAll();
foreach ($workinghours as $workinghour) {
@@ -402,7 +436,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 +456,11 @@ 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];
//Lastdate staticmust deleted
// $lastdate = strtotime("2024-03-22 23:59:59");
// $daycount=22;
$searchArray = ['user_id' => $user_id, 'start' => $firstdate, 'end' => $lastdate];
$timestamp = $firstdate;
for ($i = 1; $i <= $daycount; $i++) {
@@ -441,7 +479,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,14 +500,52 @@ class TimerecordingReportController extends mfBaseController
$timerecordingcategories = TimerecordingCategoryModel::getAll();
$timerecordings = TimerecordingModel::search($searchArray);
$responsecount = count($timerecordings);
$oldday = "";
$homeoffice = false;
$homeofficesum = 0;
$dietsum = 0;
$diet = 0;
$dietbase = TimerecordingBillingModel::$dieatBase;
foreach ($timerecordings as $timerecording):
$state = "";
$enddate = "";
$sum = "-";
$day = "";
$orderdate = $timerecording->start;
if ($oldday != date('Y-m-d', $timerecording->start)) {
if ($homeoffice == 1) {
$homeofficesum++;
$homeoffice = false;
}
if ($diet > 10800) {
if ($diet >= 43200) {
$diet = 43200;
}
$calcdiet = $dietbase / 12;
$calcdiet = ($diet / 3600) * $calcdiet;
$dietsum = $dietsum + $calcdiet;
}
$diet = 0;
}
if ($timerecording->homeoffice == 1 && (!$homeoffice || $homeoffice == 1)) {
$homeoffice = 1;
} else {
$homeoffice = 0;
}
if ($timerecording->businesstrip == 1 && $timerecording->timerecordingCategory->hourday == 1) {
$diet = $diet + $timerecording->end - $timerecording->start;
}
if ($timerecording->timerecordingCategory->hourday == 1) {
$date = date("d.m.Y", $timerecording->start);
$datadate = date("Y-m-d", $timerecording->start);
$start = date("H:i", $timerecording->start);
@@ -480,6 +556,27 @@ class TimerecordingReportController extends mfBaseController
$sum = sprintf("%02d", $hours) . ":" . sprintf("%02d", $minutes);
$day = $daysgerm[date("w", $timerecording->start)];
$isSeconds = $isSeconds + $seconds;
if ($isSecondscleanarray[$timerecording->timerecordingCategory->short]) {
$isSecondscleanarray[$timerecording->timerecordingCategory->short] = $isSecondscleanarray[$timerecording->timerecordingCategory->short] + $seconds;
} else {
$isSecondscleanarray[$timerecording->timerecordingCategory->short] = $seconds;
}
if ($timerecording->timerecordingCategory->short != "1000,1200,1400") {
if (!$daysum[$timerecording->timerecordingCategory->name]) {
$daysum[$timerecording->timerecordingCategory->name] = $seconds;
} else {
$daysum[$timerecording->timerecordingCategory->name] = $daysum[$timerecording->timerecordingCategory->name] + $seconds;
}
$nlzTimes[$timerecording->id]['start'] = date("d.m.Y", $timerecording->start);
$nlzTimes[$timerecording->id]['end'] = date("d.m.Y", $timerecording->end);
$nlzTimes[$timerecording->id]['minutes'] = $seconds / 60;
$nlzTimes[$timerecording->id]['unpaid'] = $timerecording->timerecordingCategory->unpaid;
$nlzTimes[$timerecording->id]['category'] = $timerecording->timerecordingCategory->name;
$nlzTimes[$timerecording->id]['categoryshort'] = $timerecording->timerecordingCategory->short;
}
} else if ($timerecording->timerecordingCategory->hourday == 2 || ($timerecording->timerecordingCategory->hourday == 3 && $timerecording->end)) {
$date = date("d.m.", $timerecording->start) . " - " . $daysgerm[date("w", $timerecording->end)] . " " . date("d.m.Y", $timerecording->end);
$datadate = date("Y-m-d", $timerecording->start);
@@ -500,10 +597,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,7 +618,24 @@ 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->name]) {
$daysum[$timerecording->timerecordingCategory->name] = $sumdays;
} else {
$daysum[$timerecording->timerecordingCategory->name] = $daysum[$timerecording->timerecordingCategory->name] + $sumdays;
}
$nlzTimes[$timerecording->id]['start'] = date("d.m.Y", $timerecording->start);
$nlzTimes[$timerecording->id]['end'] = date("d.m.Y", $timerecording->end);
$nlzTimes[$timerecording->id]['days'] = $sumdays;
$nlzTimes[$timerecording->id]['unpaid'] = $timerecording->timerecordingCategory->unpaid;
$nlzTimes[$timerecording->id]['category'] = $timerecording->timerecordingCategory->name;
$nlzTimes[$timerecording->id]['categoryshort'] = $timerecording->timerecordingCategory->short;
} else if ($timerecording->timerecordingCategory->hourday == 3 && !$timerecording->end) {
$date = date("d.m.Y", $timerecording->start) . " - " . $daysgerm[date("w", time())] . " " . date("d.m.Y", time());;
@@ -554,6 +676,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) {
@@ -593,18 +727,75 @@ class TimerecordingReportController extends mfBaseController
} else {
}
$oldday = date('Y-m-d', $timerecording->start);
endforeach;
if ($homeoffice == 1) {
$homeofficesum++;
$homeoffice = 0;
}
if ($diet > 10800) {
if ($diet >= 43200) {
$diet = 43200;
}
$calcdiet = $dietbase / 12;
$calcdiet = ($diet / 3600) * $calcdiet;
$dietsum = $dietsum + $calcdiet;
}
$summseconds = $isSeconds - $mustSeconds;
$isorder = $isSeconds;
if ($isSeconds < 0) {
$isSeconds = $isSeconds * -1;
$isSeconds = "-" . sprintf('%02dh:%02dm', floor($isSeconds / 3600), floor($isSeconds / 60 % 60));
} else {
$isSeconds = sprintf('%02dh:%02dm', floor($isSeconds / 3600), floor($isSeconds / 60 % 60));
}
$summsecondsorder = $summseconds;
if ($summseconds < 0) {
$summseconds = $summseconds * -1;
$summseconds = "-" . sprintf('%02dh:%02dm', floor($summseconds / 3600), floor($summseconds / 60 % 60));
} else {
$summseconds = sprintf('%02dh:%02dm', floor($summseconds / 3600), floor($summseconds / 60 % 60));
}
$plusHours_noworder = $plusHours_now;
if ($plusHours_now < 0) {
$plusHours_now = $plusHours_now * -1;
$plusHours_now = "-" . sprintf('%02dh:%02dm', floor($plusHours_now / 3600), floor($plusHours_now / 60 % 60));
} else {
$plusHours_now = sprintf('%02dh:%02dm', floor($plusHours_now / 3600), floor($plusHours_now / 60 % 60));
}
$json['success'] = true;
$json['time']['auto_workinghours'] = $auto_workinghours;
$json['time']['is'] = sprintf('%02dh:%02dm', floor($isSeconds / 3600), floor($isSeconds / 60 % 60));
$json['time']['is'] = $isSeconds;
$json['time']['isorder'] = $isorder;
$json['time']['isclean'] = $isSecondscleanarray;
$json['time']['must'] = sprintf('%02dh:%02dm', floor($mustSeconds / 3600), floor($mustSeconds / 60 % 60));
$json['time']['mustorder'] = $mustSeconds;
$json['time']['holidays'] = $holiDays;
$json['time']['plushours'] = sprintf('%02dh:%02dm', floor($plusHours / 3600), floor($plusHours / 60 % 60));
$json['time']['plushours_now'] = $plusHours_now;
$json['time']['plushours_noworder'] = $plusHours_noworder;
$json['time']['bpahours'] = sprintf('%02dh:%02dm', floor($bpahours / 3600), floor($bpahours / 60 % 60));
$json['time']['overtime_now'] = sprintf('%02dh:%02dm', floor($overtime_now / 3600), floor($overtime_now / 60 % 60));
$json['time']['overtime_noworder'] = $overtime_now;
$json['time']['homeoffice'] = $homeofficesum;
$json['time']['summseconds'] = $summseconds;
$json['time']['summsecondsorder'] = $summsecondsorder;
$json['time']['nlztimes'] = $nlzTimes;
$json['time']['diet'] = $dietsum;
$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()

View File

@@ -0,0 +1,9 @@
<?php
/**
* @property mixed|null $name
*/
class VoiceCallActive extends mfBaseModel
{
}

View File

@@ -0,0 +1,61 @@
<?php
class VoiceCallActiveController extends mfBaseController {
private User $me;
private string $VOICE_PORTAL_HOST = KOLMISOFT_API_HOST;
private string $VOICE_PORTAL_API_KEY = KOLMISOFT_API_KEY;
private string $VOICE_PORTAL_USERNAME = KOLMISOFT_API_USERNAME;
private KolmisoftMore $kolmisoftMore;
protected function init(): void {
$me = new User();
$me->loadMe();
$this->layout()->set("me", $me);
$this->me = $me;
if (!$this->me->isAdmin()) {
$this->redirect("dashboard");
}
$this->kolmisoftMore = new KolmisoftMore($this->VOICE_PORTAL_HOST, $this->VOICE_PORTAL_API_KEY, $this->VOICE_PORTAL_USERNAME);
}
protected function indexAction(): void {
$this->layout()->setTemplate("VoiceCallActive/Index");
}
protected function apiAction() {
$do = $this->request->do;
if (!$this->me->isAdmin()) {
$this->redirect("dashboard");
}
switch ($do) {
case "getActiveCalls":
$return = $this->getActiveCalls();
break;
default:
$return = false;
break;
}
if (!$return) {
$return = [
"status" => "error",
"message" => "Invalid request."
];
}
die(json_encode($return));
}
private function getActiveCalls(): array {
return [
"rows" => array_reverse($this->kolmisoftMore->getActiveCalls())
];
}
}

View File

@@ -0,0 +1,9 @@
<?php
/**
* @property mixed|null $name
*/
class VoiceCallHistory extends mfBaseModel
{
}

View File

@@ -0,0 +1,91 @@
<?php
class VoiceCallHistoryController extends mfBaseController {
private User $me;
private string $VOICE_PORTAL_HOST = KOLMISOFT_API_HOST;
private string $VOICE_PORTAL_API_KEY = KOLMISOFT_API_KEY;
private string $VOICE_PORTAL_USERNAME = KOLMISOFT_API_USERNAME;
private KolmisoftMore $kolmisoftMore;
protected function init(): void {
$me = new User();
$me->loadMe();
$this->layout()->set("me", $me);
$this->me = $me;
if (!$this->me->isAdmin()) {
$this->redirect("dashboard");
}
$this->kolmisoftMore = new KolmisoftMore($this->VOICE_PORTAL_HOST, $this->VOICE_PORTAL_API_KEY, $this->VOICE_PORTAL_USERNAME);
}
protected function indexAction(): void {
$this->layout()->setTemplate("VoiceCallHistory/Index");
}
protected function apiAction() {
$do = $this->request->do;
if (!$this->me->isAdmin()) {
$this->redirect("dashboard");
}
switch ($do) {
case "getCalls":
$return = $this->getCalls();
break;
case "importCallsFromToday":
$return = $this->importCallsFromToday();
break;
default:
$return = false;
break;
}
if (!$return) {
$return = [
"status" => "error",
"message" => "Invalid request."
];
}
die(json_encode($return));
}
private function importCallsFromToday(): array {
$startDate = strtotime(date("Y-m-d 0:00:00"));
$endDate = strtotime(date("Y-m-d 23:59:59"));
$callHistory = $this->kolmisoftMore->getVoiceCallHistory($startDate, $endDate);
return VoiceCallHistoryModel::importCallsFromKolmisoft($callHistory);
}
private function getCalls(): array {
$json = json_decode(file_get_contents('php://input'), true);
$filters = $json['filters'] ?? [];
$page = $json['pagination']['page'] ?? 1;
$perPage = $json['pagination']['per_page'] ?? 10;
$calls = VoiceCallHistoryModel::getVoiceCallHistory($filters, $perPage, $perPage * $page - $perPage);
$totalRows = VoiceCallHistoryModel::countVoiceCallHistory($filters);
return [
"rows" => $calls,
"pagination" => [
"page" => $page,
"total_pages" => ceil($totalRows / $perPage),
"per_page" => $perPage,
"total_rows" => intval($totalRows)
]
];
}
}

View File

@@ -0,0 +1,143 @@
<?php
class VoiceCallHistoryModel {
public $uid;
public $voice_account;
public $start;
public $source;
public $destination;
public $billable;
public $duration;
public function __construct($data = []) {
foreach ($data as $field => $value) {
if (property_exists(get_called_class(), $field)) {
$this->$field = $value;
}
}
}
/**
* Generate SQL Filter condition (space separated) for a given column.
*
* @param string|null $filterValue The filter value to match against.
* @param string $columnName The name of the column in the database table.
* @return string The SQL condition generated based on the filter value and column name.
*/
public static function generateFilterCondition(?string $filterValue, string $columnName): string {
$sql = "";
if (!empty($filterValue)) {
$filterItems = explode(" ", $filterValue);
foreach ($filterItems as $item) {
$sql .= " AND `$columnName` LIKE '%" . $item . "%'";
}
}
return $sql;
}
//TODO: combine these two functions into one
public static function importCallsFromKolmisoft($callHistory): array {
{
$modifiedCallHistory = [];
for ($i = 0; $i < count($callHistory); $i++) {
$call = $callHistory[$i];
$date = date("Y-m-d H:i:s", strtotime($call["calldate2"] . " UTC"));
$modifiedCall = [
"uid" => $call["uniqueid"],
"voice_account" => strpos($call["clid"], "Anonymous") !== false ? 'Anonymous' : preg_replace('/[^0-9]/', '', explode(" ", $call["clid"])[0]),
"start" => $date,
"source" => strpos($call["clid"], "nymous") !== false ? 'Anonymous' : str_replace("+", "", $call["src"]),
"destination" => $call["dst"],
"state" => preg_replace('/[^0-9]/', '', explode("(", $call["dispod"])[1]),
"billable" => gettype($call["did"]) === "string" ? 0 : 1,
"duration" => $call["nice_billsec"],
];
$modifiedCallHistory[] = $modifiedCall;
}
$voiceHistoryImport = VoiceCallHistoryModel::importVoiceCallHistory($modifiedCallHistory);
if ($callHistory === false) {
return [
"status" => "error",
"message" => "Failed to import calls."
];
}
return [
"status" => "success",
"message" => $voiceHistoryImport["message"]
];
}
}
public static function importVoiceCallHistory($callHistory): array {
$db = FronkDB::singleton();
$sql = /** @lang text */ "INSERT INTO `VoiceCallHistory` (`uid`, `voice_account`, `start`, `source`, `destination`, `state`, `billable`, `duration`) VALUES ";
$values = [];
foreach ($callHistory as $voiceCall) {
$uid = $voiceCall['uid'];
$valueStr = "(" .
($voiceCall['uid'] === 'Anonymous' ? 'NULL' : "'$uid'") . ", " .
($voiceCall['voice_account'] === 'Anonymous' ? 'NULL' : "'" . $voiceCall['voice_account']. "'" ) . ", '" .
$voiceCall['start'] . "', '" .
($voiceCall['source'] === 'Anonymous' ? "NULL" : $voiceCall['source']) . "', '" .
($voiceCall['destination'] === 'Anonymous' ? "NULL" : $voiceCall['destination'] ) . "', " .
$voiceCall['state'] . ", " .
$voiceCall['billable'] . ", " .
$voiceCall['duration'] . ")";
$values[] = $valueStr;
}
$sql .= implode(", ", $values);
$sql .= " ON DUPLICATE KEY UPDATE duration = VALUES(duration)";
$db->query($sql);
return [
"message" => "Imported " . count($callHistory) . " calls to the history."
];
}
public static function getSqlFilter($filters): string {
$sql = "";
if (isset($filters['start']['from']) && isset($filters['start']['to'])) {
$sql = " AND `start` >= FROM_UNIXTIME(" . $filters['start']['from'] . ") AND `start` <= FROM_UNIXTIME(" . $filters['start']['to'] . ")";
}
$sql .= isset($filters['end']) ? " AND `start` <= '" . $filters['end'] . "'" : "";
$sql .= isset($filters['source']) ? self::generateFilterCondition($filters['source'], "source") : "";
$sql .= isset($filters['destination']) ? self::generateFilterCondition($filters['destination'], "destination") : "";
$sql .= isset($filters['billable']) ? self::generateFilterCondition($filters['billable'], "billable") : "";
$sql .= isset($filters['duration']) ? self::generateFilterCondition($filters['duration'], "duration") : "";
return $sql . " ORDER BY `start` DESC";
}
public static function getVoiceCallHistory($filters, $limit = null, $offset = 0): array {
$db = FronkDB::singleton();
$sql = "SELECT * FROM `VoiceCallHistory` WHERE 1 " . self::getSqlFilter($filters);
$sql .= $limit === null ? "" : " LIMIT " . $limit . " OFFSET " . $offset;
$result = $db->query($sql);
$rows = [];
while ($row = $result->fetch_assoc()) {
$rows[] = new VoiceCallHistoryModel($row);
}
return $rows;
}
public static function countVoiceCallHistory($filters) {
$db = FronkDB::singleton();
$sql = "SELECT COUNT(*) as `total_rows` FROM `VoiceCallHistory` WHERE 1 " . self::getSqlFilter($filters);
$result = $db->query($sql);
return $result->fetch_assoc()['total_rows'];
}
}

View File

@@ -0,0 +1,9 @@
<?php
/**
* @property mixed|null $name
*/
class VoiceCallHistoryJob extends mfBaseModel
{
}

View File

@@ -0,0 +1,89 @@
<?php
//display errors
//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);
class VoiceCallHistoryJobController extends mfBaseController {
private User $me;
private string $VOICE_PORTAL_HOST = KOLMISOFT_API_HOST;
private string $VOICE_PORTAL_API_KEY = KOLMISOFT_API_KEY;
private string $VOICE_PORTAL_USERNAME = KOLMISOFT_API_USERNAME;
private KolmisoftMore $kolmisoftMore;
protected function init(): void {
$me = new User();
$me->loadMe();
$this->layout()->set("me", $me);
$this->me = $me;
if (!$this->me->isAdmin()) {
$this->redirect("dashboard");
}
$this->kolmisoftMore = new KolmisoftMore($this->VOICE_PORTAL_HOST, $this->VOICE_PORTAL_API_KEY, $this->VOICE_PORTAL_USERNAME);
}
protected function indexAction(): void {
$this->layout()->setTemplate("VoiceCallHistoryJob/Index");
}
protected function apiAction() {
$do = $this->request->do;
if (!$this->me->isAdmin()) {
$this->redirect("dashboard");
}
switch ($do) {
case "runJobs":
$return = $this->runJobs();
break;
default:
$return = false;
break;
}
if (!$return) {
$return = [
"status" => "error",
"message" => "Invalid request."
];
}
die(json_encode($return));
}
public function runJobs(): array {
VoiceCallHistoryJobModel::createJobsUntilToday();
$jobs = VoiceCallHistoryJobModel::getJobsNotDone();
$messages = [
"success" => [],
"error" => []
];
foreach ($jobs as $job) {
$startDate = strtotime(date("Y-m-d 00:00:00", strtotime($job->date)));
$endDate = strtotime(date("Y-m-d 00:00:00", strtotime($job->date . " +1 day")));
$callHistory = $this->kolmisoftMore->getVoiceCallHistory($startDate, $endDate);
$importedCalls = VoiceCallHistoryModel::importCallsFromKolmisoft($callHistory);
if ($importedCalls) {
$messages["success"][$job->date] = $importedCalls["message"];
VoiceCallHistoryJobModel::updateJobStatus($job->id, "success");
} else {
$messages["error"][$job->date] = "Failed to import calls for job $job->id.";
VoiceCallHistoryJobModel::updateJobStatus($job->id, "failed");
}
}
return $messages;
}
}

View File

@@ -0,0 +1,86 @@
<?php
class VoiceCallHistoryJobModel {
public $id;
public $date;
public $status;
public $create;
public $edit;
public function __construct($data = []) {
foreach ($data as $field => $value) {
if (property_exists(get_called_class(), $field)) {
$this->$field = $value;
}
}
}
/**
* Generate SQL Filter condition (space separated) for a given column.
*
* @param string|null $filterValue The filter value to match against.
* @param string $columnName The name of the column in the database table.
* @return string The SQL condition generated based on the filter value and column name.
*/
public static function generateFilterCondition(?string $filterValue, string $columnName): string {
$sql = "";
if (!empty($filterValue)) {
$filterItems = explode(" ", $filterValue);
foreach ($filterItems as $item) {
$sql .= " AND `$columnName` LIKE '%" . $item . "%'";
}
}
return $sql;
}
public static function createJobsUntilToday(): array {
$db = FronkDB::singleton();
// $i = first day of the month; $i <= today; $i += 1 day
$values = [];
for ($i = strtotime(date("Y-m-01")); $i <= strtotime(date("Y-m-d")); $i += 86400) {
$values[] = "('" . date("Y-m-d", $i) . "')";
}
$valueStr = implode(", ", $values);
$db->query("INSERT INTO `VoiceCallHistoryJob` (`date`) VALUES $valueStr ON DUPLICATE KEY UPDATE date=VALUES(date)");
$db->query("UPDATE `VoiceCallHistoryJob` SET `status` = 'created', `finished` = NULL WHERE `date` = '" . date("Y-m-d") . "'");
return [
"message" => "Created " . count($values) . " jobs."
];
}
public static function updateJobStatus($id, $status): array {
$db = FronkDB::singleton();
$escapedStatus = $db->escape($status);
$escapedId = $db->escape($id);
$finished = $status == "success" ? ", `finished` = NOW()" : "";
$db->query("UPDATE `VoiceCallHistoryJob` SET `status` = '$escapedStatus' $finished WHERE `id` = $escapedId");
return [
"message" => "Updated job $id status to $status."
];
}
public static function getJobsNotDone(): array {
$db = FronkDB::singleton();
$query = $db->query("SELECT * FROM `VoiceCallHistoryJob` WHERE `status` = 'created' OR `status` = 'failed' OR `status` = 'pending' ORDER BY `date`");
$items = [];
if($db->num_rows($query)) {
while($data = $db->fetch_object($query)) {
$items[] = new VoiceCallHistoryJobModel($data);
}
}
return $items;
}
}