diff --git a/application/ADBWohneinheit/ADBWohneinheitController.php b/application/ADBWohneinheit/ADBWohneinheitController.php index be0cf1b6b..face55bdb 100644 --- a/application/ADBWohneinheit/ADBWohneinheitController.php +++ b/application/ADBWohneinheit/ADBWohneinheitController.php @@ -158,5 +158,25 @@ class ADBWohneinheitController extends mfBaseController { $this->redirect("AddressDB", "view", ["id" => $hausnummer_id]); } + + protected function duplicateAction() { + $duplicateHomes = ADBWohneinheitModel::searchDuplicateExtref(); + + $JSGlobals = ["BASE_URL" => self::getUrl(""), + "DASHBOARD_URL" => self::getUrl("Dashboard"), + "MFAPPNAME" => MFAPPNAME_SLUG, + "PAGE_TITLE" => "Doppelte Homes", + "PATH" => [ + ["text" => MFAPPNAME_SLUG, "href" => self::getUrl("Dashboard")], + ["text" => "Doppelte Homes", "href" => self::getUrl("ADBWohneinheit", "duplicate")], + ], + "DUPLICATE_HOMES" => $duplicateHomes, + "IS_ADMIN" => $this->me->is("Admin"), + ]; + + $this->layout()->set("vueViewName", "ADBWohneinheitDuplicate"); + $this->layout()->set("JSGlobals", $JSGlobals); + $this->layout()->setTemplate("VueViews/Vue"); + } } \ No newline at end of file diff --git a/application/ADBWohneinheit/ADBWohneinheitModel.php b/application/ADBWohneinheit/ADBWohneinheitModel.php index 968b20bb9..5fea54a18 100644 --- a/application/ADBWohneinheit/ADBWohneinheitModel.php +++ b/application/ADBWohneinheit/ADBWohneinheitModel.php @@ -281,5 +281,60 @@ class ADBWohneinheitModel { //var_dump($filter, $where);exit; return $where; } - + + public static function searchDuplicateExtref($filter = []) { + $duplicates = []; + $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME)->link; + $where = self::getSqlFilter($filter); + + $sql = "SELECT Wohneinheit.extref, COUNT(*) as count + FROM Wohneinheit + LEFT JOIN Hausnummer ON (Hausnummer.id = Wohneinheit.hausnummer_id) + WHERE $where AND Wohneinheit.extref IS NOT NULL + GROUP BY Wohneinheit.extref + HAVING COUNT(*) > 1 + ORDER BY COUNT(*) DESC"; + + $res = $db->query($sql); + $duplicateExtrefs = []; + + while($data = $res->fetch_assoc()) { + $duplicateExtrefs[] = $data['extref']; + $duplicates[$data['extref']] = [ + 'extref' => $data['extref'], + 'count' => $data['count'], + 'homeData' => [] + ]; + } + + if (!empty($duplicateExtrefs)) { + $extrefList = "'" . implode("','", array_map([$db, 'real_escape_string'], $duplicateExtrefs)) . "'"; + $detailSql = "SELECT Wohneinheit.* + FROM Wohneinheit + LEFT JOIN Hausnummer ON (Hausnummer.id = Wohneinheit.hausnummer_id) + WHERE $where AND Wohneinheit.extref IN ($extrefList) + ORDER BY Wohneinheit.extref"; + + $detailRes = $db->query($detailSql); + while($homeData = $detailRes->fetch_assoc()) { + $duplicates[$homeData['extref']]['homeData'][] = [ + "id" => $homeData['id'], + "oaid" => $homeData['oaid'], + "hausnummer_id" => $homeData['hausnummer_id'], + "num" => $homeData['num'], + "nutzung" => $homeData['nutzung'], + "rimo_ex_state" => $homeData['rimo_ex_state'], + "rimo_op_state" => $homeData['rimo_op_state'], + "create" => $homeData['create'], + "edit" => $homeData['edit'], + ]; + } + } + + return array_values($duplicates); + } + + + + } diff --git a/public/js/pages/ADBWohneinheitDuplicate/ADBWohneinheitDuplicate.js b/public/js/pages/ADBWohneinheitDuplicate/ADBWohneinheitDuplicate.js new file mode 100644 index 000000000..81ae9df46 --- /dev/null +++ b/public/js/pages/ADBWohneinheitDuplicate/ADBWohneinheitDuplicate.js @@ -0,0 +1,88 @@ +Vue.component('a-d-b-wohneinheit-duplicate', { + //language=Vue + template: ` + + + + + + + + + + + `, + data() { + return { + window: window, + markedForDeletion: [], + DuplicateHomesTableConfig: { + key: 'DuplicateHomesTable', + tableHeader: 'Doppelte HomeID Liste', + defaultPageSize: 10, + headers: [ + {text: 'HomeID', key: 'extref', sortable: true, class: 'text-nowrap', priority: 10}, + {text: 'Anzahl gleicher HomeIDs', key: 'count', sortable: true, class: 'text-center', priority: 9}, + { + text: 'Home Details', + key: 'homeDetails', + sortable: false, + class: 'w-75', + filter: false, + priority: 8 + }, + ], + }, + } + }, + methods: { + formatDate(timestamp) { + if (!timestamp) return 'N/A'; + return this.window.moment.unix(timestamp).format('DD.MM.YYYY HH:mm:ss'); + }, + }, +}) \ No newline at end of file