Product.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. require_once("DataBase/database.php");
  3. class Product
  4. {
  5. function Product()
  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. $this->db->query($query);
  30. }
  31. function delete($product_id)
  32. {
  33. $query = "DELETE FROM ".$this->db->product_table." WHERE product_id='$product_id'";
  34. $this->db->query($query);
  35. }
  36. function exists($product_id, $search = "")
  37. {
  38. $query = "SELECT product_id FROM ".$this->db->product_table." WHERE product_id='".$product_id."'";
  39. if($search != "")
  40. $query .= " AND ".$search;
  41. $result = $this->db->fetchRows($this->db->query($query));
  42. if(count($result) > 0)
  43. return true;
  44. else
  45. return false;
  46. }
  47. function get($product_id = "", $row_names = array(), $search = "")
  48. {
  49. if($product_id == "")
  50. {
  51. if(count($row_names) == 0)
  52. $query = "SELECT * FROM ".$this->db->product_table;
  53. else
  54. {
  55. $query = "SELECT ".$row_names[0];
  56. for($i = 1; $i < count($row_names); $i++)
  57. $query .= ", ".$row_names[$i];
  58. $query .= " FROM ".$this->db->product_table;
  59. }
  60. if($search != "")
  61. {
  62. //$search = str_replace("(", "\(", $search);
  63. //$search = str_replace(")", "\)", $search);
  64. //$search = str_replace("/", "\/", $search);
  65. $query .= " WHERE ".$search;
  66. }
  67. $query .= " ORDER BY product_id ASC";
  68. return $this->db->fetchRows($this->db->query($query));
  69. }
  70. else
  71. {
  72. if(count($row_names) == 0)
  73. $query = "SELECT * FROM ".$this->db->product_table;
  74. else
  75. {
  76. $query = "SELECT ".$row_names[0];
  77. for($i = 1; $i < count($row_names); $i++)
  78. $query .= ", ".$row_names[$i];
  79. $query .= " FROM ".$this->db->product_table;
  80. }
  81. $query .= " WHERE product_id='".$product_id."'";
  82. if($search != "")
  83. $query .= " AND ".$search;
  84. $query .= " ORDER BY product_id ASC";
  85. return $this->db->fetchRows($this->db->query($query));
  86. }
  87. }
  88. function getAmountByDate($product_id, $date_from, $date_to, $assistant_id)
  89. {
  90. $query = "SELECT SUM(".$this->db->bill_product_table.".amount) FROM ".$this->db->bill_table." ";
  91. $query .= "RIGHT JOIN ".$this->db->bill_product_table." ON ".$this->db->bill_table.".bill_id=".$this->db->bill_product_table.".bill_id ";
  92. $query .= "WHERE ".$this->db->bill_table.".date>='".$date_from."' ";
  93. $query .= "AND ".$this->db->bill_table.".date<='".$date_to."' ";
  94. $query .= "AND ".$this->db->bill_table.".assistant_id<='".$assistant_id."' ";
  95. $query .= "AND ".$this->db->bill_product_table.".product_id='".$product_id."' ";
  96. $retval = $this->db->fetchRows($this->db->query($query));
  97. return $retval[0][0];
  98. }
  99. function getBillsByDate($product_id, $date_from, $date_to, $assistant_id)
  100. {
  101. $query = "SELECT ".$this->db->bill_table.".bill_number,SUM(".$this->db->bill_product_table.".amount) FROM ".$this->db->bill_table." ";
  102. $query .= "RIGHT JOIN ".$this->db->bill_product_table." ON ".$this->db->bill_table.".bill_id=".$this->db->bill_product_table.".bill_id ";
  103. $query .= "WHERE ".$this->db->bill_table.".date>='".$date_from."' ";
  104. $query .= "AND ".$this->db->bill_table.".date<='".$date_to."' ";
  105. $query .= "AND ".$this->db->bill_table.".assistant_id<='".$assistant_id."' ";
  106. $query .= "AND ".$this->db->bill_product_table.".product_id='".$product_id."' ";
  107. $query .= "GROUP BY ".$this->db->bill_table.".customer_id ";
  108. return $this->db->fetchRows($this->db->query($query));
  109. }
  110. function getCustomersByDate($product_id, $date_from, $date_to, $assistant_id)
  111. {
  112. $query = "SELECT DISTINCT ".$this->db->bill_table.".customer_id,SUM(".$this->db->bill_product_table.".amount) FROM ".$this->db->bill_table." ";
  113. $query .= "RIGHT JOIN ".$this->db->bill_product_table." ON ".$this->db->bill_table.".bill_id=".$this->db->bill_product_table.".bill_id ";
  114. $query .= "WHERE ".$this->db->bill_table.".date>='".$date_from."' ";
  115. $query .= "AND ".$this->db->bill_table.".date<='".$date_to."' ";
  116. $query .= "AND ".$this->db->bill_table.".assistant_id<='".$assistant_id."' ";
  117. $query .= "AND ".$this->db->bill_product_table.".product_id='".$product_id."' ";
  118. $query .= "GROUP BY ".$this->db->bill_table.".customer_id ";
  119. return $this->db->fetchRows($this->db->query($query));
  120. }
  121. function export($path)
  122. {
  123. $csv_data = "";
  124. $query = "SELECT * FROM ".$this->db->product_table." WHERE available=1";
  125. $result = $this->db->query($query);
  126. while ($row = mysqli_fetch_assoc($result))
  127. $csv_data .= implode('|', $row)."\n";
  128. $this->db->writeToFile($path, $csv_data);
  129. }
  130. }
  131. ?>