added rml unscheduled check
This commit is contained in:
@@ -186,59 +186,46 @@ class ADBWohneinheitController extends mfBaseController {
|
||||
}
|
||||
|
||||
protected function duplicateAction() {
|
||||
// if me is not admin or netowner, redirect to dashboard
|
||||
if(!$this->me->is("Admin") && !$this->me->can("ADBExtended")) {
|
||||
if (!$this->me->is("Admin") && !$this->me->can("ADBExtended")) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
|
||||
$address_id = null;
|
||||
if (!$this->me->is("Admin")) {
|
||||
$address_id = $this->me->address->id;
|
||||
}
|
||||
$address_id = $this->me->is("Admin") ? null : $this->me->address->id;
|
||||
|
||||
$duplicateHomes = array_merge(ADBWohneinheitModel::searchDuplicateExtref([], $address_id),
|
||||
$duplicateHomes = array_merge(
|
||||
ADBWohneinheitModel::searchDuplicateExtref([], $address_id),
|
||||
ADBWohneinheitModel::searchDuplicateOAID([], $address_id),
|
||||
ADBWohneinheitModel::getRimoDeletedHomes([], $address_id)
|
||||
ADBWohneinheitModel::getRimoDeletedHomes([], $address_id),
|
||||
($this->me->is("Admin") || $address_id === "4807") ? ADBWohneinheitModel::getUnscheduledOrderHomes([], 4807) : []
|
||||
);
|
||||
|
||||
if ($address_id === "4807" || $this->me->is("Admin")) $duplicateHomes = array_merge($duplicateHomes, ADBWohneinheitModel::getUnscheduledOrderHomes([], 4807));
|
||||
$getUniqueValues = fn($key) => array_values(array_unique(array_filter(array_column($duplicateHomes, $key))));
|
||||
|
||||
$networkOwners = [];
|
||||
$networks = [];
|
||||
foreach ($duplicateHomes as $home) {
|
||||
if ($home['netzgebiet_owner'] && !in_array($home['netzgebiet_owner'], array_column($networkOwners, 'value'))) {
|
||||
$networkOwners[] = [
|
||||
"value" => $home['netzgebiet_owner'],
|
||||
"text" => $home['netzgebiet_owner'],
|
||||
];
|
||||
}
|
||||
$networkOwners = array_map(
|
||||
fn($owner) => ['value' => $owner, 'text' => $owner],
|
||||
$getUniqueValues('netzgebiet_owner')
|
||||
);
|
||||
|
||||
if ($home['netzgebiet_id'] && !in_array($home['netzgebiet_id'], array_column($networks, 'value'))) {
|
||||
$network = new ADBNetzgebiet($home['netzgebiet_id']);
|
||||
$networks[] = [
|
||||
"value" => $home['netzgebiet_id'],
|
||||
"text" => $network->name,
|
||||
];
|
||||
}
|
||||
$networks = array_map(
|
||||
fn($id) => ['value' => $id, 'text' => (new ADBNetzgebiet($id))->name],
|
||||
$getUniqueValues('netzgebiet_id')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$JSGlobals = ["BASE_URL" => self::getUrl(""),
|
||||
"DASHBOARD_URL" => self::getUrl("Dashboard"),
|
||||
"MFAPPNAME" => MFAPPNAME_SLUG,
|
||||
"PAGE_TITLE" => "Doppelte Homes",
|
||||
"PATH" => [
|
||||
$this->layout()->set("vueViewName", "ADBWohneinheitDuplicate");
|
||||
$this->layout()->setTemplate("VueViews/Vue");
|
||||
$this->layout()->set("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,
|
||||
"ADB_NETZGEBIETE" => $networks,
|
||||
"NETWORK_OWNERS" => $networkOwners,
|
||||
"IS_ADMIN" => $this->me->is("Admin"),
|
||||
];
|
||||
|
||||
$this->layout()->set("vueViewName", "ADBWohneinheitDuplicate");
|
||||
$this->layout()->set("JSGlobals", $JSGlobals);
|
||||
$this->layout()->setTemplate("VueViews/Vue");
|
||||
"NETWORK_OWNERS" => $networkOwners,
|
||||
"IS_ADMIN" => $isAdmin,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -293,138 +293,94 @@ class ADBWohneinheitModel {
|
||||
}
|
||||
|
||||
public static function searchDuplicateExtref($filter = [], $network_owner = null) {
|
||||
$duplicates = [];
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME)->link;
|
||||
|
||||
$dupeSql = "SELECT extref FROM " . ADDRESSDB_DBNAME . ".Wohneinheit WHERE extref IS NOT NULL GROUP BY extref HAVING COUNT(*) > 1";
|
||||
$res = $db->query($dupeSql);
|
||||
$duplicateExtrefs = $res ? array_column($res->fetch_all(MYSQLI_ASSOC), 'extref') : [];
|
||||
if (empty($duplicateExtrefs)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$extrefList = "'" . implode("','", array_map([$db, 'real_escape_string'], $duplicateExtrefs)) . "'";
|
||||
$where = self::getSqlFilter($filter);
|
||||
if ($network_owner) {
|
||||
$where .= " AND Network.owner_id = '" . $db->real_escape_string($network_owner) . "'";
|
||||
}
|
||||
|
||||
if ($network_owner) $where .= " AND Network.owner_id = '" . FronkDB::singleton()->escape($network_owner) . "'";
|
||||
$detailSql = "
|
||||
SELECT W.*, Owner.company AS company, H.rimo_id AS hausnummer_extref
|
||||
FROM " . ADDRESSDB_DBNAME . ".Wohneinheit W
|
||||
LEFT JOIN " . ADDRESSDB_DBNAME . ".Hausnummer H ON H.id = W.hausnummer_id
|
||||
LEFT JOIN " . ADDRESSDB_DBNAME . ".Netzgebiet NG ON NG.id = H.netzgebiet_id
|
||||
LEFT JOIN " . FRONKDB_DBNAME . ".Network Network ON Network.adb_netzgebiet_id = NG.id
|
||||
LEFT JOIN " . FRONKDB_DBNAME . ".Address Owner ON Network.owner_id = Owner.id
|
||||
WHERE W.extref IN ($extrefList) AND $where AND Owner.company IS NOT NULL
|
||||
ORDER BY W.extref, W.id";
|
||||
|
||||
$sql = "SELECT Wohneinheit.extref, COUNT(*) as count, Hausnummer.netzgebiet_id as netzgebiet_id, Netzgebiet.name as netzgebiet_name, Address.company as netzgebiet_owner
|
||||
FROM ". ADDRESSDB_DBNAME . ".Wohneinheit
|
||||
LEFT JOIN ". ADDRESSDB_DBNAME . ".Hausnummer ON (Hausnummer.id = Wohneinheit.hausnummer_id)
|
||||
LEFT JOIN ". ADDRESSDB_DBNAME . ".Netzgebiet ON (Netzgebiet.id = Hausnummer.netzgebiet_id)
|
||||
LEFT JOIN ". FRONKDB_DBNAME .".Network ON (Network.adb_netzgebiet_id = Netzgebiet.id)
|
||||
LEFT JOIN ". FRONKDB_DBNAME .".Address ON (Network.owner_id = Address.id)
|
||||
WHERE $where AND Wohneinheit.extref IS NOT NULL
|
||||
GROUP BY Wohneinheit.extref, Hausnummer.netzgebiet_id
|
||||
HAVING COUNT(*) > 1
|
||||
ORDER BY COUNT(*) DESC";
|
||||
$detailRes = $db->query($detailSql);
|
||||
$duplicates = [];
|
||||
|
||||
$res = $db->query($sql);
|
||||
$duplicateExtrefs = [];
|
||||
|
||||
while($data = $res->fetch_assoc()) {
|
||||
if (!$data['netzgebiet_owner']) continue; // Skip if no owner is set
|
||||
$duplicateExtrefs[] = $data['extref'];
|
||||
$duplicates[$data['extref']] = [
|
||||
"duplicateType" => "extref",
|
||||
'extref' => $data['extref'],
|
||||
'netzgebiet_id' => $data['netzgebiet_id'],
|
||||
'netzgebiet_owner' => $data['netzgebiet_owner'],
|
||||
'count' => $data['count'],
|
||||
'homeData' => []
|
||||
while ($row = $detailRes->fetch_assoc()) {
|
||||
$extref = $row['extref'];
|
||||
$duplicates[$extref] ??= ['duplicateType' => 'extref', 'extref' => $extref, 'netzgebiet_id' => $row['netzgebiet_id'] ?? null, 'netzgebiet_owner' => $row['company'], 'count' => 0, 'homeData' => []];
|
||||
$duplicates[$extref]['homeData'][] = [
|
||||
'id' => $row['id'], 'oaid' => $row['oaid'], 'network_company' => $row['company'], 'hausnummer_id' => $row['hausnummer_id'],
|
||||
'hausnummer_extref' => $row['hausnummer_extref'], 'num' => $row['num'], 'nutzung' => $row['nutzung'],
|
||||
'rimo_ex_state' => $row['rimo_ex_state'], 'rimo_op_state' => $row['rimo_op_state'], 'create' => $row['create'], 'edit' => $row['edit'],
|
||||
];
|
||||
$duplicates[$extref]['count']++;
|
||||
}
|
||||
|
||||
if (!empty($duplicateExtrefs)) {
|
||||
$extrefList = "'" . implode("','", array_map([$db, 'real_escape_string'], $duplicateExtrefs)) . "'";
|
||||
$detailSql = "SELECT Wohneinheit.*, thetool.Address.company AS company, Hausnummer.rimo_id AS hausnummer_extref
|
||||
FROM ". ADDRESSDB_DBNAME .".Wohneinheit
|
||||
LEFT JOIN ". ADDRESSDB_DBNAME .".Hausnummer ON (Hausnummer.id = Wohneinheit.hausnummer_id)
|
||||
LEFT JOIN ". ADDRESSDB_DBNAME .".Netzgebiet ON (Netzgebiet.id = Hausnummer.netzgebiet_id)
|
||||
LEFT JOIN ". FRONKDB_DBNAME .".Network ON (Network.adb_netzgebiet_id = Netzgebiet.id)
|
||||
LEFT JOIN ". FRONKDB_DBNAME .".Address ON (Network.owner_id = Address.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'],
|
||||
"network_company" => $homeData['company'],
|
||||
"hausnummer_id" => $homeData['hausnummer_id'],
|
||||
"hausnummer_extref" => $homeData['hausnummer_extref'],
|
||||
"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);
|
||||
return array_values(array_filter($duplicates, fn($group) => $group['count'] > 1));
|
||||
}
|
||||
|
||||
public static function searchDuplicateOAID($filter = [], $network_owner = null) {
|
||||
$duplicates = [];
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME)->link;
|
||||
|
||||
$dupeSql = "SELECT oaid FROM " . ADDRESSDB_DBNAME . ".Wohneinheit WHERE oaid IS NOT NULL GROUP BY oaid HAVING COUNT(*) > 1";
|
||||
$res = $db->query($dupeSql);
|
||||
$duplicateOaids = $res ? array_column($res->fetch_all(MYSQLI_ASSOC), 'oaid') : [];
|
||||
if (empty($duplicateOaids)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$oaidList = "'" . implode("','", array_map([$db, 'real_escape_string'], $duplicateOaids)) . "'";
|
||||
$where = self::getSqlFilter($filter);
|
||||
if ($network_owner) {
|
||||
$where .= " AND Network.owner_id = '" . $db->real_escape_string($network_owner) . "'";
|
||||
}
|
||||
|
||||
if ($network_owner) $where .= " AND Network.owner_id = '" . FronkDB::singleton()->escape($network_owner) . "'";
|
||||
$detailSql = "
|
||||
SELECT W.id, W.oaid, W.extref, W.hausnummer_id, W.num, W.nutzung, W.rimo_ex_state, W.rimo_op_state, W.create, W.edit,
|
||||
H.rimo_id AS hausnummer_extref, H.netzgebiet_id, Owner.company AS netzgebiet_owner
|
||||
FROM " . ADDRESSDB_DBNAME . ".Wohneinheit W
|
||||
LEFT JOIN " . ADDRESSDB_DBNAME . ".Hausnummer H ON H.id = W.hausnummer_id
|
||||
LEFT JOIN " . ADDRESSDB_DBNAME . ".Netzgebiet NG ON NG.id = H.netzgebiet_id
|
||||
LEFT JOIN " . FRONKDB_DBNAME . ".Network Network ON Network.adb_netzgebiet_id = NG.id
|
||||
LEFT JOIN " . FRONKDB_DBNAME . ".Address Owner ON Network.owner_id = Owner.id
|
||||
WHERE W.oaid IN ($oaidList) AND $where AND Owner.company IS NOT NULL
|
||||
ORDER BY W.oaid, W.id";
|
||||
|
||||
$sql = "SELECT Wohneinheit.oaid, COUNT(*) as count, Hausnummer.netzgebiet_id as netzgebiet_id, Netzgebiet.name as netzgebiet_name, Address.company as netzgebiet_owner
|
||||
FROM ". ADDRESSDB_DBNAME .".Wohneinheit
|
||||
LEFT JOIN ". ADDRESSDB_DBNAME .".Hausnummer ON (Hausnummer.id = Wohneinheit.hausnummer_id)
|
||||
LEFT JOIN ". ADDRESSDB_DBNAME .".Netzgebiet ON (Netzgebiet.id = Hausnummer.netzgebiet_id)
|
||||
LEFT JOIN ". FRONKDB_DBNAME .".Network ON (Network.adb_netzgebiet_id = Netzgebiet.id)
|
||||
LEFT JOIN ". FRONKDB_DBNAME .".Address ON (Network.owner_id = Address.id)
|
||||
WHERE $where AND Wohneinheit.oaid IS NOT NULL
|
||||
GROUP BY Wohneinheit.oaid, Hausnummer.netzgebiet_id
|
||||
HAVING COUNT(*) > 1
|
||||
ORDER BY COUNT(*) DESC";
|
||||
$detailRes = $db->query($detailSql);
|
||||
if (!$detailRes) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$res = $db->query($sql);
|
||||
$duplicateOaids = [];
|
||||
|
||||
while($data = $res->fetch_assoc()) {
|
||||
if (!$data['netzgebiet_owner']) continue; // Skip if no owner is set
|
||||
$duplicateOaids[] = $data['oaid'];
|
||||
$duplicates[$data['oaid']] = [
|
||||
"duplicateType" => "oaid",
|
||||
'oaid' => $data['oaid'],
|
||||
'count' => $data['count'],
|
||||
'netzgebiet_id' => $data['netzgebiet_id'],
|
||||
'netzgebiet_owner' => $data['netzgebiet_owner'],
|
||||
'homeData' => []
|
||||
$duplicates = [];
|
||||
while ($row = $detailRes->fetch_assoc()) {
|
||||
$oaid = $row['oaid'];
|
||||
$duplicates[$oaid] ??= ['duplicateType' => 'oaid', 'oaid' => $oaid, 'count' => 0, 'netzgebiet_id' => $row['netzgebiet_id'], 'netzgebiet_owner' => $row['netzgebiet_owner'], 'homeData' => []];
|
||||
$duplicates[$oaid]['homeData'][] = [
|
||||
'id' => $row['id'], 'oaid' => $row['oaid'], 'extref' => $row['extref'], 'network_company' => $row['netzgebiet_owner'],
|
||||
'hausnummer_id' => $row['hausnummer_id'], 'hausnummer_extref' => $row['hausnummer_extref'], 'num' => $row['num'],
|
||||
'nutzung' => $row['nutzung'], 'rimo_ex_state' => $row['rimo_ex_state'], 'rimo_op_state' => $row['rimo_op_state'],
|
||||
'create' => $row['create'], 'edit' => $row['edit'],
|
||||
];
|
||||
$duplicates[$oaid]['count']++;
|
||||
}
|
||||
|
||||
if (!empty($duplicateOaids)) {
|
||||
$oaidList = "'" . implode("','", array_map([$db, 'real_escape_string'], $duplicateOaids)) . "'";
|
||||
$detailSql = "SELECT Wohneinheit.*, thetool.Address.company AS company, Hausnummer.rimo_id AS hausnummer_extref
|
||||
|
||||
FROM ". ADDRESSDB_DBNAME .".Wohneinheit
|
||||
LEFT JOIN ". ADDRESSDB_DBNAME .".Hausnummer ON (Hausnummer.id = Wohneinheit.hausnummer_id)
|
||||
LEFT JOIN ". ADDRESSDB_DBNAME .".Netzgebiet ON (Netzgebiet.id = Hausnummer.netzgebiet_id)
|
||||
LEFT JOIN ". FRONKDB_DBNAME .".Network ON (Network.adb_netzgebiet_id = Netzgebiet.id)
|
||||
LEFT JOIN ". FRONKDB_DBNAME .".Address ON (Network.owner_id = Address.id)
|
||||
WHERE $where AND Wohneinheit.oaid IN ($oaidList)
|
||||
ORDER BY Wohneinheit.oaid";
|
||||
|
||||
$detailRes = $db->query($detailSql);
|
||||
while($homeData = $detailRes->fetch_assoc()) {
|
||||
$duplicates[$homeData['oaid']]['homeData'][] = [
|
||||
"id" => $homeData['id'],
|
||||
'oaid' => $homeData['oaid'],
|
||||
"extref" => $homeData['extref'],
|
||||
"network_company" => $homeData['company'],
|
||||
"hausnummer_id" => $homeData['hausnummer_id'],
|
||||
"hausnummer_extref" => $homeData['hausnummer_extref'],
|
||||
"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);
|
||||
return array_values(array_filter($duplicates, fn($group) => $group['count'] > 1));
|
||||
}
|
||||
|
||||
public static function getRimoDeletedHomes($filter = [], $network_owner = null) {
|
||||
|
||||
42
db/migrations/20250612124000_add_new_indexes_adb.php
Normal file
42
db/migrations/20250612124000_add_new_indexes_adb.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php /** @noinspection ALL */
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddNewIndexesAdb extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if ($this->getEnvironment() == "addressdb") {
|
||||
$wohneinheit = $this->table("Wohneinheit");
|
||||
$wohneinheit->removeIndexByName('oaid')
|
||||
->addIndex('oaid', ['name' => 'idx_oaid_full'])
|
||||
->save();
|
||||
|
||||
$wohneinheit->removeIndexByName('extref')
|
||||
->addIndex('extref', ['name' => 'idx_extref_full'])
|
||||
->save();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if ($this->getEnvironment() == "addressdb") {
|
||||
$wohneinheit = $this->table("Wohneinheit");
|
||||
$wohneinheit->removeIndexByName('idx_oaid_full')
|
||||
->addIndex('oaid', [
|
||||
'name' => 'oaid',
|
||||
'limit' => 10
|
||||
])
|
||||
->save();
|
||||
|
||||
$wohneinheit->removeIndexByName('idx_extref_full')
|
||||
->addIndex('extref', [
|
||||
'name' => 'extref',
|
||||
'limit' => 10
|
||||
])
|
||||
->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
35
db/migrations/20250612124000_add_new_indexes_thetool.php
Normal file
35
db/migrations/20250612124000_add_new_indexes_thetool.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php /** @noinspection ALL */
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddNewIndexesThetool extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if ($this->getEnvironment() == "thetool") {
|
||||
$workerPermission = $this->table("WorkerPermission");
|
||||
$workerPermission->addColumn("canADBExtended", "enum", ["null" => false, "values" => 'false,true', "default" => "false", "after" => "canSuperexpert"])
|
||||
->update();
|
||||
|
||||
$network = $this->table("Network");
|
||||
$network->addIndex('adb_netzgebiet_id', ['name' => 'idx_adb_netzgebiet_id'])
|
||||
->addIndex('owner_id', ['name' => 'idx_owner_id'])
|
||||
->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if ($this->getEnvironment() == "thetool") {
|
||||
$workerPermission = $this->table("WorkerPermission");
|
||||
$workerPermission->removeColumn("canADBExtended")
|
||||
->save();
|
||||
|
||||
$network = $this->table("Network");
|
||||
$network->removeIndexByName('idx_adb_netzgebiet_id')
|
||||
->removeIndexByName('idx_owner_id')
|
||||
->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user