Price.php 2.6 KB

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