@@ -219,7 +232,10 @@
allowClear: true,
placeholder: ""
});
-
+ $("#networks").select2({
+ allowClear: true,
+ placeholder: ""
+ });
$('#productgroup_id').change(function() {
var value = $('#productgroup_id option:selected').val();
diff --git a/Layout/default/Product/Index.php b/Layout/default/Product/Index.php
index 5f75c4d5c..90989fac9 100644
--- a/Layout/default/Product/Index.php
+++ b/Layout/default/Product/Index.php
@@ -49,11 +49,11 @@
=($product->external == 1) ? "" : ""?> |
=$product->productgroup->name?> |
=$product->name?> |
-
=$product->producttech->name?> |
+
=$product->producttech->name?> (=$product->producttech->rtrcode?>) |
=__($product->producttech->customer_type)?> |
=$product->price?> |
=$product->billing_period?>x Jährlich |
-
=$product->sla->name?> |
+
=$product->sla->id?> |
=$product->ivt_id?> |
$product->id])?>">
diff --git a/Layout/default/menu.php b/Layout/default/menu.php
index 5434efb8a..6a3a6f52d 100644
--- a/Layout/default/menu.php
+++ b/Layout/default/menu.php
@@ -21,7 +21,7 @@
">Benutzer
- ">Neztgebiete
+ ">Netzgebiete
">Produkte
diff --git a/application/Product/Product.php b/application/Product/Product.php
index fd1b9ef69..300e9d1f6 100644
--- a/application/Product/Product.php
+++ b/application/Product/Product.php
@@ -3,10 +3,23 @@
class Product extends mfBaseModel {
private $productgroup;
private $producttech;
+ private $sla;
+ private $networks;
public function getProperty($name) {
if($this->$name == null) {
+ if($name == "networks") {
+ $this->networks = [];
+ $productNetworks = ProductNetworkModel::search(['product_id' => $this->id]);
+ foreach($productNetworks as $pnet) {
+ $this->networks[$pnet->network_id] = new Network($pnet->network_id);
+ }
+ return $this->networks;
+ }
+
+
+
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);
diff --git a/application/Product/ProductController.php b/application/Product/ProductController.php
index 7b3a618e6..d54186f6d 100644
--- a/application/Product/ProductController.php
+++ b/application/Product/ProductController.php
@@ -23,6 +23,7 @@ class ProductController extends mfBaseController {
$this->layout()->set("productgroups", ProductgroupModel::getAll());
$this->layout()->set("producttechs", ProducttechModel::getAll());
$this->layout()->set("slas", SlaModel::getAll());
+ $this->layout()->set("networks", NetworkModel::getAll());
}
@@ -96,6 +97,24 @@ class ProductController extends mfBaseController {
return $this->add();
}
+ // delete all networks to save networks
+ $pnets = ProductNetworkModel::search(['product_id' => $new_id]);
+ foreach($pnets as $pnet) {
+ $pnet->delete();
+ }
+
+ if(is_array($r->networks) && count($r->networks)) {
+ foreach($r->networks as $network_id) {
+ $network = new Network($network_id);
+ if(!$network->id) {
+ // ignore non-existing networks
+ continue;
+ }
+ $pnet = ProductNetworkModel::create(['product_id' => $new_id, 'network_id' => $network_id]);
+ $pnet->save();
+ }
+ }
+
// create new product group and tech
if($r->productgroup_id == "new") {
diff --git a/application/ProductNetwork/ProductNetwork.php b/application/ProductNetwork/ProductNetwork.php
new file mode 100644
index 000000000..6a44d8407
--- /dev/null
+++ b/application/ProductNetwork/ProductNetwork.php
@@ -0,0 +1,5 @@
+ $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("ProductNetwork", "*", "id=$id LIMIT 1");
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new ProductNetwork($data);
+ }
+ return $item;
+ }
+
+ public static function getAll() {
+ $items = [];
+
+ $db = FronkDB::singleton();
+
+ $res = $db->select("ProductNetwork", "*", "1 = 1 ORDER BY product_id, network_id");
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[$data->id] = new ProductNetwork($data);
+ }
+ }
+ return $items;
+
+ }
+
+ public static function getFirst() {
+ $db = FronkDB::singleton();
+
+ $where = self::getSqlFilter($filter);
+ $res = $db->select("ProductNetwork", "*", "$where ORDER BY product_id, network_id LIMIT 1");
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new ProductNetwork($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("ProductNetwork", "*", "$where ORDER BY product_id, network_id");
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[$data->id] = new ProductNetwork($data);
+ }
+ }
+ return $items;
+ }
+
+ private function getSqlFilter($filter) {
+ $where = "1=1 ";
+
+ $db = FronkDB::singleton();
+
+ //var_dump($filter);exit;
+ if(array_key_exists("product_id", $filter)) {
+ $product_id = $filter['product_id'];
+ if(is_numeric($product_id)) {
+ $where .= " AND product_id=$product_id";
+ }
+ }
+
+ if(array_key_exists("network_id", $filter)) {
+ $network_id = $filter['network_id'];
+ if(is_numeric($network_id)) {
+ $where .= " AND network_id=$network_id";
+ }
+ }
+
+ //var_dump($filter, $where);exit;
+ return $where;
+ }
+
+}
\ No newline at end of file
diff --git a/contrib/migrations/20210705-product-tables.sql b/contrib/migrations/20210705-product-tables.sql
index 08f6dca5e..a6243982f 100644
--- a/contrib/migrations/20210705-product-tables.sql
+++ b/contrib/migrations/20210705-product-tables.sql
@@ -6,9 +6,9 @@ CREATE TABLE `Product` (
`external` tinyint(1) NOT NULL DEFAULT '0',
`producttech_id` int DEFAULT NULL,
`productgroup_id` int DEFAULT NULL,
- `price_nne` decimal(12,2) DEFAULT NULL,
- `price_nbe` decimal(12,2) DEFAULT NULL,
- `price` decimal(12,2) NOT NULL,
+ `price_nne` decimal(14,4) DEFAULT NULL,
+ `price_nbe` decimal(14,4) DEFAULT NULL,
+ `price` decimal(14,4) NOT NULL,
`billing_period` int NOT NULL COMMENT 'in months',
`ivt_id` int DEFAULT NULL,
`note` text COLLATE utf8mb4_unicode_520_ci,
@@ -84,3 +84,18 @@ CREATE TABLE `ProducttechAttribute` (
`create` int NOT NULL,
`edit` int NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
+
+
+CREATE TABLE `Sla` (
+ `id` int NOT NULL AUTO_INCREMENT,
+ `name` varchar(1024) COLLATE utf8mb4_unicode_520_ci NOT NULL,
+ `description` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
+ `note` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
+ `create_by` int NOT NULL,
+ `edit_by` int NOT NULL,
+ `create` int NOT NULL,
+ `edit` int NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
+
+INSERT INTO `Sla` VALUES (1,'12h/6T - Working Hours','','',1,1,1625495944,1625495944),(2,'24h/7T - 2h/6h Emergency','','',1,1,1625495944,1625495944),(3,'8h/5T - Next Business Day','','',1,1,1625495985,1625495985),(4,'8h/5T - Residential','','',1,1,1625495985,1625495985);
\ No newline at end of file
|