Contract WIP & Contractqueue WIP 2024-04-18

This commit is contained in:
Frank Schubert
2024-04-18 14:01:02 +02:00
parent 1819b8ee9c
commit bede016157
8 changed files with 685 additions and 352 deletions

View File

@@ -56,7 +56,7 @@ class ContractModel {
return $model;
}
public static function createFromOrderproduct($op) {
public static function createFromOrderproduct(OrderProduct $op) {
$log = mfLoghandler::singleton();
if(!$op->id) {
@@ -107,6 +107,82 @@ class ContractModel {
return $contract;
}
public static function createFromContractQueue(Contractqueue $cq, $contracttype = "contract") {
$log = mfLoghandler::singleton();
$me = new User();
$me->loadMe();
if(!$cq->id) {
$log->warning(__METHOD__."(): Invalid Contractqueue object");
return false;
}
$order_id = $cq->order_id;
$product_id = $cq->product_id;
$order = new Order($order_id);
$product = new Product($product_id);
if(!$order->id || !$product->id) {
$log->warning(__METHOD__."(): Invalid Order or Product");
return false;
}
if(!$order->finish_date || $order->finish_date > date("U")) {
$log->warning(__METHOD__."(): Order not finished yet");
return false;
}
$data = [];
$data["orderproduct_id"] = $cq->orderproduct_id;
$data["matchcode"] = $cq->matchcode;
$data["owner_id"] = $cq->owner_id;
$data["billingaddress_id"] = ($cq->billingaddress_id) ? $cq->billingaddress_id : $cq->owner_id;
$data["termination_id"] = ($cq->termination_id) ? $cq->termination_id : null;
$data["product_id"] = $cq->product_id;
$data["product_name"] = $cq->product_name;
$data["product_info"] = $cq->product_info;
$data["amount"] = $cq->amount;
$data["sla_id"] = $cq->sla_id;
$data["product_external"] = $cq->product_external;
$data["product_external_id"] = $cq->product_external_id;
$data["price"] = $cq->price;
$data["price_setup"] = $cq->price_setup;
$data["price_nne"] = $cq->price_nne;
$data["price_nbe"] = $cq->price_nbe;
$data["billing_delay"] = $cq->billing_delay;
$data["billing_period"] = $cq->billing_period;
$data["contract_term"] = $cq->contract_term;
$data["order_date"] = $order->order_date;
$data["finish_date"] = $order->finish_date;
$data["finish_date_by"] = $me->id;
$data["note"] = $order->note;
if($contracttype == "credit") {
$crediting_price = $cq->price_nne;
if($cq->crediting_partner_rate) {
$crediting_price = round($cq->price / 100 * $cq->crediting_partner_rate, 4);
}
$crediting_price *= -1;
$data["matchcode"] = $cq->crediting_matchcode;
$data["owner_id"] = $cq->crediting_partner_id;
$data["billingaddress_id"] = $cq->crediting_partner_id;
$data["termination_id"] = null;
$data["price"] = $crediting_price;
$data["price_setup"] = 0;
$data["price_nne"] = 0;
$data["price_nbe"] = 0;
}
$contract = ContractModel::create($data);
//var_dump($contract);exit;
return $contract;
}
public function savePrecontract($contract) {