added new duplicate homeid view

This commit is contained in:
Luca Haid
2025-05-14 09:47:14 +02:00
parent f08178ada2
commit 287f4dea9a
3 changed files with 164 additions and 1 deletions

View File

@@ -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");
}
}

View File

@@ -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);
}
}

View File

@@ -0,0 +1,88 @@
Vue.component('a-d-b-wohneinheit-duplicate', {
//language=Vue
template: `
<tt-card>
<tt-table :data="window['TT_CONFIG']['DUPLICATE_HOMES']" :config="DuplicateHomesTableConfig" excel-export>
<template v-slot:extref="{ row }">
<span class="badge badge-warning">{{ row.extref }}</span>
</template>
<template v-slot:count="{ row }">
<span class="badge badge-danger">{{ row.count }}</span>
</template>
<template v-slot:homedetails="{ row }">
<div class="duplicate-homes-container">
<table class="table table-sm table-bordered table-striped">
<thead>
<tr>
<th>ID</th>
<th>OAID</th>
<th>Num</th>
<th>Nutzung</th>
<th>Rimo Ex State</th>
<th>Rimo Op State</th>
<th>Erstellt</th>
<th>Zuletzt editiert</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody>
<tr v-for="home in row.homeData" :key="home.id" :class="{'bg-light': home.id % 2 === 0}">
<td>{{ home.id }}</td>
<td>{{ home.oaid || 'N/A' }}</td>
<td>{{ home.num }}</td>
<td>{{ home.nutzung || 'N/A' }}</td>
<td>{{ home.rimo_ex_state || 'N/A' }}</td>
<td>{{ home.rimo_op_state || 'N/A' }}</td>
<td>{{ formatDate(home.create) }}</td>
<td>{{ formatDate(home.edit) }}</td>
<td>
<div class="btn-group btn-group-sm">
<a :href="window['TT_CONFIG']['BASE_URL'] + '/AddressDB/view/?id=' + home.id"
class="btn btn-info"
target="_blank"
title="View">
<i class="far fa-eye"></i>
</a>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</template>
</tt-table>
</tt-card>
`,
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');
},
},
})