Added temporary script to create Contracts from Orders
This commit is contained in:
@@ -141,7 +141,7 @@
|
||||
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
||||
<a href="<?=self::getUrl("Contract", "view", ["contract_id" => $contract->id, "s" => $s, "filter" => $filter])?>"><i class="far fa-eyes" title="Aktives Produkt anzeigen"></i></a>
|
||||
<a href="<?=self::getUrl("Contract", "edit", ["contract_id" => $contract->id, "s" => $s, "filter" => $filter])?>"><i class="far fa-edit" title="Aktives Produkt bearbeiten"></i></a>
|
||||
<?php if($contract->orderproduct_id): ?><a href="<?=self::getUrl("Order", "edit", ["id" => $contract->orderproduct->order_id])?>"><i class="far fa-file-signature" title="Bestellung anzeigen"></i></a><?php endif; ?>
|
||||
<?php if($contract->orderproduct_id): ?><a href="<?=self::getUrl("Order", "edit", ["id" => $contract->orderproduct->order_id])?>" target="_blank"><i class="far fa-file-signature" title="Bestellung anzeigen"></i></a><?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@@ -111,6 +111,22 @@ class Contract extends mfBaseModel {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function generateMatchcode() {
|
||||
$owner_address = $this->getProperty("owner")->street.", ".$this->getProperty("owner")->zip." ".$this->getProperty("owner")->city;
|
||||
|
||||
if($this->termination_id) {
|
||||
$termination = new Termination($this->termination_id);
|
||||
$termination_address = $termination->building->street.", ".$termination->building->zip." ".$termination->building->city;
|
||||
return $termination_address;
|
||||
}
|
||||
|
||||
if(stripos($this->getProperty("product")->name, "dsl") != false) {
|
||||
return $owner_address;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
@@ -136,12 +152,6 @@ class Contract extends mfBaseModel {
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if($name == "product") {
|
||||
$this->product = mfValuecache::singleton()->get("mfObjectmodel-Product-".$this->product_id);
|
||||
if($this->product === null) {
|
||||
@@ -164,6 +174,14 @@ class Contract extends mfBaseModel {
|
||||
return $this->orderproduct;
|
||||
}
|
||||
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*if($name == "contractConfigGroups") {
|
||||
$product = $this->getProperty("product");
|
||||
$this->contractConfigGroups = ContractconfigGroupModel::search(['producttech_id' => $product->producttech_id]);
|
||||
@@ -265,7 +283,6 @@ class Contract extends mfBaseModel {
|
||||
return $this->editor;
|
||||
}
|
||||
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
||||
|
||||
@@ -54,6 +54,58 @@ class ContractModel {
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function createFromOrderproduct($op) {
|
||||
$log = mfLoghandler::singleton();
|
||||
|
||||
if(!$op->id) {
|
||||
$log->warning(__METHOD__."(): Invalid OrderProduct object");
|
||||
return false;
|
||||
}
|
||||
|
||||
$order = $op->order;
|
||||
$product = $op->product;
|
||||
|
||||
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"] = $op->id;
|
||||
$data["owner_id"] = $order->owner_id;
|
||||
$data["billingaddress_id"] = $order->billingaddress_id;
|
||||
$data["termination_id"] = ($op->termination_id) ? $op->termination_id : null;
|
||||
$data["product_id"] = $op->product_id;
|
||||
$data["product_name"] = $product->name;
|
||||
$data["product_info"] = $product->description;
|
||||
$data["amount"] = $op->amount;
|
||||
$data["sla_id"] = $product->sla_id;
|
||||
$data["produt_external"] = ($product->external) ? $product->external : 0;
|
||||
$data["product_external_id"] = ($product->external) ? $product->external_id : null;
|
||||
$data["price"] = $op->price;
|
||||
$data["price_setup"] = $op->price_setup;
|
||||
$data["price_nne"] = $op->price_nne;
|
||||
$data["price_nbe"] = $op->price_nbe;
|
||||
$data["billing_delay"] = $op->billing_delay;
|
||||
$data["billing_period"] = $op->billing_period;
|
||||
$data["order_date"] = $order->order_date;
|
||||
|
||||
$data["finish_date"] = $order->finish_date;
|
||||
$data["finish_date_by"] = 1;
|
||||
$data["note"] = $order->note;
|
||||
|
||||
$contract = ContractModel::create($data);
|
||||
$contract->matchcode = $contract->generateMatchcode();
|
||||
//var_dump($contract);exit;
|
||||
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
|
||||
60
scripts/contract/order2contract.php
Normal file
60
scripts/contract/order2contract.php
Normal file
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
require("../../config/config.php");
|
||||
|
||||
define('FRONKDB_SQLDEBUG',false);
|
||||
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
|
||||
|
||||
require_once(LIBDIR."/mvcfronk/mfRouter/mfRouter.php");
|
||||
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseModel.php");
|
||||
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
|
||||
|
||||
$me = new User(1);
|
||||
|
||||
foreach(OrderModel::search(["finish_date" => true]) as $order) {
|
||||
if(!is_array($order->products) || !count($order->products)) {
|
||||
echo "keine Produkte in Order ".$order->id."\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$contracts = [];
|
||||
$primary_matchcode = false;
|
||||
|
||||
// make contracts but don't save them yet
|
||||
foreach($order->products as $op) {
|
||||
$contract = ContractModel::getFirst(["product_id" => $op->product_id, "orderproduct_id" => $op->id]);
|
||||
if($contract) {
|
||||
if($contract->matchcode) {
|
||||
$primary_matchcode = $contract->matchcode;
|
||||
}
|
||||
echo "Contract für Order ".$order->id." Produkt ".$op->product->name." (".$op->product_id.") schon vorhanden (contract_id ".$contract->id.")\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$contract = ContractModel::createFromOrderproduct($op);
|
||||
$contract->create_by = $me->id;
|
||||
$contract->edit_by = $me->id;
|
||||
|
||||
if($contract->matchcode) {
|
||||
$primary_matchcode = $contract->matchcode;
|
||||
}
|
||||
$contracts[] = $contract;
|
||||
}
|
||||
|
||||
if(!$primary_matchcode) {
|
||||
$primary_matchcode = $order->owner->street.", ".$order->owner->zip." ".$order->owner->city;
|
||||
}
|
||||
|
||||
// set matchcode and save
|
||||
foreach($contracts as $contract) {
|
||||
if(!$contract->matchcode) {
|
||||
$contract->matchcode = $primary_matchcode;
|
||||
|
||||
}
|
||||
//var_dump($contract);exit;
|
||||
$contract->save();
|
||||
|
||||
}
|
||||
exit;
|
||||
}
|
||||
Reference in New Issue
Block a user