| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- require_once("DataBase/database.php");
- class Price
- {
- function __construct()
- {
- $this->db = new Database();
- }
- function exists($priceset_id, $product_id)
- {
- $query = "SELECT * FROM ".$this->db->price_table." WHERE priceset_id='".$priceset_id."' AND product_id='".$product_id."'";
- if(count($this->db->fetchRows($this->db->query($query))) > 0)
- return true;
- else
- return false;
- }
- function create($priceset_id, $product_id, $value)
- {
- $query = "INSERT INTO ".$this->db->price_table." VALUES('', '".$priceset_id."', '".$product_id."'";
- for($i = 0; $i < count($value); $i++)
- $query .= ", '".str_replace("'", "\'", $value[$i])."'";
- $query .= ")";
- $this->db->query($query);
- }
- function update($priceset_id, $product_id, $value)
- {
- $query = "UPDATE ".$this->db->price_table." SET ";
- $query .= "price='".$value[0]."' ";
- $query .= "WHERE priceset_id='".$priceset_id."' AND product_id='".$product_id."'";
- $this->db->query($query);
- }
- function delete($price_id)
- {
- $query = "DELETE FROM ".$this->db->price_table." WHERE price_id='$price_id'";
- $this->db->query($query);
- }
- function get($price_id = "", $col_names = array(), $search = "")
- {
- if($price_id == "")
- {
- if(count($col_names) == 0)
- $query = "SELECT * FROM ".$this->db->price_table;
- else
- {
- $query = "SELECT ".$col_names[0];
- for($i = 1; $i < count($col_names); $i++)
- $query .= ", ".$col_names[$i];
- $query .= " FROM ".$this->db->price_table;
- }
- if($search != "")
- $query .= " WHERE ".$search;
- $query .= " ORDER BY price_id ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- else
- {
- $query = "SELECT * FROM ".$this->db->price_table." WHERE price_id='".$price_id."'";
- $query .= " ORDER BY price_id ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- }
- function getPrice($priceset_id, $product_id)
- {
- $query = "SELECT * FROM ".$this->db->price_table." WHERE priceset_id='".$priceset_id."' AND product_id='".$product_id."'";
- return $this->db->fetchRows($this->db->query($query));
- }
- function getPriceTax($priceset_id, $product_id, $netto, $tax_id = -1)
- {
- $query = "SELECT * FROM ".$this->db->price_table." WHERE priceset_id='".$priceset_id."' AND product_id='".$product_id."'";
- $tmp = $this->db->fetchRows($this->db->query($query));
- $price = $tmp[0][3];
- if($tax_id == -1)
- {
- $product = new Product();
- $tmp_product = $product->get($product_id);
- if(count($tmp_product) > 0)
- $tax_id = $tmp_product[0][4];
- else
- return 0;
- }
- if($netto)
- {
- $tax = new Tax();
- $tmp_tax = $tax->get($tax_id);
- if(count($tmp_tax) <= 0)
- return 0;
- $price = $price * ( 1 + $tmp_tax[0][2]);
- }
- return $price;
- }
- }
- ?>
|