| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- require_once(__DIR__."/database.php");
- class Product
- {
- function __construct()
- {
- $this->db = new Database();
- }
- function create($product_id, $value)
- {
- $query = "INSERT INTO ".$this->db->product_table." VALUES('".$product_id."'";
- for($i = 0; $i < count($value); $i++)
- $query .= ", '".str_replace("'", "\'", $value[$i])."'";
- $query .= ")";
- $this->db->query($query);
- }
- function update($product_id, $value)
- {
- $query = "UPDATE ".$this->db->product_table." SET ";
- $query .= "name='".str_replace("'", "\'", $value[0])."', ";
- $query .= "details='".str_replace("'", "\'", $value[1])."', ";
- $query .= "category_id='".str_replace("'", "\'", $value[2])."', ";
- $query .= "tax_id='".str_replace("'", "\'", $value[3])."', ";
- $query .= "available='".str_replace("'", "\'", $value[4])."', ";
- $query .= "group_id='".str_replace("'", "\'", $value[5])."', ";
- $query .= "order_number='".str_replace("'", "\'", $value[6])."', ";
- $query .= "anmerkung='".str_replace("'", "\'", $value[7])."' ";
- $query .= "WHERE product_id='".$product_id."'";
- //echo $query;
- $this->db->query($query);
- }
- function delete($product_id)
- {
- $query = "DELETE FROM ".$this->db->product_table." WHERE product_id='$product_id'";
- $this->db->query($query);
- }
- function get($product_id = "", $row_names = array(), $search = "")
- {
- if($product_id == "")
- {
- if(count($row_names) == 0)
- $query = "SELECT * FROM ".$this->db->product_table;
- else
- {
- $query = "SELECT ".$row_names[0];
- for($i = 1; $i < count($row_names); $i++)
- $query .= ", ".$row_names[$i];
- $query .= " FROM ".$this->db->product_table;
- }
- if($search != "")
- $query .= " WHERE ".$search;
- $query .= " ORDER BY product_id ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- else
- {
- $query = "SELECT * FROM ".$this->db->product_table." WHERE product_id='".$product_id."'";
- $query .= " ORDER BY product_id ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- }
- function getAmountByDate($product_id, $date_from, $date_to, $assistant_id)
- {
- $query = "SELECT SUM(".$this->db->bill_product_table.".amount) FROM ".$this->db->bill_table." ";
- $query .= "RIGHT JOIN ".$this->db->bill_product_table." ON ".$this->db->bill_table.".bill_id=".$this->db->bill_product_table.".bill_id ";
- $query .= "WHERE ".$this->db->bill_table.".date>='".$date_from."' ";
- $query .= "AND ".$this->db->bill_table.".date<='".$date_to."' ";
- $query .= "AND ".$this->db->bill_table.".assistant_id<='".$assistant_id."' ";
- $query .= "AND ".$this->db->bill_product_table.".product_id='".$product_id."' ";
- $retval = $this->db->fetchRows($this->db->query($query));
- return $retval[0][0];
- }
- function getBillsByDate($product_id, $date_from, $date_to, $assistant_id)
- {
- $query = "SELECT DISTINCT ".$this->db->bill_table.".bill_number,SUM(".$this->db->bill_product_table.".amount) FROM ".$this->db->bill_table." ";
- $query .= "RIGHT JOIN ".$this->db->bill_product_table." ON ".$this->db->bill_table.".bill_id=".$this->db->bill_product_table.".bill_id ";
- $query .= "WHERE ".$this->db->bill_table.".date>='".$date_from."' ";
- $query .= "AND ".$this->db->bill_table.".date<='".$date_to."' ";
- $query .= "AND ".$this->db->bill_table.".assistant_id<='".$assistant_id."' ";
- $query .= "AND ".$this->db->bill_product_table.".product_id='".$product_id."' ";
- $query .= "GROUP BY ".$this->db->bill_table.".customer_id ";
- return $this->db->fetchRows($this->db->query($query));
- }
- function getCustomersByDate($product_id, $date_from, $date_to, $assistant_id)
- {
- $query = "SELECT DISTINCT ".$this->db->bill_table.".customer_id,SUM(".$this->db->bill_product_table.".amount) FROM ".$this->db->bill_table." ";
- $query .= "RIGHT JOIN ".$this->db->bill_product_table." ON ".$this->db->bill_table.".bill_id=".$this->db->bill_product_table.".bill_id ";
- $query .= "WHERE ".$this->db->bill_table.".date>='".$date_from."' ";
- $query .= "AND ".$this->db->bill_table.".date<='".$date_to."' ";
- $query .= "AND ".$this->db->bill_table.".assistant_id<='".$assistant_id."' ";
- $query .= "AND ".$this->db->bill_product_table.".product_id='".$product_id."' ";
- $query .= "GROUP BY ".$this->db->bill_table.".customer_id ";
- return $this->db->fetchRows($this->db->query($query));
- }
- function getByFilter($search_product, $search_category, $item_offset, $item_count)
- {
- $query = "SELECT * FROM ".$this->db->product_table." ";
- if($search_product != "" || $search_category != "")
- {
- $query .= " WHERE ";
- if($search_product != "")
- $query .= " (product_id LIKE '%".$search_product."%' OR name LIKE '%".$search_product."%' OR details LIKE '%".$search_product."%') ";
- if($search_category != "" && $search_product != "")
- $query .= " AND category_id=".$search_category." ";
- elseif($search_category != "" && $search_product == "")
- $query .= " category_id=".$search_category." ";
- }
- $query .= " ORDER BY product_id ASC";
- if($item_count != 0)
- $query .= " LIMIT ".$item_count." ";
- if($item_offset != 0)
- $query .= " OFFSET ".$item_offset." ";
- return $this->db->fetchRows($this->db->query($query));
- }
- function getCountByFilter($search_product, $search_category)
- {
- $query = "SELECT count(*) FROM ".$this->db->product_table." ";
- if($search_product != "" || $search_category != "")
- {
- $query .= " WHERE ";
- if($search_product != "")
- $query .= " (product_id LIKE '%".$search_product."%' OR name LIKE'%".$search_product."%' OR details LIKE '%".$search_product."%') AND ";
- if($search_category != "")
- $query .= " category_id=".$search_category." ";
- else
- $query .= " 1=1 ";
- }
- $query .= " ORDER BY product_id ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- }
- ?>
|