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)); } } ?>