diff --git a/Layout/default/ADBWohneinheit/Form.php b/Layout/default/ADBWohneinheit/Form.php index 7773256c2..656ebac7d 100644 --- a/Layout/default/ADBWohneinheit/Form.php +++ b/Layout/default/ADBWohneinheit/Form.php @@ -123,50 +123,56 @@ - - - rimo_workorder) && $unit->rimo_workorder->id) || (is_array($unit->ftu_data) && $unit->ftu_data->id)): ?> -
-
-
-
-
-
+ rimo_workorders) && count($unit->rimo_workorders)) || (is_array($unit->ftu_data) && $unit->ftu_data->id)): ?> +
+
+
- - - - - - - - - - - - - - - - - - - - - - -

FTU

FTU Name:ftu_data["name"]?> -
FTU External IDftu_data["id"]?> -

Workorder

Namerimo_workorder->rimo_name?>
External IDrimo_workorder->rimo_id?>
Statusrimo_workorder->rimo_status?>
Erstelltrimo_workorder)) ? date("d.m.Y H:i:s", $unit->rimo_workorder->create) : ""?>
+
+ +
+
+ + + + + + + + + + rimo_workorders) && count($unit->rimo_workorders)): ?> + + + + rimo_workorders as $wo): ?> + + + + + + + + + + + + + + + +

FTU

FTU Name:ftu_data["name"] ?> +
FTU External IDftu_data["id"] ?> +

Workorder

Namerimo_name ?>
External IDrimo_id ?>
Statusrimo_status ?>
Erstelltcreate)?>
+
+
+
+
-
-
-
-
- +
diff --git a/Layout/default/Contract/View.php b/Layout/default/Contract/View.php new file mode 100644 index 000000000..7b61a5213 --- /dev/null +++ b/Layout/default/Contract/View.php @@ -0,0 +1,485 @@ + + + +
+
+
+
+ +
+

Aktives Produkt

+
+
+
+ + +
+
+ + + +
+
+ isFinished()): ?> +

In Herstellung

+ + isCancelled()): ?> +

GEKÜNDIGT

+ + sla->name), "residential")): ?> +

Privatprodukt

+ +

Businessprodukt

+ +

">product_name?> [id?>]

+ + + + + + + + upgradeFrom) && count($contract->upgradeFrom)): ?> + + + + + + upgradeTo) && count($contract->upgradeTo)): ?> + + + + + + + + downgradeFrom) && count($contract->downgradeFrom)): ?> + + + + + + downgradeTo) && count($contract->downgradeTo)): ?> + + + + + + + + productchangeFrom) && count($contract->productchangeFrom)): ?> + + + + + + productchangeTo) && count($contract->productchangeTo)): ?> + + + + + + + + relocationFrom) && count($contract->relocationFrom)): ?> + + + + + + relocationTo) && count($contract->relocationTo)): ?> + + + + + + + + + + billingaddress_id): ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Matchcode:matchcode?>
Upgrade von: + upgradeFrom as $link): ?> + $link->origin_contract_id])?>" class="contract-link origin->cancel_date && $link->origin->cancel_date <= date('U')) ? "canceled" : ""?>">origin->product_name?> [origin->matchcode?>] (origin_contract_id?>)
+ +
Upgrade auf: + upgradeTo as $link): ?> + $link->contract_id])?>" class="contract-link contract->cancel_date && $link->contract->cancel_date <= date('U')) ? "canceled" : ""?> contract->isFinished()) ? "not-finished" : "" ?>">contract->product_name?> [contract->matchcode?>] (contract_id?>)
+ +
Downgrade von: + downgradeFrom as $link): ?> + $link->origin_contract_id])?>" class="contract-link origin->cancel_date <= date('U')) ? "canceled" : ""?>">origin->product_name?> [origin->matchcode?>] (origin_contract_id?>)
+ +
Downgrade auf: + downgradeTo as $link): ?> + $link->contract_id])?>" class="contract-link contract->cancel_date && $link->contract->cancel_date <= date('U')) ? "canceled" : ""?>">contract->product_name?> [contract->matchcode?>] (contract_id?>)
+ +
Produktwechsel von: + productchangeFrom as $link): ?> + $link->origin_contract_id])?>" class="contract-link origin->cancel_date <= date('U')) ? "canceled" : ""?>">origin->product_name?> [origin->matchcode?>] (origin_contract_id?>)
+ +
Produktwechsel auf: + productchangeTo as $link): ?> + $link->contract_id])?>" class="contract-link contract->cancel_date && $link->contract->cancel_date <= date('U')) ? "canceled" : ""?>">contract->product_name?> [contract->matchcode?>] (contract_id?>)
+ +
Umzug von: + relocationFrom as $link): ?> + $link->origin_contract_id])?>" class="contract-link origin->cancel_date && $link->origin->cancel_date <= date('U')) ? "canceled" : ""?>">origin->product_name?> [origin->matchcode?>] (origin_contract_id?>)
+ +
Umzug auf: + relocationTo as $link): ?> + $link->contract_id])?>" class="contract-link contract->cancel_date && $link->contract->cancel_date <= date('U')) ? "canceled" : ""?>">contract->product_name?> [contract->matchcode?>] (contract_id?>)
+ +
Vertragsinhaber: $contract->owner_id])?>">owner->getCompanyOrName()?> [owner->customer_number?>]
Rechnungsempfänger: $contract->billingaddress_id])?>">billingaddress->getCompanyOrName()?> [billingaddress->customer_number?>]
Produkt:product_name?> [product_id?>]product_name != $contract->product->name) ? " (".$contract->product->name.")" : ""?>
Produkt Info:product_info?>
SLA:sla->name?>
Externes Produkt:product_external) ? "Ja" : "Nein"?>
Menge:amount, 3, ",", ".")?>
Preis Periodisch Netto:">€ amount != 1) ? $contract->price * $contract->amount : $contract->price, 4, ",", ".")?>
Preis Periodisch Brutto:">€ + price && $contract->vatrate): ?> + amount != 1): ?> + price + ($contract->price / 100) * $contract->vatrate, 4, ",", ".")?> + + price + ($contract->price / 100) * $contract->vatrate) * $contract->amount, 4, ",", ".")?> + + +
Verrechnungsperiode: + billing_period, "billing_period")?> +
Herstellungskosten:"> + price_setup != 0): ?> + Netto: € price_setup, 4, ",", ".")?>amount != 1) ? " (Gesamt: € ".number_format($contract->price_setup * $contract->amount, 4, ",", ".").")" : ""?>
+ Brutto: € price_setup && $contract->vatrate) ? number_format($contract->price_setup + ($contract->price_setup / 100) * $contract->vatrate, 4, ",", ".") : ""?>price_setup && $contract->vatrate && $contract->amount != 1) ? " (Gesamt: € ".number_format(($contract->price_setup + ($contract->price_setup / 100) * $contract->vatrate) * $contract->amount, 4, ",", ".").")" : ""?>
Verrechnungsstart Verzögerung: + billing_delay): ?> + billing_delay?> Monate + +
Bestelldatum:order_date) ? date('d.m.Y',$contract->order_date) : ""?>
Fertigstellungsdatum: + finish_date) ? date('d.m.Y',$contract->finish_date) : ""?> + finish_date_by) ? "(".$contract->finisher->name.")" : ""?> +
Kündigungsdatum:"> + cancel_date) ? date('d.m.Y',$contract->cancel_date) : ""?> + cancel_date_by) ? "(".$contract->canceler->name.")" : ""?> +
Erstellt:create)?> (creator->name?>)
Zuletzt bearbeitet:edit)?> (editor->name?>)
+ $contract->id])?>"> + $contract->id])?>"> + finish_date && $contract->finish_date < date('U')): ?> + + $contract->id])?>"> + $contract->id])?>"> + finish_date): ?> + $contract->id])?>" onclick="if(!confirm('Jetzt fertigstellen und in Verrechnung geben?')) return false"> + +
+ +
+
+ +
+
+
Journaleinträge
+
+
+
+
+ + + journals) && count($contract->journals)): ?> + journals as $j): ?> + + + + type == "text" || $j->type == "phone"):?> + + text) > 120): ?> + + + + + + + type == "file"): ?> + + + + type == "created_from"): ?> + + + type == "contract_finished"): ?> + + + type == "credit_created"): ?> + + + type == "link"): ?> + value); ?> + + + type == "canceled"): ?> + + + + + + + + + + + + + +
create)?> (creator?>) + type == "text"): ?> + + + + + + text), 120)?> + + + text)?> + + text): ?> + text), 128)?>
+ + $j->contractfile->file_id])?>">contractfile->file->filename?> +
+ value == "manual"): ?> + Vertrag manuell erstellt + value == "import"): ?> + Vertrag importiert: text))?> + value == "order"): ?> + Vertrag aus Bestellung $contract->orderproduct->order_id])?>">#orderproduct->order_id?> erstellt + value == "productchange"): ?> + Vertrag erstellt: text))?> + + Vertag fertiggestellt + + Gutschrift-Vertrag $j->value])?>">value?> erstellt + + Verknüpfung mit $link->id])?>">id?> - product_name?> [matchcode?>] erstelltVertag gekündigt + $j->id])?>" title="Journaleintrag bearbeiten"> +
+
+ +
+ +
+
+
+
+ + + +
+
+

Verknüpfte Verträge $contract->id])?>">Neuen Contract anlegen

+ linkFrom) && count($contract->linkFrom)) || (is_array($contract->linkTo) && count($contract->linkTo))): ?> + + + + + + + + + + + + + + linkFrom, $contract->linkTo] as $links): ?> + + contract_id == $contract->id) { + $direction = "von"; + $linkcontract = $link->origin; + if($link->type == "credit") { + $direction = "zu"; + //continue; + } + } else { + $linkcontract = $link->contract; + if($link->type == "upgrade" || $link->type == "downgrade") { + $direction = "auf"; + } + if($link->type == "relocation") { + $direction = "nach"; + } + if($link->type == "credit") { + $direction = ""; + //continue; + } + + } + + ?> + + + + + + + + + + + + + + + +
TypKundeContract IDProduktPreisPreis SetupBestelldatumFertigstellungKündigung
">type, "contract")?> type != "link") ? $direction : ""?> $linkcontract->owner_id])?>">owner->getCompanyOrName()?> isFinished()) ? "not-finished" : "" ?>"> $linkcontract->id])?>">id?> isFinished()) ? "not-finished" : "" ?>"> $linkcontract->id])?>">product_name?> [matchcode?>] isFinished()) ? "not-finished" : "" ?> price < 0) ? "text-danger" : ""?>">€ price,4,",",".")?> isFinished()) ? "not-finished" : "" ?> price_setup < 0) ? "text-danger" : ""?>">€ price_setup,4,",",".")?> isFinished()) ? "not-finished" : "" ?>">order_date) ? date('d.m.Y', $linkcontract->order_date) : ""?> isFinished()) ? "not-finished" : "" ?>">finish_date) ? date('d.m.Y', $linkcontract->finish_date) : ""?> isFinished()) ? "not-finished" : "" ?> cancel_date) ? "text-danger font-weight-bold" : ""?>">cancel_date) ? date('d.m.Y', $linkcontract->cancel_date) : ""?> + $link->id])?>" onclick="if(!confirm('Verknüpfung wirklich entfernen?')) return false;" class="text-danger" title="Verknüpfung entfernen"> +
+ +
+
+ + + + +
+
+ + + diff --git a/application/ContractFile/ContractFile.php b/application/ContractFile/ContractFile.php index fad92dbf4..55225c131 100644 --- a/application/ContractFile/ContractFile.php +++ b/application/ContractFile/ContractFile.php @@ -1,7 +1,7 @@ id) { diff --git a/application/Preorder/PreorderModel.php b/application/Preorder/PreorderModel.php index 0992ad40a..ac9362696 100644 --- a/application/Preorder/PreorderModel.php +++ b/application/Preorder/PreorderModel.php @@ -1,292 +1,302 @@ $value) { - if(property_exists(get_called_class(), $field)) { - if(substr($field, 0, 5) == "vlan_" && !$value) { - $model->$field = null; - continue; +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; + } } - $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 function createFromRimoWorkorder($workorder) { + $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; + } - 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 $model; } - return $items; - - } - - public static function getFirstActive($filter = [], $order = false) { - if(!is_array($filter)) return false; - - if(!array_key_exists("deleted", $filter)) { - $filter["deleted"] = null; + + + public function createFromRimoWorkorder($workorder) + { + } - - if( !array_key_exists("status_code", $filter) && !array_key_exists("status_code", $filter) - && !array_key_exists("status_id", $filter) && !array_key_exists("status_id", $filter) ) { - $filter["select("Preorder", "*"); + if ($db->num_rows($res)) { + while ($data = $db->fetch_object($res)) { + $items[] = new Preorder($data); + } + } + return $items; + } - - 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, MAX(rimo_team_name) as rimo_team_name, MAX(rimo_team_id) as rimo_team_id FROM `".FRONKDB_DBNAME."`.RimoWorkorder GROUP BY adb_wohneinheit_id) workorder ON adb_wohneinheit.id = workorder.adb_wohneinheit_id + + 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_id", $filter) && !array_key_exists("status_id", $filter)) { + $filter["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 { + + 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; - } } - return null; - } - public static function getAllPartners(): array { - $items = []; + public static function getAllPartners(): array + { + $items = []; - $db = FronkDB::singleton(); + $db = FronkDB::singleton(); - $res = $db->select("Preorder", "partner_id", "partner_id IS NOT NULL AND partner_id > 0 GROUP BY partner_id"); - if($db->num_rows($res)) { - while($data = $db->fetch_object($res)) { - $partner = AddressModel::getOne($data->partner_id); - $items[] = [ - "partner_id" => $data->partner_id, - "name" => $partner->getCompanyOrName() - ]; - } + $res = $db->select("Preorder", "partner_id", "partner_id IS NOT NULL AND partner_id > 0 GROUP BY partner_id"); + if ($db->num_rows($res)) { + while ($data = $db->fetch_object($res)) { + $partner = AddressModel::getOne($data->partner_id); + $items[] = [ + "partner_id" => $data->partner_id, + "name" => $partner->getCompanyOrName() + ]; + } + } + return $items; } - return $items; - } - - 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, MAX(rimo_team_name) as rimo_team_name, MAX(rimo_team_id) as rimo_team_id FROM `".FRONKDB_DBNAME."`.RimoWorkorder GROUP BY adb_wohneinheit_id) workorder ON adb_wohneinheit.id = workorder.adb_wohneinheit_id + + 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, MAX(rimo_team_name) as rimo_team_name, MAX(rimo_team_id) as rimo_team_id 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, MAX(rimo_team_name) as rimo_team_name, MAX(rimo_team_id) as rimo_team_id FROM `".FRONKDB_DBNAME."`.RimoWorkorder GROUP BY adb_wohneinheit_id) workorder ON adb_wohneinheit.id = workorder.adb_wohneinheit_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 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, MAX(rimo_team_name) as rimo_team_name, MAX(rimo_team_id) as rimo_team_id 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']; - } + /*$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; } - - 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)) { - $filter["status_code", $filter) && !array_key_exists("status_code", $filter)) { + $filter["debug($sql); - - $res = $db->query($sql); - if($db->num_rows($res)) { - $data = $db->fetch_object($res); - return $data->cnt; + + mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if ($db->num_rows($res)) { + $data = $db->fetch_object($res); + return $data->cnt; + } + return 0; } - 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)) { - $filter["status_code", $filter) && !array_key_exists("status_code", $filter)) { + $filter["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_id", $filter) && !array_key_exists("status_id", $filter) ) { - $filter["status_code", $filter) && !array_key_exists("status_code", $filter) - && !array_key_exists("status_id", $filter) && !array_key_exists("status_id", $filter) ) { - $filter["query($sql); - mfLoghandler::singleton()->debug("[Query took: ".(microtime(true) - $queryStart)." seconds] " . $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, $returnArray = 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, MAX(rimo_team_name) as rimo_team_name, MAX(rimo_team_id) as rimo_team_id 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($limit['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)) { - if ($returnArray) { - $items[] = $data; - } else { - $items[] = new Preorder($data); + if (is_array($limit) && count($limit)) { + if (is_numeric($limit['start']) && is_numeric($limit['count'])) { + $sql .= " LIMIT " . $limit['start'] . ", " . $limit['count']; + } elseif (is_numeric($limit['count'])) { + $sql .= " LIMIT " . $limit['count']; + } } - } - } - 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_array($partner_id)) { - $where .= " AND partner_id IN (".join(",", $partner_id).")"; - } elseif(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"; - } - } + mfLoghandler::singleton()->debug($sql); - if(array_key_exists("preorder_status_flags", $filter)) { - $preorder_status_flags = $filter['preorder_status_flags']; - if (is_array($preorder_status_flags) && count($preorder_status_flags)) { - $where .= " AND tt_preorder.id IN ( - SELECT psv.preorder_id - FROM `".FRONKDB_DBNAME."`.PreorderStatusflagValue psv - WHERE psv.flag_id IN (" . implode(',', $preorder_status_flags) . ") - AND psv.value = 1 - GROUP BY psv.preorder_id - HAVING COUNT(DISTINCT psv.flag_id) = " . count($preorder_status_flags) . " - )"; + $res = $db->query($sql); + if ($db->num_rows($res)) { + while ($data = $db->fetch_object($res)) { + $items[] = new Preorder($data); + } } + return $items; } - if(array_key_exists("created_from", $filter)) { - $created_from = $filter['created_from']; - if(is_numeric($created_from)) { - // use mysql function for the date (column is unix epoch) - $created_from_epoch = time() - $created_from * 86400; -// var_dump($created_from_epoch); -// die(); - $where .= " AND FROM_UNIXTIME(tt_preorder.create) >= FROM_UNIXTIME($created_from_epoch)"; - } - } - - - if(array_key_exists("status_code", $filter)) { - $status_code = $filter['status_code']; - if(is_numeric($status_code)) { - $where .= " AND tt_preorderstatus.code=$status_code"; - } elseif(is_array($status_code)) { - $where .= " AND tt_preorderstatus.code IN (".implode(",", $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"; - } - } + public static function countActive($filter = []) + { + if (!is_array($filter)) return false; - if(array_key_exists("operator_id", $filter)) { - $operator_id = $filter['operator_id']; - if(is_numeric($operator_id)) { - $where .= " AND partner_id IN ( - SELECT PreordercampaignOperatorIsp.isp_id as isp_id - FROM PreordercampaignOperatorIsp - LEFT JOIN PreordercampaignOperator ON (PreordercampaignOperatorIsp.campaignoperator_id = PreordercampaignOperator.id) - WHERE operator_id = $operator_id - )"; - } - } - - 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("deleted", $filter)) { + $filter["deleted"] = null; } - } - } - - 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("status_code", $filter) && !array_key_exists("status_code", $filter) + && !array_key_exists("status_id", $filter) && !array_key_exists("status_id", $filter)) { + $filter["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'"; - } + return self::count($filter); } - if(array_key_exists("email", $filter)) { - $email = FronkDB::singleton()->escape($filter['email']); - if($email) { - $where .= " AND tt_preorder.email = '$email'"; - } - } + public static function searchActive($filter = [], $limit = false, $returnDBRessource = false, $returnArray = false) + { + if (!is_array($filter)) return false; - if(array_key_exists("phone", $filter)) { - $phone = $filter["phone"]; - if(is_array($phone)) { - $where .= " AND REGEXP_REPLACE(tt_preorder.phone, '[^0-9]+', '') IN ('".implode("','", $phone)."')"; - } else { - $phone = FronkDB::singleton()->escape($filter['phone']); - if($phone) { - $where .= " AND REGEXP_REPLACE(tt_preorder.phone, '[^0-9]+', '') = '$phone'"; - } - } - } - - 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 = $filter['rimo_workorder_status']; - if (is_array($rimo_workorder_status) && count($rimo_workorder_status)) { - $rimo_workorder_status = array_map(function($value) { - return FronkDB::singleton()->escape($value); - }, $filter['rimo_workorder_status']); - $where .= " AND workorder.rimo_status IN ('".implode("','", $rimo_workorder_status)."')"; - } else if($rimo_workorder_status) { - $rimo_workorder_status = FronkDB::singleton()->escape($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("rimo_workorder_team_name", $filter)) { - $rimo_workorder_team_name = FronkDB::singleton()->escape($filter['rimo_workorder_team_name']); - if($rimo_workorder_team_name) { - $where .= " AND workorder.rimo_team_name LIKE '%$rimo_workorder_team_name%'"; - } - } - - if(array_key_exists("rimo_workorder_team_id", $filter)) { - $rimo_workorder_team_id = FronkDB::singleton()->escape($filter['rimo_workorder_team_id']); - if($rimo_workorder_team_id) { - $where .= " AND workorder.rimo_team_id = '$rimo_workorder_team_id'"; - } - } - - 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_id", $filter)) { - if(!is_array($filter['gemeinde_id'])) { - $gemeinde_id = FronkDB::singleton()->escape($filter['gemeinde_id']); - $where .= " AND `".ADDRESSDB_DBNAME."`.adb_hausnummer.gemeinde_id = $gemeinde_id"; - } elseif(count($filter['gemeinde_id'])) { - $gemeinde_id = $filter['gemeinde_id']; - $where .= " AND `".ADDRESSDB_DBNAME."`.adb_hausnummer.gemeinde_id IN (".implode(",",$gemeinde_id).")"; - } - } - - 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("stiege", $filter)) { - $stiege = FronkDB::singleton()->escape($filter['stiege']); - if($stiege) { - $where .= " AND adb_hausnummer.stiege like '%$stiege%'"; - } - } - - 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("deleted", $filter)) { + $filter["deleted"] = null; } - 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; - } - public static function countStatusFlagsActive($filter = [], $statusFlag = null) { - if ($statusFlag === null) { - die("Please select a statusflag"); - } - - 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_id", $filter) && !array_key_exists("status_id", $filter) ) { + if (!array_key_exists("status_code", $filter) && !array_key_exists("status_code", $filter) + && !array_key_exists("status_id", $filter) && !array_key_exists("status_id", $filter)) { $filter["query($sql); - mfLoghandler::singleton()->debug("[Query took: ".(microtime(true) - $queryStart)." seconds] " . $sql); + $queryStart = microtime(true); + $res = $db->query($sql); + mfLoghandler::singleton()->debug("[Query took: " . (microtime(true) - $queryStart) . " seconds] " . $sql); if ($db->num_rows($res)) { $data = $db->fetch_object($res); return $data->cnt; @@ -911,19 +424,484 @@ class PreorderModel { return 0; } - public static function countHistoryStatus($filter = [], $status_code = null) { - if ($status_code === null) { - die("Please select a status code"); - } + public static function search($filter = [], $limit = false, $returnDBRessource = false, $returnArray = false) + { + $items = []; + $db = FronkDB::singleton(); - if(!is_array($filter)) return false; + $where = self::getSqlFilter($filter); - if(!array_key_exists("deleted", $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, MAX(rimo_team_name) as rimo_team_name, MAX(rimo_team_id) as rimo_team_id 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($limit['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)) { + if ($returnArray) { + $items[] = $data; + } else { + $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_array($partner_id)) { + $where .= " AND partner_id IN (" . join(",", $partner_id) . ")"; + } elseif (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("preorder_status_flags", $filter)) { + $preorder_status_flags = $filter['preorder_status_flags']; + if (is_array($preorder_status_flags) && count($preorder_status_flags)) { + $where .= " AND tt_preorder.id IN ( + SELECT psv.preorder_id + FROM `" . FRONKDB_DBNAME . "`.PreorderStatusflagValue psv + WHERE psv.flag_id IN (" . implode(',', $preorder_status_flags) . ") + AND psv.value = 1 + GROUP BY psv.preorder_id + HAVING COUNT(DISTINCT psv.flag_id) = " . count($preorder_status_flags) . " + )"; + } + } + + if (array_key_exists("created_from", $filter)) { + $created_from = $filter['created_from']; + if (is_numeric($created_from)) { + // use mysql function for the date (column is unix epoch) + $created_from_epoch = time() - $created_from * 86400; +// var_dump($created_from_epoch); +// die(); + $where .= " AND FROM_UNIXTIME(tt_preorder.create) >= FROM_UNIXTIME($created_from_epoch)"; + } + } + + + if (array_key_exists("status_code", $filter)) { + $status_code = $filter['status_code']; + if (is_numeric($status_code)) { + $where .= " AND tt_preorderstatus.code=$status_code"; + } elseif (is_array($status_code)) { + $where .= " AND tt_preorderstatus.code IN (" . implode(",", $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("operator_id", $filter)) { + $operator_id = $filter['operator_id']; + if (is_numeric($operator_id)) { + $where .= " AND partner_id IN ( + SELECT PreordercampaignOperatorIsp.isp_id as isp_id + FROM PreordercampaignOperatorIsp + LEFT JOIN PreordercampaignOperator ON (PreordercampaignOperatorIsp.campaignoperator_id = PreordercampaignOperator.id) + WHERE operator_id = $operator_id + )"; + } + } + + 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("email", $filter)) { + $email = FronkDB::singleton()->escape($filter['email']); + if ($email) { + $where .= " AND tt_preorder.email = '$email'"; + } + } + + if (array_key_exists("phone", $filter)) { + $phone = $filter["phone"]; + if (is_array($phone)) { + $where .= " AND REGEXP_REPLACE(tt_preorder.phone, '[^0-9]+', '') IN ('" . implode("','", $phone) . "')"; + } else { + $phone = FronkDB::singleton()->escape($filter['phone']); + if ($phone) { + $where .= " AND REGEXP_REPLACE(tt_preorder.phone, '[^0-9]+', '') = '$phone'"; + } + } + } + + 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 = $filter['rimo_workorder_status']; + if (is_array($rimo_workorder_status) && count($rimo_workorder_status)) { + $rimo_workorder_status = array_map(function ($value) { + return FronkDB::singleton()->escape($value); + }, $filter['rimo_workorder_status']); + $where .= " AND workorder.rimo_status IN ('" . implode("','", $rimo_workorder_status) . "')"; + } else if ($rimo_workorder_status) { + $rimo_workorder_status = FronkDB::singleton()->escape($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("rimo_workorder_team_name", $filter)) { + $rimo_workorder_team_name = FronkDB::singleton()->escape($filter['rimo_workorder_team_name']); + if ($rimo_workorder_team_name) { + $where .= " AND workorder.rimo_team_name LIKE '%$rimo_workorder_team_name%'"; + } + } + + if (array_key_exists("rimo_workorder_team_id", $filter)) { + $rimo_workorder_team_id = FronkDB::singleton()->escape($filter['rimo_workorder_team_id']); + if ($rimo_workorder_team_id) { + $where .= " AND workorder.rimo_team_id = '$rimo_workorder_team_id'"; + } + } + + 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_id", $filter)) { + if (!is_array($filter['gemeinde_id'])) { + $gemeinde_id = FronkDB::singleton()->escape($filter['gemeinde_id']); + $where .= " AND `" . ADDRESSDB_DBNAME . "`.adb_hausnummer.gemeinde_id = $gemeinde_id"; + } elseif (count($filter['gemeinde_id'])) { + $gemeinde_id = $filter['gemeinde_id']; + $where .= " AND `" . ADDRESSDB_DBNAME . "`.adb_hausnummer.gemeinde_id IN (" . implode(",", $gemeinde_id) . ")"; + } + } + + 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("stiege", $filter)) { + $stiege = FronkDB::singleton()->escape($filter['stiege']); + if ($stiege) { + $where .= " AND adb_hausnummer.stiege like '%$stiege%'"; + } + } + + 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; + } + + public static function countStatusFlagsActive($filter = [], $statusFlag = null) + { + if ($statusFlag === null) { + die("Please select a statusflag"); + } + + 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_id", $filter) && !array_key_exists("status_id", $filter) ) { + if (!array_key_exists("status_code", $filter) && !array_key_exists("status_code", $filter) + && !array_key_exists("status_id", $filter) && !array_key_exists("status_id", $filter)) { $filter["query($sql); - mfLoghandler::singleton()->debug("[Query took: ".(microtime(true) - $queryStart)." seconds] " . $sql); + mfLoghandler::singleton()->debug("[Query took: " . (microtime(true) - $queryStart) . " seconds] " . $sql); + if ($db->num_rows($res)) { + $data = $db->fetch_object($res); + return $data->cnt; + } + return 0; + } + + public static function countHistoryStatus($filter = [], $status_code = null) + { + if ($status_code === null) { + die("Please select a status code"); + } + + 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_id", $filter) && !array_key_exists("status_id", $filter)) { + $filter["query($sql); + mfLoghandler::singleton()->debug("[Query took: " . (microtime(true) - $queryStart) . " seconds] " . $sql); if ($db->num_rows($res)) { $data = $db->fetch_object($res);