diff --git a/application/Admin/functions/IvtContractImport.php b/application/Admin/functions/IvtContractImport.php index 4b72f984c..e9d2b3c1e 100644 --- a/application/Admin/functions/IvtContractImport.php +++ b/application/Admin/functions/IvtContractImport.php @@ -20,6 +20,7 @@ class Admin_IvtContractImport { $i = 0; foreach(IvtCustomerProductModel::search(["lasdt_date>", "2024-04-01"], "cid") as $ivt_contract) { + if($ivt_contract->cid == 1494); if($i > 150 && $ivt_contract->cid != $last_cid) break; // only break after the last ivtcontract of this customer $last_cid = $ivt_contract->cid; @@ -111,6 +112,8 @@ class Admin_IvtContractImport { $contract_data['finish_date_by'] = 1; $contract_data['imported_from'] = "ivt"; $contract_data['imported_data'] = $ivt_contract->id; + $contract_data['create_by'] = 1; + $contract_data['edit_by'] = 1; switch($ip->interval) { case 0: @@ -130,7 +133,7 @@ class Admin_IvtContractImport { $neu['action'] = "import"; $ignore = false; - if($product->price <= 0) { + if($product->price <= 0 && $ivt_contract->cid != 1799) { $contract_data['price'] = 0; $contract_data['price_setup'] = $ip->price; $contract_data['billing_period'] = 0; @@ -147,6 +150,10 @@ class Admin_IvtContractImport { foreach($order->products as $orderproduct) { if($orderproduct->product_id == $product->id) { $orderproduct_id = $orderproduct->id; + if($orderproduct->termination_id) { + $contract_data['termination_id'] = $orderproduct->termination_id; + } + break; } } if($orderproduct_id) { @@ -160,7 +167,7 @@ class Admin_IvtContractImport { } /* - * Create Conttract (dont save yet) + * Create Contract (dont save yet) */ $contract = ContractModel::create($contract_data); if(trim($ivt_contract->comment)) { @@ -183,7 +190,7 @@ class Admin_IvtContractImport { if(!array_key_exists($ivt_customer->id, $new_contracts)) { $new_contracts[$ivt_customer->id] = []; } - $new_contracts[$ivt_customer->id][] = $contract_id; + $new_contracts[$ivt_customer->id][] = $contract; // create journal entry @@ -191,7 +198,7 @@ class Admin_IvtContractImport { 'contract_id' => $contract_id, 'type' => "created_from", 'value' => "import", - 'text' => "IVT" + 'text' => "IVT customer_product ".$ivt_contract->id."; cid: ".$ivt_contract->cid."; pid: ".$ivt_contract->pid ]); $journal_id = $journal->save(); if(!$journal_id) { @@ -202,7 +209,11 @@ class Admin_IvtContractImport { // import Contractconfig } - $contractconfig = $this->importContractconfig($ivt_customer, $ivt_product, $contract, ($doit && !$ignore)); + + if($doit && !$ignore) { + $contractconfig = $this->importContractconfig($ivt_customer, $ivt_product, $contract); + } + //var_dump($contractconfig);exit; $data["contracts"][] = $neu; @@ -216,28 +227,43 @@ class Admin_IvtContractImport { } if($doit) { + $this->log->debug("Linking new contracts and creating missing matchcodes"); //var_dump($new_contracts[1789]);exit; foreach($new_contracts as $ivt_customer_id => $contracts) { if(count($contracts) < 2) continue; $prev_contracts = []; + $primary_matchcode = false; - foreach($contracts as $contract_id) { - if(!$prev_contracts) { - $prev_contracts[] = $contract_id; + foreach($contracts as $contract) { + if($contract->matchcode && !$primary_matchcode && !preg_match('/(Pauschalen|TV|Managed Services|Vorbestellung|Mobilfunk|Standortvernetzung|Colo|Vorort|Webhosting|zusatz)/i',$contract->product->productgroup->name)) { + $primary_matchcode = $contract->matchcode; + } + if($primary_matchcode && !$contract->matchcode) { + $contract->matchcode = $primary_matchcode; + $contract->save(); + } + + if(!count($prev_contracts)) { + $prev_contracts[] = $contract; continue; } foreach($prev_contracts as $prev) { - if (ContractLinkModel::getFirst(["contract_id" => $contract_id, "origin_contract_id" => $prev])) { + if(!$prev->matchcode && $primary_matchcode) { + $prev->matchcode = $primary_matchcode; + $prev->save(); + } + + if (ContractLinkModel::getFirst(["contract_id" => $contract->id, "origin_contract_id" => $prev->id])) { continue; } $link = ContractLinkModel::create([ - 'contract_id' => $contract_id, - 'origin_contract_id' => $prev, + 'contract_id' => $contract->id, + 'origin_contract_id' => $prev->id, 'type' => 'link' ]); $link->save(); } - $prev_contracts[] = $contract_id; + $prev_contracts[] = $contract; @@ -366,7 +392,7 @@ class Admin_IvtContractImport { private function importContractconfig($ivt_customer, $ivt_product, &$contract, $doit = false) { //return true; //var_dump($contract, $contract->product, $contract->configgroups); - + $this->log->debug("Getting Contractconfig for ivt_customer ".$ivt_customer->id); if(!is_array($contract->configgroups) || !count($contract->configgroups)) { //echo "no contract config"; @@ -396,17 +422,20 @@ class Admin_IvtContractImport { 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(); + if($ruser) { + $i->value->set($ruser->getAttribute("Rate-Limit-Down")); + $i->value->save(); + } break; case "bandwidth_up": - $i->value->set($product->attributes["bw_up"]->value); - $i->value->save(); + if($ruser) { + $i->value->set($ruser->getAttribute("Rate-Limit-Up")); + $i->value->save(); + } break; - case "radiususer_username": if($ruser) { $i->value->set($ruser->username); @@ -417,38 +446,45 @@ class Admin_IvtContractImport { if($ruser) { $i->value->set($ruser->getPassword()); $i->value->save(); - break; } + break; case "radiususer_ipaddress": + case "ipv4_address": if($ruser) { $i->value->set($ruser->getAttribute("Framed-IP-Address")); $i->value->save(); - break; + } + break; case "radiususer_netmask": + case "ipv4_netmask": if($ruser) { $i->value->set($ruser->getAttribute("Framed-IP-Netmask")); $i->value->save(); - break; + } + break; case "radiususer_iproute": if($ruser) { $i->value->set($ruser->getAttribute("Framed-Route")); $i->value->save(); - break; + } + break; case "radiususer_dns1": if($ruser) { $i->value->set($ruser->getAttribute("MS-Primary-DNS-Server")); $i->value->save(); - break; + } + break; case "radiususer_dns2": if($ruser) { $i->value->set($ruser->getAttribute("MS-Secondary-DNS-Server")); $i->value->save(); - break; + } + break; default: $this->log->debug(__METHOD__.": ".$ivt_customer->id.": Kein Wert für Configgroupitem ".$i->name." gefunden"); } diff --git a/application/Contract/Contract.php b/application/Contract/Contract.php index 5f1b81386..9b9c8de80 100644 --- a/application/Contract/Contract.php +++ b/application/Contract/Contract.php @@ -144,11 +144,19 @@ class Contract extends mfBaseModel { $termination_address = $termination->building->street.", ".$termination->building->zip." ".$termination->building->city; return $termination_address; } - - if(stripos($this->getProperty("product")->name, "dsl") != false) { - return $owner_address; - } - + + $product = $this->getProperty("product"); + /* + * exceptions for certain products + */ + foreach(["dsl", "standortgeber", "funkinternet", "glasfaser", "brettljausn"] as $qname) { + $qname = strtolower($qname); + $product_name = strtolower($product->name); + if(stripos($product_name, $qname) !== false) { + return $owner_address; + } + } + return false; }