Added Contractconfig Edit
This commit is contained in:
@@ -4,11 +4,12 @@ class Address extends mfBaseModel {
|
||||
protected $forcestr = ['street','company','zip','phone','fax','mobile','note'];
|
||||
private $parent;
|
||||
private $childaddresses;
|
||||
private $links;
|
||||
private $linked_as;
|
||||
private $links = [];
|
||||
private $linked_as = [];
|
||||
private $types;
|
||||
private $attributes;
|
||||
private $permissions;
|
||||
private $contracts;
|
||||
|
||||
private $phoneparts;
|
||||
|
||||
@@ -181,6 +182,14 @@ class Address extends mfBaseModel {
|
||||
$this->childaddresses = AddressModel::search(['parent' => $this->id]);
|
||||
return $this->childaddresses;
|
||||
}
|
||||
|
||||
if($name == "contracts") {
|
||||
$owning = ContractModel::search(['owner_id' => $this->id]);
|
||||
$billing = ContractModel::search(['billingaddress_id' => $this->id]);
|
||||
$this->contracts = array_merge($owning, $billing);
|
||||
return $this->contracts;
|
||||
}
|
||||
|
||||
/*
|
||||
if($name == "links_to") {
|
||||
$links = AddressLinkModel::search(['address_id' => $this->id]);
|
||||
|
||||
@@ -10,6 +10,7 @@ class Contract extends mfBaseModel {
|
||||
private $contractConfigGroups;
|
||||
private $contractConfigItems;
|
||||
private $configgroups;
|
||||
private $isCancelled;
|
||||
private $links;
|
||||
private $linkFrom;
|
||||
private $linkTo;
|
||||
@@ -86,22 +87,24 @@ class Contract extends mfBaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*$this->links = mfValuecache::singleton()->get("ContractLinks-origin-".$this->id);
|
||||
if(!$this->links) {
|
||||
$this->links = [];
|
||||
foreach(ContractLinkModel::search(["origin_contract_id" => $this->id]) as $link) {
|
||||
if(array_key_exists($link->type, $this->links)) {
|
||||
$this->links[$link->type] = [];
|
||||
}
|
||||
$this->links[$link->type][] = $link;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function isCancelled() {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
}
|
||||
if(count($this->links)) {
|
||||
mfValuecache::singleton()->set("ContractLinks-origin-".$this->id, $this->links);
|
||||
|
||||
if(!$this->cancel_date) {
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
$now = date('U');
|
||||
if($this->cancel_date < $now) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
@@ -186,6 +189,7 @@ class Contract extends mfBaseModel {
|
||||
|
||||
if($name == "links") {
|
||||
$this->links = ContractLinkModel::includesContractId($this->id, ["type" => $link]);
|
||||
//var_dump($this->links);exit;
|
||||
return $this->links;
|
||||
}
|
||||
|
||||
|
||||
@@ -172,6 +172,13 @@ class ContractModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("billingaddress_id", $filter)) {
|
||||
$billingaddress_id = $filter['billingaddress_id'];
|
||||
if(is_numeric($billingaddress_id)) {
|
||||
$where .= " AND Contract.billingaddress_id=$billingaddress_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("product_id", $filter)) {
|
||||
$product_id = $filter['product_id'];
|
||||
if(is_numeric($product_id)) {
|
||||
|
||||
@@ -27,13 +27,13 @@ class ContractconfigController extends mfBaseController {
|
||||
|
||||
$contract_id = $this->request->contract_id;
|
||||
if(!$contract_id) {
|
||||
$this->layout()->setFlash("Contract ID nicht gefunden.","danger");
|
||||
$this->layout()->setFlash("Contract ID nicht gefunden.","error");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
$contract = new Contract($contract_id);
|
||||
if(!$contract_id) {
|
||||
$this->layout()->setFlash("Contract ID nicht gefunden.","danger");
|
||||
$this->layout()->setFlash("Contract ID nicht gefunden.","error");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
@@ -44,6 +44,51 @@ class ContractconfigController extends mfBaseController {
|
||||
|
||||
$this->layout()->set("contract", $contract);
|
||||
$this->layout()->set("groups", $contract->configgroups);
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
$contract_id = $r->contract_id;
|
||||
|
||||
if(!is_numeric($contract_id) || $contract_id < 1) {
|
||||
$this->layout()->setFlash("Contract ID nicht gefunden.","error");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
if(!is_array($r->itemvalues) || !count($r->itemvalues)) {
|
||||
$this->layout()->setFlash("Keine Änderungen.","info");
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
$error_items = [];
|
||||
|
||||
foreach($r->itemvalues as $item_id => $itemvalue) {
|
||||
$item = new ContractconfigItem($item_id);
|
||||
if(!$item->id) {
|
||||
$this->log->warn("Tried to save non-existant ContractconfigItem $item_id");
|
||||
continue;
|
||||
}
|
||||
$item->setContractId($contract_id);
|
||||
if(!$item->value->set($itemvalue)) {
|
||||
$error_items[$item->id] = $item->name;
|
||||
continue;
|
||||
}
|
||||
if(!$item->value->save()) {
|
||||
$this->layout()->set("request", $r);
|
||||
$this->layout()->setFlash("Fehler beim Speichern von".$item->name,"info");
|
||||
return $this->editAction();
|
||||
}
|
||||
}
|
||||
|
||||
if(count($error_items)) {
|
||||
$this->layout()->set("error_items", array_keys($error_items));
|
||||
$this->layout()->set("request", $r);
|
||||
$this->layout()->setFlash("Konfiguration nicht vollständig gespeichert. Fehler in folgenden Feldern:\n<br />".implode(", ", $error_items), "warning");
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Konfiguration gespeichert", "success");
|
||||
$this->redirect("Contract", "view", ['id' => $contract_id]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -12,14 +12,52 @@ class ContractconfigItem extends mfBaseModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getValue() {
|
||||
$value = $this->getProperty("value");
|
||||
if(!$value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($this->type == "int") {
|
||||
return $value->int;
|
||||
}
|
||||
if($this->type == "decimal") {
|
||||
return $value->number;
|
||||
}
|
||||
|
||||
return $value->string;
|
||||
}
|
||||
|
||||
public function getTypedataArray() {
|
||||
if(!$this->typedata) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return explode("\n", $this->typedata);
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($name == "value") {
|
||||
if(!$this->contract_id) {
|
||||
return null;
|
||||
}
|
||||
$this->value = ContractconfigValueModel::getFirst(['item_id' => $this->id, "contract_id" => $this->contract_id]);
|
||||
$value = ContractconfigValueModel::getFirst(['item_id' => $this->id, "contract_id" => $this->contract_id]);
|
||||
if(!$value) {
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$value = new ContractconfigValue();
|
||||
$value->item_id = $this->id;
|
||||
$value->contract_id = $this->contract_id;
|
||||
$value->create_by = $me->id;
|
||||
}
|
||||
|
||||
$this->value = $value;
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class ContractconfigItemController extends mfBaseController {
|
||||
break;
|
||||
case "enum":
|
||||
$item_data['type'] = "enum";
|
||||
$item_data['typedata'] = $r->data;
|
||||
$item_data['typedata'] = preg_replace(['/\n{2,}/','/^\n+/','/\n+$/'], ["\n",'',''], str_replace("\r","\n",$r->data));
|
||||
break;
|
||||
case "int":
|
||||
$item_data['type'] = "int";
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
class ContractconfigItemModel {
|
||||
public $order;
|
||||
public $contractconfiggroup_id;
|
||||
public $ype;
|
||||
public $type;
|
||||
public $name;
|
||||
public $displayname;
|
||||
public $description;
|
||||
@@ -16,7 +16,7 @@ class ContractconfigItemModel {
|
||||
public $edit = null;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
public static function create(Array $data) {
|
||||
$model = new ContractconfigItem();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
|
||||
@@ -1,5 +1,63 @@
|
||||
<?php
|
||||
|
||||
class ContractconfigValue extends mfBaseModel {
|
||||
private $item;
|
||||
|
||||
public function set($new_value) {
|
||||
$item = $this->getProperty("item");
|
||||
|
||||
if($new_value === null || strlen($new_value) == 0) {
|
||||
$this->int = null;
|
||||
$this->number = null;
|
||||
$this->string = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
if($item->type == "int") {
|
||||
if(!is_numeric($new_value)) return false;
|
||||
$this->int = $new_value;
|
||||
} elseif($item->type == "decimal") {
|
||||
if(!is_float($new_value) && !is_numeric($new_value)) return false;
|
||||
$this->number = $new_value;
|
||||
} elseif(is_scalar($new_value)) {
|
||||
$this->string = $new_value;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->edit_by = $me->id;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($name == "item") {
|
||||
$this->item = new ContractconfigItem($this->item_id);
|
||||
if(!$this->item->id) {
|
||||
return null;
|
||||
}
|
||||
return $this->item;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
if($this->$name->id) {
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
||||
@@ -77,9 +77,6 @@ class ProductgroupController extends mfBaseController {
|
||||
$this->layout()->setFlash("Produktgruppe nicht gefunden", "error");
|
||||
$this->redirect("Productgroup");
|
||||
}
|
||||
} else {
|
||||
$mode = "add";
|
||||
$group = new Productgroup();
|
||||
}
|
||||
|
||||
$name = trim($r->name);
|
||||
@@ -88,7 +85,14 @@ class ProductgroupController extends mfBaseController {
|
||||
$this->redirect("Productgroup");
|
||||
}
|
||||
|
||||
$group->name = $r->name;
|
||||
$group_data = [];
|
||||
$group_data['name'] = $name;
|
||||
|
||||
if($mode == "edit") {
|
||||
$group->update($group_data);
|
||||
} else {
|
||||
$group = ProductgroupModel::create(['name' => $name]);
|
||||
}
|
||||
$id = $group->save();
|
||||
|
||||
if(!$id) {
|
||||
|
||||
Reference in New Issue
Block a user