From 7932ad7ca44f83ab4b61589564c167fe7ae964da Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Tue, 22 Apr 2025 17:46:23 +0200 Subject: [PATCH] added construction consent owner import --- Layout/default/ConstructionConsent/Index.php | 61 ++++++++++++++++++- .../ConstructionConsentController.php | 49 +++++++++++++++ .../ConstructionConsentOwner.php | 12 ++++ .../WarehouseEShopController.php | 6 +- 4 files changed, 125 insertions(+), 3 deletions(-) diff --git a/Layout/default/ConstructionConsent/Index.php b/Layout/default/ConstructionConsent/Index.php index 28a769ae8..84d63b362 100644 --- a/Layout/default/ConstructionConsent/Index.php +++ b/Layout/default/ConstructionConsent/Index.php @@ -159,8 +159,11 @@ $pagination_entity_name = "Zustimmungserklärungen";
1, "filter" => ["project_id" => (is_array($filter) && array_key_exists("project_id", $filter) ? $filter["project_id"] : "")]])?>"> Filter zurücksetzen + + isAdmin() && is_array($filter) && array_key_exists("project_id", $filter) && !empty($filter["project_id"])): ?> + +
-
$filter])?>"> Zustimmungserklärungen herunterladen
@@ -442,4 +445,60 @@ $pagination_entity_name = "Zustimmungserklärungen"; background-color: #337ab7; /* Blue */ } + + + + + diff --git a/application/ConstructionConsent/ConstructionConsentController.php b/application/ConstructionConsent/ConstructionConsentController.php index ec3f26f1b..35af915a3 100644 --- a/application/ConstructionConsent/ConstructionConsentController.php +++ b/application/ConstructionConsent/ConstructionConsentController.php @@ -1041,4 +1041,53 @@ class ConstructionConsentController extends mfBaseController { $this->returnJson(["status" => "OK"]); } + + protected function importConstructionConsentOwnersAction() { + $projectId = $this->request->project_id; + $importData = json_decode(file_get_contents('php://input'), true); + + if (empty($importData) || !is_array($importData)) { $this->layout()->setFlash("Keine Daten gefunden", "error"); return $this->redirect("ConstructionConsent"); } + if (!is_numeric($projectId) || $projectId < 1) { $this->layout()->setFlash("Projekt nicht gefunden", "error"); return $this->redirect("ConstructionConsent"); } + if (!($consentProject = new ConstructionConsentProject($projectId))->id) { $this->layout()->setFlash("Projekt nicht gefunden", "error"); return $this->redirect("ConstructionConsent"); } + + $counts = ["created" => 0, "updated" => 0, "skipped" => 0]; + + foreach ($importData as $ownerData) { + $consentFilter = ["constructionconsentproject_id" => $consentProject->id, "kg" => $ownerData["KG-EZ"] ?? null, "ez" => $ownerData["EZ"] ?? null, "lnr" => $ownerData["LNR"] ?? null]; + if (!($consentRecord = ConstructionConsent::getFirst(array_filter($consentFilter)))) { + $counts["skipped"]++; continue; + } + + $birthdate = (isset($ownerData["GEB"]) && preg_match("/^\d{4}-\d{2}-\d{2}$/", $ownerData["GEB"])) ? $ownerData["GEB"] : null; + $ownerFilter = ["constructionconsent_id" => $consentRecord->id, "firstname" => $ownerData["VN"] ?? null, "lastname" => $ownerData["NN"] ?? null]; + if ($birthdate) { $ownerFilter["birthdate"] = $birthdate; } + + $isNew = !($ownerRecord = ConstructionConsentOwner::getFirst(array_filter($ownerFilter))); + if ($isNew) $ownerRecord = new ConstructionConsentOwner(["constructionconsent_id" => $consentRecord->id]); + + $addressKey = null; foreach(array_keys($ownerData) as $k) { if(strpos($k,"ADR") === 0) {$addressKey=$k; break;} } + $street = $city = $postcode = $country = null; + if ($addressKey && isset($ownerData[$addressKey])) { + $addressParts = explode(", ", str_replace('"', '', $ownerData[$addressKey])); + $street = $addressParts[0] ?? null; + if (isset($addressParts[1])) { list($postcode, $city) = array_pad(explode(" ", trim($addressParts[1]), 2), 2, null); } + $country = $addressParts[2] ?? null; + } + + $ownerRecord->firstname = $ownerData["VN"] ?? null; + $ownerRecord->lastname = (($ownerData["JUR"] ?? 'nein') === "ja") ? ($ownerData['BEZ'] ?? $ownerData["NN"]) : ($ownerData["NN"] ?? null); + $ownerRecord->birthdate = $birthdate; + $ownerRecord->street = $street; + $ownerRecord->city = $city; + $ownerRecord->zip = $postcode; + $ownerRecord->country = $country; + $ownerRecord->save(); + + $counts[$isNew ? "created" : "updated"]++; + } + + self::returnJson(["status" => "OK", "counts" => $counts]); + return true; + } + } diff --git a/application/ConstructionConsentOwner/ConstructionConsentOwner.php b/application/ConstructionConsentOwner/ConstructionConsentOwner.php index 89b5ba777..deb60fa90 100644 --- a/application/ConstructionConsentOwner/ConstructionConsentOwner.php +++ b/application/ConstructionConsentOwner/ConstructionConsentOwner.php @@ -221,9 +221,21 @@ class ConstructionConsentOwner extends mfBaseModel { $constructionconsent_id = $filter['constructionconsent_id']; if(is_numeric($constructionconsent_id)) { $where .= " AND constructionconsent_id=$constructionconsent_id"; + } else if(is_array($constructionconsent_id)) { + $where .= " AND constructionconsent_id IN (".implode(",", $constructionconsent_id).")"; } } + foreach($filter as $field => $value) + if(in_array($field, ["firstname", "lastname", "street", "zip", "city", "country", "phone", "phone2", "birthdate", "fax", "email"])) + if(is_array($value)) { + $where .= " AND $field IN ('".implode("','", $value)."')"; + } else { + $where .= " AND $field LIKE '%$value%'"; + } + + + if(array_key_exists("add-where", $filter)) { diff --git a/application/WarehouseEShop/WarehouseEShopController.php b/application/WarehouseEShop/WarehouseEShopController.php index 956689926..49df6ac90 100644 --- a/application/WarehouseEShop/WarehouseEShopController.php +++ b/application/WarehouseEShop/WarehouseEShopController.php @@ -42,11 +42,11 @@ class WarehouseEShopController extends TTCrud { $warehouseArticleFilter['isEShop'] = 1; $warehouseArticleFilter['isEShopHide'] = 0; - $warehouseArticles = WarehouseArticleModel::getAll($warehouseArticleFilter, $perPage, ($page - 1) * $perPage, $order); + $warehouseArticles = WarehouseArticleModel::getAll($warehouseArticleFilter, null, 0, $order); $warehouseArticlesTotal = WarehouseArticleModel::count(['isEShop' => 1, 'isEShopHide' => 0]); $warehouseArticlesAvailable = WarehouseArticleModel::count($warehouseArticleFilter); - $warehousePackets = WarehouseArticlePacketModel::getAll(); + $warehousePackets = WarehouseArticlePacketModel::getAll($filter, null, 0, $order); $warehousePacketsTotal = WarehouseArticlePacketModel::count(); $warehousePacketsAvailable = WarehouseArticlePacketModel::count($filter); @@ -54,6 +54,8 @@ class WarehouseEShopController extends TTCrud { $totalRows = $warehouseArticlesTotal + $warehousePacketsTotal; $rows = [...$warehouseArticles, ...$warehousePackets]; + $rows = array_slice($rows, ($page - 1) * $perPage, $perPage); + self::returnJson(["rows" => $rows, "pagination" => ["page" => $page, "total_pages" => ceil($filteredAvailable / $perPage),