Price.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. require_once(__DIR__."/database.php");
  3. class Price
  4. {
  5. function __construct()
  6. {
  7. $this->db = new Database();
  8. }
  9. function exists($priceset_id, $product_id)
  10. {
  11. $query = "SELECT * FROM ".$this->db->price_table." WHERE priceset_id=".$priceset_id." AND product_id='".$product_id."'";
  12. if(count($this->db->fetchRows($this->db->query($query))) > 0)
  13. return true;
  14. else
  15. return false;
  16. }
  17. function create($priceset_id, $product_id, $price)
  18. {
  19. $query = "INSERT INTO ".$this->db->price_table." VALUES(0, ".$priceset_id.", '".$product_id."', ".$price.")";
  20. $this->db->query($query);
  21. }
  22. function update($priceset_id, $product_id, $value)
  23. {
  24. $query = "UPDATE ".$this->db->price_table." SET ";
  25. $query .= "price='".$value[0]."' ";
  26. $query .= "WHERE priceset_id=".$priceset_id." AND product_id='".$product_id."'";
  27. $this->db->query($query);
  28. }
  29. function delete($price_id)
  30. {
  31. $query = "DELETE FROM ".$this->db->price_table." WHERE price_id=".$price_id."";
  32. $this->db->query($query);
  33. }
  34. function get($price_id = "", $col_names = array(), $search = "")
  35. {
  36. if($price_id == "")
  37. {
  38. if(count($col_names) == 0)
  39. $query = "SELECT * FROM ".$this->db->price_table;
  40. else
  41. {
  42. $query = "SELECT ".$col_names[0];
  43. for($i = 1; $i < count($col_names); $i++)
  44. $query .= ", ".$col_names[$i];
  45. $query .= " FROM ".$this->db->price_table;
  46. }
  47. if($search != "")
  48. $query .= " WHERE ".$search;
  49. $query .= " ORDER BY price_id ASC";
  50. return $this->db->fetchRows($this->db->query($query));
  51. }
  52. else
  53. {
  54. $query = "SELECT * FROM ".$this->db->price_table." WHERE price_id='".$price_id."'";
  55. $query .= " ORDER BY price_id ASC";
  56. return $this->db->fetchRows($this->db->query($query));
  57. }
  58. }
  59. function getPrice($priceset_id, $product_id)
  60. {
  61. $query = "SELECT * FROM ".$this->db->price_table." WHERE priceset_id='".$priceset_id."' AND product_id='".$product_id."'";
  62. return $this->db->fetchRows($this->db->query($query));
  63. }
  64. function getPriceTax($priceset_id, $product_id, $netto, $tax_id = -1)
  65. {
  66. $query = "SELECT * FROM ".$this->db->price_table." WHERE priceset_id='".$priceset_id."' AND product_id='".$product_id."'";
  67. $tmp = $this->db->fetchRows($this->db->query($query));
  68. $price = $tmp[0][3];
  69. if($tax_id == -1)
  70. {
  71. $product = new Product();
  72. $tmp_product = $product->get($product_id);
  73. if(count($tmp_product) > 0)
  74. $tax_id = $tmp_product[0][4];
  75. else
  76. return 0;
  77. }
  78. if($netto)
  79. {
  80. $tax = new Tax();
  81. $tmp_tax = $tax->get($tax_id);
  82. if(count($tmp_tax) <= 0)
  83. return 0;
  84. $price = $price * ( 1 + $tmp_tax[0][2]);
  85. }
  86. return $price;
  87. }
  88. }
  89. ?>