WIP Contract 2024-06-13
This commit is contained in:
@@ -166,12 +166,12 @@ class Admin_IvtContractImport {
|
||||
|
||||
|
||||
|
||||
$finish_date = new DateTime($ivt_contract->created);
|
||||
$finish_date->modify("+2 hours");
|
||||
$order_date = new DateTime($ivt_contract->created);
|
||||
$order_date->modify("+2 hours");
|
||||
|
||||
$last_date = new DateTime($ivt_contract->lastdate);
|
||||
$last_date->modify("+1 day");
|
||||
$last_date->modify("+1 hours");
|
||||
$finish_date = new DateTime($ivt_contract->lastdate);
|
||||
$finish_date->setDate($finish_date->format("Y"), $finish_date->format("m"), 1);
|
||||
//$finish_date->modify("+1 hours");
|
||||
|
||||
$contract_data = [];
|
||||
$contract_data['owner_id'] = $customer->id;
|
||||
@@ -184,8 +184,8 @@ class Admin_IvtContractImport {
|
||||
$contract_data['price_nne'] = 0;
|
||||
$contract_data['price_nbe'] = 0;
|
||||
$contract_data['sla_id'] = $this->getNewSlaId($ivt_contract->sid);
|
||||
$contract_data['order_date'] = $finish_date->getTimestamp();
|
||||
$contract_data['finish_date'] = $last_date->getTimestamp();
|
||||
$contract_data['order_date'] = $order_date->getTimestamp();
|
||||
$contract_data['finish_date'] = $finish_date->getTimestamp();
|
||||
$contract_data['finish_date_by'] = 1;
|
||||
$contract_data['imported_from'] = "ivt";
|
||||
$contract_data['imported_data'] = $ivt_contract->id;
|
||||
|
||||
@@ -6,12 +6,18 @@ class Admin_IvtCreditImport {
|
||||
private $netownerid = [
|
||||
3805 => 2840,
|
||||
4941 => 2840,
|
||||
4909 => 3199,
|
||||
4909 => 3199
|
||||
];
|
||||
private $cust_cred_ignore = [
|
||||
2267,
|
||||
2934
|
||||
];
|
||||
private $netowner_ignore = [
|
||||
3716
|
||||
];
|
||||
private $netowner_rules = [
|
||||
3715 => ["action" => "double_price"],
|
||||
];
|
||||
private $cust_cred_id_to_customer_id = [
|
||||
2891 => 104004,
|
||||
|
||||
@@ -49,6 +55,8 @@ class Admin_IvtCreditImport {
|
||||
$ivt_customer = $cust_cred->customer;
|
||||
}
|
||||
|
||||
if(in_array($ivt_netowner->id, $this->netowner_ignore)) continue;
|
||||
|
||||
if(!$ivt_customer) {
|
||||
echo __METHOD__.": No customer in cust_cred ".$cust_cred->id."\n";
|
||||
continue;
|
||||
@@ -62,7 +70,7 @@ class Admin_IvtCreditImport {
|
||||
}
|
||||
|
||||
if(!$customer) {
|
||||
echo __METHOD__ . ": No Customer ".$ivt_customer->id." cust_cred ".$cust_cred->id."\n";
|
||||
// XXX 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;
|
||||
}
|
||||
@@ -74,60 +82,105 @@ class Admin_IvtCreditImport {
|
||||
}
|
||||
|
||||
$contracts = ContractModel::search(["owner_id" => $customer->id]);
|
||||
|
||||
// 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
|
||||
$primary_contract = reset($contracts);
|
||||
// find more suitable primary contract
|
||||
foreach($contracts as $contract) {
|
||||
// only monthly products
|
||||
if($contract->biling_period > 1) continue;
|
||||
// no one-off products
|
||||
if(!$contract->price && $contract->price_setup) continue;
|
||||
if($contract->termination_id) {
|
||||
$primary_contract = $contract;
|
||||
break;
|
||||
}
|
||||
if(preg_match('/(dsl|funkinternet|standortgeber|glasfaser|brettljausn)/i', $contract->product->name)) {
|
||||
$primary_contract = $contract;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!$primary_contract) {
|
||||
//echo __METHOD__ . ": Contract not found for credit ".$cust_cred->id."\n";
|
||||
$this->log->debug("No primary contract cust ".$ivt_customer->id);
|
||||
}
|
||||
|
||||
// create Credit Contract
|
||||
|
||||
if(!$primary_contract->product_id) {
|
||||
var_dump($primary_contract);exit;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data["orderproduct_id"] = $primary_contract->orderproduct_id;
|
||||
$data["product_id"] = $primary_contract->product_id;
|
||||
$data["product_name"] = $primary_contract->product_name;
|
||||
$data["product_info"] = $primary_contract->product_info;
|
||||
$data["amount"] = $primary_contract->amount;
|
||||
$data["sla_id"] = $primary_contract->sla_id;
|
||||
$data["product_external"] = $primary_contract->product_external;
|
||||
$data["product_external_id"] = $primary_contract->product_external_id;
|
||||
$data["billing_delay"] = $primary_contract->billing_delay;
|
||||
$data["billing_period"] = $primary_contract->billing_period;
|
||||
$data["contract_term"] = $primary_contract->contract_term;
|
||||
$data["order_date"] = $primary_contract->order_date;
|
||||
|
||||
$data["finish_date"] = $primary_contract->finish_date;
|
||||
$data["finish_date_by"] = $primary_contract->finish_date_by;
|
||||
$data["note"] = $primary_contract->note;
|
||||
/*
|
||||
* 1962 - internal xinon account for credits missing contract
|
||||
*
|
||||
*/
|
||||
if($ivt_customer->id != 1962) {
|
||||
// if not xinon internal, look up primary contract for linking
|
||||
if(!count($contracts)) {
|
||||
$ivt_contracts = IvtCustomerProductModel::search(["cid" => $ivt_customer->id]);
|
||||
//echo __METHOD__ . ": Contract not found for credit ".$cust_cred->id." Kunde ".$customer->getCompanyOrName()." (".$customer->customer_number."; ".count($ivt_contracts)." IVT Contracts), GS an ".$netowner->getCompanyOrName()." (".$netowner->customer_number.")\n";
|
||||
echo "Netzinhaber: " . $netowner->getCompanyOrName() . " (" . $netowner->customer_number . ")\n";
|
||||
echo "Kunde: " . $customer->getCompanyOrName() . " (" . $customer->customer_number . ")\n";
|
||||
echo "Gutschft: " . $cust_cred->crediting_product->name . " | " . $cust_cred->crediting_product->price_excl . "\n";
|
||||
echo "GS Comment: " . $cust_cred->comment . "\n";
|
||||
if($ivt_contracts) {
|
||||
echo "Kunde Produkte:\n";
|
||||
foreach($ivt_contracts as $ivtc) {
|
||||
echo "\t" . $ivtc->pid . ": " . $ivtc->product->name . " | " . $ivtc->product->price . "\n";
|
||||
}
|
||||
} else {
|
||||
echo "Keine aktiven Produkte\n";
|
||||
}
|
||||
|
||||
echo "=========================\n\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
// use first contract as primary contract
|
||||
$primary_contract = reset($contracts);
|
||||
// find more suitable primary contract
|
||||
foreach($contracts as $contract) {
|
||||
// only monthly products
|
||||
if($contract->biling_period > 1) continue;
|
||||
// no one-off products
|
||||
if(!$contract->price && $contract->price_setup) continue;
|
||||
if($contract->termination_id) {
|
||||
$primary_contract = $contract;
|
||||
break;
|
||||
}
|
||||
if(preg_match('/(dsl|funkinternet|standortgeber|glasfaser|brettljausn)/i', $contract->product->name)) {
|
||||
$primary_contract = $contract;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!$primary_contract) {
|
||||
//echo __METHOD__ . ": Contract not found for credit ".$cust_cred->id."\n";
|
||||
$this->log->debug("No primary contract cust " . $ivt_customer->id);
|
||||
}
|
||||
|
||||
// create Credit Contract
|
||||
|
||||
if(!$primary_contract->product_id) {
|
||||
var_dump($primary_contract);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$data["orderproduct_id"] = $primary_contract->orderproduct_id;
|
||||
$data["product_id"] = $primary_contract->product_id;
|
||||
$data["product_name"] = $primary_contract->product_name;
|
||||
$data["product_info"] = $primary_contract->product_info;
|
||||
$data["amount"] = $primary_contract->amount;
|
||||
$data["sla_id"] = $primary_contract->sla_id;
|
||||
$data["product_external"] = $primary_contract->product_external;
|
||||
$data["product_external_id"] = $primary_contract->product_external_id;
|
||||
$data["billing_delay"] = $primary_contract->billing_delay;
|
||||
$data["billing_period"] = $primary_contract->billing_period;
|
||||
$data["contract_term"] = $primary_contract->contract_term;
|
||||
$data["order_date"] = $primary_contract->order_date;
|
||||
|
||||
$data["finish_date"] = $primary_contract->finish_date;
|
||||
$data["finish_date_by"] = $primary_contract->finish_date_by;
|
||||
$data["note"] = $primary_contract->note;
|
||||
} else {
|
||||
$create_date = new DateTime($cust_cred->created);
|
||||
$create_date->setTime(2,0);
|
||||
|
||||
$finish_date = new DateTime($cust_cred->lastdate);
|
||||
$finish_date->setDate($finish_date->format("Y"), $finish_date->format("m"), 1);
|
||||
|
||||
$data["orderproduct_id"] = null;
|
||||
$data["product_id"] = 336; // Mainproduct dummy for crediting import [IVT]
|
||||
$data["product_name"] = $cust_cred->crediting_product->name;
|
||||
$data["product_info"] = null;
|
||||
$data["amount"] = 1;
|
||||
$data["sla_id"] = 4;
|
||||
$data["product_external"] = 0;
|
||||
$data["product_external_id"] = null;
|
||||
$data["billing_delay"] = 0;
|
||||
$data["billing_period"] = 1;
|
||||
$data["contract_term"] = 12;
|
||||
$data["order_date"] = $create_date->getTimestamp();
|
||||
$data["finish_date"] = $finish_date->getTimestamp();
|
||||
$data["finish_date_by"] = 1;
|
||||
$data["note"] = null;
|
||||
}
|
||||
|
||||
$data["matchcode"] = $cust_cred->comment;
|
||||
$data["owner_id"] = $netowner->id;
|
||||
@@ -138,6 +191,16 @@ class Admin_IvtCreditImport {
|
||||
$data["price_nne"] = 0;
|
||||
$data["price_nbe"] = 0;
|
||||
|
||||
$data['imported_from'] = "ivt-credit";
|
||||
$data['imported_data'] = $cust_cred->id;
|
||||
|
||||
|
||||
if(array_key_exists($ivt_netowner->id, $this->netowner_rules)) {
|
||||
if($this->netowner_rules[$ivt_netowner->id]["action"] == "double_price") {
|
||||
$data['price'] *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
$cred_contract = ContractModel::create($data);
|
||||
if(!$cred_contract->save()) {
|
||||
$this->log->debug("error saving credit contract");
|
||||
@@ -146,22 +209,50 @@ class Admin_IvtCreditImport {
|
||||
}
|
||||
$c++;
|
||||
|
||||
// create Journals
|
||||
// creation journal
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $cred_contract->id,
|
||||
'type' => "created_from",
|
||||
'value' => "import",
|
||||
'text' => "IVT customer_credit ".$cust_cred->id."; cid: ".$cust_cred->cust_id."; pid: ".$ivt_cred_product->id." (".$ivt_cred_product->name.")"
|
||||
]);
|
||||
$journal_id = $journal->save();
|
||||
if(!$journal_id) {
|
||||
echo "Fehler beim Journal erstellen.<br />\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
// Link to all Contracts of Customer
|
||||
foreach($contracts as $contract) {
|
||||
if (ContractLinkModel::getFirst(["contract_id" => $cred_contract->id, "origin_contract_id" => $contract->id])) {
|
||||
continue;
|
||||
// credit linking journal
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $primary_contract->id,
|
||||
'type' => "credit_created",
|
||||
'value' => $primary_contract->id,
|
||||
//'text' => "IVT customer_credit ".$cust_cred->id."; cid: ".$cust_cred->cust_id."; pid: ".$ivt_cred_product->id." (".$ivt_cred_product->name.")"
|
||||
]);
|
||||
$journal_id = $journal->save();
|
||||
if(!$journal_id) {
|
||||
echo "Fehler beim Journal erstellen.<br />\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
if(count($contracts)) {
|
||||
// Link to all Contracts of Customer
|
||||
foreach($contracts as $contract) {
|
||||
if(ContractLinkModel::getFirst(["contract_id" => $cred_contract->id, "origin_contract_id" => $contract->id])) {
|
||||
continue;
|
||||
}
|
||||
$link = ContractLinkModel::create([
|
||||
'contract_id' => $cred_contract->id,
|
||||
'origin_contract_id' => $contract->id,
|
||||
'type' => 'link'
|
||||
]);
|
||||
$link->save();
|
||||
}
|
||||
$link = ContractLinkModel::create([
|
||||
'contract_id' => $cred_contract->id,
|
||||
'origin_contract_id' => $contract->id,
|
||||
'type' => 'link'
|
||||
]);
|
||||
$link->save();
|
||||
}
|
||||
}
|
||||
|
||||
echo "Imported $i credits; $c Contracts erstellt\n";
|
||||
echo "Imported $i credits; $c Credit Contracts erstellt\n";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user