Added SLA to Products

This commit is contained in:
Frank Schubert
2021-07-05 18:43:03 +02:00
parent 4fae807663
commit 771c0f4bc2
12 changed files with 192 additions and 18 deletions
+2
View File
@@ -17,5 +17,7 @@ class Product extends mfBaseModel {
return null;
}
}
return $this->$name;
}
}
+9 -1
View File
@@ -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);
+2
View File
@@ -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;
+11 -5
View File
@@ -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;
}
+5
View File
@@ -0,0 +1,5 @@
<?php
class Sla extends mfBaseModel {
}
+122
View File
@@ -0,0 +1,122 @@
<?php
class SlaModel {
public $name = null;
public $description = null;
public $note = null;
public $create_by = null;
public $edit_by = null;
public $create = null;
public $edit = null;
public static function create(Array $data) {
$model = new Sla();
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("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;
}
}