WIP Productchange 2024-07-16
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -140,34 +140,13 @@ class ContractController extends mfBaseController
|
||||
$this->redirect("Contract", "view", ["contract_id" => $contract->id]);
|
||||
}
|
||||
|
||||
if($contract->finish_date) {
|
||||
$today = new DateTime();
|
||||
$tomorrow = clone($today);
|
||||
$tomorrow->modify("+1 day");
|
||||
$today = new DateTime();
|
||||
$tomorrow = clone($today);
|
||||
$tomorrow->modify("+1 day");
|
||||
|
||||
$finish_date = new DateTime("@".$contract->finish_date);
|
||||
$finish_date->setTimezone(new DateTimeZone("Europe/Vienna"));
|
||||
|
||||
$period_end_date = clone($finish_date);
|
||||
$period_end_date->modify("+".$contract->contract_term." months");
|
||||
|
||||
while($period_end_date->format("Y-m-d") <= $today->format("Y-m-d")) {
|
||||
$period_end_date = $finish_date->modify("+".$contract->billing_period." months");
|
||||
|
||||
}
|
||||
$period_end_date->modify("-1 day");
|
||||
|
||||
$next_billing_period = clone($finish_date);
|
||||
$next_billing_period->modify("+".$contract->billing_period." months");
|
||||
while($next_billing_period->format("Y-m-d") <= $today->format("Y-m-d")) {
|
||||
$next_billing_period->modify("+".$contract->billing_period." months");
|
||||
}
|
||||
$next_billing_period->modify("-1 day");
|
||||
|
||||
$this->layout()->set("tomorrow", $tomorrow);
|
||||
$this->layout()->set("term_end_date", $period_end_date);
|
||||
$this->layout()->set("period_end_date", $next_billing_period);
|
||||
}
|
||||
$this->layout()->set("tomorrow", $tomorrow);
|
||||
$this->layout()->set("term_end_date", $contract->getRegularCanceldate());
|
||||
$this->layout()->set("period_end_date", $contract->getNextBillingPeriodEnd());
|
||||
|
||||
|
||||
$this->layout()->set("contract", $contract);
|
||||
@@ -191,7 +170,7 @@ class ContractController extends mfBaseController
|
||||
|
||||
try {
|
||||
$cancel_date = DateTime::createFromFormat("d.m.Y", trim($r->cancel_date), new DateTimeZone("Europe/Vienna"));
|
||||
$cancel_date->setTime(2,0,0);
|
||||
$cancel_date->setTime(23,59,59);
|
||||
} catch(Exception $e) {
|
||||
$this->layout()->setFlash("Ungültiges Datumsformat");
|
||||
$this->redirect("Contract", "cancel", ["contract_id" => $contract->id]);
|
||||
@@ -288,6 +267,7 @@ class ContractController extends mfBaseController
|
||||
protected function saveProductchangeAction()
|
||||
{
|
||||
$r = $this->request;
|
||||
//var_dump($r->links);exit;
|
||||
|
||||
$id = $r->contract_id;
|
||||
if (!is_numeric($id) || !$id) {
|
||||
@@ -330,6 +310,22 @@ class ContractController extends mfBaseController
|
||||
$contract_data['product_external_id'] = $product->external_id;
|
||||
$contract_data['sla_id'] = $product->sla_id;
|
||||
|
||||
if($r->finish_date) {
|
||||
try {
|
||||
$finish_date = DateTime::createFromFormat("d.m.Y", $r->finish_date, new DateTimeZone("Europe/Vienna"));
|
||||
} catch (Exception $e) {
|
||||
$this->layout()->setFlash("Ungültiges Kündigungsdateum", "error");
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id]);
|
||||
}
|
||||
|
||||
$finish_date->setTime(0,0,0);
|
||||
$contract_data["finish_date"] = $finish_date->getTimestamp();
|
||||
|
||||
$contract_cancel_date = clone($finish_date);
|
||||
$contract_cancel_date->modify("-1 day");
|
||||
$contract_cancel_date->setTime(23,59,59);
|
||||
}
|
||||
|
||||
$require_term = false;
|
||||
if (array_key_exists(TT_ATTRIB_TERMINATION_REQUIRED_NAME, $product->attributes) && $product->attributes[TT_ATTRIB_TERMINATION_REQUIRED_NAME]->value == 1) {
|
||||
//var_dump($prod->attributes);
|
||||
@@ -353,41 +349,124 @@ class ContractController extends mfBaseController
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id]);
|
||||
}
|
||||
|
||||
if($contract_cancel_date) {
|
||||
$contract->cancel_date = $contract_cancel_date->getTimestamp();
|
||||
$contract->save();
|
||||
}
|
||||
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $new_contract->id,
|
||||
'type' => "created_from",
|
||||
'value' => "productchange",
|
||||
'text' => "Produkt-/Standortwechsel von Contract ID ".$contract->id
|
||||
]);
|
||||
$journal->save();
|
||||
|
||||
if (is_array($r->links) && count($r->links)) {
|
||||
foreach ($r->links as $link_id => $action) {
|
||||
foreach ($r->links as $link_id => $link_data) {
|
||||
$action = $link_data["action"];
|
||||
$cancel_date = false;
|
||||
if($link_data["cancel_date"]) {
|
||||
try {
|
||||
$cancel_date = DateTime::createFromFormat("d.m.Y", $link_data["cancel_date"], new DateTimeZone("Europe/Vienna"));
|
||||
} catch (Exception $e) {
|
||||
$this->layout()->setFlash("Ungültiges Kündigungsdateum", "error");
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$old_link = new ContractLink($link_id);
|
||||
if (!$old_link->id) continue;
|
||||
|
||||
// check if link contains this contract
|
||||
if ($old_link->contract_id == $contract->id) {
|
||||
$origin_id = $old_link->origin_contract_id;
|
||||
$link_contract_id = $old_link->contract_id;
|
||||
|
||||
$new_link_contract_id = $new_contract->id;
|
||||
$new_link_origin_id = $old_link->origin_contract_id;
|
||||
} elseif ($old_link->origin_contract_id == $contract->id) {
|
||||
$origin_id = $old_link->contract_id;
|
||||
$link_contract_id = $old_link->origin_contract_id;
|
||||
|
||||
$new_link_contract_id = $old_link->contract_id;
|
||||
$new_link_origin_id = $new_contract->id;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
$new_link = ContractLinkModel::create([
|
||||
'contract_id' => $new_link_contract_id,
|
||||
'origin_contract_id' => $new_link_origin_id,
|
||||
'type' => $old_link->type,
|
||||
]);
|
||||
if (!$new_link->save()) {
|
||||
$this->layout()->setFlash("Konnte neuen Link nicht speichern", "warn");
|
||||
}
|
||||
|
||||
if ($action == "cancel") {
|
||||
$old_link->change_action = "cancel";
|
||||
if (!$old_link->save()) {
|
||||
$this->layout()->setFlash("Konnte alten Link nicht speichern", "warn");
|
||||
if($action != "cancel" && $old_link->type != "credit") {
|
||||
$new_link = ContractLinkModel::create([
|
||||
'contract_id' => $new_link_contract_id,
|
||||
'origin_contract_id' => $new_link_origin_id,
|
||||
'type' => $old_link->type,
|
||||
]);
|
||||
if (!$new_link->save()) {
|
||||
$this->layout()->setFlash("Konnte neuen Link nicht speichern", "warn");
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == "cancel") {
|
||||
if($cancel_date) {
|
||||
// insert cancel_date in old contract
|
||||
$lc = new Contract($origin_id);
|
||||
$lc->cancel_date = $cancel_date->getTimestamp();
|
||||
$lc->save();
|
||||
} else {
|
||||
// leave cancellation for later (when finishing upgrade)
|
||||
$old_link->change_action = "cancel";
|
||||
if (!$old_link->save()) {
|
||||
$this->layout()->setFlash("Konnte alten Link nicht speichern", "warn");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($old_link->type == "credit" && $action == "keep") {
|
||||
$old_link->change_action = "recreate";
|
||||
// XXX - if we have finish date then recreate credit contract right now
|
||||
if($contract_cancel_date) {
|
||||
$new_credit = ContractModel::createCreditForContract($new_contract);
|
||||
$new_credit->save();
|
||||
|
||||
// create journal for credit
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $new_credit->id,
|
||||
'type' => "created_from",
|
||||
'value' => "productchange",
|
||||
'text' => "Produkt-/Standortwechsel von Contract ID ".$new_link_origin_id
|
||||
]);
|
||||
$journal->save();
|
||||
|
||||
|
||||
$this->log->debug(print_r($new_credit, true));
|
||||
|
||||
// set cancel date for old credit
|
||||
$old_credit = new Contract($origin_id);
|
||||
$old_credit->cancel_date = $contract_cancel_date->getTimestamp();
|
||||
$old_credit->save();
|
||||
|
||||
// create link to new credit contract
|
||||
$link = ContractLinkModel::create([
|
||||
"contract_id" => $new_credit->id,
|
||||
"origin_contract_id" => $new_contract->id,
|
||||
"type" => "credit"
|
||||
]);
|
||||
$link->save();
|
||||
|
||||
// create upgrade link from old to new credit contract
|
||||
$link = ContractLinkModel::create([
|
||||
"contract_id" => $new_credit->id,
|
||||
"origin_contract_id" => $origin_id,
|
||||
"type" => "upgrade"
|
||||
]);
|
||||
$link->save();
|
||||
|
||||
} else {
|
||||
$old_link->change_action = "recreate";
|
||||
$old_link->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//var_dump($new_link);exit;
|
||||
@@ -439,82 +518,23 @@ class ContractController extends mfBaseController
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
$now = date('U');
|
||||
|
||||
/*
|
||||
* Vorgänger Contracts kündigen
|
||||
*/
|
||||
foreach (ContractLinkModel::search(['contract_id' => $id]) as $link) {
|
||||
if (!in_array($link->type, ["upgrade", "downgrade", "relocation", "productchange"])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$origin = $link->origin;
|
||||
$origin->cancel_date = $now;
|
||||
$origin->cancel_date_by = $this->me->id;
|
||||
$origin->edit_by = $this->me->id;
|
||||
if (!$origin->save()) {
|
||||
$this->layout()->setFlash("Achtung: Konnte nicht alle Vorgängercontracts kündigen!", "warn");
|
||||
}
|
||||
|
||||
/*
|
||||
* alte Links übernehmen / kündigen
|
||||
*/
|
||||
foreach (ContractLinkModel::search(['type' => "link", 'contract_id' => $origin->id]) as $old_link) {
|
||||
// verlinkten Contract kündigen (wenn nicht schon gekündigt)
|
||||
if ($old_link->change_action == "cancel" && !$old_link->contract->cancel_date) {
|
||||
$old_link->origin->update([
|
||||
'cancel_date' => $now,
|
||||
'cancel_date_by' => $this->me->id,
|
||||
'edit_by' => $this->me->id
|
||||
]);
|
||||
$old_link->origin->save();
|
||||
|
||||
$old_link->change_action = null;
|
||||
$old_link->save();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ContractLinkModel::search(['type' => "link", 'origin_contract_id' => $origin->id]) as $old_link) {
|
||||
// verlinkten Contract kündigen (wenn nicht schon gekündigt)
|
||||
if ($old_link->change_action == "cancel" && !$old_link->contract->cancel_date) {
|
||||
$old_link->contract->update([
|
||||
'cancel_date' => $now,
|
||||
'cancel_date_by' => $this->me->id,
|
||||
'edit_by' => $this->me->id
|
||||
]);
|
||||
$old_link->contract->save();
|
||||
|
||||
$old_link->change_action = null;
|
||||
$old_link->save();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ContractLinkModel::search(['type' => "credit", 'contract_id' => $origin->id]) as $old_credit) {
|
||||
// verlinkten Contract kündigen (wenn nicht schon gekündigt)
|
||||
if ($old_credit->change_action == "recreate" && !$old_credit->contract->cancel_date) {
|
||||
$old_credit->origin->update([
|
||||
'cancel_date' => $now,
|
||||
'cancel_date_by' => $this->me->id,
|
||||
'edit_by' => $this->me->id
|
||||
]);
|
||||
$old_credit->origin->save();
|
||||
|
||||
$old_credit->change_action = null;
|
||||
$old_credit->save();
|
||||
}
|
||||
}
|
||||
$now = new DateTime("now");
|
||||
$now->setTime(0,0,0);
|
||||
|
||||
$contract->finish_date = $now->getTimestamp();
|
||||
$contract->finish_date_by = $this->me->id;
|
||||
try {
|
||||
$saved = $contract->save();
|
||||
} catch(Exception $e) {
|
||||
$saved = false;
|
||||
}
|
||||
|
||||
|
||||
$contract->finish_date = $now;
|
||||
$contract->finish_date_by = $this->me->id;
|
||||
if (!$contract->save()) {
|
||||
if(!$saved) {
|
||||
$this->layout()->setFlash("Contract konnte nicht gespeichert werden", "error");
|
||||
$this->redirect("Contract", "view", ['contract_id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
// create Journal
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $contract->id,
|
||||
@@ -620,6 +640,10 @@ class ContractController extends mfBaseController
|
||||
$contract_data['billing_delay'] = (int)$r->billing_delay;
|
||||
$contract_data['note'] = $r->note;
|
||||
|
||||
if($r->termination_id) {
|
||||
$contract_data["termination_id"] = $r->termination_id;
|
||||
}
|
||||
|
||||
if($r->order_date) {
|
||||
$order_date = new DateTime("@" . $this->dateToTimestamp($r->order_date));
|
||||
$order_date->setTimezone(new DateTimeZone("Europe/Vienna"));
|
||||
|
||||
@@ -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 = [];
|
||||
|
||||
186
application/Contract/trigger/Finished.php
Normal file
186
application/Contract/trigger/Finished.php
Normal file
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
class ContractTrigger_Finished {
|
||||
private $log;
|
||||
private $db;
|
||||
private $me;
|
||||
private $contract;
|
||||
public $errors;
|
||||
|
||||
public function __construct($injection = []) {
|
||||
foreach($injection as $name => $value) {
|
||||
if(in_array($name, ["log", "db", "contract", "me"])) {
|
||||
$this->$name = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks Contract if can/must run
|
||||
* return true if it wants to run
|
||||
* @return bool
|
||||
*/
|
||||
public function precheck() {
|
||||
$contract = $this->contract;
|
||||
if($contract->finish_date && !$contract->_old_data->finish_date) {
|
||||
// contract was just finished, so we need to run
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function run() {
|
||||
$contract = $this->contract;
|
||||
if($contract->_old_data->finish_date) {
|
||||
var_dump($contract->finish_date, $contract->_old_data->finish_date);
|
||||
return true;
|
||||
}
|
||||
// contract was just finished, so we need to run
|
||||
|
||||
/*
|
||||
* Vorgänger Contracts kündigen
|
||||
*/
|
||||
foreach (ContractLinkModel::search(['contract_id' => $contract->id]) as $link) {
|
||||
if (!in_array($link->type, ["upgrade", "downgrade", "relocation", "productchange", "ownerchange"])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$now = new DateTime("now");
|
||||
$now->setTime(2,0,0);
|
||||
|
||||
$cancel_date = clone($now);
|
||||
$cancel_date->setTime(23,59,59);
|
||||
|
||||
$origin = $link->origin;
|
||||
$origin->cancel_date = $cancel_date->getTimestamp();
|
||||
$origin->cancel_date_by = $this->me->id;
|
||||
$origin->edit_by = $this->me->id;
|
||||
if (!$origin->save()) {
|
||||
throw new Exception("Fehler beim Speichern der Kündigung des Vorgängercontracts!");
|
||||
}
|
||||
// cancel journal
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $origin->id,
|
||||
'type' => "canceled",
|
||||
'value' => "",
|
||||
'text' => ""
|
||||
]);
|
||||
$journal->save();
|
||||
|
||||
|
||||
/*
|
||||
* alte Links übernehmen / kündigen
|
||||
*/
|
||||
foreach (ContractLinkModel::search(['type' => "link", 'contract_id' => $origin->id]) as $old_link) {
|
||||
// verlinkten Contract kündigen (wenn nicht schon gekündigt)
|
||||
if ($old_link->change_action == "cancel" && !$old_link->origin->cancel_date) {
|
||||
$old_link->origin->update([
|
||||
'cancel_date' => $now->getTimestamp(),
|
||||
'cancel_date_by' => $this->me->id,
|
||||
'edit_by' => $this->me->id
|
||||
]);
|
||||
if(!$old_link->origin->save()) {
|
||||
throw new Exception("Fehler beim Speichern der Kündigung des Vorgängercontracts!");
|
||||
}
|
||||
|
||||
$old_link->change_action = null;
|
||||
$old_link->save();
|
||||
|
||||
// cancel journal
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $old_link->origin->id,
|
||||
'type' => "canceled",
|
||||
'value' => "",
|
||||
'text' => ""
|
||||
]);
|
||||
$journal->save();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ContractLinkModel::search(['type' => "link", 'origin_contract_id' => $origin->id]) as $old_link) {
|
||||
// verlinkten Contract kündigen (wenn nicht schon gekündigt)
|
||||
if ($old_link->change_action == "cancel" && !$old_link->contract->cancel_date) {
|
||||
$old_link->contract->update([
|
||||
'cancel_date' => $now->getTimestamp(),
|
||||
'cancel_date_by' => $this->me->id,
|
||||
'edit_by' => $this->me->id
|
||||
]);
|
||||
//$this->log->debug(print_r($old_link->contract, true));
|
||||
$old_link->contract->save();
|
||||
|
||||
$old_link->change_action = null;
|
||||
$old_link->save();
|
||||
|
||||
// cancel journal
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $old_link->contract->id,
|
||||
'type' => "canceled",
|
||||
'value' => "",
|
||||
'text' => ""
|
||||
]);
|
||||
$journal->save();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ContractLinkModel::search(['type' => "credit", 'origin_contract_id' => $origin->id]) as $old_credit) {
|
||||
if ($old_credit->change_action == "recreate" && !$old_credit->contract->cancel_date) {
|
||||
// Alte Gutschrift kündigen und neue anlegen
|
||||
//var_dump($old_credit->contract);
|
||||
$old_credit->contract->update([
|
||||
'cancel_date' => $now->getTimestamp(),
|
||||
'cancel_date_by' => $this->me->id,
|
||||
'edit_by' => $this->me->id
|
||||
]);
|
||||
$old_credit->contract->save();
|
||||
//var_dump($old_credit->contract);
|
||||
//exit;
|
||||
|
||||
$old_credit->change_action = null;
|
||||
$old_credit->save();
|
||||
|
||||
$new_credit = ContractModel::createCreditForContract($contract);
|
||||
if(!$new_credit->save()) {
|
||||
$this->log->debug(print_r($new_credit, true));
|
||||
throw new Exception("Fehler beim Speichern des neuen Gutschrift Contracts");
|
||||
}
|
||||
|
||||
// create journal for credit
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $new_credit->id,
|
||||
'type' => "created_from",
|
||||
'value' => "productchange",
|
||||
'text' => "Produkt-/Standortwechsel von Contract ID ".$old_credit->contract_id
|
||||
]);
|
||||
$journal->save();
|
||||
|
||||
|
||||
$this->log->debug(print_r($new_credit, true));
|
||||
|
||||
// create link to new credit contract
|
||||
$link = ContractLinkModel::create([
|
||||
"contract_id" => $new_credit->id,
|
||||
"origin_contract_id" => $contract->id,
|
||||
"type" => "credit"
|
||||
]);
|
||||
$link->save();
|
||||
|
||||
// create link from old to new credit contract
|
||||
$link = ContractLinkModel::create([
|
||||
"contract_id" => $new_credit->id,
|
||||
"origin_contract_id" => $old_credit->contract_id,
|
||||
"type" => "upgrade"
|
||||
]);
|
||||
$link->save();
|
||||
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $old_credit->contract_id,
|
||||
'type' => "canceled",
|
||||
'value' => "",
|
||||
'text' => ""
|
||||
]);
|
||||
$journal->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user