From 4fae807663c429c64528680441496acadb8cfb45 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Mon, 5 Jul 2021 16:12:28 +0200 Subject: [PATCH 01/10] Added Products --- Layout/default/Dashboard/Index.php | 3 +- Layout/default/Network/Index.php | 8 +- Layout/default/Pop/Form.php | 4 +- Layout/default/Product/Form.php | 235 ++++++++++++++++++ Layout/default/Product/Index.php | 69 +++++ Layout/default/footer.php | 2 +- Layout/default/menu.php | 7 +- application/Network/NetworkController.php | 2 +- application/Network/NetworkModel.php | 10 + .../NetworkAddressController.php | 38 +++ application/Product/Product.php | 21 ++ application/Product/ProductController.php | 134 ++++++++++ application/Product/ProductModel.php | 142 +++++++++++ application/Productgroup/Productgroup.php | 5 + .../Productgroup/ProductgroupController.php | 30 +++ .../Productgroup/ProductgroupModel.php | 122 +++++++++ application/Producttech/Producttech.php | 5 + application/Producttech/ProducttechModel.php | 129 ++++++++++ ... => 20210629-addresstype-planner-vlan.sql} | 0 .../migrations/20210705-product-tables.sql | 83 +++++++ lib/Layout/Layout.php | 4 + 21 files changed, 1040 insertions(+), 13 deletions(-) create mode 100644 Layout/default/Product/Form.php create mode 100644 Layout/default/Product/Index.php create mode 100644 application/Product/Product.php create mode 100644 application/Product/ProductController.php create mode 100644 application/Product/ProductModel.php create mode 100644 application/Productgroup/Productgroup.php create mode 100644 application/Productgroup/ProductgroupController.php create mode 100644 application/Productgroup/ProductgroupModel.php create mode 100644 application/Producttech/Producttech.php create mode 100644 application/Producttech/ProducttechModel.php rename contrib/migrations/{20210629-01-addresstype-planner-vlan.sql => 20210629-addresstype-planner-vlan.sql} (100%) create mode 100644 contrib/migrations/20210705-product-tables.sql diff --git a/Layout/default/Dashboard/Index.php b/Layout/default/Dashboard/Index.php index 1f71252e1..38cd090f4 100644 --- a/Layout/default/Dashboard/Index.php +++ b/Layout/default/Dashboard/Index.php @@ -10,8 +10,7 @@

Dashboard

diff --git a/Layout/default/Network/Index.php b/Layout/default/Network/Index.php index 19bec65c9..08969831f 100644 --- a/Layout/default/Network/Index.php +++ b/Layout/default/Network/Index.php @@ -133,6 +133,7 @@ + @@ -141,10 +142,11 @@ addresstypes as $address_id => $addresstypes): ?> + @@ -184,7 +186,7 @@ + + + @@ -47,8 +50,11 @@ + + + - + - + - + diff --git a/application/Product/ProductController.php b/application/Product/ProductController.php index ad037b85d..9ac5f4637 100644 --- a/application/Product/ProductController.php +++ b/application/Product/ProductController.php @@ -66,7 +66,9 @@ class ProductController extends mfBaseController { $data['price_nne'] = Layout::commaToDot($r->price_nne); $data['price_nbe'] = Layout::commaToDot($r->price_nbe); $data['price'] = Layout::commaToDot($r->price); + $data['price_setup'] = $r->price_setup; $data['billing_period'] = $r->billing_period; + $data['billing_delay'] = $r->billing_delay; $data['ivt_id'] = ($r->ivt_id) ? $r->ivt_id : null; $data['note'] = $r->note; diff --git a/contrib/migrations/20210705-product-tables.sql b/contrib/migrations/20210705-product-tables.sql index a6243982f..f4d0b5fca 100644 --- a/contrib/migrations/20210705-product-tables.sql +++ b/contrib/migrations/20210705-product-tables.sql @@ -9,6 +9,8 @@ CREATE TABLE `Product` ( `price_nne` decimal(14,4) DEFAULT NULL, `price_nbe` decimal(14,4) DEFAULT NULL, `price` decimal(14,4) NOT NULL, + `price_setup` decimal(14,4) NOT NULL DEFAULT '0', + `billing_delay` int NOT NULL DEFAULT '0' COMMENT 'in months', `billing_period` int NOT NULL COMMENT 'in months', `ivt_id` int DEFAULT NULL, `note` text COLLATE utf8mb4_unicode_520_ci, @@ -30,21 +32,17 @@ CREATE TABLE `ProductNetwork` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; -CREATE TABLE `Productattribute` ( +CREATE TABLE `ProductAttribute` ( `id` int NOT NULL AUTO_INCREMENT, `product_id` int NOT NULL, `producttechattribute_id` int NOT NULL, - `name` varchar(1024) COLLATE utf8mb4_unicode_520_ci NOT NULL, - `displayname` varchar(1024) COLLATE utf8mb4_unicode_520_ci NOT NULL, `value` 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; +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; CREATE TABLE `Productgroup` ( `id` int NOT NULL AUTO_INCREMENT, @@ -73,7 +71,8 @@ CREATE TABLE `Producttech` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; CREATE TABLE `ProducttechAttribute` ( - `id` int NOT NULL, + `id` int NOT NULL AUTO_INCREMENT, + `producttech_id` int NOT NULL, `name` varchar(1024) COLLATE utf8mb4_unicode_520_ci NOT NULL, `displayname` varchar(1024) COLLATE utf8mb4_unicode_520_ci NOT NULL, `value` varchar(1024) COLLATE utf8mb4_unicode_520_ci NOT NULL, @@ -82,9 +81,9 @@ CREATE TABLE `ProducttechAttribute` ( `create_by` int NOT NULL, `edit_by` int NOT NULL, `create` int NOT NULL, - `edit` int NOT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; - + `edit` int NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; CREATE TABLE `Sla` ( `id` int NOT NULL AUTO_INCREMENT, @@ -98,4 +97,4 @@ CREATE TABLE `Sla` ( 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 +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); From 262cf073da8a106516b72bc5ceb3e4490b4ced98 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 6 Jul 2021 15:49:34 +0200 Subject: [PATCH 08/10] Changed layout in Product/Form --- Layout/default/Product/Form.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Layout/default/Product/Form.php b/Layout/default/Product/Form.php index a70222929..7a2f50b96 100644 --- a/Layout/default/Product/Form.php +++ b/Layout/default/Product/Form.php @@ -138,7 +138,20 @@ +
+ +
+ +
+
+ + + +

Verrechnungsdaten

+
+
+
@@ -179,17 +192,10 @@
- -
- -
- -
- -
+ attributes) && count($product->attributes)): ?>

Produktattribute

From c94fc809eca4edf6d38e497145c072191696909b Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 6 Jul 2021 15:53:59 +0200 Subject: [PATCH 09/10] added onfig option for rtr code attrib --- Layout/default/Product/Index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Layout/default/Product/Index.php b/Layout/default/Product/Index.php index 384cb2120..d68c0692b 100644 --- a/Layout/default/Product/Index.php +++ b/Layout/default/Product/Index.php @@ -49,7 +49,7 @@
- + From b27de680b96a11c7111ac4dae346b6cb725d098e Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 6 Jul 2021 15:57:12 +0200 Subject: [PATCH 10/10] Fixed setup price saving --- application/Product/ProductController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/Product/ProductController.php b/application/Product/ProductController.php index 9ac5f4637..da3fa2626 100644 --- a/application/Product/ProductController.php +++ b/application/Product/ProductController.php @@ -66,7 +66,7 @@ class ProductController extends mfBaseController { $data['price_nne'] = Layout::commaToDot($r->price_nne); $data['price_nbe'] = Layout::commaToDot($r->price_nbe); $data['price'] = Layout::commaToDot($r->price); - $data['price_setup'] = $r->price_setup; + $data['price_setup'] = Layout::commaToDot($r->price_setup); $data['billing_period'] = $r->billing_period; $data['billing_delay'] = $r->billing_delay; $data['ivt_id'] = ($r->ivt_id) ? $r->ivt_id : null;
NameNetzeigentümer
getCompanyOrName()?>owner_id == $address_id) ? "checked='checked'" : ""?> disabled="disabled" /> $address_id, 'addresstype' => [$role]]) !== null): ?> - - $address_id])?>" class="text-danger" title="Löschen"> + $network->id, "address_id" => $address_id])?>" onclick="if(!confirm('Berechtigungen wirklich löschen?')) return false;" class="text-danger" title="Löschen">
- 1]) as $address): ?> addresstypes) && array_key_exists($address->id, $network->addresstypes)) continue; ?> diff --git a/Layout/default/Pop/Form.php b/Layout/default/Pop/Form.php index dfd5971e7..f28b12f4e 100644 --- a/Layout/default/Pop/Form.php +++ b/Layout/default/Pop/Form.php @@ -148,10 +148,10 @@ $(this).on('wheel.disableScroll', function (e) { e.preventDefault() }) - }) + }); $('form').on('blur', 'input[type=number]', function (e) { $(this).off('wheel.disableScroll') - }) + }); \ No newline at end of file diff --git a/Layout/default/Product/Form.php b/Layout/default/Product/Form.php new file mode 100644 index 000000000..eeda90436 --- /dev/null +++ b/Layout/default/Product/Form.php @@ -0,0 +1,235 @@ + + +
+
+ + +
+
+
+
+ +
+

Produkte

+
+
+
+ + +
+
+ +
+
+

id) ? "Produkt bearbeiten" : "Neues Produkt"?>

+ +
"> +
+
+ + + +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ + + +
+ +
+ +
+
+ + + +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+ + +

Zusatzdaten

+
+
+
+ +
+ +
+
+
+
+ + +
+
+
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+ + + +
+
+
+ +
+
+ +
+
+ + + + + \ No newline at end of file diff --git a/Layout/default/Product/Index.php b/Layout/default/Product/Index.php new file mode 100644 index 000000000..dcf08ab7d --- /dev/null +++ b/Layout/default/Product/Index.php @@ -0,0 +1,69 @@ + + +
+
+ + +
+
+
+ +

Produkte

+
+
+
+ + +
+
+ +
+
+
+

Liste aller Produkte

+
+ + + + + + + + + + + + + + + + + + + + + + + +
FremdproduktGruppeNameTechnologieVerkaufspreisVerr. Periode
external == 1) ? "" : ""?>productgroup->name?>name?>producttech->name?>price?>billing_period?>x Jährlich + $product->id])?>"> + $product->id])?>" class="text-danger" onclick="if(!confirm('Berechtigungen wirklich löschen?')) return false;" title="Produkt Löschen"> +
+
+
+ +
+
+ +
+
+ + + \ No newline at end of file diff --git a/Layout/default/footer.php b/Layout/default/footer.php index e9e847db0..bc40d9049 100644 --- a/Layout/default/footer.php +++ b/Layout/default/footer.php @@ -3,7 +3,7 @@
- the tool © 2021 Xinon GmbH - Made by fronk - Simulor Theme by Coderthemes + the tool © 2021 Xinon GmbH - Made by fronk
- + +
+ +
+
+ +
+
@@ -142,6 +155,13 @@
+
+ +
+ +
+
+
diff --git a/Layout/default/Product/Index.php b/Layout/default/Product/Index.php index dcf08ab7d..5f75c4d5c 100644 --- a/Layout/default/Product/Index.php +++ b/Layout/default/Product/Index.php @@ -10,7 +10,7 @@

Produkte

@@ -37,8 +37,11 @@
Gruppe Name TechnologieKundentyp Verkaufspreis Verr. PeriodeSLAIVT ID
productgroup->name?> name?> producttech->name?>producttech->customer_type)?> price?> billing_period?>x Jährlichsla->name?>ivt_id?> $product->id])?>"> $product->id])?>" class="text-danger" onclick="if(!confirm('Berechtigungen wirklich löschen?')) return false;" title="Produkt Löschen"> diff --git a/Layout/default/User/Index.php b/Layout/default/User/Index.php index ac8d39ae8..a81907d2f 100644 --- a/Layout/default/User/Index.php +++ b/Layout/default/User/Index.php @@ -13,7 +13,7 @@

Benutzer

diff --git a/Layout/default/menu.php b/Layout/default/menu.php index a0d431b15..5434efb8a 100644 --- a/Layout/default/menu.php +++ b/Layout/default/menu.php @@ -23,7 +23,6 @@
  • ">Benutzer
  • ">Neztgebiete
  • ">Produkte
  • -
  • ">Produktgruppen
  • diff --git a/application/Product/Product.php b/application/Product/Product.php index 47391993f..fd1b9ef69 100644 --- a/application/Product/Product.php +++ b/application/Product/Product.php @@ -17,5 +17,7 @@ class Product extends mfBaseModel { return null; } } + + return $this->$name; } } \ No newline at end of file diff --git a/application/Product/ProductController.php b/application/Product/ProductController.php index 18fdfa554..7b3a618e6 100644 --- a/application/Product/ProductController.php +++ b/application/Product/ProductController.php @@ -22,6 +22,7 @@ class ProductController extends mfBaseController { $this->layout()->setTemplate("Product/Form"); $this->layout()->set("productgroups", ProductgroupModel::getAll()); $this->layout()->set("producttechs", ProducttechModel::getAll()); + $this->layout()->set("slas", SlaModel::getAll()); } @@ -57,18 +58,24 @@ class ProductController extends mfBaseController { $data = []; $data['name'] = $r->name; $data['description'] = $r->description; + $data['sla_id'] = $r->sla_id; $data['external'] = ($r->external == 1) ? "1" : "0"; $data['price_nne'] = Layout::commaToDot($r->price_nne); $data['price_nbe'] = Layout::commaToDot($r->price_nbe); $data['price'] = Layout::commaToDot($r->price); $data['billing_period'] = $r->billing_period; + $data['ivt_id'] = ($r->ivt_id) ? $r->ivt_id : null; $data['note'] = $r->note; if(is_numeric($r->producttech_id)) { $data['producttech_id'] = $r->producttech_id; + } else { + $data['producttech_id'] = null; } if(is_numeric($r->productgroup_id)) { $data['productgroup_id'] = $r->productgroup_id; + } else { + $data['productgroup_id'] = null; } $data['edit_by'] = 1; @@ -105,7 +112,8 @@ class ProductController extends mfBaseController { if($r->producttech_id == "new") { $nt = []; $nt['name'] = $r->producttech_new_name; - $nt['code'] = $r->producttech_new_code; + $nt['rtrcode'] = $r->producttech_new_rtrcode; + $nt['customer_type'] = ($r->producttech_new_customer_type == "business") ? "business" : "residential"; $nt['description'] = $r->producttech_new_description; $nt['note'] = $r->producttech_new_note; $tech = ProducttechModel::create($nt); diff --git a/application/Product/ProductModel.php b/application/Product/ProductModel.php index 1882b431f..9bcb88580 100644 --- a/application/Product/ProductModel.php +++ b/application/Product/ProductModel.php @@ -3,6 +3,7 @@ class ProductModel { public $name = null; public $description = null; + public $sla_id = null; public $external = null; public $productgroup_id = null; public $producttech_id = null; @@ -10,6 +11,7 @@ class ProductModel { public $price_nne = null; public $price_nbe = null; public $billing_period = null; + public $ivt_id = null; public $note = null; public $create_by = null; diff --git a/application/Producttech/ProducttechModel.php b/application/Producttech/ProducttechModel.php index 67f11f657..e5e84bc8e 100644 --- a/application/Producttech/ProducttechModel.php +++ b/application/Producttech/ProducttechModel.php @@ -2,7 +2,8 @@ class ProducttechModel { public $name = null; - public $code = null; + public $rtrcode = null; + public $customer_type = null; public $description = null; public $note = null; @@ -115,13 +116,18 @@ class ProducttechModel { } } - if(array_key_exists("code", $filter)) { - $code = $db->escape($filter['code']); - if($code) { - $where .= " AND `code` like '$code'"; + if(array_key_exists("rtrcode", $filter)) { + $rtrcode = $db->escape($filter['rtrcode']); + if($rtrcode) { + $where .= " AND `code` like '$rtrcode'"; } } + if(array_key_exists("customer_type", $filter)) { + $customer_type = ($customer_type == "business") ? "business" : "residential"; + $where .= " AND `customer_type`='$customer_type'"; + } + //var_dump($filter, $where);exit; return $where; } diff --git a/application/Sla/Sla.php b/application/Sla/Sla.php new file mode 100644 index 000000000..1b5d08640 --- /dev/null +++ b/application/Sla/Sla.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("Sla", "*", "id=$id LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new Sla($data); + } + return $item; + } + + public static function getAll() { + $items = []; + + $db = FronkDB::singleton(); + + $res = $db->select("Sla", "*", "1 = 1 ORDER BY name"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new Sla($data); + } + } + return $items; + + } + + public static function getFirst() { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("Sla", "*", "$where ORDER BY name LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new Sla($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("Sla", "*", "$where ORDER BY name"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new Sla($data); + } + } + return $items; + } + + private function getSqlFilter($filter) { + $where = "1=1 "; + + $db = FronkDB::singleton(); + + //var_dump($filter);exit; + + if(array_key_exists("name", $filter)) { + $name = $db->escape($filter['name']); + if($name) { + $where .= " AND `name` like '$name'"; + } + } + + if(array_key_exists("nameLike", $filter)) { + $name = $db->escape($filter['nameLike']); + if($name) { + $where .= " AND `name` like '%$name%'"; + } + } + + //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 2c97abf47..810d5f8d7 100644 --- a/contrib/migrations/20210705-product-tables.sql +++ b/contrib/migrations/20210705-product-tables.sql @@ -2,6 +2,8 @@ CREATE TABLE `Product` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci NOT NULL, `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `customer_type` ENUM('residential','business') NOT NULL DEFAULT 'residential', + `sla_id` int NOT NULL, `external` tinyint(1) NOT NULL DEFAULT '0', `producttech_id` int DEFAULT NULL, `productgroup_id` int DEFAULT NULL, @@ -9,13 +11,14 @@ CREATE TABLE `Product` ( `price_nbe` decimal(12,2) DEFAULT NULL, `price` decimal(12,2) NOT NULL, `billing_period` int NOT NULL COMMENT 'in months', + `ivt_id` INT(11) NULL DEFAULT NULL, `note` text COLLATE utf8mb4_unicode_520_ci, `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 +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; CREATE TABLE `ProductNetwork` ( `id` int NOT NULL AUTO_INCREMENT, @@ -26,7 +29,7 @@ CREATE TABLE `ProductNetwork` ( `create` int NOT NULL, `edit` int NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; CREATE TABLE `Productattribute` ( `id` int NOT NULL AUTO_INCREMENT, @@ -42,7 +45,7 @@ CREATE TABLE `Productattribute` ( `create` int NOT NULL, `edit` int NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; CREATE TABLE `Productgroup` ( `id` int NOT NULL AUTO_INCREMENT, @@ -54,7 +57,7 @@ CREATE TABLE `Productgroup` ( `create` int NOT NULL, `edit` int NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; CREATE TABLE `Producttech` ( `id` int NOT NULL AUTO_INCREMENT, @@ -67,7 +70,7 @@ CREATE TABLE `Producttech` ( `create` int NOT NULL, `edit` int NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; CREATE TABLE `ProducttechAttribute` ( `id` int NOT NULL, @@ -80,4 +83,4 @@ CREATE TABLE `ProducttechAttribute` ( `edit_by` int NOT NULL, `create` int NOT NULL, `edit` int NOT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; diff --git a/lang/de.php b/lang/de.php index b689f0cf1..008799c9f 100644 --- a/lang/de.php +++ b/lang/de.php @@ -18,6 +18,7 @@ $l['supplier'] = "Lieferant"; $l['suppliers'] = "Lieferanten"; $l['contact'] = "Kontakt"; $l['billing'] = "Verrechnungsadresse"; - +$l['business'] = "Business"; +$l['residential'] = "Residential"; $lang['de'] = $l; \ No newline at end of file From c06c29530bedb838bb5dff4ce0ba1f3a2bacb4c9 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Mon, 5 Jul 2021 19:00:36 +0200 Subject: [PATCH 03/10] Added sql migrations for product --- contrib/migrations/20210705-product-tables.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/migrations/20210705-product-tables.sql b/contrib/migrations/20210705-product-tables.sql index 810d5f8d7..08f6dca5e 100644 --- a/contrib/migrations/20210705-product-tables.sql +++ b/contrib/migrations/20210705-product-tables.sql @@ -2,7 +2,6 @@ CREATE TABLE `Product` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci NOT NULL, `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, - `customer_type` ENUM('residential','business') NOT NULL DEFAULT 'residential', `sla_id` int NOT NULL, `external` tinyint(1) NOT NULL DEFAULT '0', `producttech_id` int DEFAULT NULL, @@ -11,7 +10,7 @@ CREATE TABLE `Product` ( `price_nbe` decimal(12,2) DEFAULT NULL, `price` decimal(12,2) NOT NULL, `billing_period` int NOT NULL COMMENT 'in months', - `ivt_id` INT(11) NULL DEFAULT NULL, + `ivt_id` int DEFAULT NULL, `note` text COLLATE utf8mb4_unicode_520_ci, `create_by` int NOT NULL, `edit_by` int NOT NULL, @@ -62,7 +61,8 @@ CREATE TABLE `Productgroup` ( CREATE TABLE `Producttech` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(1024) COLLATE utf8mb4_unicode_520_ci NOT NULL, - `code` varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL, + `rtrcode` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci NOT NULL, + `customer_type` enum('residential','business') COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT 'residential', `description` text COLLATE utf8mb4_unicode_520_ci NOT NULL, `note` text COLLATE utf8mb4_unicode_520_ci NOT NULL, `create_by` int NOT NULL, From 110c3fe71d4cd05a22a0981df1f3071da9237f98 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Mon, 5 Jul 2021 19:46:22 +0200 Subject: [PATCH 04/10] Added ProductNetwork --- Layout/default/Product/Form.php | 20 ++- Layout/default/Product/Index.php | 4 +- Layout/default/menu.php | 2 +- application/Product/Product.php | 13 ++ application/Product/ProductController.php | 19 +++ application/ProductNetwork/ProductNetwork.php | 5 + .../ProductNetwork/ProductNetworkModel.php | 120 ++++++++++++++++++ .../migrations/20210705-product-tables.sql | 21 ++- 8 files changed, 196 insertions(+), 8 deletions(-) create mode 100644 application/ProductNetwork/ProductNetwork.php create mode 100644 application/ProductNetwork/ProductNetworkModel.php diff --git a/Layout/default/Product/Form.php b/Layout/default/Product/Form.php index 57dab99f4..9202c87e7 100644 --- a/Layout/default/Product/Form.php +++ b/Layout/default/Product/Form.php @@ -78,7 +78,6 @@
    Neue Produktgruppe:
    Name: - Code: Beschreibung: Interne Notiz:
    @@ -127,6 +126,20 @@ +
    + +
    + +
    +
    + + +
    @@ -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 @@
    external == 1) ? "" : ""?> productgroup->name?> name?>producttech->name?>producttech->name?> (producttech->rtrcode?>) producttech->customer_type)?> price?> billing_period?>x Jährlichsla->name?>sla->id?> 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 From 002c2565ebb23d8f735e0e39a5d64686bae0c1c6 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Mon, 5 Jul 2021 19:53:31 +0200 Subject: [PATCH 05/10] showing networks in Product/Index list --- Layout/default/Product/Index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Layout/default/Product/Index.php b/Layout/default/Product/Index.php index 90989fac9..320052bb1 100644 --- a/Layout/default/Product/Index.php +++ b/Layout/default/Product/Index.php @@ -33,7 +33,7 @@ - + @@ -46,14 +46,14 @@ - + - + diff --git a/Layout/default/Product/Form.php b/Layout/default/Product/Form.php index 9202c87e7..b63326682 100644 --- a/Layout/default/Product/Form.php +++ b/Layout/default/Product/Form.php @@ -178,16 +178,18 @@ - -

    Zusatzdaten

    + attributes) && count($product->attributes)): ?> +

    Produktattribute

    -
    - -
    - + attributes as $attrib): ?> +
    + +
    + +
    -
    +
    diff --git a/Layout/default/Producttech/Form.php b/Layout/default/Producttech/Form.php new file mode 100644 index 000000000..7d507d2b5 --- /dev/null +++ b/Layout/default/Producttech/Form.php @@ -0,0 +1,235 @@ + + +
    +
    + + +
    +
    +
    +
    + +
    +

    Produkte

    +
    +
    +
    + + +
    +
    + +
    +
    +

    id) ? "Technologie bearbeiten" : "Neue Technologie"?>

    + +
    "> +
    +
    + + + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + + + +
    +
    + +

    Produktattribute

    +
    +
    + + attributes) && count($producttech->attributes)): ?> + attributes as $attribute): ?> +
    "> + +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    + + + +
    +

    Neues Attribut:

    +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    +
    + + +
    +
    +
    + +
    + +
    +
    +
    +
    + +
    + +
    + +
    +
    + + + + +
    +
    + +
    +
    + +
    +
    + + + + + \ No newline at end of file diff --git a/Layout/default/Producttech/Index.php b/Layout/default/Producttech/Index.php new file mode 100644 index 000000000..084878958 --- /dev/null +++ b/Layout/default/Producttech/Index.php @@ -0,0 +1,62 @@ + + +
    +
    + + +
    +
    +
    +
    + +
    +

    Produkttechnologien

    +
    +
    +
    + + +
    +
    + +
    +
    +
    +

    Liste aller Technologien

    +
    + + +
    FremdproduktNetzgebiete Gruppe Name Technologie
    external == 1) ? "" : ""?>networks)) ? array_shift($product->networks)->name . ((count($product->networks) > 1) ? ", ..." : "") : ""?> productgroup->name?> name?> producttech->name?> (producttech->rtrcode?>) producttech->customer_type)?> price?> billing_period?>x Jährlichsla->id?>sla->name?> ivt_id?> $product->id])?>"> From ad4ab5833257e114a09089ff0f5e41a47ae67276 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 6 Jul 2021 14:56:57 +0200 Subject: [PATCH 06/10] Attributes can be set in products now --- Layout/default/Address/Index.php | 2 +- Layout/default/Product/Form.php | 16 +- Layout/default/Producttech/Form.php | 235 ++++++++++++++++++ Layout/default/Producttech/Index.php | 62 +++++ Layout/default/menu.php | 7 +- application/Product/Product.php | 35 ++- application/Product/ProductController.php | 24 +- application/Product/ProductModel.php | 2 +- .../ProductAttribute/ProductAttribute.php | 33 +++ .../ProductAttributeController.php | 18 ++ .../ProductAttributeModel.php | 121 +++++++++ application/Producttech/Producttech.php | 27 ++ .../Producttech/ProducttechController.php | 133 ++++++++++ .../ProducttechAttribute.php | 23 ++ .../ProducttechAttributeController.php | 37 +++ .../ProducttechAttributeModel.php | 132 ++++++++++ 16 files changed, 893 insertions(+), 14 deletions(-) create mode 100644 Layout/default/Producttech/Form.php create mode 100644 Layout/default/Producttech/Index.php create mode 100644 application/ProductAttribute/ProductAttribute.php create mode 100644 application/ProductAttribute/ProductAttributeController.php create mode 100644 application/ProductAttribute/ProductAttributeModel.php create mode 100644 application/Producttech/ProducttechController.php create mode 100644 application/ProducttechAttribute/ProducttechAttribute.php create mode 100644 application/ProducttechAttribute/ProducttechAttributeController.php create mode 100644 application/ProducttechAttribute/ProducttechAttributeModel.php diff --git a/Layout/default/Address/Index.php b/Layout/default/Address/Index.php index 426240230..e9ec5e2d1 100644 --- a/Layout/default/Address/Index.php +++ b/Layout/default/Address/Index.php @@ -75,7 +75,7 @@ ["address_id" => $address->id]])?>" title="Benutzer anzeigen"> $address->id])?>"> - $address->id])?>" class="text-danger" title="Löschen"> + $address->id])?>" onclick="if(!confirm('Person/Firma wirklich löschen?')) return false;" class="text-danger" title="Löschen">
    + + + + + + + + + + + + +
    NameKundentyp
    name?>customer_type)?> + $tech->id])?>"> + $tech->id])?>" class="text-danger" onclick="if(!confirm('Technologie wirklich löschen?')) return false;" title="Technologie Löschen"> +
    + + + + + + + + + + + \ No newline at end of file diff --git a/Layout/default/menu.php b/Layout/default/menu.php index 6a3a6f52d..9711f6385 100644 --- a/Layout/default/menu.php +++ b/Layout/default/menu.php @@ -20,9 +20,14 @@
  • ["addresstype" => ["supplier"]]])?>">Lieferanten
  • +
  • + ">Produkte + +
  • ">Benutzer
  • ">Netzgebiete
  • -
  • ">Produkte
  • diff --git a/application/Product/Product.php b/application/Product/Product.php index 300e9d1f6..13259d899 100644 --- a/application/Product/Product.php +++ b/application/Product/Product.php @@ -5,6 +5,36 @@ class Product extends mfBaseModel { private $producttech; private $sla; private $networks; + private $attributes; + + public function loadAttributes() { + if(!$this->producttech_id) { + return false; + } + + $this->attributes = []; + + // get tech attribs + $ptattribs = ProducttechAttributeModel::search(['producttech_id' => $this->producttech_id]); + // fill atrribs with existing values of product attribs + foreach($ptattribs as $pta) { + $attrib = ProductAttributeModel::getFirst(['product_id' => $this->id, 'producttechattribute_id' => $pta->id]); + if(!$attrib) { + $attrib = new ProductAttribute(); + $attrib->product_id = $this->id; + $attrib->producttechattribute_id = $pta->id; + $attrib->value = $pta->value; + $attrib->note = $pta->note; + } + $attrib->name = $pta->name; + $attrib->displayname = $pta->displayname; + $attrib->description = $pta->description; + $this->attributes[$attrib->name] = $attrib; + } + + return true; + + } public function getProperty($name) { if($this->$name == null) { @@ -18,7 +48,10 @@ class Product extends mfBaseModel { return $this->networks; } - + if($name == "attributes") { + $this->loadAttributes(); + return $this->attributes; + } $classname = ucfirst($name); $idfield = $name."_id"; diff --git a/application/Product/ProductController.php b/application/Product/ProductController.php index d54186f6d..ad037b85d 100644 --- a/application/Product/ProductController.php +++ b/application/Product/ProductController.php @@ -35,6 +35,8 @@ class ProductController extends mfBaseController { $this->redirect("Product"); } + //var_dump($product->attributes);exit; + $this->layout()->set("product", $product); return $this->addAction(); @@ -49,7 +51,7 @@ class ProductController extends mfBaseController { $product = new Product($id); if(!$product->id) { $this->layout()->setFlash("Produkt nicht gefunden", "error"); - $this->redirect("Produkt"); + $this->redirect("Product"); } } else { $id = false; @@ -79,10 +81,10 @@ class ProductController extends mfBaseController { $data['productgroup_id'] = null; } - $data['edit_by'] = 1; + $data['edit_by'] = $this->me->id; if($mode == "add") { - $data['create_by'] = 1; + $data['create_by'] = $this->me->id; $product = ProductModel::create($data); } else { $product->update($data); @@ -141,6 +143,22 @@ class ProductController extends mfBaseController { $product->save(); } + if(is_array($r->attributes) && count($r->attributes)) { + foreach($r->attributes as $pta_id => $attribute_value) { + $attrib = ProductAttributeModel::getFirst(['product_id' => $new_id, 'producttechattribute_id' => $pta_id]); + if(!$attrib) { + $attrib = ProductAttributeModel::create([ + 'product_id' => $new_id, + 'producttechattribute_id' => $pta_id, + ]); + //var_dump($attrib);exit; + } + $attrib->value = $attribute_value; + $attrib->edit_by = $this->me->id; + $attrib->save(); + } + } + $this->layout()->setFlash("Produkt erfolgreich gespeichert.", "success"); $this->redirect("Product", "Edit", ['id' => $new_id]); } diff --git a/application/Product/ProductModel.php b/application/Product/ProductModel.php index 9bcb88580..e1dc9aee8 100644 --- a/application/Product/ProductModel.php +++ b/application/Product/ProductModel.php @@ -94,7 +94,7 @@ class ProductModel { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); - $res = $db->select("Product", "*", "$where ORDER BY name, owner_id"); + $res = $db->select("Product", "*", "$where ORDER BY producttech_id, name"); if($db->num_rows($res)) { while($data = $db->fetch_object($res)) { $items[] = new Product($data); diff --git a/application/ProductAttribute/ProductAttribute.php b/application/ProductAttribute/ProductAttribute.php new file mode 100644 index 000000000..f9ce6a4a0 --- /dev/null +++ b/application/ProductAttribute/ProductAttribute.php @@ -0,0 +1,33 @@ +$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); + + if($this->$name->id) { + return $this->$name; + } else { + return null; + } + } + + return $this->$name; + } +} \ No newline at end of file diff --git a/application/ProductAttribute/ProductAttributeController.php b/application/ProductAttribute/ProductAttributeController.php new file mode 100644 index 000000000..cbcc0ddd1 --- /dev/null +++ b/application/ProductAttribute/ProductAttributeController.php @@ -0,0 +1,18 @@ +needlogin=true; + $me = new User(); + $me->loadMe(); + $this->me = $me; + $this->layout()->set("me",$me); + /* + if(!$me->isAdmin()) { + $this->redirect("Dashboard"); + }*/ + } + + +} \ No newline at end of file diff --git a/application/ProductAttribute/ProductAttributeModel.php b/application/ProductAttribute/ProductAttributeModel.php new file mode 100644 index 000000000..959483f61 --- /dev/null +++ b/application/ProductAttribute/ProductAttributeModel.php @@ -0,0 +1,121 @@ + $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("ProductAttribute", "*", "id=$id LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new ProductAttribute($data); + } + return $item; + } + + public static function getAll() { + $items = []; + + $db = FronkDB::singleton(); + + $res = $db->select("ProductAttribute", "*", "1 = 1 ORDER BY product_id, producttechattribute_id"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[$data->id] = new ProductAttribute($data); + } + } + return $items; + + } + + public static function getFirst($filter) { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("ProductAttribute", "*", "$where ORDER BY product_id, producttechattribute_id"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new ProductAttribute($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("ProductAttribute", "*", "$where ORDER BY name"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[$data->id] = new ProductAttribute($data); + } + } + return $items; + } + + private function getSqlFilter($filter) { + $where = "1=1 "; + + $db = FronkDB::singleton(); + + 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("producttechattribute_id", $filter)) { + $producttechattribute_id = $filter['producttechattribute_id']; + if(is_numeric($producttechattribute_id)) { + $where .= " AND `producttechattribute_id` = $producttechattribute_id"; + } + } + + + //var_dump($filter, $where);exit; + return $where; + } + +} \ No newline at end of file diff --git a/application/Producttech/Producttech.php b/application/Producttech/Producttech.php index 3ba28e7e0..11d0ca7f5 100644 --- a/application/Producttech/Producttech.php +++ b/application/Producttech/Producttech.php @@ -1,5 +1,32 @@ $name == null) { + + if($name == "attributes") { + $this->attributes = []; + $producttechAttributes = ProducttechAttributeModel::search(['producttech_id' => $this->id]); + foreach($producttechAttributes as $pta) { + $this->attributes[$pta->id] = $pta; + } + return $this->attributes; + } + + + $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/Producttech/ProducttechController.php b/application/Producttech/ProducttechController.php new file mode 100644 index 000000000..48b27ade9 --- /dev/null +++ b/application/Producttech/ProducttechController.php @@ -0,0 +1,133 @@ +needlogin=true; + $me = new User(); + $me->loadMe(); + $this->me = $me; + $this->layout()->set("me",$me); + /* + if(!$me->isAdmin()) { + $this->redirect("Dashboard"); + }*/ + } + + protected function indexAction() { + $this->layout()->setTemplate("Producttech/Index"); + $this->layout()->set("producttechs", ProducttechModel::getAll()); + } + + protected function addAction() { + $this->layout()->setTemplate("Producttech/Form"); + + } + + protected function editAction() { + $tech_id = $this->request->id; + $tech = new Producttech($tech_id); + if(!$tech->id) { + $this->layout()->setFlash("Technologie nicht gefunden.", "error"); + $this->redirect("Producttech"); + } + + $this->layout()->set("producttech", $tech); + return $this->addAction(); + } + + protected function saveAction() { + $r = $this->request; + //var_dump($r); + //var_dump($r->attributes); + //exit; + $id = $r->id; + if(is_numeric($id) && $id > 0) { + $mode = "edit"; + $producttech = new Producttech($id); + if(!$producttech->id) { + $this->layout()->setFlash("Technologie nicht gefunden", "error"); + $this->redirect("Producttech"); + } + } else { + $id = false; + $mode = "add"; + } + + $data = []; + $data['name'] = $r->name; + $data['customer_type'] = $r->customer_type; + $data['description'] = $r->description; + $data['note'] = $r->note; + + $data['edit_by'] = $this->me->id; + + if($mode == "add") { + $data['create_by'] = $this->me->id; + $producttech = ProducttechModel::create($data); + } else { + $producttech->update($data); + } + + //var_dump($address);exit; + + $new_id = $producttech->save(); + if(!$new_id) { + $this->layout()->setFlash("Fehler beim Speichern", "error"); + $this->layout()->set("producttech", $producttech); + return $this->add(); + } + + // handle ProductAttributes + if(is_array($r->attributes) && count($r->attributes)) { + foreach($r->attributes as $aid => $attribute) { + if(!trim($attribute['name']) || !trim($attribute['displayname'])) { + continue; + } + + $a = []; + $a['name'] = $attribute['name']; + $a['producttech_id'] = $new_id; + $a['displayname'] = $attribute['displayname']; + $a['value'] = $attribute['value']; + $a['description'] = $attribute['description']; + $a['note'] = $attribute['note']; + $a['edit_by'] = $this->me->id; + + if($aid == "new") { + $attrib = ProducttechAttributeModel::create($a); + } elseif(is_numeric($aid) && $aid > 0) { + $attrib = new ProducttechAttribute($aid); + $attrib->update($a); + } else { + continue; + } + + $attrib->save(); + } + } + + $this->layout()->setFlash("Technologie erfolgreich gespeichert.", "success"); + $this->redirect("Producttech", "edit", ['id' => $new_id]); + + } + + protected function delete() { + $id = $this->request->id; + + $tech = new Producttech($id); + if(!$tech->id || $tech->id != $id) { + $this->layout()->setFlash("Technologie nicht gefunden.", "error"); + $this->redirect("Producttech"); + } + + if(ProductModel::search(["producttech_id" => $tech->id])) { + $this->layout()->setFlash("Technologie kann nicht gelöscht werden, da sie in Verwendung ist.", "error"); + $this->redirect("Producttech"); + } + + // check if Product is unused + $tech->delete(); + $this->redirect("Producttech"); + } +} \ No newline at end of file diff --git a/application/ProducttechAttribute/ProducttechAttribute.php b/application/ProducttechAttribute/ProducttechAttribute.php new file mode 100644 index 000000000..a5dafef73 --- /dev/null +++ b/application/ProducttechAttribute/ProducttechAttribute.php @@ -0,0 +1,23 @@ +$name == null) { + + $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/ProducttechAttribute/ProducttechAttributeController.php b/application/ProducttechAttribute/ProducttechAttributeController.php new file mode 100644 index 000000000..664540506 --- /dev/null +++ b/application/ProducttechAttribute/ProducttechAttributeController.php @@ -0,0 +1,37 @@ +needlogin=true; + $me = new User(); + $me->loadMe(); + $this->me = $me; + $this->layout()->set("me",$me); + /* + if(!$me->isAdmin()) { + $this->redirect("Dashboard"); + }*/ + } + + protected function deleteAction() { + $id = $this->request->id; + + $ta = new ProducttechAttribute($id); + if(!$ta->id || $ta->id != $id) { + $this->layout()->setFlash("Attribut nicht gefunden.", "error"); + $this->redirect("Producttech"); + } + + /*if(ProductModel::search(["producttech_id" => $tech->id])) { + $this->layout()->setFlash("Technologie kann nicht gelöscht werden, da sie in Verwendung ist.", "error"); + $this->redirect("Producttech"); + }*/ + + $producttech_id = $ta->producttech_id; + + // check if Product is unused + $ta->delete(); + $this->redirect("Producttech", "edit", ['id' => $producttech_id]); + } +} \ No newline at end of file diff --git a/application/ProducttechAttribute/ProducttechAttributeModel.php b/application/ProducttechAttribute/ProducttechAttributeModel.php new file mode 100644 index 000000000..cf98a9c10 --- /dev/null +++ b/application/ProducttechAttribute/ProducttechAttributeModel.php @@ -0,0 +1,132 @@ + $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("ProducttechAttribute", "*", "id=$id LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new ProducttechAttribute($data); + } + return $item; + } + + public static function getAll() { + $items = []; + + $db = FronkDB::singleton(); + + $res = $db->select("ProducttechAttribute", "*", "1 = 1 ORDER BY name"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[$data->id] = new ProducttechAttribute($data); + } + } + return $items; + + } + + public static function getFirst() { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("ProducttechAttribute", "*", "$where ORDER BY name"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new ProducttechAttribute($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("ProducttechAttribute", "*", "$where ORDER BY name"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[$data->id] = new ProducttechAttribute($data); + } + } + return $items; + } + + private function getSqlFilter($filter) { + $where = "1=1 "; + + $db = FronkDB::singleton(); + + //var_dump($filter);exit; + if(array_key_exists("name", $filter)) { + $name = $db->escape($filter['name']); + if($name) { + $where .= " AND `name` like '$name'"; + } + } + + if(array_key_exists("nameLike", $filter)) { + $name = $db->escape($filter['nameLike']); + if($name) { + $where .= " AND `name` like '%$name%'"; + } + } + + if(array_key_exists("producttech_id", $filter)) { + $producttech_id = $db->escape($filter['producttech_id']); + if(is_numeric($producttech_id)) { + $where .= " AND `producttech_id` = $producttech_id"; + } + } + + + //var_dump($filter, $where);exit; + return $where; + } + +} \ No newline at end of file From 7ed8c473743fbaa888f5df87855de6f95572b0d2 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 6 Jul 2021 15:44:47 +0200 Subject: [PATCH 07/10] Added price_setup and billing_delay to Product --- Layout/default/Product/Form.php | 14 ++++++++++++- Layout/default/Product/Index.php | 2 +- application/Product/ProductController.php | 2 ++ .../migrations/20210705-product-tables.sql | 21 +++++++++---------- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/Layout/default/Product/Form.php b/Layout/default/Product/Form.php index b63326682..a70222929 100644 --- a/Layout/default/Product/Form.php +++ b/Layout/default/Product/Form.php @@ -141,7 +141,13 @@
    - + +
    + +
    +
    +
    +
    @@ -167,6 +173,12 @@
    +
    + +
    + +
    +
    diff --git a/Layout/default/Product/Index.php b/Layout/default/Product/Index.php index 320052bb1..384cb2120 100644 --- a/Layout/default/Product/Index.php +++ b/Layout/default/Product/Index.php @@ -49,7 +49,7 @@
    networks)) ? array_shift($product->networks)->name . ((count($product->networks) > 1) ? ", ..." : "") : ""?> productgroup->name?> name?>producttech->name?> (producttech->rtrcode?>)producttech->name?> (attributes['rtrcode']->value?>) producttech->customer_type)?> price?> billing_period?>x Jährlichnetworks)) ? array_shift($product->networks)->name . ((count($product->networks) > 1) ? ", ..." : "") : ""?> productgroup->name?> name?>producttech->name?> (attributes['rtrcode']->value?>)producttech->name?> (attributes[TT_ATTRIB_RTRTECHCODE_NAME]->value?>) producttech->customer_type)?> price?> billing_period?>x Jährlich