WIP Contract / IVT Import2024-05-23

This commit is contained in:
Frank Schubert
2024-05-23 18:16:41 +02:00
parent 72c406766c
commit ac598e83e9
9 changed files with 472 additions and 117 deletions
+194 -14
View File
@@ -5,7 +5,7 @@ class Admin_IvtContractImport {
private $log;
private $static_ivt_order_match = [];
public function __construct($request) {
public function __construct($request = false) {
$this->request = $request;
$this->log = mfLoghandler::singleton();
@@ -32,12 +32,39 @@ class Admin_IvtContractImport {
561 => false,
11409 => 1222, // x-tec 1842
14192 => 2596
14192 => 2596,
//tourismusverband thermen- & vulkanland
11221 => 1120,
11222 => 1044,
11223 => 1003,
11224 => 1004,
11225 => 1002,
11226 => 999,
11227 => 1000,
2987 => 4126, // Atos
14890 => 3612,
14891 => 3612,
13551 => 2776, // Wolfgang Lipp
14908 => 2776,
13552 => 2055,
10550 => 230, // Anneliese Wabnegg
10551 => 230,
10995 => 1190
];
}
/* TODO: Credit */
/* TODO: Credit */
public function run($doit = false) {
echo "running...<br />\n";
//echo "running...<br />\n";
$data = [];
$data['ignore'] = 0;
$data["contracts"] = [];
@@ -47,7 +74,7 @@ class Admin_IvtContractImport {
$i = 0;
foreach(IvtCustomerProductModel::search(["lasdt_date>", "2023-04-01"], "cid") as $ivt_contract) {
if($i > 1000 && $ivt_contract->cid != $last_cid) break; // only break after the last ivtcontract of this customer
//if($i > 1000 && $ivt_contract->cid != $last_cid) break; // only break after the last ivtcontract of this customer
$last_cid = $ivt_contract->cid;
$i++;
@@ -166,7 +193,14 @@ class Admin_IvtContractImport {
$ignore = true;
}
if($product->billing_period > 1 && $ivt_contract->last_date < "2023-04-08")
// filter cancelled products
/* // disabled weil gibt keine
if($product->billing_period == 1 && $ivt_contract->lastdate < "2024-04-09") {
continue;
}
if($product->billing_period >= 12 && $ivt_contract->lastdate < "2023-06-06") {
continue;
}*/
/*
* Try to match ivt contract to thetool Order
@@ -254,9 +288,11 @@ class Admin_IvtContractImport {
}
if($doit) {
$this->log->debug("Linking new contracts and creating missing matchcodes");
$this->log->debug("Linking new contracts, creating missing matchcodes and adding voip data");
//var_dump($new_contracts[1789]);exit;
foreach($new_contracts as $ivt_customer_id => $contracts) {
$this->addVoipData($ivt_customer_id, $contracts);
if(count($contracts) < 2) continue;
$prev_contracts = [];
$primary_matchcode = false;
@@ -311,7 +347,7 @@ class Admin_IvtContractImport {
}
}
$this->addVoipData($ivt_customer, $customer);
}
return $data;
@@ -591,7 +627,7 @@ class Admin_IvtContractImport {
$found_product++;
}
if($found_product > 1) {
die("Mehr als eine Bestellung für ivt_customer ".$ivt_customer->id." gefunden.\n" . print_r($owner, true));
die("Mehr als eine Bestellung für ivt_customer ".$ivt_customer->id." (ivt contract ".$ivt_contract->id.") gefunden.\n" . print_r($owner, true));
}
}
$order = new Order($order_id);
@@ -621,36 +657,180 @@ class Admin_IvtContractImport {
// return data
}
private function addVoipData($ivt_customer, $customer) {
private function addVoipData($ivt_customer_id, $contracts) {
//$this->log->debug("in addVoipData(): cid ".$ivt_customer_id);
if($ivt_customer_id == 1376) {
$this->log->debug("Not importing reseller voicenumbers for PROMETHEUS - Markus Paar [1376]");
return true;
}
$ported_in = [];
$voicenumbers = [];
// find voice numbers in ivt
foreach(IvtCustomerTelephoneNrModel::search(["cid" => $ivt_customer->id]) as $ivtnum) {
$ivt_num_count = IvtCustomerTelephoneNrModel::count(["cid" => $ivt_customer_id]);
if(!$ivt_num_count) {
$this->log->debug("No voicenumber in ivt for cid ".$ivt_customer_id);
return false;
}
$this->log->debug("$ivt_num_count voicenumbers in ivt for cid ".$ivt_customer_id);
foreach(IvtCustomerTelephoneNrModel::search(["cid" => $ivt_customer_id]) as $ivtnum) {
$number = preg_replace('/^0043/', '43', $ivtnum->number);
if(!$number) return true;
if(!$number) continue;
// find number in block
$voicenumberblock = Voicenumberblock::findBlock($number);
if(!$voicenumberblock) {
$ported_in[] = $number;
continue;
}
if(!$voicenumberblock->isNumberInBlock($number)) {
die("Block für Nummer $number enthält nummer nicht.");
echo "Block für Nummer $number enthält nummer nicht.\n";
exit;
}
$voicenumber = $voicenumberblock->getVoicenumber($number);
if(!$voicenumber) {
die("Nummer $number gehört nicht in Block ".$voicenumberblock->id);
echo "Nummer $number gehört nicht in Block ".$voicenumberblock->id."\n";
exit;
}
$voicenumbers[] = $voicenumber;
}
$voice_contract = false;
foreach($contracts as $contract) {
if(array_key_exists("needs_number", $contract->product->attributes) && $contract->product->attributes["needs_number"] == 1) {
$voice_contract = $contract;
}
}
if(!$voice_contract) {
$voice_contract = $this->createVoiceContract($contracts);
}
//var_dump($voice_contract);exit;
// put all numbers in $all_numbers array
$all_numbers = [];
foreach($voicenumbers as $voicenumber) {
$all_numbers[] = $voicenumber;
}
foreach($ported_in as $voicenumber) {
// create single number if it does not exist
$ported_number = VoicenumberModel::getFirst(["number" => $voicenumber]);
if(!$ported_number) {
$num_data = [];
if($voice_contract->orderproduct_id) {
$num_data["orderproduct_id"] = $voice_contract->orderproduct_id;
}
$ported_number = VoicenumberModel::create([
"voicenumberblock_id" => null,
"number" => $voicenumber,
"port_in_date" => date("U"),
"ported_in" => 1,
"ported_from" => "A1 Telekom Austria",
]);
} else {
die("Importierte Nummer gibts bereits $voicenumber");
}
$all_numbers[] = $ported_number;
}
$contract_new_numbers = [];
// update all numbers
foreach($all_numbers as $voicenumber) {
$voicenumber->contract_id = $voice_contract->id;
$voicenumber->active = 1;
$voicenumber->activated_date = date("U");
$voicenumber->routing = "kolmisoft";
$voicenumber->comment = "IVT Import ".date("Y-m-d");
if(!$voicenumber->save()) {
die("Fehler beim Speichern der neuen Nummer ".$voicenumber->number);
}
$contract_new_numbers[] = $voicenumber->number;
}
if(array_key_exists("voicenumberblock_voicenumber", $voice_contract->configvalues)) {
$confitem = $voice_contract->configvalues["voicenumberblock_voicenumber"];
} else {
$confitem = ContractconfigItemModel::getFirst(["name" => "voicenumberblock_voicenumber"]);
$confitem->setContractId($voice_contract->id);
}
$confitem->value->set($contract_new_numbers);
$confitem->save();
// return voicenumber object
return $voicenumber;
return true;
}
private function createVoiceContract($contracts) {
// find rufnummer only product (residential or business)
$product = new Product(101); // Telefonie (nur Rufnummer - Privat)
$sla_id = 4;
foreach($contracts as $contract) {
if($contract->sla_id < 4) {
$product = new Product(102); // Telefonie (nur Rufnummer - Business)
$sla_id = 3;
}
}
// first contract
$fc = $contracts[0];
$data = [];
$data["orderproduct_id"] = null;
$data["owner_id"] = $fc->owner_id;
$data["billingaddress_id"] = $fc->billingaddress_id;
$data["termination_id"] = null;
$data["product_id"] = $product->id;
$data["product_name"] = "Telefonie (nur Rufnummer)";
$data["product_info"] = null;
$data["amount"] = 1;
$data["sla_id"] = $sla_id;
$data["product_external"] = 0;
$data["product_external_id"] = null;
$data["price"] = $product->price;
$data["price_setup"] = $product->price_setup;
$data["price_nne"] = $product->price_nne;
$data["price_nbe"] = $product->price_nbe;
$data["billing_delay"] = $product->billing_delay;
$data["billing_period"] = $product->billing_period;
$data["order_date"] = $fc->order_date;
$data["finish_date"] = $fc->finish_date;
$data["finish_date_by"] = 1;
$data["note"] = null;
$voice_contract = ContractModel::create($data);
if(!$voice_contract->save()) {
$this->log->error("Unable to create voice contract for cust ".$fc->customer_number);
exit;
}
// link to all $contracts
foreach($contracts as $contract) {
if (ContractLinkModel::getFirst(["contract_id" => $voice_contract->id, "origin_contract_id" => $contract->id])) {
continue;
}
$link = ContractLinkModel::create([
'contract_id' => $voice_contract->id,
'origin_contract_id' => $contract->id,
'type' => 'link'
]);
$link->save();
}
return $voice_contract;
}
private function createAddressFromIvtCustomer(IvtCustomer $cust) {