Added ProductNetwork
This commit is contained in:
@@ -78,7 +78,6 @@
|
||||
<div class="col-lg-2">Neue Produktgruppe:</div>
|
||||
<div class="col-lg-10">
|
||||
Name: <input type="text" class="form-control" name="productgroup_new_name" id="productgroup_new_name" value="<?=$productgroup_new_name?>">
|
||||
Code: <input type="text" class="form-control" name="productgroup_new_code" id="productgroup_new_code" value="<?=$productgroup_new_code?>">
|
||||
Beschreibung: <textarea class="form-control" name="productgroup_new_description" id="productgroup_new_description"><?=$productgroup_new_description?></textarea>
|
||||
Interne Notiz: <textarea class="form-control" name="productgroup_new_note" id="productgroup_new_note"><?=$productgroup_new_note?></textarea>
|
||||
</div>
|
||||
@@ -127,6 +126,20 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="networks">Netzgebiete</label>
|
||||
<div class="col-lg-10">
|
||||
<select class="select2 form-control select2-multiple" name="networks[]" id="networks" multiple="multiple" data-placeholder="Choose ...">
|
||||
<option></option>
|
||||
<?php foreach($networks as $network): ?>
|
||||
<option value="<?=$network->id?>" <?=(array_key_exists($network->id, $product->networks)) ? "selected='selected'" : ""?>><?=$network->name?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="price">Verkaufspreis Netto</label>
|
||||
<div class="col-lg-10">
|
||||
@@ -219,7 +232,10 @@
|
||||
allowClear: true,
|
||||
placeholder: ""
|
||||
});
|
||||
|
||||
$("#networks").select2({
|
||||
allowClear: true,
|
||||
placeholder: ""
|
||||
});
|
||||
|
||||
$('#productgroup_id').change(function() {
|
||||
var value = $('#productgroup_id option:selected').val();
|
||||
|
||||
@@ -49,11 +49,11 @@
|
||||
<td><?=($product->external == 1) ? "<i class='fas fa-check text-success'></i>" : ""?></td>
|
||||
<td><?=$product->productgroup->name?></td>
|
||||
<td><?=$product->name?></td>
|
||||
<td><?=$product->producttech->name?></td>
|
||||
<td><?=$product->producttech->name?> (<?=$product->producttech->rtrcode?>)</td>
|
||||
<td><?=__($product->producttech->customer_type)?></td>
|
||||
<td><?=$product->price?></td>
|
||||
<td><?=$product->billing_period?>x Jährlich</td>
|
||||
<td><?=$product->sla->name?></td>
|
||||
<td><?=$product->sla->id?></td>
|
||||
<td><?=$product->ivt_id?></td>
|
||||
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
||||
<a href="<?=self::getUrl("Product", "edit", ["id" => $product->id])?>"><i class="far fa-edit" title="Produkt Bearbeiten"></i></a>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="<?=self::getUrl("User")?>">Benutzer</a></li>
|
||||
<li><a href="<?=self::getUrl("Network")?>">Neztgebiete</a></li>
|
||||
<li><a href="<?=self::getUrl("Network")?>">Netzgebiete</a></li>
|
||||
<li><a href="<?=self::getUrl("Product")?>">Produkte</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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") {
|
||||
|
||||
5
application/ProductNetwork/ProductNetwork.php
Normal file
5
application/ProductNetwork/ProductNetwork.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class ProductNetwork extends mfBaseModel {
|
||||
|
||||
}
|
||||
120
application/ProductNetwork/ProductNetworkModel.php
Normal file
120
application/ProductNetwork/ProductNetworkModel.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
class ProductNetworkModel {
|
||||
public $product_id = null;
|
||||
public $network_id = null;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new ProductNetwork();
|
||||
|
||||
foreach($data as $field => $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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
Reference in New Issue
Block a user