Merge branch 'master' into devbyspi
This commit is contained in:
@@ -2,14 +2,13 @@
|
||||
|
||||
class ADBGemeinde extends mfBaseModel {
|
||||
public $plzs = [];
|
||||
|
||||
private $ortschaften = [];
|
||||
|
||||
protected function init() {
|
||||
$this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
$this->table = "Gemeinde";
|
||||
}
|
||||
|
||||
|
||||
public function loadByGemeindeCode($code) {
|
||||
$res = $this->db->select("Gemeinde","*","code=$code");
|
||||
if($this->db->num_rows($res)) {
|
||||
@@ -66,4 +65,35 @@ class ADBGemeinde extends mfBaseModel {
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($name == "types") {
|
||||
$this->loadAddresstypes();
|
||||
return $this->types;
|
||||
}
|
||||
|
||||
if($name == "ortschaften") {
|
||||
$this->ortschaften = ADBOrtschaftModel::search(["gemeinde_id" => $this->id]);
|
||||
return $this->ortschaften;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
if($this->$name->id) {
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,16 @@ class ADBGemeindeModel {
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Gemeinde", "*", "$where ORDER BY name,code,kennziffer LIMIT 1");
|
||||
$sql = "SELECT Gemeinde.* FROM Gemeinde
|
||||
LEFT JOIN Plz ON (Plz.gemeinde_id = Gemeinde.id)
|
||||
LEFT JOIN GemeindeNetzgebiet ON (GemeindeNetzgebiet.gemeinde_id = Gemeinde.id)
|
||||
LEFT JOIN Netzgebiet ON (GemeindeNetzgebiet.netzgebiet_id = Netzgebiet.id)
|
||||
LEFT JOIN Ortschaft ON (Ortschaft.gemeinde_id = Gemeinde.id)
|
||||
WHERE $where
|
||||
GROUP BY Gemeinde.id
|
||||
ORDER BY name,code,kennziffer
|
||||
LIMIT 1";
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ADBGemeinde($data);
|
||||
@@ -94,6 +103,7 @@ class ADBGemeindeModel {
|
||||
LEFT JOIN Plz ON (Plz.gemeinde_id = Gemeinde.id)
|
||||
LEFT JOIN GemeindeNetzgebiet ON (GemeindeNetzgebiet.gemeinde_id = Gemeinde.id)
|
||||
LEFT JOIN Netzgebiet ON (GemeindeNetzgebiet.netzgebiet_id = Netzgebiet.id)
|
||||
LEFT JOIN Ortschaft ON (Ortschaft.gemeinde_id = Gemeinde.id)
|
||||
WHERE $where
|
||||
GROUP BY Gemeinde.id
|
||||
ORDER BY name,code,kennziffer";
|
||||
@@ -126,6 +136,15 @@ class ADBGemeindeModel {
|
||||
$where .= " AND Netzgebiet.id=$netzgebiet_id";
|
||||
} elseif(is_array($netzgebiet_id) && count($netzgebiet_id)) {
|
||||
$where .= " AND Netzgebiet.id IN (". implode(",", $netzgebiet_id).")";
|
||||
} elseif($netzgebiet_id === null) {
|
||||
$where .= " AND Netzgebiet.id IS NULL";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("netzgebiet_extref", $filter)) {
|
||||
$netzgebiet_extref = FronkDB::singleton()->escape($filter['netzgebiet_extref']);
|
||||
if($netzgebiet_extref) {
|
||||
$where .= " AND Netzgebiet.extref = '$netzgebiet_extref'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +176,7 @@ class ADBGemeindeModel {
|
||||
if(array_key_exists("name%", $filter)) {
|
||||
$name = FronkDB::singleton()->escape($filter['name%']);
|
||||
if($name) {
|
||||
$where .= " AND Gemeinde.`name` like '%$name%'";
|
||||
$where .= " AND Gemeinde.`name` like '$name%'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +190,21 @@ class ADBGemeindeModel {
|
||||
if(array_key_exists("plz%", $filter)) {
|
||||
$plz = FronkDB::singleton()->escape($filter['plz%']);
|
||||
if($plz) {
|
||||
$where .= " AND Plz.plzstring like '%$plz%'";
|
||||
$where .= " AND Plz.plzstring like '$plz%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("ortschaft", $filter)) {
|
||||
$ortschaft = FronkDB::singleton()->escape($filter['ortschaft']);
|
||||
if($ortschaft) {
|
||||
$where .= " AND Plz.ortschaft = '$ortschaft'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("ortschaft%", $filter)) {
|
||||
$ortschaft = FronkDB::singleton()->escape($filter['ortschaft%']);
|
||||
if($ortschaft) {
|
||||
$where .= " AND Plz.ortschaft like '$ortschaft%'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
<?php
|
||||
|
||||
class ADBHausnummer extends mfBaseModel {
|
||||
private $netzgebiet;
|
||||
private $ortschaft;
|
||||
private $strasse;
|
||||
private $plz;
|
||||
private $freigaben = [];
|
||||
private $wohneinheiten = [];
|
||||
|
||||
protected function init() {
|
||||
$this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
@@ -36,23 +39,87 @@ class ADBHausnummer extends mfBaseModel {
|
||||
return $data;
|
||||
}*/
|
||||
|
||||
public function getNewOAID() {
|
||||
if(!$this->plz_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cc = "AT";
|
||||
$zip = $this->getProperty("plz")->plz;
|
||||
|
||||
for($try = 16; $try > 0; $try--) {
|
||||
$rnd[0] = random_int(0, 255);
|
||||
$rnd[1] = random_int(0, 255);
|
||||
$rnd[2] = random_int(0, 255);
|
||||
$rnd[3] = random_int(0, 255);
|
||||
|
||||
$code = "$cc-$zip-";
|
||||
foreach($rnd as $r) {
|
||||
$code .= str_pad(dechex($r), 2, "0", STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
if(ADBHausnummerModel::search(['oaid' => $code])) {
|
||||
$this->log->warn(__FILE__."::getNewObjectCode: New Code already in use. Trying again for a maximum of $try times.");
|
||||
} else {
|
||||
// code is unique
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if($try == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "freigaben") {
|
||||
$this->freigaben = explode(",", $this->freigabe);
|
||||
$this->freigaben = json_decode($this->freigabe);
|
||||
if(!is_array($this->freigaben)) {
|
||||
$this->freigaben = [];
|
||||
}
|
||||
return $this->freigaben;
|
||||
}
|
||||
|
||||
if($name == "netzgebiet") {
|
||||
$this->netzgebiet = new ADBNetzgebiet($this->netzgebiet_id);
|
||||
return $this->netzgebiet;
|
||||
}
|
||||
|
||||
if($name == "ortschaft") {
|
||||
$this->ortschaft = new ADBOrtschaft($this->ortschaft_id);
|
||||
return $this->ortschaft;
|
||||
}
|
||||
|
||||
if($name == "strasse") {
|
||||
$this->strasse = new ADBStrasse($this->strasse_id);
|
||||
return $this->strasse;
|
||||
}
|
||||
|
||||
if($name == "plz") {
|
||||
$this->plz = new ADBPlz($this->plz_id);
|
||||
$this->plz = mfValuecache::singleton()->get("adbplz-".$this->plz_id);
|
||||
if($this->plz === null) {
|
||||
$this->plz = new ADBPlz($this->plz_id);
|
||||
if($this->plz->id) {
|
||||
mfValuecache::singleton()->set("adplz-".$this->plz_id, $this->plz);
|
||||
}
|
||||
}
|
||||
return $this->plz;
|
||||
}
|
||||
|
||||
if($name == "wohneinheiten") {
|
||||
$this->wohneinheiten = mfValuecache::singleton()->get("adbWohneinheiten-hausnummer-".$this->id);
|
||||
if($this->wohneinheiten === null) {
|
||||
$this->wohneinheiten = ADBWohneinheitModel::search(['hausnummer_id' => $this->id]);
|
||||
if($this->wohneinheiten) {
|
||||
mfValuecache::singleton()->set("adbWohneinheiten-hausnummer-".$this->id, $this->wohneinheiten);
|
||||
}
|
||||
}
|
||||
return $this->wohneinheiten;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
class ADBHausnummerModel {
|
||||
public $oaid;
|
||||
public $adrcd;
|
||||
public $netzgebiet_id;
|
||||
public $extref;
|
||||
public $ortschaft_id;
|
||||
@@ -8,12 +10,20 @@ class ADBHausnummerModel {
|
||||
public $strasse_id;
|
||||
public $hausnummer;
|
||||
public $zusatz;
|
||||
public $grund_nr;
|
||||
public $unit_count;
|
||||
public $gps_lat;
|
||||
public $gps_long;
|
||||
public $rollout;
|
||||
public $rollout_info;
|
||||
public $freigabe;
|
||||
public $manual_add;
|
||||
public $manual_add_by;
|
||||
public $manual_add_info;
|
||||
public $manual_update;
|
||||
public $manual_update_by;
|
||||
public $manual_update_info;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
@@ -47,7 +57,17 @@ class ADBHausnummerModel {
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
mfLoghandler::singleton()->debug($where);
|
||||
|
||||
$sql = "SELECT Hausnummer.* FROM Hausnummer
|
||||
LEFT JOIN Ortschaft ON (Ortschaft.id = Hausnummer.ortschaft_id)
|
||||
LEFT JOIN Gemeinde ON (Gemeinde.id = Ortschaft.gemeinde_id)
|
||||
LEFT JOIN Strasse ON (Hausnummer.strasse_id = Strasse.id)
|
||||
LEFT JOIN Plz ON (Hausnummer.plz_id = Plz.id)
|
||||
WHERE $where
|
||||
ORDER BY netzgebiet_id,Gemeinde.id,ortschaft_id,strasse_id,LENGTH(hausnummer), hausnummer
|
||||
LIMIT 1";
|
||||
|
||||
//mfLoghandler::singleton()->debug($where);
|
||||
$res = $db->select("Hausnummer", "*", "$where ORDER BY strasse_id,hausnummer LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
@@ -82,8 +102,13 @@ class ADBHausnummerModel {
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM Hausnummer
|
||||
LEFT JOIN Ortschaft ON (Ortschaft.id = Hausnummer.ortschaft_id)
|
||||
LEFT JOIN Gemeinde ON (Gemeinde.id = Ortschaft.gemeinde_id)
|
||||
LEFT JOIN Strasse ON (Hausnummer.strasse_id = Strasse.id)
|
||||
LEFT JOIN Plz ON (Hausnummer.plz_id = Plz.id)
|
||||
WHERE $where
|
||||
";
|
||||
";
|
||||
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
@@ -93,14 +118,18 @@ class ADBHausnummerModel {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit = false) {
|
||||
public static function search($filter, $limit = false, $returnDBRessource = false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT Hausnummer.* FROM Hausnummer
|
||||
LEFT JOIN Ortschaft ON (Ortschaft.id = Hausnummer.ortschaft_id)
|
||||
LEFT JOIN Gemeinde ON (Gemeinde.id = Ortschaft.gemeinde_id)
|
||||
LEFT JOIN Strasse ON (Hausnummer.strasse_id = Strasse.id)
|
||||
LEFT JOIN Plz ON (Hausnummer.plz_id = Plz.id)
|
||||
WHERE $where
|
||||
ORDER BY strasse_id,hausnummer";
|
||||
ORDER BY netzgebiet_id,Gemeinde.id,ortschaft_id,strasse_id,LENGTH(hausnummer), hausnummer";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
if(is_array($limit) && count($limit)) {
|
||||
@@ -111,8 +140,16 @@ class ADBHausnummerModel {
|
||||
}
|
||||
}
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
|
||||
// hack for AddressDBController::exportAction
|
||||
if($returnDBRessource) {
|
||||
return $res;
|
||||
}
|
||||
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new ADBHausnummer($data);
|
||||
}
|
||||
@@ -123,6 +160,36 @@ class ADBHausnummerModel {
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
if(array_key_exists("adrcd", $filter)) {
|
||||
$adrcd = FronkDB::singleton()->escape($filter['adrcd']);
|
||||
if($adrcd) {
|
||||
$where .= " AND Hausnummer.`adrcd` = '$adrcd'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("adrcd%", $filter)) {
|
||||
$adrcd = FronkDB::singleton()->escape($filter['adrcd%']);
|
||||
if($adrcd) {
|
||||
$where .= " AND Hausnummer.`adrcd` like '$adrcd%'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("oaid", $filter)) {
|
||||
$oaid = FronkDB::singleton()->escape($filter['oaid']);
|
||||
if($oaid) {
|
||||
$where .= " AND Hausnummer.`oaid` = '$oaid'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("oaid%", $filter)) {
|
||||
$oaid = FronkDB::singleton()->escape($filter['oaid%']);
|
||||
if($oaid) {
|
||||
$where .= " AND Hausnummer.`oaid` like '$oaid%'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("extref", $filter)) {
|
||||
$extref = FronkDB::singleton()->escape($filter['extref']);
|
||||
if($extref) {
|
||||
@@ -130,12 +197,37 @@ class ADBHausnummerModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("extref%", $filter)) {
|
||||
$extref = FronkDB::singleton()->escape($filter['extref%']);
|
||||
if($extref) {
|
||||
$where .= " AND Hausnummer.`extref` like '$extref%'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("plz", $filter)) {
|
||||
$plz = FronkDB::singleton()->escape($filter['plz']);
|
||||
if($plz) {
|
||||
$where .= " AND Plz.plz = '$plz'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("plz%", $filter)) {
|
||||
$plz = FronkDB::singleton()->escape($filter['plz%']);
|
||||
if($plz) {
|
||||
$where .= " AND Plz.plz like '$plz%'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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).")";
|
||||
} elseif($netzgebiet_id === null) {
|
||||
$where .= " AND Hausnummer.netzgebiet_id IS NULL";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,10 +249,61 @@ class ADBHausnummerModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("gemeinde_id", $filter)) {
|
||||
$gemeinde_id = $filter['gemeinde_id'];
|
||||
if(is_numeric($gemeinde_id)) {
|
||||
$where .= " AND Ortschaft.gemeinde_id=$gemeinde_id";
|
||||
} elseif(is_array($gemeinde_id) && count($gemeinde_id)) {
|
||||
$where .= " AND Ortschaft.gemeinde_id IN (". implode(",", $gemeinde_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("gemeinde", $filter)) {
|
||||
$gemeinde = FronkDB::singleton()->escape($filter['gemeinde']);
|
||||
if($gemeinde) {
|
||||
$where .= " AND Gemeinde.name = '$gemeinde'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("gemeinde%", $filter)) {
|
||||
$gemeinde = FronkDB::singleton()->escape($filter['gemeinde%']);
|
||||
if($gemeinde) {
|
||||
$where .= " AND Gemeinde.name like '$gemeinde%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("ortschaft", $filter)) {
|
||||
$ortschaft = FronkDB::singleton()->escape($filter['ortschaft']);
|
||||
if($ortschaft) {
|
||||
$where .= " AND Ortschaft.name = '$ortschaft'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("ortschaft%", $filter)) {
|
||||
$ortschaft = FronkDB::singleton()->escape($filter['ortschaft%']);
|
||||
if($ortschaft) {
|
||||
$where .= " AND Ortschaft.name like '$ortschaft%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("ortschaft_id", $filter)) {
|
||||
$ortschaft_id = $filter['ortschaft_id'];
|
||||
if(is_numeric($ortschaft_id)) {
|
||||
$where .= " AND Hausnummer.ortschaft_id=$ortschaft_id";
|
||||
} elseif(is_array($ortschaft_id) && count($ortschaft_id)) {
|
||||
$where .= " AND Hausnummer.ortschaft_id IN (". implode(",", $ortschaft_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("hausnummer", $filter)) {
|
||||
$hausnummer = FronkDB::singleton()->escape($filter['hausnummer']);
|
||||
if($hausnummer) {
|
||||
$where .= " AND Hausnummer.`hausnummer` = '$hausnummer'";
|
||||
if(is_array($filter['hausnummer'])) {
|
||||
$hausnummer = $filter['hausnummer'];
|
||||
$where .= " AND Hausnummer.`hausnummer` IN ('".implode("','", $hausnummer)."')";
|
||||
} else {
|
||||
$hausnummer = FronkDB::singleton()->escape($filter['hausnummer']);
|
||||
if($hausnummer) {
|
||||
$where .= " AND Hausnummer.`hausnummer` = '$hausnummer'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,6 +314,48 @@ class ADBHausnummerModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("strasse", $filter)) {
|
||||
$strasse = FronkDB::singleton()->escape($filter['strasse']);
|
||||
if($strasse) {
|
||||
$where .= " AND Strasse.name = '$strasse'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("strasse%", $filter)) {
|
||||
$strasse = FronkDB::singleton()->escape($filter['strasse%']);
|
||||
if($strasse) {
|
||||
$where .= " AND Strasse.name like '%$strasse%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("rollout", $filter)) {
|
||||
$rollout = FronkDB::singleton()->escape($filter['rollout']);
|
||||
if($rollout) {
|
||||
$where .= " AND Hausnummer.rollout = '$rollout'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("rollout%", $filter)) {
|
||||
$rollout = FronkDB::singleton()->escape($filter['rollout%']);
|
||||
if($rollout) {
|
||||
$where .= " AND Hausnummer.rollout like '%$rollout%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("rollout_info", $filter)) {
|
||||
$rollout_info = FronkDB::singleton()->escape($filter['rollout_info']);
|
||||
if($rollout_info) {
|
||||
$where .= " AND Hausnummer.rollout_info = '$rollout_info'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("rollout_info%", $filter)) {
|
||||
$rollout_info = FronkDB::singleton()->escape($filter['rollout_info%']);
|
||||
if($rollout_info) {
|
||||
$where .= " AND Hausnummer.rollout_info like '%$rollout_info%'";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ class ADBNetzgebietModel {
|
||||
public $extref;
|
||||
public $source;
|
||||
public $source_id;
|
||||
public $freigabe;
|
||||
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
@@ -90,9 +91,7 @@ class ADBNetzgebietModel {
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT Netzgebiet.* FROM Netzgebiet
|
||||
LEFT JOIN Plz ON (Plz.netzgebiet_id = Netzgebiet.id)
|
||||
WHERE $where
|
||||
GROUP BY Netzgebiet.id
|
||||
ORDER BY name";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
@@ -116,6 +115,15 @@ class ADBNetzgebietModel {
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
if(array_key_exists("netzgebiet_id", $filter)) {
|
||||
$netzgebiet_id = $filter['netzgebiet_id'];
|
||||
if(is_numeric($netzgebiet_id)) {
|
||||
$where .= " AND Netzgebiet.netzgebiet_id=$netzgebiet_id";
|
||||
} elseif(is_array($netzgebiet_id) && count($netzgebiet_id)) {
|
||||
$where .= " AND Netzgebiet.id IN (". implode(",", $netzgebiet_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("name", $filter)) {
|
||||
$name = FronkDB::singleton()->escape($filter['name']);
|
||||
if($name) {
|
||||
@@ -123,6 +131,13 @@ class ADBNetzgebietModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("name%", $filter)) {
|
||||
$name = FronkDB::singleton()->escape($filter['name%']);
|
||||
if($name) {
|
||||
$where .= " AND Netzgebiet.`name` LIKE '$name%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("extref", $filter)) {
|
||||
$extref = FronkDB::singleton()->escape($filter['extref']);
|
||||
if($extref) {
|
||||
|
||||
@@ -31,7 +31,7 @@ class ADBOrtschaft extends mfBaseModel {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "gemeinde") {
|
||||
$this->gemeinde = new ADBGemeinde($this->hausnummer_id);
|
||||
$this->gemeinde = new ADBGemeinde($this->gemeinde_id);
|
||||
return $this->gemeinde;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,16 @@ class ADBOrtschaftModel {
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Ortschaft", "*", "$where ORDER BY name,kennziffer LIMIT 1");
|
||||
$sql = "SELECT Ortschaft.* FROM Ortschaft
|
||||
LEFT JOIN Gemeinde ON (Ortschaft.gemeinde_id = Gemeinde.id)
|
||||
LEFT JOIN Plz ON (Plz.gemeinde_id = Gemeinde.id)
|
||||
LEFT JOIN GemeindeNetzgebiet ON (GemeindeNetzgebiet.gemeinde_id = Gemeinde.id)
|
||||
LEFT JOIN Netzgebiet ON (GemeindeNetzgebiet.netzgebiet_id = Netzgebiet.id)
|
||||
WHERE $where
|
||||
ORDER BY gemeinde_id,Ortschaft.name,Ortschaft.kennziffer
|
||||
LIMIT 1";
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ADBOrtschaft($data);
|
||||
@@ -92,10 +101,15 @@ class ADBOrtschaftModel {
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT Ortschaft.* FROM Ortschaft
|
||||
LEFT JOIN Gemeinde ON (Ortschaft.gemeinde_id = Gemeinde.id)
|
||||
LEFT JOIN Plz ON (Plz.gemeinde_id = Gemeinde.id)
|
||||
LEFT JOIN GemeindeNetzgebiet ON (GemeindeNetzgebiet.gemeinde_id = Gemeinde.id)
|
||||
LEFT JOIN Netzgebiet ON (GemeindeNetzgebiet.netzgebiet_id = Netzgebiet.id)
|
||||
WHERE $where
|
||||
ORDER BY name,kennziffer";
|
||||
GROUP BY Ortschaft.id
|
||||
ORDER BY Ortschaft.name,Ortschaft.kennziffer,gemeinde_id";
|
||||
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
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'];
|
||||
@@ -116,6 +130,24 @@ class ADBOrtschaftModel {
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
if(array_key_exists("netzgebiet_id", $filter)) {
|
||||
$netzgebiet_id = $filter['netzgebiet_id'];
|
||||
if(is_numeric($netzgebiet_id)) {
|
||||
$where .= " AND Netzgebiet.id=$netzgebiet_id";
|
||||
} elseif(is_array($netzgebiet_id) && count($netzgebiet_id)) {
|
||||
$where .= " AND Netzgebiet.id IN (". implode(",", $netzgebiet_id).")";
|
||||
} elseif($netzgebiet_id === null) {
|
||||
$where .= " AND Netzgebiet.id IS NULL";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("netzgebiet_extref", $filter)) {
|
||||
$netzgebiet_extref = FronkDB::singleton()->escape($filter['netzgebiet_extref']);
|
||||
if($netzgebiet_extref) {
|
||||
$where .= " AND Netzgebiet.extref = '$netzgebiet_extref'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("gemeinde_id", $filter)) {
|
||||
$gemeinde_id = $filter['gemeinde_id'];
|
||||
if(is_numeric($gemeinde_id)) {
|
||||
@@ -149,7 +181,21 @@ class ADBOrtschaftModel {
|
||||
if(array_key_exists("name%", $filter)) {
|
||||
$name = FronkDB::singleton()->escape($filter['name%']);
|
||||
if($name) {
|
||||
$where .= " AND Ortschaft.`name` like '%$name%'";
|
||||
$where .= " AND Ortschaft.`name` like '$name%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("plz", $filter)) {
|
||||
$plz = FronkDB::singleton()->escape($filter['plz']);
|
||||
if($plz) {
|
||||
$where .= " AND Plz.plzstring = '$plz'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("plz%", $filter)) {
|
||||
$plz = FronkDB::singleton()->escape($filter['plz%']);
|
||||
if($plz) {
|
||||
$where .= " AND Plz.plzstring like '$plz%'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,16 @@ class ADBPlzModel {
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Plz", "*", "$where ORDER BY plz LIMIT 1");
|
||||
$sql = "SELECT Plz.* FROM Plz
|
||||
LEFT JOIN Gemeinde ON (Gemeinde.id = Plz.gemeinde_id)
|
||||
LEFT JOIN GemeindeNetzgebiet ON (GemeindeNetzgebiet.gemeinde_id = Plz.gemeinde_id)
|
||||
LEFT JOIN Netzgebiet ON (GemeindeNetzgebiet.netzgebiet_id = Netzgebiet.id)
|
||||
WHERE $where
|
||||
GROUP BY Plz.id
|
||||
ORDER BY plz
|
||||
LIMIT 1";
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ADBPlz($data);
|
||||
@@ -119,7 +128,6 @@ class ADBPlzModel {
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
|
||||
if(array_key_exists("netzgebiet_id", $filter)) {
|
||||
$netzgebiet_id = $filter['netzgebiet_id'];
|
||||
if(is_numeric($netzgebiet_id)) {
|
||||
@@ -129,12 +137,19 @@ class ADBPlzModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("hausnummer_id", $filter)) {
|
||||
$hausnummer_id = $filter['hausnummer_id'];
|
||||
if(is_numeric($hausnummer_id)) {
|
||||
$where .= " AND Plz.hausnummer_id=$hausnummer_id";
|
||||
} elseif(is_array($hausnummer_id) && count($hausnummer_id)) {
|
||||
$where .= " AND Plz.hausnummer_id IN (". implode(",", $hausnummer_id).")";
|
||||
if(array_key_exists("netzgebiet_extref", $filter)) {
|
||||
$netzgebiet_extref = FronkDB::singleton()->escape($filter['netzgebiet_extref']);
|
||||
if($netzgebiet_extref) {
|
||||
$where .= " AND Netzgebiet.extref = '$netzgebiet_extref'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("gemeinde_id", $filter)) {
|
||||
$gemeinde_id = $filter['gemeinde_id'];
|
||||
if(is_numeric($gemeinde_id)) {
|
||||
$where .= " AND Plz.gemeinde_id=$gemeinde_id";
|
||||
} elseif(is_array($gemeinde_id) && count($gemeinde_id)) {
|
||||
$where .= " AND Plz.gemeinde_id IN (". implode(",", $gemeinde_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +172,7 @@ class ADBPlzModel {
|
||||
if(array_key_exists("plzstring%", $filter)) {
|
||||
$plzstring = FronkDB::singleton()->escape($filter['plzstring%']);
|
||||
if($plzstring) {
|
||||
$where .= " AND Plz.`plzstring` like '%$plzstring%'";
|
||||
$where .= " AND Plz.`plzstring` like '$plzstring%'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,17 @@ class ADBStrasseModel {
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Strasse", "*", "$where ORDER BY gemeinde_id,kennziffer,name LIMIT 1");
|
||||
$sql = "SELECT Strasse.* FROM Strasse
|
||||
LEFT JOIN Hausnummer ON (Hausnummer.strasse_id = Strasse.id)
|
||||
LEFT JOIN Plz ON (Plz.id = Hausnummer.plz_id)
|
||||
LEFT JOIN Gemeinde ON (Gemeinde.id = Strasse.gemeinde_id)
|
||||
LEFT JOIN GemeindeNetzgebiet ON (GemeindeNetzgebiet.gemeinde_id = Strasse.gemeinde_id)
|
||||
LEFT JOIN Netzgebiet ON (GemeindeNetzgebiet.netzgebiet_id = Netzgebiet.id)
|
||||
WHERE $where
|
||||
GROUP BY Strasse.id
|
||||
ORDER BY gemeinde_id,name,kennziffer
|
||||
LIMIT 1";
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ADBStrasse($data);
|
||||
@@ -170,7 +180,7 @@ class ADBStrasseModel {
|
||||
if(array_key_exists("name%", $filter)) {
|
||||
$name = FronkDB::singleton()->escape($filter['name%']);
|
||||
if($name) {
|
||||
$where .= " AND Strasse.`name` like '%$name%'";
|
||||
$where .= " AND Strasse.`name` like '$name%'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +194,7 @@ class ADBStrasseModel {
|
||||
if(array_key_exists("gemeinde%", $filter)) {
|
||||
$gemeinde = FronkDB::singleton()->escape($filter['gemeinde%']);
|
||||
if($gemeinde) {
|
||||
$where .= " AND Gemeinde.`name` like '%$gemeinde%'";
|
||||
$where .= " AND Gemeinde.`name` like '$gemeinde%'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +208,7 @@ class ADBStrasseModel {
|
||||
if(array_key_exists("plz%", $filter)) {
|
||||
$plz = FronkDB::singleton()->escape($filter['plz%']);
|
||||
if($plz) {
|
||||
$where .= " AND Plz.`plzstring` like '%$plz%'";
|
||||
$where .= " AND Plz.`plzstring` like '$plz%'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,20 @@ class ADBWohneinheit extends mfBaseModel {
|
||||
$this->table = "Wohneinheit";
|
||||
}
|
||||
|
||||
protected function afterSave() {
|
||||
if(!$this->id) return true;
|
||||
if(!$this->hausnummer_id) return true;
|
||||
|
||||
if(!defined("ADBWohneinheit_onSave_noAutoUnitCount") || !ADBWohneinheit_onSave_noAutoUnitCount) {
|
||||
$unit_count = ADBWohneinheitModel::count(['hausnummer_id' => $this->hausnummer_id]);
|
||||
$hausnummer = $this->getProperty("hausnummer");
|
||||
if($hausnummer->id) {
|
||||
$hausnummer->unit_count = $unit_count;
|
||||
$hausnummer->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function parseHausnummerZusatz($text) {
|
||||
|
||||
$data = [];
|
||||
@@ -53,6 +67,49 @@ class ADBWohneinheit extends mfBaseModel {
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getNewOAID() {
|
||||
if(!$this->hausnummer_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$bcode = $this->getProperty("hausnummer")->oaid;
|
||||
//var_dump($bcode);
|
||||
if(!$bcode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$codes = [];
|
||||
|
||||
// get existing codes
|
||||
$res = $this->db->select("Wohneinheit", "oaid", "oaid like '$bcode.%'");
|
||||
if($this->db->num_rows($res)) {
|
||||
while($data = $this->db->fetch_object($res)) {
|
||||
$codes[] = $data->oaid;
|
||||
}
|
||||
} else {
|
||||
return $bcode.".001";
|
||||
}
|
||||
|
||||
if(count($codes)) {
|
||||
sort($codes);
|
||||
}
|
||||
|
||||
$last_code = end($codes);
|
||||
|
||||
$m = [];
|
||||
if(preg_match('/\.(\d+)$/', $last_code, $m)) {
|
||||
if($m[1]) {
|
||||
$last_num = $m[1];
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
$new_num = ++$last_num;
|
||||
$code = $bcode.".".sprintf("%03d", $new_num);
|
||||
return $code;
|
||||
}
|
||||
|
||||
public function afterLoad() {
|
||||
//$this->hausnummer = new ADBHausnummer($this->hausnummer_id);
|
||||
//$this->loadStatus();
|
||||
|
||||
@@ -9,6 +9,7 @@ class ADBWohneinheitModel {
|
||||
public $stock;
|
||||
public $tuer;
|
||||
public $zusatz;
|
||||
public $bezeichner;
|
||||
public $nutzung;
|
||||
|
||||
public $create_by = null;
|
||||
@@ -46,7 +47,14 @@ class ADBWohneinheitModel {
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Wohneinheit", "*", "$where ORDER BY hausnummer_id,block,stiege,LENGTH(stock),stock,LENGTH(tuer),tuer LIMIT 1");
|
||||
$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";
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ADBWohneinheit($data);
|
||||
@@ -64,7 +72,7 @@ class ADBWohneinheitModel {
|
||||
|
||||
$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");
|
||||
$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);
|
||||
@@ -87,7 +95,7 @@ class ADBWohneinheitModel {
|
||||
) as tbl
|
||||
";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
@@ -105,9 +113,9 @@ class ADBWohneinheitModel {
|
||||
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";
|
||||
ORDER BY hausnummer_id,block,stiege,LENGTH(stock),stock,LENGTH(tuer),tuer,num";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
//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'];
|
||||
|
||||
@@ -4,11 +4,12 @@ class Address extends mfBaseModel {
|
||||
protected $forcestr = ['street','company','zip','phone','fax','mobile','note'];
|
||||
private $parent;
|
||||
private $childaddresses;
|
||||
private $links;
|
||||
private $linked_as;
|
||||
private $links = [];
|
||||
private $linked_as = [];
|
||||
private $types;
|
||||
private $attributes;
|
||||
private $permissions;
|
||||
private $contracts;
|
||||
|
||||
private $phoneparts;
|
||||
|
||||
@@ -181,6 +182,14 @@ class Address extends mfBaseModel {
|
||||
$this->childaddresses = AddressModel::search(['parent' => $this->id]);
|
||||
return $this->childaddresses;
|
||||
}
|
||||
|
||||
if($name == "contracts") {
|
||||
$owning = ContractModel::search(['owner_id' => $this->id]);
|
||||
$billing = ContractModel::search(['billingaddress_id' => $this->id]);
|
||||
$this->contracts = array_merge($owning, $billing);
|
||||
return $this->contracts;
|
||||
}
|
||||
|
||||
/*
|
||||
if($name == "links_to") {
|
||||
$links = AddressLinkModel::search(['address_id' => $this->id]);
|
||||
|
||||
@@ -3,6 +3,46 @@
|
||||
class AddressDB {
|
||||
private $db;
|
||||
private $log;
|
||||
public static $wohneinheit_query = "select `Netzgebiet`.`id` AS `netzgebiet_id`,
|
||||
`Netzgebiet`.`name` AS `netzgebiet`,
|
||||
`Netzgebiet`.`extref` AS `netzgebiet_extref`,
|
||||
`Gemeinde`.`id` AS `gemeinde_id`,
|
||||
`Gemeinde`.`kennziffer` AS `gemeinde_kennziffer`,
|
||||
`Gemeinde`.`code` AS `gemeinde_code`,
|
||||
`Gemeinde`.`name` AS `gemeinde`,
|
||||
`Ortschaft`.`id` AS `ortschaft_id`,
|
||||
`Ortschaft`.`kennziffer` AS `ortschaft_kennziffer`,
|
||||
`Ortschaft`.`name` AS `ortschaft`,
|
||||
`Plz`.`plz` AS `plz`,
|
||||
`Strasse`.`id` AS `strasse_id`,
|
||||
`Strasse`.`kennziffer` AS `strasse_kennziffer`,
|
||||
`Strasse`.`name` AS `strasse`,
|
||||
`Hausnummer`.`id` AS `hausnummer_id`,
|
||||
`Hausnummer`.`oaid` AS `hausnummer_oaid`,
|
||||
`Hausnummer`.`hausnummer` AS `hausnummer`,
|
||||
`Hausnummer`.`extref` AS `hausnummer_extref`,
|
||||
`Hausnummer`.`grund_nr` AS `grund_nr`,
|
||||
`Hausnummer`.`gps_lat` AS `gps_lat`,
|
||||
`Hausnummer`.`gps_long` AS `gps_long`,
|
||||
`Hausnummer`.`rollout` AS `rollout`,
|
||||
`Hausnummer`.`rollout_info` AS `rollout_info`,
|
||||
`Hausnummer`.`freigabe` AS `freigabe`,
|
||||
`Wohneinheit`.`id` AS `wohneinheit_id`,
|
||||
`Wohneinheit`.`oaid` AS `wohneinheit_oaid`,
|
||||
`Wohneinheit`.`extref` AS `wohneinheit_extref`,
|
||||
`Wohneinheit`.`num` AS `num`,
|
||||
`Wohneinheit`.`block` AS `block`,
|
||||
`Wohneinheit`.`stiege` AS `stiege`,
|
||||
`Wohneinheit`.`stock` AS `stock`,
|
||||
`Wohneinheit`.`tuer` AS `tuer`,
|
||||
`Wohneinheit`.`bezeichner` AS `bezeichner`,
|
||||
`Wohneinheit`.`zusatz` AS `zusatz` from `Hausnummer`
|
||||
left join `Netzgebiet` on (`Hausnummer`.`netzgebiet_id` = `Netzgebiet`.`id`)
|
||||
left join `Plz` on (`Plz`.`id` = `Hausnummer`.`plz_id`)
|
||||
left join `Strasse` on (`Strasse`.`id` = `Hausnummer`.`strasse_id`)
|
||||
left join `Ortschaft` on (`Ortschaft`.`id` = `Hausnummer`.`ortschaft_id`)
|
||||
left join `Gemeinde` on (`Gemeinde`.`id` = `Strasse`.`gemeinde_id`)
|
||||
left join `Wohneinheit` on (`Wohneinheit`.`hausnummer_id` = `Hausnummer`.`id`)";
|
||||
|
||||
public function __construct() {
|
||||
$this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
@@ -30,4 +70,182 @@ class AddressDB {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* methods to create or update an Address from strings
|
||||
*/
|
||||
|
||||
public function createUpdateHausnummer($data) {
|
||||
$netzgebiet = null;
|
||||
$gemeinde = null;
|
||||
$ortschaft = null;
|
||||
$strasse = null;
|
||||
$plz = null;
|
||||
$hausnummer = null;
|
||||
|
||||
//var_dump($data);exit;
|
||||
|
||||
if(!array_key_exists("netzgebiet_id", $data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach(["gemeinde", "ortschaft", "strasse", "plz"] as $field) {
|
||||
$classname = "ADB".ucfirst($field);
|
||||
$idfield = $field."_id";
|
||||
if(!array_key_exists($field."_id", $data)) continue;
|
||||
$$field = new $classname($data[$idfield]);
|
||||
if(!${$field}->id) {
|
||||
$$field = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$netzgebiet = new ADBNetzgebiet($data['netzgebiet_id']);
|
||||
if(!$netzgebiet->id) {
|
||||
$this->log->debug(__CLASS__."::".__METHOD__.": Missing netzgebiet_id");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$gemeinde) {
|
||||
// dont allow creating Gemeinden
|
||||
$this->log->debug(__CLASS__."::".__METHOD__.": Missing Gemeinde");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$ortschaft) {
|
||||
// search by kennziffer
|
||||
if(array_key_exists("ortschaft_kennziffer", $data) && $data['ortschaft_kennziffer']) {
|
||||
$ortschaft = ADBOrtschaftModel::getFirst(['kennziffer' => $data['ortschaft_kennziffer']]);
|
||||
}
|
||||
|
||||
if(!$ortschaft) {
|
||||
// search by name
|
||||
if(!array_key_exists("ortschaft", $data) || !$data['ortschaft']) return false;
|
||||
$ortschaft = ADBOrtschaftModel::getFirst(['gemeinde_id' => $gemeinde->id, 'name' => $data['ortschaft']]);
|
||||
}
|
||||
|
||||
if(!$ortschaft) {
|
||||
// create Ortschaft
|
||||
$ortschaft = ADBOrtschaftModel::create([
|
||||
'gemeinde_id' => $gemeinde->id,
|
||||
'kennziffer' => ($data['ortschaft_kennziffer']) ? $data['ortschaft_kennziffer'] : null,
|
||||
'name' => $data['ortschaft']
|
||||
]);
|
||||
if(!$ortschaft->save()) {
|
||||
$this->log->debug(__CLASS__."::".__METHOD__.": Cannot save Ortschaft");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!$strasse) {
|
||||
// search by kennziffer
|
||||
if(array_key_exists("strasse_kennziffer", $data) && $data['strasse_kennziffer']) {
|
||||
$strasse = ADBStrasseModel::getFirst(['kennziffer' => $data['strasse_kennziffer']]);
|
||||
}
|
||||
|
||||
if(!$strasse) {
|
||||
// search by name
|
||||
if(!array_key_exists("strasse", $data) || !$data['strasse']) return false;
|
||||
$strasse = ADBStrasseModel::getFirst(['gemeinde_id' => $gemeinde->id, 'name' => $data['strasse']]);
|
||||
}
|
||||
|
||||
if(!$strasse) {
|
||||
// create Strasse
|
||||
if(!array_key_exists("strasse", $data) || !$data['strasse']) return false;
|
||||
$strasse = ADBStrasseModel::create([
|
||||
'gemeinde_id' => $gemeinde->id,
|
||||
'kennziffer' => ($data['strasse_kennziffer']) ? $data['strasse_kennziffer'] : null,
|
||||
'name' => $data['strasse']
|
||||
]);
|
||||
if(!$strasse->save()) {
|
||||
$this->log->debug(__CLASS__."::".__METHOD__.": Cannot save Strasse");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!$plz) {
|
||||
// search by plz
|
||||
if(!array_key_exists("plz", $data) || !$data['plz']) return false;
|
||||
$plz = ADBPlzModel::getFirst(['gemeinde_id' => $gemeinde->id, 'plz' => $data['plz']]);
|
||||
if(!$plz) {
|
||||
// create PLZ
|
||||
$plz = ADBPlzModel::create([
|
||||
'gemeinde_id' => $gemeinde->id,
|
||||
'plz' => $data['plz'],
|
||||
'plzstring' => $data['plz']
|
||||
]);
|
||||
if(!$plz->save()) {
|
||||
$this->log->debug(__CLASS__."::".__METHOD__.": Cannot save PLZ");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("hausnummer_id", $data)) {
|
||||
// if hausnummer_id is set but empty => fail
|
||||
if(!$data['hausnummer_id']) return false;
|
||||
$hausnummer = new ADBHausnummer($data['hausnummer_id']);
|
||||
if(!$hausnummer->id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
// build hausnummer data
|
||||
//$hausnummer_data['oaid'] = (array_key_exists("oaid", $data) && $data['oaid']) ? $data['oaid'] : null;
|
||||
$hausnummer_data['adrcd'] = ($data['adrcd']) ? $data['adrcd'] : null;
|
||||
$hausnummer_data['extref'] = ($data['extref']) ? $data['extref'] : null;
|
||||
$hausnummer_data['netzgebiet_id'] = $netzgebiet->id;
|
||||
$hausnummer_data['ortschaft_id'] = $ortschaft->id;
|
||||
$hausnummer_data['plz_id'] = $plz->id;
|
||||
$hausnummer_data['strasse_id'] = $strasse->id;
|
||||
$hausnummer_data['hausnummer'] = $data['hausnummer'];
|
||||
$hausnummer_data['grund_nr'] = $data['grund_nr'];
|
||||
$hausnummer_data['gps_lat'] = ($data['gps_lat']) ? str_replace(",", ".", $data['gps_lat']) : null;
|
||||
$hausnummer_data['gps_long'] = ($data['gps_long']) ? str_replace(",", ".", $data['gps_long']) : null;
|
||||
$hausnummer_data['rollout'] = (trim($data['rollout'])) ? trim($data['rollout']) : null;
|
||||
$hausnummer_data['rollout_info'] = (trim($data['rollout_info'])) ? trim($data['rollout_info']) : null;
|
||||
$hausnummer_data['freigabe'] = json_encode($data['freigabe']);
|
||||
$hausnummer_data['manual_add'] = date('U');
|
||||
$hausnummer_data['manual_add_by'] = $me->id;
|
||||
$hausnummer_data['manual_add_info'] = "thetool user ".$me->username." via AddressDB";
|
||||
$hausnummer_data['manual_update'] = date('U');
|
||||
$hausnummer_data['manual_update_by'] = $me->id;
|
||||
$hausnummer_data['manual_update_info'] = "thetool user ".$me->username." via AddressDB";
|
||||
|
||||
//var_dump($hausnummer_data, $hausnummer);exit;
|
||||
|
||||
if(!$hausnummer) {
|
||||
// create hausnummer
|
||||
$hausnummer = ADBHausnummerModel::create($hausnummer_data);
|
||||
} else {
|
||||
// update hausnummer
|
||||
$hausnummer->update($hausnummer_data);
|
||||
}
|
||||
|
||||
$hausnummer_id = $hausnummer->save();
|
||||
if(!$hausnummer_id) {
|
||||
$this->log->debug(__CLASS__."::".__METHOD__.": Cannot save Hausnummer");
|
||||
return false;
|
||||
}
|
||||
|
||||
// create OAID
|
||||
if(!$hausnummer->oaid) {
|
||||
$hausnummer->oaid = $hausnummer->getNewOAID();
|
||||
if(!$hausnummer->save()) {
|
||||
$this->log->debug(__CLASS__."::".__METHOD__.": Cannot save Hausnummer OAID");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $hausnummer_id;
|
||||
}
|
||||
|
||||
public function updateHausnummer($hausnummer_id, $data) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,11 +9,374 @@ class AddressDBController extends mfBaseController {
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
if(!$me->is(["Admin", "netowner", "pipeplanner"])) {
|
||||
if(!$me->is(["Admin", "netowner"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function indexAction() {
|
||||
$this->layout()->setTemplate("AddressDB/Index");
|
||||
|
||||
$rfilter = $this->request->filter;
|
||||
iF(!is_array($rfilter)) {
|
||||
$rfilter = [];
|
||||
}
|
||||
|
||||
$this->layout->set("filter", $rfilter);
|
||||
|
||||
$filter = $this->getPreparedFilter($rfilter);
|
||||
|
||||
// pagination defaults
|
||||
$pagination = [];
|
||||
$pagination['start'] = 0;
|
||||
$pagination['count'] = 25;
|
||||
$pagination['maxItems'] = 0;
|
||||
|
||||
if(is_numeric($this->request->s)) {
|
||||
$pagination['start'] = intval($this->request->s);
|
||||
}
|
||||
|
||||
|
||||
if($this->me->is("Admin")) {
|
||||
$my_networks = NetworkModel::getAll();
|
||||
if($filter['network_id']) {
|
||||
$filter['netzgebiet_id'] = $filter['network_id'];
|
||||
}
|
||||
} else {
|
||||
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
|
||||
}
|
||||
|
||||
$netzgebiet_ids = [];
|
||||
$my_adb_networks = [];
|
||||
foreach($my_networks as $network) {
|
||||
if($network->adb_netzgebiet_id && !in_array($network->adb_netzgebiet_id, $netzgebiet_ids)) {
|
||||
$netzgebiet_ids[] = $network->adb_netzgebiet_id;
|
||||
$my_adb_networks[$network->adb_netzgebiet_id] = new ADBNetzgebiet($network->adb_netzgebiet_id);
|
||||
}
|
||||
}
|
||||
//var_dump($my_networks, $my_adb_networks);
|
||||
if(!$this->me->is("Admin") && array_key_exists("network_id", $filter)) {
|
||||
if(array_key_exists($filter['network_id'], $my_adb_networks)) {
|
||||
$filter['netzgebiet_id'] = $filter['network_id'];
|
||||
} else {
|
||||
unset($filter['network_id']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$addressdb_filter = $filter;
|
||||
if(!array_key_exists("netzgebiet_id", $addressdb_filter)) {
|
||||
$addressdb_filter['netzgebiet_id'] = $netzgebiet_ids;
|
||||
}
|
||||
//var_dump($my_adb_networks);exit;
|
||||
$this->layout()->set("my_networks", ADBNetzgebietModel::getAll());
|
||||
$this->layout()->set("my_adb_networks", $my_adb_networks);
|
||||
//var_dump($addressdb_filter);exit;
|
||||
|
||||
if($filter['netzgebiet_id'] === "null") {
|
||||
$addressdb_filter['netzgebiet_id'] = 0;
|
||||
$pagination['maxItems'] = ADBHausnummerModel::count($addressdb_filter);
|
||||
$addresses = ADBHausnummerModel::search($addressdb_filter, $pagination);
|
||||
} else if(count($my_adb_networks)) {
|
||||
$pagination['maxItems'] = ADBHausnummerModel::count($addressdb_filter);
|
||||
$addresses = ADBHausnummerModel::search($addressdb_filter, $pagination);
|
||||
}
|
||||
$this->layout()->set("pagination", $pagination);
|
||||
$this->layout()->set("addresses", $addresses);
|
||||
|
||||
// get filter lists
|
||||
$filter_filter = [];
|
||||
if(array_key_exists("netzgebiet_id", $addressdb_filter)) {
|
||||
$filter_filter["netzgebiet_id"] = $netzgebiet_ids;
|
||||
$this->layout()->set("gemeinden", ADBGemeindeModel::search($filter_filter));
|
||||
if(array_key_exists("gemeinde_id", $addressdb_filter)) {
|
||||
$filter_filter['gemeinde_id'] = $addressdb_filter['gemeinde_id'];
|
||||
}
|
||||
$this->layout()->set("ortschaften", ADBOrtschaftModel::search($filter_filter));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function getPreparedFilter($filter) {
|
||||
$new_filter = [];
|
||||
|
||||
if(array_key_exists("street", $filter) && $filter['street']) {
|
||||
$new_filter['strasse%'] = "%".$filter['street'];
|
||||
unset($filter['street']);
|
||||
}
|
||||
|
||||
if(array_key_exists("adrcd", $filter) && $filter['adrcd']) {
|
||||
$new_filter['adrcd%'] = $filter['adrcd'];
|
||||
unset($filter['adrcd']);
|
||||
}
|
||||
|
||||
if(array_key_exists("oaid", $filter) && $filter['oaid']) {
|
||||
$new_filter['oaid%'] = $filter['oaid'];
|
||||
unset($filter['oaid']);
|
||||
}
|
||||
|
||||
if(array_key_exists("extref", $filter) && $filter['extref']) {
|
||||
$new_filter['extref%'] = "%".$filter['extref'];
|
||||
unset($filter['extref']);
|
||||
}
|
||||
|
||||
if(array_key_exists("zip", $filter) && $filter['zip']) {
|
||||
$new_filter['plz%'] = $filter['zip'];
|
||||
unset($filter['zip']);
|
||||
}
|
||||
|
||||
if(array_key_exists("rollout", $filter) && $filter['rollout']) {
|
||||
$new_filter['rollout%'] = $filter['rollout'];
|
||||
unset($filter['rollout']);
|
||||
}
|
||||
|
||||
if(array_key_exists("rollout_info", $filter) && $filter['rollout_info']) {
|
||||
$new_filter['rollout_info%'] = $filter['rollout_info'];
|
||||
unset($filter['rollout_info']);
|
||||
}
|
||||
|
||||
if(array_key_exists("gemeinde", $filter) && $filter['gemeinde']) {
|
||||
$new_filter['gemeinde%'] = $filter['gemeinde'];
|
||||
unset($filter['gemeinde']);
|
||||
unset($filter['gemeinde_id']);
|
||||
}
|
||||
|
||||
if(array_key_exists("ortschaft", $filter) && $filter['ortschaft']) {
|
||||
$new_filter['ortschaft%'] = $filter['ortschaft'];
|
||||
unset($filter['ortschaft']);
|
||||
unset($filter['ortschaft_id']);
|
||||
}
|
||||
|
||||
if(is_array($filter) && count($filter)) {
|
||||
foreach($filter as $name => $value) {
|
||||
if(strlen($value) > 0) $new_filter[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $new_filter;
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
$this->layout()->setTemplate("AddressDB/Form");
|
||||
|
||||
if($this->me->is("Admin")) {
|
||||
$my_networks = NetworkModel::getAll();
|
||||
} else {
|
||||
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
|
||||
}
|
||||
|
||||
$netzgebiet_ids = [];
|
||||
$my_adb_networks = [];
|
||||
foreach($my_networks as $network) {
|
||||
if($network->adb_netzgebiet_id && !in_array($network->adb_netzgebiet_id, $netzgebiet_ids)) {
|
||||
$netzgebiet_ids[] = $network->adb_netzgebiet_id;
|
||||
$my_adb_networks[$network->adb_netzgebiet_id] = new ADBNetzgebiet($network->adb_netzgebiet_id);
|
||||
}
|
||||
}
|
||||
$this->layout()->set("my_adb_networks", $my_adb_networks);
|
||||
|
||||
|
||||
$save_data = [];
|
||||
foreach($this->request->get() as $key => $value) {
|
||||
$save_data[$key] = $value;
|
||||
}
|
||||
//var_dump($save_data);exit;
|
||||
$this->layout()->set("save_data", $save_data);
|
||||
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
|
||||
$id = $this->request->id;
|
||||
if(!is_numeric($id) || $id < 1) {
|
||||
$this->layout()->setFlash("Adresse nicht gefunden", "error");
|
||||
$this->redirect("AddressDB");
|
||||
}
|
||||
|
||||
$hausnummer = new ADBHausnummer($id);
|
||||
if(!$hausnummer->id) {
|
||||
$this->layout()->setFlash("Adresse nicht gefunden", "error");
|
||||
$this->redirect("AddressDB");
|
||||
}
|
||||
|
||||
/*if(!in_array($hausnummer->netzgebiet_id, $my_adb_networks)) {
|
||||
$this->layout()->setFlash("Adresse nicht gefunden", "error");
|
||||
$this->redirect("AddressDB");
|
||||
}*/
|
||||
|
||||
$this->layout()->set("address", $hausnummer);
|
||||
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
//var_dump($r->get());exit;
|
||||
|
||||
$address_data = [];
|
||||
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$hausnummer = new ADBHausnummer($id);
|
||||
if(!$hausnummer->id) {
|
||||
$this->layout()->setFlash("Addresse nicht gefunden", "error");
|
||||
$this->redirect("AddressDB");
|
||||
}
|
||||
$address_data['hausnummer_id'] = $hausnummer->id;
|
||||
} else {
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
$required = ['netzgebiet_id','strasse','hausnummer','plz','ortschaft','gemeinde'];
|
||||
foreach(['adrcd','extref','netzgebiet_id','strasse','hausnummer','plz','ortschaft','gemeinde','grund_nr','gps_lat','gps_long','unit_count'] as $field) {
|
||||
if(in_array($field, $required)) {
|
||||
if(!trim($r->$field)) {
|
||||
$this->layout()->setFlash("'".ucfirst($field)."' darf nicht leer sein!", "error");
|
||||
return $this->addAction();
|
||||
//$this->redirect("AddressDB", $mode, ['id' => $id]);
|
||||
}
|
||||
}
|
||||
$address_data[$field] = $this->db()->escape(trim($r->$field));
|
||||
}
|
||||
|
||||
$gemeinde = ADBGemeindeModel::getFirst(['name' => $address_data['gemeinde']]);
|
||||
if(!$gemeinde->id) {
|
||||
$this->layout()->setFlash("Gemeinde nicht gefunden", "error");
|
||||
return $this->addAction();
|
||||
//$this->redirect("AddressDB", $mode, ['id' => $id]);
|
||||
}
|
||||
|
||||
$address_data['gemeinde_id'] = $gemeinde->id;
|
||||
|
||||
$freigabe = [];
|
||||
if(is_array($r->freigabe) && count($r->freigabe)) {
|
||||
if(in_array("interest", $r->freigabe)) {
|
||||
$freigabe[] = "interest";
|
||||
}
|
||||
if(in_array("provision", $r->freigabe)) {
|
||||
$freigabe[] = "provision";
|
||||
}
|
||||
if(in_array("order", $r->freigabe)) {
|
||||
$freigabe[] = "order";
|
||||
}
|
||||
if(in_array("reorder", $r->freigabe)) {
|
||||
$freigabe[] = "reorder";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$address_data['freigabe'] = $freigabe;
|
||||
|
||||
$rollout = null;
|
||||
$rollout_info = null;
|
||||
if(trim($r->rollout)) {
|
||||
$rollout = intval(trim($r->rollout));
|
||||
}
|
||||
if(trim($r->rollout_info)) {
|
||||
$rollout_info = trim($r->rollout_info);
|
||||
}
|
||||
if(!$rollout_info) {
|
||||
$rollout_info = "unscheduled";
|
||||
}
|
||||
|
||||
$address_data['rollout'] = $rollout;
|
||||
$address_data['rollout_info'] = $rollout_info;
|
||||
|
||||
//var_dump($address_data);exit;
|
||||
|
||||
$adb = new AddressDB();
|
||||
$hausnummer_id = $adb->createUpdateHausnummer($address_data);
|
||||
if(!$hausnummer_id) {
|
||||
$this->layout()->setFlash("Fehler beim Erstellen der Adresse!", "error");
|
||||
return $this->addAction();
|
||||
//$this->redirect("AddressDB");
|
||||
}
|
||||
|
||||
if($mode == "add") {
|
||||
$hausnummer = new ADBHausnummer($hausnummer_id);
|
||||
|
||||
/*
|
||||
* Wohneinheiten erstellen
|
||||
*/
|
||||
if($r->unit_count > 0) {
|
||||
for($i = 1; $i <= $r->unit_count; $i++) {
|
||||
$unit = ADBWohneinheitModel::create([
|
||||
'hausnummer_id' => $hausnummer_id,
|
||||
'num' => $i,
|
||||
]);
|
||||
$unit_id = $unit->save();
|
||||
if(!$unit_id) {
|
||||
$this->log->debug(__CLASS__."::".__METHOD__.": Cannot save Woneinheit");
|
||||
continue;
|
||||
}
|
||||
$unit->oaid = $unit->getNewOAID();
|
||||
$unit->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$qs = http_build_query(['filter' => ['oaid' => $hausnummer->oaid]]);
|
||||
//var_dump($qs);exit;
|
||||
$this->layout()->setFlash("Adresse erfolgreich gespeichert", "success");
|
||||
$this->redirect("AddressDB", "Index", $qs);
|
||||
|
||||
}
|
||||
|
||||
protected function exportAction() {
|
||||
$rfilter = $this->request->filter;
|
||||
if(!is_array($rfilter)) {
|
||||
$rfilter = [];
|
||||
}
|
||||
$filter = $this->getPreparedFilter($rfilter);
|
||||
|
||||
|
||||
if($this->me->is("Admin")) {
|
||||
$my_networks = NetworkModel::getAll();
|
||||
} else {
|
||||
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
|
||||
}
|
||||
|
||||
$netzgebiet_ids = [];
|
||||
$my_adb_networks = [];
|
||||
foreach($my_networks as $network) {
|
||||
if($network->adb_netzgebiet_id && !in_array($network->adb_netzgebiet_id, $netzgebiet_ids)) {
|
||||
$netzgebiet_ids[] = $network->adb_netzgebiet_id;
|
||||
$my_adb_networks[$network->adb_netzgebiet_id] = new ADBNetzgebiet($network->adb_netzgebiet_id);
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("network_id", $filter) && $filter['network_id']) {
|
||||
if($this->me->is("Admin")) {
|
||||
$filter['netzgebiet_id'] = $filter['network_id'];
|
||||
} else {
|
||||
if(in_array($filter['network_id'], $netzgebiet_ids)) {
|
||||
$filter['netzgebiet_id'] = $filter['network_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($filter['network_id']);
|
||||
|
||||
$addressdb_filter = $filter;
|
||||
if(!array_key_exists("netzgebiet_id", $addressdb_filter)) {
|
||||
$addressdb_filter['netzgebiet_id'] = $netzgebiet_ids;
|
||||
}
|
||||
|
||||
// Get mysqli resource from Model so layout can output data as it's retrieved
|
||||
// Fixes lousy performance and horrendous memory usage
|
||||
$res = ADBHausnummerModel::search($addressdb_filter, [], true);
|
||||
|
||||
$this->layout()->setTemplate("AddressDB/export.csv");
|
||||
$this->layout()->set("res", $res);
|
||||
|
||||
//var_dump($filter, $hausnummern);exit;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function apiAction() {
|
||||
if(!$this->me->is(["Admin","netowner"])) {
|
||||
$this->redirect("Dashboard");
|
||||
@@ -28,12 +391,24 @@ class AddressDBController extends mfBaseController {
|
||||
case "getFilteredBuildings":
|
||||
$return = $this->getFilteredBuildingsApi();
|
||||
break;
|
||||
case "getAddressByHousenumber":
|
||||
$return = $this->getAddressByHousenumberApi();
|
||||
break;
|
||||
case "getUnits":
|
||||
$return = $this->getUnitsApi();
|
||||
break;
|
||||
case "findStreets":
|
||||
$return = $this->findStreetsApi();
|
||||
break;
|
||||
case "findDistricts":
|
||||
$return = $this->findDistrictsApi();
|
||||
break;
|
||||
case "findCities":
|
||||
$return = $this->findCitiesApi();
|
||||
break;
|
||||
case "findZips":
|
||||
$return = $this->findZipsApi();
|
||||
break;
|
||||
case 'findBuildings':
|
||||
$return = $this->findBuildingsApi();
|
||||
break;
|
||||
@@ -55,6 +430,20 @@ class AddressDBController extends mfBaseController {
|
||||
private function findAddressApi() {
|
||||
$addresses = [];
|
||||
$search = trim($this->request->q);
|
||||
$campagin_id = ($this->request->campaign_id);
|
||||
|
||||
$campaign = new Preordercampaign($campagin_id);
|
||||
if(!$campaign->id) {
|
||||
header("Content-Type: application/json");
|
||||
echo json_encode(["results" => []]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$scluster_ids = [];
|
||||
foreach($campaign->salesclusters as $scluster) {
|
||||
$scluster_ids[] = $scluster->id;
|
||||
}
|
||||
|
||||
$results = [];
|
||||
|
||||
$search_parts = explode(" ", $search);
|
||||
@@ -62,19 +451,25 @@ class AddressDBController extends mfBaseController {
|
||||
$ort_search = $strasse_search = $plz_search = $hausnummer_search = [];
|
||||
|
||||
foreach($search_parts as $p) {
|
||||
$p = trim($p);
|
||||
$p = $this->db->escape(trim($p));
|
||||
if(!$p) continue;
|
||||
$ort_search[] = "ortschaft like '%$p%'";
|
||||
$strasse_search[] = "strasse like '%$p%'";
|
||||
$ort_search[] = "ortschaft like '$p%'";
|
||||
$strasse_search[] = "strasse like '$p%'";
|
||||
$plz_search[] = "plz like '%$p%'";
|
||||
$hausnummer_search[] = "hausnummer like '%$p%'";
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM view_hausnummer WHERE (".implode(" OR ", $ort_search).") OR (".implode(" OR ", $strasse_search).") OR (".implode(" OR ", $plz_search).") OR (".implode(" OR ", $hausnummer_search).")";
|
||||
//echo $sql;exit;
|
||||
$where = "1=1";
|
||||
if(count($scluster_ids)) {
|
||||
$where .= " AND netzgebiet_id IN (".implode(', ',$scluster_ids).")";
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM view_hausnummer WHERE $where AND ((".implode(" OR ", $ort_search).") OR (".implode(" OR ", $strasse_search).") OR (".implode(" OR ", $plz_search).") OR (".implode(" OR ", $hausnummer_search).")) ORDER BY strasse, LENGTH(hausnummer), hausnummer";
|
||||
$this->log->debug($sql);
|
||||
|
||||
$adb = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
$res = $adb->query($sql);
|
||||
$this->log->debug("done");
|
||||
|
||||
if(!$adb->num_rows($res)) {
|
||||
header("Content-Type: application/json");
|
||||
@@ -84,22 +479,39 @@ class AddressDBController extends mfBaseController {
|
||||
|
||||
while($data = $adb->fetch_object($res)) {
|
||||
$address_string = $data->plz." ".$data->ortschaft.", ".$data->strasse." ".$data->hausnummer;
|
||||
$sort_key = $data->plz." ".$data->ortschaft." ".$data->strasse;
|
||||
|
||||
$address = [];
|
||||
$address['id'] = $data->hausnummer_id;
|
||||
$address["text"] = $address_string;
|
||||
$address['sort_key'] = $sort_key;
|
||||
$addresses[] = $address;
|
||||
}
|
||||
|
||||
|
||||
// sort results by most occurences of search strings
|
||||
$sort = [];
|
||||
foreach($addresses as $address) {
|
||||
foreach($addresses as $key => $address) {
|
||||
$includes_int = false;
|
||||
$count = 0;
|
||||
foreach($search_parts as $p) {
|
||||
$count += substr_count(strtolower($address['text']), strtolower($p));
|
||||
$p = $this->db->escape(trim($p));
|
||||
if(!$p) continue;
|
||||
if(is_numeric(($p))) {
|
||||
$includes_int = true;
|
||||
if(substr_count(strtolower($address['text']), strtolower($p))) {
|
||||
$count++;
|
||||
}
|
||||
} else {
|
||||
$count += substr_count(strtolower($address['text']), strtolower($p));
|
||||
}
|
||||
}
|
||||
unset($address['sort_key']);
|
||||
//echo $address['text']." $p $count<br />\n";
|
||||
|
||||
if($includes_int && (($count + 1) - count($search_parts) ) < 1) {
|
||||
continue;
|
||||
}
|
||||
if(!array_key_exists($count, $sort)) {
|
||||
$sort[$count] = [];
|
||||
}
|
||||
@@ -136,7 +548,7 @@ class AddressDBController extends mfBaseController {
|
||||
$u = [];
|
||||
$u['id'] = $unit->id;
|
||||
$u['zip'] = $unit->hausnummer->plz->plzstring;
|
||||
$u['city'] = $unit->hausnummer->strasse->ortschaft->name;
|
||||
$u['city'] = $unit->hausnummer->ortschaft->name;
|
||||
$u['street'] = $unit->hausnummer->strasse->name;
|
||||
$u['housenumber'] = $unit->hausnummer->hausnummer;
|
||||
$u['block'] = $unit->block;
|
||||
@@ -152,15 +564,109 @@ class AddressDBController extends mfBaseController {
|
||||
return ['units' => $results];
|
||||
}
|
||||
|
||||
private function findCitiesApi() {
|
||||
$cities = [];
|
||||
$search = $this->request->search;
|
||||
private function getAddressByHousenumberApi() {
|
||||
$zips = [];
|
||||
$hausnummer_id = trim($this->request->hausnummer_id);
|
||||
|
||||
$ort_ids = [];
|
||||
if(!is_numeric($hausnummer_id) || $hausnummer_id < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$hausnummer = new ADBHausnummer($hausnummer_id);
|
||||
|
||||
$result = [
|
||||
'hausnummer_id' => $hausnummer->id,
|
||||
'strasse' => $hausnummer->strasse->name,
|
||||
'hausnummer' => $hausnummer->hausnummer,
|
||||
'plz' => $hausnummer->plz->plz,
|
||||
'ort' => $hausnummer->strasse->gemeinde->name,
|
||||
'ortschaft' => $hausnummer->ortschaft->name
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function findStreetsApi() {
|
||||
$streets = [];
|
||||
$search = trim($this->request->q);
|
||||
|
||||
foreach(ADBStrasseModel::search(['name%' => $search]) as $street) {
|
||||
if(!in_array($street->name, $streets)) {
|
||||
$streets[] = $street->name;
|
||||
}
|
||||
}
|
||||
|
||||
$this->returnJson($streets);
|
||||
}
|
||||
|
||||
private function findZipsApi() {
|
||||
$zips = [];
|
||||
$search = trim($this->request->q);
|
||||
$campaign_id = trim($this->request->campaign_id);
|
||||
|
||||
$plz_search = [];
|
||||
|
||||
if($campaign_id) {
|
||||
$campaign = new Preordercampaign($campaign_id);
|
||||
if(!$campaign->id) {
|
||||
header("Content-Type: application/json");
|
||||
echo json_encode(["results" => []]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$scluster_ids = [];
|
||||
foreach($campaign->salesclusters as $scluster) {
|
||||
$scluster_ids[] = $scluster->id;
|
||||
}
|
||||
$plz_search['netzgebiet_id'] = $scluster_ids;
|
||||
}
|
||||
|
||||
$plz_search['plzstring%'] = $search;
|
||||
|
||||
|
||||
foreach(ADBPlzModel::search($plz_search) as $zip) {
|
||||
if(!in_array($zip->plz, $zips)) {
|
||||
$zips[] = $zip->plz;
|
||||
}
|
||||
}
|
||||
|
||||
$this->returnJson($zips);
|
||||
}
|
||||
|
||||
private function findDistrictsApi() {
|
||||
$districts = [];
|
||||
$search = trim($this->request->q);
|
||||
$autocomplete = $this->request->autocomplete;
|
||||
$campaign_id = trim($this->request->campaign_id);
|
||||
|
||||
$district_search = [];
|
||||
|
||||
if($campaign_id) {
|
||||
$campaign = new Preordercampaign($campaign_id);
|
||||
if(!$campaign->id) {
|
||||
header("Content-Type: application/json");
|
||||
echo json_encode(["results" => []]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$scluster_ids = [];
|
||||
foreach($campaign->salesclusters as $scluster) {
|
||||
$scluster_ids[] = $scluster->id;
|
||||
}
|
||||
$district_search['netzgebiet_id'] = $scluster_ids;
|
||||
}
|
||||
|
||||
$district_search['name%'] = "%".$search;
|
||||
|
||||
foreach(ADBOrtschaftModel::search($district_search) as $district) {
|
||||
if(!in_array($district->name, $districts)) {
|
||||
$districts[] = $district->name;
|
||||
}
|
||||
}
|
||||
/*
|
||||
if(is_numeric($search)) {
|
||||
$adb = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
$sql = "SELECT ortschaft_id from view_wohneinheit WHERE plz like '%$search%' GROUP BY ortschaft_id";
|
||||
$sql = "SELECT ortschaft_id from view_wohneinheit WHERE ortschaft like '%$search%' GROUP BY ortschaft_id";
|
||||
$res = $adb->query($sql);
|
||||
|
||||
if($adb->num_rows($res)) {
|
||||
@@ -178,9 +684,18 @@ class AddressDBController extends mfBaseController {
|
||||
$results = ADBOrtschaftModel::search(['name%' => $search]);
|
||||
}
|
||||
|
||||
if($autocomplete) {
|
||||
foreach($results as $city) {
|
||||
if(!in_array($city->name, $cities)) {
|
||||
$cities[] = $city->name;
|
||||
}
|
||||
}
|
||||
$this->returnJson($cities);
|
||||
}
|
||||
|
||||
foreach($results as $city) {
|
||||
$gemeinde = new ADBGemeinde($city->gemeinde_id);
|
||||
|
||||
|
||||
$data = [];
|
||||
$data['id'] = $city->id;
|
||||
$data['gemeinde_id'] = $city->gemeinde_id;
|
||||
@@ -189,8 +704,43 @@ class AddressDBController extends mfBaseController {
|
||||
$data['name'] = $city->name;
|
||||
$cities[] = $data;
|
||||
}
|
||||
*/
|
||||
$this->returnJson($districts);
|
||||
//return ['cities' => $cities];
|
||||
}
|
||||
|
||||
private function findCitiesApi() {
|
||||
$cities = [];
|
||||
$search = $this->request->q;
|
||||
//$autocomplete = $this->request->autocomplete;
|
||||
$campaign_id = trim($this->request->campaign_id);
|
||||
|
||||
$city_search = [];
|
||||
|
||||
if($campaign_id) {
|
||||
$campaign = new Preordercampaign($campaign_id);
|
||||
if(!$campaign->id) {
|
||||
header("Content-Type: application/json");
|
||||
echo json_encode(["results" => []]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$scluster_ids = [];
|
||||
foreach($campaign->salesclusters as $scluster) {
|
||||
$scluster_ids[] = $scluster->id;
|
||||
}
|
||||
$city_search['netzgebiet_id'] = $scluster_ids;
|
||||
}
|
||||
|
||||
$city_search['name%'] = "%".$search;
|
||||
|
||||
foreach(ADBGemeindeModel::search($city_search) as $city) {
|
||||
if(!in_array($city->name, $cities)) {
|
||||
$cities[] = $city->name;
|
||||
}
|
||||
}
|
||||
$this->returnJson($cities);
|
||||
|
||||
return ['cities' => $cities];
|
||||
}
|
||||
|
||||
private function getFilteredBuildingsApi() {
|
||||
|
||||
@@ -114,19 +114,21 @@ class AddresstypeModel {
|
||||
/*
|
||||
* Address Type
|
||||
*/
|
||||
if(is_array($filter['addresstype']) && count($filter['addresstype'])) {
|
||||
$at = $filter['addresstype'];
|
||||
$in = [];
|
||||
foreach(TT_ROLES as $role) {
|
||||
if(in_array($role, $at)) {
|
||||
$in[] = "Addresstype.type = '$role'";
|
||||
if(array_key_exists('addresstype', $filter)) {
|
||||
if(is_array($filter['addresstype']) && count($filter['addresstype'])) {
|
||||
$at = $filter['addresstype'];
|
||||
$in = [];
|
||||
foreach(TT_ROLES as $role) {
|
||||
if(in_array($role, $at)) {
|
||||
$in[] = "Addresstype.type = '$role'";
|
||||
}
|
||||
}
|
||||
|
||||
$or = "";
|
||||
if(count($in)) {
|
||||
$or = implode(" OR ", $in);
|
||||
$where .= " AND ( $or )";
|
||||
}
|
||||
}
|
||||
|
||||
$or = "";
|
||||
if(count($in)) {
|
||||
$or = implode(" OR ", $in);
|
||||
$where .= " AND ( $or )";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
class AdminController extends mfBaseController {
|
||||
|
||||
protected function init() {
|
||||
$this->needlogin=true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
if(!$me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
$this->layout()->setTemplate("Admin/Index");
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function createNetworkAddressForNetowner() {
|
||||
$i = 0;
|
||||
foreach(NetworkModel::getAll() as $network) {
|
||||
$netaddress = NetworkAddressModel::getFirst(["network_id" => $network->id, "address_id" => $network->owner_id, "addresstype" => "netowner"]);
|
||||
if(!$netaddress) {
|
||||
$netaddress = NetworkAddressModel::create([
|
||||
'network_id' => $network->id,
|
||||
'address_id' => $network->owner_id,
|
||||
'type' => "netowner"
|
||||
]);
|
||||
$netaddress->save();
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$this->layout()->setFlash("$i NetworkAddress Objekte angelegt.", "success");
|
||||
$this->redirect("Admin");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,20 +4,26 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
private $campaigns = [];
|
||||
private $filter_salescluster_ids = [];
|
||||
private $campaigns_by_scluster = [];
|
||||
|
||||
private $allowed_preordertypes = [];
|
||||
private $district_is_city = false;
|
||||
private $hausnummer_add_zusatz = false;
|
||||
|
||||
protected function init() {
|
||||
$db = $this->db(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$this->addRoute("/addressdb/getClusters", "getClusters", "GET");
|
||||
$this->addRoute("/addressdb/findAddress", "find", "GET");
|
||||
$this->addRoute("/addressdb/findAddress", "find", "POST");
|
||||
$this->addRoute("/addressdb/findStreet", "findStreet", "GET");
|
||||
$this->addRoute("/addressdb/searchAddress", "search", "GET");
|
||||
$this->addRoute("/addressdb/searchAddress", "search", "POST");
|
||||
$this->addRoute("/addressdb/findStreet", "findStreet", "GET");
|
||||
$this->addRoute("/addressdb/findStreet", "findStreet", "POST");
|
||||
$this->addRoute("/addressdb/findZip", "findZip", "GET");
|
||||
$this->addRoute("/addressdb/findZip", "findZip", "POST");
|
||||
$this->addRoute("/addressdb/findCity", "findCity", "GET");
|
||||
$this->addRoute("/addressdb/findCity", "findCity", "POST");
|
||||
$this->addRoute("/addressdb/findDistrict", "findDistrict", "GET");
|
||||
$this->addRoute("/addressdb/findDistrict", "findDistrict", "POST");
|
||||
|
||||
$this->allowMissingOrigin = true;
|
||||
}
|
||||
@@ -33,10 +39,7 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
$this->filter_salescluster_ids[] = $campain_scluster->salescluster_id;
|
||||
}
|
||||
|
||||
if(!array_key_exists($campain_scluster->salescluster_id, $this->campaigns_by_scluster)) {
|
||||
$this->campaigns_by_scluster[$campain_scluster->salescluster_id] = [];
|
||||
}
|
||||
$this->campaigns_by_scluster[$campain_scluster->salescluster_id][] = $campaign->id;
|
||||
$this->campaigns_by_scluster[$campain_scluster->salescluster_id] = $campaign->id;
|
||||
|
||||
}
|
||||
$this->campaigns[$campaign->id] = $campaign;
|
||||
@@ -47,6 +50,14 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
$this->allowed_preordertypes[] = $type->type;
|
||||
}
|
||||
}
|
||||
|
||||
if($campaign->district_is_city == 1) {
|
||||
$this->district_is_city = true;
|
||||
}
|
||||
|
||||
if($campaign->hausnummer_add_zusatz == 1) {
|
||||
$this->hausnummer_add_zusatz = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach(PreordercampaignOriginhostnameModel::search(['preordercampaign_id' => $campaign->id]) as $origin) {
|
||||
@@ -61,6 +72,23 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
|
||||
}
|
||||
|
||||
protected function getClusters() {
|
||||
$cluster_search = [];
|
||||
if(count($this->filter_salescluster_ids)) {
|
||||
$cluster_search['netzgebiet_id'] = $this->filter_salescluster_ids;
|
||||
}
|
||||
$clusters = [];
|
||||
foreach(ADBNetzgebietModel::search($cluster_search) as $cluster) {
|
||||
$c = [];
|
||||
$c['id'] = $cluster->extref;
|
||||
$c['name'] = $cluster->name;
|
||||
$clusters[] = $c;
|
||||
}
|
||||
|
||||
return mfResponse::Ok(["clusters" => $clusters]);
|
||||
|
||||
}
|
||||
|
||||
protected function findCity() {
|
||||
// unofficially supporting GET and POST in v1
|
||||
$get = array_merge($this->post, $this->get);
|
||||
@@ -68,13 +96,15 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
// search parameter is unofficially deprecated but still supported
|
||||
$search = trim($get['search']);
|
||||
$city = trim($get['city']);
|
||||
$district = trim($get['district']);
|
||||
$zip = trim($get['zip']);
|
||||
$search_cluster_id = trim($get['cluster_id']);
|
||||
|
||||
if(!$city) {
|
||||
$city = $search;
|
||||
}
|
||||
|
||||
if(!$city && !$zip) {
|
||||
if(!$city && !$zip && !$search_cluster_id) {
|
||||
return mfResponse::BadRequest(['message' => "No search parameters"]);
|
||||
}
|
||||
|
||||
@@ -82,12 +112,23 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
if($zip) {
|
||||
$city_search['plz%'] = $zip;
|
||||
}
|
||||
if($district) {
|
||||
$district_search['ortschaft%'] = $zip;
|
||||
}
|
||||
|
||||
if(count($this->filter_salescluster_ids)) {
|
||||
$city_search['netzgebiet_id'] = $this->filter_salescluster_ids;
|
||||
}
|
||||
|
||||
$results = ADBGemeindeModel::search($city_search);
|
||||
if($search_cluster_id) {
|
||||
$city_search['netzgebiet_extref'] = $search_cluster_id;
|
||||
}
|
||||
|
||||
if($this->district_is_city) {
|
||||
$results = ADBOrtschaftModel::search($city_search);
|
||||
} else {
|
||||
$results = ADBGemeindeModel::search($city_search);
|
||||
}
|
||||
|
||||
|
||||
$cities = [];
|
||||
@@ -99,6 +140,62 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
return mfResponse::Ok(['cities' => array_values($cities)]);
|
||||
}
|
||||
|
||||
protected function findDistrict() {
|
||||
// unofficially supporting GET and POST in v1
|
||||
$get = array_merge($this->post, $this->get);
|
||||
|
||||
// search parameter is unofficially deprecated but still supported
|
||||
$search = $this->db()->escape(trim($get['search']));
|
||||
$city = $this->db()->escape(trim($get['city']));
|
||||
$district = $this->db()->escape(trim($get['district']));
|
||||
$zip = $this->db()->escape(trim($get['zip']));
|
||||
$search_cluster_id = $this->db()->escape(trim($get['cluster_id']));
|
||||
|
||||
if(!$district) {
|
||||
$district = $search;
|
||||
}
|
||||
/*
|
||||
if(!$city && !$zip && !$district) {
|
||||
return mfResponse::BadRequest(['message' => "No search parameters"]);
|
||||
}*/
|
||||
|
||||
$where = "1=1";
|
||||
|
||||
if($district && $district != "%") {
|
||||
$where .= " AND ortschaft like '$district%'";
|
||||
}
|
||||
if($city && $city != "%") {
|
||||
$where .= " AND gemeinde like '$city%'";
|
||||
}
|
||||
if($zip && $zip != "%") {
|
||||
$where .= " AND plz like '$zip%'";
|
||||
}
|
||||
|
||||
if(count($this->filter_salescluster_ids)) {
|
||||
$where .= " AND netzgebiet_id IN (".join(", ", $this->filter_salescluster_ids).")";
|
||||
}
|
||||
|
||||
if($search_cluster_id) {
|
||||
$where .= " AND netzgebiet_extref='$search_cluster_id'";
|
||||
}
|
||||
|
||||
$cities = [];
|
||||
|
||||
$sql = "SELECT gemeinde, ortschaft FROM view_hausnummer WHERE $where GROUP BY gemeinde,ortschaft_id ORDER BY gemeinde, ortschaft";
|
||||
//echo $sql;exit;
|
||||
$res = $this->db()->query($sql);
|
||||
if($this->db()->num_rows($res)) {
|
||||
while($data = $this->db()->fetch_object($res)) {
|
||||
if(!array_key_exists($data->gemeinde, $cities)) {
|
||||
$cities[$data->gemeinde] = [];
|
||||
}
|
||||
$cities[$data->gemeinde][] = $data->ortschaft;
|
||||
}
|
||||
}
|
||||
|
||||
return mfResponse::Ok(['cities' => $cities]);
|
||||
}
|
||||
|
||||
protected function findZip() {
|
||||
// unofficially supporting GET and POST in v1
|
||||
$get = array_merge($this->post, $this->get);
|
||||
@@ -106,8 +203,9 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
// search parameter is unofficially deprecated but still supported
|
||||
$search = trim($get['search']);
|
||||
$zip = trim($get['zip']);
|
||||
$search_cluster_id = trim($get['cluster_id']);
|
||||
|
||||
if(!$search && !$zip) {
|
||||
if(!$search && !$zip && !$search_cluster_id) {
|
||||
return mfResponse::BadRequest(['message' => "Searchstring cannot be empty!"]);
|
||||
}
|
||||
|
||||
@@ -116,11 +214,16 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
}
|
||||
|
||||
$zip_search = ['plzstring%' => $zip];
|
||||
|
||||
//var_dump($this->filter_salescluster_ids);exit;
|
||||
if(count($this->filter_salescluster_ids)) {
|
||||
$zip_search['netzgebiet_id'] = $this->filter_salescluster_ids;
|
||||
}
|
||||
|
||||
if($search_cluster_id) {
|
||||
$zip_search['netzgebiet_extref'] = $search_cluster_id;
|
||||
}
|
||||
|
||||
//var_dump($zip_search);exit;
|
||||
$results = ADBPlzModel::search($zip_search);
|
||||
|
||||
|
||||
@@ -138,12 +241,13 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
$get = array_merge($this->post, $this->get);
|
||||
|
||||
// search parameter is unofficially deprecated but still supported
|
||||
$search = trim($get['search']);
|
||||
$street = trim($get['street']);
|
||||
$city = trim($get['city']);
|
||||
$zip = trim($get['zip']);
|
||||
$search = $this->db()->escape(trim($get['search']));
|
||||
$street = $this->db()->escape(trim($get['street']));
|
||||
$city = $this->db()->escape(trim($get['city']));
|
||||
$zip = $this->db()->escape(trim($get['zip']));
|
||||
$search_cluster_id = $this->db()->escape(trim($get['cluster_id']));
|
||||
|
||||
if(!$search && !$street && !$city && !$zip) {
|
||||
if(!$search && !$street && !$city && !$zip && !$search_cluster_id) {
|
||||
return mfResponse::BadRequest(['message' => "No search parameters"]);
|
||||
}
|
||||
|
||||
@@ -151,24 +255,37 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
$street = $search;
|
||||
}
|
||||
|
||||
$street_search = ["name%" => $street];
|
||||
$where = "1=1";
|
||||
$where .= " AND strasse like '$street%'";
|
||||
if($city) {
|
||||
$street_search['gemeinde%'] = $city;
|
||||
if($this->district_is_city) {
|
||||
$where .= " AND ortschaft like '$city%'";
|
||||
} else {
|
||||
$where .= " AND gemeinde like '$city%'";
|
||||
}
|
||||
}
|
||||
if($zip) {
|
||||
$street_search['plz%'] = $zip;
|
||||
$where .= " AND plz like '$zip%'";
|
||||
}
|
||||
|
||||
if(count($this->filter_salescluster_ids)) {
|
||||
$street_search['netzgebiet_id'] = $this->filter_salescluster_ids;
|
||||
$where .= " AND netzgebiet_id IN (".join(", ", $this->filter_salescluster_ids).")";
|
||||
}
|
||||
|
||||
$results = ADBStrasseModel::search($street_search);
|
||||
|
||||
if($search_cluster_id) {
|
||||
$where .= " AND netzgebiet_extref='$search_cluster_id'";
|
||||
}
|
||||
|
||||
$streets = [];
|
||||
foreach($results as $result) {
|
||||
$streets[] = $result->name;
|
||||
|
||||
$sql = "SELECT strasse FROM view_hausnummer WHERE $where GROUP BY strasse ORDER BY strasse";
|
||||
//echo "$sql";exit;
|
||||
$res = $this->db()->query($sql);
|
||||
if($this->db()->num_rows($res)) {
|
||||
while($data = $this->db()->fetch_object($res)) {
|
||||
$streets[] = $data->strasse;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$streets = array_unique($streets);
|
||||
@@ -176,17 +293,396 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
return mfResponse::Ok(['streets' => array_values($streets)]);
|
||||
}
|
||||
|
||||
protected function search() {
|
||||
$get = array_merge($this->post, $this->get);
|
||||
|
||||
$search = $this->db()->escape(trim($get['search']));
|
||||
|
||||
$format = "flat";
|
||||
if($get['format'] == "tree") {
|
||||
$format = "tree";
|
||||
}
|
||||
|
||||
if(!$search) {
|
||||
return mfResponse::BadRequest(['message' => "Search string cannot be empty"]);
|
||||
}
|
||||
if($search == "%") {
|
||||
return mfResponse::BadRequest(['message' => "Search string cannot be empty"]);
|
||||
}
|
||||
|
||||
/*
|
||||
* try direct search
|
||||
*/
|
||||
/*$m = [];
|
||||
if(preg_match('/^([^,]+)\s+(\d+\w+),\s*(\d+),?\s*(.+)$/', $search, $m)) {
|
||||
if($m[1] && $m[2] && $m[3] && $m[4]) {
|
||||
$dsearch['Strasse.name'] = $this->db()->escape(trim($m[1]));
|
||||
$dsearch['Hausnummer.hausnummer'] = $this->db()->escape(trim($m[2]));
|
||||
$dsearch['Plz.plz'] = $this->db()->escape(trim($m[3]));
|
||||
if($this->district_is_city) {
|
||||
$dsearch['Ortschaft.name'] = $this->db()->escape(trim($m[4]));
|
||||
} else {
|
||||
$dsearch['Gemeinde.name'] = $this->db()->escape(trim($m[4]));
|
||||
}
|
||||
|
||||
$where = "1=1";
|
||||
if(count($this->filter_salescluster_ids)) {
|
||||
$where .= " AND netzgebiet_id IN (".implode(",", $this->filter_salescluster_ids).")";
|
||||
}
|
||||
foreach($dsearch as $field => $value) {
|
||||
$where .= " AND $field = '$value'";
|
||||
}
|
||||
|
||||
$sql = AddressDB::$wohneinheit_query;
|
||||
$sql .= "\n WHERE $where";
|
||||
$this->log->debug($sql);
|
||||
|
||||
$res = $this->db()->query($sql);
|
||||
|
||||
if($this->db()->num_rows($res)) {
|
||||
$address = [];
|
||||
$units = [];
|
||||
$hausnummer_id = false;
|
||||
while($data = $this->db()->fetch_object($res)) {
|
||||
if(!$hausnummer_id) {
|
||||
$hausnummer_id = $data->hausnummer_id;
|
||||
|
||||
// get allowed preorderTypes
|
||||
$ptypes = [];
|
||||
if($data->freigabe) {
|
||||
$freigaben = json_decode($data->freigabe);
|
||||
if(is_array($freigaben) && count($freigaben)) {
|
||||
foreach($freigaben as $freigabe) {
|
||||
if(in_array($freigabe, $this->allowed_preordertypes)) {
|
||||
$ptypes[] = $freigabe;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$housenumber = $data->hausnummer;
|
||||
if($this->hausnummer_add_zusatz) {
|
||||
if($data->zusatz) {
|
||||
$housenumber .= " (".$data->zusatz.")";
|
||||
}
|
||||
}
|
||||
|
||||
$address = [
|
||||
'oaid' => $data->hausnummer_oaid,
|
||||
'cluster_id' => $data->netzgebiet_extref,
|
||||
'zip' => $data->plz,
|
||||
'city' => $data->gemeinde,
|
||||
"municipality" => "",
|
||||
'district' => $data->ortschaft,
|
||||
'street' => $data->strasse,
|
||||
'housenumber' => $housenumber,
|
||||
'lot_number' => $data->grund_nr,
|
||||
'building_unit_count' => 0,
|
||||
'gps_lat' => ($data->gps_lat) ? (float)$data->gps_lat : null,
|
||||
'gps_long' => ($data->gps_long) ? (float)$data->gps_long : null,
|
||||
'rollout_year' => ($data->rollout) ? (int)$data->rollout : null,
|
||||
'rollout_info' => $data->rollout_info,
|
||||
'preorderTypes' => $ptypes,
|
||||
'units' => []
|
||||
];
|
||||
if($this->district_is_city) {
|
||||
$address['city'] = $data->ortschaft;
|
||||
$address['municipality'] = $data->gemeinde;
|
||||
} else {
|
||||
unset($address['municipality']);
|
||||
}
|
||||
}
|
||||
if($hausnummer_id && $hausnummer_id != $data->hausnummer_id) {
|
||||
$address = [];
|
||||
break;
|
||||
}
|
||||
|
||||
$units[] = [
|
||||
'oaid' => $data->wohneinheit_oaid,
|
||||
'num' => (int)$data->num,
|
||||
'block' => $data->block,
|
||||
'stiege' => $data->stiege,
|
||||
'stock' => $data->stock,
|
||||
'tuer' => $data->tuer,
|
||||
'zusatz' => $data->zusatz,
|
||||
];
|
||||
}
|
||||
//var_dump($address, $units);exit;
|
||||
$new_addresses = [];
|
||||
if($address) {
|
||||
if($format == "tree") {
|
||||
$new_address = $address;
|
||||
$new_address['units'] = $units;
|
||||
$new_addresses[] = $address;
|
||||
} else {
|
||||
foreach($units as $unit) {
|
||||
$new_address = $address;
|
||||
unset($new_address['units']);
|
||||
$new_address['building_unit_count'] = count($units);
|
||||
$new_address['num'] = $unit['num'];
|
||||
$new_address['block'] = $unit['block'];
|
||||
$new_address['stiege'] = $unit['stiege'];
|
||||
$new_address['stock'] = $unit['stock'];
|
||||
$new_address['tuer'] = $unit['tuer'];
|
||||
$new_address['zusatz'] = $unit['zusatz'];
|
||||
$new_addresses[] = $new_address;
|
||||
}
|
||||
}
|
||||
|
||||
return mfResponse::Ok(['addresses' => $new_addresses]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
/*
|
||||
* do normal search
|
||||
*/
|
||||
$search_parts = [];
|
||||
$search = str_replace(",", "", $search);
|
||||
$tmp_search_parts = explode(" ", $search);
|
||||
$ort_search = $strasse_search = $plz_search = $hausnummer_search = [];
|
||||
|
||||
foreach($tmp_search_parts as $p) {
|
||||
$p = $this->db()->escape(trim($p));
|
||||
if(!$p) continue;
|
||||
if(in_array($p,$search_parts)) continue;
|
||||
$search_parts[] = $p;
|
||||
$gem_search[] = "Gemeinde.name like '$p%'";
|
||||
$ort_search[] = "Ortschaft.name like '$p%'";
|
||||
$strasse_search[] = "Strasse.name like '$p%'";
|
||||
$plz_search[] = "Plz.plz like '$p%'";
|
||||
$hausnummer_search[] = "Hausnummer.hausnummer like '$p%'";
|
||||
}
|
||||
|
||||
$where = "1=1";
|
||||
if(count($this->filter_salescluster_ids)) {
|
||||
$where .= " AND netzgebiet_id IN (".implode(",", $this->filter_salescluster_ids).")";
|
||||
}
|
||||
|
||||
$sql = AddressDB::$wohneinheit_query;
|
||||
$sql .= "\n WHERE $where AND ((".implode(" OR ", $ort_search).") OR (".implode(" OR ", $strasse_search).") OR (".implode(" OR ", $plz_search).") OR (".implode(" OR ", $hausnummer_search).")) ORDER BY strasse, LENGTH(hausnummer), hausnummer, LENGTH(tuer),tuer, zusatz, LENGTH(num), num";
|
||||
|
||||
//$sql = "SELECT * FROM view_wohneinheit WHERE $where AND ((".implode(" OR ", $ort_search).") OR (".implode(" OR ", $strasse_search).") OR (".implode(" OR ", $plz_search).") OR (".implode(" OR ", $hausnummer_search).")) ORDER BY strasse, LENGTH(hausnummer), hausnummer, LENGTH(tuer),tuer, zusatz, LENGTH(num), num";
|
||||
$this->log->debug($sql);
|
||||
|
||||
$res = $this->db()->query($sql);
|
||||
|
||||
|
||||
|
||||
if($this->db()->num_rows($res)) {
|
||||
$tmp_addresses = [];
|
||||
while($data = $this->db()->fetch_object($res)) {
|
||||
$address_key = $data->hausnummer_id;
|
||||
if($this->hausnummer_add_zusatz) {
|
||||
$address_key = $data->hausnummer_id."-".$data->zusatz;
|
||||
}
|
||||
//$sort_key = $data->plz." ".$data->gemeinde." ".$data->ortschaft." ".$data->strasse." ".$data->hausnummer." ".$data->zusatz;
|
||||
$sort_key = $data->plz." ".$data->gemeinde." ".$data->ortschaft." ".$data->strasse." ".$data->hausnummer." ".$data->zusatz;
|
||||
if(!array_key_exists($address_key, $tmp_addresses)) {
|
||||
|
||||
// get allowed preorderTypes
|
||||
$ptypes = [];
|
||||
if($data->freigabe) {
|
||||
$freigaben = json_decode($data->freigabe);
|
||||
if(is_array($freigaben) && count($freigaben)) {
|
||||
foreach($freigaben as $freigabe) {
|
||||
if(in_array($freigabe, $this->allowed_preordertypes)) {
|
||||
$ptypes[] = $freigabe;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$housenumber = $data->hausnummer;
|
||||
if($this->hausnummer_add_zusatz) {
|
||||
if($data->zusatz) {
|
||||
$housenumber .= " (".$data->zusatz.")";
|
||||
}
|
||||
}
|
||||
|
||||
$tmp_addresses[$address_key] = [
|
||||
'sort_key' => $sort_key,
|
||||
'oaid' => $data->hausnummer_oaid,
|
||||
'cluster_id' => $data->netzgebiet_extref,
|
||||
'zip' => $data->plz,
|
||||
'city' => $data->gemeinde,
|
||||
"municipality" => "",
|
||||
'district' => $data->ortschaft,
|
||||
'street' => $data->strasse,
|
||||
'housenumber' => $housenumber,
|
||||
'lot_number' => $data->grund_nr,
|
||||
'building_unit_count' => 0,
|
||||
'gps_lat' => ($data->gps_lat) ? (float)$data->gps_lat : null,
|
||||
'gps_long' => ($data->gps_long) ? (float)$data->gps_long : null,
|
||||
'rollout_year' => ($data->rollout) ? (int)$data->rollout : null,
|
||||
'rollout_info' => $data->rollout_info,
|
||||
'preorderTypes' => $ptypes,
|
||||
'units' => []
|
||||
];
|
||||
if($this->district_is_city) {
|
||||
$tmp_addresses[$address_key]['city'] = $data->ortschaft;
|
||||
$tmp_addresses[$address_key]['municipality'] = $data->gemeinde;
|
||||
} else {
|
||||
unset($tmp_addresses[$address_key]['municipality']);
|
||||
}
|
||||
}
|
||||
|
||||
$tmp_addresses[$address_key]['units'][] = [
|
||||
'oaid' => $data->wohneinheit_oaid,
|
||||
'num' => (int)$data->num,
|
||||
'block' => $data->block,
|
||||
'stiege' => $data->stiege,
|
||||
'stock' => $data->stock,
|
||||
'tuer' => $data->tuer,
|
||||
'zusatz' => $data->zusatz,
|
||||
];
|
||||
$tmp_addresses[$address_key]['building_unit_count']++;
|
||||
//if($data->hausnummer_oaid == "AT-8940-30400d5c") var_dump($data);
|
||||
}
|
||||
//exit;
|
||||
//var_dump($tmp_addresses);exit;
|
||||
// sort found addresses by count of found keywords
|
||||
// if there is an int we don't want to show more than one street
|
||||
$sorted_addresses = [];
|
||||
foreach($tmp_addresses as $temp_add) {
|
||||
$includes_int = false;
|
||||
$count = 0;
|
||||
$count_parts = 0;
|
||||
$uniq_parts_count = 0;
|
||||
$uniq_parts_found = [];
|
||||
/*if($temp_add['oaid'] == "AT-8940-30400d5c") {
|
||||
var_dump($temp_add);
|
||||
}*/
|
||||
foreach($search_parts as $p) {
|
||||
$p = $this->db->escape(trim($p));
|
||||
if(strlen($p) === 0) continue;
|
||||
$uniq_parts_count++;
|
||||
if(is_numeric(($p))) {
|
||||
$includes_int = true;
|
||||
$count_parts++;
|
||||
if(substr_count(strtolower($temp_add['sort_key']), strtolower($p))) {
|
||||
$count++;
|
||||
}
|
||||
if(!in_array($p, $uniq_parts_found)) {
|
||||
$uniq_parts_found[] = $p;
|
||||
}
|
||||
} else {
|
||||
$p_count = substr_count(strtolower($temp_add['sort_key']), strtolower($p));
|
||||
if($p_count) {
|
||||
$count += $p_count;
|
||||
$count_parts++;
|
||||
if(!in_array($p, $uniq_parts_found)) {
|
||||
$uniq_parts_found[] = $p;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($temp_add['sort_key']);
|
||||
if($includes_int && (($count + 1) - count($search_parts) ) < 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//var_dump(count($search_parts), $count, $count_parts, $temp_add);
|
||||
|
||||
/*if($temp_add['oaid'] == "AT-8954-d6c41665") {
|
||||
echo $temp_add['sort_key'].": AT-8954-d6c41665: count $count; uniq_parts_count $uniq_parts_count; count_parts $count_parts; search_parts ".count($search_parts)."<br /><br />\n";
|
||||
//var_dump();
|
||||
//exit;
|
||||
}*/
|
||||
|
||||
if($count_parts == count($search_parts)) {
|
||||
$count += 50;
|
||||
}
|
||||
|
||||
if($uniq_parts_count <= count($uniq_parts_found)) {
|
||||
if(!array_key_exists($count, $sorted_addresses)) {
|
||||
$sorted_addresses[$count] = [];
|
||||
}
|
||||
$sorted_addresses[$count][] = $temp_add;
|
||||
}
|
||||
}
|
||||
//exit;
|
||||
|
||||
|
||||
ksort($sorted_addresses, SORT_NUMERIC);
|
||||
$sorted_addresses = array_reverse($sorted_addresses, true);
|
||||
//var_dump($sorted_addresses);exit;
|
||||
|
||||
// sort / format
|
||||
if($format == "tree") {
|
||||
foreach($sorted_addresses as $counted_addresses) {
|
||||
foreach($counted_addresses as $cadd) {
|
||||
$addresses[] = $cadd;
|
||||
}
|
||||
}
|
||||
//var_dump($addresses);exit;
|
||||
//$addresses = array_values($sorted_addresses);
|
||||
|
||||
if(!$addresses) $addresses = [];
|
||||
} else {
|
||||
foreach($sorted_addresses as $counted_addresses) {
|
||||
foreach($counted_addresses as $ta) {
|
||||
foreach($ta['units'] as $u) {
|
||||
$new_address = [];
|
||||
$new_address['oaid'] = $u['oaid'];
|
||||
$new_address['building_oaid'] = $ta['oaid'];
|
||||
$new_address['cluster_id'] = $ta['cluster_id'];
|
||||
$new_address['street'] = $ta['street'];
|
||||
$new_address['housenumber'] = $ta['housenumber'];
|
||||
$new_address['zip'] = $ta['zip'];
|
||||
$new_address['city'] = $ta['city'];
|
||||
if(array_key_exists("municipality", $ta)) {
|
||||
$new_address['municipality'] = $ta['municipality'];
|
||||
}
|
||||
$new_address['district'] = $ta['district'];
|
||||
$new_address['lot_number'] = $ta['lot_number'];
|
||||
$new_address['building_unit_count'] = $ta['building_unit_count'];
|
||||
$new_address['num'] = $u['num'];
|
||||
$new_address['block'] = $u['block'];
|
||||
$new_address['stiege'] = $u['stiege'];
|
||||
$new_address['stock'] = $u['stock'];
|
||||
$new_address['tuer'] = $u['tuer'];
|
||||
$new_address['zusatz'] = $u['zusatz'];
|
||||
$new_address['gps_lat'] = $ta['gps_lat'];
|
||||
$new_address['gps_long'] = $ta['gps_long'];
|
||||
$new_address['rollout_year'] = $ta['rollout_year'];
|
||||
$new_address['rollout_info'] = $ta['rollout_info'];
|
||||
$new_address['preorderTypes'] = $ta['preorderTypes'];
|
||||
|
||||
$addresses[] = $new_address;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return mfResponse::Ok(['addresses' => $addresses]);
|
||||
}
|
||||
|
||||
protected function find() {
|
||||
// unofficially supporting GET and POST in v1
|
||||
$get = array_merge($this->post, $this->get);
|
||||
|
||||
$search_cluster_id = $this->db()->escape(trim($get['cluster_id']));
|
||||
$search_street = $this->db()->escape(trim($get['street']));
|
||||
$search_zip = $this->db()->escape(trim($get['zip']));
|
||||
$search_district = $this->db()->escape(trim($get['district']));
|
||||
$search_city = $this->db()->escape(trim($get['city']));
|
||||
$search_housenumber = $this->db()->escape(trim($get['housenumber']));
|
||||
|
||||
$format = "flat";
|
||||
if($get['format'] == "tree") {
|
||||
$format = "tree";
|
||||
}
|
||||
|
||||
if(!$search_street) {
|
||||
if(!$search_street && !$search_cluster_id) {
|
||||
return mfResponse::BadRequest(['message' => "Searchstring cannot be empty!"]);
|
||||
}
|
||||
|
||||
@@ -194,54 +690,148 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
|
||||
$where = "1=1";
|
||||
|
||||
if($search_zip) {
|
||||
$where .= " AND plz like '%$search_zip%'";
|
||||
if($search_zip && $search_zip != "%") {
|
||||
$where .= " AND Plz.plz like '$search_zip%'";
|
||||
}
|
||||
if($search_city) {
|
||||
$where .= " AND gemeinde like '%$search_city%'";
|
||||
if($search_district && $search_district != "%") {
|
||||
$where .= " AND Ortschaft.name like '$search_district%'";
|
||||
}
|
||||
if($search_street) {
|
||||
$where .= " AND strasse like '%$search_street%'";
|
||||
if($search_city && $search_city != "%") {
|
||||
if($this->district_is_city) {
|
||||
$where .= " AND Ortschaft.name like '$search_city%'";
|
||||
} else {
|
||||
$where .= " AND Gemeinde.name like '$search_city%'";
|
||||
}
|
||||
}
|
||||
if($search_housenumber) {
|
||||
$where .= " AND hausnummer like '%$search_housenumber%'";
|
||||
if($search_street && $search_street != "%") {
|
||||
$where .= " AND Strasse.name like '$search_street%'";
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM view_wohneinheit WHERE $where ORDER BY plz, gemeinde, ortschaft, strasse, LENGTH(hausnummer), hausnummer, block, stiege, stock, LENGTH(tuer), tuer";
|
||||
if($search_housenumber && $search_housenumber != "%") {
|
||||
$where .= " AND Hausnummer.hausnummer like '$search_housenumber%'";
|
||||
}
|
||||
|
||||
if(count($this->filter_salescluster_ids)) {
|
||||
$where .= " AND Hausnummer.netzgebiet_id IN (".implode(",", $this->filter_salescluster_ids).")";
|
||||
}
|
||||
if($search_cluster_id) {
|
||||
$where .= " AND Netzgebiet.extref='$search_cluster_id'";
|
||||
}
|
||||
//echo $where;
|
||||
//var_dump($this->filter_salescluster_ids);exit;
|
||||
|
||||
$sql = AddressDB::$wohneinheit_query;
|
||||
$sql .= "\n WHERE $where ORDER BY plz, gemeinde, ortschaft, strasse, LENGTH(hausnummer), hausnummer, block, stiege, stock, LENGTH(num), num, LENGTH(tuer), tuer";
|
||||
|
||||
//$sql = "SELECT * FROM view_wohneinheit WHERE $where ORDER BY plz, gemeinde, ortschaft, strasse, LENGTH(hausnummer), hausnummer, block, stiege, stock, LENGTH(num), num, LENGTH(tuer), tuer";
|
||||
$this->log->debug($sql);
|
||||
$res = $this->db()->query($sql);
|
||||
|
||||
if($this->db()->num_rows($res)) {
|
||||
while($data = $this->db()->fetch_object($res)) {
|
||||
|
||||
// get allowed preorderTypes
|
||||
$ptypes = [];
|
||||
if($data->freigabe) {
|
||||
$freigaben = json_decode($data->freigabe);
|
||||
if(is_array($freigaben) && count($freigaben)) {
|
||||
foreach($freigaben as $freigabe) {
|
||||
if(in_array($freigabe, $this->allowed_preordertypes)) {
|
||||
$ptypes[] = $freigabe;
|
||||
$tmp_addresses = [];
|
||||
while($data = $this->db()->fetch_object($res)) {
|
||||
$address_key = $data->hausnummer_id;
|
||||
if($this->hausnummer_add_zusatz) {
|
||||
$address_key = $data->hausnummer_id."-".$data->zusatz;
|
||||
}
|
||||
if(!array_key_exists($address_key, $tmp_addresses)) {
|
||||
|
||||
// get allowed preorderTypes
|
||||
$ptypes = [];
|
||||
if($data->freigabe) {
|
||||
$freigaben = json_decode($data->freigabe);
|
||||
if(is_array($freigaben) && count($freigaben)) {
|
||||
foreach($freigaben as $freigabe) {
|
||||
if(in_array($freigabe, $this->allowed_preordertypes)) {
|
||||
$ptypes[] = $freigabe;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$housenumber = $data->hausnummer;
|
||||
if($this->hausnummer_add_zusatz) {
|
||||
if($data->zusatz) {
|
||||
$housenumber .= " (".$data->zusatz.")";
|
||||
}
|
||||
}
|
||||
|
||||
$tmp_addresses[$address_key] = [
|
||||
'oaid' => $data->hausnummer_oaid,
|
||||
'cluster_id' => $data->netzgebiet_extref,
|
||||
'zip' => $data->plz,
|
||||
'city' => $data->gemeinde,
|
||||
"municipality" => "",
|
||||
'district' => $data->ortschaft,
|
||||
'street' => $data->strasse,
|
||||
'housenumber' => $housenumber,
|
||||
'lot_number' => $data->grund_nr,
|
||||
'building_unit_count' => 0,
|
||||
'gps_lat' => ($data->gps_lat) ? (float)$data->gps_lat : null,
|
||||
'gps_long' => ($data->gps_long) ? (float)$data->gps_long : null,
|
||||
'rollout_year' => ($data->rollout) ? (int)$data->rollout : null,
|
||||
'rollout_info' => $data->rollout_info,
|
||||
'preorderTypes' => $ptypes,
|
||||
'units' => []
|
||||
];
|
||||
if($this->district_is_city) {
|
||||
$tmp_addresses[$address_key]['city'] = $data->ortschaft;
|
||||
$tmp_addresses[$address_key]['municipality'] = $data->gemeinde;
|
||||
} else {
|
||||
unset($tmp_addresses[$address_key]['municipality']);
|
||||
}
|
||||
}
|
||||
|
||||
$tmp_addresses[$address_key]['units'][] = [
|
||||
'oaid' => $data->wohneinheit_oaid,
|
||||
'num' => (int)$data->num,
|
||||
'block' => $data->block,
|
||||
'stiege' => $data->stiege,
|
||||
'stock' => $data->stock,
|
||||
'tuer' => $data->tuer,
|
||||
'zusatz' => $data->zusatz,
|
||||
];
|
||||
$tmp_addresses[$address_key]['building_unit_count']++;
|
||||
|
||||
}
|
||||
if($format == "tree") {
|
||||
/*foreach($tmp_addresses as $ta) {
|
||||
$addresses[] = $ta;
|
||||
}*/
|
||||
$addresses = array_values($tmp_addresses);
|
||||
} else {
|
||||
foreach($tmp_addresses as $ta) {
|
||||
foreach($ta['units'] as $u) {
|
||||
$new_address = [];
|
||||
$new_address['oaid'] = $u['oaid'];
|
||||
$new_address['building_oaid'] = $ta['oaid'];
|
||||
$new_address['cluster_id'] = $ta['cluster_id'];
|
||||
$new_address['street'] = $ta['street'];
|
||||
$new_address['housenumber'] = $ta['housenumber'];
|
||||
$new_address['zip'] = $ta['zip'];
|
||||
$new_address['city'] = $ta['city'];
|
||||
if(array_key_exists("municipality", $ta)) {
|
||||
$new_address['municipality'] = $ta['municipality'];
|
||||
}
|
||||
$new_address['district'] = $ta['district'];
|
||||
$new_address['lot_number'] = $ta['lot_number'];
|
||||
$new_address['building_unit_count'] = $ta['building_unit_count'];
|
||||
$new_address['num'] = $u['num'];
|
||||
$new_address['block'] = $u['block'];
|
||||
$new_address['stiege'] = $u['stiege'];
|
||||
$new_address['stock'] = $u['stock'];
|
||||
$new_address['tuer'] = $u['tuer'];
|
||||
$new_address['zusatz'] = $u['zusatz'];
|
||||
$new_address['gps_lat'] = $ta['gps_lat'];
|
||||
$new_address['gps_long'] = $ta['gps_long'];
|
||||
$new_address['rollout_year'] = $ta['rollout_year'];
|
||||
$new_address['rollout_info'] = $ta['rollout_info'];
|
||||
$new_address['preorderTypes'] = $ta['preorderTypes'];
|
||||
|
||||
$addresses[] = $new_address;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$addresses[] = [
|
||||
'zip' => $data->plz,
|
||||
'city' => $data->gemeinde,
|
||||
'street' => $data->strasse,
|
||||
'housenumber' => $data->hausnummer,
|
||||
'block' => $data->block,
|
||||
'stock' => $data->stock,
|
||||
'stiege' => $data->stiege,
|
||||
'tuer' => $data->tuer,
|
||||
'zusatz' => $data->zusatz,
|
||||
'gps_lat' => $data->gps_lat,
|
||||
'gps_long' => $data->gps_long,
|
||||
'rollout_year' => ($data->rollout) ? (int)$data->rollout : null,
|
||||
'preorderTypes' => $ptypes
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return mfResponse::Ok(['addresses' => $addresses]);
|
||||
|
||||
@@ -10,12 +10,18 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
private $campaigns_by_scluster = [];
|
||||
|
||||
private $allowed_preordertypes = [];
|
||||
|
||||
private $district_is_city = false;
|
||||
private $hausnummer_add_zusatz = false;
|
||||
private $exist_is_error = false;
|
||||
private $require_connectiontype = false;
|
||||
private $allow_unit_update = false;
|
||||
|
||||
protected function init() {
|
||||
$db = $this->db(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$this->addRoute("/preorder", "submitPreorder", "POST");
|
||||
$this->addRoute("/preorder/:code", "getPreorder", "GET");
|
||||
$this->addRoute("/preorder/:code", "cancelPreorder", "DELETE");
|
||||
|
||||
$this->allowMissingOrigin = true;
|
||||
}
|
||||
@@ -42,7 +48,26 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
$this->allowed_preordertypes[] = $type->type;
|
||||
}
|
||||
}
|
||||
|
||||
if($campaign->district_is_city == 1) {
|
||||
$this->district_is_city = true;
|
||||
}
|
||||
if($campaign->hausnummer_add_zusatz == 1) {
|
||||
$this->hausnummer_add_zusatz = true;
|
||||
}
|
||||
if($campaign->exist_is_error == 1) {
|
||||
$this->exist_is_error = true;
|
||||
}
|
||||
if($campaign->require_connectiontype == 1) {
|
||||
$this->require_connectiontype = true;
|
||||
}
|
||||
if($campaign->allow_unit_update == 1) {
|
||||
$this->allow_unit_update = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
foreach(PreordercampaignOriginhostnameModel::search(['preordercampaign_id' => $campaign->id]) as $origin) {
|
||||
$this->addAllowedOrigin($origin->hostname);
|
||||
@@ -54,7 +79,76 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
//var_dump($campaign, $this->allowed_origins);exit;
|
||||
}
|
||||
|
||||
protected function getPreorder($code) {
|
||||
$code = trim(strtoupper($code));
|
||||
if(!$code) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
}
|
||||
|
||||
$preorder = PreorderModel::getFirst(['ucode' => $code]);
|
||||
if(!$preorder) {
|
||||
// try oan id
|
||||
$preorder = PreorderModel::getFirst(['oaid' => $code]);
|
||||
if(!$preorder) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
}
|
||||
}
|
||||
|
||||
if($preorder->partner_id != $this->me->address_id) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
}
|
||||
|
||||
$return = $preorder->getApiArray();
|
||||
if(!$return) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
}
|
||||
|
||||
|
||||
return mfResponse::Ok($return);
|
||||
|
||||
}
|
||||
|
||||
protected function cancelPreorder($code) {
|
||||
$code = trim(strtoupper($code));
|
||||
if(!$code) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
}
|
||||
|
||||
$preorder = PreorderModel::getFirst(['ucode' => $code, 'partner_id' => $this->me->address_id, 'deleted' => 0, '<status_code' => 800]);
|
||||
if(!$preorder) {
|
||||
// try oan id
|
||||
$preorder = PreorderModel::getFirst(['oaid' => $code, 'partner_id' => $this->me->address_id, 'deleted' => 0, '<status_code' => 800]);
|
||||
if(!$preorder) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found or cancelled already"]);
|
||||
}
|
||||
}
|
||||
|
||||
// check if user owns preorder
|
||||
if($preorder->partner_id != $this->me->address_id) {
|
||||
return mfResponse::Forbidden(["message" => "Permission denied"]);
|
||||
}
|
||||
|
||||
if($preorder->cancel_request) {
|
||||
if($preorder->cancel_approved) {
|
||||
return mfResponse::Forbidden(["message" => "Order already cancelled"]);
|
||||
} else {
|
||||
return mfResponse::Forbidden(["message" => "Cancellation request was already submitted"]);
|
||||
}
|
||||
}
|
||||
|
||||
// set cancel_date and canceller
|
||||
$preorder->cancel_request = date('U');
|
||||
$preorder->cancel_request_by = $this->me->id;
|
||||
if(!$preorder->save()) {
|
||||
return mfResponse::InternalServerError();
|
||||
}
|
||||
|
||||
return mfResponse::Ok(['message' => "Cancellation request submited"]);
|
||||
|
||||
}
|
||||
|
||||
protected function submitPreorder() {
|
||||
//var_dump($this->post);exit;
|
||||
if(!$this->campaigns) {
|
||||
$this->log->debug("disallowed request because no campaign for apikey");
|
||||
return mfResponse::Forbidden();
|
||||
@@ -65,7 +159,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
return mfResponse::BadRequest(["message" => "Invalid preorderType"]);
|
||||
}
|
||||
|
||||
$connection_type = false;
|
||||
$connection_type = null;
|
||||
switch($this->post['connectionType']) {
|
||||
case "single-dwelling":
|
||||
$connection_type = "single-dwelling";
|
||||
@@ -83,7 +177,9 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
$connection_type = "business";
|
||||
break;
|
||||
default:
|
||||
return mfResponse::BadRequest(["message" => "Invalid connectionType"]);
|
||||
if($this->require_connectiontype) {
|
||||
return mfResponse::BadRequest(["message" => "Invalid connectionType"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +191,12 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
return mfResponse::BadRequest(['message' => "customer data missing"]);
|
||||
}
|
||||
|
||||
/*
|
||||
$is_additional_order = false;
|
||||
if(array_key_exists("isAdditionalOrder", $this->post) && $this->post['isAdditionalOrder']) {
|
||||
$is_additional_order = true;
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* check address
|
||||
*/
|
||||
if(!property_exists($this->post['address'],"street") || !$this->post['address']->street ||
|
||||
@@ -106,20 +207,48 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
return mfResponse::BadRequest(['message' => "Mandatory address fields missing"]);
|
||||
}
|
||||
|
||||
$shipping_address = "customer";
|
||||
if(property_exists($this->post['address'], "is_shipping") && $this->post['address']->is_shipping) {
|
||||
$shipping_address = "address";
|
||||
}
|
||||
|
||||
$address_search = [];
|
||||
foreach(['street' => 'strasse','housenumber' => "hausnummer",'zip' => "plz",'city' => "gemeinde"] as $key => $field_name) {
|
||||
$address_search_fields = [
|
||||
'street' => 'strasse',
|
||||
'housenumber' => "hausnummer",
|
||||
'zip' => "plz"
|
||||
];
|
||||
if($this->district_is_city) {
|
||||
$address_search_fields['city'] = "ortschaft";
|
||||
} else {
|
||||
$address_search_fields['city'] = "gemeinde";
|
||||
}
|
||||
|
||||
foreach($address_search_fields as $key => $field_name) {
|
||||
if(property_exists($this->post['address'], $key)) {
|
||||
$address_search[$field_name] = $this->db()->escape(trim($this->post['address']->$key));
|
||||
}
|
||||
}
|
||||
|
||||
$zusatz = false;
|
||||
if($this->hausnummer_add_zusatz) {
|
||||
$m = [];
|
||||
if(preg_match('/^(.*) \((.+)\)$/', trim($address_search['hausnummer']), $m)) {
|
||||
$address_search['hausnummer'] = $this->db()->escape($m[1]);
|
||||
$zusatz = $m[2];
|
||||
}
|
||||
}
|
||||
|
||||
$unit_search = [];
|
||||
foreach(['block','stiege','stock','tuer'] as $key) {
|
||||
foreach(['block','stiege','stock','tuer','unit_string'] as $key) {
|
||||
if(property_exists($this->post['address'], $key) && trim($this->post['address']->$key)) {
|
||||
$unit_search[$key] = trim($this->post['address']->$key);
|
||||
}
|
||||
}
|
||||
|
||||
if($zusatz) {
|
||||
$unit_search['zusatz'] = $zusatz;
|
||||
}
|
||||
|
||||
/*
|
||||
* check customer
|
||||
*/
|
||||
@@ -134,7 +263,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
return mfResponse::BadRequest(['message' => "Mandatory customer fields missing"]);
|
||||
}
|
||||
|
||||
/*
|
||||
/**************************************************************
|
||||
* search address in AddressDB
|
||||
*/
|
||||
$where = "1=1 ";
|
||||
@@ -148,54 +277,83 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM view_hausnummer WHERE $where";
|
||||
$this->log->debug($sql);
|
||||
$res = $this->db()->query($sql);
|
||||
if(!$this->db()->num_rows($res)) {
|
||||
//var_dump($this->db()->num_rows($res), $this->db()->fetch_object($res));
|
||||
return mfResponse::NotFound(['message' => "Adresse nicht gefunden"]);
|
||||
}
|
||||
|
||||
$address = $this->db()->fetch_object($res);
|
||||
//var_dump($address);exit;
|
||||
|
||||
|
||||
/*
|
||||
/* **************************************************************
|
||||
* search wohneinheit
|
||||
*/
|
||||
$update_unit = false;
|
||||
$assign_unit = false;
|
||||
$where = "1=1 ";
|
||||
$unit = false;
|
||||
if(count($unit_search)) {
|
||||
foreach($unit_search as $field => $value) {
|
||||
if($field == "stock" || $field == "stiege") continue; // only check for block and tuer
|
||||
$where .= " AND `$field` = '$value'";
|
||||
//var_dump($unit_search);exit;
|
||||
if(array_key_exists("unit_string", $unit_search)) {
|
||||
$where .= " AND bezeichner LIKE '".$unit_search['unit_string']."'";
|
||||
} else {
|
||||
foreach($unit_search as $field => $value) {
|
||||
if($field == "stock") continue; // only check for block, stiege and tuer
|
||||
$where .= " AND `$field` = '$value'";
|
||||
}
|
||||
}
|
||||
|
||||
// filter salesclusters
|
||||
if(count($this->filter_salescluster_ids)) {
|
||||
$where .= " AND netzgebiet_id IN (".implode(',', $this->filter_salescluster_ids).")";
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM view_wohneinheit WHERE 1=1 $where AND hausnummer_id=".$address->hausnummer_id;
|
||||
$sql = "SELECT * FROM view_wohneinheit WHERE $where AND hausnummer_id=".$address->hausnummer_id;
|
||||
$this->log->debug($sql);
|
||||
$res = $this->db()->query($sql);
|
||||
if($this->db()->num_rows($res)) {
|
||||
$unit = $this->db()->fetch_object($res);
|
||||
//return mfResponse::NotFound(['message' => "Wohneinheit nicht gefunden"]);
|
||||
} else {
|
||||
$update_unit = true;
|
||||
}
|
||||
//var_dump($this->db()->num_rows($res), $this->db()->fetch_object($res));
|
||||
} else {
|
||||
// if all unit values are empty try to find the unit with all empty values
|
||||
// failure is not an error, but must be checked by a human at some point
|
||||
|
||||
$where = "hausnummer_id=".$address->hausnummer_id." AND (block = '' OR block IS NULL) AND (stiege = '' OR stiege IS NULL) AND (stock = '' OR stock IS NULL) AND (tuer = '' OR tuer IS NULL)";
|
||||
$where = "hausnummer_id=".$address->hausnummer_id." AND (block = '' OR block IS NULL) AND (stiege = '' OR stiege IS NULL) AND (stock = '' OR stock IS NULL) AND (tuer = '' OR tuer IS NULL) AND (bezeichner = '' OR bezeichner IS NULL)";
|
||||
if($zusatz) {
|
||||
$where .= " AND zusatz='$zusatz'";
|
||||
} else {
|
||||
$where .= " AND (zusatz = '' OR zusatz IS NULL)";
|
||||
}
|
||||
// filter salesclusters
|
||||
if(count($this->filter_salescluster_ids)) {
|
||||
$where .= " AND netzgebiet_id IN (".implode(',', $this->filter_salescluster_ids).")";
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM view_wohneinheit WHERE $where";
|
||||
$this->log->debug($sql);
|
||||
$res = $this->db()->query($sql);
|
||||
if($this->db()->num_rows($res)) {
|
||||
$unit = $this->db()->fetch_object($res);
|
||||
} else {
|
||||
// XXX
|
||||
//$assign_unit = true;
|
||||
}
|
||||
}
|
||||
|
||||
if($this->exist_is_error && !$is_additional_order) {
|
||||
/*
|
||||
* check if there is an existing preorder for this unit already
|
||||
*/
|
||||
if($unit && $unit->wohneinheit_id) {
|
||||
$existing_preorder = PreorderModel::getFirst(['adb_wohneinheit_id' => $unit->wohneinheit_id, 'deleted' => 0]);
|
||||
if($existing_preorder) {
|
||||
return mfResponse::Forbidden(['message' => "Für diese Wohneinheit liegt bereits eine Bestellung vor"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$address_info = $this->db()->escape(trim($this->post['address_info']));
|
||||
|
||||
// get correct campaign by salescluster
|
||||
@@ -206,6 +364,10 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
$campaign_id = $this->campaigns_by_scluster[$address->netzgebiet_id];
|
||||
$this->campaign = new Preordercampaign($campaign_id);
|
||||
|
||||
if($this->campaign->from > date('U') || $this->campaign->to < date('U')) {
|
||||
return mfResponse::Forbidden(['message' => "Bestellung in diesem Netzgebiet/Cluster nicht erlaubt"]);
|
||||
}
|
||||
|
||||
/*
|
||||
* build fields
|
||||
*/
|
||||
@@ -219,13 +381,18 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
$preorder_data['submit_request'] = $this->request_json;
|
||||
}
|
||||
$preorder_data['adb_hausnummer_id'] = $address->hausnummer_id;
|
||||
$preorder_data['partner_id'] = $this->me->address_id;
|
||||
|
||||
if($unit) {
|
||||
$preorder_data['adb_wohneinheit_id'] = $unit->wohneinheit_id;
|
||||
$preorder_data['oaid'] = $unit->wohneinheit_oaid;
|
||||
}
|
||||
if($address_info) {
|
||||
$preorder_data['address_info'] = $address_info;
|
||||
}
|
||||
if(property_exists($this->post['address'],"district") && $this->post['address']->district) {
|
||||
$preorder_data['address_district'] = $this->post['address']->district;
|
||||
}
|
||||
|
||||
if($this->post['acceptAgb'] === true) {
|
||||
$preorder_data['accept_agb'] = 1;
|
||||
@@ -240,6 +407,14 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
$preorder_data['accept_withdrawal'] = 1;
|
||||
}
|
||||
|
||||
if($is_additional_order) {
|
||||
$preorder_data['is_additional_order'] = 1;
|
||||
} else {
|
||||
$preorder_data['is_additional_order'] = 0;
|
||||
}
|
||||
$preorder_data['technology'] = ($this->post['technology']) ? $this->post['technology'] : null;
|
||||
$preorder_data['patchposition'] = ($this->post['patchposition']) ? $this->post['patchposition'] : null;
|
||||
|
||||
/*
|
||||
* setup price
|
||||
*/
|
||||
@@ -281,9 +456,9 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
/*
|
||||
* get customer data
|
||||
*/
|
||||
foreach(['company','uid','firstname','lastname','street','zip','city','phone','email'] as $key) {
|
||||
foreach(['company','uid','firstname','lastname','street','housenumber','zip','city','phone','email','block','stiege','stock','tuer', 'unit_string'] as $key) {
|
||||
if(property_exists($customer, $key)) {
|
||||
$preorder_data[$key] = $customer->$key;
|
||||
$preorder_data[$key] = ($customer->$key) ? $customer->$key : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,6 +497,103 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//var_dump($this->allow_unit_update, $update_unit);exit;
|
||||
|
||||
/**************************************************
|
||||
* update wohneinheit if allowed
|
||||
* and unit search data was submitted
|
||||
*/
|
||||
|
||||
$unit_changed = false;
|
||||
|
||||
if($this->allow_unit_update && $update_unit) {
|
||||
//var_dump($unit_search);
|
||||
//var_dump($unit);
|
||||
//exit;
|
||||
|
||||
// get available units
|
||||
$exclude_wohneinheit_ids = [];
|
||||
$preorders_in_hausnummer = PreorderModel::search(['adb_hausnummer_id' => $address->hausnummer_id]);
|
||||
if(count($preorders_in_hausnummer)) {
|
||||
|
||||
foreach($preorders_in_hausnummer as $pih) {
|
||||
if($pih->adb_wohneinheit_id) {
|
||||
$exclude_wohneinheit_ids[] = $pih->adb_wohneinheit_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
// get units excluding unavailable units
|
||||
$where = "hausnummer_id=".$address->hausnummer_id;
|
||||
$where .= " AND ( block = '' OR block IS NULL)";
|
||||
$where .= " AND ( stiege = '' OR stiege IS NULL)";
|
||||
$where .= " AND ( stock = '' OR stock IS NULL)";
|
||||
$where .= " AND ( tuer = '' OR tuer IS NULL)";
|
||||
$where .= " AND ( bezeichner = '' OR bezeichner IS NULL)";
|
||||
|
||||
if(count($exclude_wohneinheit_ids)) {
|
||||
$where .= " AND wohneinheit_id NOT IN (". implode(",",$exclude_wohneinheit_ids).")";
|
||||
}
|
||||
$sql = "SELECT * FROM view_wohneinheit WHERE $where";
|
||||
$this->log->debug($sql);
|
||||
$res = $this->db()->query($sql);
|
||||
if(!$this->db()->num_rows($res)) {
|
||||
return mfResponse::Forbidden(['message' => "Keine Wohneinheiten verfügbar"]);
|
||||
}
|
||||
|
||||
$unit_row = $this->db()->fetch_object($res);
|
||||
$unit = new ADBWohneinheit($unit_row->wohneinheit_id);
|
||||
if(!$unit->id) {
|
||||
return mfResponse::InternalServerError(['message' => "unit not found"]);
|
||||
}
|
||||
//echo "blah";exit;
|
||||
|
||||
$change_note_data = [];
|
||||
foreach(['block','stiege','stock','tuer','bezeichner'] as $unit_address_part) {
|
||||
if($unit_search[$unit_address_part]) {
|
||||
$unit->$unit_address_part = $unit_search[$unit_address_part];
|
||||
$unit_changed = true;
|
||||
$change_note_data[] = [
|
||||
'field' => $unit_address_part,
|
||||
'from' => $unit->_old_data->$unit_address_part,
|
||||
'to' => $unit_search[$unit_address_part]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if($unit_changed) {
|
||||
$change_note_text = ($unit->note) ? $unit->note : "";
|
||||
$change_note_text .= date("Y-m-d H:i:s").": ";
|
||||
foreach($change_note_data as $cn) {
|
||||
$field = $cn['field'];
|
||||
$from = ($cn['from'] === null) ? "NULL" : "'".$cn['from']."'";
|
||||
$to = ($cn['to'] === null) ? "NULL" : "'".$cn['to']."'";
|
||||
$change_note_text .= "$field from $from to $to; ";
|
||||
}
|
||||
$change_note_text .= "\n";
|
||||
$unit->note = $change_note_text;
|
||||
|
||||
$unit->startTransaction();
|
||||
$unit->save();
|
||||
}
|
||||
//var_dump($unit);exit;
|
||||
|
||||
$preorder_data['adb_wohneinheit_id'] = $unit->id;
|
||||
$preorder_data['oaid'] = $unit->oaid;
|
||||
}
|
||||
|
||||
|
||||
// assign next wohneinheit if no unit search data was submitted
|
||||
/*
|
||||
if($this->allow_unit_update && $assign_unit) {
|
||||
var_dump($unit_search);
|
||||
var_dump($unit);
|
||||
exit;
|
||||
}*/
|
||||
|
||||
|
||||
/*
|
||||
* create preorder record
|
||||
*/
|
||||
@@ -331,10 +603,21 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
$preorder_id = $preorder->save();
|
||||
|
||||
if(!$preorder_id || !$preorder->ucode) {
|
||||
if($unit_changed) $unit->rollbackTransaction();
|
||||
return mfResponse::InternalServerError();
|
||||
}
|
||||
|
||||
return mfResponse::Ok(["code" => $preorder->ucode]);
|
||||
if($unit_changed) $unit->commitTransaction();
|
||||
|
||||
$return = ["code" => $preorder->ucode];
|
||||
if($preorder->oaid) {
|
||||
$return ['oaid'] = $preorder->oaid;
|
||||
}
|
||||
if($addon_data) {
|
||||
$return["additionalData"] = $addon_data;
|
||||
}
|
||||
|
||||
return mfResponse::Ok($return);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -372,14 +372,56 @@ class BuildingController extends mfBaseController {
|
||||
|
||||
private function getFilteredBuildingsApi() {
|
||||
$buildings = [];
|
||||
$filter = $this->request->filter;
|
||||
$filter = [];
|
||||
if(is_array($this->request->filter)) {
|
||||
$filter = $this->request->filter;
|
||||
}
|
||||
|
||||
if(!$this->me->is("Admin")) {
|
||||
$my_networks = $this->me->myNetworks(['netowner','salespartner']);
|
||||
|
||||
$network_ids = [];
|
||||
foreach($my_networks as $net) {
|
||||
$network_ids[] = $net->id;
|
||||
}
|
||||
|
||||
if(array_key_exists("network_id", $filter)) {
|
||||
if(!in_array($filter['network_id'], $network_ids)) {
|
||||
$filter['network_id'] = $network_ids;
|
||||
}
|
||||
} else {
|
||||
$filter['network_id'] = $network_ids;
|
||||
}
|
||||
}
|
||||
|
||||
$results = BuildingModel::search($filter);
|
||||
|
||||
foreach($results as $building) {
|
||||
$data = $building->data;
|
||||
//$this->log->debug("building status: ".print_r($building->status,true));
|
||||
$data = clone($building->data);
|
||||
$data->id = $building->id;
|
||||
$data->status = "none";
|
||||
$data->type = $building->type->name;
|
||||
$data->popname = ($building->pop_id) ? $building->pop->name : "-";
|
||||
|
||||
$terms = [];
|
||||
foreach($building->terminations as $term) {
|
||||
$building_term = [];
|
||||
$building_term['id'] = $term->id;
|
||||
$building_term['status'] = "none";
|
||||
|
||||
//$this->log->debug("building status: ".print_r($building->status,true));
|
||||
if($term->status->code == TT_TERMSTATUS_CONNECTED) {
|
||||
$building_term['status'] = "connected";
|
||||
$data->status = "connected";
|
||||
} elseif($building->status->code == TT_BUILDINGSTATUS_CONNECTED) {
|
||||
$building_term['status'] = "pipework-done";
|
||||
if($data->status != "connected") $data->status = "pipework-done";
|
||||
}
|
||||
$terms[] = $building_term;
|
||||
}
|
||||
|
||||
$data->terminations = $terms;
|
||||
$buildings[] = $data;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ class BuildingModel {
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
public static function getFirst($filter = []) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
@@ -105,7 +105,7 @@ class BuildingModel {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit = false) {
|
||||
public static function search($filter=[], $limit = false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
@@ -168,7 +168,7 @@ class BuildingModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(is_array($filter['type']) && count($filter['type'])) {
|
||||
if(array_key_exists("type", $filter) && is_array($filter['type']) && count($filter['type'])) {
|
||||
$ot = $filter['type'];
|
||||
$in = [];
|
||||
foreach($ot as $type) {
|
||||
|
||||
@@ -2,22 +2,126 @@
|
||||
|
||||
class Contract extends mfBaseModel {
|
||||
private $owner;
|
||||
private $creator;
|
||||
private $billingaddress;
|
||||
private $product;
|
||||
private $orderproduct;
|
||||
private $termination;
|
||||
private $sla;
|
||||
private $contractConfigGroups;
|
||||
private $contractConfigItems;
|
||||
private $configgroups;
|
||||
private $isCancelled;
|
||||
private $links;
|
||||
private $linkFrom;
|
||||
private $linkTo;
|
||||
private $upgradeFrom;
|
||||
private $upgradeTo;
|
||||
private $downgradeFrom;
|
||||
private $downgradeTo;
|
||||
private $productchangeFrom;
|
||||
private $productchangeTo;
|
||||
private $relocationFrom;
|
||||
private $relocationTo;
|
||||
private $finisher;
|
||||
private $canceler;
|
||||
private $creator;
|
||||
private $editor;
|
||||
|
||||
|
||||
private function getLinks() {
|
||||
$this->linkFrom = [];
|
||||
$this->linkTo = [];
|
||||
$this->upgradeFrom = [];
|
||||
$this->upgradeTo = [];
|
||||
$this->downgradeFrom = [];
|
||||
$this->downgradeTo = [];
|
||||
$this->productchangeFrom = [];
|
||||
$this->productchangeTo = [];
|
||||
$this->relocationFrom = [];
|
||||
$this->relocationTo = [];
|
||||
|
||||
// Links targeting this contract (to)
|
||||
foreach(ContractLinkModel::search(['origin_contract_id' => $this->id]) as $link) {
|
||||
switch($link->type) {
|
||||
case "link":
|
||||
$this->linkTo[] = $link;
|
||||
break;
|
||||
case "upgrade":
|
||||
$this->upgradeTo[] = $link;
|
||||
break;
|
||||
case "downgrade":
|
||||
$this->downgradeTo[] = $link;
|
||||
break;
|
||||
case "productchange":
|
||||
$this->productchangeTo[] = $link;
|
||||
break;
|
||||
case "relocation":
|
||||
$this->relocationTo[] = $link;
|
||||
break;
|
||||
default:
|
||||
$this->log->warn("ContractLink with invalid type: ".$link->id." ".$link->type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach(ContractLinkModel::search(['contract_id' => $this->id]) as $link) {
|
||||
switch($link->type) {
|
||||
case "link":
|
||||
$this->linkFrom[] = $link;
|
||||
break;
|
||||
case "upgrade":
|
||||
$this->upgradeFrom[] = $link;
|
||||
break;
|
||||
case "downgrade":
|
||||
$this->downgradeFrom[] = $link;
|
||||
break;
|
||||
case "productchange":
|
||||
$this->productchangeFrom[] = $link;
|
||||
break;
|
||||
case "relocation":
|
||||
$this->relocationFrom[] = $link;
|
||||
break;
|
||||
default:
|
||||
$this->log->warn("ContractLink with invalid type: ".$link->id." ".$link->type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function isCancelled() {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$this->cancel_date) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$now = date('U');
|
||||
if($this->cancel_date <= $now) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
if($name == "billingaddress" && $this->billingaddress_id) {
|
||||
$this->billingaddress = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->billingaddress_id);
|
||||
if($this->billingaddress === null) {
|
||||
$this->billingaddress = new Address($this->billingaddress_id);
|
||||
if($this->billingaddress->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-Address-".$this->billingaddress_id, $this->billingaddress);
|
||||
}
|
||||
}
|
||||
return $this->billingaddress;
|
||||
}
|
||||
|
||||
if($name == "owner") {
|
||||
if($name == "owner" && $this->owner_id) {
|
||||
$this->owner = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->owner_id);
|
||||
if($this->owner === null) {
|
||||
$this->owner = new Address($this->owner_id);
|
||||
@@ -28,17 +132,12 @@ class Contract extends mfBaseModel {
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
if($name == "billingaddress") {
|
||||
$this->billingaddress = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->billingaddress_id);
|
||||
if($this->billingaddress === null) {
|
||||
$this->billingaddress = new Address($this->billingaddress_id);
|
||||
if($this->billingaddress->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-Address-".$this->billingaddress_id, $this->billingaddress);
|
||||
}
|
||||
}
|
||||
return $this->billingaddress;
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if($name == "product") {
|
||||
$this->product = mfValuecache::singleton()->get("mfObjectmodel-Product-".$this->product_id);
|
||||
if($this->product === null) {
|
||||
@@ -61,6 +160,69 @@ class Contract extends mfBaseModel {
|
||||
return $this->orderproduct;
|
||||
}
|
||||
|
||||
if($name == "contractConfigGroups") {
|
||||
$product = $this->getProperty("product");
|
||||
$this->contractConfigGroups = ContractconfigGroupModel::search(['producttech_id' => $product->producttech_id]);
|
||||
return $this->contractConfigGroups;
|
||||
}
|
||||
|
||||
if($name == "configgroups") {
|
||||
$product = $this->getProperty("product");
|
||||
$this->configgroups = [];
|
||||
foreach(ContractconfiggroupProductgroupModel::search(['productgroup_id' => $product->productgroup_id]) as $ccpg) {
|
||||
$ccpg->contractconfiggroup->setContractId($this->id);
|
||||
$this->configgroups[] = $ccpg->contractconfiggroup;
|
||||
}
|
||||
return $this->configgroups;
|
||||
}
|
||||
|
||||
if($name == "contractConfigItems") {
|
||||
$product = $this->getProperty("product");
|
||||
|
||||
$this->contractConfigItems = [];
|
||||
foreach(ProducttechAttributeModel::search(['producttech_id' => $product->producttech_id, "forcontract" => 1]) as $item) {
|
||||
$item->setContractId($this->id);
|
||||
$this->contractConfigItems [] = $item;
|
||||
}
|
||||
|
||||
return $this->contractConfigItems;
|
||||
}
|
||||
|
||||
if($name == "links") {
|
||||
$this->links = ContractLinkModel::includesContractId($this->id, ["type" => $link]);
|
||||
//var_dump($this->links);exit;
|
||||
return $this->links;
|
||||
}
|
||||
|
||||
if(in_array($name, ['linkFrom','linkTo','upgradeFrom','upgradeTo','downgradeFrom','downgradeTo','productchangeFrom','productchangeTo','relocationFrom','relocationTo'])) {
|
||||
if($this->$name === null) {
|
||||
$this->getLinks();
|
||||
}
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
if($name == "finisher") {
|
||||
$this->finisher = mfValuecache::singleton()->get("Worker-id-".$this->finish_date_by);
|
||||
if($this->finisher === null) {
|
||||
$this->finisher = new User($this->finish_date_by);
|
||||
if($this->finisher->id) {
|
||||
mfValuecache::singleton()->set("Worker-id-".$this->finish_date_by, $this->finisher);
|
||||
}
|
||||
}
|
||||
return $this->finisher;
|
||||
}
|
||||
|
||||
if($name == "canceler") {
|
||||
$this->canceler = mfValuecache::singleton()->get("Worker-id-".$this->cancel_date_by);
|
||||
if($this->canceler === null) {
|
||||
$this->canceler = new User($this->cancel_date_by);
|
||||
if($this->canceler->id) {
|
||||
mfValuecache::singleton()->set("Worker-id-".$this->cancel_date_by, $this->canceler);
|
||||
}
|
||||
}
|
||||
return $this->canceler;
|
||||
}
|
||||
|
||||
if($name == "creator") {
|
||||
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||
if($this->creator === null) {
|
||||
@@ -103,4 +265,45 @@ class Contract extends mfBaseModel {
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* When object is cloned, new object will call this funtion to let us clean up the new Contract.
|
||||
* Throws Exception if cloning fails.
|
||||
*/
|
||||
public function __clone() {
|
||||
$me = new User;
|
||||
$me->loadMe();
|
||||
|
||||
$old_id = $this->id;
|
||||
$old_nummer = $this->nummer;
|
||||
unset($this->id);
|
||||
|
||||
|
||||
// cleanup Contract daten
|
||||
$this->orderproduct_id = null;
|
||||
$this->order_date = null;
|
||||
$this->finish_date = null;
|
||||
$this->finish_date_by = null;
|
||||
$this->cancel_date = null;
|
||||
$this->cancel_date_by = null;
|
||||
$this->create_by = $me->id;
|
||||
$this->edit_by = $me->id;
|
||||
|
||||
$this->create = null;
|
||||
$this->edit = null;
|
||||
$this->saved = 0;
|
||||
$this->mode = "new";
|
||||
$this->_old_data = new StdClass();
|
||||
|
||||
//$this->save();
|
||||
|
||||
if($old_id == $this->id) {
|
||||
$this->log->error("save() of cloned Contract $old_nummer failed!");
|
||||
throw new Exception("Saving clone failed.");
|
||||
}
|
||||
|
||||
$this->log->debug("Cloned Contract $old_id");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -47,6 +47,14 @@ class ContractController extends mfBaseController {
|
||||
private function getPreparedFilter($filter) {
|
||||
$new_filter = [];
|
||||
|
||||
if(array_key_exists("show_canceled", $filter)) {
|
||||
if($filter['show_canceled'] == 0) {
|
||||
$new_filter['add-where'] = " AND (cancel_date IS NULL OR cancel_date > UNIX_TIMESTAMP())";
|
||||
}
|
||||
} else {
|
||||
$new_filter['add-where'] = " AND (cancel_date IS NULL OR cancel_date > UNIX_TIMESTAMP())";
|
||||
}
|
||||
|
||||
if(is_array($filter) && count($filter)) {
|
||||
foreach($filter as $name => $value) {
|
||||
$new_filter[$name] = $value;
|
||||
@@ -56,12 +64,13 @@ class ContractController extends mfBaseController {
|
||||
return $new_filter;
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
$this->layout()->setTemplate("Contract/Form");
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
$id = $this->request->id;
|
||||
protected function viewAction() {
|
||||
$this->layout()->setTemplate("Contract/View");
|
||||
|
||||
$id = $this->request->contract_id;
|
||||
if(!$id) {
|
||||
$id = $this->request->id;
|
||||
}
|
||||
if(!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
|
||||
$this->redirect("Contract");
|
||||
@@ -75,11 +84,437 @@ class ContractController extends mfBaseController {
|
||||
|
||||
$this->layout()->set("contract", $contract);
|
||||
|
||||
if($this->request->filter) {
|
||||
$this->layout()->set("filter", $this->request->filter);
|
||||
}
|
||||
if($this->request->s) {
|
||||
$this->layout()->set("filter", $this->request->s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function productchangeAction() {
|
||||
$this->layout()->setTemplate("Contract/ProductchangeForm");
|
||||
|
||||
$id = $this->request->contract_id;
|
||||
if(!$id) {
|
||||
$id = $this->request->id;
|
||||
}
|
||||
if(!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
$contract = new Contract($id);
|
||||
if(!$contract->id) {
|
||||
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
$this->layout()->set("contract", $contract);
|
||||
$this->layout()->set("terminations", TerminationModel::getAll());
|
||||
|
||||
if($this->request->filter) {
|
||||
$this->layout()->set("filter", $this->request->filter);
|
||||
}
|
||||
if($this->request->s) {
|
||||
$this->layout()->set("filter", $this->request->s);
|
||||
}
|
||||
}
|
||||
|
||||
protected function saveProductchangeAction() {
|
||||
$r = $this->request;
|
||||
|
||||
$id = $r->contract_id;
|
||||
if(!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
$contract = new Contract($id);
|
||||
if(!$contract->id) {
|
||||
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
$new_contract = clone($contract);
|
||||
|
||||
|
||||
$contract_data = [];
|
||||
$contract_data['product_id'] = $r->product_id;
|
||||
$contract_data['product_name'] = trim($r->product_name);
|
||||
$contract_data['product_info'] = trim($r->product_info);
|
||||
$contract_data['matchcode'] = trim($r->matchcode);
|
||||
$contract_data['termination_id'] = $r->termination_id;
|
||||
$contract_data['amount'] = 1;
|
||||
$contract_data['price'] = $r->price;
|
||||
$contract_data['price_setup'] = $r->price_setup;
|
||||
$contract_data['price_nne'] = $r->price_nne;
|
||||
$contract_data['price_nbe'] = $r->price_nbe;
|
||||
$contract_data['note'] = trim($r->note);
|
||||
|
||||
/*
|
||||
* termination check
|
||||
*/
|
||||
$product = new Product($r->product_id);
|
||||
if(!$product->id) {
|
||||
$this->layout()->setFlash("Produkt nicht gefunden", "error");
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id]);
|
||||
}
|
||||
|
||||
$contract_data['product_external'] = $product->external;
|
||||
$contract_data['product_external_id'] = $product->external_id;
|
||||
$contract_data['sla_id'] = $product->sla_id;
|
||||
|
||||
$require_term = false;
|
||||
if(array_key_exists(TT_ATTRIB_TERMINATION_REQUIRED_NAME, $product->attributes) && $product->attributes[TT_ATTRIB_TERMINATION_REQUIRED_NAME]->value == 1) {
|
||||
//var_dump($prod->attributes);
|
||||
$require_term = true;
|
||||
$termination = new Termination($contract_data['termination_id']);
|
||||
|
||||
if(!$contract_data['termination_id'] || !$termination->id) {
|
||||
$this->layout()->setFlash("Produkt erfordert Anschluss.", "error");
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id]);
|
||||
}
|
||||
} else {
|
||||
$contract_data['termination_id'] = null;
|
||||
}
|
||||
|
||||
|
||||
$new_contract->update($contract_data);
|
||||
$new_contract_id = $new_contract->save();
|
||||
|
||||
if(!$new_contract_id) {
|
||||
$this->layout()->setFlash("Neuer Contract konnte nicht gespeichert werden", "error");
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(is_array($r->links) && count($r->links)) {
|
||||
foreach($r->links as $link_id => $action) {
|
||||
$old_link = new ContractLink($link_id);
|
||||
if(!$old_link->id) continue;
|
||||
$new_link_origin_id = 0;
|
||||
$new_link_origin_id = 0;
|
||||
// check if link contains this contract
|
||||
if($old_link->contract_id == $contract->id) {
|
||||
$new_link_contract_id = $new_contract->id;
|
||||
$new_link_origin_id = $old_link->origin_contract_id;
|
||||
} elseif($old_link->origin_contract_id == $contract->id) {
|
||||
$new_link_contract_id = $old_link->contract_id;
|
||||
$new_link_origin_id = $new_contract->id;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
$new_link = ContractLinkModel::create([
|
||||
'contract_id' => $new_link_contract_id,
|
||||
'origin_contract_id' => $new_link_origin_id,
|
||||
'type' => $old_link->type,
|
||||
]);
|
||||
if(!$new_link->save()) {
|
||||
$this->layout()->setFlash("Konnte neuen Link nicht speichern", "warn");
|
||||
}
|
||||
|
||||
if($action == "cancel") {
|
||||
$old_link->change_action = "cancel";
|
||||
if(!$old_link->save()) {
|
||||
$this->layout()->setFlash("Konnte alten Link nicht speichern", "warn");
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($new_link);exit;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Upgrade Link erstellen
|
||||
*/
|
||||
$change_type = "upgrade";
|
||||
/*if($contract->product_id != $new_contract->product_id) {
|
||||
$change_type = "upgrade";
|
||||
} elseif($contract->matchcode != $new_contract->matchcode) {
|
||||
$change_type = "relocation";
|
||||
} else {
|
||||
$change_type = "productchange";
|
||||
}*/
|
||||
|
||||
$link = ContractLinkModel::create([
|
||||
'contract_id' => $new_contract_id,
|
||||
'origin_contract_id' => $id,
|
||||
'type' => $change_type
|
||||
]);
|
||||
|
||||
$link_id = $link->save();
|
||||
if(!$link_id) {
|
||||
$this->layout()->setFlash("Konnte Verknüpfung nicht speichern", "warn");
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Neuer Contract erfolgreich erstellt", "success");
|
||||
$this->redirect("Contract", "view", ["contract_id" => $new_contract_id]);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function finishContractAction() {
|
||||
$r = $this->request;
|
||||
|
||||
$id = $r->contract_id;
|
||||
if(!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Contract nicht gefunden", "error");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
$contract = new Contract($id);
|
||||
if(!$contract->id) {
|
||||
$this->layout()->setFlash("Contract nicht gefunden", "error");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
$now = date('U');
|
||||
|
||||
/*
|
||||
* Vorgänger Contracts kündigen
|
||||
*/
|
||||
foreach(ContractLinkModel::search(['contract_id' => $id]) as $link) {
|
||||
if(!in_array($link->type, ["upgrade","downgrade","relocation","productchange"])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$origin = $link->origin;
|
||||
$origin->cancel_date = $now;
|
||||
$origin->cancel_date_by = $this->me->id;
|
||||
$origin->edit_by = $this->me->id;
|
||||
if(!$origin->save()) {
|
||||
$this->layout()->setFlash("Achtung: Konnte nicht alle Vorgängercontracts kündigen!", "warn");
|
||||
}
|
||||
|
||||
/*
|
||||
* alte Links übernehmen / kündigen
|
||||
*/
|
||||
foreach(ContractLinkModel::search(['type' => "link", 'contract_id' => $origin->id] ) as $old_link) {
|
||||
// verlinkten Contract kündigen (wenn nicht schon gekündigt)
|
||||
if($old_link->change_action == "cancel" && !$old_link->contract->cancel_date) {
|
||||
$old_link->origin->update([
|
||||
'cancel_date' => $now,
|
||||
'cancel_date_by' => $this->me->id,
|
||||
'edit_by' => $this->me->id
|
||||
]);
|
||||
$old_link->origin->save();
|
||||
|
||||
$old_link->change_action = null;
|
||||
$old_link->save();
|
||||
}
|
||||
}
|
||||
|
||||
foreach(ContractLinkModel::search(['type' => "link", 'origin_contract_id' => $origin->id] ) as $old_link) {
|
||||
// verlinkten Contract kündigen (wenn nicht schon gekündigt)
|
||||
if($old_link->change_action == "cancel" && !$old_link->contract->cancel_date) {
|
||||
$old_link->contract->update([
|
||||
'cancel_date' => $now,
|
||||
'cancel_date_by' => $this->me->id,
|
||||
'edit_by' => $this->me->id
|
||||
]);
|
||||
$old_link->contract->save();
|
||||
|
||||
$old_link->change_action = null;
|
||||
$old_link->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$contract->finish_date = $now;
|
||||
$contract->finish_date_by = $this->me->id;
|
||||
if(!$contract->save()) {
|
||||
$this->layout()->setFlash("Contract konnte nicht gespeichert werden", "error");
|
||||
$this->redirect("Contract", "view", ['contract_id' => $id]);
|
||||
}
|
||||
|
||||
/*
|
||||
* bestehende Links übernehmen oder kündigen
|
||||
*/
|
||||
|
||||
$this->layout()->setFlash("Contract erfolgreich fertiggestellt", "success");
|
||||
$this->redirect("Contract", "view", ['contract_id' => $id]);
|
||||
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
$this->layout()->setTemplate("Contract/Form");
|
||||
$this->layout()->set("terminations", TerminationModel::getAll());
|
||||
|
||||
if($this->request->origin_contract_id) {
|
||||
$origin = new Contract($this->request->origin_contract_id);
|
||||
if($origin->id) {
|
||||
$contract = new Contract();
|
||||
$contract->owner_id = $origin->owner_id;
|
||||
$contract->billingaddress_id = $origin->billingaddress_id;
|
||||
$contract->matchcode = $origin->matchcode;
|
||||
//var_dump($contract);exit;
|
||||
$this->layout()->set("contract", $contract);
|
||||
$this->layout()->set("origin_contract_id", $origin->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
$id = $this->request->contract_id;
|
||||
if(!$id) {
|
||||
$id = $this->request->id;
|
||||
}
|
||||
if(!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
$contract = new Contract($id);
|
||||
if(!$contract->id) {
|
||||
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
$this->layout()->set("contract", $contract);
|
||||
|
||||
if($this->request->f == "view") $this->layout()->set("f", "view");
|
||||
if($this->request->f != "view") $this->layout()->set("f", "index");
|
||||
|
||||
if($this->request->filter) {
|
||||
$this->layout()->set("filter", $this->request->filter);
|
||||
}
|
||||
if($this->request->s) {
|
||||
$this->layout()->set("filter", $this->request->s);
|
||||
}
|
||||
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
//var_dump($r);
|
||||
|
||||
/*
|
||||
* add or edit
|
||||
*/
|
||||
$id = $r->id;
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$contract = new Contract($id);
|
||||
if(!$contract->id) {
|
||||
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
} else {
|
||||
$id = false;
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
//var_dump($r->get());exit;
|
||||
$contract_data = [];
|
||||
$contract_data["owner_id"] = (int)$r->owner_id;
|
||||
$contract_data["billingaddress_id"] = ($r->billingaddress_id) ? (int)$r->billingaddress_id : null;
|
||||
$contract_data["product_id"] = (int)$r->product_id;
|
||||
$contract_data["matchcode"] = $r->matchcode;
|
||||
$contract_data["product_name"] = $r->product_name;
|
||||
$contract_data["product_info"] = $r->product_info;
|
||||
$contract_data['amount'] = ($r->amount) ? (float)$r->amount : 1;
|
||||
$contract_data['price'] = (float)$r->price;
|
||||
$contract_data['price_setup'] = (float)$r->price_setup;
|
||||
$contract_data['price_nne'] = (float)$r->price_nne;
|
||||
$contract_data['price_nbe'] = (float)$r->price_nbe;
|
||||
$contract_data['billing_period'] = (int)$r->billing_period;
|
||||
$contract_data['billing_delay'] = (int)$r->billing_delay;
|
||||
$contract_data['finish_date'] = ($r->finish_date) ? $this->dateToTimestamp($r->finish_date) : null;
|
||||
$contract_data['cancel_date'] = ($r->cancel_date) ? $this->dateToTimestamp($r->cancel_date) : null;
|
||||
$contract_data['note'] = $r->note;
|
||||
|
||||
|
||||
//var_dump($contract_data);exit;
|
||||
|
||||
if($mode == "add") {
|
||||
$contract = ContractModel::create($contract_data);
|
||||
} else {
|
||||
$contract->update($contract_data);
|
||||
}
|
||||
|
||||
$this->layout()->set("contract", $contract);
|
||||
|
||||
if(!$contract_data["owner_id"]) {
|
||||
$this->layout()->setFlash("Bitte Vertragsinhaber auswählen.", "error");
|
||||
return $this->addAction();
|
||||
}
|
||||
if(!$contract_data["product_id"]) {
|
||||
$this->layout()->setFlash("Bitte Produkt auswählen.", "error");
|
||||
return $this->addAction();
|
||||
}
|
||||
if(!$contract_data['billing_period']) {
|
||||
$this->layout()->setFlash("Bitte Rechnungsperiode auswählen.", "error");
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
if(!$contract->product_name) {
|
||||
$product = new Product($contract_data["product_id"]);
|
||||
if(!$product->id) {
|
||||
$this->layout()->setFlash("Ungültiges Produkt.", "error");
|
||||
return $this->addAction();
|
||||
}
|
||||
$contract->product_name = $product->name;
|
||||
}
|
||||
|
||||
//var_dump($contract);exit;
|
||||
|
||||
$contract_id = $contract->save();
|
||||
if(!$contract_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern.", "error");
|
||||
$this->layout()->set("contract", $contract);
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Vertrag erfolgreich gespeichert.", "success");
|
||||
|
||||
/*
|
||||
* Create link to origin contract if set
|
||||
*/
|
||||
if($mode == "add" && $r->origin_contract_id) {
|
||||
$origin = new Contract($r->origin_contract_id);
|
||||
if($origin->id) {
|
||||
$link = ContractLinkModel::create([
|
||||
'contract_id' => $contract_id,
|
||||
'origin_contract_id' => $origin->id,
|
||||
'type' => 'link'
|
||||
]);
|
||||
$link->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ContractLinks */
|
||||
|
||||
|
||||
$query = [];
|
||||
if($r->s) {
|
||||
$query['s'] = $r->s;
|
||||
}
|
||||
if($r->filter) {
|
||||
$query["filter"] = $r->filter;
|
||||
}
|
||||
if($r->return != "index") {
|
||||
$query['id'] = $contract_id;
|
||||
}
|
||||
|
||||
$qs = http_build_query($query);
|
||||
|
||||
if($mode == "add" || $r->f == "view") {
|
||||
$this->redirect("Contract", "view", $qs, "contract=$contract_id");
|
||||
} else {
|
||||
$this->redirect("Contract", "Index", $qs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function apiAction() {
|
||||
if(!$this->me->is(["Admin"])) {
|
||||
|
||||
@@ -1,20 +1,29 @@
|
||||
<?php
|
||||
|
||||
class ContractModel {
|
||||
public $name = null;
|
||||
public $description = null;
|
||||
public $orderproduct_id;
|
||||
public $owner_id;
|
||||
public $billingaddress_id;
|
||||
public $termination_id;
|
||||
public $product_id;
|
||||
public $product_name;
|
||||
public $product_info;
|
||||
public $matchcode;
|
||||
public $amount;
|
||||
public $sla_id = null;
|
||||
public $external = null;
|
||||
public $external_id;
|
||||
public $productgroup_id = null;
|
||||
public $producttech_id = null;
|
||||
public $product_external;
|
||||
public $product_external_id;
|
||||
public $price = null;
|
||||
public $price_setup = null;
|
||||
public $price_nne = null;
|
||||
public $price_nbe = null;
|
||||
public $billing_delay = null;
|
||||
public $billing_period = null;
|
||||
public $ivt_id = null;
|
||||
public $order_date;
|
||||
public $finish_date;
|
||||
public $finish_date_by;
|
||||
public $cancel_date;
|
||||
public $cancel_date_by;
|
||||
|
||||
public $note = null;
|
||||
public $create_by = null;
|
||||
@@ -50,7 +59,7 @@ class ContractModel {
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Contract", "*", "1 = 1 ORDER BY owner_id,product_id,`create`");
|
||||
$res = $db->select("Contract", "*", "1 = 1 ORDER BY owner_id,`create`");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Contract($data);
|
||||
@@ -120,7 +129,7 @@ class ContractModel {
|
||||
LEFT JOIN Product ON (Contract.product_id = Product.id)
|
||||
WHERE $where
|
||||
GROUP BY Contract.id
|
||||
ORDER BY Contract.owner_id,Contract.product_id,Contract.`create`";
|
||||
ORDER BY Contract.owner_id,Contract.`create`";
|
||||
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
@@ -163,6 +172,13 @@ class ContractModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("billingaddress_id", $filter)) {
|
||||
$billingaddress_id = $filter['billingaddress_id'];
|
||||
if(is_numeric($billingaddress_id)) {
|
||||
$where .= " AND Contract.billingaddress_id=$billingaddress_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("product_id", $filter)) {
|
||||
$product_id = $filter['product_id'];
|
||||
if(is_numeric($product_id)) {
|
||||
@@ -192,6 +208,13 @@ class ContractModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("customer_number", $filter)) {
|
||||
$customer_number = $filter['customer_number'];
|
||||
if(is_numeric($customer_number)) {
|
||||
$where .= " AND Address.customer_number=$customer_number";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("owner", $filter)) {
|
||||
$owner = FronkDB::singleton()->escape($filter["owner"]);
|
||||
if($owner) {
|
||||
@@ -199,6 +222,10 @@ class ContractModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("add-where", $filter)) {
|
||||
$where .= " ".$filter['add-where'];
|
||||
}
|
||||
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
class ContractLink extends mfBaseModel {
|
||||
private $contract;
|
||||
private $origin;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($name == "origin") {
|
||||
$this->origin = mfValuecache::singleton()->get("mfObjectmodel-Contract-".$this->origin_contract_id);
|
||||
if($this->origin === null) {
|
||||
$this->origin = new Contract($this->origin_contract_id);
|
||||
if($this->origin->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-Contract-".$this->id, $this->origin);
|
||||
}
|
||||
}
|
||||
return $this->origin;
|
||||
}
|
||||
|
||||
if($name == "creator") {
|
||||
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||
if($this->creator === null) {
|
||||
$this->creator = new User($this->create_by);
|
||||
if($this->creator->id) {
|
||||
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
|
||||
}
|
||||
}
|
||||
return $this->creator;
|
||||
}
|
||||
|
||||
if($name == "editor") {
|
||||
$this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
|
||||
if($this->editor === null) {
|
||||
$this->editor = new User($this->edit_by);
|
||||
if($this->editor->id) {
|
||||
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
|
||||
}
|
||||
}
|
||||
return $this->editor;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
||||
if(!$this->$name) {
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if($this->$name->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
class ContractLinkModel {
|
||||
public $contract_id;
|
||||
public $origin_contract_id;
|
||||
public $type;
|
||||
public $change_action;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new ContractLink();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$model ->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
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 getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("ContractLink", "*", "1 = 1 ORDER BY contract_id,origin_contract_id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new ContractLink($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM ContractLink
|
||||
WHERE $where
|
||||
ORDER BY contract_id,origin_contract_id
|
||||
LIMIT 1";
|
||||
//var_dump($sql);exit;
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ContractLink($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function includesContractId($contract_id, $filter=[]) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM ContractLink
|
||||
WHERE (contract_id=$contract_id OR origin_contract_id=$contract_id)
|
||||
AND $where
|
||||
ORDER BY contract_id,origin_contract_id";
|
||||
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new ContractLink($data);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) FROM ContractLink
|
||||
WHERE $where
|
||||
";
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return $data->cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit = false) {
|
||||
//var_dump($filter);exit;
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM ContractLink
|
||||
WHERE $where
|
||||
ORDER BY contract_id,origin_contract_id";
|
||||
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($count)) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new ContractLink($data);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
//var_dump($filter);exit;
|
||||
|
||||
if(array_key_exists("contract_id", $filter)) {
|
||||
$contract_id = $filter['contract_id'];
|
||||
if(is_numeric($contract_id)) {
|
||||
$where .= " AND ContractLink.contract_id = '$contract_id'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("origin_contract_id", $filter)) {
|
||||
$origin_contract_id = $filter['origin_contract_id'];
|
||||
if(is_numeric($origin_contract_id)) {
|
||||
$where .= " AND ContractLink.origin_contract_id = '$origin_contract_id'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,9 +15,82 @@ class ContractconfigController extends mfBaseController {
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
$groups = ContractconfigGroupModel::getAll();
|
||||
|
||||
$this->layout()->set("groups", $groups);
|
||||
}
|
||||
|
||||
protected function viewAction() {
|
||||
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
$this->layout()->setTemplate("Contractconfig/Form");
|
||||
|
||||
$contract_id = $this->request->contract_id;
|
||||
if(!$contract_id) {
|
||||
$this->layout()->setFlash("Contract ID nicht gefunden.","error");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
$contract = new Contract($contract_id);
|
||||
if(!$contract_id) {
|
||||
$this->layout()->setFlash("Contract ID nicht gefunden.","error");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
if(!is_array($contract->configgroups) || !count($contract->configgroups)) {
|
||||
$this->layout()->setFlash("Produkt hat keine Vertragsconfiggruppen hinterlegt.","info");
|
||||
$this->redirect("Contract", "View", ["id" => $contract_id]);
|
||||
}
|
||||
|
||||
$this->layout()->set("contract", $contract);
|
||||
$this->layout()->set("groups", $contract->configgroups);
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
$contract_id = $r->contract_id;
|
||||
|
||||
if(!is_numeric($contract_id) || $contract_id < 1) {
|
||||
$this->layout()->setFlash("Contract ID nicht gefunden.","error");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
if(!is_array($r->itemvalues) || !count($r->itemvalues)) {
|
||||
$this->layout()->setFlash("Keine Änderungen.","info");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
$error_items = [];
|
||||
|
||||
foreach($r->itemvalues as $item_id => $itemvalue) {
|
||||
$item = new ContractconfigItem($item_id);
|
||||
if(!$item->id) {
|
||||
$this->log->warn("Tried to save non-existant ContractconfigItem $item_id");
|
||||
continue;
|
||||
}
|
||||
$item->setContractId($contract_id);
|
||||
if(!$item->value->set($itemvalue)) {
|
||||
$error_items[$item->id] = $item->name;
|
||||
continue;
|
||||
}
|
||||
if(!$item->value->save()) {
|
||||
$this->layout()->set("request", $r);
|
||||
$this->layout()->setFlash("Fehler beim Speichern von".$item->name,"info");
|
||||
return $this->editAction();
|
||||
}
|
||||
}
|
||||
|
||||
if(count($error_items)) {
|
||||
$this->layout()->set("error_items", array_keys($error_items));
|
||||
$this->layout()->set("request", $r);
|
||||
$this->layout()->setFlash("Konfiguration nicht vollständig gespeichert. Fehler in folgenden Feldern:\n<br />".implode(", ", $error_items), "warning");
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Konfiguration gespeichert", "success");
|
||||
$this->redirect("Contract", "view", ['id' => $contract_id]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
class ContractconfigGroup extends mfBaseModel {
|
||||
private $items;
|
||||
private $value;
|
||||
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "items") {
|
||||
$this->items = ContractconfigItemModel::search(['group_id' => $this->id]);
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
if($this->$name->id) {
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,77 @@
|
||||
<?php
|
||||
|
||||
class ContractconfigItem extends mfBaseModel {
|
||||
private $value;
|
||||
private $contract_id;
|
||||
|
||||
public function setContractId($contract_id) {
|
||||
if(!is_numeric($contract_id)) {
|
||||
return false;
|
||||
}
|
||||
$this->contract_id = $contract_id;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getValue() {
|
||||
$value = $this->getProperty("value");
|
||||
if(!$value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($this->type == "int") {
|
||||
return $value->int;
|
||||
}
|
||||
if($this->type == "decimal") {
|
||||
return $value->number;
|
||||
}
|
||||
|
||||
return $value->string;
|
||||
}
|
||||
|
||||
public function getTypedataArray() {
|
||||
if(!$this->typedata) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return explode("\n", $this->typedata);
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($name == "value") {
|
||||
if(!$this->contract_id) {
|
||||
return null;
|
||||
}
|
||||
$value = ContractconfigValueModel::getFirst(['item_id' => $this->id, "contract_id" => $this->contract_id]);
|
||||
if(!$value) {
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$value = new ContractconfigValue();
|
||||
$value->item_id = $this->id;
|
||||
$value->contract_id = $this->contract_id;
|
||||
$value->create_by = $me->id;
|
||||
}
|
||||
|
||||
$this->value = $value;
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
if($this->$name->id) {
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
class ContractconfigItemController extends mfBaseController {
|
||||
|
||||
protected function init() {
|
||||
$this->needlogin=true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
if(!$me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
|
||||
$item_id = $r->item_id;
|
||||
if(is_numeric($item_id) && $item_id > 0) {
|
||||
$mode = "edit";
|
||||
$item = new ContractconfigItem($item_id);
|
||||
if(!$item->id) {
|
||||
$this->layout()->setFlash("Element nicht gefunden", "error");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
} else {
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
$item_data['contractconfiggroup_id'] = $r->group_id;
|
||||
$item_data['name'] = $r->name;
|
||||
$item_data['displayname'] = $r->displayname;
|
||||
$item_data['description'] = $r->description;
|
||||
|
||||
$item_data['typedata'] = "";
|
||||
$item_data['pattern'] = "";
|
||||
|
||||
switch($r->type) {
|
||||
case "string":
|
||||
$item_data['type'] = "string";
|
||||
$item_data['pattern'] = $r->pattern;
|
||||
break;
|
||||
case "enum":
|
||||
$item_data['type'] = "enum";
|
||||
$item_data['typedata'] = preg_replace(['/\n{2,}/','/^\n+/','/\n+$/'], ["\n",'',''], str_replace("\r","\n",$r->data));
|
||||
break;
|
||||
case "int":
|
||||
$item_data['type'] = "int";
|
||||
break;
|
||||
case "decimal":
|
||||
$item_data['type'] = "decimal";
|
||||
break;
|
||||
default:
|
||||
$this->layout()->setFlash("Ungültiger Datentyp!");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
|
||||
if($mode == "edit") {
|
||||
$item->update($item_data);
|
||||
} else {
|
||||
$item = ContractconfigItemModel::create($item_data);
|
||||
}
|
||||
|
||||
//var_dump($item);exit;
|
||||
|
||||
$item_id = $item->save();
|
||||
|
||||
if(!$item_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern!");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Element erfolgreich gespeichert", "success");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
//$this->redirect("Contractconfig","Index","","item=$item_id");
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
<?php
|
||||
|
||||
class ContractconfigItemModel {
|
||||
public $order;
|
||||
public $contractconfiggroup_id;
|
||||
public $type;
|
||||
public $name;
|
||||
public $displayname;
|
||||
public $description;
|
||||
public $filename;
|
||||
public $store_filename;
|
||||
public $orig_filename;
|
||||
public $subfolder;
|
||||
public $typedata;
|
||||
public $pattern;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
@@ -14,7 +16,7 @@ class ContractconfigItemModel {
|
||||
public $edit = null;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
public static function create(Array $data) {
|
||||
$model = new ContractconfigItem();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
@@ -41,7 +43,7 @@ class ContractconfigItemModel {
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("ContractconfigItem", "*", "1=1 ORDER BY name, `create`");
|
||||
$res = $db->select("ContractconfigItem", "*", "1=1 ORDER BY `order`, name, `create`");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new ContractconfigItem($data);
|
||||
@@ -55,7 +57,7 @@ class ContractconfigItemModel {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("ContractconfigItem", "*", "$where LIMIT 1");
|
||||
$res = $db->select("ContractconfigItem", "*", "$where ORDER BY `order`,name LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ContractconfigItem($data);
|
||||
@@ -73,7 +75,7 @@ class ContractconfigItemModel {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("ContractconfigItem", "*", "$where ORDER BY name");
|
||||
$res = $db->select("ContractconfigItem", "*", "$where ORDER BY `order`,name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new ContractconfigItem($data);
|
||||
@@ -100,6 +102,13 @@ class ContractconfigItemModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("contractconfiggroup_id", $filter)) {
|
||||
$contractconfiggroup_id = $filter['contractconfiggroup_id'];
|
||||
if(is_numeric($contractconfiggroup_id)) {
|
||||
$where .= " AND contractconfiggroup_id=$contractconfiggroup_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("group_id", $filter)) {
|
||||
$group_id = $filter['group_id'];
|
||||
if(is_numeric($group_id)) {
|
||||
|
||||
@@ -1,5 +1,63 @@
|
||||
<?php
|
||||
|
||||
class ContractconfigValue extends mfBaseModel {
|
||||
private $item;
|
||||
|
||||
public function set($new_value) {
|
||||
$item = $this->getProperty("item");
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->edit_by = $me->id;
|
||||
|
||||
if($new_value === null || strlen($new_value) == 0) {
|
||||
$this->int = null;
|
||||
$this->number = null;
|
||||
$this->string = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
if($item->type == "int") {
|
||||
if(!is_numeric($new_value)) return false;
|
||||
$this->int = $new_value;
|
||||
} elseif($item->type == "decimal") {
|
||||
if(!is_float($new_value) && !is_numeric($new_value)) return false;
|
||||
$this->number = $new_value;
|
||||
} elseif(is_scalar($new_value)) {
|
||||
$this->string = $new_value;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($name == "item") {
|
||||
$this->item = new ContractconfigItem($this->item_id);
|
||||
if(!$this->item->id) {
|
||||
return null;
|
||||
}
|
||||
return $this->item;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
if($this->$name->id) {
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
<?php
|
||||
|
||||
class ContractconfigValueModel {
|
||||
public $name;
|
||||
public $description;
|
||||
public $filename;
|
||||
public $store_filename;
|
||||
public $orig_filename;
|
||||
public $subfolder;
|
||||
public $contract_id;
|
||||
public $item_id;
|
||||
public $string;
|
||||
public $int;
|
||||
public $text;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
@@ -51,11 +50,11 @@ class ContractconfigValueModel {
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("ContractconfigValue", "*", "$where LIMIT 1");
|
||||
$res = $db->select("ContractconfigValue", "*", "$where ORDER BY item_id, contract_id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ContractconfigValue($data);
|
||||
@@ -73,7 +72,7 @@ class ContractconfigValueModel {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("ContractconfigValue", "*", "$where ORDER BY name, filename");
|
||||
$res = $db->select("ContractconfigValue", "*", "$where ORDER BY item_id, contract_id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new ContractconfigValue($data);
|
||||
@@ -86,24 +85,44 @@ class ContractconfigValueModel {
|
||||
$where = "1=1 ";
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("name", $filter)) {
|
||||
$name = FronkDB::singleton()->escape($filter['name']);
|
||||
if($name) {
|
||||
$where .= " AND name='$name'";
|
||||
if(array_key_exists("contract_id", $filter)) {
|
||||
$contract_id = $filter['contract_id'];
|
||||
if(is_numeric($contract_id)) {
|
||||
$where .= " AND contract_id=$contract_id";
|
||||
} elseif(is_array($contract_id) && count($contract_id)) {
|
||||
$where .= " AND contract_id IN (". implode(",", $contract_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("filename", $filter)) {
|
||||
$filename = FronkDB::singleton()->escape($filter['filename']);
|
||||
if($filename) {
|
||||
$where .= " AND filename='$filename'";
|
||||
if(array_key_exists("item_id", $filter)) {
|
||||
$item_id = $filter['item_id'];
|
||||
if(is_numeric($item_id)) {
|
||||
$where .= " AND item_id=$item_id";
|
||||
} elseif(is_array($item_id) && count($item_id)) {
|
||||
$where .= " AND item_id IN (". implode(",", $item_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("subfolder", $filter)) {
|
||||
$subfolder = FronkDB::singleton()->escape($filter['subfolder']);
|
||||
if($subfolder) {
|
||||
$where .= " AND subfolder='$subfolder'";
|
||||
if(array_key_exists("int", $filter)) {
|
||||
$int = $filter['int'];
|
||||
if(is_numeric($int)) {
|
||||
$where .= " AND int=$int";
|
||||
} elseif(is_array($int) && count($int)) {
|
||||
$where .= " AND `int` IN (". implode(",", $int).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("string", $filter)) {
|
||||
$string = FronkDB::singleton()->escape($filter['string']);
|
||||
if($string) {
|
||||
$where .= " AND `string`='$string'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("text", $filter)) {
|
||||
$text = FronkDB::singleton()->escape($filter['text']);
|
||||
if($text) {
|
||||
$where .= " AND `text`='$text'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
class Contractconfiggroup extends mfBaseModel {
|
||||
private $items;
|
||||
private $contract_id;
|
||||
|
||||
public function setContractId($contract_id) {
|
||||
if(!is_numeric($contract_id)) {
|
||||
return false;
|
||||
}
|
||||
$this->contract_id = $contract_id;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
/*if($name == "items") {
|
||||
$this->items = ContractconfigItemModel::search(['group_id' => $this->id]);
|
||||
return $this->items;
|
||||
}*/
|
||||
|
||||
if($name == "items") {
|
||||
if($this->contract_id) {
|
||||
foreach(ContractconfigItemModel::search(['contractconfiggroup_id' => $this->id]) as $item) {
|
||||
$item->setContractId($this->contract_id);
|
||||
$this->items[] = $item;
|
||||
}
|
||||
} else {
|
||||
$this->items = ContractconfigItemModel::search(['contractconfiggroup_id' => $this->id]);
|
||||
}
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
if($this->$name->id) {
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
class ContractconfiggroupController extends mfBaseController {
|
||||
|
||||
protected function init() {
|
||||
$this->needlogin=true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
if(!$me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
$groups = ContractconfiggroupModel::search([]);
|
||||
|
||||
$this->layout()->set("configgroups", $groups);
|
||||
}
|
||||
|
||||
|
||||
protected function saveAction() {
|
||||
$groupname = ucfirst(trim($this->request->name));
|
||||
|
||||
if(!$groupname) {
|
||||
$this->layout()->setFlash("Gruppenname darf nicht leer sein!", "error");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
|
||||
$group = ContractconfiggroupModel::getFirst(["name" => $groupname]);
|
||||
if($group) {
|
||||
$this->layout()->setFlash("Gruppe gibs scho", "warn");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
|
||||
$group = ContractconfiggroupModel::create(["name" => $groupname]);
|
||||
$group_id = $group->save();
|
||||
if(!$group_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Gruppe $groupname erfolgreich angelegt", "success");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+34
-19
@@ -1,12 +1,7 @@
|
||||
<?php
|
||||
|
||||
class ContractconfigGroupModel {
|
||||
class ContractconfiggroupModel {
|
||||
public $name;
|
||||
public $description;
|
||||
public $filename;
|
||||
public $store_filename;
|
||||
public $orig_filename;
|
||||
public $subfolder;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
@@ -15,7 +10,7 @@ class ContractconfigGroupModel {
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new ContractconfigGroup();
|
||||
$model = new Contractconfiggroup();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
@@ -41,24 +36,24 @@ class ContractconfigGroupModel {
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("ContractconfigGroup", "*", "1=1 ORDER BY name, `create`");
|
||||
$res = $db->select("Contractconfiggroup", "*", "1=1 ORDER BY name, `create`");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new ContractconfigGroup($data);
|
||||
$items[] = new Contractconfiggroup($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
public static function getFirst($filter = []) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("ContractconfigGroup", "*", "$where LIMIT 1");
|
||||
$res = $db->select("Contractconfiggroup", "*", "$where ORDER BY name, `create` LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ContractconfigGroup($data);
|
||||
$item = new Contractconfiggroup($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
@@ -73,10 +68,19 @@ class ContractconfigGroupModel {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("ContractconfigGroup", "*", "$where ORDER BY name, filename");
|
||||
$sql = "SELECT Contractconfiggroup.* FROM Contractconfiggroup
|
||||
LEFT JOIN ContractconfiggroupProductgroup ON (Contractconfiggroup.id = ContractconfiggroupProductgroup.contractconfiggroup_id)
|
||||
LEFT JOIN Productgroup ON (ContractconfiggroupProductgroup.productgroup_id = Productgroup.id)
|
||||
WHERE $where
|
||||
GROUP BY Contractconfiggroup.id
|
||||
ORDER BY Contractconfiggroup.name, Contractconfiggroup.`create`
|
||||
";
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
$res = $db->query($sql);
|
||||
//$res = $db->select("Contractconfiggroup", "*", "$where ORDER BY name, `create`");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new ContractconfigGroup($data);
|
||||
$items[] = new Contractconfiggroup($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
@@ -89,14 +93,25 @@ class ContractconfigGroupModel {
|
||||
if(array_key_exists("name", $filter)) {
|
||||
$name = FronkDB::singleton()->escape($filter['name']);
|
||||
if($name) {
|
||||
$where .= " AND name='$name'";
|
||||
$where .= " AND Contractconfiggroup.name='$name'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("filename", $filter)) {
|
||||
$filename = FronkDB::singleton()->escape($filter['filename']);
|
||||
if($filename) {
|
||||
$where .= " AND filename='$filename'";
|
||||
if(array_key_exists("producttech_id", $filter)) {
|
||||
$producttech_id = $filter['producttech_id'];
|
||||
if(is_numeric($producttech_id)) {
|
||||
$where .= " AND producttech_id=$producttech_id";
|
||||
} elseif(is_array($producttech_id) && count($producttech_id)) {
|
||||
$where .= " AND producttech_id IN (". implode(",", $producttech_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("productgroup_id", $filter)) {
|
||||
$productgroup_id = $filter['productgroup_id'];
|
||||
if(is_numeric($productgroup_id)) {
|
||||
$where .= " AND productgroup_id=$productgroup_id";
|
||||
} elseif(is_array($productgroup_id) && count($productgroup_id)) {
|
||||
$where .= " AND productgroup_id IN (". implode(",", $productgroup_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
class ContractconfiggroupProductgroup extends mfBaseModel {
|
||||
private $productgroup;
|
||||
private $contractconfiggroup;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($name == "productgroup") {
|
||||
$this->productgroup = new Productgroup($this->productgroup_id);
|
||||
return $this->productgroup;
|
||||
}
|
||||
|
||||
if($name == "contractconfiggroup") {
|
||||
$this->contractconfiggroup = new Contractconfiggroup($this->contractconfiggroup_id);
|
||||
return $this->contractconfiggroup;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
if($this->$name->id) {
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
class ContractconfiggroupProductgroupModel {
|
||||
public $productgroup_id;
|
||||
public $contractconfiggroup_id;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new ContractconfiggroupProductgroup();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$model ->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
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 getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("ContractconfiggroupProductgroup", "*", "1=1");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new ContractconfiggroupProductgroup($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("ContractconfiggroupProductgroup", "*", "$where ORDER BY productgroup_id, contractconfiggroup_id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ContractconfiggroupProductgroup($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function search($filter) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("ContractconfiggroupProductgroup", "*", "$where ORDER BY productgroup_id, contractconfiggroup_id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new ContractconfiggroupProductgroup($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("productgroup_id", $filter)) {
|
||||
$productgroup_id = $filter['productgroup_id'];
|
||||
if(is_numeric($productgroup_id)) {
|
||||
$where .= " AND productgroup_id=$productgroup_id";
|
||||
} elseif(is_array($productgroup_id) && count($productgroup_id)) {
|
||||
$where .= " AND productgroup_id IN (". implode(",", $productgroup_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("contractconfiggroup_id", $filter)) {
|
||||
$contractconfiggroup_id = $filter['contractconfiggroup_id'];
|
||||
if(is_numeric($contractconfiggroup_id)) {
|
||||
$where .= " AND contractconfiggroup_id=$contractconfiggroup_id";
|
||||
} elseif(is_array($contractconfiggroup_id) && count($contractconfiggroup_id)) {
|
||||
$where .= " AND contractconfiggroup_id IN (". implode(",", $contractconfiggroup_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,15 +18,37 @@ class DashboardController extends mfBaseController {
|
||||
|
||||
|
||||
protected function testAction() {
|
||||
$sql = "SELECT tt_preorder.* FROM `thetool_live`.Preorder tt_preorder
|
||||
LEFT JOIN `thetool_addressdb`.view_hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.hausnummer_id)
|
||||
WHERE 1=1 AND deleted=0 AND preordercampaign_id=1 AND (adb_hausnummer.gemeinde like '%stift%' OR adb_hausnummer.plz like '%stift%' OR adb_hausnummer.strasse like '%stift%')
|
||||
ORDER By lastname, firstname";
|
||||
$res = $this->db()->query($sql);
|
||||
if($this->db()->num_rows($res)) {
|
||||
$data = $this->db()->fetch_object($res);
|
||||
var_dump($data);exit;
|
||||
var_dump(ADBWohneinheitModel::count(["hausnummer_id" => 1772369]));
|
||||
exit;
|
||||
}
|
||||
|
||||
protected function colorAction() {
|
||||
|
||||
foreach(TT_CABLE_COLORS as $name => $color) {
|
||||
if(!$color['two-color']) continue;
|
||||
$hex = $color['hex'];
|
||||
$hexfg = $color['hexfg'];
|
||||
$hex2 = $color['hex2'];
|
||||
$hexfg2 = $color['hexfg2'];
|
||||
$r = $color['r'];
|
||||
$g = $color['g'];
|
||||
$b = $color['b'];
|
||||
$r2 = $color['r2'];
|
||||
$g2 = $color['g2'];
|
||||
$b2 = $color['b2'];
|
||||
|
||||
|
||||
$class = ".btn-outline-".$name." {
|
||||
color: #$hexfg;
|
||||
border-left-color: #$hex;
|
||||
border-top-color: #$hex;
|
||||
border-right-color: #$hex2;
|
||||
border-bottom-color: #$hex2;
|
||||
background: linear-gradient(90deg, rgba($r,$g,$b,.5) 0%, rgba($r,$g,$b,.5) 50%, rgba($r2,$g2,$b2,.5) 50%, rgba($r2,$g2,$b2,.5) 100%);
|
||||
}";
|
||||
echo "<pre>$class</pre>\n";
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
protected function pdfAction() {
|
||||
@@ -72,8 +94,8 @@ class DashboardController extends mfBaseController {
|
||||
$email->setBody($body);
|
||||
$email->setFrom($from, $from_name);
|
||||
$email->setTo($to);
|
||||
$email->setHeader("X-xinon-oid", $order->id);
|
||||
$email->setHeader("X-xinon-pid", $product->id);
|
||||
$email->setHeader("X-".MFAPPNAME."-oid", $order->id);
|
||||
$email->setHeader("X-".MFAPPNAME."-pid", $product->id);
|
||||
$email->addAttachment($pdfpath, null, $pdfname, "application/pdf");
|
||||
$email->send();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ class Emailnotification {
|
||||
private $headers = [];
|
||||
private $subject;
|
||||
private $body;
|
||||
private $html;
|
||||
private $from_name = false;
|
||||
private $email_from = false;
|
||||
private $email_to = false;
|
||||
@@ -14,7 +15,7 @@ class Emailnotification {
|
||||
|
||||
public function __construct() {
|
||||
$this->headers = [
|
||||
'X-Mailer' => 'XINON Mailer',
|
||||
'X-Mailer' => MFAPPNAME.' Mailer',
|
||||
];
|
||||
|
||||
$this->email_from = TT_OUTGOING_EMAIL;
|
||||
@@ -52,6 +53,10 @@ class Emailnotification {
|
||||
$this->body = $body;
|
||||
}
|
||||
|
||||
public function setHtmlBody($html) {
|
||||
$this->html = $html;
|
||||
}
|
||||
|
||||
public function setFrom($email, $name = false) {
|
||||
$this->email_from = $email;
|
||||
$this->from_name = $name;
|
||||
@@ -65,7 +70,7 @@ class Emailnotification {
|
||||
if(!$this->email_to) {
|
||||
return false;
|
||||
}
|
||||
if(!$this->body) {
|
||||
if(!$this->body && !$this->html) {
|
||||
return false;
|
||||
}
|
||||
if(!is_array($this->headers) || !count($this->headers)) {
|
||||
@@ -75,14 +80,15 @@ class Emailnotification {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$this->headers['Subject']) {
|
||||
if(!array_key_exists("Subject", $this->headers) || !$this->headers['Subject']) {
|
||||
$this->setHeader("Subject", $this->subject);
|
||||
}
|
||||
|
||||
if(!$this->headers['From'] && $this->from_name) {
|
||||
if((!array_key_exists("From", $this->headers) || !$this->headers['From']) && $this->from_name) {
|
||||
$this->headers['From'] = '"'.$this->from_name.'" <'.$this->email_from.'>';
|
||||
}
|
||||
|
||||
$log = mfLoghandler::singleton();
|
||||
|
||||
//var_dump($this);exit;
|
||||
|
||||
@@ -92,8 +98,13 @@ class Emailnotification {
|
||||
$mimeparams['head_charset']="utf-8";
|
||||
|
||||
$mime = new Mail_mime();
|
||||
$mime->setTXTBody($this->body);
|
||||
|
||||
if($this->body) {
|
||||
$mime->setTXTBody($this->body);
|
||||
}
|
||||
if($this->html) {
|
||||
$mime->setHTMLBody($this->html);
|
||||
}
|
||||
|
||||
//var_dump($this->attachments);exit;
|
||||
|
||||
if(count($this->attachments)) {
|
||||
@@ -108,6 +119,7 @@ class Emailnotification {
|
||||
|
||||
$body = $mime->get($mimeparams);
|
||||
$headers = $mime->headers($this->headers);
|
||||
//$log->debug(print_r($headers, true));
|
||||
|
||||
$mail =& Mail::factory('mail', ["-f ".$this->email_from]);
|
||||
$mail->send($this->email_to, $headers, $body);
|
||||
|
||||
@@ -15,7 +15,11 @@ class File extends mfBaseModel {
|
||||
$id = $this->id;
|
||||
|
||||
// delete file in store
|
||||
$path = MFUPLOAD_FILE_SAVE_PATH."/documents/".$this->store_filename;
|
||||
if($this->subfolder) {
|
||||
$path = MFUPLOAD_FILE_SAVE_PATH."/".$this->subfolder."/".$this->store_filename;
|
||||
} else {
|
||||
$path = MFUPLOAD_FILE_SAVE_PATH."/".$this->store_filename;
|
||||
}
|
||||
if(!unlink($path)) {
|
||||
$this->log->warn(__CLASS__."::delete(): Error unlinking file ($path)");
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ class FileModel {
|
||||
public $store_filename;
|
||||
public $orig_filename;
|
||||
public $subfolder;
|
||||
public $mimetype;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
@@ -66,7 +67,7 @@ class FileModel {
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
@@ -100,6 +100,17 @@ class NetworkController extends mfBaseController {
|
||||
return $this->add();
|
||||
}
|
||||
|
||||
$netaddress = NetworkAddressModel::getFirst(["network_id" => $new_id, "address_id" => $network->owner_id, "addresstype" => "netowner"]);
|
||||
if(!$netaddress) {
|
||||
$netaddress = NetworkAddressModel::create([
|
||||
'network_id' => $new_id,
|
||||
'address_id' => $network->owner_id,
|
||||
'type' => "netowner"
|
||||
]);
|
||||
//var_dump($netaddress);exit;
|
||||
$netaddress->save();
|
||||
}
|
||||
|
||||
|
||||
$this->layout()->setFlash("Netzgebiet erfolgreich gespeichert.", "success");
|
||||
$this->redirect("Network", "Edit", ['id' => $new_id]);
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
<?php
|
||||
|
||||
class NetworkModel {
|
||||
public $name = null;
|
||||
public $owner_id = null;
|
||||
public $sytemowner_action_status = null;
|
||||
public $note = null;
|
||||
public $name;
|
||||
public $owner_id ;
|
||||
public $adb_netzgebiet_id;
|
||||
public $sytemowner_action_status;
|
||||
public $note;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
public $create_by;
|
||||
public $edit_by;
|
||||
public $create;
|
||||
public $edit;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
@@ -99,10 +100,27 @@ class NetworkModel {
|
||||
$where = "1=1 ";
|
||||
|
||||
//var_dump($filter);exit;
|
||||
|
||||
if(array_key_exists("name", $filter)) {
|
||||
$name = FronkDB::singleton()->escape($filter['name']);
|
||||
if($name) {
|
||||
$where .= " AND Network.`name` = '$name'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("name%", $filter)) {
|
||||
$name = FronkDB::singleton()->escape($filter['name%']);
|
||||
if($name) {
|
||||
$where .= " AND Network.`name` LIKE '$name%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("owner_id", $filter)) {
|
||||
$ownerid= $filter['owner_id'];
|
||||
if(is_numeric($ownerid)) {
|
||||
$where .= " AND owner_id=$ownerid";
|
||||
$owner_id = $filter['owner_id'];
|
||||
if(is_numeric($owner_id)) {
|
||||
$where .= " AND owner_id=$owner_id";
|
||||
} elseif(is_array($owner_id) && count($owner_id)) {
|
||||
$where .= " AND owner_id IN (". implode(",", $owner_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,11 @@ class NetworkAddressModel {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("NetworkAddress", "*", "$where ORDER BY `type`");
|
||||
$sql = "SELECT * FROM NetworkAddress WHERE $where ORDER BY `type`";
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
$res = $db->query($sql);
|
||||
|
||||
//$res = $db->select("NetworkAddress", "*", "$where ORDER BY `type`");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new NetworkAddress($data);
|
||||
@@ -84,7 +88,9 @@ class NetworkAddressModel {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("NetworkAddress", "*", "$where ORDER BY `type`");
|
||||
$sql = "SELECT * FROM NetworkAddress WHERE $where ORDER BY `type`";
|
||||
$res = $db->query($sql);
|
||||
//$res = $db->select("NetworkAddress", "*", "$where ORDER BY `type`");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new NetworkAddress($data->id);
|
||||
@@ -112,23 +118,25 @@ class NetworkAddressModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(is_array($filter['addresstype']) && count($filter['addresstype'])) {
|
||||
$at = $filter['addresstype'];
|
||||
$in = [];
|
||||
foreach(TT_ROLES as $role) {
|
||||
if(in_array($role, $at)) {
|
||||
$role = $db->escape($role);
|
||||
$in[] = "NetworkAddress.type = '$role'";
|
||||
if(array_key_exists("addresstype", $filter)) {
|
||||
if(is_array($filter['addresstype'])) {
|
||||
$addresstypes = [];
|
||||
foreach(TT_ROLES as $role) {
|
||||
if(in_array($role, $filter['addresstype'])) {
|
||||
$addresstypes[] = $role;
|
||||
}
|
||||
}
|
||||
$where .= " AND NetworkAddress.type IN ('".implode("', '", $addresstypes)."')";
|
||||
} else {
|
||||
$addresstype = FronkDB::singleton()->escape($filter['addresstype']);
|
||||
if(in_array($addresstype, TT_ROLES)) {
|
||||
$where .= " AND NetworkAddress.type = '$addresstype'";
|
||||
}
|
||||
}
|
||||
|
||||
$or = "";
|
||||
if(count($in)) {
|
||||
$or = implode(" OR ", $in);
|
||||
$where .= " AND ( $or )";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ class Order extends mfBaseModel {
|
||||
private $contracts;
|
||||
private $terminations;
|
||||
private $journals;
|
||||
private $install_products;
|
||||
private $files;
|
||||
private $creator;
|
||||
private $editor;
|
||||
@@ -92,6 +93,68 @@ class Order extends mfBaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
public function sendSpinEmail() {
|
||||
$owner = $this->getProperty("owner");
|
||||
|
||||
$spin_pdf_template = "Emailtemplates/attachments/new_order_spin.pdf";
|
||||
$new_order_template = "Emailtemplates/customer/new_order";
|
||||
|
||||
$pdf_vars = [
|
||||
'order' => $this,
|
||||
'owner' => $owner
|
||||
];
|
||||
|
||||
|
||||
if(TT_CUSTOM_ORDER_PDF_PER_NETOWNER) {
|
||||
$terms = $this->getTerminations();
|
||||
if(is_array($terms) && count($terms) && $terms[0]->id) {
|
||||
$netowner = $terms[0]->building->network->owner;
|
||||
} else {
|
||||
$netowner = new Address(TT_CUSTOM_ORDER_PDF_DEFAULT_OWNER_ID);
|
||||
}
|
||||
$pdf_vars['netowner'] = $netowner;
|
||||
}
|
||||
|
||||
// render service pin PDF
|
||||
$pdf = new PdfForm($spin_pdf_template, $pdf_vars);
|
||||
$pdfpath = $pdf->render();
|
||||
$tvalue = $pdf->getReturnedValues();
|
||||
$pdfname = $tvalue['filename'];
|
||||
|
||||
// send email to customer
|
||||
// TODO template rendern auslagern nach Emailtempate klasse
|
||||
$tpl = new Layout();
|
||||
$tpl->setTemplate($new_order_template);
|
||||
|
||||
foreach($pdf_vars as $name => $val) {
|
||||
$tpl->set($name, $val);
|
||||
}
|
||||
|
||||
$body = $tpl->render();
|
||||
$values = $tpl->getReturnedValue();
|
||||
|
||||
$subject = $values['subject'];
|
||||
$from = $values['from_email'];
|
||||
$from_name = $values['from_email_name'];
|
||||
$to = $owner->email;
|
||||
|
||||
if(!$subject || !$from || !$from_name || !$to) {
|
||||
$this->log->warn("Service PIN Email not sent. (subject: '$subject', from: '$from', from_email: '$from_email', to: '$to')");
|
||||
} else {
|
||||
$email = new Emailnotification();
|
||||
$email->setSubject($subject);
|
||||
$email->setBody($body);
|
||||
$email->setFrom($from, $from_name);
|
||||
$email->setTo($to);
|
||||
$email->setHeader("X-".MFAPPNAME."-Oid", $this->id);
|
||||
$email->addAttachment($pdfpath, null, $pdfname, "application/pdf");
|
||||
$email->send();
|
||||
$this->log->info(__CLASS__."::sendSpinEmail(): Sending new SPIN for ".$owner->getCompanyOrName()." (".$owner->id.")");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function sendIntBillinfoEmail() {
|
||||
// TODO template rendern auslagern nach Emailtempate klasse
|
||||
$tpl = new Layout();
|
||||
@@ -118,7 +181,7 @@ class Order extends mfBaseModel {
|
||||
$email->setBody($body);
|
||||
$email->setFrom($from, $from_name);
|
||||
$email->setTo($to);
|
||||
$email->setHeader("X-xinon-oid", $this->id);
|
||||
$email->setHeader("X-".MFAPPNAME."-oid", $this->id);
|
||||
$email->send();
|
||||
|
||||
return true;
|
||||
@@ -157,7 +220,7 @@ class Order extends mfBaseModel {
|
||||
$email->setBody($body);
|
||||
$email->setFrom($from, $from_name);
|
||||
$email->setTo($to);
|
||||
$email->setHeader("X-Xinon-Oid", $this->id);
|
||||
$email->setHeader("X-".MFAPPNAME."-Oid", $this->id);
|
||||
$email->send();
|
||||
|
||||
return true;
|
||||
@@ -212,8 +275,8 @@ class Order extends mfBaseModel {
|
||||
$email->setBody($body);
|
||||
$email->setFrom($from, $from_name);
|
||||
$email->setTo($to);
|
||||
$email->setHeader("X-Xinon-Oid", $this->id);
|
||||
$email->setHeader("X-Xinon-OFid", $file->id);
|
||||
$email->setHeader("X-".MFAPPNAME."-Oid", $this->id);
|
||||
$email->setHeader("X-".MFAPPNAME."-OFid", $file->id);
|
||||
$email->addAttachment($filepath, null, $file->file->filename, $mimetype);
|
||||
$email->send();
|
||||
$this->log->info(__CLASS__."::save(): Sending Order Fileupload Email to '$to'");
|
||||
@@ -269,6 +332,21 @@ class Order extends mfBaseModel {
|
||||
return $this->products;
|
||||
}
|
||||
|
||||
if($name == "install_products") {
|
||||
$this->install_products = [];
|
||||
|
||||
foreach($this->getProperty("products") as $orderproduct) {
|
||||
$product = $orderproduct->product;
|
||||
//$atrribs = $product->attributes;
|
||||
//var_dump($attribs);exit;
|
||||
if(is_array($product->attributes) && array_key_exists("vot", $product->attributes) && $product->attributes["vot"] == 1) {
|
||||
$this->install_products[] = $product;
|
||||
}
|
||||
}
|
||||
//var_dump($this->install_products);exit;
|
||||
return $this->install_products;
|
||||
}
|
||||
|
||||
if($name == "customer_type") {
|
||||
$this->customer_type = "residential";
|
||||
foreach($this->getProperty("products") as $order_product) {
|
||||
|
||||
@@ -67,9 +67,12 @@ class OrderController extends mfBaseController {
|
||||
}
|
||||
}
|
||||
|
||||
$filter = [];
|
||||
$rfilter = $this->request->filter;
|
||||
if(!$rfilter) {
|
||||
$rfilter = [];
|
||||
}
|
||||
|
||||
$this->layout->set("filter", $this->request->filter);
|
||||
$this->layout->set("filter", $rfilter);
|
||||
$filter = $this->getPreparedFilter($this->request->filter);
|
||||
|
||||
// pagination defaults
|
||||
@@ -792,14 +795,16 @@ class OrderController extends mfBaseController {
|
||||
}
|
||||
|
||||
// add techcontact as AddressLink to owner if not exists
|
||||
$link = AddressLinkModel::getFirst(['address_id' => $techcontact->id, 'origin_address_id' => $order->owner_id, 'type' => "techcontact"]);
|
||||
if(!$link) {
|
||||
$linkdata = [];
|
||||
$linkdata['address_id'] = $techcontact->id;
|
||||
$linkdata['origin_address_id'] = $order->owner_id;
|
||||
$linkdata['type'] = "techcontact";
|
||||
$link = AddressLinkModel::create($linkdata);
|
||||
$link->save();
|
||||
if($techcontact->id) {
|
||||
$link = AddressLinkModel::getFirst(['address_id' => $techcontact->id, 'origin_address_id' => $order->owner_id, 'type' => "techcontact"]);
|
||||
if(!$link) {
|
||||
$linkdata = [];
|
||||
$linkdata['address_id'] = $techcontact->id;
|
||||
$linkdata['origin_address_id'] = $order->owner_id;
|
||||
$linkdata['type'] = "techcontact";
|
||||
$link = AddressLinkModel::create($linkdata);
|
||||
$link->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -868,6 +873,7 @@ class OrderController extends mfBaseController {
|
||||
continue;
|
||||
}
|
||||
$product_data['termination_id'] = $p['termination_id'];
|
||||
$order_termination_id = $p['termination_id'];
|
||||
} else {
|
||||
$product_data['termination_id'] = null;
|
||||
}
|
||||
@@ -905,59 +911,28 @@ class OrderController extends mfBaseController {
|
||||
$owner->save();
|
||||
}
|
||||
}
|
||||
|
||||
// generate and send Service PIN
|
||||
// only if owner_id wasn't changed
|
||||
if(!$owner->spin && (!property_exists($order->_old_data, "owner_id") || $order->owner_id == $order->_old_data->owner_id)) {
|
||||
$this->log->debug(__CLASS__."::save(): creating new SPIN for ".$owner->getCompanyOrName()." (".$owner->id.")");
|
||||
$spin = $owner->generateServicePin();
|
||||
if($spin && !AddressModel::search(['spin' => $spin])) {
|
||||
$owner->spin = $spin;
|
||||
if($owner->save()) {
|
||||
|
||||
// render service pin PDF
|
||||
$pdf = new PdfForm("Emailtemplates/attachments/new_order_spin.pdf", ["owner" => $owner, "order" => $order]);
|
||||
$pdfpath = $pdf->render();
|
||||
$tvalue = $pdf->getReturnedValues();
|
||||
$pdfname = $tvalue['filename'];
|
||||
|
||||
// send email to customer
|
||||
// TODO template rendern auslagern nach Emailtempate klasse
|
||||
$tpl = new Layout();
|
||||
$tpl->setTemplate("Emailtemplates/customer/new_order");
|
||||
$tpl->set("owner", $owner);
|
||||
$body = $tpl->render();
|
||||
|
||||
$values = $tpl->getReturnedValue();
|
||||
|
||||
$subject = $values['subject'];
|
||||
$from = $values['from_email'];
|
||||
$from_name = $values['from_email_name'];
|
||||
$to = $owner->email;
|
||||
|
||||
if(!$subject || !$from || !$from_name || !$to) {
|
||||
$this->log->warn("Service PIN Email not sent. (subject: '$subject', from: '$from', from_email: '$from_email', to: '$to')");
|
||||
} else {
|
||||
$email = new Emailnotification();
|
||||
$email->setSubject($subject);
|
||||
$email->setBody($body);
|
||||
$email->setFrom($from, $from_name);
|
||||
$email->setTo($to);
|
||||
$email->setHeader("X-Xinon-Oid", $order->id);
|
||||
$email->setHeader("X-Xinon-Pid", $product->id);
|
||||
$email->addAttachment($pdfpath, null, $pdfname, "application/pdf");
|
||||
$email->send();
|
||||
$this->log->info(__CLASS__."::save(): Sending new SPIN for ".$owner->getCompanyOrName()." (".$owner->id.")");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
$this->log->debug(__CLASS__."::save(): NOT creating new SPIN for ".$owner->getCompanyOrName()." (".$owner->id."): SPIN exists or owner of Order was changed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// generate and send Service PIN, only if:
|
||||
// - owner does not have a Service PIN yet
|
||||
// - there are no external products
|
||||
// - owner_id was not set before or owner_id wasn't changed
|
||||
|
||||
// TODO: move this to Order class
|
||||
if(!$ext_products && !$owner->spin && (!property_exists($order->_old_data, "owner_id") || $order->owner_id == $order->_old_data->owner_id)) {
|
||||
$this->log->debug(__CLASS__."::save(): creating new SPIN for ".$owner->getCompanyOrName()." (".$owner->id.")");
|
||||
$spin = $owner->generateServicePin();
|
||||
if($spin && !AddressModel::search(['spin' => $spin])) {
|
||||
$owner->spin = $spin;
|
||||
if($owner->save()) {
|
||||
$order->sendSpinEmail();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->log->debug(__CLASS__."::save(): NOT creating new SPIN for ".$owner->getCompanyOrName()." (".$owner->id."): SPIN exists or owner of Order was changed or external products");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//var_dump($_FILES['OrderFileUpload']);exit;
|
||||
@@ -1210,8 +1185,24 @@ class OrderController extends mfBaseController {
|
||||
$this->redirect("Order");
|
||||
}
|
||||
|
||||
$pdf_vars = [
|
||||
'order' => $order,
|
||||
'owner' => $owner
|
||||
];
|
||||
|
||||
|
||||
if(TT_CUSTOM_ORDER_PDF_PER_NETOWNER) {
|
||||
$terms = $order->terminations;
|
||||
if(is_array($terms) && count($terms) && $terms[0]->id) {
|
||||
$netowner = $terms[0]->building->network->owner;
|
||||
} else {
|
||||
$netowner = new Address(TT_CUSTOM_ORDER_PDF_DEFAULT_OWNER_ID);
|
||||
}
|
||||
$pdf_vars['netowner'] = $netowner;
|
||||
}
|
||||
|
||||
// render service pin PDF
|
||||
$pdf = new PdfForm("Emailtemplates/attachments/new_order_spin.pdf", ["owner" => $owner, "order" => $order]);
|
||||
$pdf = new PdfForm("Emailtemplates/attachments/new_order_spin.pdf", $pdf_vars);
|
||||
$pdfpath = $pdf->render();
|
||||
$tvalue = $pdf->getReturnedValues();
|
||||
$pdfname = $tvalue['filename'];
|
||||
@@ -1239,45 +1230,13 @@ class OrderController extends mfBaseController {
|
||||
$this->redirect("Order");
|
||||
}
|
||||
|
||||
// render service pin PDF
|
||||
$pdf = new PdfForm("Emailtemplates/attachments/new_order_spin.pdf", ["owner" => $owner, "order" => $order]);
|
||||
$pdfpath = $pdf->render();
|
||||
$tvalue = $pdf->getReturnedValues();
|
||||
$pdfname = $tvalue['filename'];
|
||||
|
||||
// TODO template rendern auslagern nach Emailtempate klasse
|
||||
$tpl = new Layout();
|
||||
$tpl->setTemplate("Emailtemplates/customer/new_order");
|
||||
$tpl->set("owner", $owner);
|
||||
$body = $tpl->render();
|
||||
|
||||
$values = $tpl->getReturnedValue();
|
||||
|
||||
//var_dump($values);exit;
|
||||
|
||||
$subject = $values['subject'];
|
||||
$from = $values['from_email'];
|
||||
$from_name = $values['from_email_name'];
|
||||
$to = $owner->email;
|
||||
|
||||
if(!$subject || !$from || !$from_name || !$to) {
|
||||
$this->log->warn("Service PIN Email not sent. (subject: '$subject', from: '$from', from_email: '$from_name', to: '$to')");
|
||||
$this->layout()->setFlash("Beim Email versenden ist ein Fehler aufgetreten.", "error");
|
||||
$this->redirect("Order");
|
||||
} else {
|
||||
$email = new Emailnotification();
|
||||
$email->setSubject($subject);
|
||||
$email->setBody($body);
|
||||
$email->setFrom($from, $from_name);
|
||||
$email->setTo($to);
|
||||
$email->setHeader("X-Xinon-Oid", $order->id);
|
||||
$email->setHeader("X-Xinon-Pid", $product->id);
|
||||
$email->addAttachment($pdfpath, null, $pdfname, "application/pdf");
|
||||
$email->send();
|
||||
|
||||
if($order->sendSpinEmail()) {
|
||||
$this->layout()->setFlash("Service PIN wurde erfolgreich versendet.", "success");
|
||||
$this->redirect("Order");
|
||||
} else {
|
||||
$this->layout()->setFlash("Fehler beim SPIN Versand!", "success");
|
||||
}
|
||||
|
||||
$this->redirect("Order");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
class Preorder extends mfBaseModel {
|
||||
protected $forcestr = ['street','company','zip','phone','email','note'];
|
||||
private $status;
|
||||
private $campaign;
|
||||
private $partner;
|
||||
private $building;
|
||||
@@ -34,6 +35,94 @@ class Preorder extends mfBaseModel {
|
||||
return $ucode;
|
||||
}
|
||||
|
||||
public function getApiArray() {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$hausnummer = $this->getProperty("adb_hausnummer");
|
||||
$wohneinheit = $this->getProperty("adb_wohneinheit");
|
||||
$campaign = $this->getProperty("campaign");
|
||||
|
||||
|
||||
$a = [];
|
||||
$a['code'] = strtoupper($this->ucode);
|
||||
$a['oaid'] = $this->oaid;
|
||||
$a['status'] = $this->getProperty("status")->getApiArray();
|
||||
$a['connectionType'] = $this->connection_type;
|
||||
$a['connectionCount'] = ($this->connection_count) ? (int)$this->connection_count : 1;
|
||||
$a['isAdditionalOrder'] = ($this->is_additional_order) ? true : false;
|
||||
$a['technology'] = ($this->technology) ? $this->technology : null;
|
||||
$a['patchposition'] = ($this->patchposition) ? $this->patchposition : null;
|
||||
$a['preorderType'] = $this->type;
|
||||
$a['acceptMarketing'] = ($this->accept_marketing) ? true : false;
|
||||
$a['acceptAgb'] = ($this->accept_agb) ? true : false;
|
||||
$a['acceptDsgvo'] = ($this->accept_dsgvo) ? true : false;
|
||||
$a['acceptWithdrawal'] = ($this->accept_withdrawal) ? true : false;
|
||||
$a['address_info'] = ($this->address_info) ? $this->address_info : null;
|
||||
|
||||
$address = [];
|
||||
$address['cluster_id'] = $hausnummer->netzgebiet->extref;
|
||||
$address['street'] = $hausnummer->strasse->name;
|
||||
$address['housenumber'] = $hausnummer->hausnummer;
|
||||
$address['zip'] = $hausnummer->plz->plz;
|
||||
$address['city'] = $hausnummer->strasse->gemeinde->name;
|
||||
$address['municipality'] = "";
|
||||
$address['district'] = $hausnummer->ortschaft->name;
|
||||
$address['block'] = ($wohneinheit->block) ? $wohneinheit->block : null;
|
||||
$address['stock'] = ($wohneinheit->stock) ? $wohneinheit->stock : null;
|
||||
$address['stiege'] = ($wohneinheit->stiege) ? $wohneinheit->stiege : null;
|
||||
$address['tuer'] = ($wohneinheit->tuer) ? $wohneinheit->tuer : null;
|
||||
$address['unit_string'] = ($wohneinheit->bezeichner) ? $wohneinheit->bezeichner : null;
|
||||
$address['is_shipping'] = ($this->shipping_address == "address") ? true : false;
|
||||
|
||||
if($campaign->district_is_city) {
|
||||
$address['city'] = $hausnummer->ortschaft->name;
|
||||
$address['municipality'] = $hausnummer->strasse->gemeinde->name;
|
||||
} else {
|
||||
unset($address['municipality']);
|
||||
}
|
||||
|
||||
$customer = [];
|
||||
$customer['company'] = ($this->company) ? $this->company : null;
|
||||
$customer['uid'] = ($this->uid) ? $this->uid : null;
|
||||
$customer['firstnam'] = ($this->firstname) ? $this->firstname : null;
|
||||
$customer['lastname'] = ($this->lastname) ? $this->lastname : null;
|
||||
$customer['street'] = ($this->street) ? $this->street : null;
|
||||
$customer['housenumber'] = ($this->housenumber) ? $this->housenumber : null;
|
||||
$customer['zip'] = ($this->zip) ? $this->zip : null;
|
||||
$customer['city'] = ($this->city) ? $this->city : null;
|
||||
$customer['block'] = ($this->block) ? $this->block : null;
|
||||
$customer['stock'] = ($this->stock) ? $this->stock : null;
|
||||
$customer['stiege'] = ($this->stiege) ? $this->stiege : null;
|
||||
$customer['tuer'] = ($this->tuer) ? $this->tuer : null;
|
||||
$customer['unit_string'] = ($this->unit_string) ? $this->unit_string : null;
|
||||
$customer['phone'] = ($this->phone) ? $this->phone : null;
|
||||
$customer['email'] = ($this->email) ? $this->email : null;
|
||||
|
||||
$a['address'] = $address;
|
||||
$a['customer'] = $customer;
|
||||
|
||||
$a['addonServices'] = null;
|
||||
if($this->addon_services) {
|
||||
$addon_services = json_decode($this->addon_services);
|
||||
if(json_last_error() === JSON_ERROR_NONE) {
|
||||
$a['addonServices'] = $addon_services;
|
||||
}
|
||||
}
|
||||
|
||||
$a['additionalData'] = null;
|
||||
if($this->addon_data) {
|
||||
$addon_data = json_decode($this->addon_data);
|
||||
if(json_last_error() === JSON_ERROR_NONE) {
|
||||
$a['additionalData'] = $addon_data;
|
||||
}
|
||||
}
|
||||
|
||||
return $a;
|
||||
}
|
||||
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
@@ -42,6 +131,17 @@ class Preorder extends mfBaseModel {
|
||||
return $this->campaign;
|
||||
}
|
||||
|
||||
if($name == "status") {
|
||||
$this->status = mfValuecache::singleton()->get("mfObjectmodel-Preorderstatus-".$this->status_id);
|
||||
if(!$this->status) {
|
||||
$this->status = new Preorderstatus($this->status_id);
|
||||
if($this->status->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-Preorderstatus-".$this->status_id, $this->status);
|
||||
}
|
||||
}
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
if($name == "partner") {
|
||||
$this->partner = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->partner_id);
|
||||
if(!$this->partner) {
|
||||
@@ -74,6 +174,9 @@ class Preorder extends mfBaseModel {
|
||||
return $this->adb_wohneinheit;
|
||||
}
|
||||
|
||||
if($name == "addon_services") {
|
||||
|
||||
}
|
||||
|
||||
if($name == "creator") {
|
||||
$user = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||
|
||||
@@ -9,7 +9,7 @@ class PreorderController extends mfBaseController {
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
if(!$me->is(["Admin", "salespartner"])) {
|
||||
if(!$me->is(["Admin", "netowner", "salespartner"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
@@ -37,21 +37,49 @@ class PreorderController extends mfBaseController {
|
||||
$pagination['start'] = intval($this->request->s);
|
||||
}
|
||||
|
||||
$campaign_filter = [];
|
||||
$preorder_filter = $filter;
|
||||
$my_campaigns = [];
|
||||
$my_campaign_ids = [];
|
||||
|
||||
if($filter['preordercampaign_id']) {
|
||||
$campaign_id = $filter['preordercampaign_id'];
|
||||
if(is_numeric($campaign_id) && $campaign_id > 0) {
|
||||
$campaign = new Preordercampaign($campaign_id);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
if($this->me->is("Admin")) {
|
||||
if($filter['preordercampaign_id']) {
|
||||
$this->layout()->set("campaign", new Preordercampaign($filter['preordercampaign_id']));
|
||||
} else {
|
||||
$my_campaigns = PreordercampaignModel::getAll();
|
||||
}
|
||||
$this->layout()->set("my_campaigns", PreordercampaignModel::getAll());
|
||||
} else {
|
||||
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
|
||||
//var_dump($my_networks);exit;
|
||||
|
||||
foreach($my_networks as $network) {
|
||||
foreach(PreordercampaignModel::search(['network_id' => $network->id]) as $campaign) {
|
||||
$my_campaigns[] = $campaign;
|
||||
if(!in_array($campaign->id, $my_campaign_ids)) $my_campaign_ids[] = $campaign->id;
|
||||
}
|
||||
}
|
||||
//var_dump($my_network_ids,$my_campaign_ids);exit;
|
||||
$this->layout()->set("my_campaigns", $my_campaigns);
|
||||
|
||||
if($filter['preordercampaign_id'] && in_array($filter['preordercampaign_id'], $my_campaign_ids)) {
|
||||
$campaign_id = $filter['preordercampaign_id'];
|
||||
if(is_numeric($campaign_id) && $campaign_id > 0) {
|
||||
$campaign = new Preordercampaign($campaign_id);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
}
|
||||
} else {
|
||||
$filter['preordercampaign_id'] = $my_campaign_ids;
|
||||
}
|
||||
}
|
||||
//var_dump($filter);exit;
|
||||
|
||||
$pagination['maxItems'] = PreorderModel::count($filter);
|
||||
if($filter['addon_services']) {
|
||||
$pagination['maxItems'] = PreorderModel::countOrderedAddonservices($filter);
|
||||
$preorders = PreorderModel::searchOrderedAddonservices($filter, $pagination);
|
||||
} else {
|
||||
$pagination['maxItems'] = PreorderModel::count($filter);
|
||||
$preorders = PreorderModel::search($filter, $pagination);
|
||||
}
|
||||
$this->layout()->set("pagination", $pagination);
|
||||
|
||||
$preorders = PreorderModel::search($filter, $pagination);
|
||||
$this->layout()->set("preorders", $preorders);
|
||||
|
||||
}
|
||||
@@ -75,12 +103,27 @@ class PreorderController extends mfBaseController {
|
||||
|
||||
if(array_key_exists("address", $filter)) {
|
||||
$address = $this->db()->escape($filter['address']);
|
||||
$new_filter['add-where'] = " AND (adb_hausnummer.gemeinde like '%$address%' OR adb_hausnummer.plz like '%$address%' OR adb_hausnummer.strasse like '%$address%')";
|
||||
$new_filter['add-where'] .= " AND (adb_hausnummer.gemeinde like '%$address%' OR adb_hausnummer.plz like '%$address%' OR adb_hausnummer.strasse like '%$address%')";
|
||||
}
|
||||
|
||||
if(array_key_exists("kunde", $filter)) {
|
||||
$kunde = $this->db()->escape($filter['kunde']);
|
||||
$new_filter['add-where'] = " AND (firstname like '%$kunde%' OR lastname like '%$kunde%' OR street like '%$kunde%' OR zip like '%$kunde%' OR city like '%$kunde%')";
|
||||
$new_filter['add-where'] .= " AND (company like '%$kunde%' OR firstname like '%$kunde%' OR lastname like '%$kunde%' OR street like '%$kunde%' OR zip like '%$kunde%' OR city like '%$kunde%')";
|
||||
}
|
||||
|
||||
|
||||
$new_filter['addon_services'] = false;
|
||||
if(array_key_exists("addon_services", $filter) && $filter['addon_services'] == 1) {
|
||||
$new_filter['addon_services'] = true;
|
||||
}
|
||||
|
||||
if(array_key_exists("address_source", $filter)) {
|
||||
if($filter['address_source'] == "manual") {
|
||||
$new_filter['address_created'] = true;
|
||||
}
|
||||
if($filter['address_source'] == "addressdb") {
|
||||
$new_filter['address_created'] = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,7 +164,7 @@ class PreorderController extends mfBaseController {
|
||||
//var_dump($products);exit;
|
||||
$this->layout()->set("products", $products);
|
||||
|
||||
$partners = AddressModel::search(['addresstype' => ['salespartner']]);
|
||||
$partners = AddressModel::search(['addresstype' => ['netowner','salespartner']]);
|
||||
$this->layout()->set("partners", $partners);
|
||||
}
|
||||
|
||||
@@ -149,7 +192,7 @@ class PreorderController extends mfBaseController {
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
//var_dump($r);
|
||||
//var_dump($r);exit;
|
||||
|
||||
/*
|
||||
* add or edit
|
||||
@@ -232,28 +275,33 @@ class PreorderController extends mfBaseController {
|
||||
$data['accept_marketing'] = 1;
|
||||
}
|
||||
|
||||
$data['price'] = ($r->price) ? $r->price : 0;
|
||||
$data['price_setup'] = ($r->price_setup) ? $r->price_setup : 0;
|
||||
$data['price_nne'] = ($r->price_nne) ? $r->price_nne : 0;
|
||||
$data['price_nbe'] = ($r->price_nbe) ? $r->price_nbe : 0;
|
||||
$data['price'] = ($r->price) ? Layout::commaToDot($r->price) : 0;
|
||||
$data['price_setup'] = ($r->price_setup) ? Layout::commaToDot($r->price_setup) : 0;
|
||||
$data['price_nne'] = ($r->price_nne) ? Layout::commaToDot($r->price_nne) : 0;
|
||||
$data['price_nbe'] = ($r->price_nbe) ? Layout::commaToDot($r->price_nbe) : 0;
|
||||
$data['billing_delay'] = ($r->billing_delay) ? $r->billing_delay : 0;
|
||||
|
||||
//var_dump($r->partner_id);exit;
|
||||
if($r->partner_id) {
|
||||
$data['partner_id'] = $r->partner_id;
|
||||
} else {
|
||||
$data['partner_id'] = null;
|
||||
}
|
||||
|
||||
$data['company'] = $r->company;
|
||||
$data['uid'] = $r->uid;
|
||||
$data['firstname'] = $r->firstname;
|
||||
$data['lastname'] = $r->lastname;
|
||||
$data['street'] = $r->street;
|
||||
$data['zip'] = $r->zip;
|
||||
$data['city'] = $r->city;
|
||||
$data['phone'] = $r->phone;
|
||||
$data['email'] = $r->email;
|
||||
$data['note'] = $r->note;
|
||||
$data['company'] = (trim($r->company)) ? trim($r->company) : null;
|
||||
$data['uid'] = (trim($r->uid)) ? trim($r->uid) : null;
|
||||
$data['firstname'] = (trim($r->firstname)) ? trim($r->firstname) : null;
|
||||
$data['lastname'] = (trim($r->lastname)) ? trim($r->lastname) : null;
|
||||
$data['street'] = (trim($r->street)) ? trim($r->street) : null;
|
||||
$data['housenumber'] = (trim($r->housenumber)) ? trim($r->housenumber) : null;
|
||||
$data['block'] = (trim($r->block)) ? trim($r->block) : null;
|
||||
$data['stiege'] = (trim($r->stiege)) ? trim($r->stiege) : null;
|
||||
$data['stock'] = (trim($r->stock)) ? trim($r->stock) : null;
|
||||
$data['tuer'] = (trim($r->tuer)) ? trim($r->tuer) : null;
|
||||
$data['zip'] = (trim($r->zip)) ? trim($r->zip) : null;
|
||||
$data['city'] = (trim($r->city)) ? trim($r->city) : null;
|
||||
$data['phone'] = (trim($r->phone)) ? trim($r->phone) : null;
|
||||
$data['email'] = (trim($r->email)) ? trim($r->email) : null;
|
||||
$data['note'] = (trim($r->note)) ? trim($r->note) : null;
|
||||
|
||||
$data['edit_by'] = $this->me->id;
|
||||
|
||||
@@ -263,16 +311,173 @@ class PreorderController extends mfBaseController {
|
||||
} else {
|
||||
$preorder->update($data);
|
||||
}
|
||||
|
||||
/*
|
||||
* validation
|
||||
*/
|
||||
|
||||
$campaign = new Preordercampaign($preorder->preordercampaign_id);
|
||||
if(!$campaign->id) {
|
||||
$this->layout()->setFlash("Keine Kampagne ausgewählt!", "error");
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
//var_dump($preorder, $r);exit;
|
||||
// handle new address creation
|
||||
if(!$preorder->adb_hausnummer_id) {
|
||||
// check if new address was submitted
|
||||
$this->log->debug("check if new address was submitted");
|
||||
if($r->new_address_street && $r->new_address_housenumber && $r->new_address_zip && $r->new_address_city && $r->new_address_district) {
|
||||
$city_search = trim($r->new_address_city);
|
||||
$district_search = trim($r->new_address_district);
|
||||
$zip_search = trim($r->new_address_zip);
|
||||
$street_search = trim($r->new_address_street);
|
||||
$housenumber_search = trim($r->new_address_housenumber);
|
||||
|
||||
$block = trim($r->new_address_block);
|
||||
$stiege = trim($r->new_address_stiege);
|
||||
$stock = trim($r->new_address_stock);
|
||||
$tuer = trim($r->new_address_tuer);
|
||||
|
||||
$preorder->new_address_city = $city_search;
|
||||
$preorder->new_address_district = $district_search;
|
||||
$preorder->new_address_zip = $zip_search;
|
||||
$preorder->new_address_street = $street_search;
|
||||
$preorder->new_address_housenumber = $housenumber_search;
|
||||
|
||||
|
||||
$netzgebiet_ids = [];
|
||||
foreach($campaign->salesclusters as $scluster) {
|
||||
$netzgebiet_ids[] = $scluster->id;
|
||||
}
|
||||
$netzgebiet_id = $netzgebiet_ids[0];
|
||||
if(!$netzgebiet_id) {
|
||||
$this->layout()->setFlash("Kann Adresse nicht updaten: Kampagne hat kein Netzgebiet", "error");
|
||||
$this->layout()->set("preorder", $preorder);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
return $this->addAction();
|
||||
}
|
||||
$netzgebiet = new ADBNetzgebiet($netzgebiet_id);
|
||||
if(!$netzgebiet->id) {
|
||||
$this->layout()->setFlash("Neztgebiet nicht gefunden", "error");
|
||||
$this->layout()->set("preorder", $preorder);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
$city = ADBGemeindeModel::getFirst(['name' => $city_search, 'netzgebiet_id' => $netzgebiet_id]);
|
||||
if(!$city) {
|
||||
$this->layout()->setFlash("Gemeinde nicht Adress-DB gefunden", "error");
|
||||
$this->layout()->set("preorder", $preorder);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
$district = ADBOrtschaftModel::getFirst(['name' => $district_search, 'netzgebiet_id' => $netzgebiet_id]);
|
||||
if(!$district) {
|
||||
$this->layout()->setFlash("Ortsteil nicht Adress-DB gefunden", "error");
|
||||
$this->layout()->set("preorder", $preorder);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
$zip = ADBPlzModel::getFirst(['plz' => $zip_search, 'gemeinde_id' => $city->id]);
|
||||
if(!$zip) {
|
||||
$this->layout()->setFlash("PLZ nicht Adress-DB gefunden", "error");
|
||||
$this->layout()->set("preorder", $preorder);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
$street = ADBStrasseModel::getFirst(['name' => $street_search, 'gemeinde_id' => $city->id]);
|
||||
if(!$street) {
|
||||
$this->log->debug("create street");
|
||||
$street = ADBStrasseModel::create([
|
||||
'ortschaft_id' => $district->id,
|
||||
'gemeinde_id' => $city->id,
|
||||
'name' => $street_search
|
||||
]);
|
||||
|
||||
if(!$street->save()) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern der neuen Straße", "error");
|
||||
$this->layout()->set("preorder", $preorder);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
return $this->addAction();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->log->debug("search hausnummer");
|
||||
$hausnummer = ADBHausnummerModel::getFirst(['netzgebiet_id' => $netzgebiet_ids, 'ortschaft_id' => $district_search, 'gemeinde_id' => $city->id, 'plz_id' => $zip->id, 'strasse_id' => $street->id, 'hausnummer' => $housenumber_search]);
|
||||
if($hausnummer) {
|
||||
// hausnummer gibts scho!
|
||||
$this->layout()->setFlash("Adresse war schon vorhanden!", "warn");
|
||||
$preorder->adb_hausnummer_id = $hausnummer->id;
|
||||
} else {
|
||||
// try with empty netzgebiet
|
||||
$this->log->debug("search hausnummer mit empty netzgebiet");
|
||||
$hausnummer = ADBHausnummerModel::getFirst(['netzgebiet_id' => null, 'ortschaft_id' => $district_search, 'gemeinde_id' => $city->id, 'plz_id' => $zip->id, 'strasse_id' => $street->id, 'hausnummer' => $housenumber_search]);
|
||||
if($hausnummer) {
|
||||
// Hausnummer ohne Netzgebiet gefunden -> update netzgebiet_id
|
||||
$this->log->debug("hausnummer id: updated netzgebiet from NULL to ".$netzgebiet_ids);
|
||||
$hausnummer->netzgebiet_id = $netzgebiet_id;
|
||||
$hausnummer->save();
|
||||
$preorder->adb_hausnummer_id = $hausnummer->id;
|
||||
} else {
|
||||
// try with any netzgebiet
|
||||
$this->log->debug("search hausnummer with ohne netzgebiet");
|
||||
$hausnummer = ADBHausnummerModel::getFirst(['ortschaft_id' => $district_search, 'gemeinde_id' => $city->id, 'plz_id' => $zip->id, 'strasse_id' => $street->id, 'hausnummer' => $housenumber_search]);
|
||||
if($hausnummer) {
|
||||
$this->log->debug("Hausnummer ".$hausnummer->id." in Netzgebiet (".implode(",", $netzgebiet_ids)." gesucht, aber in ".$hausnummer->netzgebiet_id)." gefunden";
|
||||
$this->layout()->setFlash("Neue Adresse ist bereits im Netzgebiet ".$hausnummer->netzgebiet->name." vorhanden", "error");
|
||||
$this->layout()->set("preorder", $preorder);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
return $this->addAction();
|
||||
} else {
|
||||
// hausnummer anlegen
|
||||
$hausnummer = ADBHausnummerModel::create([
|
||||
'netzgebiet_id' => $netzgebiet_id,
|
||||
'ortschaft_id' => $district->id,
|
||||
'plz_id' => $zip->id,
|
||||
'strasse_id' => $street->id,
|
||||
'hausnummer' => $housenumber_search,
|
||||
'freigabe' => $netzgebiet->freigabe,
|
||||
'manual_add' => date('U'),
|
||||
'manual_add_by' => $this->me->id,
|
||||
'manual_add_info' => "thetool user ".$this->me->username." via Preorder create"
|
||||
]);
|
||||
|
||||
if(!$hausnummer->save()) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern der neuen Adresse", "error");
|
||||
$this->layout()->set("preorder", $preorder);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
return $this->addAction();
|
||||
}
|
||||
$preorder->adb_hausnummer_id = $hausnummer->id;
|
||||
$preorder->address_created = date('U');
|
||||
$preorder->address_created_by = $this->me->id;
|
||||
$preorder->adb_wohneinheit_id = null;
|
||||
|
||||
// create wohneinheit
|
||||
$wohneinheit = ADBWohneinheitModel::create([
|
||||
'hausnummer_id' => $hausnummer->id,
|
||||
'num' => 1,
|
||||
'block' => ($block) ? $block : null,
|
||||
'stiege' => ($stiege) ? $stiege : null,
|
||||
'stock' => ($stock) ? $stock : null,
|
||||
'tuer' => ($tuer) ? $tuer : null
|
||||
]);
|
||||
if($wohneinheit->save()) {
|
||||
$preorder->adb_wohneinheit_id = $wohneinheit->id;
|
||||
} else {
|
||||
$this->layout()->setFlash("Konnte Wohneinheit nicht speichern", "warn");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* validation
|
||||
*/
|
||||
|
||||
if(!array_key_exists($data['type'], $campaign->types)) {
|
||||
$this->layout()->setFlash("Bitte Vorbestelltyp auswählen!", "error");
|
||||
@@ -324,6 +529,12 @@ class PreorderController extends mfBaseController {
|
||||
|
||||
//var_dump($preorder);exit;
|
||||
|
||||
// unset temporary properties
|
||||
unset($preorder->new_address_city);
|
||||
unset($preorder->new_address_district);
|
||||
unset($preorder->new_address_zip);
|
||||
unset($preorder->new_address_street);
|
||||
unset($preorder->new_address_housenumber);
|
||||
|
||||
/*
|
||||
* generate ucode and save
|
||||
@@ -337,7 +548,7 @@ class PreorderController extends mfBaseController {
|
||||
}
|
||||
|
||||
|
||||
$qs = ['filter' => ['campaign_id' => $preorder->preordercampaign_id]];
|
||||
$qs = ['filter' => ['preordercampaign_id' => $preorder->preordercampaign_id, 'ucode' => $preorder->ucode]];
|
||||
$qs = http_build_query($qs);
|
||||
|
||||
$this->layout()->setFlash("Vorbestellung erfolgreich gespeichert!", "success");
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
|
||||
class PreorderModel {
|
||||
public $ucode;
|
||||
public $status_id;
|
||||
public $preordercampaign_id;
|
||||
public $adb_hausnummer_id;
|
||||
public $adb_wohneinheit_id;
|
||||
public $oaid;
|
||||
public $address_district;
|
||||
public $address_info;
|
||||
public $building_id;
|
||||
public $termination_id;
|
||||
@@ -31,15 +34,32 @@ class PreorderModel {
|
||||
public $firstname;
|
||||
public $lastname;
|
||||
public $street;
|
||||
public $housenumber;
|
||||
public $block;
|
||||
public $stiege;
|
||||
public $stock;
|
||||
public $tuer;
|
||||
public $unit_string;
|
||||
public $zip;
|
||||
public $city;
|
||||
public $phone;
|
||||
public $email;
|
||||
public $technology;
|
||||
public $patchposition;
|
||||
public $is_additional_order;
|
||||
public $shipping_address;
|
||||
public $addon_services;
|
||||
public $addon_data;
|
||||
public $submit_type;
|
||||
public $submit_request;
|
||||
|
||||
public $cancel_request;
|
||||
public $cancel_request_by;
|
||||
public $cancel_approved;
|
||||
public $cancel_approved_by;
|
||||
public $deleted;
|
||||
public $deleted_by;
|
||||
|
||||
public $note;
|
||||
|
||||
public $create_by;
|
||||
@@ -93,11 +113,26 @@ class PreorderModel {
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
public static function getFirst($filter = false, $order = false) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Preorder", "*", "$where ORDER BY lastname, firstname");
|
||||
|
||||
$orderBy = "lastname, firstname";
|
||||
if($order) $orderBy = $order;
|
||||
|
||||
$sql = "SELECT tt_preorder.* FROM `".FRONKDB_DBNAME."`.Preorder tt_preorder
|
||||
LEFT JOIN `".FRONKDB_DBNAME."`.Preorderstatus tt_preorderstatus ON (tt_preorder.status_id = tt_preorderstatus.id)
|
||||
LEFT JOIN `".ADDRESSDB_DBNAME."`.view_hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.hausnummer_id)
|
||||
WHERE $where
|
||||
ORDER BY $orderBy
|
||||
LIMIT 1
|
||||
";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Preorder($data);
|
||||
@@ -110,6 +145,71 @@ class PreorderModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function countOrderedAddonservices($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) AS cnt FROM `".FRONKDB_DBNAME."`.Preorder tt_preorder
|
||||
LEFT JOIN `".ADDRESSDB_DBNAME."`.view_hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.hausnummer_id),
|
||||
JSON_TABLE(addon_services,
|
||||
'$[*]' COLUMNS (
|
||||
ordered VARCHAR(64) PATH '$.ordered'
|
||||
)
|
||||
) a_services
|
||||
WHERE $where
|
||||
AND addon_services IS NOT NULL AND (a_services.ordered = 'true' OR a_services.ordered=1)
|
||||
GROUP BY tt_preorder.id
|
||||
";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return $data->cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function searchOrderedAddonservices($filter, $limit = false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
$sql = "SELECT tt_preorder.* FROM `".FRONKDB_DBNAME."`.Preorder tt_preorder
|
||||
LEFT JOIN `".ADDRESSDB_DBNAME."`.view_hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.hausnummer_id),
|
||||
JSON_TABLE(addon_services,
|
||||
'$[*]' COLUMNS (
|
||||
ordered VARCHAR(64) PATH '$.ordered'
|
||||
)
|
||||
) a_services
|
||||
WHERE $where
|
||||
AND addon_services IS NOT NULL AND (a_services.ordered = 'true' OR a_services.ordered=1)
|
||||
GROUP BY tt_preorder.id
|
||||
ORDER BY lastname, firstname
|
||||
|
||||
";
|
||||
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($count)) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Preorder($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
@@ -136,6 +236,7 @@ class PreorderModel {
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
$sql = "SELECT tt_preorder.* FROM `".FRONKDB_DBNAME."`.Preorder tt_preorder
|
||||
LEFT JOIN `".FRONKDB_DBNAME."`.Preorderstatus tt_preorderstatus ON (tt_preorder.status_id = tt_preorderstatus.id)
|
||||
LEFT JOIN `".ADDRESSDB_DBNAME."`.view_hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.hausnummer_id)
|
||||
WHERE $where
|
||||
ORDER BY lastname, firstname
|
||||
@@ -172,10 +273,63 @@ class PreorderModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("partner_id", $filter)) {
|
||||
$partner_id = $filter['partner_id'];
|
||||
if(is_numeric($partner_id)) {
|
||||
$where .= " AND partner_id=$partner_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("status_id", $filter)) {
|
||||
$status_id = $filter['status_id'];
|
||||
if(is_numeric($status_id)) {
|
||||
$where .= " AND status_id=$status_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("<status_id", $filter)) {
|
||||
$status_id = $filter['<status_id'];
|
||||
if(is_numeric($status_id)) {
|
||||
$where .= " AND status_id < $status_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists(">status_id", $filter)) {
|
||||
$status_id = $filter['>status_id'];
|
||||
if(is_numeric($status_id)) {
|
||||
$where .= " AND status_id > $status_id";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("status_code", $filter)) {
|
||||
$status_code = $filter['status_code'];
|
||||
if(is_numeric($status_code)) {
|
||||
$where .= " AND tt_preorderstatus.code=$status_code";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("<status_code", $filter)) {
|
||||
$status_code = $filter['<status_code'];
|
||||
if(is_numeric($status_code)) {
|
||||
$where .= " AND tt_preorderstatus.code < $status_code";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists(">status_code", $filter)) {
|
||||
$status_code = $filter['>status_code'];
|
||||
if(is_numeric($status_code)) {
|
||||
$where .= " AND tt_preorderstatus.code > $status_code";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("preordercampaign_id", $filter)) {
|
||||
$preordercampaign_id = $filter['preordercampaign_id'];
|
||||
if(is_numeric($preordercampaign_id)) {
|
||||
$where .= " AND preordercampaign_id=$preordercampaign_id";
|
||||
} elseif(is_array($preordercampaign_id) && count($preordercampaign_id)) {
|
||||
$where .= " AND preordercampaign_id IN (". implode(",", $preordercampaign_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,6 +366,15 @@ class PreorderModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("address_created", $filter)) {
|
||||
$address_created = $filter['address_created'];
|
||||
if($address_created === true) {
|
||||
$where .= " AND address_created > 0";
|
||||
} elseif($address_created == null) {
|
||||
$where .= " AND address_created IS NULL";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("type", $filter)) {
|
||||
$type = $filter['type'];
|
||||
if(is_array($type) && count($type)) {
|
||||
@@ -224,13 +387,31 @@ class PreorderModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("ucode", $filter)) {
|
||||
$ucode = FronkDB::singleton()->escape($filter['ucode']);
|
||||
if($ucode) {
|
||||
$where .= " AND ucode like '%$ucode%'";
|
||||
if(array_key_exists("connection_type", $filter)) {
|
||||
$connection_type = $filter['connection_type'];
|
||||
if(is_array($connection_type) && count($connection_type)) {
|
||||
$where .= " AND connection_type IN ('".implode("','",$connection_type)."')";
|
||||
} else {
|
||||
$connection_type = FronkDB::singleton()->escape($filter['connection_type']);
|
||||
if($connection_type) {
|
||||
$where .= " AND connection_type like '%$connection_type%'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("ucode", $filter)) {
|
||||
$ucode = FronkDB::singleton()->escape($filter['ucode']);
|
||||
if($ucode) {
|
||||
$where .= " AND ucode = '$ucode'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("oaid", $filter)) {
|
||||
$oaid = FronkDB::singleton()->escape($filter['oaid']);
|
||||
if($oaid) {
|
||||
$where .= " AND tt_preorder.oaid = '$oaid'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("gemeinde", $filter)) {
|
||||
$gemeinde = FronkDB::singleton()->escape($filter['gemeinde']);
|
||||
@@ -253,6 +434,7 @@ class PreorderModel {
|
||||
}
|
||||
}
|
||||
|
||||
// custom where clause
|
||||
if(array_key_exists("add-where", $filter)) {
|
||||
$where .= " ".$filter['add-where'];
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ class Preordercampaign extends mfBaseModel {
|
||||
if($name == "salesclusters") {
|
||||
$items = PreordercampaignSalesclusterModel::search(["preordercampaign_id" => $this->id]);
|
||||
foreach($items as $pog) {
|
||||
$this->salesclusters[$pog->salescluster_id] = $pog;
|
||||
$this->salesclusters[$pog->salescluster_id] = new ADBNetzgebiet($pog->salescluster_id);
|
||||
}
|
||||
return $this->salesclusters;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ class PreordercampaignController extends mfBaseController {
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
if(!$me->is(["Admin", "salespartner"])) {
|
||||
if(!$me->is(["Admin", "netowner", "salespartner"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ class PreordercampaignController extends mfBaseController {
|
||||
|
||||
$this->layout->set("filter", $this->request->filter);
|
||||
|
||||
$filter = [];
|
||||
if($this->request->filter) {
|
||||
$filter = $this->getPreparedFilter($this->request->filter);
|
||||
}
|
||||
@@ -34,43 +35,75 @@ class PreordercampaignController extends mfBaseController {
|
||||
}
|
||||
|
||||
$my_networks = [];
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if($this->me->is("Admin")) {
|
||||
if($filter['network_id']) {
|
||||
if(!is_array($filter['network_id']) && $filter['network_id']) {
|
||||
$my_networks[] = new Network($filter['network_id']);
|
||||
} else {
|
||||
$my_networks = NetworkModel::getAll();
|
||||
}
|
||||
$this->layout()->set("mynetworks", NetworkModel::getAll());
|
||||
|
||||
$netowners = $this->getNetworkOwners($my_network_ids);
|
||||
$this->layout()->set("netowners", $netowners);
|
||||
|
||||
} else {
|
||||
$use_filter_network = false;
|
||||
$my_networks = $this->me->my_networks;
|
||||
|
||||
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
|
||||
//var_dump($my_networks);exit;
|
||||
foreach($my_networks as $mn) {
|
||||
if($mn->id == $filter['network_id']) {
|
||||
$use_filter_network = true;
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout()->set("mynetworks", $my_networks);
|
||||
|
||||
if($use_filter_network) {
|
||||
$my_networks = [];
|
||||
$my_networks[] = new Network($filter['network_id']);
|
||||
}
|
||||
|
||||
$this->layout()->set("mynetworks", $this->me->my_networks);
|
||||
|
||||
$my_network_ids = [];
|
||||
foreach($my_networks as $network) {
|
||||
$my_network_ids[] = $network->id;
|
||||
}
|
||||
$filter['network_id'] = $my_network_ids;
|
||||
}
|
||||
unset($filter['network_id']);
|
||||
|
||||
$campaigns = PreordercampaignModel::search(['network_id' => $my_networks]);
|
||||
|
||||
|
||||
$campaigns = PreordercampaignModel::search($filter);
|
||||
$this->layout()->set("campaigns", $campaigns);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function getPreparedFilter($filter) {
|
||||
$new_filter = [];
|
||||
|
||||
if(array_key_exists("netowner", $filter) && $filter['netowner']) {
|
||||
if($this->me->is("Admin")) {
|
||||
$owner_id = $filter['netowner'];
|
||||
foreach(NetworkModel::search(['owner_id' => $owner_id]) as $network) {
|
||||
$new_filter['network_id'][] = $network->id;
|
||||
}
|
||||
unset($filter['network_id']);
|
||||
} else {
|
||||
unset($filter['netowner']);
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("name", $filter) && $filter['name']) {
|
||||
$new_filter['name%'] = "%".$filter['name'];
|
||||
unset($filter['name']);
|
||||
}
|
||||
if(array_key_exists("area", $filter) && $filter['area']) {
|
||||
$new_filter['area%'] = "%".$filter['area'];
|
||||
unset($filter['area']);
|
||||
}
|
||||
|
||||
foreach($filter as $name => $value) {
|
||||
$new_filter[$name] = $value;
|
||||
}
|
||||
@@ -78,7 +111,30 @@ class PreordercampaignController extends mfBaseController {
|
||||
return $new_filter;
|
||||
}
|
||||
|
||||
private function getNetworkOwners() {
|
||||
$owners = [];
|
||||
|
||||
$sql = "SELECT Address.* FROM Preordercampaign
|
||||
LEFT JOIN Network ON (Preordercampaign.network_id = Network.id)
|
||||
LEFT JOIN Address ON (Network.owner_id = Address.id)
|
||||
GROUP BY Address.id
|
||||
ORDER BY Address.company, Address.lastname, Address.firstname
|
||||
";
|
||||
$res = $this->db()->query($sql);
|
||||
if($this->db()->num_rows($reso)) {
|
||||
while($data = $this->db()->fetch_object($res)) {
|
||||
$owners[] = new Address($data->id);
|
||||
}
|
||||
}
|
||||
|
||||
return $owners;
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
if(!$this->me->is("Admin")) {
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
|
||||
$this->layout()->setTemplate("Preordercampaign/Form");
|
||||
|
||||
if($this->me->isAdmin()) {
|
||||
@@ -98,6 +154,10 @@ class PreordercampaignController extends mfBaseController {
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
if(!$this->me->is("Admin")) {
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
|
||||
$id = $this->request->id;
|
||||
if(!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
@@ -116,6 +176,10 @@ class PreordercampaignController extends mfBaseController {
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
if(!$this->me->is("Admin")) {
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
|
||||
$r = $this->request;
|
||||
//var_dump($r);exit;
|
||||
$id = $r->id;
|
||||
@@ -173,6 +237,23 @@ class PreordercampaignController extends mfBaseController {
|
||||
$data['required_preorder_fields'] = null;
|
||||
}
|
||||
|
||||
if($r->district_is_city == 1) {
|
||||
$data['district_is_city'] = 1;
|
||||
} else {
|
||||
$data['district_is_city'] = 0;
|
||||
}
|
||||
|
||||
if($r->hausnummer_add_zusatz == 1) {
|
||||
$data['hausnummer_add_zusatz'] = 1;
|
||||
} else {
|
||||
$data['hausnummer_add_zusatz'] = 0;
|
||||
}
|
||||
|
||||
if($r->exist_is_error == 1) {
|
||||
$data['exist_is_error'] = 1;
|
||||
} else {
|
||||
$data['exist_is_error'] = 0;
|
||||
}
|
||||
|
||||
$data['edit_by'] = $this->me->id;
|
||||
|
||||
@@ -246,5 +327,84 @@ class PreordercampaignController extends mfBaseController {
|
||||
$this->redirect("Preordercampaign");
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function downloadAddonServices() {
|
||||
$id = $this->request->preordercampaign_id;
|
||||
if(!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
|
||||
$campaign = new Preordercampaign($id);
|
||||
if(!$campaign->id) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
$preorders = PreorderModel::search(["preordercampaign_id" => $id, "add-where" => "AND JSON_LENGTH(addon_services) > 1"]);
|
||||
|
||||
if(!count($preorders)) {
|
||||
$this->layout->setFlash("Keine Vorbestellungen mit bestellten Dienstleistungen gefunden.");
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
|
||||
$csv = [];
|
||||
foreach($preorders as $preorder) {
|
||||
$sjson = json_decode($preorder->addon_services);
|
||||
if(!$sjson) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// address data and stuff
|
||||
$general = [
|
||||
"ucode" => $preorder->ucode,
|
||||
"gemeinde" => $preorder->adb_hausnummer->ortschaft->gemeinde->name,
|
||||
"plz" => $preorder->adb_hausnummer->plz->plzstring,
|
||||
"ortschaft" => $preorder->adb_hausnummer->ortschaft->name,
|
||||
"strasse" => $preorder->adb_hausnummer->strasse->name,
|
||||
"hausnummer" => $preorder->adb_hausnummer->hausnummer,
|
||||
"block" => "",
|
||||
"stiege" => "",
|
||||
"stock" => "",
|
||||
"tuer" => "",
|
||||
"zusatz" => "",
|
||||
"address_info" => $preorder->address_info,
|
||||
"contact_firma" => $preorder->company,
|
||||
"contact_uid" => $preorder->uid,
|
||||
"contact_firstname" => $preorder->firstname,
|
||||
"contact_lastname" => $preorder->lastname,
|
||||
"contact_street" => $preorder->street,
|
||||
"contact_plz" => $preorder->zip,
|
||||
"contact_ort" => $preorder->city,
|
||||
"phone" => $preorder->phone,
|
||||
"email" => $preorder->email,
|
||||
];
|
||||
|
||||
if($preorder->adb_wohneinheit_id) {
|
||||
$general["block"] = $preorder->adb_wohneinheit->block;
|
||||
$general["stiege"] = $preorder->adb_wohneinheit->stiege;
|
||||
$general["stock"] = $preorder->adb_wohneinheit->stock;
|
||||
$general["tuer"] = $preorder->adb_wohneinheit->tuer;
|
||||
$general["zusatz"] = $preorder->adb_wohneinheit->zusatz;
|
||||
}
|
||||
|
||||
foreach($sjson as $service) {
|
||||
if(!$service->ordered) continue;
|
||||
|
||||
$s = $general;
|
||||
$s["service"] = $service->service;
|
||||
$data = [];
|
||||
foreach($service->data as $d) {
|
||||
$data[] = (string)$d->name.": ".(is_bool($d->value) ? (int)$d->value : (string)$d->value);
|
||||
}
|
||||
$s["service_data"] = implode("; ", $data);
|
||||
$csv[] = $s;
|
||||
}
|
||||
//var_dump($csv);exit;
|
||||
$this->layout()->setTemplate("Preordercampaign/services.csv");
|
||||
$this->layout()->set("csv", $csv);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,19 @@
|
||||
class PreordercampaignModel {
|
||||
public $name;
|
||||
public $network_id;
|
||||
public $homes_count;
|
||||
public $fulfillment;
|
||||
public $product_type;
|
||||
public $description;
|
||||
public $area;
|
||||
public $from;
|
||||
public $to;
|
||||
|
||||
public $required_preorder_fields;
|
||||
public $district_is_city;
|
||||
public $hausnummer_add_zusatz;
|
||||
public $exist_is_error;
|
||||
public $require_connectiontype;
|
||||
public $allow_unit_update;
|
||||
public $note;
|
||||
|
||||
public $create_by;
|
||||
@@ -79,6 +86,12 @@ class PreordercampaignModel {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
$sql = "SELECT Preordercampaign.* FROM Preordercampaign
|
||||
LEFT JOIN Network on (Preordercampaign.network_id = Network.id)
|
||||
WHERE $where ORDER BY name,`create`
|
||||
";
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
$res = $db->select("Preordercampaign", "*", "$where ORDER BY name,`create`");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
@@ -90,17 +103,54 @@ class PreordercampaignModel {
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("network_id", $filter)) {
|
||||
$networkid = $filter['network_id'];
|
||||
if(is_numeric($networkid)) {
|
||||
$where .= " AND network_id=$networkid";
|
||||
$network_id = $filter['network_id'];
|
||||
if(is_numeric($network_id)) {
|
||||
$where .= " AND network_id=$network_id";
|
||||
} elseif(is_array($network_id) && count($network_id)) {
|
||||
$where .= " AND network_id IN (". implode(",", $network_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("owner_id", $filter)) {
|
||||
$owner_id = $filter['owner_id'];
|
||||
if(is_numeric($owner_id)) {
|
||||
$where .= " AND Network.owner_id=$owner_id";
|
||||
} elseif(is_array($owner_id) && count($owner_id)) {
|
||||
$where .= " AND Network.owner_id IN (". implode(",", $owner_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("name", $filter)) {
|
||||
$name = FronkDB::singleton()->escape($filter['name']);
|
||||
if($name) {
|
||||
$where .= " AND `name` = '$name'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("name%", $filter)) {
|
||||
$name = FronkDB::singleton()->escape($filter['name%']);
|
||||
if($name) {
|
||||
$where .= " AND `name` LIKE '$name%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("area", $filter)) {
|
||||
$area = FronkDB::singleton()->escape($filter['area']);
|
||||
if($area) {
|
||||
$where .= " AND `area` = '$area'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("area%", $filter)) {
|
||||
$area = FronkDB::singleton()->escape($filter['area%']);
|
||||
if($area) {
|
||||
$where .= " AND `area` LIKE '$area%'";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
class Preordernotification extends mfBaseModel {
|
||||
private $campaign;
|
||||
private $filter;
|
||||
private $files;
|
||||
|
||||
private $creator;
|
||||
private $editor;
|
||||
|
||||
public function getPreorders() {
|
||||
if(!$this->preordercampaign_id) return false;
|
||||
|
||||
$preorder_filter = json_decode($this->preorder_filter, true);
|
||||
$preorder_filter['preordercampaign_id'] = $this->preordercampaign_id;
|
||||
|
||||
$preorders = PreorderModel::search($preorder_filter);
|
||||
return $preorders;
|
||||
}
|
||||
|
||||
public function sendToPreorder(Preorder $preorder, $email_to = false) {
|
||||
$subject = $this->subject;
|
||||
$body = $this->replaceBodyVariables($this->body_html, $preorder); // TODO: Variable replacement
|
||||
|
||||
// TODO: Extract text part
|
||||
|
||||
//var_dump($body);exit;
|
||||
$from = $this->sender_email;
|
||||
$from_name = $this->sender_name;
|
||||
$reply_to = null;
|
||||
if($this->sender_replyto) {
|
||||
$reply_to = $this->sender_replyto;
|
||||
}
|
||||
|
||||
$to = $preorder->email;
|
||||
|
||||
if($email_to) {
|
||||
$to = $email_to;
|
||||
} else {
|
||||
// check if email was sent to this preorder already
|
||||
$log = PreordernotificationLogModel::getFirst([
|
||||
'preordernotification_id' => $this->id,
|
||||
'preorder_id' => $preorder->id
|
||||
]);
|
||||
|
||||
if(!$log) {
|
||||
// check if this was sent to the same emailaddress already
|
||||
$log = PreordernotificationLogModel::getFirst([
|
||||
'preordernotification_id' => $this->id,
|
||||
'email' => $preorder->email
|
||||
]);
|
||||
}
|
||||
|
||||
if($log) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$to) return true;
|
||||
|
||||
// get attachments
|
||||
$attachments = [];
|
||||
foreach($this->getProperty("files") as $file) {
|
||||
$att = [];
|
||||
$att["path"] = MFUPLOAD_FILE_SAVE_PATH."/".$file->file->subfolder."/".$file->file->store_filename;
|
||||
$att["filename"] = $file->filename;
|
||||
$att["mimetype"] = $file->file->mimetype;
|
||||
$attachments[] = $att;
|
||||
}
|
||||
|
||||
//var_dump($attachments);exit;
|
||||
|
||||
if(!$subject || !$from || !$from_name || !$to) {
|
||||
$this->log->warn("Preordernotification not sent. subject, from or to missing. Preorder id ".$preorder->id);
|
||||
return false;
|
||||
} else {
|
||||
$email = new Emailnotification();
|
||||
$email->setSubject($subject);
|
||||
$email->setHtmlBody($body);
|
||||
$email->setFrom($from, $from_name);
|
||||
$email->setTo($to);
|
||||
if($reply_to) {
|
||||
$email->setHeader("Reply-To", $reply_to);
|
||||
}
|
||||
$email->setHeader("X-".ucfirst(MFAPPNAME)."-Pnid", $this->id);
|
||||
if(count($attachments)) {
|
||||
foreach($attachments as $file) {
|
||||
$email->addAttachment($file["path"], null, $file["filename"], $file['mimetype']);
|
||||
}
|
||||
}
|
||||
$email->send();
|
||||
$this->log->info(__CLASS__."::sendToPreorder(): Sending Preordernotification for Preorder id ".$preorder->id);
|
||||
|
||||
if($preorder && !$email_to) {
|
||||
// save notification log
|
||||
$log = PreordernotificationLogModel::create([
|
||||
'preordernotification_id' => $this->id,
|
||||
'preorder_id' => $preorder->id,
|
||||
'email' => $preorder->email,
|
||||
'sent' => date('U')
|
||||
]);
|
||||
$log->save();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function replaceBodyVariables($body, $preorder) {
|
||||
$fullname = "";
|
||||
if($preorder->firstname) {
|
||||
$fullname = $preorder->firstname;
|
||||
if($preorder->lastname) {
|
||||
$fullname .= " ".$preorder->lastname;
|
||||
}
|
||||
} elseif($preorder->lastname) {
|
||||
$fullname = $preorder->lastname;
|
||||
}
|
||||
|
||||
$replacers = [
|
||||
'VORNAME' => $preorder->firstname,
|
||||
'NACHNAME' => $preorder->nachname,
|
||||
'FIRMA' => $preorder->company,
|
||||
'FIRMA_ODER_NAME' => ($preorder->company) ? $preorder->company : $fullname,
|
||||
'EMAIL' => $preorder->email,
|
||||
'ANSCHLUSS_OAID' => ($preorder->adb_wohneinheit_id) ? $preorder->adb_wohneinheit->oaid : $preorder->adb_hausnummer->oaid,
|
||||
'ANSCHLUSS_STRASSE' => $preorder->adb_hausnummer->strasse->name,
|
||||
'ANSCHLUSS_HAUSNUMMER' => $preorder->adb_hausnummer->hausnummer,
|
||||
'ANSCHLUSS_PLZ' => $preorder->adb_hausnummer->plz->plz,
|
||||
'ANSCHLUSS_ORT' => $preorder->adb_hausnummer->ortschaft->name,
|
||||
'ANSCHLUSS_GEMEINDE' => $preorder->adb_hausnummer->strasse->gemeinde->name,
|
||||
'PREORDER_CODE' => $preorder->ucode
|
||||
|
||||
];
|
||||
|
||||
foreach($replacers as $key => $replacement) {
|
||||
$body = str_replace("{{".$key."}}", $replacement, $body);
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "campaign") {
|
||||
$this->campaign = new Preordercampaign($this->preordercampaign_id);
|
||||
return $this->campaign;
|
||||
}
|
||||
|
||||
if($name == "filter") {
|
||||
if($this->preorder_filter) {
|
||||
$this->filter = json_decode($this->preorder_filter, true);
|
||||
} else {
|
||||
$this->filter = [];
|
||||
}
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
if($name == "files") {
|
||||
$this->files = PreordernotificationFileModel::search(["preordernotification_id" => $this->id]);
|
||||
return $this->files;
|
||||
}
|
||||
|
||||
if($name == "creator") {
|
||||
$user = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||
if($user) {
|
||||
$this->creator = $user;
|
||||
return $this->creator;
|
||||
}
|
||||
$this->creator = new User($this->create_by);
|
||||
if($this->creator->id) {
|
||||
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
|
||||
}
|
||||
return $this->creator;
|
||||
}
|
||||
|
||||
if($name == "editor") {
|
||||
$this->editor = new User($this->edit_by);
|
||||
return $this->editor;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
||||
if(!$this->$name) {
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
}
|
||||
|
||||
if($this->$name->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,389 @@
|
||||
<?php
|
||||
|
||||
class PreordernotificationController extends mfBaseController {
|
||||
|
||||
protected function init() {
|
||||
$this->needlogin=true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
if(!$me->is(["Admin", "netowner", "salespartner"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
$this->layout()->setTemplate("Preordernotification/Index");
|
||||
|
||||
$rfilter = $this->request->filter;
|
||||
iF(!is_array($rfilter)) {
|
||||
$rfilter = [];
|
||||
}
|
||||
|
||||
$this->layout->set("filter", $rfilter);
|
||||
|
||||
$where = "";
|
||||
$filter = $this->getPreparedFilter($rfilter);
|
||||
|
||||
// pagination defaults
|
||||
$pagination = [];
|
||||
$pagination['start'] = 0;
|
||||
$pagination['count'] = 25;
|
||||
$pagination['maxItems'] = 0;
|
||||
|
||||
if(is_numeric($this->request->s)) {
|
||||
$pagination['start'] = intval($this->request->s);
|
||||
}
|
||||
|
||||
$preorder_filter = $filter;
|
||||
$my_campaigns = [];
|
||||
$my_campaign_ids = [];
|
||||
|
||||
if($this->me->is("Admin")) {
|
||||
if($filter['preordercampaign_id']) {
|
||||
$this->layout()->set("campaign", new Preordercampaign($filter['preordercampaign_id']));
|
||||
} else {
|
||||
$my_campaigns = PreordercampaignModel::getAll();
|
||||
}
|
||||
$this->layout()->set("my_campaigns", PreordercampaignModel::getAll());
|
||||
} else {
|
||||
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
|
||||
//var_dump($my_networks);exit;
|
||||
|
||||
foreach($my_networks as $network) {
|
||||
foreach(PreordercampaignModel::search(['network_id' => $network->id]) as $campaign) {
|
||||
$my_campaigns[] = $campaign;
|
||||
if(!in_array($campaign->id, $my_campaign_ids)) $my_campaign_ids[] = $campaign->id;
|
||||
}
|
||||
}
|
||||
//var_dump($my_network_ids,$my_campaign_ids);exit;
|
||||
$this->layout()->set("my_campaigns", $my_campaigns);
|
||||
|
||||
if($filter['preordercampaign_id'] && in_array($filter['preordercampaign_id'], $my_campaign_ids)) {
|
||||
$campaign_id = $filter['preordercampaign_id'];
|
||||
if(is_numeric($campaign_id) && $campaign_id > 0) {
|
||||
$campaign = new Preordercampaign($campaign_id);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
}
|
||||
} else {
|
||||
$filter['preordercampaign_id'] = $my_campaign_ids;
|
||||
}
|
||||
}
|
||||
//var_dump($filter);exit;
|
||||
$pagination['maxItems'] = PreordernotificationModel::count($filter);
|
||||
$notifications = PreordernotificationModel::search($filter, $pagination);
|
||||
|
||||
$this->layout()->set("pagination", $pagination);
|
||||
$this->layout()->set("notifications", $notifications);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function getPreparedFilter($filter) {
|
||||
$new_filter = [];
|
||||
|
||||
if(is_array($filter) && count($filter)) {
|
||||
foreach($filter as $name => $value) {
|
||||
$new_filter[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $new_filter;
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
$this->layout()->setTemplate("Preordernotification/Form");
|
||||
if(!$this->request->preordercampaign_id) {
|
||||
$this->layout()->setFlash("Keine Kampagne ausgewählt!", "warn");
|
||||
}
|
||||
|
||||
$campaign_id = $this->request->preordercampaign_id;
|
||||
$campaign = new Preordercampaign($campaign_id);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
|
||||
$partners = AddressModel::search(['addresstype' => ['netowner','salespartner']]);
|
||||
$this->layout()->set("partners", $partners);
|
||||
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
$id = $this->request->id;
|
||||
if(!is_numeric($id) || $id < 1) {
|
||||
$this->layout()->setFlash("Aussendung nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
|
||||
$notification = new Preordernotification($id);
|
||||
if(!$notification->id) {
|
||||
$this->layout()->setFlash("Aussendung nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
|
||||
//var_dump($notification->filter);exit;
|
||||
|
||||
$this->request->set("preordercampaign_id", $notification->preordercampaign_id); // needed in addAction()
|
||||
$this->layout()->set("notification", $notification);
|
||||
|
||||
return $this->addAction();
|
||||
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
//var_dump($r->get(), $_FILES);exit;
|
||||
|
||||
/*
|
||||
* add or edit
|
||||
*/
|
||||
$id = $r->id;
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$notification = new Preordernotification($id);
|
||||
if(!$notification->id) {
|
||||
$this->layout()->setFlash("Aussendung nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
} else {
|
||||
$id = false;
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
/*
|
||||
* check campaign and permissions
|
||||
*/
|
||||
|
||||
$campaign_id = $r->preordercampaign_id;
|
||||
if(!$campaign_id) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
$campaign = new Preordercampaign($campaign_id);
|
||||
if(!$campaign->id) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
|
||||
// check permission
|
||||
if(!$this->me->is("Admin")) {
|
||||
$my_campaign_ids = [];
|
||||
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
|
||||
//var_dump($my_networks);exit;
|
||||
|
||||
foreach($my_networks as $network) {
|
||||
foreach(PreordercampaignModel::search(['network_id' => $network->id]) as $campaign) {
|
||||
if(!in_array($campaign->id, $my_campaign_ids)) $my_campaign_ids[] = $campaign->id;
|
||||
}
|
||||
}
|
||||
|
||||
if(!in_array($campaign_id, $my_campaign_ids)) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* data colletion
|
||||
*/
|
||||
$filter = [];
|
||||
if(is_array($r->type) && count($r->type)) {
|
||||
$filter['type'] = [];
|
||||
foreach($r->type as $type) {
|
||||
switch($type) {
|
||||
case "interest":
|
||||
$filter["type"][] = "interest";
|
||||
break;
|
||||
case "provision":
|
||||
$filter["type"][] = "provision";
|
||||
break;
|
||||
case "order":
|
||||
$filter["type"][] = "order";
|
||||
break;
|
||||
case "reorder":
|
||||
$filter["type"][] = "reorder";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(is_array($r->connection_type) && count($r->connection_type)) {
|
||||
$filter['connection_type'] = [];
|
||||
foreach($r->connection_type as $type) {
|
||||
switch($type) {
|
||||
case "single-dwelling":
|
||||
$filter["connection_type"][] = "single-dwelling";
|
||||
break;
|
||||
case "multi-dwelling":
|
||||
$filter["connection_type"][] = "multi-dwelling";
|
||||
break;
|
||||
case "apartment-building":
|
||||
$filter["connection_type"][] = "apartment-building";
|
||||
break;
|
||||
case "apartment":
|
||||
$filter["connection_type"][] = "apartment";
|
||||
break;
|
||||
case "business":
|
||||
$filter["connection_type"][] = "business";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter);
|
||||
$data = [];
|
||||
$data['preordercampaign_id'] = $campaign_id;
|
||||
$data['sender_email'] = $r->sender_email;
|
||||
$data['sender_name'] = $r->sender_name;
|
||||
$data['sender_replyto'] = $r->sender_replyto;
|
||||
$data['subject'] = $r->subject;
|
||||
$data['body_html'] = $r->body_html;
|
||||
$data['note'] = $r->note;
|
||||
|
||||
if($r->tosend_day) {
|
||||
$tosend_day = $r->tosend_day;
|
||||
$tosend_hour = $r->tosend_hour;
|
||||
if($tosend_hour < 0 || $tosend_hour > 23) {
|
||||
$tosend_hour = 0;
|
||||
}
|
||||
$data['tosend_date'] = self::dateToTimestamp($tosend_day." ".str_pad($tosend_hour, 2, "0", STR_PAD_LEFT).":00:00");
|
||||
}
|
||||
|
||||
$data['preorder_filter'] = json_encode($filter);
|
||||
|
||||
//var_dump($data);exit;
|
||||
|
||||
if($mode == "edit") {
|
||||
$notification->update($data);
|
||||
} else {
|
||||
$notification = PreordernotificationModel::create($data);
|
||||
}
|
||||
|
||||
$new_id = $notification->save();
|
||||
if(!$new_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
if($id) {
|
||||
$this->redirect("Preordernotification", "edit", ['id' => $id]);
|
||||
} else {
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Attachment upload
|
||||
*/
|
||||
|
||||
if(array_key_exists("attachment", $_FILES)) {
|
||||
$files = $_FILES['attachment'];
|
||||
if(is_array($files) && count($files)) {
|
||||
$file_errors = 0;
|
||||
foreach($files['name'] as $i => $name) {
|
||||
if(!$name) continue;
|
||||
$upload_error = false;
|
||||
try {
|
||||
$upload = new mfUpload(['attachment', $i]);
|
||||
$upload->setSavepath(MFUPLOAD_FILE_SAVE_PATH . "/" . TT_PREORDERNOTIFICATION_FILE_UPLOAD_SUBFOLDER);
|
||||
} catch(Exception $e) {
|
||||
$this->layout()->setFlash("Dateiupload fehlgeschlagen: ".$e->getMessage(), "warn");
|
||||
$file_errors++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!$upload->getSize()) {
|
||||
$this->layout()->setFlash("Dateiupload fehlgeschlagen: Datei ist leer!", "warn");
|
||||
$upload_error = true;
|
||||
}
|
||||
|
||||
$mime = "";
|
||||
|
||||
if(!$upload_error) {
|
||||
try {
|
||||
$mime = $upload->getMimetype();
|
||||
$upload->save();
|
||||
} catch(Exception $e) {
|
||||
$this->layout()->setFlash("Dateiupload fehlgeschlagen", "warn");
|
||||
$upload_error = true;
|
||||
}
|
||||
}
|
||||
|
||||
if($upload_error) {
|
||||
$file_errors++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$file_data = [];
|
||||
$file_data['name'] = $upload->getOriginalFilename();
|
||||
$file_data['filename'] = $upload->getOriginalFilename();
|
||||
$file_data['subfolder'] = TT_PREORDERNOTIFICATION_FILE_UPLOAD_SUBFOLDER;
|
||||
$file_data['store_filename'] = $upload->getFilename();
|
||||
$file_data['orig_filename'] = $upload->getOriginalFilename();
|
||||
$file_data['mimetype'] = $mime;
|
||||
|
||||
$file = FileModel::create($file_data);
|
||||
$file_id = $file->save();
|
||||
if(!$file_id) {
|
||||
$this->layout()->setFlash("Dateiupload fehlgeschlagen", "warn");
|
||||
unlink($upload->getSavepath()."/".$upload->getFilename());
|
||||
} else {
|
||||
$pnf = [];
|
||||
$pnf['preordernotification_id'] = $notification->id;
|
||||
$pnf['file_id'] = $file_id;
|
||||
$pnf['filename'] = $file->filename;
|
||||
|
||||
$notification_file = PreordernotificationFileModel::create($pnf);
|
||||
if(!$notification_file->save()) {
|
||||
$file->delete();
|
||||
unlink($upload->getSavepath()."/".$upload->getFilename());
|
||||
$this->layout()->setFlash("Dateiupload fehlgeschlagen", "warn");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* delete files
|
||||
*/
|
||||
//var_dump($r->deletefile);exit;
|
||||
if(is_array($r->deletefile)) {
|
||||
foreach($r->deletefile as $pnf_id => $check) {
|
||||
if(!$check) continue;
|
||||
$pnf = new PreordernotificationFile($pnf_id);
|
||||
if($pnf->preordernotification_id != $notification->id) continue;
|
||||
$pnf->file->delete();
|
||||
$pnf->delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// get and save preorder count
|
||||
$preorder_filter = json_decode($notification->preorder_filter, true);
|
||||
$preorder_filter['preordercampaign_id'] = $notification->preordercampaign_id;
|
||||
$preorder_count = PreorderModel::count($preorder_filter);
|
||||
$notification->recipient_count = $preorder_count;
|
||||
$notification->save();
|
||||
|
||||
if($r->send_testmail && $r->testmail_to) {
|
||||
$preorder = PreorderModel::getFirst($preorder_filter);
|
||||
if(!$preorder) {
|
||||
$this->layout()->setFlash("Testmail konnte nicht versendet werden. Keine Empfänger gefunden", "warn");
|
||||
$this->redirect("Preordernotification", "edit", ['id' => $new_id]);
|
||||
}
|
||||
$notification->sendToPreorder($preorder, $r->testmail_to);
|
||||
$this->layout()->setFlash("Test Email erfolgreich versendet", "success");
|
||||
$this->redirect("Preordernotification", "edit", ['id' => $new_id]);
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Erfolgreich gepeichert.", "success");
|
||||
if($r->return == "index") {
|
||||
$this->redirect("Preordernotification");
|
||||
} else {
|
||||
$this->redirect("Preordernotification", "edit", ['id' => $new_id]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
class PreordernotificationModel {
|
||||
public $sender_email;
|
||||
public $sender_name;
|
||||
public $sender_replyto;
|
||||
public $subject;
|
||||
public $body_text;
|
||||
public $body_html;
|
||||
public $tosend_date;
|
||||
public $send_start;
|
||||
public $send_finish;
|
||||
public $recipient_count;
|
||||
public $preordercampaign_id;
|
||||
public $preorder_filter;
|
||||
public $send_lock;
|
||||
|
||||
public $note = null;
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new Preordernotification();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$model ->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
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 getOne($id) {
|
||||
if(!is_numeric($id) || !$id) {
|
||||
throw new Exception("Invalid number", 400);
|
||||
}
|
||||
$item = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Preordernotification", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Preordernotification($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Preordernotification", "*", "1 = 1 ORDER BY name,producttech_id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Preordernotification($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Preordernotification", "*", "$where ORDER BY producttech_id, name LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Preordernotification($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM `Preordernotification`
|
||||
WHERE $where
|
||||
";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return $data->cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit=false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
$sql = "SELECT Preordernotification.* FROM `Preordernotification`
|
||||
WHERE $where
|
||||
ORDER BY preordercampaign_id, `create`
|
||||
";
|
||||
|
||||
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($count)) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Preordernotification($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("id", $filter)) {
|
||||
$id = $db->escape($filter['id']);
|
||||
if($id) {
|
||||
$where .= " AND Preordernotification.`id` = '$id'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("preordercampaign_id", $filter)) {
|
||||
$preordercampaign_id = $filter['preordercampaign_id'];
|
||||
if(is_numeric($preordercampaign_id)) {
|
||||
$where .= " AND preordercampaign_id=$preordercampaign_id";
|
||||
} elseif(is_array($preordercampaign_id) && count($preordercampaign_id)) {
|
||||
$where .= " AND Preordernotification.preordercampaign_id IN (". implode(",", $preordercampaign_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("send_finish", $filter)) {
|
||||
$send_finish = $db->escape($filter['send_finish']);
|
||||
if($send_finish === null) {
|
||||
$where .= " AND Preordernotification.send_finish = NULL";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("send_lock", $filter)) {
|
||||
$send_lock = $db->escape($filter['send_lock']);
|
||||
if($send_lock === null) {
|
||||
$where .= " AND Preordernotification.send_lock = NULL";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
class PreordernotificationFile extends mfBaseModel {
|
||||
private $file;
|
||||
private $preordernotification;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
||||
if(!$this->$name) {
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
}
|
||||
|
||||
if($this->$name->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
class PreordernotificationFileModel {
|
||||
public $preordernotification_id;
|
||||
public $file_id;
|
||||
public $filename;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new PreordernotificationFile();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$model ->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
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 getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("PreordernotificationFile", "*", "1 = 1 ORDER BY preordernotification_id,file_id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new PreordernotificationFile($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("PreordernotificationFile", "*", "$where ORDER BY preordernotification_id,file_id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new PreordernotificationFile($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM `PreordernotificationFile`
|
||||
WHERE $where
|
||||
";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return $data->cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit=false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
$sql = "SELECT PreordernotificationFile.* FROM `PreordernotificationFile`
|
||||
WHERE $where
|
||||
ORDER BY preordernotification_id,file_id
|
||||
";
|
||||
|
||||
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($count)) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new PreordernotificationFile($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("id", $filter)) {
|
||||
$id = $db->escape($filter['id']);
|
||||
if($id) {
|
||||
$where .= " AND PreordernotificationFile.`id` = '$id'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("preordernotification_id", $filter)) {
|
||||
$preordernotification_id = $filter['preordernotification_id'];
|
||||
if(is_numeric($preordernotification_id)) {
|
||||
$where .= " AND preordernotification_id=$preordernotification_id";
|
||||
} elseif(is_array($preordernotification_id) && count($preordernotification_id)) {
|
||||
$where .= " AND PreordernotificationFile.preordernotification_id IN (". implode(",", $preordernotification_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("file_id", $filter)) {
|
||||
$file_id = $filter['file_id'];
|
||||
if(is_numeric($file_id)) {
|
||||
$where .= " AND PreordernotificationFile.file_id=$file_id";
|
||||
} elseif(is_array($file_id) && count($file_id)) {
|
||||
$where .= " AND PreordernotificationFile.file_id IN (". implode(",", $file_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class PreordernotificationLog extends mfBaseModel {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
class PreordernotificationLogModel {
|
||||
public $preordernotification_id;
|
||||
public $preorder_id;
|
||||
public $email;
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new PreordernotificationLog();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$model ->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
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 getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("PreordernotificationLog", "*", "1 = 1 ORDER BY `create`");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new PreordernotificationLog($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("PreordernotificationLog", "*", "$where ORDER BY `create` LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new PreordernotificationLog($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM `PreordernotificationLog`
|
||||
WHERE $where
|
||||
";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return $data->cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit=false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
$sql = "SELECT PreordernotificationLog.* FROM `PreordernotificationLog`
|
||||
WHERE $where
|
||||
ORDER BY `create`
|
||||
";
|
||||
|
||||
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($count)) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new PreordernotificationLog($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("id", $filter)) {
|
||||
$id = $filter['id'];
|
||||
if(is_numeric($id)) {
|
||||
$where .= " AND PreordernotificationLog.`id` = $id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("preordernotification_id", $filter)) {
|
||||
$preordernotification_id = $filter['preordernotification_id'];
|
||||
if(is_numeric($preordernotification_id)) {
|
||||
$where .= " AND preordernotification_id=$preordernotification_id";
|
||||
} elseif(is_array($preordernotification_id) && count($preordernotification_id)) {
|
||||
$where .= " AND PreordernotificationLog.preordernotification_id IN (". implode(",", $preordernotification_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("preorder_id", $filter)) {
|
||||
$preorder_id = $filter['preorder_id'];
|
||||
if(is_numeric($preorder_id)) {
|
||||
$where .= " AND preorder_id=$preorder_id";
|
||||
} elseif(is_array($preorder_id) && count($preorder_id)) {
|
||||
$where .= " AND PreordernotificationLog.preorder_id IN (". implode(",", $preorder_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("email", $filter)) {
|
||||
$email = $db->escape($filter['email']);
|
||||
if($email) {
|
||||
$where .= " AND PreordernotificationLog.email = '$email'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
class Preorderstatus extends mfBaseModel {
|
||||
|
||||
public function getApiArray() {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$a = [];
|
||||
$a['code'] = (int)$this->code;
|
||||
$a['text'] = $this->name;
|
||||
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
class PreorderstatusModel {
|
||||
public $code;
|
||||
public $name;
|
||||
|
||||
public $create_by;
|
||||
public $edit_by;
|
||||
public $create;
|
||||
public $edit;
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new Preorderstatus();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
if(substr($field, 0, 5) == "vlan_" && !$value) {
|
||||
$model->$field = null;
|
||||
continue;
|
||||
}
|
||||
$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 getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Preorderstatus", "*");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Preorderstatus($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter = false) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Preorderstatus", "*", "$where ORDER BY code, name");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Preorderstatus($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM Preorderstatus
|
||||
WHERE $where
|
||||
";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return $data->cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit = false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
$sql = "SELECT * FROM Preorderstatus
|
||||
WHERE $where
|
||||
ORDER BY code, name
|
||||
";
|
||||
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($count)) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Preorderstatus($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
//var_dump($filter);exit;
|
||||
|
||||
if(array_key_exists("code", $filter)) {
|
||||
$code = $filter['code'];
|
||||
if(is_numeric($code)) {
|
||||
$where .= " AND code=$code";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,7 +9,7 @@ class Product extends mfBaseModel {
|
||||
|
||||
public function loadAttributes() {
|
||||
if(!$this->producttech_id) {
|
||||
return false;
|
||||
return [];
|
||||
}
|
||||
|
||||
$this->attributes = [];
|
||||
|
||||
@@ -18,7 +18,48 @@ class ProductController extends mfBaseController {
|
||||
if(!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$this->layout()->set("products", ProductModel::getAll());
|
||||
|
||||
$filter = [];
|
||||
if(is_array($this->request->filter)) {
|
||||
$filter = $this->request->filter;
|
||||
}
|
||||
|
||||
$this->layout->set("filter", $filter);
|
||||
|
||||
if($filter) {
|
||||
$filter = $this->getPreparedFilter($filter);
|
||||
}
|
||||
|
||||
// pagination defaults
|
||||
$pagination = [];
|
||||
$pagination['start'] = 0;
|
||||
$pagination['count'] = 20;
|
||||
$pagination['maxItems'] = 0;
|
||||
|
||||
if(is_numeric($this->request->s)) {
|
||||
$pagination['start'] = intval($this->request->s);
|
||||
}
|
||||
|
||||
$pagination['maxItems'] = ProductModel::count($filter);
|
||||
$this->layout()->set("pagination", $pagination);
|
||||
|
||||
$products = ProductModel::search($filter, $pagination);
|
||||
$this->layout()->set("products", $products);
|
||||
}
|
||||
|
||||
private function getPreparedFilter($filter) {
|
||||
$new_filter = [];
|
||||
|
||||
if(array_key_exists("name", $filter)) {
|
||||
$new_filter['name%'] = $filter['name'];
|
||||
unset($filter['name']);
|
||||
}
|
||||
|
||||
foreach($filter as $name => $value) {
|
||||
$new_filter[$name] = $value;
|
||||
}
|
||||
|
||||
return $new_filter;
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
@@ -161,7 +202,7 @@ class ProductController extends mfBaseController {
|
||||
if($r->producttech_id == "new") {
|
||||
$nt = [];
|
||||
$nt['name'] = $r->producttech_new_name;
|
||||
$nt['rtrcode'] = $r->producttech_new_rtrcode;
|
||||
//$nt['rtrcode'] = $r->producttech_new_rtrcode;
|
||||
$nt['customer_type'] = ($r->producttech_new_customer_type == "business") ? "business" : "residential";
|
||||
$nt['description'] = $r->producttech_new_description;
|
||||
$nt['note'] = $r->producttech_new_note;
|
||||
@@ -276,7 +317,7 @@ class ProductController extends mfBaseController {
|
||||
}
|
||||
|
||||
|
||||
$products = array_merge($products, ProductModel::search(["nameLike" => $search]));
|
||||
$products = array_merge($products, ProductModel::search(["name%" => $search]));
|
||||
|
||||
if(!is_array($products) && !count($products)) {
|
||||
return false;
|
||||
|
||||
@@ -92,21 +92,55 @@ class ProductModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function search($filter) {
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM (
|
||||
SELECT `Product`.id FROM `Product`
|
||||
LEFT JOIN ProductAttribute ON (ProductAttribute.product_id = Product.id)
|
||||
LEFT JOIN Producttech ON (Product.producttech_id = Producttech.id)
|
||||
LEFT JOIN ProducttechAttribute ON (ProducttechAttribute.producttech_id = Producttech.id)
|
||||
WHERE $where
|
||||
GROUP BY Product.id
|
||||
) as p
|
||||
";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return $data->cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit=false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
$sql = "SELECT Product.* FROM `Product`
|
||||
LEFT JOIN Productgroup ON (Productgroup.id = Product.id)
|
||||
LEFT JOIN ProductAttribute ON (ProductAttribute.product_id = Product.id)
|
||||
LEFT JOIN Producttech ON (Product.producttech_id = Producttech.id)
|
||||
LEFT JOIN ProducttechAttribute ON (ProducttechAttribute.producttech_id = Producttech.id)
|
||||
WHERE $where
|
||||
GROUP BY Product.id";
|
||||
GROUP BY Product.id
|
||||
ORDER BY Productgroup.name,Producttech.name,Product.name
|
||||
";
|
||||
|
||||
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($count)) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
$res = $db->query($sql);
|
||||
//$res = $db->select("Product", "*", "$where ORDER BY name, producttech_id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Product($data);
|
||||
@@ -124,7 +158,7 @@ class ProductModel {
|
||||
if(array_key_exists("id", $filter)) {
|
||||
$id = $db->escape($filter['id']);
|
||||
if($id) {
|
||||
$where .= " AND Product.`id` like '%$id%'";
|
||||
$where .= " AND Product.`id` = '$id'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,13 +166,27 @@ class ProductModel {
|
||||
$productgroup_id = $filter['productgroup_id'];
|
||||
if(is_numeric($productgroup_id)) {
|
||||
$where .= " AND productgroup_id=$productgroup_id";
|
||||
} elseif(is_array($productgroup_id) && count($productgroup_id)) {
|
||||
$where .= " AND Product.productgroup_id IN (". implode(",", $productgroup_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("producttech_id", $filter)) {
|
||||
$producttech_id = $filter['producttech_id'];
|
||||
if(is_numeric($producttech_id)) {
|
||||
$where .= " AND producttech_id=$producttech_id";
|
||||
$where .= " AND Product.producttech_id=$producttech_id";
|
||||
} elseif(is_array($producttech_id) && count($producttech_id)) {
|
||||
$where .= " AND Product.producttech_id IN (". implode(",", $producttech_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("sla_id", $filter)) {
|
||||
$sla_id = $filter['sla_id'];
|
||||
if(is_numeric($sla_id)) {
|
||||
$where .= " AND sla_id=$sla_id";
|
||||
} elseif(is_array($sla_id) && count($sla_id)) {
|
||||
$where .= " AND Product.sla_id IN (". implode(",", $sla_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,13 +197,32 @@ class ProductModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("nameLike", $filter)) {
|
||||
$name = $db->escape($filter['nameLike']);
|
||||
if(array_key_exists("name%", $filter)) {
|
||||
$name = $db->escape($filter['name%']);
|
||||
if($name) {
|
||||
$where .= " AND Product.`name` like '%$name%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("external", $filter)) {
|
||||
$external = $filter['external'];
|
||||
if(is_numeric($external)) {
|
||||
if($external) {
|
||||
$where .= " AND Product.external=1";
|
||||
} else {
|
||||
$where .= " AND Product.external=0";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("customer_type", $filter)) {
|
||||
$customer_type = $db->escape($filter['customer_type']);
|
||||
if($customer_type) {
|
||||
$where .= " AND Producttech.`customer_type` = '$customer_type'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("attributename", $filter)) {
|
||||
$attributename = $db->escape($filter['attributename']);
|
||||
if($attributename) {
|
||||
|
||||
@@ -1,5 +1,80 @@
|
||||
<?php
|
||||
|
||||
class Productgroup extends mfBaseModel {
|
||||
private $products;
|
||||
private $contractconfiggroups;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($name == "products") {
|
||||
$this->products = mfValuecache::singleton()->get("Productgroup-id-".$this->id."-Products");
|
||||
if($this->products === null) {
|
||||
$this->products = ProductModel::search(['productgroup_id' => $this->id]);
|
||||
if($this->products) {
|
||||
mfValuecache::singleton()->set("Productgroup-id-".$this->id."-Products", $this->products);
|
||||
}
|
||||
}
|
||||
return $this->products;
|
||||
}
|
||||
|
||||
if($name == "contractconfiggroups") {
|
||||
$this->contractconfiggroups = mfValuecache::singleton()->get("Contractconfiggroups-byProductgroupid-".$this->id);
|
||||
if($this->contractconfiggroups === null) {
|
||||
$this->contractconfiggroups = [];
|
||||
foreach(ContractconfiggroupProductgroupModel::search(['productgroup_id' => $this->id]) as $ccpg) {
|
||||
$this->contractconfiggroups[$ccpg->contractconfiggroup_id] = $ccpg->contractconfiggroup;
|
||||
}
|
||||
if(count($this->contractconfiggroups)) {
|
||||
mfValuecache::singleton()->set("Contractconfiggroups-byProductgroupid-".$this->id, $this->contractconfiggroups);
|
||||
}
|
||||
}
|
||||
return $this->contractconfiggroups;
|
||||
}
|
||||
|
||||
if($name == "creator") {
|
||||
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||
if($this->creator === null) {
|
||||
$this->creator = new User($this->create_by);
|
||||
if($this->creator->id) {
|
||||
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
|
||||
}
|
||||
}
|
||||
return $this->creator;
|
||||
}
|
||||
|
||||
if($name == "editor") {
|
||||
$this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
|
||||
if($this->editor === null) {
|
||||
$this->editor = new User($this->edit_by);
|
||||
if($this->editor->id) {
|
||||
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
|
||||
}
|
||||
}
|
||||
return $this->editor;
|
||||
}
|
||||
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
||||
if(!$this->$name) {
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
}
|
||||
|
||||
if($this->$name->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
||||
@@ -15,15 +15,107 @@ class ProductgroupController extends mfBaseController {
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
$this->layout()->setTemplate("Productgroup/Index");
|
||||
|
||||
$filter = [];
|
||||
if(is_array($this->request->filter)) {
|
||||
$filter = $this->request->filter;
|
||||
}
|
||||
|
||||
$this->layout->set("filter", $filter);
|
||||
|
||||
if($filter) {
|
||||
$filter = $this->getPreparedFilter($filter);
|
||||
}
|
||||
|
||||
// pagination defaults
|
||||
$pagination = [];
|
||||
$pagination['start'] = 0;
|
||||
$pagination['count'] = 20;
|
||||
$pagination['maxItems'] = 0;
|
||||
|
||||
if(is_numeric($this->request->s)) {
|
||||
$pagination['start'] = intval($this->request->s);
|
||||
}
|
||||
|
||||
$pagination['maxItems'] = ProductgroupModel::count($filter);
|
||||
$this->layout()->set("pagination", $pagination);
|
||||
$productgroups = ProductgroupModel::search($filter, $pagination);
|
||||
$this->layout()->set("productgroups", $productgroups);
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
|
||||
$this->layout()->setTemplate("Productgroup/Form");
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
$id = $this->request->id;
|
||||
if(!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Produktgruppe nicht gefunden", "error");
|
||||
$this->redirect("Productgroup");
|
||||
}
|
||||
|
||||
$group = new Productgroup($id);
|
||||
if(!$group->id) {
|
||||
$this->layout()->setFlash("Produktgruppe nicht gefunden", "error");
|
||||
$this->redirect("Productgroup");
|
||||
}
|
||||
|
||||
$this->layout()->set("group", $group);
|
||||
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
|
||||
$id = $r->id;
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$group = new Productgroup($id);
|
||||
if(!$group->id) {
|
||||
$this->layout()->setFlash("Produktgruppe nicht gefunden", "error");
|
||||
$this->redirect("Productgroup");
|
||||
}
|
||||
}
|
||||
|
||||
$name = trim($r->name);
|
||||
if(!$name) {
|
||||
$this->layout()->setFlash("Name darf nicht leer sein", "error");
|
||||
$this->redirect("Productgroup");
|
||||
}
|
||||
|
||||
$group_data = [];
|
||||
$group_data['name'] = $name;
|
||||
|
||||
if($mode == "edit") {
|
||||
$group->update($group_data);
|
||||
} else {
|
||||
$group = ProductgroupModel::create(['name' => $name]);
|
||||
}
|
||||
$id = $group->save();
|
||||
|
||||
if(!$id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
$this->layout()->set("group", $group);
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
// contractconfig groups
|
||||
foreach(ContractconfiggroupProductgroupModel::search(['productgroup_id' => $id]) as $ccpg) {
|
||||
$ccpg->delete();
|
||||
}
|
||||
|
||||
foreach($r->contractconfiggroups as $cg_id) {
|
||||
$ccgroup = ContractconfiggroupProductgroupModel::create([
|
||||
"productgroup_id" => $id,
|
||||
"contractconfiggroup_id" => $cg_id
|
||||
]);
|
||||
$ccgroup->save();
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Produktgruppe erfolgreich gespeichert", "success");
|
||||
$this->redirect("Productgroup","edit", ['id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -34,21 +34,6 @@ class ProductgroupModel {
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getOne($id) {
|
||||
if(!is_numeric($id) || !$id) {
|
||||
throw new Exception("Invalid number", 400);
|
||||
}
|
||||
$item = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Productgroup", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Productgroup($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
@@ -64,7 +49,7 @@ class ProductgroupModel {
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
@@ -81,7 +66,23 @@ class ProductgroupModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function search($filter) {
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM `Productgroup`
|
||||
WHERE $where
|
||||
";
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return $data->cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit = false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
class ProducttechModel {
|
||||
public $name = null;
|
||||
public $rtrcode = null;
|
||||
//public $rtrcode = null;
|
||||
public $customer_type = null;
|
||||
public $description = null;
|
||||
|
||||
@@ -65,7 +65,7 @@ class ProducttechModel {
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
@@ -2,10 +2,30 @@
|
||||
|
||||
class ProducttechAttribute extends mfBaseModel {
|
||||
private $producttech;
|
||||
private $contractval;
|
||||
private $contract_id;
|
||||
|
||||
|
||||
public function setContractId($contract_id) {
|
||||
if(!is_numeric($contract_id)) {
|
||||
return false;
|
||||
}
|
||||
$this->contract_id = $contract_id;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "contractval") {
|
||||
if(!$this->contract_id) {
|
||||
return null;
|
||||
}
|
||||
$this->contractval = ContractconfigValueModel::getFirst(['item_id' => $this->id]);
|
||||
//var_dump($this->contractval);
|
||||
return $this->contractval;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
@@ -102,6 +102,20 @@ class ProducttechAttributeModel {
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
if(array_key_exists("forproduct", $filter)) {
|
||||
$forproduct = $db->escape($filter['forproduct']);
|
||||
if(is_numeric($forproduct)) {
|
||||
$where .= " AND `forproduct` = $forproduct";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("forcontract", $filter)) {
|
||||
$forcontract = $db->escape($filter['forcontract']);
|
||||
if(is_numeric($forcontract)) {
|
||||
$where .= " AND `forcontract` = $forcontract";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("name", $filter)) {
|
||||
$name = $db->escape($filter['name']);
|
||||
|
||||
@@ -185,7 +185,7 @@ class User extends mfBaseModel {
|
||||
}
|
||||
//var_dump($this->address->types);exit;
|
||||
if(is_object($this->address) && property_exists($this->address, "types") && is_array($this->address->types)) {
|
||||
if($this->address->types[$w]->id) {
|
||||
if(array_key_exists($w, $this->address->types) && $this->address->types[$w]->id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -234,11 +234,13 @@ class User extends mfBaseModel {
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
public function myNetworks($type) {
|
||||
public function myNetworks($types) {
|
||||
$typenets = [];
|
||||
$my_networks = $this->getProperty("my_networks");
|
||||
|
||||
//var_dump($my_networks);exit;
|
||||
if(!is_array($types)) {
|
||||
$types = [$types];
|
||||
}
|
||||
|
||||
foreach($my_networks as $net) {
|
||||
//var_dump($net);exit;
|
||||
@@ -246,10 +248,8 @@ class User extends mfBaseModel {
|
||||
if($this->address->parent_id) {
|
||||
$address_id = $this->address->parent_id;
|
||||
}
|
||||
$found = NetworkaddressModel::search(['network_id' => $net->id, "addresstype" => [$type], 'address_id' => $address_id]);
|
||||
//var_dump($found);exit;
|
||||
$found = NetworkaddressModel::search(['network_id' => $net->id, "addresstype" => $types, 'address_id' => $address_id]);
|
||||
if($found) {
|
||||
$this->log->debug("allowed net: ".$net->id);
|
||||
$typenets[] = $net;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user