diff --git a/Layout/default/Linework/Index.php b/Layout/default/Linework/Index.php index 06d493d33..2244deab4 100644 --- a/Layout/default/Linework/Index.php +++ b/Layout/default/Linework/Index.php @@ -104,6 +104,15 @@ +
+ + +
+ diff --git a/Layout/default/Pipework/Index.php b/Layout/default/Pipework/Index.php index 5edb5e961..6be5849b1 100644 --- a/Layout/default/Pipework/Index.php +++ b/Layout/default/Pipework/Index.php @@ -74,7 +74,7 @@ id) ? "selected='selected'" : ""?> - id == 3) ? "selected='selected'" : ""?> + id, ["145","62","56"]) && $status->id == 3) ? "selected='selected'" : ""?> > code?> - name."-b")?> @@ -91,6 +91,15 @@ + +
+ + +
@@ -99,7 +108,10 @@
- ">Filter zurücksetzen + ">Filter zurücksetzen + is(["Admin"])) :?> + ">Zur Historie +
diff --git a/application/Building/BuildingModel.php b/application/Building/BuildingModel.php index 12b970b67..2b23a63b2 100644 --- a/application/Building/BuildingModel.php +++ b/application/Building/BuildingModel.php @@ -167,6 +167,13 @@ class BuildingModel { $where .= " AND Building.pipeworker_id=$pipeworker_id"; } } + + if(array_key_exists("pipework_enabled", $filter)) { + $pipework_enabled = $filter['pipework_enabled']; + if(!empty($pipework_enabled) || $pipework_enabled === "0") { + $where .= " AND Building.pipework_enabled=$pipework_enabled"; + } + } if(array_key_exists("type", $filter) && is_array($filter['type']) && count($filter['type'])) { $ot = $filter['type']; @@ -267,5 +274,54 @@ class BuildingModel { //var_dump($filter, $where);exit; return $where; } - + + public static function getHistory($from, $to, $network_id, $street_filter): array { + $sql = "SELECT b.id AS building_id, + b.street AS building_street, + b.zip AS building_zip, + b.city AS building_city, + wi.id AS item_id, + wi.name AS item_name, + wi.label AS item_label, + wi.type AS item_type, + wv.id AS value_id, + wv.value_string, + wv.value_int, + wv.value_text, + (wv.create) AS created_at, + wv.create_by AS created_by_user_id, + (wv.edit) AS last_edited_at, + wv.edit_by AS last_edited_by_user_id +FROM Workflowvalue wv +JOIN Workflowitem wi ON wv.item_id = wi.id +JOIN Building b ON wv.object_id = b.id"; + $where = ["wi.object_type = 'Building'", "wi.num < 150"]; + + if ($from !== null && $to !== null) { + $where[] = "((wv.create >= " . intval($from) . " AND wv.create <= " . intval($to) . ") OR (wv.edit >= " . intval($from) . " AND wv.edit <= " . intval($to) . "))"; + } + if ($network_id !== null) { + $where[] = "b.network_id = " . intval($network_id); + } + if (!empty($street_filter)) { + $escaped_street = addslashes($street_filter); + $where[] = "b.street LIKE '%" . $escaped_street . "%'"; + } + + $sql .= " WHERE " . implode(" AND ", $where); + $sql .= " ORDER BY wv.edit DESC, wv.create DESC;"; + + $db = FronkDB::singleton(); + $res = $db->query($sql); + + if ($db->num_rows($res)) { + $items = []; + while ($data = $db->fetch_object($res)) { + $items[] = $data; + } + return $items; + } else { + return []; + } + } } diff --git a/application/Pipework/PipeworkController.php b/application/Pipework/PipeworkController.php index b3774c03b..86294b368 100644 --- a/application/Pipework/PipeworkController.php +++ b/application/Pipework/PipeworkController.php @@ -102,7 +102,7 @@ class PipeworkController extends mfBaseController { } - if(!array_key_exists("status_id", $filter)) { + if(!in_array($this->me->id, ["145","62","56"]) && !array_key_exists("status_id", $filter)) { $building_search["status_id"] = 3; } @@ -461,5 +461,51 @@ class PipeworkController extends mfBaseController { } - + + + protected function historyAction() { + if (!$this->me->isAdmin()) { + throw new Exception("Forbidden", 403); + } + + Helper::renderVue($this, "PipeworkHistory", "PipeworkHistory", [ + "IS_ADMIN" => $this->me->isAdmin(), + "NETWORKS" => array_map(function ($network) { + return [ + "value" => $network->id, + "text" => $network->name, + ]; + }, NetworkModel::getAll()), + "USERS" => array_map(function ($user) { + return [ + "value" => $user->id, + "text" => $user->name, + ]; + }, UserModel::search(['employee' => true])), + ]); + } + + protected function historyAPIAction() { + if (!$this->me->isAdmin()) self::sendError("Keine Berechtigung"); + + $from = $this->request->from; + $to = $this->request->to; + $network_id = $this->request->network_id; + $street_filter = $this->request->street_filter; + + // from and to is unix timestamp + if ($from && $to) { + $from = (int)$from; + $to = (int)$to; + if ($from > $to) self::sendError('Von kann nicht nach dem Bis-Datum liegen'); + $fourWeeksInSeconds = 2419200; +// if (($to - $from) > $fourWeeksInSeconds) self::sendError('Der Zeitraum darf maximal 4 Wochen betragen'); + } + + if ($from && $to && $network_id) { + self::returnJson(["status" => "OK","data" => BuildingModel::getHistory($from,$to,$network_id,$street_filter)]); + } else { + self::sendError('Fehlerhafte Parameter'); + } + } } diff --git a/application/Termination/TerminationModel.php b/application/Termination/TerminationModel.php index e27c06f6a..f69d68b43 100644 --- a/application/Termination/TerminationModel.php +++ b/application/Termination/TerminationModel.php @@ -146,6 +146,13 @@ class TerminationModel { $where .= " AND Termination.status_id = $status_id"; } } + + if(array_key_exists("linework_enabled", $filter)) { + $linework_enabled = $filter['linework_enabled']; + if(!empty($linework_enabled) || $linework_enabled === '0') { + $where .= " AND Termination.linework_enabled=$linework_enabled"; + } + } if(array_key_exists("lineworker_id", $filter)) { $lineworker_id = $filter['lineworker_id']; diff --git a/public/js/pages/PipeworkHistory/PipeworkHistory.js b/public/js/pages/PipeworkHistory/PipeworkHistory.js new file mode 100644 index 000000000..fdeb22011 --- /dev/null +++ b/public/js/pages/PipeworkHistory/PipeworkHistory.js @@ -0,0 +1,119 @@ +Vue.component('pipework-history', { + //language=Vue + template: ` + + +
+ + + + + + {{ checkParameters }} +
+ +
+ + + + + + + + + + +
+ + +
`, + data() { + return { + window: window, + address: '', + dateRange: { + from: window.moment().subtract(4, 'weeks').unix(), + to: window.moment().unix() + }, + selectedNetwork: null, + pipeworkHistory: [], + pipeworkHistoryLoading: true, + pipeworkHistoryError: false, + pipeworkHistoryTableIndex: 0, + pipeworkHistoryTableConfig: { + key: 'PipeworkHistoryTable', + tableHeader: 'Tiefbau Historie', + defaultPageSize: 50, + headers: [ + {text: 'Straße', key: 'building_street'}, + {text: 'Ort', key: 'building_city'}, + {text: 'Feld', key: 'item_label'}, + {text: 'Wert', key: 'item_type'}, + {text: 'Editiert', key: 'last_edited_at'}, + {text: 'Von', key: 'last_edited_by_user_id'}, + {text: 'Actions', key: 'item_id'}, + ], + } + } + }, + computed: { + checkParameters() { + if (!this.selectedNetwork) { + return 'Bitte Netzgebiet auswählen'; + } else if (this.dateRange.from && this.dateRange.to) { + const from = window.moment.unix(this.dateRange.from); + const to = window.moment.unix(this.dateRange.to); + const diff = to.diff(from, 'days'); + if (diff > 28) { + return 'Bitte Zeitraum von maximal 4 Wochen auswählen'; + } + } + return true; + } + }, + methods: { + async getPipeworkHistory() { + this.pipeworkHistoryLoading = true; + this.pipeworkHistoryError = false; + + try { + const response = await axios.get(`${window.TT_CONFIG.BASE_PATH}/Pipework/HistoryAPI`, { + params: { + network_id: this.selectedNetwork, + street_filter: this.address, + from: this.dateRange.from, + to: this.dateRange.to + } + }) + this.pipeworkHistory = response.data.data; + this.pipeworkHistoryLoading = false; + this.pipeworkHistoryTableIndex++; + } catch (error) { + console.error(error); + this.pipeworkHistoryLoading = false; + this.pipeworkHistoryError = true; + this.window.notify('error', 'Fehler beim Abrufen der Daten'); + } + }, + openPipework(row) { + + const networkId = this.selectedNetwork; + const street = row.building_street; + + this.window.open(`${window.TT_CONFIG.BASE_PATH}/Pipework?filter[network_id]=${networkId}&filter[street]=${street}&filter[status_id]=`, '_blank'); + } + } +}) \ No newline at end of file