added new permissions and changed handling of ADBWohneinheitController.php/duplicate

This commit is contained in:
Luca Haid
2025-06-12 10:01:01 +02:00
parent 3050603474
commit 528f3680d2
7 changed files with 91 additions and 26 deletions

View File

@@ -179,6 +179,9 @@
<a class="btn btn-secondary" href="<?=self::getUrl("AddressDB", "", ["resetFilter" => 1])?>">Filter zurücksetzen</a>
<button type="submit" formaction="<?=self::getUrl("AddressDB", "export")?>" id="export-button" class="btn btn-outline-success ml-2"><i class="fas fa-download"></i> CSV-Export Gebäude</button>
<button type="submit" formaction="<?=self::getUrl("AddressDB", "exportHomes")?>" id="export-button-homes" class="btn btn-outline-success ml-2"><i class="fas fa-download"></i> CSV-Export Homes</button>
<?php if($me->can("ADBExtended")): ?>
<a class="btn btn-outline-secondary ml-2" href="<?=self::getUrl("ADBWohneinheit", "duplicate")?>"><i class="fas fa-fw fa-copy"></i> Doppelte Homes</a>
<?php endif; ?>
</div>
</div>
</form>

View File

@@ -449,6 +449,15 @@ $siteTitle = "Benutzer";
anzeigen</label>
</div>
</div>
<div class="col-4">
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" name="can[ADBExtended]"
id="can_ADBExtended"
value="1" <?=($user && $user->can("ADBExtended")) ? "checked='checked'" : ""?> />
<label for="can_ADBExtended" class="form-check-label">Address-DB erweitert</label>
</div>
</div>
</div>
<hr/>

View File

@@ -186,9 +186,19 @@ class ADBWohneinheitController extends mfBaseController {
}
protected function duplicateAction() {
$duplicateHomes = array_merge(ADBWohneinheitModel::searchDuplicateExtref(),
ADBWohneinheitModel::searchDuplicateOAID(),
ADBWohneinheitModel::getRimoDeletedHomes()
// if me is not admin or netowner, redirect to dashboard
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;
}
$duplicateHomes = array_merge(ADBWohneinheitModel::searchDuplicateExtref([], $address_id),
ADBWohneinheitModel::searchDuplicateOAID([], $address_id),
ADBWohneinheitModel::getRimoDeletedHomes([], $address_id)
);
$ADBNetzgebiete = array_map(function($network) {
@@ -198,10 +208,13 @@ class ADBWohneinheitController extends mfBaseController {
];
}, ADBNetzgebietModel::getAll());
$filteredNetzgebiete = [];
foreach ($ADBNetzgebiete as $network) {
if (!strstr($network["text"], "SBIDI") && !strstr($network["text"], "Liezen")) {
$filteredNetzgebiete[] = $network;
$networkOwners = [];
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'],
];
}
}
@@ -214,7 +227,8 @@ class ADBWohneinheitController extends mfBaseController {
["text" => "Doppelte Homes", "href" => self::getUrl("ADBWohneinheit", "duplicate")],
],
"DUPLICATE_HOMES" => $duplicateHomes,
"ADB_NETZGEBIETE" => $filteredNetzgebiete,
"ADB_NETZGEBIETE" => $ADBNetzgebiete,
"NETWORK_OWNERS" => $networkOwners,
"IS_ADMIN" => $this->me->is("Admin"),
];

View File

@@ -292,15 +292,19 @@ class ADBWohneinheitModel {
return $where;
}
public static function searchDuplicateExtref($filter = []) {
public static function searchDuplicateExtref($filter = [], $network_owner = null) {
$duplicates = [];
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME)->link;
$where = self::getSqlFilter($filter);
$sql = "SELECT Wohneinheit.extref, COUNT(*) as count, Hausnummer.netzgebiet_id as netzgebiet_id, Netzgebiet.name as netzgebiet_name
if ($network_owner) $where .= " AND Network.owner_id = '" . FronkDB::singleton()->escape($network_owner) . "'";
$sql = "SELECT Wohneinheit.extref, COUNT(*) as count, Hausnummer.netzgebiet_id as netzgebiet_id, Netzgebiet.name as netzgebiet_name, Address.company as netzgebiet_owner
FROM Wohneinheit
LEFT JOIN Hausnummer ON (Hausnummer.id = Wohneinheit.hausnummer_id)
LEFT JOIN Netzgebiet ON (Netzgebiet.id = Hausnummer.netzgebiet_id)
LEFT JOIN Netzgebiet ON (Netzgebiet.id = Hausnummer.netzgebiet_id)
LEFT JOIN thetool.Network ON (Network.adb_netzgebiet_id = Netzgebiet.id)
LEFT JOIN thetool.Address ON (Network.owner_id = Address.id)
WHERE $where AND Wohneinheit.extref IS NOT NULL AND Netzgebiet.name NOT LIKE 'SBIDI%'
GROUP BY Wohneinheit.extref, Hausnummer.netzgebiet_id
HAVING COUNT(*) > 1
@@ -310,12 +314,13 @@ class ADBWohneinheitModel {
$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' => strstr($data['netzgebiet_name'], 'Liezen') ? 'RML' : 'ESTMK',
'netzgebiet_owner' => $data['netzgebiet_owner'],
'count' => $data['count'],
'homeData' => []
];
@@ -354,16 +359,20 @@ class ADBWohneinheitModel {
return array_values($duplicates);
}
public static function searchDuplicateOAID($filter = []) {
public static function searchDuplicateOAID($filter = [], $network_owner = null) {
$duplicates = [];
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME)->link;
$where = self::getSqlFilter($filter);
$sql = "SELECT Wohneinheit.oaid, COUNT(*) as count, Hausnummer.netzgebiet_id as netzgebiet_id, Netzgebiet.name as netzgebiet_name
if ($network_owner) $where .= " AND Network.owner_id = '" . FronkDB::singleton()->escape($network_owner) . "'";
$sql = "SELECT Wohneinheit.oaid, COUNT(*) as count, Hausnummer.netzgebiet_id as netzgebiet_id, Netzgebiet.name as netzgebiet_name, Address.company as netzgebiet_owner
FROM Wohneinheit
LEFT JOIN Hausnummer ON (Hausnummer.id = Wohneinheit.hausnummer_id)
LEFT JOIN Netzgebiet ON (Netzgebiet.id = Hausnummer.netzgebiet_id)
WHERE $where AND Wohneinheit.oaid IS NOT NULL AND Netzgebiet.name NOT LIKE 'SBIDI%'
LEFT JOIN thetool.Network ON (Network.adb_netzgebiet_id = Netzgebiet.id)
LEFT JOIN thetool.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";
@@ -372,13 +381,14 @@ class ADBWohneinheitModel {
$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' => strstr($data['netzgebiet_name'], 'Liezen') ? 'RML' : 'ESTMK',
'netzgebiet_owner' => $data['netzgebiet_owner'],
'homeData' => []
];
}
@@ -416,30 +426,33 @@ class ADBWohneinheitModel {
return array_values($duplicates);
}
public static function getRimoDeletedHomes($filter = []) {
public static function getRimoDeletedHomes($filter = [], $network_owner = null) {
$deletedHomes = [];
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME)->link;
$where = self::getSqlFilter($filter);
$detailSql = "SELECT Wohneinheit.*, thetool.Address.company AS company, Hausnummer.rimo_id AS hausnummer_extref, Netzgebiet.name AS netzgebiet_name
if ($network_owner) $where .= " AND Network.owner_id = '" . FronkDB::singleton()->escape($network_owner) . "'";
$detailSql = "SELECT Wohneinheit.*, thetool.Address.company AS company, Hausnummer.rimo_id AS hausnummer_extref, Netzgebiet.name AS netzgebiet_name, Netzgebiet.id AS netzgebiet_id, Address.company as netzgebiet_owner
FROM Wohneinheit
LEFT JOIN Hausnummer ON (Hausnummer.id = Wohneinheit.hausnummer_id)
LEFT JOIN Netzgebiet ON (Netzgebiet.id = Hausnummer.netzgebiet_id)
LEFT JOIN thetool.Network ON (Network.adb_netzgebiet_id = Netzgebiet.id)
LEFT JOIN thetool.Address ON (Network.owner_id = Address.id)
WHERE $where AND Wohneinheit.rimo_deleted = 1 AND Netzgebiet.name NOT LIKE 'SBIDI%'
WHERE $where AND Wohneinheit.rimo_deleted = 1
ORDER BY Wohneinheit.oaid";
$counter = 0;
$detailRes = $db->query($detailSql);
while($homeData = $detailRes->fetch_assoc()) {
if (!$homeData['netzgebiet_owner']) continue; // Skip if no owner is set
$counter++;
$deletedHomes[$counter] = [
"duplicateType" => "rimo_deleted",
'oaid' => $homeData['oaid'] ?? 'Keine OAID',
'extref' => $homeData['extref'],
'netzgebiet_id' => $homeData['netzgebiet_id'],
'netzgebiet_owner' => strstr($homeData['netzgebiet_name'], 'Liezen') ? 'RML' : 'ESTMK',
'netzgebiet_owner' => $homeData['netzgebiet_owner'],
'count' => 1, // Each entry is unique in this context
'homeData' => []
];

View File

@@ -262,6 +262,7 @@ class UserController extends mfBaseController
$user->permissions->canWarehouseAdmin = "false";
$user->permissions->canWarehouseEShop = "false";
$user->permissions->canWarehouseUser = "false";
$user->permissions->canADBExtended = "false";
if($r->get("can") && is_array($r->can)) {
foreach($r->can as $key => $can) {

View File

@@ -0,0 +1,30 @@
<?php /** @noinspection ALL */
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class WorkerPermissionAddCanAdbExtended extends AbstractMigration {
public function up(): void {
if ($this->getEnvironment() == "thetool") {
$table = $this->table("WorkerPermission");
$table->addColumn("canADBExtended", "enum", ["null" => false, "values" => 'false,true', "default" => "false", "after" => "canSuperexpert"]);
$table->update();
}
if ($this->getEnvironment() == "addressdb") {
}
}
public function down(): void {
if ($this->getEnvironment() == "thetool") {
$table = $this->table("WorkerPermission");
$table->removeColumn("canADBExtended");
$table->save();
}
if ($this->getEnvironment() == "addressdb") {
}
}
}

View File

@@ -70,12 +70,7 @@ Vue.component('a-d-b-wohneinheit-duplicate', {
defaultPageSize: 10,
headers: [
{text: 'Netzgebiet', key: 'netzgebiet_id', sortable: true, class: 'text-nowrap', priority: 11, filter: 'select', filterOptions: window['TT_CONFIG']['ADB_NETZGEBIETE']},
{text: 'Firma', key: 'netzgebiet_owner', sortable: true, class: 'text-nowrap', priority: 11, filter: 'select', filterOptions:
[
{text: 'RML', value: 'RML'},
{text: 'ESTMK', value: 'ESTMK'},
]
},
{text: 'Firma', key: 'netzgebiet_owner', sortable: true, class: 'text-nowrap', priority: 11, filter: 'select', filterOptions: window['TT_CONFIG']['NETWORK_OWNERS']},
{text: 'HomeID/OAID', key: 'extref', sortable: true, class: 'text-nowrap', priority: 10},
{text: 'Check-Typ', key: 'duplicateType', sortable: true, class: 'text-nowrap', priority: 9, filter: 'select', filterOptions: [
{text: 'HomeID', value: 'extref'},