Merge branch 'fronkdev' into 'master'

WIP Contract/Billing/Voicenumberbilling

See merge request fronk/thetool!424
This commit is contained in:
Frank Schubert
2024-07-06 16:40:44 +00:00
34 changed files with 8277 additions and 153 deletions

View File

@@ -76,8 +76,23 @@
}
$inputid = "itemvalues_".$item->id;
$array_count = 0;
?>
<?php if($item->multiple): ?>
<?php // TODO: spezial configs besser machen ?>
<?php if($item->name == "voicenumberblock_voiceplan_id"): ?>
<tr id="tr-<?=$inputid?>_0">
<th style="max-width: 50vw;"><?=$item->displayname?>:</th>
<td style="width: 50vw;">
<select class="form-control" name="<?=$inputname?>" id="<?=$inputid?>" <?=($item->multiple) ? "data-item-multiple='true'" : ""?>>
<option value="0"></option>
<?php foreach(VoiceplanModel::getAll() as $voiceplan): ?>
<option value="<?=$voiceplan->id?>" <?=($item->getValue() == $voiceplan->id) ? "selected='selected'" : ""?>><?=$voiceplan->name?></option>
<?php endforeach; ?>
</select>
<small><?=$item->description?></small>
</td>
</tr>
<?php elseif($item->multiple): ?>
<?php foreach($item->getValue() as $item_value): ?>
<tr id="tr-<?=$inputid?>_<?=$array_count?>">
<th style="max-width: 50vw;"><?=$item->displayname?><span class="array_counter"> (<?=$array_count + 1?>)</span>:</th>

View File

@@ -592,7 +592,7 @@ class Address extends mfBaseModel {
}*/
if($name == "links") {
$links = AddressLinkModel::search(['origin_address_id' => $this->id]);
$links = AddressLinkModel::search(['address_or_origin_id' => $this->id]);
//var_dump($links);exit;
foreach($links as $link) {
if(!array_key_exists($link->type, $this->links)) {

View File

@@ -91,7 +91,7 @@ class AddressLinkModel {
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
} elseif(is_numeric($count)) {
} elseif(is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['count'];
}
}
@@ -125,6 +125,13 @@ class AddressLinkModel {
$where .= " AND origin_address_id=$origin_address_id";
}
}
if(array_key_exists("address_or_origin_id", $filter)) {
$address_or_origin_id = $filter["address_or_origin_id"];
if(is_numeric($address_or_origin_id)) {
$where .= " AND (address_id=$address_or_origin_id OR origin_address_id=$address_or_origin_id)";
}
}
if(array_key_exists("type", $filter)) {
switch($filter['type']) {

View File

@@ -5,6 +5,13 @@ class Admin_IvtContractImport {
private $log;
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;
@@ -140,6 +147,7 @@ class Admin_IvtContractImport {
if(!$customer_check_return || !array_key_exists("billingaddress_id", $customer_check_return) || !$customer_check_return["billingaddress_id"]) {
echo "IVT Customer " . $ivt_contract->cid . " nicht im tool<br />\n";
var_dump($customer_check_return);
exit;
}
@@ -183,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;
@@ -413,77 +422,217 @@ class Admin_IvtContractImport {
die("Address $ivt_custnum not found!");
}
if(array_key_exists($owner->id, $this->ownerIdToBillingAddress)) {
return ["billingaddress_id" => $this->ownerIdToBillingAddress[$owner->id]];
}
$compare_address = $owner;
$compare_type = "owner";
$return["billingaddress_id"] = $owner->id;
$order = $this->findOrder($ivt_contract);
if(!$order) {
return ["billingaddress_id" => $owner->id];
$return["billingaddress_id"] = $owner->id;
$compare_address = $owner;
$compare_type = "owner";
}
// look for billingaddress_id in order and use it
if ($order->billingaddress_id) {
if ($order->billingaddress_id == $ivt_custnum) {
$return["billingaddress_id"] = $order->billingaddress_id;
} else {
$billingaddress = new Address($order->billingaddress_id);
if (!$billingaddress->id) {
die("Billingaddress " . $order->billingaddress_id . " does not exist (order " . $order->id . "; ivt customer $ivt_custnum)");
}
$return["billingaddress_id"] = $billingaddress->id;
if ($order && $order->billingaddress_id) {
$return["billingaddress_id"] = $order->billingaddress_id;
$billingaddress = new Address($order->billingaddress_id);
if (!$billingaddress->id) {
die("Billingaddress " . $order->billingaddress_id . " does not exist (order " . $order->id . "; ivt customer $ivt_custnum)");
}
$compare_address = $billingaddress;
$compare_type = "billingaddress";
}
// if no billingaddress_id in order, compare address of Address and ivt_customer and
// create new billingaddress if nessecary
if(!$compare_address) {
die("No Compare address");
}
$address_update = $this->compareBillingAddresses($ivt_customer, $compare_address);
if($address_update === true) {
$return["billingaddress_id"] = $compare_address->id;
} elseif(is_array($address_update) && count($address_update)) {
if($compare_type == "billingaddress") {
// update billingaddress
$compare_address->update($address_update);
if(!$compare_address->save()) {
die("error updateing Billingaddress");
}
$this->ownerIdToBillingAddress[$owner->id] = $compare_address->id;
$return["billingaddress_id"] = $compare_address->id;
} else {
// create billingaddress
$billingaddress = AddressModel::create($address_update);
try {
if(!$billingaddress->save()) {
var_dump($address_update);
die("error creating Billingaddress");
}
$return["billingaddress_id"] = $billingaddress->id;
if(!array_key_exists($owner->id, $this->ownerIdToBillingAddress)) {
$this->ownerIdToBillingAddress[$owner->id] = $billingaddress->id;
$this->log->debug(__METHOD__.": Creating billing link for owner ".$owner->id." ".$owner->getCompanyOrName()." with billing address ".$billingaddress->id." ".$billingaddress->getCompanyOrName());
$this->log->debug("OWNER:");
$this->log->debug(print_r($owner->data, true));
$this->log->debug("ADDRESS UPDATE:");
$this->log->debug(print_r($address_update, true));
// create addresslink
$link = AddressLinkModel::create([
'origin_address_id' => $owner->id,
'type' => "billing",
'address_id' => $billingaddress->id
]);
$link->save();
}
} catch (Exception $e) {
echo "Exception: ".$e->getMessage()."\n";
var_dump($address_update);
exit();
}
}
}
return $return;
}
private function compareBillingAddresses($ivt_customer, $tool_customer) {
$owner = $tool_customer;
$new_billing = [];
if ($ivt_customer->company) {
if ($ivt_customer->company != $owner->company) $new_billing["company"] = $ivt_customer->company;
if (strtolower(trim($ivt_customer->company)) != strtolower(trim($owner->company))) $new_billing["company"] = $ivt_customer->company;
} else {
if ($ivt_customer->firstname != $owner->firstname) $new_billing["firstname"] = $ivt_customer->firstname;
if ($ivt_customer->surname != $owner->lastname) $new_billing["lastname"] = $ivt_customer->surname;
if (strtolower(trim($ivt_customer->firstname)) != strtolower(trim($owner->firstname))) $new_billing["firstname"] = $ivt_customer->firstname;
if (strtolower(trim($ivt_customer->surname)) != strtolower(trim($owner->lastname))) $new_billing["lastname"] = $ivt_customer->surname;
}
//if ($ivt_customer->UID != $owner->uid) $new_billing["uid"] = $ivt_customer->UID;
if ($ivt_customer->zip != $owner->zip) $new_billing["zip"] = $ivt_customer->zip;
if ($ivt_customer->location != $owner->city) $new_billing["city"] = $ivt_customer->location;
if ($ivt_customer->street . " " . $ivt_customer->housenumber != $owner->street) $new_billing["street"] = $ivt_customer->street . " " . $ivt_customer->housenumber;
if ($ivt_customer->phone != $owner->phone) $new_billing["phone"] = $ivt_customer->phone;
if ($ivt_customer->email != $owner->email) $new_billing["email"] = $ivt_customer->email;
if (strtolower(trim($ivt_customer->zip)) != strtolower(trim($owner->zip))) $new_billing["zip"] = $ivt_customer->zip;
if (strtolower(trim($ivt_customer->location)) != strtolower(trim($owner->city))) $new_billing["city"] = $ivt_customer->location;
if (strtolower(trim($ivt_customer->street . " " . $ivt_customer->housenumber)) != strtolower(trim($owner->street))) $new_billing["street"] = $ivt_customer->street . " " . $ivt_customer->housenumber;
//if (strtolower(trim($ivt_customer->phone)) != strtolower(trim($owner->phone))) $new_billing["phone"] = $ivt_customer->phone;
if (strtolower(trim($ivt_customer->email)) != strtolower(trim($owner->email))) {
if($ivt_customer->email && (!$owner->email || $owner->email = "dummy@xinon.at")) {
$owner->email = strtolower(trim($ivt_customer->email));
$owner->save();
} else {
$new_billing["email"] = $ivt_customer->email;
}
}
if ($ivt_customer->payment == 1 && $owner->billing_type != "invoice") {
$new_billing["billing_type"] = "invoice";
} elseif ($ivt_customer->payment == 0 && $owner->billing_type != "sepa") {
$new_billing["billing_type"] = "sepa";
} elseif ($ivt_customer->paper_invoice == 1 && $owner->billing_delivery != "paper") {
$new_billing["billing_delivery"] = "paper";
} elseif ($ivt_customer->paper_invoice == 0 && $owner->billing_delivery != "email") {
$new_billing["billing_delivery"] = "email";
$billing_type = "";
$billing_delivery = "";
if($ivt_customer->payment == 1 && $owner->billing_type != "invoice") {
$billing_type = "invoice";
if($owner->billing_type) {
$new_billing["billing_type"] = "invoice";
} else {
$owner->billing_type = "invoice";
$owner->save();
}
} elseif($ivt_customer->payment == 0 && $owner->billing_type != "sepa") {
$billing_type = "sepa";
if($owner->billing_type) {
$new_billing["billing_type"] = "sepa";
} else {
$owner->billing_type = "sepa";
$owner->save();
}
} elseif($ivt_customer->paper_invoice == 1 && $owner->billing_delivery != "paper") {
$billing_delivery = "paper";
if($owner->billing_delivery) {
$new_billing["billing_delivery"] = "paper";
} else {
$owner->billing_delivery = "paper";
$owner->save();
}
} elseif($ivt_customer->paper_invoice == 0 && $owner->billing_delivery != "email") {
$billing_delivery = "email";
if($owner->billing_delivery) {
$new_billing["billing_delivery"] = "email";
} else {
$owner->billing_delivery = "email";
$owner->save();
}
}
//if($ivt_customer->bank_account_bank != $owner->bank_account_bank) $new_billing["bank_account_bank"] = $ivt_customer->bank_account_bank;
//if($ivt_customer->bank_account_owner != $owner->bank_account_owner) $new_billing["bank_account_owner"] = $ivt_customer->bank_account_owner;
$iban = strtoupper(trim($ivt_customer->IBAN));
$bic = strtoupper(trim($ivt_customer->BIC));
$iban = strtoupper(trim(str_replace(" ","", $ivt_customer->IBAN)));
$bic = strtoupper(trim(str_replace(" ","", $ivt_customer->BIC)));
if ((array_key_exists("billing_type", $new_billing) && $new_billing["billing_type"] == "sepa") || $ivt_customer->payment == 0 && ($iban || $bic)) {
if ($iban != strtoupper(trim($owner->bank_account_iban))) $new_billing["bank_account_iban"] = $iban;
if ($bic != strtoupper(trim($owner->bank_account_bic))) $new_billing["bank_account_bic"] = $bic;
if ($iban != strtoupper(trim(str_replace(" ","", $owner->bank_account_iban)))) $new_billing["bank_account_iban"] = $iban;
if ($bic != strtoupper(trim(str_replace(" ","", $owner->bank_account_bic)))) $new_billing["bank_account_bic"] = $bic;
}
$missing_fields = [];
if(array_key_exists("bank_account_bic", $new_billing) && !array_key_exists("bank_account_iban", $new_billing)) {
$owner->bank_account_bic = $new_billing["bank_account_bic"];
$owner->save();
unset($new_billing["bank_account_bic"]);
}
if(count($new_billing) == 2 && array_key_exists("billing_type", $new_billing) && array_key_exists("billing_delivery", $new_billing)) {
$owner->billing_type = $billing_type;
$owner->billing_delivery = $billing_delivery;
$owner->save();
return true;
}
if(count($new_billing) == 1) {
if(array_key_exists("billing_type", $new_billing)) {
$owner->billing_type = $billing_type;
$owner->save();
return true;
}
if(array_key_exists("billing_delivery", $new_billing)) {
$owner->billing_delivery = $billing_delivery;
$owner->save();
return true;
}
}
//$missing_fields = [];
$create = false;
foreach(["company", "firstname", "lastname", "street", "zip", "city", "phone", "email", "uid", "billing_type", "billing_delivery",
foreach(["company", "firstname", "lastname", "street", "zip", "city", "email", "uid", "billing_type", "billing_delivery",
"bank_account_iban", "bank_account_bic"] as $field) {
if(!array_key_exists($field, $new_billing)) {
/*if(!$owner->$field) {
if($field == "billing_delivery") {
$new_billing[$field] = "paper";
} else {
$new_billing[$field] = "";
}
} else {
$new_billing[$field] = $owner->$field;
}*/
$new_billing[$field] = $owner->$field;
} else {
if($field == "email" && $field = "dummy@xinon.at") continue;
$missing_fields[] = $field;
if($field == "email" && $new_billing["email"] == "dummy@xinon.at") continue;
$create = true;
}
}
/*
if($create) {
$billingaddress = AddressModel::create($new_billing);
//var_dump($billingaddress, $missing_fields);exit;
@@ -491,9 +640,14 @@ class Admin_IvtContractImport {
die("Error createing billingaddress\n");
}
$return["billingaddress_id"] = $billingaddress->id;
}*/
if($create) {
return $new_billing;
}
return ["billingaddress_id" => $owner->id];
return true;
}
private function checkIvtProduct($product) {
@@ -631,7 +785,7 @@ class Admin_IvtContractImport {
}
private function findOrder($ivt_contract) {
public function findOrder($ivt_contract) {
// find order
$ivt_customer = $ivt_contract->customer;
$ivt_product = $ivt_contract->product;
@@ -706,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 = [];
@@ -720,10 +874,24 @@ 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;
// find number in block
$voicenumberblock = Voicenumberblock::findBlock($number);
if(!$voicenumberblock) {
@@ -746,17 +914,37 @@ class Admin_IvtContractImport {
$voice_contract = false;
foreach($contracts as $contract) {
if(array_key_exists("needs_number", $contract->product->attributes) && $contract->product->attributes["needs_number"] == 1) {
$voice_contract = $contract;
}
// 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($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);
$voice_contract = $this->createVoiceContract($contracts, $new_nolink_contract);
}
//var_dump($voice_contract);exit;
// put all numbers in $all_numbers array
@@ -815,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();
@@ -824,7 +1015,32 @@ class Admin_IvtContractImport {
return true;
}
private function createVoiceContract($contracts) {
/**
* @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)
$sla_id = 4;
@@ -854,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;
@@ -863,21 +1080,23 @@ class Admin_IvtContractImport {
$voice_contract = ContractModel::create($data);
if(!$voice_contract->save()) {
$this->log->error("Unable to create voice contract for cust ".$fc->customer_number);
$this->log->error("Unable to create voice contract for cust " . $fc->customer_number);
exit;
}
// link to all $contracts
foreach($contracts as $contract) {
if (ContractLinkModel::getFirst(["contract_id" => $voice_contract->id, "origin_contract_id" => $contract->id])) {
continue;
if(!$nolink) {
foreach($contracts as $contract) {
if(ContractLinkModel::getFirst(["contract_id" => $voice_contract->id, "origin_contract_id" => $contract->id])) {
continue;
}
$link = ContractLinkModel::create([
'contract_id' => $voice_contract->id,
'origin_contract_id' => $contract->id,
'type' => 'link'
]);
$link->save();
}
$link = ContractLinkModel::create([
'contract_id' => $voice_contract->id,
'origin_contract_id' => $contract->id,
'type' => 'link'
]);
$link->save();
}
return $voice_contract;
@@ -902,7 +1121,7 @@ class Admin_IvtContractImport {
}
$address_data['zip'] = $cust->zip;
$address_data['city'] = $cust->location;
$address_data['country'] = "";
$address_data['country_id'] = 163; // 163 - Austria
$address_data['phone'] = $cust->phone;
$address_data['fax'] = "";
$address_data['mobile'] = "";

View File

@@ -154,10 +154,25 @@ class Admin_IvtCreditImport {
$data["billing_period"] = $primary_contract->billing_period;
$data["contract_term"] = $primary_contract->contract_term;
$data["order_date"] = $primary_contract->order_date;
$data["vatgroup_id"] = $primary_contract->product->vatgroup_id;
$data["finish_date"] = $primary_contract->finish_date;
$data["finish_date_by"] = $primary_contract->finish_date_by;
$data["note"] = $primary_contract->note;
$matchcode = "";
if($primary_contract->termination_id) {
$building = $primary_contract->termination->building;
if($building->networksection_id) {
$matchcode .= $building->networksection->name;
}
$matchcode .= $customer->getCompanyOrName();
$matchcode .= "; ".$building->street.", ".$building->zip." ".$building->city;
} else {
$matchcode .= "; ".$customer->street.", ".$customer->zip." ".$customer->city;
}
} else {
$create_date = new DateTime($cust_cred->created);
$create_date->setTime(2,0);
@@ -176,6 +191,7 @@ class Admin_IvtCreditImport {
$data["sla_id"] = 4;
$data["product_external"] = 0;
$data["product_external_id"] = null;
$data["vatgroup_id"] = 1;
$data["billing_delay"] = 0;
$data["billing_period"] = 1;
$data["contract_term"] = 12;
@@ -183,9 +199,17 @@ class Admin_IvtCreditImport {
$data["finish_date"] = $finish_date->getTimestamp();
$data["finish_date_by"] = 1;
$data["note"] = null;
$matchcode = $cust_cred->comment;
}
$data["matchcode"] = $cust_cred->comment;
$data["matchcode"] = $matchcode;
$data["owner_id"] = $netowner->id;
$data["billingaddress_id"] = $netowner->id;
$data["termination_id"] = null;

View File

@@ -3,6 +3,7 @@
class Billing extends mfBaseModel {
protected $forcestr = ["product_name","product_info","matchcode"];
private $contract;
private $vatgroup;

View File

@@ -101,6 +101,7 @@ class BillingController extends mfBaseController {
//$tomorrow->setTime(0,0,0);
$i = 0;
$v = 0;
//$yearly_not_before = new DateTime("2023-06-01");
@@ -109,7 +110,7 @@ class BillingController extends mfBaseController {
$now_day = date("d");
//$now_year = 2024;
//$now_month = 6;
$now_day = 3; // XXX for debugging only, must be removed
//$now_day = 3; // XXX for debugging only, must be removed
// XXX only for 1st Billing after IVT Import
//$yearly_not_before = new DateTime("$now_year-$now_month-01");
@@ -160,10 +161,6 @@ class BillingController extends mfBaseController {
$this->log->debug(__METHOD__.": Ignoring Contract ".$contract->id." because billing_period == 0");
continue;
}*/
if($contract->price == 0 && $contract->price_setup == 0) {
$this->log->debug(__METHOD__.": Ignoring Contract ".$contract->id." because price and price_setup == 0");
continue;
}
$cancel_date = false;
if($contract->cancel_date) {
@@ -295,6 +292,10 @@ class BillingController extends mfBaseController {
}
/*if($contract->price != 0 || $contract->price_setup != 0) {
$this->log->debug(__METHOD__.": Ignoring Contract ".$contract->id." because price and price_setup == 0");
continue;
}*/
$sday = $start_date->format("d");
$eday = $end_date->format("d");
@@ -354,13 +355,13 @@ class BillingController extends mfBaseController {
$data["owner_id"] = $contract->owner_id;
$data["billingaddress_id"] = ($contract->billingaddress_id) ? $contract->billingaddress_id : $contract->owner_id;
$data["customer_number"] = $contract->owner->customer_number;
$data["fibu_account_number"] = $contract->owner->fibu_account_number;
$data["company"] = $billingaddress->company;
$data["firstname"] = $billingaddress->firstname;
$data["lastname"] = $billingaddress->lastname;
$data["street"] = $billingaddress->street;
$data["zip"] = $billingaddress->zip;
$data["city"] = $billingaddress->city;
$data["country"] = $billingaddress->country->name;
$data["email"] = $billingaddress->email;
$data["uid"] = $billingaddress->uid;
$data["billing_type"] = $billing_type;
@@ -369,16 +370,41 @@ class BillingController extends mfBaseController {
$data["bank_account_owner"] = $billingaddress->bank_account_owner;
$data["bank_account_iban"] = $billingaddress->bank_account_iban;
$data["bank_account_bic"] = $billingaddress->bank_account_bic;
$data["matchcode"] = $contract->matchcode;
$data["product_id"] = $contract->product_id;
$data["product_name"] = $contract->product_name;
$data["product_info"] = $contract->product_info;
$data["amount"] = $contract->amount;
$data["price"] = $price;
$data["price_setup"] = $price_setup;
$data["vatrate"] = $contract->vatrate;
$data["billing_period"] = $contract->billing_period;
$matchcode = $contract->matchcode;
// if voice product and matchcode consists oh phonenumbers only, remove matchcode
if(array_key_exists("needs_number", $contract->product->attributes) && $contract->product->attributes["needs_number"] == 1 && preg_match('/^[0-9, ]+$]/', $matchcode)) {
$matchcode = "";
}
$data["matchcode"] = $matchcode;
if(!$contract->billingaddress->country_id) {
$billcountry = CountryModel::getFirst(["isocode" => TT_HOMECOUNTRY_ISOCODE]);
} else {
$billcountry = $contract->billingaddress->country;
}
$vatgroup = $contract->vatgroup;
$vatarea = "domestic";
if($billcountry->isocode != TT_HOMECOUNTRY_ISOCODE && $billcountry->is_eu) {
$vatarea = "eu";
} if($billcountry->isocode != TT_HOMECOUNTRY_ISOCODE && !$billcountry->is_eu) {
$vatarea = "other";
}
$data["country"] = $billcountry->name;
$data["vatrate"] = $vatgroup->rates[$vatarea]->rate;
$data["vatgroup_id"] = $contract->vatgroup_id;
$data["vatarea"] = $vatarea;
$billing = BillingModel::create($data);
if (!$billing->save()) {
var_dump($billing);
@@ -386,10 +412,170 @@ class BillingController extends mfBaseController {
}
$i++;
/*
* Create Voice Billing, if contract has voicenumbers
*/
$voicenumbers = VoicenumberModel::search(["contract_id" => $contract->id]);
if(count($voicenumbers)) {
//var_dump($voicenumbers);exit;
$voice_start_date = clone $start_date;
$voice_start_date->modify("-1 month");
$voice_start_date->setTime(0,0,0);
$voice_end_date = clone $voice_start_date;
$voice_end_date->modify("first day of this month");
$voice_end_date->modify("+1 months");
$voice_end_date->modify("-1 day");
$voice_end_date->setTime(23,59,59);
$this->log->debug("Voice End Date: ".$voice_end_date->format("Y-m-d H:i:s"));
$earliest_start_date = $start_date;
$voicebills = [];
$zones = [];
$destinations_cache = [];
$voiceplan_id = $contract->getConfigValue("voicenumberblock_voiceplan_id")->int;
if (!$voiceplan_id) {
$this->log->debug(__METHOD__ . ": No voiceplan_id in Contract " . $contract->id. ". Numbers: ".count($voicenumbers));
continue;
}
$voiceplan = new Voiceplan($voiceplan_id);
// always look for whole month
// numbers usually don't change owner without at least a few months being stale
if($voice_start_date->format("d") > 1) {
$voice_start_date->modify("first day of this month");
}
foreach ($voicenumbers as $voicenumber) {
$vbill = BillingVoicenumberModel::getFirst(["contract_id" => $contract->id, "voicenumber" => $voicenumber->number, "start_date" => $voice_start_date->format("Y-m-d")]);
if ($vbill) {
//var_dump($vbill);exit;
continue; // number was already billed in this period
}
$calls = VoiceCallHistoryModel::getVoiceCallHistoryAsEntity(["contract_id" => $contract->id, "start" => ["from" => $voice_start_date->getTimestamp(), "to" => $voice_end_date->getTimestamp()]]);
foreach ($calls as $call) {
//var_dump($call);
$number = $call->voice_account;
$dest_nummer = $call->destination;
if (array_key_exists($dest_nummer, $destinations_cache)) {
$destination = $destinations_cache[$dest_nummer];
} else {
$destination = $voiceplan->getDestinationByNumber($dest_nummer);
$destinations_cache[$dest_nummer] = $destination;
}
//var_dump($destination);
$zone = $destination->voiceplanzone;
//var_dump($zone);
// inc_first - first minimumm duration to bill
// inc - subsequent minimum duration to bill
$inc_first = $zone->increment_first;
$inc = $zone->increment;
$billable_duration = $call->duration;
if($billable_duration <= 0) continue;
// calculate price of first duration unit
// then subtract first minimum duration from duration
$sec_price = $zone->price / 60;
$call_price = $inc_first * $sec_price;
$billable_duration -= $inc_first;
// calculate price of remaining duration and make sure to bill in full duration units
if($billable_duration > 0) {
$multi = ceil($billable_duration / $inc);
$call_price += ($multi * $inc) * $sec_price;
}
if (!array_key_exists($number, $voicebills)) {
$voicebills[$number] = [];
}
if (!array_key_exists($zone->id, $voicebills[$number])) {
$voicebills[$number][$zone->id] = [
"zone_name" => $zone->name,
"voiceplan" => $voiceplan->name,
"duration" => 0,
"price" => $sec_price,
"zone_total" => 0,
"increment_first" => $zone->increment_first,
"increment" => $zone->increment,
"count" => 0
];
}
$voicebills[$number][$zone->id]["count"]++;
$voicebills[$number][$zone->id]["zone_total"] += $call_price;
$voicebills[$number][$zone->id]["duration"] += $call->duration;
}
if(!count($voicebills)) {
continue;
}
//var_dump($voicebills);exit;
foreach($voicebills as $vbnumber => $zones) {
foreach($zones as $zone_id => $vb) {
$vbdata = [];
$vbdata["billing_id"] = $billing->id;
$vbdata["contract_id"] = $contract->id;
$vbdata["voicenumber"] = $vbnumber;
$vbdata["start_date"] = $voice_start_date->format("Y-m-d");
$vbdata["end_date"] = $voice_end_date->format("Y-m-d");
$vbdata["voiceplan"] = $vb["voiceplan"];
$vbdata["zone"] = $vb["zone_name"];
$vbdata["call_count"] = $vb["count"];
$vbdata["duration"] = $vb["duration"];
$vbdata["price"] = $vb["price"];
$vbdata["price_total"] = $vb["zone_total"];
$vbdata["increment"] = $vb["increment"];
$vbdata["increment_first"] = $vb["increment_first"];
$bill_voice = BillingVoicenumberModel::create($vbdata);
if(!$bill_voice->save()) {
var_dump($vbdata);
die("Error saving Billing Voicenumber!");
}
}
}
$v++;
// save to BillingVoicenumber
}
}
/*foreach(VoiceCallHistoryModel::getVoiceCallHistoryAsEntity(["contract_id" => $contract->id, "start" => ["from" => $start_date->getTimestamp()]]) as $call) {
// find BillingVoicenumber record for this call
$vbill = BillingVoicenumberModel::getFirst(["contract_id" => $contract->id, "voicenumber" => $call->voice_account, "start_date" => ]);
if($vbill) {
}
}*/
}
}
$this->layout()->setFlash("$i Billing records generiert");
$this->layout()->setFlash("$i Contract Billing records generiert. $v Voicenumber Billing records generiert");
$this->redirect("Billing");
}

View File

@@ -8,6 +8,7 @@ class BillingModel {
public $owner_id;
public $billingaddress_id;
public $customer_number;
public $fibu_account_number;
public $company;
public $firstname;
public $lastname;
@@ -30,7 +31,9 @@ class BillingModel {
public $amount;
public $price;
public $price_setup;
public $vatarea;
public $vatrate;
public $vatgroup_id;
public $billing_period;
public $create_by;

View File

@@ -0,0 +1,5 @@
<?php
class BillingVoicenumber extends mfBaseModel {
}

View File

@@ -0,0 +1,19 @@
<?php
class BillingVoicenumberController extends mfBaseController {
protected function init()
{
$this->needlogin = true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me", $me);
if (!$me->is(["Admin"])) {
$this->redirect("Dashboard");
}
}
}

View File

@@ -0,0 +1,280 @@
<?php
class BillingVoicenumberModel {
public $billing_id;
public $contract_id;
public $voicenumber;
public $start_date;
public $end_date;
public $voiceplan;
public $zone;
public $call_count;
public $duration;
public $price;
public $price_total;
public $increment;
public $increment_first;
public $create_by;
public $edit_by;
public $create;
public $edit;
public static function create(Array $data) {
$model = new BillingVoicenumber();
foreach($data as $field => $value) {
if(property_exists(get_called_class(), $field)) {
$model ->$field = $value;
}
}
$me = new User();
$me->loadMe();
if($model->create_by === null) {
$model->create_by = $me->id;
}
if($model->edit_by === null) {
$model->edit_by = $me->id;
}
return $model;
}
public static function getAll() {
$items = [];
$db = FronkDB::singleton();
$res = $db->select("BillingVoicenumber", "*", "1 = 1 ORDER BY id");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new BillingVoicenumber($data);
}
}
return $items;
}
public static function getFirst($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM BillingVoicenumber
WHERE $where
ORDER BY id LIMIT 1";
//var_dump($sql);exit;
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new BillingVoicenumber($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function getLast($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM BillingVoicenumber
WHERE $where
ORDER BY `create` DESC LIMIT 1";
//var_dump($sql);exit;
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new BillingVoicenumber($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function count($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) as cnt FROM BillingVoicenumber
WHERE $where";
//mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
return $data->cnt;
}
return 0;
}
public static function search($filter, $limit = false, $order = false) {
//var_dump($filter);exit;
$items = [];
if(!$order) {
$order = "id ASC";
}
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM BillingVoicenumber
WHERE $where
ORDER BY $order";
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
} elseif(is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['count'];
}
}
mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[$data->id] = new BillingVoicenumber($data);
}
}
return $items;
}
private static function getSqlFilter($filter) {
$where = "1=1 ";
$db = FronkDB::singleton();
//var_dump($filter);exit;
if(array_key_exists("id", $filter)) {
$id = $filter['id'];
if(is_numeric($id)) {
$where .= " AND BillingVoicenumber.id like '%$id%'";
}
}
if(array_key_exists("approved", $filter)) {
$approved = $filter['approved'];
if($approved) {
$where .= " AND BillingVoicenumber.approved = 1";
} else {
$where .= " AND BillingVoicenumber.approved = 0";
}
}
if(array_key_exists("billing_id", $filter)) {
$billing_id = $filter['billing_id'];
if(is_numeric($billing_id)) {
$where .= " AND BillingVoicenumber.billing_id=$billing_id";
} elseif($billing_id === null || $billing_id === false) {
$where .= " AND (BillingVoicenumber.billing_id IS NULL OR BillingVoicenumber.billing_id=0)";
}
}
if(array_key_exists("contract_id", $filter)) {
$contract_id = $filter['contract_id'];
if(is_numeric($contract_id)) {
$where .= " AND BillingVoicenumber.contract_id=$contract_id";
}
}
if(array_key_exists("voicenumber", $filter)) {
$voicenumber = FronkDB::singleton()->escape($filter['voicenumber']);
if($voicenumber) {
$where .= " AND BillingVoicenumber.voicenumber='$voicenumber'";
}
}
if(array_key_exists("start_date", $filter)) {
$start_date = FronkDB::singleton()->escape($filter['start_date']);
if($start_date) {
$where .= " AND BillingVoicenumber.start_date='$start_date'";
}
}
if(array_key_exists("start_date>", $filter)) {
$start_date = FronkDB::singleton()->escape($filter['start_date>']);
if($start_date) {
$where .= " AND BillingVoicenumber.start_date > '$start_date'";
}
}
if(array_key_exists("start_date<", $filter)) {
$start_date = FronkDB::singleton()->escape($filter['start_date<']);
if($start_date) {
$where .= " AND BillingVoicenumber.start_date < '$start_date'";
}
}
if(array_key_exists("start_date>=", $filter)) {
$start_date = FronkDB::singleton()->escape($filter['start_date>=']);
if($start_date) {
$where .= " AND BillingVoicenumber.start_date >= '$start_date'";
}
}
if(array_key_exists("start_date<=", $filter)) {
$start_date = FronkDB::singleton()->escape($filter['start_date<=']);
if($start_date) {
$where .= " AND BillingVoicenumber.start_date <= '$start_date'";
}
}
if(array_key_exists("owner_id", $filter)) {
$owner_id = $filter['owner_id'];
if(is_numeric($owner_id)) {
$where .= " AND BillingVoicenumber.owner_id=$owner_id";
}
}
if(array_key_exists("add-where", $filter)) {
$where .= " ".$filter['add-where'];
}
if(array_key_exists("BillingVoicenumber_type", $filter)) {
$BillingVoicenumber_type = $filter['BillingVoicenumber_type'];
if(is_numeric($BillingVoicenumber_type)) {
$where .= " AND BillingVoicenumber.BillingVoicenumber_type = $BillingVoicenumber_type";
}
}
if(array_key_exists("BillingVoicenumber_type", $filter)) {
$BillingVoicenumber_type = $db->escape($filter['BillingVoicenumber_type']);
if($BillingVoicenumber_type) {
$where .= " AND BillingVoicenumber.BillingVoicenumber_type = '$BillingVoicenumber_type'";
}
}
if(array_key_exists("BillingVoicenumber_delivery", $filter)) {
$BillingVoicenumber_delivery = $db->escape($filter['BillingVoicenumber_delivery']);
if($BillingVoicenumber_delivery) {
$where .= " AND BillingVoicenumber.BillingVoicenumber_delivery = '$BillingVoicenumber_delivery'";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -27,6 +27,8 @@ class Contract extends mfBaseModel {
private $productchangeTo;
private $relocationFrom;
private $relocationTo;
private $vatgroup;
private $vatrate;
private $finisher;
private $canceler;
private $creator;
@@ -193,6 +195,27 @@ class Contract extends mfBaseModel {
}
public function getConfigValue($itemname) {
$configvalues = $this->getProperty("configvalues");
if(!$configvalues) return null;
if(!array_key_exists($itemname, $configvalues)) return null;
$configitem = $configvalues[$itemname];
return $configitem->value;
}
public function setConfigValue($itemname, $value) {
$configvalues = $this->getProperty("configvalues");
if(!$configvalues) return null;
if(!array_key_exists($itemname, $configvalues)) return null;
$configitem = $configvalues[$itemname];
$configitem->value->set($value);
$configitem->value->save();
return true;
}
public function getProperty($name) {
if($this->$name == null) {
@@ -292,6 +315,19 @@ class Contract extends mfBaseModel {
return $this->contractConfigItems;
}*/
if($name == "vatrate") {
$vatgroup = $this->getProperty("vatgroup");
$country = $this->getProperty("country");
$vatrate = $vatgroup->rates["domestic"]->rate;
if($this->country_id && $country->is_eu) {
$vatrate = $vatgroup->rates["eu"]->rate;
} if($this->country_id && !$country->is_eu) {
$vatrate = $vatgroup->rates["other"]->rate;
}
$this->vatrate = $vatrate;
return $this->vatrate;
}
if($name == "journals") {
$this->journals = array_reverse(ContractjournalModel::search(["contract_id" => $this->id]));

View File

@@ -15,7 +15,7 @@ class ContractModel {
public $product_external_id;
public $price = null;
public $price_setup = null;
public $vatrate = null;
public $vatgroup_id = null;
public $price_nne = null;
public $price_nbe = null;
public $billing_delay = null;

View File

@@ -99,7 +99,7 @@ class CountryModel {
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
} elseif(is_numeric($count)) {
} elseif(is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['count'];
}
}
@@ -131,7 +131,7 @@ class CountryModel {
if(array_key_exists("isocode", $filter)) {
$isocode = $db->escape($filter['isocode']);
if($isocode) {
$where .= " AND Country.`isocode` like '%$isocode%'";
$where .= " AND Country.`isocode` like '$isocode'";
}
}

View File

@@ -65,7 +65,7 @@ class InvoiceController extends mfBaseController {
}
if(array_key_exists("address", $filter)) {
if(array_key_exists("address", $filter) && $filter["address"]) {
if($filter["address"]) {
$search = $this->db()->escape($filter['address']);
if(!array_key_exists("add-where", $new_filter)) $new_filter["add-where"] = "";
$new_filter['add-where'] .= " AND (street like '%$search%' OR zip like '%$search%' OR city like '%$search%' OR country like '%$search%')";
@@ -102,7 +102,7 @@ class InvoiceController extends mfBaseController {
if(!array_key_exists($p->vatrate, $vat)) {
$vat[$p->vatrate] = 0;
}
$vat[$p->vatrate] += $p->price_gross - $p->price;
$vat[$p->vatrate] += $p->price_gross - ($p->price * $p->amount);
}
$pdf_vars = [
@@ -153,9 +153,13 @@ class InvoiceController extends mfBaseController {
//var_dump($owner_id, $billingaddress_id, $bills);exit;
$invoice_data = [];
$invoice_vatrate = 20;
foreach($billing_rows as $bill) {
$vatrate = $bill->vatrate;
$vatarea = $bill->vatarea;
$invoice_vatrate = $bill->vatgroup->rates[$vatarea]->rate;
$vatrate = $invoice_vatrate;
$price = $bill->price;
$price_total = $bill->price * $bill->amount;
$price_gross = ($vatrate) ? $price_total + ($price_total / 100) * $vatrate : $price_total;
@@ -177,6 +181,9 @@ class InvoiceController extends mfBaseController {
$position_data["amount"] = $bill->amount;
$position_data["billing_period"] = $bill->billing_period;
$position_data["fibu_cost_account"] = $bill->vatgroup->rates[$vatarea]->account;
$position_data["fibu_cost_account_legacy"] = $bill->vatgroup->rates[$vatarea]->legacy_account;
$position_data["fibu_taxcode"] = $bill->vatgroup->rates[$vatarea]->taxcode;
if($is_setup_only) {
$this->log->debug("Contract ID ". $bill->contract_id." is setup only");
@@ -219,6 +226,8 @@ class InvoiceController extends mfBaseController {
$invoice_data["owner_id"] = $owner_id;
$invoice_data["billingaddress_id"] = $billingaddress_id;
$invoice_data["customer_number"] = $bill->customer_number;
$invoice_data["fibu_account_number"] = $bill->fibu_account_number;
$invoice_data["company"] = $bill->company;
$invoice_data["firstname"] = $bill->firstname;
$invoice_data["lastname"] = $bill->lastname;
@@ -239,6 +248,12 @@ class InvoiceController extends mfBaseController {
$invoice_data["total_vat"] = 0;
$invoice_data["fibu_cost_area"] = $vatarea;
$invoice_data["fibu_cost_account"] = $bill->vatgroup->rates[$vatarea]->account;
$invoice_data["fibu_cost_account_legacy"] = $bill->vatgroup->rates[$vatarea]->legacy_account;
$invoice_data["fibu_taxcode"] = $bill->vatgroup->rates[$vatarea]->taxcode;
$invoice_data["tax_text"] = $bill->vatgroup->rates[$vatarea]->invoice_text;
}
@@ -265,9 +280,9 @@ class InvoiceController extends mfBaseController {
// add Invoice::id to Invoiceposition
$position->invoice_id = $invoice->id;
if(!$position->vatrate) {
if(!$invoice_vatrate || !$position->vatrate) {
$total_net += $position->price_total;
$total_gross += $position->price_total;
} else {
$total_vat += ($position->price_total / 100) * $position->vatrate;
$total_net += $position->price_total;

View File

@@ -3,8 +3,15 @@
class InvoiceModel {
public $invoice_number;
public $invoice_date;
public $owner_id;
public $billingaddress_id;
public $customer_number;
public $fibu_account_number;
public $fibu_cost_area;
public $fibu_cost_account;
public $fibu_cost_account_legacy;
public $fibu_taxcode;
public $tax_text;
public $company;
public $firstname;
public $lastname;

View File

@@ -15,6 +15,9 @@ class InvoicepositionModel {
public $price_total;
public $price_gross;
public $vatrate;
public $fibu_cost_account;
public $fibu_cost_account_legacy;
public $fibu_taxcode;
public $billing_period;
public $create_by;

View File

@@ -12,7 +12,7 @@ class IvtCustomerProduct extends mfBaseModel {
public function __construct($_=NULL) {
$this->log = mfLoghandler::singleton();
$this->data = new stdClass();
$this->table = "products";
$this->table = "customer_product";
$this->db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);

View File

@@ -106,4 +106,89 @@ class VoiceCallHistoryController extends mfBaseController {
]
];
}
public function addContractIds() {
$ignore_numbers = [
"4331641220846",
"43623237705",
"4367761737195"
];
$unknown_numbers = [];
// get calls without contract id
foreach(VoiceCallHistoryModel::getVoiceCallHistoryAsEntity(["contract_id" => null, "billable" => "1", "duration" => ["from" => 1]]) as $call) {
//var_dump($call);exit;
//echo "\n";
$number = $call->voice_account;
if(!$number) continue;
// server side failed/disconnected calls
if($call->duration == 1 && $call->state == 38) continue;
if(in_array($number, $unknown_numbers)) continue;
$voicenumber = VoicenumberModel::getFirst(["number" => $number]);
// TODO: Mail an office
if(!$voicenumber) {
$this->log->debug(__METHOD__.": Voicenumber $number not found.");
$unknown_numbers[] = $number;
continue;
}
if(!$voicenumber->contract_id) {
$this->log->debug(__METHOD__.": Missing Contract_ID in Voicenumber ".$voicenumber->number);
continue;
}
$contract = new Contract($voicenumber->contract_id);
if(!$contract) {
$this->log->debug(__METHOD__.": No Contract with Contract_ID ".$voicenumber->contract_id." in Voicenumber ".$voicenumber->number);
continue;
}
if($contract->isCancelled()) {
// mail an office
$this->log->warning(__METHOD__.": Contract ".$voicenumber->contract_id." for Voicenumber ".$voicenumber->number." is cancelled!");
}
$calldate = new DateTime($call->start);
$calldate->setTimezone(new DateTimeZone("Europe/Vienna"));
// calls from before first IVT Import must be right, we don't have historic contract data
if($calldate->format("Y-m") < "2024-08") {
$call->contract_id = $contract->id;
//echo "save 1\n";
if(!$call->save()) {
die("Cannot save call ".$call->id);
}
continue;
}
// check if contract was active at this time ...
if($calldate->getTimestamp() <= $contract->finish_date && (!$contract->cancel_date || $calldate->getTimestamp() <= $contract->cancel_date)) {
// 2023-08 is the oldest we can know because of contract import in July 2024
$call->contract_id = $contract->id;
echo "save 2\n";
$call->save();
}
// ... else look for contract with this number active at that time ...
// ... else use current active contract
if(!$contract) {
// find contract by ContractConfigValue voicenumberblock_voicenumber
}
$call->contract_id = $voicenumber->contract_id;
echo "save 3\n";
$call->save();
}
}
}

View File

@@ -2,6 +2,7 @@
class VoiceCallHistoryModel {
public $uid;
public $voice_account;
public $contract_id;
public $start;
public $source;
public $destination;
@@ -109,6 +110,7 @@ class VoiceCallHistoryModel {
$sql .= isset($filters['destination']) ? Helper::generateFilterCondition($filters['destination'], "destination") : "";
$sql .= isset($filters['billable']) ? Helper::generateFilterCondition($filters['billable'], "billable") : "";
$sql .= isset($filters['duration']) ? Helper::generateFilterCondition($filters['duration'], "duration") : "";
$sql .= array_key_exists("contract_id", $filters) ? Helper::generateFilterCondition($filters['contract_id'], "contract_id", true) : "";
return $sql;
}
@@ -119,6 +121,7 @@ class VoiceCallHistoryModel {
$sql .= $order === null || $order['key'] === null ? " ORDER BY `start` DESC" : " ORDER BY `" . $order['key'] . "` " . $order['order'];
$sql .= $limit === null ? "" : " LIMIT " . $limit . " OFFSET " . $offset;
//mfLoghandler::singleton()->debug($sql);exit;
// die($sql);
$result = $db->query($sql);
$rows = [];
@@ -129,6 +132,23 @@ class VoiceCallHistoryModel {
return $rows;
}
public static function getVoiceCallHistoryAsEntity($filters, $limit = null, $offset = 0, $order = null) {
$db = FronkDB::singleton();
$sql = "SELECT * FROM `VoiceCallHistory` WHERE 1 " . self::getSqlFilter($filters);
$sql .= $order === null || $order['key'] === null ? " ORDER BY `start` DESC" : " ORDER BY `" . $order['key'] . "` " . $order['order'];
$sql .= $limit === null ? "" : " LIMIT " . $limit . " OFFSET " . $offset;
mfLoghandler::singleton()->debug($sql);
// die($sql);
$result = $db->query($sql);
$rows = [];
while ($row = $db->fetch_object($result)) {
$rows[] = new VoiceCallHistory($row);
}
return $rows;
}
public static function countVoiceCallHistory($filters) {
$db = FronkDB::singleton();
$sql = "SELECT COUNT(*) as `total_rows` FROM `VoiceCallHistory` WHERE 1 " . self::getSqlFilter($filters);

View File

@@ -67,7 +67,7 @@ class VoicenumberModel {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
mfLoghandler::singleton()->debug($where);
//mfLoghandler::singleton()->debug($where);
$res = $db->select("Voicenumber", "*", "$where ORDER BY voicenumberblock_id, number");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
@@ -109,7 +109,7 @@ class VoicenumberModel {
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
} elseif(is_numeric($count)) {
} elseif(is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['count'];
}
}
@@ -144,6 +144,13 @@ class VoicenumberModel {
$where .= " AND voicenumberblock_id = $block_id";
}
}
if(array_key_exists("contract_id", $filter)) {
$contract_id = $filter['contract_id'];
if(is_numeric($contract_id)) {
$where .= " AND contract_id = $contract_id";
}
}
//var_dump($filter);exit;
if(array_key_exists("countrycode", $filter)) {

View File

@@ -8,7 +8,36 @@ class Voiceplan extends mfBaseModel {
private $destinations;
public $import_errors;
public function getDestinationByNumber($number) {
if(!$number) return false;
$prefix = $number;
while(strlen($prefix)) {
$destination = VoiceplandestinationModel::getFirst(["prefix" => $prefix, "voiceplan_id" => $this->id]);
if($destination) {
break;
}
$prefix = substr($prefix, 0, strlen($prefix) - 1);
}
if(!$destination) return false;
return $destination;
}
public function getZoneByNumber($number) {
if(!$number) return false;
$destination = $this->getDestinationByNumber($number);
if(!$destination) return false;
return $destination->voiceplanzone;
}
public function importDestinationsFromCsv(File $file) {
if(!$this->id) {
return false;
@@ -169,7 +198,7 @@ class Voiceplan extends mfBaseModel {
return true;
}
public function getProperty($name) {
if($this->$name == null) {

View File

@@ -23,16 +23,20 @@ class Voiceplandestination extends mfBaseModel {
}
return $this->voiceplan;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);
if($this->$name->id) {
return $this->$name;
} else {
return null;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
if(!$this->$name) {
$this->$name = new $classname($this->$idfield);
}
if($this->$name->id) {
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
return $this->$name;
} else {
return null;
}
}
return $this->$name;

View File

@@ -52,8 +52,16 @@ class VoiceplandestinationModel {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
mfLoghandler::singleton()->debug($where);
$res = $db->select("Voiceplandestination", "*", "$where ORDER BY destination,prefix");
$sql = "SELECT * FROM Voiceplandestination WHERE $where ORDER BY destination,prefix";
$sql = "SELECT Voiceplandestination.* FROM Voiceplandestination
LEFT JOIN Voiceplanzone ON (Voiceplanzone.id = Voiceplandestination.voiceplanzone_id)
WHERE $where
ORDER BY destination,prefix LIMIT 1
";
mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
//$res = $db->select("Voiceplandestination", "*", "$where ORDER BY destination,prefix");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Voiceplandestination($data);
@@ -99,7 +107,7 @@ class VoiceplandestinationModel {
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
} elseif(is_numeric($count)) {
} elseif(is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['count'];
}
}

View File

@@ -25,16 +25,20 @@ class Voiceplanzone extends mfBaseModel {
$this->destinations = VoiceplandestinationModel::search(["voiceplanzone_id" => $this->id]);
return $this->destinations;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);
if($this->$name->id) {
return $this->$name;
} else {
return null;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
if(!$this->$name) {
$this->$name = new $classname($this->$idfield);
}
if($this->$name->id) {
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
return $this->$name;
} else {
return null;
}
}
return $this->$name;

View File

@@ -38,7 +38,7 @@ final class CreateBilling extends AbstractMigration
$table->addColumn("amount", "decimal", ["null" => false, "precision" => 9, "scale" => 6]);
$table->addColumn("price", "decimal", ["null" => false, "precision" => 14, "scale" => 4]);
$table->addColumn("price_setup", "decimal", ["null" => false, "default" => 0, "precision" => 14, "scale" => 4]);
$table->addColumn("total_vat", "decimal", ["null" => false, "precision" => 14, "scale" => 4]);
$table->addColumn("vatrate", "decimal", ["null" => false, "precision" => 14, "scale" => 4]);
$table->addColumn("billing_period", "integer", ["null" => false, "default" => 0]);
$table->addColumn("create_by", "integer", ["null" => false]);

View File

@@ -9,7 +9,7 @@ final class ContractAddVat extends AbstractMigration
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("Contract");
$table->addColumn("vatrate", "decimal", ["null" => false, "default" => 0, "precision" => 6, "scale" => 2, "after" => "price_setup"]);
$table->addColumn("vatgroup_id", "integer", ["null" => false, "after" => "price_setup"]);
$table->update();
}
@@ -22,7 +22,7 @@ final class ContractAddVat extends AbstractMigration
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("Contract");
$table->removeColumn("vatrate");
$table->removeColumn("vatgroup_id");
$table->update();
}

View File

@@ -0,0 +1,67 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class BillingAddFibuData extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$billing = $this->table("Billing");
$billing->addColumn("fibu_account_number", "integer", ["null" => true, "default" => null, "after" => "customer_number"]);
$billing->addColumn("vatgroup_id", "string", ["null" => true, "default" => null, "after" => "vatrate"]);
$billing->addColumn("vatarea", "string", ["null" => true, "default" => null, "after" => "vatgroup_id"]);
$billing->save();
$invoice = $this->table("Invoice");
$invoice->addColumn("fibu_account_number", "integer", ["null" => true, "default" => null, "after" => "customer_number"]);
$invoice->addColumn("fibu_cost_area", "string", ["null" => true, "default" => null, "after" => "fibu_account_number"]);
$invoice->addColumn("fibu_cost_account", "integer", ["null" => true, "default" => null, "after" => "fibu_cost_area"]);
$invoice->addColumn("fibu_cost_account_legacy", "integer", ["null" => true, "default" => null, "after" => "fibu_cost_account"]);
$invoice->addColumn("fibu_taxcode", "integer", ["null" => true, "default" => null, "after" => "fibu_cost_account_legacy"]);
$invoice->addColumn("tax_text", "string", ["null" => true, "default" => null, "length" => 255, "after" => "fibu_taxcode"]);
$invoice->save();
$ip = $this->table("Invoiceposition");
$ip->addColumn("fibu_cost_account", "integer", ["null" => true, "default" => null, "after" => "vatrate"]);
$ip->addColumn("fibu_cost_account_legacy", "integer", ["null" => true, "default" => null, "after" => "fibu_cost_account"]);
$ip->addColumn("fibu_taxcode", "integer", ["null" => true, "default" => null, "after" => "fibu_cost_account_legacy"]);
$ip->save();
}
if($this->getEnvironment() == "addressdb") {
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$this->table("Invoiceposition")
->removeColumn("fibu_taxcode")
->removeColumn("fibu_cost_account_legacy")
->removeColumn("fibu_cost_account")
->update();
$this->table("Invoice")
->removeColumn("fibu_invoice_text")
->removeColumn("fibu_taxcode")
->removeColumn("fibu_cost_account_legacy")
->removeColumn("fibu_cost_account")
->removeColumn("fibu_cost_area")
->removeColumn("fibu_account_number")
->update();
$this->table("Billing")
->removeColumn("vatarea")
->removeColumn("vatgroup_id")
->removeColumn("fibu_account_number")
->update();
}
if($this->getEnvironment() == "addressdb") {
}
}
}

View File

@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class CreateBillingVoicenumber extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("BillingVoicenumber");
$table->addColumn("billing_id", "integer", ["null" => true, "default" => null]);
$table->addColumn("contract_id", "integer", ["null" => false]);
$table->addColumn("voicenumber", "string", ["null" => false, "limit" => 64]);
$table->addColumn("start_date", "date", ["null" => false]);
$table->addColumn("end_date", "date", ["null" => false]);
$table->addColumn("voiceplan", "string", ["null" => false, "limit" => 255]);
$table->addColumn("zone", "string", ["null" => false, "limit" => 64]);
$table->addColumn("call_count", "integer", ["null" => false]);
$table->addColumn("duration", "integer", ["null" => false]);
$table->addColumn("price", "decimal", ["null" => false, "precision" => 14, "scale" => 8]);
$table->addColumn("price_total", "decimal", ["null" => false, "precision" => 14, "scale" => 4]);
$table->addColumn("increment", "integer", ["null" => false]);
$table->addColumn("increment_first", "integer", ["null" => false]);
$table->addColumn("create_by", "integer", ["null" => false]);
$table->addColumn("edit_by", "integer", ["null" => false]);
$table->addColumn("create", "integer", ["null" => false]);
$table->addColumn("edit", "integer", ["null" => false]);
$table->create();
}
if($this->getEnvironment() == "addressdb") {
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$this->table("BillingVoicenumber")->drop()->save();
}
if($this->getEnvironment() == "addressdb") {
}
}
}

View File

@@ -15,13 +15,15 @@ class Helper {
if (is_array($filterValue)) {
if (isset($filterValue['from']) && isset($filterValue['to'])) {
$sql = " AND `$columnName` >= " . $filterValue['from'] . " AND `$columnName` <= " . $filterValue['to'];
} else if (isset($filterValue['from'])) {
} elseif (isset($filterValue['from'])) {
$sql = " AND `$columnName` >= " . $filterValue['from'];
} else if (isset($filterValue['to'])) {
} elseif (isset($filterValue['to'])) {
$sql = " AND `$columnName` <= " . $filterValue['to'];
}
} else if ($filterValue === "0" || $filterValue === "1") {
$sql .= " AND `$columnName` = " . $filterValue;
} else if ($filterValue === null) {
$sql .= " AND `$columnName` IS NULL";
} else if (!empty($filterValue)) {
if ($exactMatch) {
$sql .= " AND `$columnName` = '" . $filterValue . "'";

View File

@@ -1,16 +1,23 @@
@page {
size: A4;
margin: 0mm;
}
* {
font-family: "Open Sans";
}
html {
margin: 24pt;
/*margin: 24pt;*/
margin: 0;
height:100%;
}
body {
font-size:9pt;
height:100%;
margin-top: 50pt;
margin: 0;
margin-top: 20pt;
}
h2 {

View File

@@ -4,61 +4,290 @@
//require 'vendor/autoload.php';
require("../config/config.php");
define('FRONKDB_SQLDEBUG',false);
define('FRONKDB_SQLDEBUG', false);
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
require_once(LIBDIR."/mvcfronk/mfRouter/mfRouter.php");
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseModel.php");
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
require_once(LIBDIR . "/mvcfronk/mfRouter/mfRouter.php");
require_once(LIBDIR . "/mvcfronk/mfBase/mfBaseModel.php");
require_once(LIBDIR . "/mvcfronk/mfBase/mfBaseController.php");
$me = new User(1);
define("INTERNAL_USER_ID", $me->id);
define("INTERNAL_USER_USERNAME", $me->username);
$chars = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
$charsLength = strlen($chars);
require_once(APPDIR . "Admin/functions/IvtContractImport.php");
$c = 0;
$ownerIdToBillingAddress = [];
$db = FronkDB::singleton();
$res = $db->query("SELECT id FROM Preorder WHERE oaid IS NOT NULL ORDER BY RAND()");
/*while($data = $db->fetch_object($res)) {
if($c > 1000) break;
$ici = new Admin_IvtContractImport();
$orderproduct = false;
$orderproduct_id = false;
$ivt_contract = new IvtCustomerProduct(5983);
$ivt_customer = $ivt_contract->customer;
$ivt_product = $ivt_contract->product;
/*
* get thetool product from IvtProductMatch
*/
$productMatch = IvtProductMatchModel::getFirst(["ivt_product_id" => $ivt_contract->pid]);
if(!$productMatch) {
echo "Kein Match zu IVT Product " . $ivt_contract->pid . " gefunden.<br />\n";
exit;
}
$ip = $productMatch->ivtproduct;
$product = $productMatch->product;
/*
* check ivt customer and get Billingaddress
*/
$billingaddress_id = false;
//var_dump($ivt_contract);exit;
$customer_check_return = checkIvtCustomer($ivt_contract, $ivt_customer, $product);
private function checkIvtCustomer($ivt_contract, $ivt_customer, $product, $doit = false)
{
global $ownerIdToBillingAddress;
$return = [];
// create customer if not exists
$ivt_custnum = $ivt_customer->id;
if (!$ivt_custnum) return false;
// sync billing address
$owner = AddressModel::getFirst(["customer_number" => $ivt_custnum]);
if (!$owner) {
//var_dump($ivt_customer, $ivt_contract);
die("Address $ivt_custnum not found!");
}
if(array_key_exists($owner->id, $this->ownerIdToBillingAddress)) {
return ["billingaddress_id" => $this->ownerIdToBillingAddress[$owner->id]];
}
$compare_address = $owner;
$compare_type = "owner";
$return["billingaddress_id"] = $owner->id;
$order = $this->findOrder($ivt_contract);
if(!$order) {
$return["billingaddress_id"] = $owner->id;
$compare_address = $owner;
$compare_type = "owner";
}
// look for billingaddress_id in order and use it
if ($order && $order->billingaddress_id) {
$return["billingaddress_id"] = $order->billingaddress_id;
$billingaddress = new Address($order->billingaddress_id);
if (!$billingaddress->id) {
die("Billingaddress " . $order->billingaddress_id . " does not exist (order " . $order->id . "; ivt customer $ivt_custnum)");
}
$compare_address = $billingaddress;
$compare_type = "billingaddress";
}
// if no billingaddress_id in order, compare address of Address and ivt_customer and
// create new billingaddress if nessecary
if(!$compare_address) {
die("No Compare address");
}
$address_update = $this->compareBillingAddresses($ivt_customer, $compare_address);
if($address_update === true) {
$return["billingaddress_id"] = $compare_address->id;
} elseif(is_array($address_update) && count($address_update)) {
if($compare_type == "billingaddress") {
// update billingaddress
$compare_address->update($address_update);
if(!$compare_address->save()) {
die("error updateing Billingaddress");
}
$this->ownerIdToBillingAddress[$owner->id] = $billingaddress->id;
$return["billingaddress_id"] = $compare_address->id;
} else {
// create billingaddress
$billingaddress = AddressModel::create($address_update);
try {
if(!$billingaddress->save()) {
var_dump($address_update);
die("error creating Billingaddress");
}
$return["billingaddress_id"] = $billingaddress->id;
if(!array_key_exists($owner->id, $this->ownerIdToBillingAddress)) {
$ownerIdToBillingAddress[$owner->id] = $billingaddress->id;
/*$this->log->debug(__METHOD__.": Creating billing link for owner ".$owner->id." ".$owner->getCompanyOrName()."with billing address ".$billingaddress->id." ".$billingaddress->getCompanyOrName());
$this->log->debug("OWNER:");
$this->log->debug(print_r($owner->data, true));
$this->log->debug("ADDRESS UPDATE:");
$this->log->debug(print_r($address_update, true));*/
// create addresslink
$l = AddressLinkModel::create([
'origin_address_id' => $owner->id,
'type' => "billing",
'address_id' => $billingaddress->id
]);
$l->save();
}
} catch (Exception $e) {
echo "Exception: ".$e->getMessage()."\n";
var_dump($address_update);
exit();
}
}
}
return $return;
$preorder = new Preorder($data->id);
if(!$preorder->oaid) {
echo "no oaid ".$preorder->id."\n";
}
$oaid = $preorder->oaid;
$ucode = '';
for($i = 0; $i < 20; $i++) {
$ucode .= $chars[rand(0, $charsLength - 1)];
}
echo "$oaid;$ucode\n";
$c++;
}*/
private function compareBillingAddresses($ivt_customer, $tool_customer) {
$owner = $tool_customer;
$stati = PreorderstatusModel::getAll();
$new_billing = [];
while($data = $db->fetch_object($res)) {
if($c > 1000) break;
if ($ivt_customer->company) {
if (strtolower(trim($ivt_customer->company)) != strtolower(trim($owner->company))) $new_billing["company"] = $ivt_customer->company;
} else {
if (strtolower(trim($ivt_customer->firstname)) != strtolower(trim($owner->firstname))) $new_billing["firstname"] = $ivt_customer->firstname;
if (strtolower(trim($ivt_customer->surname)) != strtolower(trim($owner->lastname))) $new_billing["lastname"] = $ivt_customer->surname;
}
$preorder = new Preorder($data->id);
if(!$preorder->oaid) {
echo "no oaid ".$preorder->id."\n";
}
$oaid = $preorder->oaid;
//if ($ivt_customer->UID != $owner->uid) $new_billing["uid"] = $ivt_customer->UID;
if (strtolower(trim($ivt_customer->zip)) != strtolower(trim($owner->zip))) $new_billing["zip"] = $ivt_customer->zip;
if (strtolower(trim($ivt_customer->location)) != strtolower(trim($owner->city))) $new_billing["city"] = $ivt_customer->location;
if (strtolower(trim($ivt_customer->street . " " . $ivt_customer->housenumber)) != strtolower(trim($owner->street))) $new_billing["street"] = $ivt_customer->street . " " . $ivt_customer->housenumber;
//if (strtolower(trim($ivt_customer->phone)) != strtolower(trim($owner->phone))) $new_billing["phone"] = $ivt_customer->phone;
if (strtolower(trim($ivt_customer->email)) != strtolower(trim($owner->email))) {
if($ivt_customer->email && !$owner->email) {
$owner->email = strtolower(trim($ivt_customer->email));
$owner->save();
} else {
$new_billing["email"] = $ivt_customer->email;
}
}
$r = rand(0, count($stati)-1);
$new_status = $stati[$r];
$billing_type = "";
$billing_delivery = "";
if($ivt_customer->payment == 1 && $owner->billing_type != "invoice") {
$billing_type = "invoice";
if($owner->billing_type) {
$new_billing["billing_type"] = "invoice";
} else {
$owner->billing_type = "invoice";
$owner->save();
}
} elseif($ivt_customer->payment == 0 && $owner->billing_type != "sepa") {
$billing_type = "sepa";
if($owner->billing_type) {
$new_billing["billing_type"] = "sepa";
} else {
$owner->billing_type = "sepa";
$owner->save();
}
} elseif($ivt_customer->paper_invoice == 1 && $owner->billing_delivery != "paper") {
$billing_delivery = "paper";
if($owner->billing_delivery) {
$new_billing["billing_delivery"] = "paper";
} else {
$owner->billing_delivery = "paper";
$owner->save();
}
} elseif($ivt_customer->paper_invoice == 0 && $owner->billing_delivery != "email") {
$billing_delivery = "email";
if($owner->billing_delivery) {
$new_billing["billing_delivery"] = "email";
} else {
$owner->billing_delivery = "email";
$owner->save();
}
}
if(!$new_status->code) {
fwrite(STDERR, "status not found\n");
continue;
}
//if($ivt_customer->bank_account_bank != $owner->bank_account_bank) $new_billing["bank_account_bank"] = $ivt_customer->bank_account_bank;
//if($ivt_customer->bank_account_owner != $owner->bank_account_owner) $new_billing["bank_account_owner"] = $ivt_customer->bank_account_owner;
$iban = strtoupper(trim(str_replace(" ","", $ivt_customer->IBAN)));
$bic = strtoupper(trim(str_replace(" ","", $ivt_customer->BIC)));
if ((array_key_exists("billing_type", $new_billing) && $new_billing["billing_type"] == "sepa") || $ivt_customer->payment == 0 && ($iban || $bic)) {
if ($iban != strtoupper(trim(str_replace(" ","", $owner->bank_account_iban)))) $new_billing["bank_account_iban"] = $iban;
if ($bic != strtoupper(trim(str_replace(" ","", $owner->bank_account_bic)))) $new_billing["bank_account_bic"] = $bic;
}
echo "$oaid;".$new_status->code."\n";
if(array_key_exists("bank_account_bic", $new_billing) && !array_key_exists("bank_account_iban", $new_billing)) {
$owner->bank_account_bic = $new_billing["bank_account_bic"];
$owner->save();
unset($new_billing["bank_account_bic"]);
}
$c++;
}
if(count($new_billing) == 2 && array_key_exists("billing_type", $new_billing) && array_key_exists("billing_delivery", $new_billing)) {
$owner->billing_type = $billing_type;
$owner->billing_delivery = $billing_delivery;
$owner->save();
return true;
}
if(count($new_billing) == 1) {
if(array_key_exists("billing_type", $new_billing)) {
$owner->billing_type = $billing_type;
$owner->save();
return true;
}
if(array_key_exists("billing_delivery", $new_billing)) {
$owner->billing_delivery = $billing_delivery;
$owner->save();
return true;
}
}
//$missing_fields = [];
$create = false;
foreach(["company", "firstname", "lastname", "street", "zip", "city", "email", "uid", "billing_type", "billing_delivery",
"bank_account_iban", "bank_account_bic"] as $field) {
if(!array_key_exists($field, $new_billing)) {
/*if(!$owner->$field) {
if($field == "billing_delivery") {
$new_billing[$field] = "paper";
} else {
$new_billing[$field] = "";
}
} else {
$new_billing[$field] = $owner->$field;
}*/
$new_billing[$field] = $owner->$field;
} else {
if($field == "email" && $new_billing["email"] == "dummy@xinon.at") continue;
$create = true;
}
}
/*
if($create) {
$billingaddress = AddressModel::create($new_billing);
//var_dump($billingaddress, $missing_fields);exit;
if(!$billingaddress->save()) {
die("Error createing billingaddress\n");
}
$return["billingaddress_id"] = $billingaddress->id;
}*/
if($create) {
return $new_billing;
}
return true;
}

View File

@@ -0,0 +1,21 @@
#!/usr/bin/php
<?php
//require 'vendor/autoload.php';
require("../../config/config.php");
define('FRONKDB_SQLDEBUG',false);
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
require_once(LIBDIR."/mvcfronk/mfRouter/mfRouter.php");
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseModel.php");
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
$me = new User(1);
define("INTERNAL_USER_ID", $me->id);
define("INTERNAL_USER_USERNAME", $me->username);
$vchc = new VoiceCallHistoryController(false);
$vchc->addContractIds();

File diff suppressed because it is too large Load Diff