WIP Contract 2024-06-06

This commit is contained in:
Frank Schubert
2024-06-11 13:19:40 +02:00
parent aca45c1064
commit 7181dd0b23
6 changed files with 107 additions and 15 deletions
@@ -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
@@ -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";
}
}