request = $request; } public function run($doit = false) { echo "running...
\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
\n"; exit; } $productMatch = IvtProductMatchModel::getFirst(["ivt_product_id" => $ivt_contract->pid]); if(!$productMatch) { echo "Kein Match zu IVT Product ".$ivt_contract->pid." gefunden.
\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
\n"; $customer = $this->createAddressFromIvtCustomer($ivt_contract->customer); if(!$customer) { echo "Fehler beim anlegen der Adresse
\n"; exit; } } /* // 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."
\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!
\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.
\n"; exit; } // import Contractconfig $this->importContractconfig($ivt_customer, $ivt_product, $contract); } $data["contracts"][] = $neu; if($neu['action'] == "ignore") { $data['ignore']++; } } 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
\n"; return false; } if(!$product->name) { echo __METHOD__.": Keine Produkt id
\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."
\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; } } } 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; 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; } }