Bill_Product.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. require_once(__DIR__."/database.php");
  3. require_once(__DIR__."/Customer.php");
  4. require_once(__DIR__."/Bill.php");
  5. require_once(__DIR__."/Product.php");
  6. require_once(__DIR__."/Price.php");
  7. require_once(__DIR__."/Tax.php");
  8. class Bill_Product
  9. {
  10. function __construct()
  11. {
  12. $this->db = new Database();
  13. }
  14. function create($bill_id, $product_id, $amount, $details, $rabatt, $price, $tax)
  15. {
  16. $query = "INSERT INTO ".$this->db->bill_product_table." (bill_id, product_id, amount, details, rabatt, price, tax) VALUES(".$bill_id.",'".$product_id."',".$amount.",'".$details."',".$rabatt.",".$price.",".$tax.")";
  17. $this->db->query($query);
  18. }
  19. function update($bill_product_id, $value)
  20. {
  21. $query = "UPDATE ".$this->db->bill_product_table." SET ";
  22. $query .= "bill_id=".$value[0].", ";
  23. $query .= "product_id='".$value[1]."', ";
  24. $query .= "amount=".$value[2].", ";
  25. $query .= "details='".$value[3]."', ";
  26. $query .= "rabatt=".$value[4].", ";
  27. $query .= "price=".$value[5].", ";
  28. $query .= "tax=".$value[6]." ";
  29. $query .= "WHERE bill_product_id='".$bill_product_id."'";
  30. $this->db->query($query);
  31. }
  32. function delete($bill_product_id)
  33. {
  34. $query = "DELETE FROM ".$this->db->bill_product_table." WHERE bill_product_id='$bill_product_id'";
  35. $this->db->query($query);
  36. }
  37. function get($bill_product_id = "", $row_names = array(), $search = "")
  38. {
  39. if($bill_product_id == "")
  40. {
  41. if(count($row_names) == 0)
  42. $query = "SELECT * FROM ".$this->db->bill_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->bill_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->bill_product_table." WHERE bill_product_id='".$bill_product_id."'";
  58. return $this->db->fetchRows($this->db->query($query));
  59. }
  60. }
  61. function getByBillId($bill_id)
  62. {
  63. $query = "SELECT * FROM ".$this->db->bill_product_table." WHERE bill_id='".$bill_id."'";
  64. $query .= " ORDER BY product_id ASC";
  65. return $this->db->fetchRows($this->db->query($query));
  66. }
  67. function getByBillIdAndProductId($bill_id, $product_id)
  68. {
  69. $query = "SELECT * FROM ".$this->db->bill_product_table." WHERE bill_id='".$bill_id."' AND product_id='".$product_id."'";
  70. $query .= " ORDER BY product_id ASC";
  71. return $this->db->fetchRows($this->db->query($query));
  72. }
  73. function getByBillIdsAndProductId($bill_id, $product_id)
  74. {
  75. $query = "SELECT * FROM ".$this->db->bill_product_table." WHERE product_id='".$product_id."' AND";
  76. $query .=" (bill_id='".$bill_id[0][0]."'";
  77. for($i=1;$i<count($bill_id); $i++)
  78. $query.=" OR bill_id='".$bill_id[$i][0]."'";
  79. $query .= ") ORDER BY product_id ASC";
  80. return $this->db->fetchRows($this->db->query($query));
  81. }
  82. function fix($bill_id)
  83. {
  84. $query = "SELECT product.product_id,price.price FROM price,customer,product,bill_product,bill WHERE bill.bill_id='".$bill_id."' AND bill_product.bill_id='".$bill_id."' AND bill_product.product_id=product.product_id AND customer.customer_id=bill.customer_id AND customer.pricelist_id=price.priceset_id AND price.product_id=bill_product.product_id";
  85. $result = $this->db->fetchRows($this->db->query($query));
  86. for($i = 0; $i < count($result); $i++)
  87. {
  88. $query = "UPDATE bill_product SET price='".$result[$i][1]."' WHERE product_id='".$result[$i][0]."' AND bill_id='".$bill_id."'";
  89. $this->db->query($query);
  90. }
  91. }
  92. function getTourZusammenfassung($tour_id, $date)
  93. {
  94. $query = "SELECT DISTINCT product.product_id, product.name, SUM(bill_product.amount), product.order_number FROM product, bill_product,bill WHERE product.product_id=bill_product.product_id AND bill_product.bill_id=bill.bill_id AND bill_product.amount > 0 AND bill.date='".$date."' AND bill.tour_id=".$tour_id." GROUP BY product.product_id ORDER BY product.product_id";
  95. return $this->db->fetchRows($this->db->query($query));
  96. }
  97. function getTourZusammenfassungFromTo($tour_id, $date_from, $date_to)
  98. {
  99. $query = "SELECT DISTINCT product.product_id, product.name, SUM(bill_product.amount), product.order_number FROM product, bill_product,bill WHERE product.product_id=bill_product.product_id AND bill_product.bill_id=bill.bill_id AND bill_product.amount > 0 AND bill.date>='".$date_from."' AND bill.date<='".$date_to."' GROUP BY product.product_id ORDER BY product.product_id";
  100. return $this->db->fetchRows($this->db->query($query));
  101. }
  102. }
  103. ?>