WIP Productchange 2024-07-16
This commit is contained in:
@@ -184,6 +184,108 @@ class ContractModel {
|
||||
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public static function createCreditForContract($contract) {
|
||||
$log = mfLoghandler::singleton();
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if(!$contract->id) {
|
||||
$log->warning(__METHOD__."(): Invalid Contractqueue object");
|
||||
return false;
|
||||
}
|
||||
|
||||
$product = $contract->product;
|
||||
$owner = $contract->owner;
|
||||
|
||||
if(!$product->id) {
|
||||
$log->warning(__METHOD__."(): Invalid Product");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get credit price from NNE or percentage of sales price
|
||||
*/
|
||||
$crediting_partner_id = false;
|
||||
$crediting_partner_rate = false;
|
||||
|
||||
$product_attribs = $product->attributes;
|
||||
if(is_array($product_attribs) && array_key_exists("crediting_partner", $product_attribs) && $product_attribs["crediting_partner"] && is_object($product_attribs["crediting_partner"])) {
|
||||
if($product_attribs["crediting_partner"]->value) {
|
||||
$crediting_partner_id = $product_attribs["crediting_partner"]->value;
|
||||
}
|
||||
if($product_attribs["crediting_rate"]->value) {
|
||||
$crediting_partner_rate = str_replace(",", ".",$product_attribs["crediting_rate"]->value);
|
||||
}
|
||||
}
|
||||
|
||||
// or from netowner if anschluss product
|
||||
if(!$crediting_partner_id && $contract->termination_id) {
|
||||
$crediting_partner_id = $contract->termination->building->network->owner_id;
|
||||
}
|
||||
|
||||
$crediting_partner = new Address($crediting_partner_id);
|
||||
if(!$crediting_partner->id) {
|
||||
$log->error(__METHOD__.": Kein Crediting Partner gefunden für Credit für Contract ID ".$contract->id);
|
||||
return false;
|
||||
}
|
||||
|
||||
// determine price:
|
||||
// either NNE or percentage based, depends on product
|
||||
$crediting_price = $product->price_nne;
|
||||
if($crediting_partner_rate) {
|
||||
$crediting_price = round($contract->price / 100 * $crediting_partner_rate, 4);
|
||||
}
|
||||
|
||||
if(!$crediting_price) return true;
|
||||
$crediting_price *= -1;
|
||||
|
||||
$data = [];
|
||||
$data["orderproduct_id"] = null;
|
||||
$data["owner_id"] = $crediting_partner_id;
|
||||
$data["billingaddress_id"] = null;
|
||||
$data["termination_id"] = null;
|
||||
$data["product_id"] = $contract->product_id;
|
||||
$data["product_name"] = $contract->product_name;
|
||||
$data["product_info"] = $contract->product_info;
|
||||
$data["amount"] = $contract->amount;
|
||||
$data["sla_id"] = $contract->sla_id;
|
||||
$data["product_external"] = $contract->product_external;
|
||||
$data["product_external_id"] = $contract->product_external_id;
|
||||
$data["billing_delay"] = $contract->billing_delay;
|
||||
$data["billing_period"] = $contract->billing_period;
|
||||
$data["contract_term"] = $contract->contract_term;
|
||||
$data["order_date"] = $contract->order_date;
|
||||
|
||||
$data["finish_date"] = $contract->finish_date;
|
||||
$data["finish_date_by"] = $me->id;
|
||||
$data["note"] = null;
|
||||
|
||||
|
||||
// matchcode
|
||||
$owner_address = $owner->street.", ".$owner->zip." ".$owner->city;
|
||||
if($contract->termination_id) {
|
||||
$termination = new Termination($contract->termination_id);
|
||||
$termination_address = $termination->building->street.", ".$termination->building->zip." ".$termination->building->city;
|
||||
$matchcode = $termination_address;
|
||||
} else {
|
||||
$matchcode = $owner_address;
|
||||
}
|
||||
|
||||
$matchcode = $contract->owner->getCompanyOrName()."; $matchcode";
|
||||
|
||||
$data["matchcode"] = $matchcode;
|
||||
$data["price"] = $crediting_price;
|
||||
$data["price_setup"] = 0;
|
||||
$data["price_nne"] = 0;
|
||||
$data["price_nbe"] = 0;
|
||||
$data["vatgroup_id"] = $contract->vatgroup_id;
|
||||
|
||||
|
||||
$credit = ContractModel::create($data);
|
||||
|
||||
return $credit;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
Reference in New Issue
Block a user