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
@@ -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";
}
}