diff --git a/application/Admin/functions/IvtContractImport.php b/application/Admin/functions/IvtContractImport.php index 5ebd40712..93fc58768 100644 --- a/application/Admin/functions/IvtContractImport.php +++ b/application/Admin/functions/IvtContractImport.php @@ -91,7 +91,7 @@ class Admin_IvtContractImport { $last_cid = 0; $i = 0; - foreach(IvtCustomerProductModel::search(["lastdate>", "2023-04-01"]) as $ivt_contract) { + 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; @@ -173,7 +173,7 @@ class Admin_IvtContractImport { $contract_data['product_id'] = $product->id; $contract_data['product_name'] = $ip->name; $contract_data['amount'] = 1; - $contract_data['price'] = $ip->price; + $contract_data['price'] = $ivt_product->price; $contract_data['price_setup'] = 0; $contract_data['price_nne'] = 0; $contract_data['price_nbe'] = 0; @@ -760,6 +760,7 @@ class Admin_IvtContractImport { } $contract_new_numbers = []; + $contract_matchcode_numbers = []; // update all numbers foreach($all_numbers as $voicenumber) { $voicenumber->contract_id = $voice_contract->id; @@ -773,6 +774,7 @@ class Admin_IvtContractImport { die("Fehler beim Speichern der neuen Nummer ".$voicenumber->number); } $contract_new_numbers[] = $voicenumber->number; + $contract_matchcode_numbers[] = preg_replace('/^\+?43 */', '0', $voicenumber->number); } @@ -786,6 +788,9 @@ class Admin_IvtContractImport { $confitem->value->set($contract_new_numbers); $confitem->save(); + $voice_contract->matchcode = implode(", ", $contract_matchcode_numbers); + $voice_contract->save(); + // return voicenumber object diff --git a/application/Admin/functions/IvtCreditImport.php b/application/Admin/functions/IvtCreditImport.php index a07154abe..a155bc2b2 100644 --- a/application/Admin/functions/IvtCreditImport.php +++ b/application/Admin/functions/IvtCreditImport.php @@ -12,6 +12,10 @@ class Admin_IvtCreditImport { 2267, 2934 ]; + private $cust_cred_id_to_customer_id = [ + 2891 => 104004, + + ]; public function __construct($request = false) { $this->request = $request; @@ -20,6 +24,7 @@ class Admin_IvtCreditImport { public function run($doit = false) { $i = 0; + $c = 0; foreach(IvtCustomerCreditingModel::getAll() as $cust_cred) { /*if($i > 200) { continue; @@ -33,12 +38,23 @@ class Admin_IvtCreditImport { var_dump($cust_cred->crediting_product); exit;*/ - if(!$cust_cred->customer) continue; + $ivt_netowner = $cust_cred->netowner; - $ivt_customer = $cust_cred->customer; $ivt_cred_product = $cust_cred->crediting_product; + if(array_key_exists($cust_cred->id, $this->cust_cred_id_to_customer_id)) { + $ivt_customer = new IvtCustomer($this->cust_cred_id_to_customer_id[$cust_cred->id]); + } else { + $ivt_customer = $cust_cred->customer; + } + + if(!$ivt_customer) { + echo __METHOD__.": No customer in cust_cred ".$cust_cred->id."\n"; + continue; + } + + $customer = AddressModel::getFirst(["customer_number" => $ivt_customer->id]); $netowner = AddressModel::getFirst(["customer_number" => $ivt_netowner->id]); if(array_key_exists($ivt_netowner->id, $this->netownerid)) { @@ -46,12 +62,14 @@ class Admin_IvtCreditImport { } if(!$customer) { - $this->log->debug("No Customer ".$ivt_customer->id." cust_cred ".$cust_cred->id); + echo __METHOD__ . ": No Customer ".$ivt_customer->id." cust_cred ".$cust_cred->id."\n"; + //$this->log->debug("No Customer ".$ivt_customer->id." cust_cred ".$cust_cred->id); exit; } if(!$netowner) { - $this->log->debug("No netowner ".$ivt_netowner->id); + echo __METHOD__ . ": No Netowner ".$ivt_netowner->id."\n"; + //$this->log->debug("No netowner ".$ivt_netowner->id); exit; } @@ -59,6 +77,8 @@ class Admin_IvtCreditImport { // DEBUG: not all contracts imported yet if(!count($contracts)) { + $ivt_contract_count = IvtCustomerProductModel::count(["cid" => $customer->id]); + echo __METHOD__ . ": Contract not found for credit ".$cust_cred->id." Kunde ".$customer->getCompanyOrName()." (".$customer->customer_number."; $ivt_contract_count IVT Contracts), GS an ".$netowner->getCompanyOrName()." (".$netowner->customer_number.")\n"; continue; } // use first contract as primary contract @@ -81,6 +101,7 @@ class Admin_IvtCreditImport { } if(!$primary_contract) { + //echo __METHOD__ . ": Contract not found for credit ".$cust_cred->id."\n"; $this->log->debug("No primary contract cust ".$ivt_customer->id); } @@ -120,9 +141,10 @@ class Admin_IvtCreditImport { $cred_contract = ContractModel::create($data); if(!$cred_contract->save()) { $this->log->debug("error saving credit contract"); - echo "error saving credit contract"; + echo __METHOD__.": error saving credit contract"; exit; } + $c++; // Link to all Contracts of Customer @@ -138,6 +160,8 @@ class Admin_IvtCreditImport { $link->save(); } } + + echo "Imported $i credits; $c Contracts erstellt\n"; } } \ No newline at end of file diff --git a/application/IvtCustomerCrediting/IvtCustomerCrediting.php b/application/IvtCustomerCrediting/IvtCustomerCrediting.php index b7e3560a2..a5bd3c83e 100644 --- a/application/IvtCustomerCrediting/IvtCustomerCrediting.php +++ b/application/IvtCustomerCrediting/IvtCustomerCrediting.php @@ -7,13 +7,13 @@ class IvtCustomerCrediting extends mfBaseModel { public function __construct($_=NULL) { - $this->log = mfLoghandler::singleton(); + $this->log = mfLoghandler::singleton(); $this->data = new stdClass(); $this->table = "customer_crediting"; $this->db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); - if(is_numeric($_)) { + if(is_numeric($_)) { $this->fetch($_); } elseif(is_object($_)) { $this->load($_); diff --git a/application/Voicenumber/Voicenumber.php b/application/Voicenumber/Voicenumber.php index 64602a276..0804c3f41 100644 --- a/application/Voicenumber/Voicenumber.php +++ b/application/Voicenumber/Voicenumber.php @@ -13,14 +13,21 @@ class Voicenumber extends mfBaseModel { return true; } - public function getPrettyNumber() { + public function getPrettyNumber($include_cc = true) { if(!$this->voicenumberblock_id) return $this->number; $block = $this->getProperty("block"); - $prefix = $this->block->countrycode; + $prefix = ""; + $return = ""; + + if($include_cc) { + $prefix = $this->block->countrycode." "; + $return = $this->block->countrycode." "; + } else { + $return = "0"; + } $prefix .= $this->block->areacode; - - $return = $this->block->countrycode." ".$this->block->areacode." ".substr($this->number, strlen($prefix)); + $return .= $this->block->areacode." ".substr($this->number, strlen($prefix)); return $return; } diff --git a/scripts/contract/import-ivt.php b/scripts/contract/import-ivt.php index 30522c0b6..e2451c6ed 100644 --- a/scripts/contract/import-ivt.php +++ b/scripts/contract/import-ivt.php @@ -16,14 +16,14 @@ define("INTERNAL_USER_ID", $me->id); require_once(APPDIR."Admin/functions/IvtContractImport.php"); require_once(APPDIR."Admin/functions/IvtCreditImport.php"); + echo "Import Contracts from IVT\n"; $import = new Admin_IvtContractImport(); $data = $import->run(1); -exit; +//exit; echo "Import Credit from IVT\n"; $import = new Admin_IvtCreditImport(); $data = $import->run(1); - diff --git a/scripts/contract/test.php b/scripts/contract/test.php new file mode 100644 index 000000000..6a8c60875 --- /dev/null +++ b/scripts/contract/test.php @@ -0,0 +1,56 @@ +#!/usr/bin/php +id); + +$cms = 0; +$cys = 0; +foreach(ContractModel::search(["billing_period" => 1]) as $contract) { + $cms += $contract->price; +} + +$First = new DateTime("2024-04-10 00:00:00"); +$Last = new DateTime("2024-05-10 23:59:59"); + +foreach(ContractModel::search(["billing_period" => 12]) as $contract) { + if($contract->finish_date >= $First->getTimestamp() && $contract->finish_date <= $Last->getTimestamp()) { + $cys += $contract->price; + } +} + +$cts = $cms + $cys; + +echo "Contract Monthly Sum: $cms\n"; +echo "Contract Yearly Sum: $cys\n"; +echo "Contract Total Sum: $cts\n"; + + + + +$ims = 0; +$iys = 0; + +foreach(IvtCustomerProductModel::getAll() as $ivt_contract) { + $product = $ivt_contract->product; + if($product->interval < 1) { + $ims += $product->price; + } elseif($product->interval == 1 && $ivt_contract->lastdate == "2023-06-06") { + $iys += $product->price; + } +} + +$its = $ims + $iys; + +echo "IvtContract Monthly Sum: $ims\n"; +echo "IvtContract Yearly Sum: $iys\n"; +echo "IvtContract Total Sum: $its\n"; \ No newline at end of file