753 lines
27 KiB
PHP
753 lines
27 KiB
PHP
<?php
|
|
|
|
class PreorderModel {
|
|
public $ucode;
|
|
public $ciftoken;
|
|
public $cifurl;
|
|
public $status_id;
|
|
public $preordercampaign_id;
|
|
public $adb_hausnummer_id;
|
|
public $adb_wohneinheit_id;
|
|
public $address_created;
|
|
public $address_created_by;
|
|
public $oaid;
|
|
public $extref;
|
|
public $address_district;
|
|
public $address_info;
|
|
public $building_id;
|
|
public $termination_id;
|
|
public $connection_type;
|
|
public $connection_count;
|
|
public $product_id;
|
|
public $setup_product_id;
|
|
public $type;
|
|
public $order_id;
|
|
public $price;
|
|
public $price_setup;
|
|
public $price_nne;
|
|
public $price_nbe;
|
|
public $billing_delay;
|
|
public $billing_period;
|
|
public $partner_id;
|
|
public $accept_agb;
|
|
public $accept_dsgvo;
|
|
public $accept_marketing;
|
|
public $accept_withdrawal;
|
|
public $accept_digging;
|
|
public $contact_type;
|
|
public $company;
|
|
public $uid;
|
|
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 $is_additional_order;
|
|
public $shipping_address;
|
|
public $addon_services;
|
|
public $addon_data;
|
|
public $attributes;
|
|
public $submit_type;
|
|
public $submit_request;
|
|
public $installation_date;
|
|
public $workorder_export_date;
|
|
public $workorder_export_data;
|
|
public $order_date;
|
|
|
|
public $cancel_request;
|
|
public $cancel_request_by;
|
|
public $cancel_approved;
|
|
public $cancel_approved_by;
|
|
public $deleted;
|
|
public $deleted_by;
|
|
|
|
public $note;
|
|
|
|
public $create_by;
|
|
public $edit_by;
|
|
public $create;
|
|
public $edit;
|
|
|
|
public static function create(Array $data) {
|
|
$model = new Preorder();
|
|
|
|
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("Preorder", "*");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new Preorder($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
public static function getFirstActive($filter = [], $order = false) {
|
|
if(!is_array($filter)) return false;
|
|
|
|
if(!array_key_exists("deleted", $filter)) {
|
|
$filter["deleted"] = null;
|
|
}
|
|
|
|
if( !array_key_exists("<status_code", $filter) && !array_key_exists(">status_code", $filter) && !array_key_exists("status_code", $filter)
|
|
&& !array_key_exists("<status_id", $filter) && !array_key_exists(">status_id", $filter) && !array_key_exists("status_id", $filter) ) {
|
|
$filter["<status_code"] = 899;
|
|
}
|
|
|
|
return self::getFirst($filter, $order);
|
|
}
|
|
|
|
public static function getFirst($filter = false, $order = false) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
|
|
$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
|
|
";*/
|
|
$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)
|
|
LEFT JOIN `".ADDRESSDB_DBNAME."`.Wohneinheit as adb_wohneinheit ON (tt_preorder.adb_wohneinheit_id = adb_wohneinheit.id)
|
|
LEFT OUTER JOIN (SELECT adb_wohneinheit_id, count(*) cnt, MAX(rimo_status) as rimo_status, MAX(rimo_name) as rimo_name FROM `".FRONKDB_DBNAME."`.RimoWorkorder GROUP BY adb_wohneinheit_id) workorder ON adb_wohneinheit.id = workorder.adb_wohneinheit_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);
|
|
if($item->id) {
|
|
return $item;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static function countWithLogistics($filter) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT COUNT(*) as cnt 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)
|
|
LEFT JOIN `".ADDRESSDB_DBNAME."`.Wohneinheit as adb_wohneinheit ON (tt_preorder.adb_wohneinheit_id = adb_wohneinheit.id)
|
|
LEFT OUTER JOIN (SELECT adb_wohneinheit_id, count(*) cnt, MAX(rimo_status) as rimo_status, MAX(rimo_name) as rimo_name FROM `".FRONKDB_DBNAME."`.RimoWorkorder GROUP BY adb_wohneinheit_id) workorder ON adb_wohneinheit.id = workorder.adb_wohneinheit_id
|
|
LEFT JOIN Preorderlogistics ON (Preorderlogistics.preorder_id = tt_preorder.id)
|
|
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 searchWithLogistics($filter, $limit = false, $returnDBRessource = false) {
|
|
$items = [];
|
|
$db = FronkDB::singleton();
|
|
|
|
$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)
|
|
LEFT JOIN `".ADDRESSDB_DBNAME."`.Wohneinheit as adb_wohneinheit ON (tt_preorder.adb_wohneinheit_id = adb_wohneinheit.id)
|
|
LEFT OUTER JOIN (SELECT adb_wohneinheit_id, count(*) cnt, MAX(rimo_status) as rimo_status, MAX(rimo_name) as rimo_name FROM `".FRONKDB_DBNAME."`.RimoWorkorder GROUP BY adb_wohneinheit_id) workorder ON adb_wohneinheit.id = workorder.adb_wohneinheit_id
|
|
LEFT JOIN Preorderlogistics ON (Preorderlogistics.preorder_id = tt_preorder.id)
|
|
WHERE $where
|
|
ORDER BY lastname, firstname
|
|
";
|
|
/*$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";*/
|
|
|
|
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)) {
|
|
|
|
// hack for Preorder::exportAction
|
|
if($returnDBRessource) {
|
|
return $res;
|
|
}
|
|
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new Preorder($data);
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
public static function countOrderedAddonservices($filter = []) {
|
|
$db = FronkDB::singleton();
|
|
|
|
if(!array_key_exists("deleted", $filter)) {
|
|
$filter["deleted"] = null;
|
|
}
|
|
|
|
if(!array_key_exists("<status_code", $filter) && !array_key_exists(">status_code", $filter) && !array_key_exists("status_code", $filter)) {
|
|
$filter["<status_code"] = 899;
|
|
}
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT COUNT(*) AS cnt FROM (
|
|
SELECT tt_preorder.* FROM`".FRONKDB_DBNAME."`.Preorder tt_preorder
|
|
LEFT JOIN `".FRONKDB_DBNAME."`.Preorderstatus as 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)
|
|
LEFT JOIN `".ADDRESSDB_DBNAME."`.Wohneinheit as adb_wohneinheit ON (tt_preorder.adb_wohneinheit_id = adb_wohneinheit.id)
|
|
LEFT OUTER JOIN (SELECT adb_wohneinheit_id, count(*) cnt, MAX(rimo_status) as rimo_status, MAX(rimo_name) as rimo_name FROM `".FRONKDB_DBNAME."`.RimoWorkorder GROUP BY adb_wohneinheit_id) workorder ON adb_wohneinheit.id = workorder.adb_wohneinheit_id,
|
|
JSON_TABLE(tt_preorder.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
|
|
) as tbl
|
|
";
|
|
|
|
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();
|
|
|
|
if(!array_key_exists("deleted", $filter)) {
|
|
$filter["deleted"] = null;
|
|
}
|
|
|
|
if(!array_key_exists("<status_code", $filter) && !array_key_exists(">status_code", $filter) && !array_key_exists("status_code", $filter)) {
|
|
$filter["<status_code"] = 899;
|
|
}
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
|
|
$sql = "SELECT tt_preorder.* FROM `".FRONKDB_DBNAME."`.Preorder tt_preorder
|
|
LEFT JOIN `".FRONKDB_DBNAME."`.Preorderstatus as 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)
|
|
LEFT JOIN `".ADDRESSDB_DBNAME."`.Wohneinheit as adb_wohneinheit ON (tt_preorder.adb_wohneinheit_id = adb_wohneinheit.id)
|
|
LEFT OUTER JOIN (SELECT adb_wohneinheit_id, count(*) cnt, MAX(rimo_status) as rimo_status, MAX(rimo_name) as rimo_name FROM `".FRONKDB_DBNAME."`.RimoWorkorder GROUP BY adb_wohneinheit_id) workorder ON adb_wohneinheit.id = workorder.adb_wohneinheit_id,
|
|
JSON_TABLE(tt_preorder.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 countActive($filter = []) {
|
|
if(!is_array($filter)) return false;
|
|
|
|
if(!array_key_exists("deleted", $filter)) {
|
|
$filter["deleted"] = null;
|
|
}
|
|
|
|
if( !array_key_exists("<status_code", $filter) && !array_key_exists(">status_code", $filter) && !array_key_exists("status_code", $filter)
|
|
&& !array_key_exists("<status_id", $filter) && !array_key_exists(">status_id", $filter) && !array_key_exists("status_id", $filter) ) {
|
|
$filter["<status_code"] = 899;
|
|
}
|
|
|
|
return self::count($filter);
|
|
}
|
|
|
|
public static function searchActive($filter = [], $limit = false, $returnDBRessource = false) {
|
|
if(!is_array($filter)) return false;
|
|
|
|
if(!array_key_exists("deleted", $filter)) {
|
|
$filter["deleted"] = null;
|
|
}
|
|
|
|
if( !array_key_exists("<status_code", $filter) && !array_key_exists(">status_code", $filter) && !array_key_exists("status_code", $filter)
|
|
&& !array_key_exists("<status_id", $filter) && !array_key_exists(">status_id", $filter) && !array_key_exists("status_id", $filter) ) {
|
|
$filter["<status_code"] = 899;
|
|
}
|
|
|
|
return self::search($filter, $limit, $returnDBRessource);
|
|
}
|
|
|
|
public static function count($filter) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT COUNT(*) as cnt 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)
|
|
LEFT JOIN `".ADDRESSDB_DBNAME."`.Wohneinheit as adb_wohneinheit ON (tt_preorder.adb_wohneinheit_id = adb_wohneinheit.id)
|
|
LEFT OUTER JOIN (SELECT adb_wohneinheit_id, count(*) cnt, MAX(rimo_status) as rimo_status, MAX(rimo_name) as rimo_name FROM `".FRONKDB_DBNAME."`.RimoWorkorder GROUP BY adb_wohneinheit_id) workorder ON adb_wohneinheit.id = workorder.adb_wohneinheit_id
|
|
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, $returnDBRessource = false) {
|
|
$items = [];
|
|
$db = FronkDB::singleton();
|
|
|
|
$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)
|
|
LEFT JOIN `".ADDRESSDB_DBNAME."`.Wohneinheit as adb_wohneinheit ON (tt_preorder.adb_wohneinheit_id = adb_wohneinheit.id)
|
|
LEFT OUTER JOIN (SELECT adb_wohneinheit_id, count(*) cnt, MAX(rimo_status) as rimo_status, MAX(rimo_name) as rimo_name FROM `".FRONKDB_DBNAME."`.RimoWorkorder GROUP BY adb_wohneinheit_id) workorder ON adb_wohneinheit.id = workorder.adb_wohneinheit_id
|
|
WHERE $where
|
|
ORDER BY lastname, firstname
|
|
";
|
|
/*$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";*/
|
|
|
|
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)) {
|
|
|
|
// hack for Preorder::exportAction
|
|
if($returnDBRessource) {
|
|
return $res;
|
|
}
|
|
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new Preorder($data);
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter) {
|
|
$where = "1=1 ";
|
|
|
|
//var_dump($filter);exit;
|
|
|
|
if(array_key_exists("deleted", $filter)) {
|
|
$deleted = $filter['deleted'];
|
|
if($deleted === null || $deleted === false) {
|
|
$where .= " AND (deleted IS NULL OR deleted = 0)";
|
|
} elseif($deleted) {
|
|
$where .= " AND deleted > 0";
|
|
}
|
|
}
|
|
|
|
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 tt_preorder.status_id=$status_id";
|
|
} elseif(is_array($status_id)) {
|
|
$where .= " AND tt_preorder.status_id IN (". implode(",", $status_id).")";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("<status_id", $filter)) {
|
|
$status_id = $filter['<status_id'];
|
|
if(is_numeric($status_id)) {
|
|
$where .= " AND tt_preorder.status_id < $status_id";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists(">status_id", $filter)) {
|
|
$status_id = $filter['>status_id'];
|
|
if(is_numeric($status_id)) {
|
|
$where .= " AND tt_preorder.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).")";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("building_id", $filter)) {
|
|
$building_id = $filter['building_id'];
|
|
if(is_numeric($building_id)) {
|
|
$where .= " AND building_id=$building_id";
|
|
} elseif(is_array($building_id)) {
|
|
$where .= " AND building_id IN (".implode(",",$building_id).")";
|
|
} elseif($building_id === null) {
|
|
$where .= " AND building_id IS NULL";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("adb_hausnummer_id", $filter)) {
|
|
$adb_hausnummer_id = $filter['adb_hausnummer_id'];
|
|
if(is_numeric($adb_hausnummer_id)) {
|
|
$where .= " AND tt_preorder.adb_hausnummer_id=$adb_hausnummer_id";
|
|
} elseif(is_array($adb_hausnummer_id)) {
|
|
$where .= " AND tt_preorder.adb_hausnummer_id IN (".implode(",",$adb_hausnummer_id).")";
|
|
} elseif($adb_hausnummer_id === null) {
|
|
$where .= " AND tt_preorder.adb_hausnummer_id IS NULL";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("adb_wohneinheit_id", $filter)) {
|
|
$adb_wohneinheit_id = $filter['adb_wohneinheit_id'];
|
|
if(is_numeric($adb_wohneinheit_id)) {
|
|
$where .= " AND tt_preorder.adb_wohneinheit_id=$adb_wohneinheit_id";
|
|
} elseif(is_array($adb_wohneinheit_id)) {
|
|
$where .= " AND tt_preorder.adb_wohneinheit_id IN (".implode(",",$adb_wohneinheit_id).")";
|
|
} elseif($adb_wohneinheit_id === null) {
|
|
$where .= " AND tt_preorder.adb_wohneinheit_id IS NULL";
|
|
} elseif($adb_wohneinheit_id === true) {
|
|
$where .= " AND tt_preorder.adb_wohneinheit_id IS NOT NULL AND tt_preorder.adb_wohneinheit_id > 0";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("product_id", $filter)) {
|
|
$product_id = $filter['product_id'];
|
|
if(is_numeric($product_id)) {
|
|
$where .= " AND tt_preorder.product_id=$product_id";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("setup_product_id", $filter)) {
|
|
$setup_product_id = $filter['setup_product_id'];
|
|
if(is_numeric($setup_product_id)) {
|
|
$where .= " AND tt_preorder.setup_product_id=$setup_product_id";
|
|
}
|
|
}
|
|
|
|
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)) {
|
|
$where .= " AND tt_preorder.type IN ('".implode("','",$type)."')";
|
|
} else {
|
|
$type = FronkDB::singleton()->escape($filter['type']);
|
|
if($type) {
|
|
$where .= " AND tt_preorder.type like '%$type%'";
|
|
}
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("connection_type", $filter)) {
|
|
$connection_type = $filter['connection_type'];
|
|
if(is_array($connection_type) && count($connection_type)) {
|
|
$where .= " AND tt_preorder.connection_type IN ('".implode("','",$connection_type)."')";
|
|
} else {
|
|
$connection_type = FronkDB::singleton()->escape($filter['connection_type']);
|
|
if($connection_type) {
|
|
$where .= " AND tt_preorder.connection_type like '%$connection_type%'";
|
|
}
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("connection_count", $filter)) {
|
|
$connection_count = $filter['connection_count'];
|
|
if(intval($connection_count) === 1) {
|
|
$where .= " AND connection_count = 1";
|
|
} elseif(intval($connection_count) === 2) {
|
|
$where .= " AND connection_count > 1";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("ucode", $filter)) {
|
|
$ucode = FronkDB::singleton()->escape($filter['ucode']);
|
|
if($ucode) {
|
|
$where .= " AND ucode LIKE '$ucode'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("ciftoken", $filter)) {
|
|
$ciftoken = FronkDB::singleton()->escape($filter['ciftoken']);
|
|
if($ciftoken) {
|
|
$where .= " AND ciftoken LIKE '$ciftoken'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("oaid", $filter)) {
|
|
$oaid = $filter['oaid'];
|
|
if($oaid) {
|
|
$oaid = FronkDB::singleton()->escape($oaid);
|
|
$where .= " AND tt_preorder.oaid LIKE '$oaid'";
|
|
} elseif($oaid === null) {
|
|
$where .= " AND tt_preorder.oaid IS NULL";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if(array_key_exists("extref", $filter)) {
|
|
$extref = FronkDB::singleton()->escape($filter['extref']);
|
|
if($extref) {
|
|
$where .= " AND tt_preorder.extref = '$extref'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("workorder_export_date", $filter)) {
|
|
$workorder_export_date = $filter['workorder_export_date'];
|
|
if($workorder_export_date === null || $workorder_export_date === false) {
|
|
$where .= " AND (tt_preorder.workorder_export_date IS NULL OR tt_preorder.workorder_export_date = 0)";
|
|
} elseif($workorder_export_date) {
|
|
$where .= " AND tt_preorder.workorder_export_date > 0";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("rimo_workorder", $filter)) {
|
|
$rimo_workorder = $filter['rimo_workorder'];
|
|
if($rimo_workorder === null || $rimo_workorder === false) {
|
|
$where .= " AND (workorder.cnt IS NULL OR workorder.cnt = 0)";
|
|
} elseif($rimo_workorder) {
|
|
$where .= " AND workorder.cnt > 0";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("rimo_workorder_status", $filter)) {
|
|
$rimo_workorder_status = FronkDB::singleton()->escape($filter['rimo_workorder_status']);
|
|
if($rimo_workorder_status) {
|
|
$where .= " AND workorder.rimo_status = '$rimo_workorder_status'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("rimo_workorder_name", $filter)) {
|
|
$rimo_workorder_name = FronkDB::singleton()->escape($filter['rimo_workorder_name']);
|
|
if($rimo_workorder_name) {
|
|
$where .= " AND workorder.rimo_name = '$rimo_workorder_name'";
|
|
}
|
|
}
|
|
|
|
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)) {
|
|
$where .= " AND netzgebiet_id IN (".implode(",",$netzgebiet_id).")";
|
|
} elseif($netzgebiet_id === null) {
|
|
$where .= " AND netzgebiet_id IS NULL";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("gemeinde", $filter)) {
|
|
$gemeinde = FronkDB::singleton()->escape($filter['gemeinde']);
|
|
if($gemeinde) {
|
|
$where .= " AND `".ADDRESSDB_DBNAME."`.view_hausnummer.gemeinde like '%$gemeinde%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("plz", $filter)) {
|
|
$plz = FronkDB::singleton()->escape($filter['plz']);
|
|
if($plz) {
|
|
$where .= " AND `".ADDRESSDB_DBNAME."`.view_hausnummer.plz like '%$plz%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("strasse", $filter)) {
|
|
$strasse = FronkDB::singleton()->escape($filter['strasse']);
|
|
if($strasse) {
|
|
$where .= " AND `".ADDRESSDB_DBNAME."`.view_hausnummer.strasse like '%$strasse%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("hausnummer", $filter)) {
|
|
$hausnummer = FronkDB::singleton()->escape($filter['hausnummer']);
|
|
if($hausnummer) {
|
|
$where .= " AND adb_hausnummer.hausnummer like '%$hausnummer%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("unit_count", $filter)) {
|
|
$unit_count = $filter['unit_count'];
|
|
if(intval($unit_count) === 1) {
|
|
$where .= " AND adb_hausnummer.unit_count = 1";
|
|
} elseif(intval($unit_count) === 2) {
|
|
$where .= " AND adb_hausnummer.unit_count > 1";
|
|
} elseif(strlen($unit_count) && intval($unit_count) === 0) {
|
|
$where .= " AND adb_hausnummer.unit_count = 0 OR adb_hausnummer.unit_count IS NULL";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("sent", $filter)) {
|
|
$sent = $filter['sent'];
|
|
if($sent) {
|
|
$where .= " AND sent > 0";
|
|
} else {
|
|
$where .= " AND (sent = 0 OR sent IS NULL)";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("attributes", $filter)) {
|
|
$attributes = FronkDB::singleton()->escape($filter['attributes']);
|
|
if(is_array($attributes) && count($attributes)) {
|
|
if(array_key_exists("bep_specified", $attributes)) {
|
|
if($attributes['bep_specified']) {
|
|
$where .= " AND JSON_EXTRACT(attributes, \"$.bep_specified\") = 1";
|
|
}
|
|
}
|
|
if(array_key_exists("inhouse_cabling_supplied", $attributes)) {
|
|
if($attributes['inhouse_cabling_supplied']) {
|
|
$where .= " AND JSON_EXTRACT(attributes, \"$.inhouse_cabling_supplied\") = 1";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// custom where clause
|
|
if(array_key_exists("add-where", $filter)) {
|
|
$where .= " ".$filter['add-where'];
|
|
}
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
}
|