diff --git a/Layout/default/Admin/Index.php b/Layout/default/Admin/Index.php index 2eafc512f..228e56382 100644 --- a/Layout/default/Admin/Index.php +++ b/Layout/default/Admin/Index.php @@ -37,6 +37,9 @@
+ diff --git a/Layout/default/Admin/ivt_active_products.csv.php b/Layout/default/Admin/ivt_active_products.csv.php new file mode 100644 index 000000000..00cc4b00b --- /dev/null +++ b/Layout/default/Admin/ivt_active_products.csv.php @@ -0,0 +1,13 @@ + +IVT ID;Typ;Produkt;Standardpreis;Anzahl Kunden;Kunde + $product): +?> +=$product_id?>;"=$types[$product['product']->typ]?>";"=$product['product']->name?>";=$product['product']->price?>;=$product['count']?>;=($product['customer']) ? $product['customer'] : ""?>; +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); + } + } \ No newline at end of file diff --git a/application/IvtCustomerProduct/IvtCustomerProduct.php b/application/IvtCustomerProduct/IvtCustomerProduct.php new file mode 100644 index 000000000..21686c6f6 --- /dev/null +++ b/application/IvtCustomerProduct/IvtCustomerProduct.php @@ -0,0 +1,75 @@ +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; + } + +} \ No newline at end of file diff --git a/application/IvtCustomerProduct/IvtCustomerProductModel.php b/application/IvtCustomerProduct/IvtCustomerProductModel.php new file mode 100644 index 000000000..4e09975b6 --- /dev/null +++ b/application/IvtCustomerProduct/IvtCustomerProductModel.php @@ -0,0 +1,121 @@ +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; + } + +} diff --git a/application/IvtProductMatch/IvtProductMatch.php b/application/IvtProductMatch/IvtProductMatch.php new file mode 100644 index 000000000..185a2a19e --- /dev/null +++ b/application/IvtProductMatch/IvtProductMatch.php @@ -0,0 +1,36 @@ +$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; + } +} \ No newline at end of file diff --git a/application/IvtProductMatch/IvtProductMatchModel.php b/application/IvtProductMatch/IvtProductMatchModel.php new file mode 100644 index 000000000..4eec0406d --- /dev/null +++ b/application/IvtProductMatch/IvtProductMatchModel.php @@ -0,0 +1,111 @@ + $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; + } + +}