diff --git a/Layout/default/Order/Index.php b/Layout/default/Order/Index.php index c12aa9ac7..fe5f847f8 100644 --- a/Layout/default/Order/Index.php +++ b/Layout/default/Order/Index.php @@ -194,9 +194,9 @@ - + id?> - + terminations) && count($order->terminations)): ?> terminations[0]->status->code >= TT_TERMSTATUS_CONNECTED): ?> CON @@ -236,23 +236,23 @@ " : ""?> " : ""?> - + owner->getCompanyOrName())?> owner->spin) ? "
".$order->owner->spin."" : ""?> - + owner->street?>
owner->zip?> owner->city?> - + terminations) && count($order->terminations)): ?> terminations[0]->building->street?>terminations[0]->name) ? " ".$order->terminations[0]->name : ""?>
terminations[0]->building->zip?> terminations[0]->building->city?> - order_date)?> - edit)?> - editor->name?> + order_date)?> + edit)?> + editor->name?> $order->id])?>"> $order->id])?>" onclick="if(!confirm('Soll der Service-PIN an den Vertragsinhaber gesendet werden?')) return false;"> @@ -260,6 +260,51 @@ $order->id])?>" onclick="if(!confirm('Bestellung wirklich löschen?')) return false;" class="text-danger" title="Löschen"> + + + +
+
+ +
+ +
+
Bestelljournal
+
+
+ +
+ + journals) && count($order->journals)): ?> + journals as $journal): ?> +
+
create)?> Eingetragen von creator->name?>
+
+ text)?> +
+
+ + + + + +
+
+ +
+
+ + + + + + @@ -297,4 +342,17 @@ + + diff --git a/application/Order/Order.php b/application/Order/Order.php index f75ff3f9b..8cdd2eb75 100644 --- a/application/Order/Order.php +++ b/application/Order/Order.php @@ -5,6 +5,7 @@ class Order extends mfBaseModel { private $billingaddress; private $products; private $terminations; + private $journals; private $files; private $creator; private $editor; @@ -132,6 +133,11 @@ class Order extends mfBaseModel { return $this->terminations; } + if($name == "journals") { + $this->journals = OrderJournalModel::search(["order_id" => $this->id]); + return $this->journals; + } + if($name == "files") { $this->files = OrderFileModel::search(['order_id' => $this->id]); return $this->files; diff --git a/application/OrderJournal/OrderJournal.php b/application/OrderJournal/OrderJournal.php new file mode 100644 index 000000000..4cab5a5c4 --- /dev/null +++ b/application/OrderJournal/OrderJournal.php @@ -0,0 +1,38 @@ +$name == null) { + + if(!$this->id) { + return null; + } + + if($name == "creator") { + $this->creator = new User($this->create_by); + return $this->creator; + } + + if($name == "editor") { + $this->editor = new User($this->edit_by); + return $this->editor; + } + + $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; + } +} \ No newline at end of file diff --git a/application/OrderJournal/OrderJournalController.php b/application/OrderJournal/OrderJournalController.php new file mode 100644 index 000000000..2fd4aa56b --- /dev/null +++ b/application/OrderJournal/OrderJournalController.php @@ -0,0 +1,61 @@ +needlogin=true; + $me = new User(); + $me->loadMe(); + $this->me = $me; + $this->layout()->set("me",$me); + + if(!$me->is(["Admin", "salespartner"])) { + $this->redirect("Dashboard"); + } + } + + protected function saveAction() { + if(!$this->me->is(["Admin", "salespartner"])) { + $this->layout()->setFlash("Keine Berechtigung", "error"); + $this->redirect("Dashboard"); + } + + $r = $this->request; + $order_id = $r->order_id; + if(!is_numeric($order_id) || $order_id < 1) { + $this->layout()->setFlash("Bestellung nicht gefunden!", "error"); + $this->redirect("Order"); + } + + $order = new Order($order_id); + if(!$order->id) { + $this->layout()->setFlash("Bestellung nicht gefunden!", "error"); + $this->redirect("Order"); + } + + $text = trim(htmlentities($r->text)); + if(!$text) { + $this->layout()->setFlash("Bitte Text eingeben", "error"); + $this->redirect("Order", "Index", [], "order=".$order_id); + } + + + + $journal = new OrderJournal(); + $journal->order_id = $order_id; + $journal->text = $text; + $journal->create_by = $this->me->id; + $journal->edit_by = $this->me->id; + + if(!$journal->save()) { + $this->layout()->setFlash("Fehler beim speichern!", "error"); + $this->redirect("Order", "Index", [], "order=".$order_id); + } + + $this->layout()->setFlash("Journaleintrag gespeichert", "success"); + $this->redirect("Order", "Index", [], "order=".$order_id); + } + + + +} \ No newline at end of file diff --git a/application/OrderJournal/OrderJournalModel.php b/application/OrderJournal/OrderJournalModel.php new file mode 100644 index 000000000..ee6bba369 --- /dev/null +++ b/application/OrderJournal/OrderJournalModel.php @@ -0,0 +1,112 @@ + $value) { + if(property_exists(get_called_class(), $field)) { + $model ->$field = $value; + } + } + + $me = new User(); + $me->loadMe(); + + if($model->create_by === null) { + $model->create_by = $me->id; + } + if($model->edit_by === null) { + $model->edit_by = $me->id; + } + + return $model; + } + + public static function getOne($id) { + if(!is_numeric($id) || !$id) { + throw new Exception("Invalid number", 400); + } + $item = []; + $db = FronkDB::singleton(); + + $res = $db->select("OrderJournal", "*", "id=$id LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new OrderJournal($data); + } + return $item; + } + + public static function getAll() { + $items = []; + + $db = FronkDB::singleton(); + + $res = $db->select("OrderJournal", "*"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new OrderJournal($data); + } + } + return $items; + + } + + public static function getFirst($filter) { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("OrderJournal", "*", "$where ORDER BY `create`"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new OrderJournal($data); + if($item->id) { + return $item; + } else { + return null; + } + } + return null; + } + + public static function search($filter) { + $items = []; + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("OrderJournal", "*", "$where ORDER BY `create` DESC"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new OrderJournal($data); + } + } + return $items; + } + + private function getSqlFilter($filter) { + $where = "1=1 "; + + //var_dump($filter);exit; + if(array_key_exists("order_id", $filter)) { + $orderid = $filter['order_id']; + if(is_numeric($orderid)) { + $where .= " AND order_id=$orderid"; + } + } + + //var_dump($filter, $where);exit; + return $where; + } + +} \ No newline at end of file