Product.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. require_once("DataBase/database.php");
  3. class Product
  4. {
  5. function __construct()
  6. {
  7. $this->db = new Database();
  8. }
  9. function create($product_id, $value)
  10. {
  11. $query = "INSERT INTO ".$this->db->product_table." VALUES('".$product_id."'";
  12. for($i = 0; $i < count($value); $i++)
  13. $query .= ", '".str_replace("'", "\'", $value[$i])."'";
  14. $query .= ")";
  15. $this->db->query($query);
  16. }
  17. function update($product_id, $value)
  18. {
  19. $query = "UPDATE ".$this->db->product_table." SET ";
  20. $query .= "name='".str_replace("'", "\'", $value[0])."', ";
  21. $query .= "details='".str_replace("'", "\'", $value[1])."', ";
  22. $query .= "category_id='".str_replace("'", "\'", $value[2])."', ";
  23. $query .= "tax_id='".str_replace("'", "\'", $value[3])."', ";
  24. $query .= "available='".str_replace("'", "\'", $value[4])."', ";
  25. $query .= "group_id='".str_replace("'", "\'", $value[5])."', ";
  26. $query .= "order_number='".str_replace("'", "\'", $value[6])."', ";
  27. $query .= "anmerkung='".str_replace("'", "\'", $value[7])."' ";
  28. $query .= "WHERE product_id='".$product_id."'";
  29. //echo $query;
  30. $this->db->query($query);
  31. }
  32. function delete($product_id)
  33. {
  34. $query = "DELETE FROM ".$this->db->product_table." WHERE product_id='$product_id'";
  35. $this->db->query($query);
  36. }
  37. function get($product_id = "", $row_names = array(), $search = "")
  38. {
  39. if($product_id == "")
  40. {
  41. if(count($row_names) == 0)
  42. $query = "SELECT * FROM ".$this->db->product_table;
  43. else
  44. {
  45. $query = "SELECT ".$row_names[0];
  46. for($i = 1; $i < count($row_names); $i++)
  47. $query .= ", ".$row_names[$i];
  48. $query .= " FROM ".$this->db->product_table;
  49. }
  50. if($search != "")
  51. $query .= " WHERE ".$search;
  52. $query .= " ORDER BY product_id ASC";
  53. return $this->db->fetchRows($this->db->query($query));
  54. }
  55. else
  56. {
  57. $query = "SELECT * FROM ".$this->db->product_table." WHERE product_id='".$product_id."'";
  58. $query .= " ORDER BY product_id ASC";
  59. return $this->db->fetchRows($this->db->query($query));
  60. }
  61. }
  62. function getAmountByDate($product_id, $date_from, $date_to, $assistant_id)
  63. {
  64. $query = "SELECT SUM(".$this->db->bill_product_table.".amount) FROM ".$this->db->bill_table." ";
  65. $query .= "RIGHT JOIN ".$this->db->bill_product_table." ON ".$this->db->bill_table.".bill_id=".$this->db->bill_product_table.".bill_id ";
  66. $query .= "WHERE ".$this->db->bill_table.".date>='".$date_from."' ";
  67. $query .= "AND ".$this->db->bill_table.".date<='".$date_to."' ";
  68. $query .= "AND ".$this->db->bill_table.".assistant_id<='".$assistant_id."' ";
  69. $query .= "AND ".$this->db->bill_product_table.".product_id='".$product_id."' ";
  70. $retval = $this->db->fetchRows($this->db->query($query));
  71. return $retval[0][0];
  72. }
  73. function getBillsByDate($product_id, $date_from, $date_to, $assistant_id)
  74. {
  75. $query = "SELECT DISTINCT ".$this->db->bill_table.".bill_number,SUM(".$this->db->bill_product_table.".amount) FROM ".$this->db->bill_table." ";
  76. $query .= "RIGHT JOIN ".$this->db->bill_product_table." ON ".$this->db->bill_table.".bill_id=".$this->db->bill_product_table.".bill_id ";
  77. $query .= "WHERE ".$this->db->bill_table.".date>='".$date_from."' ";
  78. $query .= "AND ".$this->db->bill_table.".date<='".$date_to."' ";
  79. $query .= "AND ".$this->db->bill_table.".assistant_id<='".$assistant_id."' ";
  80. $query .= "AND ".$this->db->bill_product_table.".product_id='".$product_id."' ";
  81. $query .= "GROUP BY ".$this->db->bill_table.".customer_id ";
  82. return $this->db->fetchRows($this->db->query($query));
  83. }
  84. function getCustomersByDate($product_id, $date_from, $date_to, $assistant_id)
  85. {
  86. $query = "SELECT DISTINCT ".$this->db->bill_table.".customer_id,SUM(".$this->db->bill_product_table.".amount) FROM ".$this->db->bill_table." ";
  87. $query .= "RIGHT JOIN ".$this->db->bill_product_table." ON ".$this->db->bill_table.".bill_id=".$this->db->bill_product_table.".bill_id ";
  88. $query .= "WHERE ".$this->db->bill_table.".date>='".$date_from."' ";
  89. $query .= "AND ".$this->db->bill_table.".date<='".$date_to."' ";
  90. $query .= "AND ".$this->db->bill_table.".assistant_id<='".$assistant_id."' ";
  91. $query .= "AND ".$this->db->bill_product_table.".product_id='".$product_id."' ";
  92. $query .= "GROUP BY ".$this->db->bill_table.".customer_id ";
  93. return $this->db->fetchRows($this->db->query($query));
  94. }
  95. function getByFilter($search_product, $search_category, $item_offset, $item_count)
  96. {
  97. $query = "SELECT * FROM ".$this->db->product_table." ";
  98. if($search_product != "" || $search_category != "")
  99. {
  100. $query .= " WHERE ";
  101. if($search_product != "")
  102. $query .= " (product_id LIKE '%".$search_product."%' OR name LIKE '%".$search_product."%' OR details LIKE '%".$search_product."%') ";
  103. if($search_category != "" && $search_product != "")
  104. $query .= " AND category_id=".$search_category." ";
  105. elseif($search_category != "" && $search_product == "")
  106. $query .= " category_id=".$search_category." ";
  107. }
  108. $query .= " ORDER BY product_id ASC";
  109. if($item_count != 0)
  110. $query .= " LIMIT ".$item_count." ";
  111. if($item_offset != 0)
  112. $query .= " OFFSET ".$item_offset." ";
  113. return $this->db->fetchRows($this->db->query($query));
  114. }
  115. function getCountByFilter($search_product, $search_category)
  116. {
  117. $query = "SELECT count(*) FROM ".$this->db->product_table." ";
  118. if($search_product != "" || $search_category != "")
  119. {
  120. $query .= " WHERE ";
  121. if($search_product != "")
  122. $query .= " (product_id LIKE '%".$search_product."%' OR name LIKE'%".$search_product."%' OR details LIKE '%".$search_product."%') AND ";
  123. if($search_category != "")
  124. $query .= " category_id=".$search_category." ";
  125. else
  126. $query .= " 1=1 ";
  127. }
  128. $query .= " ORDER BY product_id ASC";
  129. return $this->db->fetchRows($this->db->query($query));
  130. }
  131. }
  132. ?>