Partner Producthchange WIP 2024-07-23
This commit is contained in:
@@ -11,7 +11,7 @@ class ContractController extends mfBaseController
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me", $me);
|
||||
|
||||
if (!$me->is(["Admin"])) {
|
||||
if (!$me->is(["Admin", "salespartner", "netowner"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,10 @@ class ContractController extends mfBaseController
|
||||
|
||||
protected function indexAction()
|
||||
{
|
||||
if(!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
|
||||
$this->layout()->setTemplate("Contract/Index");
|
||||
|
||||
if ($this->request->resetFilter) {
|
||||
@@ -87,6 +91,10 @@ class ContractController extends mfBaseController
|
||||
|
||||
protected function viewAction()
|
||||
{
|
||||
if(!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
|
||||
$this->layout()->setTemplate("Contract/View");
|
||||
|
||||
$id = $this->request->contract_id;
|
||||
@@ -116,6 +124,9 @@ class ContractController extends mfBaseController
|
||||
}
|
||||
|
||||
protected function cancelAction() {
|
||||
if(!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$this->layout()->setTemplate("Contract/CancelForm");
|
||||
|
||||
$id = $this->request->contract_id;
|
||||
@@ -154,6 +165,9 @@ class ContractController extends mfBaseController
|
||||
}
|
||||
|
||||
protected function saveCancel() {
|
||||
if(!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$r = $this->request;
|
||||
|
||||
$id = $r->contract_id;
|
||||
@@ -212,6 +226,9 @@ class ContractController extends mfBaseController
|
||||
}
|
||||
|
||||
protected function sendCancelNotification() {
|
||||
if(!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$contract_id = $this->request->contract_id;
|
||||
$contract = new Contract($contract_id);
|
||||
|
||||
@@ -238,23 +255,65 @@ class ContractController extends mfBaseController
|
||||
{
|
||||
$this->layout()->setTemplate("Contract/ProductchangeForm");
|
||||
|
||||
$f = $this->request->f;
|
||||
if(!$f) {
|
||||
$f = "c"; // from Contract
|
||||
}
|
||||
$this->layout()->set("f", $f);
|
||||
|
||||
$id = $this->request->contract_id;
|
||||
if (!$id) {
|
||||
$id = $this->request->id;
|
||||
}
|
||||
if (!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
|
||||
$this->redirect("Contract");
|
||||
if($f == "o") {
|
||||
$this->redirect("Order", "addUpgrade");
|
||||
} else {
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$contract = new Contract($id);
|
||||
if (!$contract->id) {
|
||||
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
|
||||
$this->redirect("Contract");
|
||||
if($f == "o") {
|
||||
$this->redirect("Order", "addUpgrade");
|
||||
} else {
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
}
|
||||
|
||||
if($this->me->isAdmin()) {
|
||||
$this->layout()->set("terminations", TerminationModel::getAll());
|
||||
} else {
|
||||
// check permissions
|
||||
// check if correct network
|
||||
|
||||
$my_network_ids = [];
|
||||
foreach($this->me->my_networks as $network) {
|
||||
$my_network_ids[] = $network->id;
|
||||
}
|
||||
|
||||
if($contract->termination_id) {
|
||||
if(!in_array($contract->termination->network_id, $my_network_ids)) {
|
||||
if($f == "o") {
|
||||
// from Order, redirect back to Order
|
||||
$this->layout()->setFlash("Keine Berechtigung", "error");
|
||||
$this->redirect("Order", "addUpgrade", ["owner_id" => $contract->owner_id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$terms = TerminationModel::search(["network_id" => $my_network_ids]);
|
||||
$this->layout()->set("terminations", $terms);
|
||||
}
|
||||
|
||||
|
||||
$this->layout()->set("contract", $contract);
|
||||
$this->layout()->set("terminations", TerminationModel::getAll());
|
||||
|
||||
|
||||
if ($this->request->filter) {
|
||||
$this->layout()->set("filter", $this->request->filter);
|
||||
@@ -266,19 +325,36 @@ class ContractController extends mfBaseController
|
||||
|
||||
protected function saveProductchangeAction()
|
||||
{
|
||||
if(!$this->me->is(["Admin", "salespartner", "netowner"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
|
||||
$r = $this->request;
|
||||
//var_dump($r->links);exit;
|
||||
|
||||
$f = $r->f;
|
||||
if(!$f) {
|
||||
$f = "c"; // from Contract
|
||||
}
|
||||
|
||||
$id = $r->contract_id;
|
||||
if (!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
|
||||
$this->redirect("Contract");
|
||||
if($f == "o") {
|
||||
$this->redirect("Order", "addUpgrade");
|
||||
} else {
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
}
|
||||
|
||||
$contract = new Contract($id);
|
||||
if (!$contract->id) {
|
||||
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
|
||||
$this->redirect("Contract");
|
||||
if($f == "o") {
|
||||
$this->redirect("Order", "addUpgrade");
|
||||
} else {
|
||||
$this->redirect("Contract");
|
||||
}
|
||||
}
|
||||
|
||||
$new_contract = clone($contract);
|
||||
@@ -303,7 +379,12 @@ class ContractController extends mfBaseController
|
||||
$product = new Product($r->product_id);
|
||||
if (!$product->id) {
|
||||
$this->layout()->setFlash("Produkt nicht gefunden", "error");
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id]);
|
||||
if($f == "o") {
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id, "f" => $f]);
|
||||
} else {
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$contract_data['product_external'] = $product->external;
|
||||
@@ -315,7 +396,11 @@ class ContractController extends mfBaseController
|
||||
$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]);
|
||||
if($f == "o") {
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id, "f" => $f]);
|
||||
} else {
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id]);
|
||||
}
|
||||
}
|
||||
|
||||
$finish_date->setTime(0,0,0);
|
||||
@@ -334,7 +419,11 @@ class ContractController extends mfBaseController
|
||||
|
||||
if (!$contract_data['termination_id'] || !$termination->id) {
|
||||
$this->layout()->setFlash("Produkt erfordert Anschluss.", "error");
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id]);
|
||||
if($f == "o") {
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id, "f" => $f]);
|
||||
} else {
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$contract_data['termination_id'] = null;
|
||||
@@ -371,7 +460,11 @@ class ContractController extends mfBaseController
|
||||
$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]);
|
||||
if($f == "o") {
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id, "f" => $f]);
|
||||
} else {
|
||||
$this->redirect("Contract", "productchange", ["contract_id" => $id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,7 +501,7 @@ class ContractController extends mfBaseController
|
||||
}
|
||||
|
||||
if ($action == "cancel") {
|
||||
if($cancel_date) {
|
||||
if($cancel_date && $contract_cancel_date) {
|
||||
// insert cancel_date in old contract
|
||||
$lc = new Contract($origin_id);
|
||||
$lc->cancel_date = $cancel_date->getTimestamp();
|
||||
@@ -497,13 +590,21 @@ class ContractController extends mfBaseController
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Neuer Contract erfolgreich erstellt", "success");
|
||||
$this->redirect("Contract", "view", ["contract_id" => $new_contract_id]);
|
||||
if($f == "o") {
|
||||
$this->redirect("Order");
|
||||
} else {
|
||||
$this->redirect("Contract", "view", ["contract_id" => $new_contract_id]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function finishContractAction()
|
||||
{
|
||||
if(!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$r = $this->request;
|
||||
|
||||
$id = $r->contract_id;
|
||||
@@ -550,6 +651,9 @@ class ContractController extends mfBaseController
|
||||
|
||||
protected function addAction()
|
||||
{
|
||||
if(!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$this->layout()->setTemplate("Contract/Form");
|
||||
$this->layout()->set("terminations", TerminationModel::getAll());
|
||||
|
||||
@@ -569,6 +673,9 @@ class ContractController extends mfBaseController
|
||||
|
||||
protected function editAction()
|
||||
{
|
||||
if(!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$id = $this->request->contract_id;
|
||||
if (!$id) {
|
||||
$id = $this->request->id;
|
||||
@@ -602,6 +709,9 @@ class ContractController extends mfBaseController
|
||||
|
||||
protected function saveAction()
|
||||
{
|
||||
if(!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$r = $this->request;
|
||||
//var_dump($r);
|
||||
|
||||
@@ -787,7 +897,7 @@ class ContractController extends mfBaseController
|
||||
|
||||
protected function apiAction()
|
||||
{
|
||||
if (!$this->me->is(["Admin"])) {
|
||||
if (!$this->me->is(["Admin", "salespartner", "netowner"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$do = $this->request->do;
|
||||
@@ -821,6 +931,10 @@ class ContractController extends mfBaseController
|
||||
|
||||
private function getContractApi()
|
||||
{
|
||||
if (!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
|
||||
$contract_id = $this->request->contract_id;
|
||||
if (!is_numeric($contract_id) || $contract_id < 1) {
|
||||
return false;
|
||||
@@ -847,7 +961,37 @@ class ContractController extends mfBaseController
|
||||
|
||||
$return = [];
|
||||
|
||||
foreach(ContractModel::search(["owner_id" => $owner_id]) as $contract) {
|
||||
$contracts = ContractModel::search(["owner_id" => $owner_id]);
|
||||
if(!$contracts) {
|
||||
header("Content-type: application/json");
|
||||
echo json_encode([]);
|
||||
exit;
|
||||
}
|
||||
$is_valid_owner = false;
|
||||
|
||||
if(!$this->me->is("Admin")) {
|
||||
foreach($contracts as $contract) {
|
||||
foreach(ContractLinkModel::includesContractId($contract->id) as $link) {
|
||||
if($link->type != "credit") continue;
|
||||
$link_contract = $link->contract;
|
||||
if($link->contract_id == $contract->id) $link_contract = $link->origin;
|
||||
if($link_contract->owner_id == $this->me->address_id) {
|
||||
$is_valid_owner = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!$is_valid_owner) {
|
||||
header("Content-type: application/json");
|
||||
echo json_encode([]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
foreach($contracts as $contract) {
|
||||
$c = get_object_vars($contract->data);
|
||||
$c["id"] = $contract->id;
|
||||
$return[] = $c;
|
||||
@@ -860,6 +1004,9 @@ class ContractController extends mfBaseController
|
||||
|
||||
private function findContractApi()
|
||||
{
|
||||
if (!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$search = trim($this->request->q);
|
||||
$autocomplete = $this->request->autocomplete;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user