WIP Ivt Import 2024-05-02

This commit is contained in:
Frank Schubert
2024-05-06 13:24:25 +02:00
parent df108dca2d
commit 6002876343
17 changed files with 1298 additions and 404 deletions
+7 -1
View File
@@ -78,7 +78,12 @@ class Address extends mfBaseModel {
$name_search = [];
if($this->company) $name_search[] = $this->company;
if($this->lastname) $name_search[] = $this->lastname;
$country = new Country($this->country_id);
if(!$country) {
return false;
}
$fibumerge = XinonFibuMergeModel::getFirst(["old_custnum" => $old_custnum, "name" => $name_search]);
if(!$fibumerge) {
// create fibu merge
@@ -91,6 +96,7 @@ class Address extends mfBaseModel {
"strasse" => $this->street,
"plz" => $this->zip,
"ort" => $this->city,
"land" => $country->isocode,
"create_by" => 1,
"edit_by" => 1
]);
+3 -3
View File
@@ -127,7 +127,7 @@ class AdminController extends mfBaseController {
$products = [];
foreach($ivtproducts as $product) {
$active_count = IvtCustomerProductModel::count(['pid' => $product->id]);
$active_count = IvtCustomerTelephoneNrModel::count(['pid' => $product->id]);
if(!$active_count) continue;
$new_product = [];
@@ -136,7 +136,7 @@ class AdminController extends mfBaseController {
$new_product["customer"] = false;
if($active_count == 1) {
$cp = IvtCustomerProductModel::getFirst(["pid" => $product->id]);
$cp = IvtCustomerTelephoneNrModel::getFirst(["pid" => $product->id]);
//var_dump($cp);exit;
$customer = $cp->customer;
//var_dump($customer);exit;
@@ -151,7 +151,7 @@ class AdminController extends mfBaseController {
}
protected function ivtContractImportAction() {
exit;
//exit;
$doit = false;
if($this->request->doit == 1) {
$doit = true;
+471 -291
View File
@@ -1,305 +1,485 @@
<?php
class Admin_IvtContractImport {
private $request;
public function __construct($request) {
$this->request = $request;
}
public function run($doit = false) {
echo "running...<br />\n";
$data = [];
$data['ignore'] = 0;
$data["contracts"] = [];
foreach(IvtCustomerProductModel::getAll() as $ivt_contract) {
$ivt_customer = $ivt_contract->customer;
$ivt_product = $ivt_contract->product;
if(!$this->checkIvtCustomer($ivt_customer)) {
echo "IVT Customer ".$ivt_contract->cid." nicht im tool<br />\n";
private $request;
private $log;
public function __construct($request) {
$this->request = $request;
$this->log = mfLoghandler::singleton();
}
public function run($doit = false) {
echo "running...<br />\n";
$data = [];
$data['ignore'] = 0;
$data["contracts"] = [];
$i = 0;
foreach(IvtCustomerTelephoneNrModel::getAll("cid") as $ivt_contract) {
if($i > 100) break;
$i++;
$neu = [];
$orderproduct = false;
$orderproduct_id = false;
$ivt_customer = $ivt_contract->customer;
$ivt_product = $ivt_contract->product;
if(!$this->checkIvtCustomer($ivt_customer)) {
echo "IVT Customer " . $ivt_contract->cid . " nicht im tool<br />\n";
exit;
}
$productMatch = IvtProductMatchModel::getFirst(["ivt_product_id" => $ivt_contract->pid]);
if(!$productMatch) {
echo "Kein Match zu IVT Product " . $ivt_contract->pid . " gefunden.<br />\n";
exit;
}
if(!$this->checkIvtProduct($productMatch->ivtproduct, $doit)) {
exit;
}
$customer = AddressModel::getFirst(["customer_number" => $ivt_contract->cid]);
/*if($ivt_contract->id == 3035) {
var_dump($ivt_contract->cid, $customer);
}*/
if(!$customer) {
$this->log->debug("Kein thetool Kunde zu IVT customer " . $ivt_contract->cid . " gefunden -> wird angelegt");
$customer = $this->createAddressFromIvtCustomer($ivt_contract->customer);
if(!$customer) {
echo "Fehler beim anlegen der Adresse<br />\n";
exit;
}
}
$ip = $productMatch->ivtproduct;
$product = $productMatch->product;
/*
// check if contract was imported already
$existing_contract = ContractModel::getFirst(["imported_from" => "ivt", "imported_data" => $ivt_contract->id]);
if($existing_contract) {
//echo "Contract gibts schon ".$existing_contract->id."<br />\n";
continue;
}
*/
$finish_date = new DateTime($ivt_contract->created);
$finish_date->modify("+2 hours");
$contract_data = [];
$contract_data['owner_id'] = $customer->id;
$contract_data['billingaddress_id'] = $customer->id;
$contract_data['product_id'] = $product->id;
$contract_data['product_name'] = $ip->name;
$contract_data['amount'] = 1;
$contract_data['price'] = $ip->price;
$contract_data['price_setup'] = 0;
$contract_data['price_nne'] = 0;
$contract_data['price_nbe'] = 0;
$contract_data['finish_date'] = $finish_date->getTimestamp();
$contract_data['finish_date_by'] = 1;
$contract_data['imported_from'] = "ivt";
$contract_data['imported_data'] = $ivt_contract->id;
switch($ip->interval) {
case 0:
$contract_data['billing_period'] = 1;
break;
case 1:
$contract_data['billing_period'] = 12;
break;
}
$neu["customer"] = $customer;
$neu["ivtcustomer"] = $ivt_customer;
$neu["ivtproduct"] = $ip;
$neu["product"] = $product;
$neu["orderproduct"] = false;
$neu['action'] = "import";
$ignore = false;
if($product->price <= 0) {
$contract_data['price'] = 0;
$contract_data['price_setup'] = $ip->price;
$contract_data['billing_period'] = 0;
$neu['action'] = "ignore";
$ignore = true;
}
// find thetool Order
$order = OrderModel::getFirst(["owner_id" => $customer->id]);
/*if($ivt_contract->id == 3035) {
var_dump($order);
}*/
/*if($ivt_contract->id == 3035) {
var_dump($order);exit;
}*/
if($order) {
foreach($order->products as $orderproduct) {
if($orderproduct->product_id == $product->id) {
$orderproduct_id = $orderproduct->id;
}
}
if($orderproduct_id) {
$contract_data["orderproduct_id"] = $orderproduct->id;
$neu["orderproduct"] = $orderproduct;
} else {
$this->log->debug("Kein Orderproduct gefunden in Order ".$order->id." für Ivt customer_product ".$ivt_contract->id);
}
} else {
//$this->log->debug("Keine thetool order für ivt customer_product ".$ivt_contract->id);
}
/*if($ivt_contract->id == 3035) {
var_dump($order, $orderproduct);
}*/
$contract = ContractModel::create($contract_data);
$contract->matchcode = $contract->generateMatchcode();
/*if($ivt_contract->id == 3035) {
var_dump($contract);
}*/
$neu["contract"] = $contract;
if($doit && !$ignore) {
$contract_id = $contract->save();
if(!$contract_id) {
echo "Fehler beim Contract speichern!<br />\n";
exit;
}
// create journal entry
$journal = ContractjournalModel::create([
'contract_id' => $contract_id,
'type' => "created_from",
'value' => "import",
'text' => "IVT"
]);
$journal_id = $journal->save();
if(!$journal_id) {
echo "Fehler beim Journal erstellen.<br />\n";
exit;
}
// import Contractconfig
}
$contractconfig = $this->importContractconfig($ivt_customer, $ivt_product, $contract, ($doit && !$ignore));
var_dump($contractconfig);exit;
$data["contracts"][] = $neu;
if($neu['action'] == "ignore") {
$data['ignore']++;
}
/*if($ivt_contract->id == 3035) {
var_dump($neu);exit;
}*/
}
return $data;
}
private function checkIvtCustomer($ivt_customer, $doit = false) {
$return = [];
// create customer if not exists
$ivt_custnum = $ivt_customer->id;
if(!$ivt_custnum) return false;
// sync billing address
$owner = AddressModel::getFirst(["customer_number" => $ivt_custnum]);
if(!$owner) {
die("Address $ivt_custnum not found!");
}
// find order
$order_count = OrderModel::count(["owner_id" => $owner->id, "finish_date" => true]);
if($order_count > 1) {
die("Mehr als eine Bestellung für ivt_customer $ivt_custnum gefunden.\n".print_r($owner, true));
}
$order = OrderModel::getFirst(["owner_id" => $owner->id, "finish_date" => true]);
if(!$order) {
$this->log->debug(__METHOD__.": No order for ivt customer $ivt_custnum");
return true;
}
// look for billingaddress_id in order and use it
if($order->billingaddress_id) {
if($order->billingaddress_id == $ivt_custnum) {
$return["billingaddress_id"] = $order->billingaddress_id;
} else {
$billingaddress = new Address($order->billingaddress_id);
if(!$billingaddress->id) {
die("Billingaddress " . $order->billingaddress_id . " does not exist (order " . $order->id . "; ivt customer $ivt_custnum)");
}
$return["billingaddress_id"] = $billingaddress->id;
}
}
// if no billingaddress_id in order, compare address of Address and ivt_customer and
// create new billingaddress if nessecary
$new_billing = [];
foreach(["company", "firstname", "lastname", "street", "zip", "city", "phone", "email", "uid", "billing_type", "billing_delivery",
"bank_account_bank", "bank_account_owner", "bank_account_iban", "bank_account_bic"] as $field) {
$new_billing[$field] = $owner->$field;
}
if($ivt_customer->company) {
if($ivt_customer->company != $owner->company) $new_billing["company"] = $ivt_customer->company;
} else {
if($ivt_customer->firstname != $owner->firstname) $new_billing["firstname"] = $ivt_customer->firstname;
if($ivt_customer->surname != $owner->lastname) $new_billing["lastname"] = $ivt_customer->surname;
}
if($ivt_customer->UID != $owner->uid) $new_billing["uid"] = $ivt_customer->UID;
if($ivt_customer->zip != $owner->zip) $new_billing["zip"] = $ivt_customer->zip;
if($ivt_customer->location != $owner->city) $new_billing["city"] = $ivt_customer->location;
if($ivt_customer->street." ".$ivt_customer->housenumber != $owner->street) $new_billing["street"] = $ivt_customer->street." ".$ivt_customer->housenumber;
if($ivt_customer->phone != $owner->phone) $new_billing["phone"] = $ivt_customer->phone;
if($ivt_customer->email != $owner->email) $new_billing["email"] = $ivt_customer->email;
$new_billing["billing_type"] = ($ivt_customer->payment == 1) ? "invoice" : "sepa";
$new_billing["billing_delivery"] = ($ivt_customer->paper_invoice == 1) ? "paper" : "email";
if($ivt_customer->bank_account_bank != $owner->bank_account_bank) $new_billing["bank_account_bank"] = $ivt_customer->bank_account_bank;
if($ivt_customer->bank_account_owner != $owner->bank_account_owner) $new_billing["bank_account_owner"] = $ivt_customer->bank_account_owner;
if($ivt_customer->bank_account_iban != $owner->bank_account_iban) $new_billing["bank_account_iban"] = $ivt_customer->bank_account_iban;
if($ivt_customer->bank_account_bic != $owner->bank_account_bic) $new_billing["bank_account_bic"] = $ivt_customer->bank_account_bic;
$billingaddress = AddressModel::create($new_billing);
// TODO: sync bank data
return $return;
}
private function checkIvtProduct($product) {
if(!$product->id) {
echo __METHOD__ . ": Keine Produkt id<br />\n";
return false;
}
if(!$product->name) {
echo __METHOD__ . ": Keine Produkt id<br />\n";
return false;
}
return true;
}
private function importContractconfig($ivt_customer, $ivt_product, &$contract, $doit = false) {
//return true;
//var_dump($contract, $contract->product, $contract->configgroups);
if(!is_array($contract->configgroups) || !count($contract->configgroups)) {
echo "no contract config";
return true;
}
$product = $contract->product;
if(!$product->id) {
echo "Produkt nicht gefunden für Contract " . $contract->id . "<br />\n";
exit;
}
// lookup radius data
$ruser = $this->getRadiusUser($ivt_customer, $ivt_product, $contract);
// lookup voip data
$voip_data = $this->getVoipData($ivt_customer, $ivt_product, $contract);
foreach($contract->configgroups as $cgroup) {
$items = $cgroup->items;
/*var_dump($cgroup);
var_dump($items);
exit;*/
foreach($items as $i) {
/** @var ContractconfigItem $i */
if(!$i->contract_id) {
$i->setContractId($contract->id);
}
//var_dump($i, $i->value);exit;
switch($i->name) {
case "bandwidth_down":
$i->value->set($product->attributes["bw_down"]->value);
$i->value->save();
break;
case "bandwidth_up":
$i->value->set($product->attributes["bw_up"]->value);
$i->value->save();
break;
case "radiususer_username":
$i->value->set($ruser->username);
$i->value->save();
break;
case "radiususer_password":
$i->value->set($ruser->getPassword());
$i->value->save();
break;
case "radiususer_ipaddress":
$i->value->set($ruser->getAttribute("Framed-IP-Address"));
$i->value->save();
break;
case "radiususer_netmask":
$i->value->set($ruser->getAttribute("Framed-IP-Netmask"));
$i->value->save();
break;
case "radiususer_iproute":
$i->value->set($ruser->getAttribute("Framed-Route"));
$i->value->save();
break;
case "radiususer_dns1":
$i->value->set($ruser->getAttribute("MS-Primary-DNS-Server"));
$i->value->save();
break;
case "radiususer_dns2":
$i->value->set($ruser->getAttribute("MS-Secondary-DNS-Server"));
$i->value->save();
break;
default:
$this->log->debug(__METHOD__.": ".$ivt_customer->id.": Kein Wert für Configgroupitem ".$i->name." gefunden");
}
//var_dump($i, $i->value);
}
}
var_dump($contract->configgroups);
exit;
}
$productMatch = IvtProductMatchModel::getFirst(["ivt_product_id" => $ivt_contract->pid]);
if(!$productMatch) {
echo "Kein Match zu IVT Product ".$ivt_contract->pid." gefunden.<br />\n";
exit;
}
if(!$this->checkIvtProduct($productMatch->ivtproduct)) {
exit;
}
$customer = AddressModel::getFirst(["customer_number" => $ivt_contract->cid]);
$ip = $productMatch->ivtproduct;
$product = $productMatch->product;
if(!$customer->id) {
echo "Kein thetool Kunde zu IVT customer ".$ivt_contract->cid." gefunden -> wird angelegt<br />\n";
$customer = $this->createAddressFromIvtCustomer($ivt_contract->customer);
if(!$customer) {
echo "Fehler beim anlegen der Adresse<br />\n";
exit;
/*
* backbone (vlan)
* Radiususer
* Bandbreite
* IPv4
* SIP daten
* Voip
* Rufnummer
* Webhosting
*
*/
}
private function getRadiusUser($ivt_customer, $ivt_product, $contract) {
// find radius user (kundennummer in radius info feld
$radius = new RadiusDB_Client();
$user_count = 0;
$user = $radius->getUserByCustnum($ivt_customer->id);
if(!$user) {
$this->log->debug("User in Radius nicht gefunden Kundennummer ".$ivt_customer->id);
return false;
}
}
/*
// check if contract was imported already
$existing_contract = ContractModel::getFirst(["imported_from" => "ivt", "imported_data" => $ivt_contract->id]);
if($existing_contract) {
//echo "Contract gibts schon ".$existing_contract->id."<br />\n";
continue;
}
*/
$contract_data = [];
$contract_data['owner_id'] = $customer->id;
//$contract_data['billingaddress_id'] = $customer->id;
$contract_data['product_id'] = $product->id;
$contract_data['product_name'] = $ip->name;
$contract_data['matchcode'] = "";
$contract_data['amount'] = 1;
$contract_data['price'] = $ip->price;
$contract_data['price_setup'] = 0;
$contract_data['finish_date'] = mktime(2,0,0,date("m"),1,date("Y"));
$contract_data['finish_date_by'] = 1;
$contract_data['imported_from'] = "ivt";
$contract_data['imported_data'] = $ivt_contract->id;
switch($ip->interval) {
case 0:
$contract_data['billing_period'] = 1;
break;
case 1:
$contract_data['billing_period'] = 12;
break;
}
$neu["customer"] = $customer;
$neu["ivtproduct"] = $ip;
$neu["product"] = $product;
$neu['action'] = "import";
$ignore = false;
if($product->price <= 0) {
$contract_data['price'] = 0;
$contract_data['price_setup'] = $ip->price;
$contract_data['billing_period'] = 0;
$neu['action'] = "ignore";
$ignore = true;
}
$contract = ContractModel::create($contract_data);
$neu["contract"] = $contract;
if($doit && !$ignore) {
$contract_id = $contract->save();
if(!$contract_id) {
echo "Fehler beim Contract speichern!<br />\n";
exit;
return $user;
// return data
}
private function getVoipData($ivt_customer, $ivt_product, $contract) {
// find voice number in ivt
$ivtnum = IvtCustomerTelephoneNrModel::getFirst(["cid" => $ivt_customer->id]);
if(!$ivtnum) return true;
$number = preg_replace('/^0043/', '43', $ivtnum->number);
if(!$number) return true;
// find number in block
$voicenumberblock = Voicenumberblock::findBlock($number);
if(!$voicenumberblock) return false;
if(!$voicenumberblock->isNumberInBlock($number)) {
die("Block für Nummer $number enthält nummer nicht.");
}
// create journal entry
$journal = ContractjournalModel::create([
'contract_id' => $contract_id,
'type' => "created_from",
'value' => "import",
'text' => "IVT"
]);
$journal_id = $journal->save();
if(!$journal_id) {
echo "Fehler beim Journal erstellen.<br />\n";
exit;
$voicenumber = $voicenumberblock->getVoicenumber($number);
if(!$voicenumber) {
die("Nummer $number gehört nicht in Block ".$voicenumberblock->id);
}
// import Contractconfig
$this->importContractconfig($ivt_customer, $ivt_product, $contract);
}
$data["contracts"][] = $neu;
if($neu['action'] == "ignore") {
$data['ignore']++;
}
// return voicenumber object
return $voicenumber;
}
return $data;
}
private function checkIvtCustomer($customer) {
// create customer if not exists
$old_custnum = $customer->id;
if(!$old_custnum) return false;
// TODO: sync bank data
return true;
}
private function checkIvtProduct($product) {
if(!$product->id) {
echo __METHOD__.": Keine Produkt id<br />\n";
return false;
}
if(!$product->name) {
echo __METHOD__.": Keine Produkt id<br />\n";
return false;
}
return true;
}
private function importContractconfig($ivt_customer, $ivt_product, $contract) {
var_dump($contract, $contract->product, $contract->configgroups);
if(!is_array($contract->configgroups) || !count($contract->configgroups)) {
return true;
}
$product = $contract->product;
if(!$product->id) {
echo "Produkt nicht gefunden für Contract ".$contract->id."<br />\n";
exit;
}
// lookup radius data
$radius_data = $this->getRadiusUser($ivt_customer, $ivt_product, $contract);
// lookup voip data
$voip_data = $this->getVoipData($ivt_customer, $ivt_product, $contract);
foreach($contract->configgroups as $cgroup) {
$items = $cgroup->items;
var_dump($cgroup);
var_dump($items);
foreach($items as $i) {
switch($i->name) {
case "bandwidth_down":
$i->value->set($product->attributes["bw_down"]->value);
$i->value->save();
break;
case "bandwidth_up":
$i->value->set($product->attributes["bw_up"]->value);
$i->value->save();
break;
case "radiususer_username":
$i->value->set($radius_data["username"]);
$i->value->sav();
break;
case "radiususer_password":
$i->value->set($radius_data["username"]);
$i->value->sav();
break;
case "radiususer_ipaddress":
$i->value->set($radius_data["ipaddress"]);
$i->value->sav();
break;
case "radiususer_ipprefix":
$i->value->set($radius_data["subnetmask"]);
$i->value->sav();
break;
private function createAddressFromIvtCustomer(IvtCustomer $cust) {
$address_data['customer_number'] = $cust->id;
$address_data['spin'] = $cust->MandatID;
$address_data['company'] = $cust->company;
$address_data['firstname'] = $cust->firstname;
$address_data['lastname'] = $cust->surname;
if($cust->company && !$cust->firstname && $cust->company == $cust->surname) {
$address_data["firstname"] = "";
$address_data["lastname"] = "";
}
}
}
exit;
/*
* backbone (vlan)
* Radiususer
* Bandbreite
* IPv4
* SIP daten
* Voip
* Rufnummer
* Webhosting
*
*/
}
private function getRadiusUser($ivt_customer, $ivt_product, $contract) {
// find radius user
// return data
}
private function getVoipData($ivt_customer, $ivt_product, $contract) {
}
private function createAddressFromIvtCustomer(IvtCustomer $cust) {
$address_data['customer_number'] = $cust->id;
$address_data['spin'] = $cust->MandatID;
$address_data['company'] = $cust->company;
$address_data['firstname'] = $cust->firstname;
$address_data['lastname'] = $cust->surname;
if($cust->company && !$cust->firstname && $cust->company == $cust->surname) {
$address_data["firstname"] = "";
$address_data["lastname"] = "";
}
$address_data['street'] = $cust->street;
if(strlen($cust->housenumber)) {
$address_data['street'] .= " ".$cust->housenumber;
}
$address_data['zip'] = $cust->zip;
$address_data['city'] = $cust->location;
$address_data['country'] = "";
$address_data['phone'] = $cust->phone;
$address_data['fax'] = "";
$address_data['mobile'] = "";
$address_data['email'] = $cust->email;
$address_data['note'] = $cust->extrainfo;
$address_data['uid'] = ($cust->UID) ? $cust->UID : null;
$address_data["bank_account_bank"] = "";
$address_data["bank_account_owner"] = ($cust->company) ? $cust->company : $cust->firstname . " " . $cust->surname;
$address_data["bank_account_iban"] = $cust->IBAN;
$address_data["bank_account_bic"] = $cust->BIC;
$address_data['street'] = $cust->street;
if(strlen($cust->housenumber)) {
$address_data['street'] .= " " . $cust->housenumber;
}
$address_data['zip'] = $cust->zip;
$address_data['city'] = $cust->location;
$address_data['country'] = "";
$address_data['phone'] = $cust->phone;
$address_data['fax'] = "";
$address_data['mobile'] = "";
$address_data['email'] = $cust->email;
$address_data['note'] = $cust->extrainfo;
if($cust->payment == 0 ) { // 0 = sepa / 1 = rechnung
$address_data['billing_type'] = "sepa";
} else {
$address_data['billing_type'] = "invoice";
$address_data['uid'] = ($cust->UID) ? $cust->UID : null;
$address_data["bank_account_bank"] = "";
$address_data["bank_account_owner"] = ($cust->company) ? $cust->company : $cust->firstname . " " . $cust->surname;
$address_data["bank_account_iban"] = $cust->IBAN;
$address_data["bank_account_bic"] = $cust->BIC;
if($cust->payment == 0) { // 0 = sepa / 1 = rechnung
$address_data['billing_type'] = "sepa";
} else {
$address_data['billing_type'] = "invoice";
}
if($cust->paper_invoice == 1) {
$address_data["billing_delivery"] = "paper";
} else {
$address_data["billing_delivery"] = "email";
}
if($cust->accept_adver == 2) {
$address_data["allow_contact"] = 1;
} else {
$address_data["allow_contact"] = 0;
}
if($cust->accept_info == 2) {
$address_data["allow_spin"] = 1;
} else {
$address_data["allow_spin"] = 0;
}
$address_data['create_by'] = 1;
$address_data['edit_by'] = 1;
$address = AddressModel::create($address_data);
if(!$address->save()) {
var_dump($address);
return false;
}
return $address;
}
if($cust->paper_invoice == 1) {
$address_data["billing_delivery"] = "paper";
} else {
$address_data["billing_delivery"] = "email";
}
if($cust->accept_adver == 2) {
$address_data["allow_contact"] = 1;
} else {
$address_data["allow_contact"] = 0;
}
if($cust->accept_info == 2) {
$address_data["allow_spin"] = 1;
} else {
$address_data["allow_spin"] = 0;
}
$address_data['create_by'] = 1;
$address_data['edit_by'] = 1;
$address = AddressModel::create($address_data);
if(!$address->save()) {
var_dump($address);
return false;
}
return $address;
}
}
+31 -26
View File
@@ -231,8 +231,34 @@ 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 == "configvalues") {
foreach($this->getProperty("configgroups") as $group) {
foreach($group->items as $item) {
$this->configvalues[$item->name] = $item;
}
}
return $this->configvalues;
}
if(!$this->id) {
return null;
}
@@ -240,32 +266,11 @@ class Contract extends mfBaseModel {
/*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 == "configvalues") {
foreach($this->getProperty("configgroups") as $group) {
foreach($group->items as $item) {
$this->configvalues[$item->name] = $item;
}
}
return $this->configvalues;
}
/*if($name == "contractConfigItems") {
$product = $this->getProperty("product");
@@ -2,7 +2,7 @@
class ContractconfigItem extends mfBaseModel {
private $value;
private $contract_id;
public $contract_id;
public function setContractId($contract_id) {
if(!is_numeric($contract_id)) {
@@ -3,15 +3,19 @@
class IvtCustomerProductModel {
public static function getAll() {
public static function getAll($order = false) {
$items = [];
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
$res = $db->select("customer_product", "*", "1=1 ORDER BY id");
if(!$order) {
$order = "id";
}
$res = $db->select("customer_product", "*", "1=1 ORDER BY $order");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new IvtCustomerProduct($data);
$items[] = new IvtCustomerTelephoneNr($data);
}
}
return $items;
@@ -24,7 +28,7 @@ class IvtCustomerProductModel {
$res = $db->select("customer_product", "*", "$where ORDER BY id LIMIT 1");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new IvtCustomerProduct($data);
$item = new IvtCustomerTelephoneNr($data);
if($item->id) {
return $item;
} else {
@@ -67,7 +71,7 @@ class IvtCustomerProductModel {
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new IvtCustomerProduct($data);
$items[] = new IvtCustomerTelephoneNr($data);
}
}
return $items;
@@ -0,0 +1,67 @@
<?php
class IvtCustomerTelephoneNr extends mfBaseModel {
protected $forcestr = [];
private $customer;
/**
* Takes ID or DB row as arguments
* @param id or table row $_
*/
public function __construct($_ = NULL) {
$this->log = mfLoghandler::singleton();
$this->data = new stdClass();
$this->table = "products";
$this->db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
if(is_numeric($_)) {
$this->fetch($_);
} elseif(is_object($_)) {
$this->load($_);
}
}
public function save() {
return true;
}
public function getProperty($name) {
if($this->$name == null) {
if($name == "customer") {
$ivtcustomer = new IvtCustomer($this->cid);
if($ivtcustomer->id) {
$this->ivtcustomer = $ivtcustomer;
}
return $this->ivtcustomer;
}
$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;
}
public function __debugInfo() {
$vars = get_object_vars($this);
if(is_object($vars['db'])) $vars['db'] = "object(FronkDB)";
if(is_object($vars['log'])) $vars['log'] = 'object(mfLoghandler)';
return $vars;
}
}
@@ -0,0 +1,115 @@
<?php
class IvtCustomerTelephoneNrModel {
public static function getAll($order = false) {
$items = [];
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
if(!$order) {
$order = "id";
}
$res = $db->select("customer_telephone_nr", "*", "1=1 ORDER BY $order");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new IvtCustomerTelephoneNr($data);
}
}
return $items;
}
public static function getFirst($filter = []) {
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
$where = self::getSqlFilter($filter);
$res = $db->select("customer_telephone_nr", "*", "$where ORDER BY id LIMIT 1");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new IvtCustomerTelephoneNr($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function count($filter) {
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) cnt FROM customer_telephone_nr WHERE $where ORDER by id";
$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(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM customer_telephone_nr WHERE $where ORDER by cid,pid,sid,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($limit['count'])) {
$sql .= " LIMIT ".$limit['count'];
}
}
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new IvtCustomerTelephoneNr($data);
}
}
return $items;
}
private static function getSqlFilter($filter) {
$where = "1=1 ";
if(array_key_exists("cid", $filter)) {
$cid = $filter['cid'];
if(is_numeric($cid)) {
$where .= " AND cid=$cid";
}
}
if(array_key_exists("pid", $filter)) {
$pid = $filter['pid'];
if(is_numeric($pid)) {
$where .= " AND pid=$pid";
}
}
if(array_key_exists("number", $filter)) {
$number = (string)FronkDB::singleton()->escape($filter['number']);
if($number) {
$where .= " AND number='$number'";
}
}
if(array_key_exists("number%", $filter)) {
$number = (string)FronkDB::singleton()->escape($filter['number']);
if($number) {
$where .= " AND number LIKE '%$number%'";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}
+1 -1
View File
@@ -288,7 +288,7 @@ class Order extends mfBaseModel {
$to = $values['to'];
if(!$subject || !$from || !$from_name || !$to) {
$this->log->warn("Order Fileupload Email not sent. (subject: '$subject', from: '$from', from_email: '$from_email', to: '$to')");
$this->log->warn("Order Fileupload Email not sent. (subject: '$subject', from: '$from_name', from_email: '$from', to: '$to')");
} else {
$filepath = MFUPLOAD_FILE_SAVE_PATH;
if($file->file->subfolder) {
-1
View File
@@ -1236,7 +1236,6 @@ class OrderController extends mfBaseController {
$order->deletePositions();
// TODO: check if Product is unused
$order->delete();
$this->layout()->setFlash("Bestellung gelöscht", "success");
$this->redirect("Order");
@@ -34,7 +34,23 @@ class Voicenumberblock extends mfBaseModel {
return $block;
}
public function getVoicenumber($number) {
if(!$this->isNumberInBlock($number)) return false;
$vn = VoicenumberModel::getFirst(["number" => $number]);
if(!$vn) {
$vn = VoicenumberModel::create([
"voicenumberblock_id" => $this->id,
"active" => 1,
"activated_date" => date("U"),
"number" => $number
]);
}
return $vn;
}
public function getFreeNumbers() {
if(!$this->id) return false;
@@ -9,6 +9,7 @@ class XinonFibuMergeModel {
public $strasse;
public $plz;
public $ort;
public $land;
public $create_by = null;
public $edit_by = null;
@@ -41,11 +42,14 @@ class XinonFibuMergeModel {
return $model;
}
public static function getFirst($filter = []) {
public static function getFirst($filter = [], $order = false) {
$db = FronkDB::singleton();
if(!$order) {
$order = "old_custnum";
}
$where = self::getSqlFilter($filter);
$res = $db->select("XinonFibuMerge", "*", "$where ORDER BY old_custnum LIMIT 1");
$res = $db->select("XinonFibuMerge", "*", "$where ORDER BY $order LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new XinonFibuMerge($data);
@@ -58,12 +62,16 @@ class XinonFibuMergeModel {
return null;
}
public static function getAll() {
public static function getAll($order = false) {
$items = [];
if(!$order) {
$order = "old_custnum";
}
$db = FronkDB::singleton();
$res = $db->select("XinonFibuMerge", "*", "1=1 ORDER BY old_custnum");
$res = $db->select("XinonFibuMerge", "*", "1=1 ORDER BY $order");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new XinonFibuMerge($data);
@@ -88,20 +96,25 @@ class XinonFibuMergeModel {
return 0;
}
public static function search($filter = [], $limit = false) {
public static function search($filter = [], $limit = false, $order = false) {
$items = [];
$db = FronkDB::singleton();
if(!$order) {
$order = "old_custnum";
}
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM XinonFibuMerge
WHERE $where
ORDER BY old_custnum";
ORDER BY $order";
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)) {
} elseif (is_numeric($limit['count'])) {
$sql .= " LIMIT " . $limit['count'];
}
}