Contractqueue: commit to Contract finished

This commit is contained in:
Frank Schubert
2024-04-18 22:58:37 +02:00
parent b9f270fb10
commit e388c6e066
12 changed files with 932 additions and 721 deletions
+1 -1
View File
@@ -377,7 +377,7 @@
*/
<?php if($contract->product_id && is_object(($contract->product))): ?>
$('#product_id').autoComplete('set', { value: <?=$contract->product_id?>, text: '<?=($contract->product_id) ? str_replace("'", "\\'", str_replace(["\n", "\r"], " ", $contract->product->name))." [".$contract->product_id."]" : ""?>'});
<?php if(array_key_exists("termination_required", $contract->product) && $contract->product->attributes["termination_required"] != 1): ?>
<?php if(array_key_exists("termination_required", $contract->product->attributes) && $contract->product->attributes["termination_required"] != 1): ?>
$("#termination_row").hide();
<?php endif; ?>
<?php else: ?>
+13 -6
View File
@@ -64,6 +64,13 @@
</select>
</div>
<div class="col-2">
<label class="form-label" for="filter_show_credit">Gutschriften</label>
<select class="form-control" name="filter[show_credit]" id="filter_show_credit">
<option value="0" <?=($filter['show_credit'] == 0) ? "selected='selected'" : ""?>>Ausblenden</option>
<option value="1" <?=($filter['show_credit'] == 1 ) ? "selected='selected'" : ""?>>Anzeigen</option>
</select>
</div>
</div>
<div class="row mt-2">
<div class="col">
@@ -110,8 +117,8 @@
<tr>
<td><a href="<?=self::getUrl("Contract", "view", ["contract_id" => $contract->id])?>"><?=$contract->id?></a></td>
<td><a href="<?=self::getUrl("Address", "View", ["id" => $contract->owner_id])?>" target="_blank"><i class="far fa-eyes" title="Kunde in neuem Tab anzeigen"></i></a> <?=$contract->owner->getCompanyOrName()?> (<?=$contract->owner->customer_number?>)</td>
<td><a href="<?=self::getUrl("Contract", "view", ["contract_id" => $contract->id])?>"><?=$contract->product_name?></a></td>
<td><a href="<?=self::getUrl("Contract", "view", ["contract_id" => $contract->id])?>"><?=$contract->matchcode?></a></td>
<td class="<?=($contract->isCancelled()) ? "canceled" : "" ?> <?=(!$contract->isFinished()) ? "not-finished" : "" ?>"><a href="<?=self::getUrl("Contract", "view", ["contract_id" => $contract->id])?>"><?=$contract->product_name?></a></td>
<td class="<?=($contract->isCancelled()) ? "canceled" : "" ?> <?=(!$contract->isFinished()) ? "not-finished" : "" ?>"><a href="<?=self::getUrl("Contract", "view", ["contract_id" => $contract->id])?>"><?=$contract->matchcode?></a></td>
<!--<td>
<?php if($contract->termination_id): ?>
<?=$contract->termination->building->street?><br />
@@ -121,9 +128,9 @@
</a>
<?php endif; ?>
</td>-->
<td><?=$contract->price?></td>
<td><?=$contract->price_setup?></td>
<td>
<td class="<?=($contract->isCancelled()) ? "canceled" : "" ?> <?=(!$contract->isFinished()) ? "not-finished" : "" ?> <?=($contract->price < 0) ? "text-danger" : ""?>"><?=$contract->price?></td>
<td class="<?=($contract->isCancelled()) ? "canceled" : "" ?> <?=(!$contract->isFinished()) ? "not-finished" : "" ?> <?=($contract->price_setup < 0) ? "text-danger" : ""?>"><?=$contract->price_setup?></td>
<td class="<?=($contract->isCancelled()) ? "canceled" : "" ?> <?=(!$contract->isFinished()) ? "not-finished" : "" ?>">
<?php if($contract->billing_period == 1): ?>
monatlich
<?php elseif($contract->billing_period == 24): ?>
@@ -134,7 +141,7 @@
<?=(12 / $contract->billing_period)?>x Jährlich
<?php endif; ?>
</td>
<td class="text-monospace"><?=($contract->finish_date) ? date('d.m.Y', $contract->finish_date) : ""?></td>
<td class="text-monospace <?=(!$contract->isFinished()) ? "not-finished" : "" ?>"><?=($contract->finish_date) ? date('d.m.Y', $contract->finish_date) : ""?></td>
<td class="text-monospace"><?=($contract->cancel_date) ? date('d.m.Y', $contract->cancel_date) : ""?></td>
<td class="text-monospace"><?=date('d.m.Y H:i', $contract->create)?><br /><?=$contract->creator->name?></td>
<td class="text-monospace"><?=date('d.m.Y H:i', $contract->edit)?><br /><?=$contract->editor->name?></td>
+33 -5
View File
@@ -165,7 +165,7 @@
<?php if((is_array($contract->linkFrom) && count($contract->linkFrom)) || (is_array($contract->linkTo) && count($contract->linkTo))): ?>
<h4>Verknüpfte Verträge</h4>
<table class="table table-striped table-sm table-bordered table-hover">
<table class="table table-striped table-sm table-bordered table-hover" id="link-table">
<tr>
<th title="Verlinkten Contract mit neuem Contract verknüpfen">Übernehmen</th>
<th title="Verlinkten Contract mit altem Contract zusammen kündigen">Kündigen</th>
@@ -177,7 +177,7 @@
<th>Fertigstellung</th>
<th>Kündigung</th>
</tr>
<?php foreach($contract->links as $link): ?>
<?php foreach($contract->linksWithCredit as $link): ?>
<?php
if($link->contract_id == $contract->id) {
@@ -188,9 +188,14 @@
}
?>
<tr>
<td><input type="radio" class="form-check" id="link-<?=$link->id?>-action-keep" name="links[<?=$link->id?>]" value="keep" <?=($linkcontract->cancel_date && $linkcontract->cancel_date < date('U')) ? "" : "checked='checked'"?> /></td>
<td><input type="radio" class="form-check" id="link-<?=$link->id?>-action-cancel" name="links[<?=$link->id?>]" value="cancel" /></td>
<tr data-link-type="<?=$link->type?>">
<td>
<input type="radio" class="form-check link-keep" id="link-<?=$link->id?>-action-keep" name="links[<?=$link->id?>]" value="keep" <?=($linkcontract->cancel_date && $linkcontract->cancel_date < date('U')) ? "" : "checked='checked'"?> />
<?php if($link->type == "credit"): ?>
(Gutschrift wird neu erstellt)
<?php endif; ?>
</td>
<td><input type="radio" class="form-check link-cancel" id="link-<?=$link->id?>-action-cancel" name="links[<?=$link->id?>]" value="cancel" /></td>
<td><a href="<?=self::getUrl("Address", "View", ["id" => $linkcontract->owner_id])?>" target="_blank"><?=$linkcontract->owner->getCompanyOrName()?></a></td>
<td class="contract <?=($linkcontract->isCancelled()) ? "canceled" : ""?>"><a href="<?=self::getUrl("Contract", "View", ["contract_id" => $linkcontract->id])?>" target="_blank"><?=$linkcontract->id?></a></td>
<td class="contract <?=($linkcontract->isCancelled()) ? "canceled" : ""?>"><a href="<?=self::getUrl("Contract", "View", ["contract_id" => $linkcontract->id])?>" target="_blank"><?=$linkcontract->product_name?></a></td>
@@ -307,6 +312,29 @@
//$('#termination_id-' + id + '-line').hide();
}
// set credit-link to cancel if new product does not need credit
const attrib = p.attributes;
let crediting_partner = false;
let crediting_rate = 0;
if(crediting_partner in p.attributes) {
crediting_partner = parseInt(p.attributes.crediting_partner);
}
if(crediting_rate in p.attributes) {
crediting_rate = parseFloat(p.attributes.crediting_rate);
}
let price_nne = parseFloat(p.price_nne);
//console.log(p.price_nne, crediting_partner, crediting_rate);
if(price_nne || (crediting_partner && crediting_rate)) {
$("#link-table tr[data-link-type='credit'] input.link-keep").prop("checked", "checked");
}
if(!price_nne && (!crediting_partner || !crediting_rate)) {
$("#link-table tr[data-link-type='credit'] input.link-cancel").prop("checked", "checked");
}
},
'json');
+17 -6
View File
@@ -29,12 +29,17 @@
<div class="card border-top-success">
<div class="card-body">
<?php if(!$contract->finish_date || $contract->finish_date > date('U')): ?>
<?php if(!$contract->isFinished()): ?>
<h2 class="text-center mb-3 text-secondary">In Herstellung</h2>
<?php endif; ?>
<?php if($contract->isCancelled()): ?>
<h2 class="text-center mb-3 text-danger">GEKÜNDIGT</h2>
<?php endif; ?>
<?php if(str_contains(strtolower($contract->sla->name), "residential")): ?>
<h2 class="text-center mb-3 text-danger">Privatprodukt</h2>
<?php else: ?>
<h2 class="text-center mb-3 text-primary">Businessprodukt</h2>
<?php endif; ?>
<h3 class="text-center mb-3 <?=($contract->isCancelled()) ? "canceled" : ""?>"><?=$contract->product_name?> [<?=$contract->id?>]</h3>
<table class="table table-sm table-striped view-table">
@@ -232,7 +237,13 @@
<td style="white-space: nowrap" class="text-monospace"><?=date("d.m.Y H:i", $j->create)?> (<?=$j->creator?>)</td>
<?php if($j->type == "text" || $j->type == "phone"):?>
<td><i class="fas <?=($j->type == "text") ? "fa-align-left bg-success" : "fa-phone bg-success"?> text-white p-1"></i></td>
<td>
<?php if($j->type == "text"): ?>
<i class="fas fa-align-left bg-warning text-white p-1" title="Kommentar"></i>
<?php else: ?>
<i class="fas fa-phone bg-warning text-white p-1" title="Anruf"></i>
<?php endif; ?>
</td>
<?php if(strlen($j->text) > 120): ?>
<td style="width: 100%" class="pointer" onclick="toggleTruncatedJournalText(<?=$j->id?>)">
<span id="truncated-<?=$j->id?>"><i class="fas fa-caret-right"></i> <?=self::strtrim(str_replace(["\n", "\r", "\t"]," ", $j->text), 120)?></span>
@@ -246,7 +257,7 @@
</td>
<?php elseif($j->type == "file"): ?>
<td><i class="fas fa-download bg-primary text-white p-1"></i></td>
<td><i class="fas fa-download bg-primary text-white p-1" title="Dateiupload"></i></td>
<td style="width: 100%">
<?php if($j->text): ?>
<?=self::strtrim(str_replace(["\n", "\r", "\t"]," ", $j->text), 128)?><br />
@@ -262,7 +273,7 @@
<?php elseif($j->value == "import"): ?>
<em>Vertrag importiert: <?=nl2br(htmlentities($j->text))?>
<?php elseif($j->value == "order"): ?>
<em>Vertrag aus Bestellung #<a href="<?=self::getUrl("Order", "edit", ["id" => $contract->orderproduct->order_id])?>"><?=$contract->orderproduct->order_id?></a> erstellt
<em>Vertrag aus Bestellung <a href="<?=self::getUrl("Order", "edit", ["id" => $contract->orderproduct->order_id])?>">#<?=$contract->orderproduct->order_id?></a> erstellt
<?php endif; ?>
</td>
<?php elseif($j->type == "credit_created"): ?>
@@ -344,7 +355,7 @@
$direction = "von";
$linkcontract = $link->origin;
if($link->type == "credit") {
$direction = "";
$direction = "zu";
//continue;
}
} else {
@@ -356,7 +367,7 @@
$direction = "nach";
}
if($link->type == "credit") {
$direction = "zu";
$direction = "";
//continue;
}
+27 -7
View File
@@ -526,7 +526,7 @@ class Address extends mfBaseModel {
if($name == "permissions") {
$this->permissions = NetworkAddressModel::search(['address_id' => $this->id]);
return $permissions;
return $this->permissions;
}
if($name == "parent") {
@@ -540,16 +540,36 @@ class Address extends mfBaseModel {
}
if($name == "contracts") {
$owning = ContractModel::search(['owner_id' => $this->id]);
$billing = ContractModel::search(['billingaddress_id' => $this->id]);
$this->contracts = array_merge($owning, $billing);
$contracts = [];
foreach(ContractModel::search(['owner_id' => $this->id]) as $contract) {
if(!array_key_exists($contract->id, $contracts)) {
$contracts[$contract->id] = $contract;
}
}
foreach(ContractModel::search(['billingaddress_id' => $this->id]) as $contract) {
if(!array_key_exists($contract->id, $contracts)) {
$contracts[$contract->id] = $contract;
}
}
$this->contracts = $contracts;
return $this->contracts;
}
if($name == "active_contracts") {
$owning = ContractModel::searchActive(['owner_id' => $this->id]);
$billing = ContractModel::searchActive(['billingaddress_id' => $this->id]);
$this->contracts = array_merge($owning, $billing);
$contracts = [];
foreach(ContractModel::searchActive(['owner_id' => $this->id]) as $contract) {
if(!array_key_exists($contract->id, $contracts)) {
$contracts[$contract->id] = $contract;
}
}
foreach(ContractModel::searchActive(['billingaddress_id' => $this->id]) as $contract) {
if(!array_key_exists($contract->id, $contracts)) {
$contracts[$contract->id] = $contract;
}
}
$this->contracts = $contracts;
return $this->contracts;
}
+25
View File
@@ -16,6 +16,7 @@ class Contract extends mfBaseModel {
private $isCancelled;
private $journals;
private $links;
private $linksWithCredit;
private $linkFrom;
private $linkTo;
private $upgradeFrom;
@@ -117,6 +118,24 @@ class Contract extends mfBaseModel {
return false;
}
public function isFinished() {
if(!$this->id) {
return false;
}
$now = date('U');
if($this->finish_date && $this->finish_date <= $now) {
return true;
}
if($this->cancel_date && $this->cancel_date <= $now) {
return true;
}
return false;
}
public function generateMatchcode() {
$owner_address = $this->getProperty("owner")->street.", ".$this->getProperty("owner")->zip." ".$this->getProperty("owner")->city;
@@ -271,6 +290,12 @@ class Contract extends mfBaseModel {
return $this->links;
}
if($name == "linksWithCredit") {
$this->linksWithCredit = ContractLinkModel::includesContractId($this->id, ["type" => ["link", "credit"]]);
//var_dump($this->links);exit;
return $this->linksWithCredit;
}
if(in_array($name, ['linkFrom','linkTo','upgradeFrom','upgradeTo','downgradeFrom','downgradeTo','productchangeFrom','productchangeTo','relocationFrom','relocationTo'])) {
if($this->$name === null) {
$this->getLinks();
+159 -116
View File
@@ -1,34 +1,37 @@
<?php
class ContractController extends mfBaseController {
class ContractController extends mfBaseController
{
protected function init() {
$this->needlogin=true;
protected function init()
{
$this->needlogin = true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me",$me);
$this->layout()->set("me", $me);
if(!$me->is(["Admin"])) {
if (!$me->is(["Admin"])) {
$this->redirect("Dashboard");
}
}
protected function indexAction() {
protected function indexAction()
{
$this->layout()->setTemplate("Contract/Index");
if($this->request->resetFilter) {
unset($_SESSION[MFAPPNAME.'-Contract-filter']);
if ($this->request->resetFilter) {
unset($_SESSION[MFAPPNAME . '-Contract-filter']);
}
$filter = [];
if(is_array($this->request->filter)) {
if (is_array($this->request->filter)) {
$filter = $this->request->filter;
$_SESSION[MFAPPNAME.'-Contract-filter'] = $filter;
$_SESSION[MFAPPNAME . '-Contract-filter'] = $filter;
} else {
if(array_key_exists(MFAPPNAME.'-Contract-filter', $_SESSION) && count($_SESSION[MFAPPNAME.'-Contract-filter'])) {
$filter = $_SESSION[MFAPPNAME.'-Contract-filter'];
if (array_key_exists(MFAPPNAME . '-Contract-filter', $_SESSION) && count($_SESSION[MFAPPNAME . '-Contract-filter'])) {
$filter = $_SESSION[MFAPPNAME . '-Contract-filter'];
}
}
@@ -41,7 +44,7 @@ class ContractController extends mfBaseController {
$pagination['count'] = 50;
$pagination['maxItems'] = 0;
if(is_numeric($this->request->s)) {
if (is_numeric($this->request->s)) {
$pagination['start'] = intval($this->request->s);
}
//var_dump($filter);exit;
@@ -52,19 +55,29 @@ class ContractController extends mfBaseController {
$this->layout()->set("pagination", $pagination);
}
private function getPreparedFilter($filter) {
private function getPreparedFilter($filter)
{
$new_filter = [];
if(array_key_exists("show_canceled", $filter)) {
if($filter['show_canceled'] == 0) {
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) {
if (array_key_exists("show_credit", $filter)) {
if ($filter["show_credit"] == 0) {
$new_filter["price>="] = 0;
}
unset($filter["show_credit"]);
} else {
$new_filter["price>="] = 0;
}
if (is_array($filter) && count($filter)) {
foreach ($filter as $name => $value) {
$new_filter[$name] = $value;
}
}
@@ -72,49 +85,51 @@ class ContractController extends mfBaseController {
return $new_filter;
}
protected function viewAction() {
protected function viewAction()
{
$this->layout()->setTemplate("Contract/View");
$id = $this->request->contract_id;
if(!$id) {
if (!$id) {
$id = $this->request->id;
}
if(!is_numeric($id) || !$id) {
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
$this->redirect("Contract");
}
$contract = new Contract($id);
if(!$contract->id) {
if (!$contract->id) {
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
$this->redirect("Contract");
}
$this->layout()->set("contract", $contract);
if($this->request->filter) {
if ($this->request->filter) {
$this->layout()->set("filter", $this->request->filter);
}
if($this->request->s) {
if ($this->request->s) {
$this->layout()->set("filter", $this->request->s);
}
}
protected function productchangeAction() {
protected function productchangeAction()
{
$this->layout()->setTemplate("Contract/ProductchangeForm");
$id = $this->request->contract_id;
if(!$id) {
if (!$id) {
$id = $this->request->id;
}
if(!is_numeric($id) || !$id) {
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
$this->redirect("Contract");
}
$contract = new Contract($id);
if(!$contract->id) {
if (!$contract->id) {
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
$this->redirect("Contract");
}
@@ -122,25 +137,26 @@ class ContractController extends mfBaseController {
$this->layout()->set("contract", $contract);
$this->layout()->set("terminations", TerminationModel::getAll());
if($this->request->filter) {
if ($this->request->filter) {
$this->layout()->set("filter", $this->request->filter);
}
if($this->request->s) {
if ($this->request->s) {
$this->layout()->set("filter", $this->request->s);
}
}
protected function saveProductchangeAction() {
protected function saveProductchangeAction()
{
$r = $this->request;
$id = $r->contract_id;
if(!is_numeric($id) || !$id) {
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
$this->redirect("Contract");
}
$contract = new Contract($id);
if(!$contract->id) {
if (!$contract->id) {
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
$this->redirect("Contract");
}
@@ -165,7 +181,7 @@ class ContractController extends mfBaseController {
* termination check
*/
$product = new Product($r->product_id);
if(!$product->id) {
if (!$product->id) {
$this->layout()->setFlash("Produkt nicht gefunden", "error");
$this->redirect("Contract", "productchange", ["contract_id" => $id]);
}
@@ -175,12 +191,12 @@ class ContractController extends mfBaseController {
$contract_data['sla_id'] = $product->sla_id;
$require_term = false;
if(array_key_exists(TT_ATTRIB_TERMINATION_REQUIRED_NAME, $product->attributes) && $product->attributes[TT_ATTRIB_TERMINATION_REQUIRED_NAME]->value == 1) {
if (array_key_exists(TT_ATTRIB_TERMINATION_REQUIRED_NAME, $product->attributes) && $product->attributes[TT_ATTRIB_TERMINATION_REQUIRED_NAME]->value == 1) {
//var_dump($prod->attributes);
$require_term = true;
$termination = new Termination($contract_data['termination_id']);
if(!$contract_data['termination_id'] || !$termination->id) {
if (!$contract_data['termination_id'] || !$termination->id) {
$this->layout()->setFlash("Produkt erfordert Anschluss.", "error");
$this->redirect("Contract", "productchange", ["contract_id" => $id]);
}
@@ -192,24 +208,22 @@ class ContractController extends mfBaseController {
$new_contract->update($contract_data);
$new_contract_id = $new_contract->save();
if(!$new_contract_id) {
if (!$new_contract_id) {
$this->layout()->setFlash("Neuer Contract konnte nicht gespeichert werden", "error");
$this->redirect("Contract", "productchange", ["contract_id" => $id]);
}
if(is_array($r->links) && count($r->links)) {
foreach($r->links as $link_id => $action) {
if (is_array($r->links) && count($r->links)) {
foreach ($r->links as $link_id => $action) {
$old_link = new ContractLink($link_id);
if(!$old_link->id) continue;
$new_link_origin_id = 0;
$new_link_origin_id = 0;
if (!$old_link->id) continue;
// check if link contains this contract
if($old_link->contract_id == $contract->id) {
if ($old_link->contract_id == $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) {
} elseif ($old_link->origin_contract_id == $contract->id) {
$new_link_contract_id = $old_link->contract_id;
$new_link_origin_id = $new_contract->id;
} else {
@@ -221,17 +235,21 @@ class ContractController extends mfBaseController {
'origin_contract_id' => $new_link_origin_id,
'type' => $old_link->type,
]);
if(!$new_link->save()) {
if (!$new_link->save()) {
$this->layout()->setFlash("Konnte neuen Link nicht speichern", "warn");
}
if($action == "cancel") {
if ($action == "cancel") {
$old_link->change_action = "cancel";
if(!$old_link->save()) {
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";
}
//var_dump($new_link);exit;
}
}
@@ -255,7 +273,7 @@ class ContractController extends mfBaseController {
]);
$link_id = $link->save();
if(!$link_id) {
if (!$link_id) {
$this->layout()->setFlash("Konnte Verknüpfung nicht speichern", "warn");
}
@@ -263,20 +281,20 @@ class ContractController extends mfBaseController {
$this->redirect("Contract", "view", ["contract_id" => $new_contract_id]);
}
protected function finishContractAction() {
protected function finishContractAction()
{
$r = $this->request;
$id = $r->contract_id;
if(!is_numeric($id) || !$id) {
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Contract nicht gefunden", "error");
$this->redirect("Contract");
}
$contract = new Contract($id);
if(!$contract->id) {
if (!$contract->id) {
$this->layout()->setFlash("Contract nicht gefunden", "error");
$this->redirect("Contract");
}
@@ -286,8 +304,8 @@ class ContractController extends mfBaseController {
/*
* Vorgänger Contracts kündigen
*/
foreach(ContractLinkModel::search(['contract_id' => $id]) as $link) {
if(!in_array($link->type, ["upgrade","downgrade","relocation","productchange"])) {
foreach (ContractLinkModel::search(['contract_id' => $id]) as $link) {
if (!in_array($link->type, ["upgrade", "downgrade", "relocation", "productchange"])) {
continue;
}
@@ -295,16 +313,16 @@ class ContractController extends mfBaseController {
$origin->cancel_date = $now;
$origin->cancel_date_by = $this->me->id;
$origin->edit_by = $this->me->id;
if(!$origin->save()) {
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) {
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) {
if ($old_link->change_action == "cancel" && !$old_link->contract->cancel_date) {
$old_link->origin->update([
'cancel_date' => $now,
'cancel_date_by' => $this->me->id,
@@ -317,9 +335,9 @@ class ContractController extends mfBaseController {
}
}
foreach(ContractLinkModel::search(['type' => "link", 'origin_contract_id' => $origin->id] ) as $old_link) {
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) {
if ($old_link->change_action == "cancel" && !$old_link->contract->cancel_date) {
$old_link->contract->update([
'cancel_date' => $now,
'cancel_date_by' => $this->me->id,
@@ -332,13 +350,31 @@ class ContractController extends mfBaseController {
}
}
/*
* TODO: alten Credit Vertag kündigen und neuen anlegen
*/
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();
}
}
}
$contract->finish_date = $now;
$contract->finish_date_by = $this->me->id;
if(!$contract->save()) {
if (!$contract->save()) {
$this->layout()->setFlash("Contract konnte nicht gespeichert werden", "error");
$this->redirect("Contract", "view", ['contract_id' => $id]);
}
@@ -352,25 +388,27 @@ class ContractController extends mfBaseController {
}
protected function cancelAction() {
protected function cancelAction()
{
$id = $this->request->contract_id;
if(!$id) $id = $this->request->id;
if (!$id) $id = $this->request->id;
$this->layout()->setFlash("Not implemented", "error");
if($id) {
$this->redirect("Contract","view",["id" => $id]);
if ($id) {
$this->redirect("Contract", "view", ["id" => $id]);
} else {
$this->redirect("Contract");
}
}
protected function addAction() {
protected function addAction()
{
$this->layout()->setTemplate("Contract/Form");
$this->layout()->set("terminations", TerminationModel::getAll());
if($this->request->origin_contract_id) {
if ($this->request->origin_contract_id) {
$origin = new Contract($this->request->origin_contract_id);
if($origin->id) {
if ($origin->id) {
$contract = new Contract();
$contract->owner_id = $origin->owner_id;
$contract->billingaddress_id = $origin->billingaddress_id;
@@ -382,18 +420,19 @@ class ContractController extends mfBaseController {
}
}
protected function editAction() {
protected function editAction()
{
$id = $this->request->contract_id;
if(!$id) {
if (!$id) {
$id = $this->request->id;
}
if(!is_numeric($id) || !$id) {
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
$this->redirect("Contract");
}
$contract = new Contract($id);
if(!$contract->id) {
if (!$contract->id) {
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
$this->redirect("Contract");
}
@@ -401,20 +440,21 @@ class ContractController extends mfBaseController {
$this->layout()->set("contract", $contract);
//var_dump($contract->owner);exit;
if($this->request->f == "view") $this->layout()->set("f", "view");
if($this->request->f != "view") $this->layout()->set("f", "index");
if ($this->request->f == "view") $this->layout()->set("f", "view");
if ($this->request->f != "view") $this->layout()->set("f", "index");
if($this->request->filter) {
if ($this->request->filter) {
$this->layout()->set("filter", $this->request->filter);
}
if($this->request->s) {
if ($this->request->s) {
$this->layout()->set("filter", $this->request->s);
}
return $this->addAction();
}
protected function saveAction() {
protected function saveAction()
{
$r = $this->request;
//var_dump($r);
@@ -422,10 +462,10 @@ class ContractController extends mfBaseController {
* add or edit
*/
$id = $r->id;
if(is_numeric($id) && $id > 0) {
if (is_numeric($id) && $id > 0) {
$mode = "edit";
$contract = new Contract($id);
if(!$contract->id) {
if (!$contract->id) {
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
$this->redirect("Contract");
}
@@ -457,7 +497,7 @@ class ContractController extends mfBaseController {
//var_dump($contract_data);exit;
if($mode == "add") {
if ($mode == "add") {
$contract = ContractModel::create($contract_data);
} else {
$contract->update($contract_data);
@@ -465,22 +505,22 @@ class ContractController extends mfBaseController {
$this->layout()->set("contract", $contract);
if(!$contract_data["owner_id"]) {
if (!$contract_data["owner_id"]) {
$this->layout()->setFlash("Bitte Vertragsinhaber auswählen.", "error");
return $this->addAction();
}
if(!$contract_data["product_id"]) {
if (!$contract_data["product_id"]) {
$this->layout()->setFlash("Bitte Produkt auswählen.", "error");
return $this->addAction();
}
if(!$contract_data['billing_period']) {
if (!$contract_data['billing_period']) {
$this->layout()->setFlash("Bitte Rechnungsperiode auswählen.", "error");
return $this->addAction();
}
if(!$contract->product_name) {
if (!$contract->product_name) {
$product = new Product($contract_data["product_id"]);
if(!$product->id) {
if (!$product->id) {
$this->layout()->setFlash("Ungültiges Produkt.", "error");
return $this->addAction();
}
@@ -490,14 +530,14 @@ class ContractController extends mfBaseController {
//var_dump($contract);exit;
$contract_id = $contract->save();
if(!$contract_id) {
if (!$contract_id) {
$this->layout()->setFlash("Fehler beim Speichern.", "error");
$this->layout()->set("contract", $contract);
return $this->addAction();
}
// create journal
if($mode == "add") {
if ($mode == "add") {
$journal = ContractjournalModel::create([
'contract_id' => $contract_id,
'type' => "created_from",
@@ -511,16 +551,16 @@ class ContractController extends mfBaseController {
/*
* Create link to origin contract if set
*/
if($mode == "add" && $r->origin_contract_id) {
if ($mode == "add" && $r->origin_contract_id) {
$origin = new Contract($r->origin_contract_id);
if($origin->id) {
if ($origin->id) {
$link = ContractLinkModel::create([
'contract_id' => $contract_id,
'origin_contract_id' => $origin->id,
'type' => 'link'
]);
$link_id = $link->save();
if($link_id) {
if ($link_id) {
$journal = ContractjournalModel::create([
'contract_id' => $contract_id,
'type' => "link",
@@ -543,19 +583,19 @@ class ContractController extends mfBaseController {
$query = [];
if($r->s) {
if ($r->s) {
$query['s'] = $r->s;
}
if($r->filter) {
if ($r->filter) {
$query["filter"] = $r->filter;
}
if($r->return != "index") {
if ($r->return != "index") {
$query['id'] = $contract_id;
}
$qs = http_build_query($query);
if($mode == "add" || $r->f == "view") {
if ($mode == "add" || $r->f == "view") {
$this->redirect("Contract", "view", $qs, "contract=$contract_id");
} else {
$this->redirect("Contract", "Index", $qs);
@@ -563,14 +603,15 @@ class ContractController extends mfBaseController {
}
protected function apiAction() {
if(!$this->me->is(["Admin"])) {
protected function apiAction()
{
if (!$this->me->is(["Admin"])) {
$this->redirect("Dashboard");
}
$do = $this->request->do;
$data = [];
switch($do) {
switch ($do) {
case "getContract":
$return = $this->getContractApi();
break;
@@ -580,7 +621,7 @@ class ContractController extends mfBaseController {
$return = false;
}
if(!is_array($return) || !count($return)) {
if (!is_array($return) || !count($return)) {
$data = ["status" => "error"];
$this->returnJson($data);
}
@@ -589,19 +630,20 @@ class ContractController extends mfBaseController {
$this->returnJson($data);
}
private function getContractApi() {
private function getContractApi()
{
$contract_id = $this->request->contract_id;
if(!is_numeric($contract_id) || $contract_id < 1) {
if (!is_numeric($contract_id) || $contract_id < 1) {
return false;
}
$form_id = false;
if($this->request->form_id) {
if ($this->request->form_id) {
$form_id = $this->request->form_id;
}
$contract = new Contract($contract_id);
if(!$contract->id) {
if (!$contract->id) {
return false;
}
@@ -610,50 +652,51 @@ class ContractController extends mfBaseController {
return ["contract" => $data, "form_id" => $form_id];
}
private function findContractApi() {
private function findContractApi()
{
$search = trim($this->request->q);
$autocomplete = $this->request->autocomplete;
$contracts = [];
if(is_numeric($search)) {
if (is_numeric($search)) {
$c = new Contract($search);
if($c->id) {
if(!array_key_exists($c->id, $contracts)) {
if ($c->id) {
if (!array_key_exists($c->id, $contracts)) {
$contracts[$c->id] = $c;
}
}
foreach(["id", "owner_id", "product_id"] as $search_key) {
foreach(ContractModel::search([$search_key => $search]) as $c) {
if(!array_key_exists($c->id, $contracts)) {
foreach (["id", "owner_id", "product_id"] as $search_key) {
foreach (ContractModel::search([$search_key => $search]) as $c) {
if (!array_key_exists($c->id, $contracts)) {
$contracts[$c->id] = $c;
}
}
}
}
foreach(["product_name", "matchcode", "owner"] as $search_key) {
foreach(ContractModel::search([$search_key => $search]) as $c) {
if(!array_key_exists($c->id, $contracts)) {
foreach (["product_name", "matchcode", "owner"] as $search_key) {
foreach (ContractModel::search([$search_key => $search]) as $c) {
if (!array_key_exists($c->id, $contracts)) {
$contracts[$c->id] = $c;
}
}
}
if(!is_array($contracts) && !count($contracts)) {
if (!is_array($contracts) && !count($contracts)) {
return false;
}
$results = [];
// return bootstrap-autocomplete format
foreach($contracts as $contract) {
foreach ($contracts as $contract) {
//$result = ['value' => $contract->id, 'text' => str_replace("'", "\\'", str_replace(["\n", "\r"], " ",$contract->name))];
$result = ['value' => $contract->id, 'text' => $contract->id.": ".$contract->product_name." [".$contract->matchcode."] (".$contract->owner->getCompanyOrName().", ".$contract->owner->street.", ".$contract->owner->zip." ".$contract->owner->city.")"];
$result = ['value' => $contract->id, 'text' => $contract->id . ": " . $contract->product_name . " [" . $contract->matchcode . "] (" . $contract->owner->getCompanyOrName() . ", " . $contract->owner->street . ", " . $contract->owner->zip . " " . $contract->owner->city . ")"];
$results[] = $result;
if(count($results) > 15) {
if (count($results) > 15) {
$results[] = ['value' => 0, 'text' => "&nbsp;&nbsp;--> &nbsp;&nbsp;Mehr Suchergebnisse vorhanden. Bitte Suchbegriff genauer definieren &nbsp;&nbsp;<--"];
break;
}
+31 -5
View File
@@ -214,7 +214,7 @@ class ContractModel {
LEFT JOIN Product ON (Contract.product_id = Product.id)
WHERE $where
GROUP BY Contract.id
ORDER BY Contract.owner_id,Contract.product_id,Contract.`create`
ORDER BY Contract.`create`,Contract.id
LIMIT 1";
//var_dump($sql);exit;
$res = $db->query($sql);
@@ -269,12 +269,12 @@ class ContractModel {
WHERE $where
AND (cancel_date IS NULL OR cancel_date > UNIX_TIMESTAMP())
GROUP BY Contract.id
ORDER BY Contract.owner_id,Contract.`create`";
ORDER BY Contract.`create`,Contract.id";
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
} elseif(is_numeric($count)) {
} elseif(is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['count'];
}
}
@@ -328,12 +328,12 @@ class ContractModel {
LEFT JOIN Product ON (Contract.product_id = Product.id)
WHERE $where
GROUP BY Contract.id
ORDER BY Contract.owner_id,Contract.`create`";
ORDER BY Contract.`create`,Contract.id";
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
} elseif(is_numeric($count)) {
} elseif(is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['count'];
}
}
@@ -442,6 +442,32 @@ class ContractModel {
}
}
if(array_key_exists("price<", $filter)) {
$price = $filter['price<'];
if(is_numeric($price)) {
$where .= " AND Contract.price < $price";
}
}
if(array_key_exists("price<=", $filter)) {
$price = $filter['price<='];
if(is_numeric($price)) {
$where .= " AND Contract.price <= $price";
}
}
if(array_key_exists("price>", $filter)) {
$price = $filter['price>'];
if(is_numeric($price)) {
$where .= " AND Contract.price > $price";
}
}
if(array_key_exists("price>=", $filter)) {
$price = $filter['price>='];
if(is_numeric($price)) {
$where .= " AND Contract.price >= $price";
}
}
if(array_key_exists("add-where", $filter)) {
$where .= " ".$filter['add-where'];
}
@@ -161,7 +161,18 @@ class ContractLinkModel {
}
}
if(array_key_exists("type", $filter)) {
$type = $filter["type"];
if(is_array($type) && count($type)) {
$where .= " AND ContractLink.type IN ('".join("','", $type)."')";
} else {
$type = $db->escape($filter['type']);
if($type) {
$where .= " AND ContractLink.type = '$type'";
}
}
}
//var_dump($filter, $where);exit;
@@ -84,6 +84,7 @@ class ContractqueueController extends mfBaseController {
continue;
}
$skip_order = false;
$contracts = [];
$primary_matchcode = false;
@@ -93,8 +94,15 @@ class ContractqueueController extends mfBaseController {
if(!$contract) {
$contract = ContractqueueModel::getFirst(["orderproduct_id" => $op->id]);
}
if($contract && $contract->matchcode) {
if($contract) {
if($contract->matchcode) {
$primary_matchcode = $contract->matchcode;
}
continue;
}
if($op->product->external) {
$skip_order = true;
continue;
}
@@ -127,6 +135,10 @@ class ContractqueueController extends mfBaseController {
$contracts[] = $contract;
}
if($skip_order) {
$contracts = [];
continue;
}
if(!$primary_matchcode) {
$primary_matchcode = $order->owner->street.", ".$order->owner->zip." ".$order->owner->city;
@@ -176,22 +188,41 @@ class ContractqueueController extends mfBaseController {
$new_contracts = [];
$c = 0;
$o = 0;
$last_order_id = 0;
foreach(ContractqueueModel::search(["approved" => true, "contract_id" => null]) as $cq) {
//var_dump($cq);exit;
$contract = new Contract($cq->orderproduct_id);
if($contract->id) continue; // contract should not yet exist
$contract = ContractModel::getFirst(["orderproduct_id" => $cq->orderproduct_id]);
if($contract) {
$this->log->debug("Contract von orderproduct ".$cq->orderproduct_id." existiert schon: ".$contract->id);
continue;
} // contract should not yet exist
$order_id = $cq->orderproduct->order_id;
if($c >= 2000) {
if($order_id != $last_order_id) {
$this->layout()->setFlash("$c Contracts (exkl. Gutschriften) erstellt", "info");
$this->redirect("Contractqueue");
}
}
$last_order_id = $order_id;
/*
* Create Contract
*/
$contract = ContractModel::createFromContractqueue($cq);
if(!$contract->save()) {
$this->layout()->setFlash("Eine Position in Bestellung ".$cq->order_id." konnte nicht übernommen werden: Fehler beim Speichern");
$this->log->debug("Eine Position in Bestellung ".$cq->order_id." konnte nicht übernommen werden: Fehler beim Speichern");
$this->layout()->setFlash("Eine Position in Bestellung ".$cq->order_id." konnte nicht übernommen werden: Fehler beim Speichern", "warning");
continue;
}
$c++;
$cq->contract_id = $contract->id;
$cq->save();
@@ -213,7 +244,8 @@ class ContractqueueController extends mfBaseController {
if($cq->approved_credit) {
$credit = ContractModel::createFromContractQueue($cq, "credit");
if(!$credit->save()) {
$this->layout()->setFlash("Zu einer Position in Bestellung ".$cq->order_id." konnte keine Gutschrift erstellt werden: Fehler beim Speichern");
$this->log->log("Zu einer Position in Bestellung ".$cq->order_id." konnte keine Gutschrift erstellt werden: Fehler beim Speichern");
$this->layout()->setFlash("Zu einer Position in Bestellung ".$cq->order_id." konnte keine Gutschrift erstellt werden: Fehler beim Speichern", "warning");
continue;
}
$journal = ContractjournalModel::create([
@@ -229,8 +261,8 @@ class ContractqueueController extends mfBaseController {
]);
$journal->save();
$link = ContractLinkModel::create([
'contract_id' => $contract->id,
'origin_contract_id' => $credit->id,
'contract_id' => $credit->id,
'origin_contract_id' => $contract->id,
'type' => 'credit'
]);
$link->save();
@@ -240,8 +272,9 @@ class ContractqueueController extends mfBaseController {
/*
* Create ContractLinks
*/
foreach($new_contracts as $origin) {
if(ContractLinkModel::getFirst(["contract_id" => $contract->id, "origin_contract_id" => $origin->id])) {
if(array_key_exists($order_id, $new_contracts)) {
foreach ($new_contracts[$order_id] as $origin) {
if (ContractLinkModel::getFirst(["contract_id" => $contract->id, "origin_contract_id" => $origin->id])) {
continue;
}
$link = ContractLinkModel::create([
@@ -250,7 +283,7 @@ class ContractqueueController extends mfBaseController {
'type' => 'link'
]);
$link->save();
if($link->id) {
if ($link->id) {
$journal = ContractjournalModel::create([
'contract_id' => $contract->id,
'type' => "link",
@@ -266,13 +299,16 @@ class ContractqueueController extends mfBaseController {
$ojournal->save();
}
}
} else {
$new_contracts[$order_id] = [];
}
$new_contracts[] = $contract;
$new_contracts[$order_id][] = $contract;
}
$this->layout()->setFlash("$c Contracts erstellt", "success");
$this->redirect("Contract");
$this->redirect("Contractqueue");
}
@@ -141,7 +141,7 @@ class ContractqueueModel {
LEFT JOIN Product ON (Contractqueue.product_id = Product.id)
WHERE $where
GROUP BY Contractqueue.id
ORDER BY Contractqueue.owner_id,Contractqueue.product_id,Contractqueue.`create`
ORDER BY Contractqueue.order_id,Contractqueue.orderproduct_id,Contractqueue.owner_id,Contractqueue.product_id,Contractqueue.`create`
LIMIT 1";
//var_dump($sql);exit;
$res = $db->query($sql);
@@ -196,7 +196,7 @@ class ContractqueueModel {
WHERE $where
AND (cancel_date IS NULL OR cancel_date > UNIX_TIMESTAMP())
GROUP BY Contractqueue.id
ORDER BY Contractqueue.owner_id,Contractqueue.`create`";
ORDER BY Contractqueue.order_id,Contractqueue.orderproduct_id,Contractqueue.owner_id,Contractqueue.`create`";
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
@@ -231,7 +231,7 @@ class ContractqueueModel {
LEFT JOIN Product ON (Contractqueue.product_id = Product.id)
WHERE $where
GROUP BY Contractqueue.id
ORDER BY Contractqueue.owner_id,Contractqueue.`create`";
ORDER BY Contractqueue.order_id,Contractqueue.orderproduct_id,Contractqueue.owner_id,Contractqueue.`create`";
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
+4
View File
@@ -145,6 +145,10 @@ h1, h2, h3, h4, h5, h6 {
text-decoration: line-through;
}
.not-finished {
opacity: 0.7;
}
/* tinymce */
.tox-editor-header,
.tox-menubar,