WIP Voicenumber Billing 2024-07-05

This commit is contained in:
Frank Schubert
2024-07-06 18:37:40 +02:00
parent 92edb9c812
commit 200af4802a
16 changed files with 417 additions and 220 deletions

View File

@@ -6,6 +6,12 @@ class Admin_IvtContractImport {
private $static_ivt_order_match = [];
private $no_matchcode = [];
private $ownerIdToBillingAddress = [];
private $ivt_to_voiceplan = [
1 => 1, // Ivt Standard
2 => 4, // Ivt Privat Plus
3 => 3, // Ivt Business Easy
4 => 1 // ESIT Partner Tarif
];
public function __construct($request = false) {
$this->request = $request;
@@ -185,6 +191,7 @@ class Admin_IvtContractImport {
$contract_data['billingaddress_id'] = $billingaddress_id;
$contract_data['product_id'] = $product->id;
$contract_data['product_name'] = $ip->name;
$contract_data['vatgroup_id'] = $product->vatgroup_id;
$contract_data['amount'] = 1;
$contract_data['price'] = $ivt_product->price;
$contract_data['price_setup'] = 0;
@@ -853,10 +860,10 @@ class Admin_IvtContractImport {
private function addVoipData($ivt_customer_id, $contracts) {
//$this->log->debug("in addVoipData(): cid ".$ivt_customer_id);
if($ivt_customer_id == 1376) {
/*if($ivt_customer_id == 1376) {
$this->log->debug("Not importing reseller voicenumbers for PROMETHEUS - Markus Paar [1376]");
return true;
}
}*/
$ported_in = [];
$voicenumbers = [];
@@ -867,7 +874,19 @@ class Admin_IvtContractImport {
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) {
$ivtnumbers = IvtCustomerTelephoneNrModel::search(["cid" => $ivt_customer_id]);
if($ivt_customer_id == 1840) {
$injecting_ivtnumber = new IvtCustomerTelephoneNr();
$injecting_ivtnumber->number = "433152255410";
$ivtnumbers[] = $injecting_ivtnumber;
$injecting_ivtnumber = new IvtCustomerTelephoneNr();
$injecting_ivtnumber->number = "433159258910";
$ivtnumbers[] = $injecting_ivtnumber;
}
foreach($ivtnumbers as $ivtnum) {
$number = preg_replace('/^0043/', '43', $ivtnum->number);
if(!$number) continue;
@@ -895,22 +914,35 @@ class Admin_IvtContractImport {
$voice_contract = false;
// always create new voice contract for special customers
$new_nolink_contract = false;
if($ivt_customer_id == 1376) {
$new_nolink_contract = true;
/*echo "is PROMETHEUS number\n";
//if(in_array($number, [43313228451, 43313228406, 43720666572, 43313228400, 4331324890, 43720103806])) {
$prometheus_primary_contract = ContractModel::getFirst(["customer_number" => 1376]);
$voice_contract = $this->createVoiceContract($prometheus_primary_contract, true);
} else {
foreach($contracts as $contract) {
if(array_key_exists("needs_number", $contract->product->attributes) && $contract->product->attributes["needs_number"] == 1) {
$voice_contract = $this->createVoiceContract($contracts, true);*/
} elseif($ivt_customer_id == 1840) {
$new_nolink_contract = true;
/*//if(in_array($number, [433152255410, 433159258910])) {
$lugitsch_primary_contract = ContractModel::getFirst(["customer_number" => 1840]);
$voice_contract = $this->createVoiceContract($contracts, true);*/
}
if(!$new_nolink_contract) {
// try finding voice contract, otherwise create it
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);
}
}
if(!$voice_contract) {
$voice_contract = $this->createVoiceContract($contracts, $new_nolink_contract);
}
//var_dump($voice_contract);exit;
@@ -971,6 +1003,9 @@ class Admin_IvtContractImport {
$confitem->value->set($contract_new_numbers);
$confitem->save();
// import Voiceplan
$this->getVoiceplan($voice_contract);
$voice_contract->matchcode = implode(", ", $contract_matchcode_numbers);
$voice_contract->save();
@@ -980,6 +1015,31 @@ class Admin_IvtContractImport {
return true;
}
/**
* @var Contract $contract
*/
private function getVoiceplan($contract) {
$cid = $contract->owner->customer_number;
$ivt_customer = new IvtCustomer($cid);
if(!$ivt_customer) {
die(__METHOD__.": Ivt Customer nicht gefunden\n");
}
$ivt_plan = $ivt_customer->telephony_pricelist;
if(!array_key_exists($ivt_plan, $this->ivt_to_voiceplan)) {
die("Invalid Ivt Voiceplan: ".$ivt_plan."\n");
}
$new_plan = $this->ivt_to_voiceplan[$ivt_plan];
$contract->setConfigValue("voicenumberblock_voiceplan_id", $new_plan);
/*$voiceplan_item = $contract->getConfigValue("voicenumberblock_voiceplan_id");
$voiceplan_item->set($new_plan);
$voiceplan_item->save();
*/
return true;
}
private function createVoiceContract($contracts, $nolink = false) {
// find rufnummer only product (residential or business)
$product = new Product(101); // Telefonie (nur Rufnummer - Privat)
@@ -1010,6 +1070,7 @@ class Admin_IvtContractImport {
$data["price_setup"] = $product->price_setup;
$data["price_nne"] = $product->price_nne;
$data["price_nbe"] = $product->price_nbe;
$data["vatgroup_id"] = $product->vatgroup_id;
$data["billing_delay"] = $product->billing_delay;
$data["billing_period"] = $product->billing_period;
$data["order_date"] = $fc->order_date;