From e49d47ed7dc6382cedd748fb24df429ee81e10fe Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Sun, 7 Jul 2024 21:08:32 +0200 Subject: [PATCH] Tweaks to Ivt Import --- .../Admin/functions/IvtContractImport.php | 38 +++++++++++++------ application/Contract/Contract.php | 19 ++++++++++ 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/application/Admin/functions/IvtContractImport.php b/application/Admin/functions/IvtContractImport.php index 556f75642..3a4432cd1 100644 --- a/application/Admin/functions/IvtContractImport.php +++ b/application/Admin/functions/IvtContractImport.php @@ -26,7 +26,6 @@ class Admin_IvtContractImport { * WHERE `cid` = 1840; */ $this->static_ivt_order_match = [ - 9 => false, 17245 => 3946, // lugitsch 1840 16704 => 3342, 16703 => 3342, @@ -84,7 +83,8 @@ class Admin_IvtContractImport { 14189 => 3322, // andeßner-angleitner 16722 => 3322, 16267 => 3079, // schmuck marianne - 16786 => 3079 + 16786 => 3079, + 17821 => 2364, // johann höfler ]; $this->no_matchcode = [ 9, @@ -111,7 +111,6 @@ class Admin_IvtContractImport { echo "Importing from $maxIvtContracts Ivt customer_products\n"; foreach(IvtCustomerProductModel::getAll() as $ivt_contract) { - //if($ivt_contract->cid < 104200) continue; //if($i > 1000 && $ivt_contract->cid != $last_cid) break; // only break after the last ivtcontract of this customer $last_cid = $ivt_contract->cid; @@ -204,13 +203,21 @@ class Admin_IvtContractImport { $contract_data['create_by'] = 1; $contract_data['edit_by'] = 1; - $finish_date = new DateTime($ivt_contract->lastdate); + if(!$ivt_contract->lastdate) { + $finish_date = new DateTime("now"); + } else { + $finish_date = new DateTime($ivt_contract->lastdate); + + } + $finish_date->modify("first day of this month"); switch($ip->interval) { case 0: $contract_data['billing_period'] = 1; - $finish_date->modify("+1 month"); + if($ivt_contract->lastdate) { + $finish_date->modify("+1 month"); + } break; case 1: $contract_data['billing_period'] = 12; @@ -340,6 +347,7 @@ class Admin_IvtContractImport { if($doit) { $this->log->debug("Linking new contracts, creating missing matchcodes and adding voip data"); + echo "Linking new contracts, creating missing matchcodes and adding voip data\n"; //var_dump($new_contracts[1789]);exit; foreach($new_contracts as $ivt_customer_id => $contracts) { $this->addVoipData($ivt_customer_id, $contracts); @@ -886,7 +894,9 @@ class Admin_IvtContractImport { foreach($ivtnumbers as $ivtnum) { $number = preg_replace('/^0043/', '43', $ivtnum->number); - if(!$number) continue; + if(!$number) { + continue; + } @@ -937,12 +947,9 @@ class Admin_IvtContractImport { } if(!$voice_contract) { - $voice_contract = $this->createVoiceContract($contracts, $new_nolink_contract); + $voice_contract = $this->createVoiceContract($contracts, $new_nolink_contract, $ivt_customer_id); } - - - //var_dump($voice_contract);exit; // put all numbers in $all_numbers array @@ -1039,7 +1046,7 @@ class Admin_IvtContractImport { } - private function createVoiceContract($contracts, $nolink = false) { + private function createVoiceContract($contracts, $nolink = false, $ivt_customer_id = false) { // find rufnummer only product (residential or business) $product = new Product(101); // Telefonie (nur Rufnummer - Privat) $sla_id = 4; @@ -1052,6 +1059,12 @@ class Admin_IvtContractImport { // first contract $fc = $contracts[0]; + if($fc) { + $finish_date = new DateTime("@".$fc->finish_date); + } else { + $finish_date = new DateTime("now"); + $finish_date->modify("first day of this month"); + } $data = []; $data["orderproduct_id"] = null; @@ -1073,11 +1086,12 @@ class Admin_IvtContractImport { $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"] = $finish_date->format("U"); $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; diff --git a/application/Contract/Contract.php b/application/Contract/Contract.php index 2d0eb89ad..d51b05e96 100644 --- a/application/Contract/Contract.php +++ b/application/Contract/Contract.php @@ -15,6 +15,7 @@ class Contract extends mfBaseModel { private $configvalues; private $isCancelled; private $journals; + private $orderjournals; private $links; private $linksWithCredit; private $linkFrom; @@ -333,6 +334,24 @@ class Contract extends mfBaseModel { $this->journals = array_reverse(ContractjournalModel::search(["contract_id" => $this->id])); return $this->journals; } + + if($name == "orderjournals") { + if(!$this->orderproduct_id) return null; + + $journals = []; + + $order = $this->getProperty("orderproduct")->order; + foreach($order->journal as $j) { + $oj = new Contractjournal(); + $oj->type = "order_comment"; + $oj->value = ""; + $oj->text = $j->text; + $journals[] = $oj; + } + + $this->orderjournals = $journals; + return $this->orderjournals; + } if($name == "links") { $this->links = ContractLinkModel::includesContractId($this->id, ["type" => "link"]);