579 lines
23 KiB
PHP
579 lines
23 KiB
PHP
<?php
|
|
|
|
class ADBWohneinheitModel {
|
|
public $status_id;
|
|
public $oaid;
|
|
public $extref;
|
|
public $hausnummer_id;
|
|
public $num;
|
|
public $block;
|
|
public $stiege;
|
|
public $stock;
|
|
public $tuer;
|
|
public $zusatz;
|
|
public $bezeichner;
|
|
public $nutzung;
|
|
public $enduser_setup_invoice_date;
|
|
public $rimo_ex_state;
|
|
public $rimo_op_state;
|
|
public $rimo_deleted;
|
|
public $patch_cluster;
|
|
public $patch_shelf;
|
|
public $patch_module;
|
|
public $patch_port;
|
|
public $external_data;
|
|
|
|
public $note;
|
|
public $create_by = null;
|
|
public $edit_by = null;
|
|
public $create = null;
|
|
public $edit = null;
|
|
|
|
public static function create(Array $data) {
|
|
$model = new ADBWohneinheit();
|
|
|
|
foreach($data as $field => $value) {
|
|
if(property_exists(get_called_class(), $field)) {
|
|
$model ->$field = $value;
|
|
}
|
|
}
|
|
|
|
$me = mfValuecache::singleton()->get("me");
|
|
if(!$me) {
|
|
$me = new User();
|
|
$me->loadMe();
|
|
mfValuecache::singleton()->set("me", $me);
|
|
}
|
|
/*
|
|
if($model->create_by === null) {
|
|
$model->create_by = $me->id;
|
|
}
|
|
if($model->edit_by === null) {
|
|
$model->edit_by = $me->id;
|
|
}*/
|
|
|
|
return $model;
|
|
}
|
|
|
|
public static function getFirst($filter) {
|
|
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT Wohneinheit.* FROM Wohneinheit
|
|
LEFT JOIN Hausnummer ON (Hausnummer.id = Wohneinheit.hausnummer_id)
|
|
WHERE $where
|
|
GROUP BY Wohneinheit.id
|
|
ORDER BY hausnummer_id,block,stiege,LENGTH(stock),stock,LENGTH(tuer),tuer,num
|
|
LIMIT 1";
|
|
|
|
//mfLoghandler::singleton()->debug($sql);
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
|
|
// search in cache
|
|
$item = mfValuecache::singleton()->get("mfObjectmodel-adb_wohneinheit-".$data->id);
|
|
if($item && $item->id) {
|
|
mfValuecache::singleton()->set("mfObjectmodel-adb_wohneinheit-".$data->id, $item);
|
|
return $item;
|
|
}
|
|
// if not in cache, load regularly
|
|
|
|
$item = new ADBWohneinheit($data);
|
|
if($item->id) {
|
|
return $item;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static function getAll() {
|
|
$items = [];
|
|
|
|
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
|
|
|
$res = $db->select("Wohneinheit", "*", "1=1 ORDER BY hausnummer_id,block,stiege,LENGTH(stock),stock,LENGTH(tuer),tuer,num");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new ADBWohneinheit($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
|
|
public static function count($filter) {
|
|
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT COUNT(*) as cnt FROM
|
|
(SELECT Wohneinheit.* FROM Wohneinheit
|
|
LEFT JOIN Hausnummer ON (Hausnummer.id = Wohneinheit.hausnummer_id)
|
|
WHERE $where
|
|
GROUP BY Wohneinheit.id
|
|
) as tbl
|
|
";
|
|
|
|
//mfLoghandler::singleton()->debug($sql);
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
return (int)$data->cnt;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public static function search($filter, $limit = false) {
|
|
$items = [];
|
|
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT Wohneinheit.* FROM Wohneinheit
|
|
LEFT JOIN Hausnummer ON (Hausnummer.id = Wohneinheit.hausnummer_id)
|
|
WHERE $where
|
|
GROUP BY Wohneinheit.id
|
|
ORDER BY hausnummer_id,block,stiege,LENGTH(stock),stock,LENGTH(tuer),tuer,num";
|
|
|
|
//mfLoghandler::singleton()->debug($sql);
|
|
if(is_array($limit) && count($limit)) {
|
|
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
|
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
|
} elseif(is_numeric($limit['count'])) {
|
|
$sql .= " LIMIT ".$limit['count'];
|
|
}
|
|
}
|
|
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$item = mfValuecache::singleton()->get("mfObjectmodel-adb_wohneinheit-".$data->id);
|
|
if($item && $item->id) {
|
|
$items[] = $item;
|
|
} else {
|
|
$item = new ADBWohneinheit($data);
|
|
mfValuecache::singleton()->set("mfObjectmodel-adb_wohneinheit-".$data->id, $item);
|
|
$items[] = $item;
|
|
}
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter) {
|
|
$where = "1=1 ";
|
|
|
|
if(array_key_exists("extref", $filter)) {
|
|
if($filter['extref'] === null || $filter['extref'] === false) {
|
|
$where .= " AND (Wohneinheit.`extref` IS NULL OR Wohneinheit.`extref` = '')";
|
|
} else {
|
|
$extref = FronkDB::singleton()->escape($filter['extref']);
|
|
if($extref) {
|
|
$where .= " AND Wohneinheit.`extref` = '$extref'";
|
|
}
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("status_id", $filter)) {
|
|
$status_id = $filter['status_id'];
|
|
if(is_numeric($status_id)) {
|
|
$where .= " AND Wohneinheit.status_id=$status_id";
|
|
} elseif(is_array($status_id) && count($status_id)) {
|
|
$where .= " AND Wohneinheit.status_id IN (". implode(",", $status_id).")";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("rimo_deleted", $filter)) {
|
|
$rimo_deleted = $filter['rimo_deleted'];
|
|
if($rimo_deleted === true || $rimo_deleted === 1) {
|
|
$where .= " AND Wohneinheit.`rimo_deleted` = 1";
|
|
} elseif($rimo_deleted === false || $rimo_deleted === 0) {
|
|
$where .= " AND Wohneinheit.`rimo_deleted` = 0";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("netzgebiet_id", $filter)) {
|
|
$netzgebiet_id = $filter['netzgebiet_id'];
|
|
if(is_numeric($netzgebiet_id)) {
|
|
$where .= " AND Hausnummer.netzgebiet_id=$netzgebiet_id";
|
|
} elseif(is_array($netzgebiet_id) && count($netzgebiet_id)) {
|
|
$where .= " AND Hausnummer.netzgebiet_id IN (". implode(",", $netzgebiet_id).")";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("hausnummer_id", $filter)) {
|
|
$hausnummer_id = $filter['hausnummer_id'];
|
|
if(is_numeric($hausnummer_id)) {
|
|
$where .= " AND Wohneinheit.hausnummer_id=$hausnummer_id";
|
|
} elseif(is_array($hausnummer_id) && count($hausnummer_id)) {
|
|
$where .= " AND Wohneinheit.hausnummer_id IN (". implode(",", $hausnummer_id).")";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("oaid", $filter)) {
|
|
$oaid = FronkDB::singleton()->escape($filter['oaid']);
|
|
if(strlen($oaid)) {
|
|
$where .= " AND Wohneinheit.`oaid` = '$oaid'";
|
|
} else {
|
|
$where .= " AND (Wohneinheit.`oaid` IS NULL OR Wohneinheit.`oaid` = '')";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("num", $filter)) {
|
|
$num = $filter['num'];
|
|
if($num === false || $num === null) {
|
|
$where .= " AND (Wohneinheit.num IS NULL OR Wohneinheit.num = 0)";
|
|
} elseif(is_numeric($num)) {
|
|
$where .= " AND Wohneinheit.num=$num";
|
|
} elseif(is_array($num) && count($num)) {
|
|
$where .= " AND Wohneinheit.num IN (". implode(",", $num).")";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("block", $filter)) {
|
|
$block = FronkDB::singleton()->escape($filter['block']);
|
|
if(strlen($block)) {
|
|
$where .= " AND Wohneinheit.`block` = '$block'";
|
|
} else {
|
|
$where .= " AND (Wohneinheit.`block` IS NULL OR Wohneinheit.`block` = '')";
|
|
}
|
|
}
|
|
if(array_key_exists("stock", $filter)) {
|
|
$stock = FronkDB::singleton()->escape($filter['stock']);
|
|
if(strlen($stock)) {
|
|
$where .= " AND Wohneinheit.`stock` = '$stock'";
|
|
} else {
|
|
$where .= " AND (Wohneinheit.`stock` IS NULL OR Wohneinheit.`stock` = '')";
|
|
}
|
|
}
|
|
if(array_key_exists("stiege", $filter)) {
|
|
$stiege = FronkDB::singleton()->escape($filter['stiege']);
|
|
if(strlen($stiege)) {
|
|
$where .= " AND Wohneinheit.`stiege` = '$stiege'";
|
|
} else {
|
|
$where .= " AND (Wohneinheit.`stiege` IS NULL OR Wohneinheit.`stiege` = '')";
|
|
}
|
|
}
|
|
if(array_key_exists("tuer", $filter)) {
|
|
$tuer = FronkDB::singleton()->escape($filter['tuer']);
|
|
if(strlen($tuer)) {
|
|
$where .= " AND Wohneinheit.`tuer` = '$tuer'";
|
|
} else {
|
|
$where .= " AND (Wohneinheit.`tuer` IS NULL OR Wohneinheit.`tuer` = '')";
|
|
}
|
|
}
|
|
if(array_key_exists("zusatz", $filter)) {
|
|
$zusatz = FronkDB::singleton()->escape($filter['zusatz']);
|
|
if(strlen($zusatz)) {
|
|
$where .= " AND Wohneinheit.`zusatz` LIKE '$zusatz'";
|
|
} else {
|
|
$where .= " AND (Wohneinheit.`zusatz` IS NULL OR Wohneinheit.`zusatz` = '')";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("nutzung", $filter)) {
|
|
$nutzung = FronkDB::singleton()->escape($filter['nutzung']);
|
|
if(strlen($nutzung)) {
|
|
$where .= " AND Wohneinheit.`nutzung` = '$nutzung'";
|
|
} else {
|
|
$where .= " AND (Wohneinheit.`nutzung` IS NULL OR Wohneinheit.`nutzung` = '')";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("block%", $filter)) {
|
|
$block = FronkDB::singleton()->escape($filter['block']);
|
|
if($block) {
|
|
$where .= " AND Wohneinheit.`block` like '%$block%'";
|
|
}
|
|
}
|
|
if(array_key_exists("stock%", $filter)) {
|
|
$stock = FronkDB::singleton()->escape($filter['stock']);
|
|
if($stock) {
|
|
$where .= " AND Wohneinheit.`stock` like '%$stock%'";
|
|
}
|
|
}
|
|
if(array_key_exists("stiege%", $filter)) {
|
|
$stiege = FronkDB::singleton()->escape($filter['stiege']);
|
|
if($stiege) {
|
|
$where .= " AND Wohneinheit.`stiege` like '%$stiege%'";
|
|
}
|
|
}
|
|
if(array_key_exists("tuer%", $filter)) {
|
|
$tuer = FronkDB::singleton()->escape($filter['tuer']);
|
|
if($tuer) {
|
|
$where .= " AND Wohneinheit.`tuer` like '%$tuer%'";
|
|
}
|
|
}
|
|
if(array_key_exists("zusatz%", $filter)) {
|
|
$zusatz = FronkDB::singleton()->escape($filter['zusatz']);
|
|
if($zusatz) {
|
|
$where .= " AND Wohneinheit.`zusatz` like '%$zusatz%'";
|
|
}
|
|
}
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
public static function searchDuplicateExtref($filter = [], $network_owner = null) {
|
|
$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) . "'";
|
|
}
|
|
|
|
$detailSql = "
|
|
SELECT W.*, Owner.company AS company, H.rimo_id AS hausnummer_extref, NG.id AS netzgebiet_id
|
|
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";
|
|
|
|
$detailRes = $db->query($detailSql);
|
|
$duplicates = [];
|
|
|
|
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']++;
|
|
}
|
|
|
|
return array_values(array_filter($duplicates, fn($group) => $group['count'] > 1));
|
|
}
|
|
|
|
public static function searchDuplicateOAID($filter = [], $network_owner = null) {
|
|
$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) . "'";
|
|
}
|
|
|
|
$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";
|
|
|
|
$detailRes = $db->query($detailSql);
|
|
if (!$detailRes) {
|
|
return [];
|
|
}
|
|
|
|
$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']++;
|
|
}
|
|
|
|
return array_values(array_filter($duplicates, fn($group) => $group['count'] > 1));
|
|
}
|
|
|
|
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);
|
|
|
|
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 ". 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.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' => $homeData['netzgebiet_owner'],
|
|
'count' => 1, // Each entry is unique in this context
|
|
'homeData' => []
|
|
];
|
|
$deletedHomes[$counter]['homeData'][] = [
|
|
"id" => $homeData['id'],
|
|
'oaid' => $homeData['oaid'] ?? 'Keine 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($deletedHomes);
|
|
}
|
|
|
|
public static function getUnscheduledOrderHomes($filter = [], $network_owner = null) {
|
|
$deletedHomes = [];
|
|
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME)->link;
|
|
$where = self::getSqlFilter($filter);
|
|
|
|
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 ". 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)
|
|
LEFT JOIN ". FRONKDB_DBNAME .".Preorder ON (Preorder.adb_wohneinheit_id = Wohneinheit.id)
|
|
LEFT JOIN ". FRONKDB_DBNAME .".Preorderstatus ON (Preorderstatus.id = Preorder.status_id)
|
|
WHERE $where AND Hausnummer.rollout_info LIKE '%unscheduled%' AND Preorder.id IS NOT NULL AND Preorderstatus.code < 501
|
|
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" => "rml_unscheduled_with_order",
|
|
'oaid' => $homeData['oaid'] ?? 'Keine OAID',
|
|
'extref' => $homeData['extref'],
|
|
'netzgebiet_id' => $homeData['netzgebiet_id'],
|
|
'netzgebiet_owner' => $homeData['netzgebiet_owner'],
|
|
'count' => 1, // Each entry is unique in this context
|
|
'homeData' => []
|
|
];
|
|
$deletedHomes[$counter]['homeData'][] = [
|
|
"id" => $homeData['id'],
|
|
'oaid' => $homeData['oaid'] ?? 'Keine 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($deletedHomes);
|
|
}
|
|
|
|
public static function getGreenfieldWithActivePreorders($filter = [], $network_owner = null) {
|
|
$homes = [];
|
|
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME)->link;
|
|
$where = self::getSqlFilter($filter);
|
|
|
|
if ($network_owner) {
|
|
$where .= " AND Network.owner_id = '" . $db->real_escape_string($network_owner) . "'";
|
|
}
|
|
|
|
$detailSql = "
|
|
SELECT
|
|
W.*,
|
|
Owner.company AS company,
|
|
H.rimo_id AS hausnummer_extref,
|
|
NG.id AS netzgebiet_id,
|
|
Owner.company as netzgebiet_owner
|
|
FROM ". ADDRESSDB_DBNAME .".Wohneinheit W
|
|
JOIN ". ADDRESSDB_DBNAME .".Hausnummer H ON H.id = W.hausnummer_id
|
|
JOIN ". FRONKDB_DBNAME .".Preorder P ON P.adb_wohneinheit_id = W.id
|
|
JOIN ". FRONKDB_DBNAME .".Preorderstatus PS ON PS.id = P.status_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 $where
|
|
AND H.rimo_type = 'greenfield'
|
|
AND PS.code < 899
|
|
AND P.deleted = 0
|
|
GROUP BY W.id, Owner.company, H.rimo_id, NG.id
|
|
ORDER BY W.oaid";
|
|
|
|
$detailRes = $db->query($detailSql);
|
|
if (!$detailRes) {
|
|
return [];
|
|
}
|
|
|
|
while($homeData = $detailRes->fetch_assoc()) {
|
|
if (empty($homeData['netzgebiet_owner'])) continue;
|
|
|
|
$homes[] = [
|
|
"duplicateType" => "greenfield_with_order",
|
|
'oaid' => $homeData['oaid'] ?? 'Keine OAID',
|
|
'extref' => $homeData['extref'],
|
|
'netzgebiet_id' => $homeData['netzgebiet_id'],
|
|
'netzgebiet_owner' => $homeData['netzgebiet_owner'],
|
|
'count' => 1,
|
|
'homeData' => [[
|
|
"id" => $homeData['id'],
|
|
'oaid' => $homeData['oaid'] ?? 'Keine 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 $homes;
|
|
}
|
|
|
|
}
|