diff --git a/application/Contract/ContractController.php b/application/Contract/ContractController.php index c2fae4eb4..aaa7e2853 100644 --- a/application/Contract/ContractController.php +++ b/application/Contract/ContractController.php @@ -380,7 +380,7 @@ class ContractController extends mfBaseController if (!$product->id) { $this->layout()->setFlash("Produkt nicht gefunden", "error"); if($f == "o") { - $this->redirect("Contract", "productchange", ["contract_id" => $id, "f" => $f]); + $this->redirect("Order", "productchange", ["contract_id" => $id]); } else { $this->redirect("Contract", "productchange", ["contract_id" => $id]); } @@ -397,7 +397,7 @@ class ContractController extends mfBaseController } catch (Exception $e) { $this->layout()->setFlash("Ungültiges Kündigungsdateum", "error"); if($f == "o") { - $this->redirect("Contract", "productchange", ["contract_id" => $id, "f" => $f]); + $this->redirect("Order", "productchange", ["contract_id" => $id]); } else { $this->redirect("Contract", "productchange", ["contract_id" => $id]); } @@ -420,7 +420,7 @@ class ContractController extends mfBaseController if (!$contract_data['termination_id'] || !$termination->id) { $this->layout()->setFlash("Produkt erfordert Anschluss.", "error"); if($f == "o") { - $this->redirect("Contract", "productchange", ["contract_id" => $id, "f" => $f]); + $this->redirect("Order", "productchange", ["contract_id" => $id]); } else { $this->redirect("Contract", "productchange", ["contract_id" => $id]); } @@ -436,7 +436,7 @@ class ContractController extends mfBaseController if (!$new_contract_id) { $this->layout()->setFlash("Neuer Contract konnte nicht gespeichert werden", "error"); if($f == "o") { - $this->redirect("Contract", "productchange", ["contract_id" => $id, "f" => $f]); + $this->redirect("Order", "productchange", ["contract_id" => $id]); } else { $this->redirect("Contract", "productchange", ["contract_id" => $id]); } @@ -463,9 +463,9 @@ class ContractController extends mfBaseController try { $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->layout()->setFlash("Ungültiges Kündigungsdatum", "error"); if($f == "o") { - $this->redirect("Contract", "productchange", ["contract_id" => $id, "f" => $f]); + $this->redirect("Order", "productchange", ["contract_id" => $id]); } else { $this->redirect("Contract", "productchange", ["contract_id" => $id]); } @@ -593,7 +593,7 @@ class ContractController extends mfBaseController $this->layout()->setFlash("Konnte Verknüpfung nicht speichern", "warn"); } - $this->layout()->setFlash("Neuer Contract erfolgreich erstellt", "success"); + $this->layout()->setFlash("Produktwechsel erfolgreich erstellt", "success"); if($f == "o") { $this->redirect("Order"); } else { diff --git a/application/ContractLink/ContractLinkModel.php b/application/ContractLink/ContractLinkModel.php index b3c2f4170..a2344459f 100644 --- a/application/ContractLink/ContractLinkModel.php +++ b/application/ContractLink/ContractLinkModel.php @@ -93,6 +93,63 @@ class ContractLinkModel { return $items; } + + public static function countWithContracts($filter) { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $sql = "SELECT COUNT(*) as cnt FROM ContractLink + LEFT JOIN Contract ON (ContractLink.contract_id = Contract.id) + LEFT JOIN Address AS Owner ON (Contract.owner_id = Owner.id) + LEFT JOIN Worker ON (ContractLink.create_by = Worker.id) + LEFT JOIN OrderProduct ON (Contract.orderproduct_id = OrderProduct.id) + LEFT JOIN `Order` ON (OrderProduct.order_id = `Order`.id) + LEFT JOIN Product ON (Contract.product_id = Product.id) + WHERE $where + "; + + $res = $db->query($sql); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + return $data->cnt; + } + return 0; + } + + public static function searchWithContracts($filter, $limit = false) { + $items = []; + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $sql = "SELECT ContractLink.* FROM ContractLink + LEFT JOIN Contract ON (ContractLink.contract_id = Contract.id) + LEFT JOIN Address AS Owner ON (Contract.owner_id = Owner.id) + LEFT JOIN Worker ON (ContractLink.create_by = Worker.id) + LEFT JOIN OrderProduct ON (Contract.orderproduct_id = OrderProduct.id) + LEFT JOIN `Order` ON (OrderProduct.order_id = `Order`.id) + LEFT JOIN Product ON (Contract.product_id = Product.id) + WHERE $where + 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($limit['count'])) { + $sql .= " LIMIT ".$limit['count']; + } + } + + mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[$data->id] = new ContractLink($data); + } + } + + return $items; + } public static function count($filter) { $db = FronkDB::singleton(); @@ -109,7 +166,7 @@ class ContractLinkModel { } return 0; } - + public static function search($filter, $limit = false) { //var_dump($filter);exit; $items = []; @@ -123,7 +180,7 @@ class ContractLinkModel { 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']; } } @@ -171,9 +228,96 @@ class ContractLinkModel { $where .= " AND ContractLink.type = '$type'"; } } - } - + + 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("finish_date", $filter)) { + $finish_date = $filter['finish_date']; + if(is_numeric($finish_date)) { + $where .= " AND Contract.finish_date = $finish_date"; + } + } + + if(array_key_exists("finish_date>", $filter)) { + $finish_date = $filter['finish_date>']; + if(is_numeric($finish_date)) { + $where .= " AND Contract.finish_date >= $finish_date"; + } + } + + if(array_key_exists("finish_date_null_or_gte", $filter)) { + $finish_date = $filter['finish_date_null_or_gte']; + if(is_numeric($finish_date)) { + $where .= " AND (Contract.finish_date IS NULL OR Contract.finish_date >= $finish_date)"; + } + } + + if(array_key_exists("finish_date<", $filter)) { + $finish_date = $filter['finish_date<']; + if(is_numeric($finish_date)) { + $where .= " AND Contract.finish_date <= $finish_date"; + } + } + + if(array_key_exists("finish_date_null_or_lte", $filter)) { + $finish_date = $filter['finish_date_null_or_lte']; + if(is_numeric($finish_date)) { + $where .= " AND (Contract.finish_date IS NULL OR Contract.finish_date <= $finish_date)"; + } + } + + if(array_key_exists("cancel_date>", $filter)) { + $cancel_date = $filter['cancel_date>']; + if(is_numeric($cancel_date)) { + $where .= " AND Contract.cancel_date >= $cancel_date"; + } + } + + if(array_key_exists("cancel_date_null_or_gte", $filter)) { + $cancel_date = $filter['cancel_date_null_or_gte']; + if(is_numeric($cancel_date)) { + $where .= " AND (Contract.cancel_date IS NULL OR Contract.cancel_date >= $cancel_date)"; + } + } + + if(array_key_exists("cancel_date<", $filter)) { + $cancel_date = $filter['cancel_date<']; + if(is_numeric($cancel_date)) { + $where .= " AND Contract.cancel_date <= $cancel_date"; + } + } + + if(array_key_exists("cancel_date_null_or_lte", $filter)) { + $cancel_date = $filter['cancel_date_null_or_lte']; + if(is_numeric($cancel_date)) { + $where .= " AND (Contract.cancel_date IS NULL OR Contract.cancel_date <= $cancel_date)"; + } + } //var_dump($filter, $where);exit; return $where; diff --git a/application/Order/OrderController.php b/application/Order/OrderController.php index 2c7cd1697..45eff9cfb 100644 --- a/application/Order/OrderController.php +++ b/application/Order/OrderController.php @@ -427,10 +427,6 @@ class OrderController extends mfBaseController { return $this->addAction(); } - protected function upgradesAction() { - - } - protected function setwaitingAction() { $order_id = $this->request->id; $order = new Order($order_id); @@ -462,6 +458,41 @@ class OrderController extends mfBaseController { $this->redirect("Order","Index", $qs); } + protected function upgradesAction() { + $this->layout()->setTemplate("Order/Upgrades"); + + $rfilter = $this->request->filter; + if(!$rfilter) { + $rfilter = []; + } + + $this->layout->set("filter", $rfilter); + $filter = $this->getPreparedFilter($this->request->filter); + + // pagination defaults + $pagination = []; + $pagination['start'] = 0; + $pagination['count'] = 20; + $pagination['maxItems'] = 0; + + if(is_numeric($this->request->s)) { + $pagination['start'] = intval($this->request->s); + } + + $upgrade_search = [ + "type" => "upgrade", + "contract_creator_address_id" => $this->me->address_id, + "finish_date_null_or_gte" => date("U"), + "price>=" => 0 + ]; + + + $pagination["maxItems"] = ContractLinkModel::countWithContracts($upgrade_search); + + $upgrades = ContractLinkModel::searchWithContracts($upgrade_search, $pagination); + $this->layout()->set("upgrades", $upgrades); + $this->layout()->set("pagination", $pagination); + } protected function addUpgrade() { //$this->layout()->setTemplate("Order/Productchange"); Helper::renderVue($this, "OrderProductchange", "Neuer Produktwechsel", ["CONTRACT_API_URL" => $this->getUrl("Contract", "api"),