More Contract stuff
This commit is contained in:
@@ -10,12 +10,100 @@ class Contract extends mfBaseModel {
|
||||
private $contractConfigGroups;
|
||||
private $contractConfigItems;
|
||||
private $configgroups;
|
||||
private $links;
|
||||
private $linkFrom;
|
||||
private $linkTo;
|
||||
private $upgradeFrom;
|
||||
private $upgradeTo;
|
||||
private $downgradeFrom;
|
||||
private $downgradeTo;
|
||||
private $productchangeFrom;
|
||||
private $productchangeTo;
|
||||
private $relocationFrom;
|
||||
private $relocationTo;
|
||||
private $finisher;
|
||||
private $canceler;
|
||||
private $creator;
|
||||
private $editor;
|
||||
|
||||
|
||||
private function getLinks() {
|
||||
$this->linkFrom = [];
|
||||
$this->linkTo = [];
|
||||
$this->upgradeFrom = [];
|
||||
$this->upgradeTo = [];
|
||||
$this->downgradeFrom = [];
|
||||
$this->downgradeTo = [];
|
||||
$this->productchangeFrom = [];
|
||||
$this->productchangeTo = [];
|
||||
$this->relocationFrom = [];
|
||||
$this->relocationTo = [];
|
||||
|
||||
// Links targeting this contract (to)
|
||||
foreach(ContractLinkModel::search(['origin_contract_id' => $this->id]) as $link) {
|
||||
switch($link->type) {
|
||||
case "link":
|
||||
$this->linkTo[] = $link;
|
||||
break;
|
||||
case "upgrade":
|
||||
$this->upgradeTo[] = $link;
|
||||
break;
|
||||
case "downgrade":
|
||||
$this->downgradeTo[] = $link;
|
||||
break;
|
||||
case "productchange":
|
||||
$this->productchangeTo[] = $link;
|
||||
break;
|
||||
case "relocation":
|
||||
$this->relocationTo[] = $link;
|
||||
break;
|
||||
default:
|
||||
$this->log->warn("ContractLink with invalid type: ".$link->id." ".$link->type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach(ContractLinkModel::search(['contract_id' => $this->id]) as $link) {
|
||||
switch($link->type) {
|
||||
case "link":
|
||||
$this->linkFrom[] = $link;
|
||||
break;
|
||||
case "upgrade":
|
||||
$this->upgradeFrom[] = $link;
|
||||
break;
|
||||
case "downgrade":
|
||||
$this->downgradeFrom[] = $link;
|
||||
break;
|
||||
case "productchange":
|
||||
$this->productchangeFrom[] = $link;
|
||||
break;
|
||||
case "relocation":
|
||||
$this->relocationFrom[] = $link;
|
||||
break;
|
||||
default:
|
||||
$this->log->warn("ContractLink with invalid type: ".$link->id." ".$link->type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*$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;
|
||||
}
|
||||
}
|
||||
if(count($this->links)) {
|
||||
mfValuecache::singleton()->set("ContractLinks-origin-".$this->id, $this->links);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
@@ -96,6 +184,18 @@ class Contract extends mfBaseModel {
|
||||
return $this->contractConfigItems;
|
||||
}
|
||||
|
||||
if($name == "links") {
|
||||
$this->links = ContractLinkModel::includesContractId($this->id, ["type" => $link]);
|
||||
return $this->links;
|
||||
}
|
||||
|
||||
if(in_array($name, ['linkFrom','linkTo','upgradeFrom','upgradeTo','downgradeFrom','downgradeTo','productchangeFrom','productchangeTo','relocationFrom','relocationTo'])) {
|
||||
if($this->$name === null) {
|
||||
$this->getLinks();
|
||||
}
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
if($name == "finisher") {
|
||||
$this->finisher = mfValuecache::singleton()->get("Worker-id-".$this->finish_date_by);
|
||||
if($this->finisher === null) {
|
||||
|
||||
@@ -47,6 +47,14 @@ class ContractController extends mfBaseController {
|
||||
private function getPreparedFilter($filter) {
|
||||
$new_filter = [];
|
||||
|
||||
if(array_key_exists("show_canceled", $filter)) {
|
||||
if($filter['show_canceled'] == 0) {
|
||||
$new_filter['add-where'] = " AND (cancel_date IS NULL OR cancel_date > UNIX_TIMESTAMP())";
|
||||
}
|
||||
} else {
|
||||
$new_filter['add-where'] = " AND (cancel_date IS NULL OR cancel_date > UNIX_TIMESTAMP())";
|
||||
}
|
||||
|
||||
if(is_array($filter) && count($filter)) {
|
||||
foreach($filter as $name => $value) {
|
||||
$new_filter[$name] = $value;
|
||||
@@ -198,7 +206,8 @@ class ContractController extends mfBaseController {
|
||||
$this->layout()->setFlash("Vertrag erfolgreich gespeichert.", "success");
|
||||
|
||||
|
||||
|
||||
/* ContractLinks */
|
||||
|
||||
|
||||
$query = [];
|
||||
if($r->s) {
|
||||
|
||||
@@ -201,6 +201,13 @@ class ContractModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("customer_number", $filter)) {
|
||||
$customer_number = $filter['customer_number'];
|
||||
if(is_numeric($customer_number)) {
|
||||
$where .= " AND Address.customer_number=$customer_number";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("owner", $filter)) {
|
||||
$owner = FronkDB::singleton()->escape($filter["owner"]);
|
||||
if($owner) {
|
||||
@@ -208,6 +215,10 @@ class ContractModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("add-where", $filter)) {
|
||||
$where .= " ".$filter['add-where'];
|
||||
}
|
||||
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
|
||||
Reference in New Issue
Block a user