Merge branch 'fronkdev' into 'master'
Added IVT product export Admin function See merge request fronk/thetool!16
This commit is contained in:
@@ -37,6 +37,9 @@
|
||||
<div class="row col-12">
|
||||
<div><a href="<?=self::getUrl("Admin", "ivtImportMatchProducts")?>">IVT Produkte zu thetool Produkte matchen</a></div>
|
||||
</div>
|
||||
<div class="row col-12">
|
||||
<div><a href="<?=self::getUrl("Admin", "ivtDownloadActiveProducts")?>">Produkte in Verwendung herunterladen</a></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
13
Layout/default/Admin/ivt_active_products.csv.php
Normal file
13
Layout/default/Admin/ivt_active_products.csv.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
ob_end_flush();
|
||||
header("Content-type: text/csv");
|
||||
header('Content-disposition: attachment; filename="ivtproducts-active-'.date('Y-m-d_H-i-s').'.csv"');
|
||||
?>
|
||||
IVT ID;Typ;Produkt;Standardpreis;Anzahl Kunden;Kunde
|
||||
<?php
|
||||
$types = array('-----', 'xDSL', 'FTTH', 'FTTB', 'DOCSIS', 'Funk', 'Telefon', 'Webhosting', 'Carrier', 'Housing', 'TV');
|
||||
foreach($products as $product_id => $product):
|
||||
?>
|
||||
<?=$product_id?>;"<?=$types[$product['product']->typ]?>";"<?=$product['product']->name?>";<?=$product['product']->price?>;<?=$product['count']?>;<?=($product['customer']) ? $product['customer'] : ""?>;
|
||||
<?php
|
||||
endforeach;
|
||||
@@ -77,4 +77,33 @@ class AdminController extends mfBaseController {
|
||||
$this->layout()->set("products", ProductModel::getActive());
|
||||
}
|
||||
|
||||
protected function ivtDownloadActiveProducts() {
|
||||
$ivtproducts = IvtProductModel::getAll();
|
||||
|
||||
$products = [];
|
||||
|
||||
foreach($ivtproducts as $product) {
|
||||
$active_count = IvtCustomerProductModel::count(['pid' => $product->id]);
|
||||
if(!$active_count) continue;
|
||||
|
||||
$new_product = [];
|
||||
$new_product["product"] = $product;
|
||||
$new_product["count"] = $active_count;
|
||||
$new_product["customer"] = false;
|
||||
|
||||
if($active_count == 1) {
|
||||
$cp = IvtCustomerProductModel::getFirst(["pid" => $product->id]);
|
||||
//var_dump($cp);exit;
|
||||
$customer = $cp->customer;
|
||||
//var_dump($customer);exit;
|
||||
$new_product["customer"] = ($customer->company) ? $customer->company : $customer->firstname." ".$customer->surname;
|
||||
}
|
||||
|
||||
$products[$product->id] = $new_product;
|
||||
}
|
||||
|
||||
$this->layout()->setTemplate("Admin/ivt_active_products.csv");
|
||||
$this->layout()->set("products", $products);
|
||||
}
|
||||
|
||||
}
|
||||
75
application/IvtCustomerProduct/IvtCustomerProduct.php
Normal file
75
application/IvtCustomerProduct/IvtCustomerProduct.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
class IvtCustomerProduct extends mfBaseModel {
|
||||
protected $forcestr = [];
|
||||
private $customer;
|
||||
|
||||
/**
|
||||
* Takes ID or DB row as arguments
|
||||
* @param id or table row $_
|
||||
*/
|
||||
public function __construct($_=NULL) {
|
||||
$this->log = mfLoghandler::singleton();
|
||||
$this->data = new stdClass();
|
||||
$this->table = "products";
|
||||
|
||||
$this->db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
if(is_numeric($_)) {
|
||||
$this->fetch($_);
|
||||
} elseif(is_object($_)) {
|
||||
$this->load($_);
|
||||
}
|
||||
}
|
||||
|
||||
public function save() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "product") {
|
||||
$ivtproduct = new IvtProduct($this->pid);
|
||||
if($ivtproduct->id) {
|
||||
$this->ivtproduct = $ivtproduct;
|
||||
}
|
||||
return $this->ivtproduct;
|
||||
}
|
||||
|
||||
if($name == "customer") {
|
||||
$ivtcustomer = new IvtCustomer($this->cid);
|
||||
if($ivtcustomer->id) {
|
||||
$this->ivtcustomer = $ivtcustomer;
|
||||
}
|
||||
return $this->ivtcustomer;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
||||
if(!$this->$name) {
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
}
|
||||
|
||||
if($this->$name->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
|
||||
public function __debugInfo() {
|
||||
$vars = get_object_vars($this);
|
||||
if(is_object($vars['db'])) $vars['db'] = "object(FronkDB)";
|
||||
if(is_object($vars['log'])) $vars['log'] = 'object(mfLoghandler)';
|
||||
return $vars;
|
||||
}
|
||||
|
||||
}
|
||||
121
application/IvtCustomerProduct/IvtCustomerProductModel.php
Normal file
121
application/IvtCustomerProduct/IvtCustomerProductModel.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
class IvtCustomerProductModel {
|
||||
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
$res = $db->select("customer_product", "*", "1=1 ORDER BY id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new IvtCustomerProduct($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
public static function getFirst($filter = []) {
|
||||
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("customer_product", "*", "$where ORDER BY id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new IvtCustomerProduct($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) cnt FROM customer_product WHERE $where ORDER by id";
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return $data->cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit = false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM customer_product WHERE $where ORDER by cid,pid,sid,id";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($count)) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new IvtCustomerProduct($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
/*
|
||||
if(array_key_exists("status_id", $filter)) {
|
||||
$status_id = $filter['status_id'];
|
||||
if(is_numeric($status_id)) {
|
||||
$where .= " AND IvtCustomerProduct.status_id=$status_id";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("street", $filter)) {
|
||||
$street = FronkDB::singleton()->escape($filter["street"]);
|
||||
if($street) {
|
||||
$where .= " AND street like '%$street%'";
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if(array_key_exists("cid", $filter)) {
|
||||
$cid = $filter['cid'];
|
||||
if(is_numeric($cid)) {
|
||||
$where .= " AND cid=$cid";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("pid", $filter)) {
|
||||
$pid = $filter['pid'];
|
||||
if(is_numeric($pid)) {
|
||||
$where .= " AND pid=$pid";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("sid", $filter)) {
|
||||
$sid = $filter['sid'];
|
||||
if(is_numeric($sid)) {
|
||||
$where .= " AND sid=$sid";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
36
application/IvtProductMatch/IvtProductMatch.php
Normal file
36
application/IvtProductMatch/IvtProductMatch.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
class IvtProduct extends mfBaseModel {
|
||||
private $product;
|
||||
private $ivtproduct;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "ivtproduct") {
|
||||
$ivtproduct = new IvtProduct($this->ivt_id);
|
||||
if($ivtproduct->id) {
|
||||
$this->ivtproduct = $ivtproduct;
|
||||
}
|
||||
return $this->ivtproduct;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
||||
if(!$this->$name) {
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
}
|
||||
|
||||
if($this->$name->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
||||
111
application/IvtProductMatch/IvtProductMatchModel.php
Normal file
111
application/IvtProductMatch/IvtProductMatchModel.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
class IvtProuctMatchModel {
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new Contract();
|
||||
|
||||
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 getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
$res = $db->select("IvtProuctMatch", "*", "1=1 ORDER BY ivt_name,id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new IvtProuctMatch($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("IvtProuctMatch", "*", "$where ORDER BY ivt_name,id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new IvtProuctMatch($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit = false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM IvtProuctMatch $where ORDER by ivt_name,id";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($count)) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new IvtProuctMatch($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
if(array_key_exists("ivt_id", $filter)) {
|
||||
$ivt_id = $filter['ivt_id'];
|
||||
if(is_numeric($ivt_id)) {
|
||||
$where .= " AND IvtProuctMatch.ivt_id=$ivt_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("ivt_name", $filter)) {
|
||||
$ivt_name = FronkDB::singleton()->escape($filter["ivt_name"]);
|
||||
if($ivt_name) {
|
||||
$where .= " AND IvtProuctMatch.ivt_name like '%$ivt_name%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("product_id", $filter)) {
|
||||
$product_id = $filter['product_id'];
|
||||
if(is_numeric($product_id)) {
|
||||
$where .= " AND IvtProuctMatch.product_id=$product_id";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user