Bill_Product.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. require_once("../DataBase/database.php");
  3. require_once("DataBase/Customer.php");
  4. require_once("DataBase/Bill.php");
  5. require_once("DataBase/Product.php");
  6. require_once("DataBase/Price.php");
  7. require_once("../DataBase/Tax.php");
  8. class Bill_Product
  9. {
  10. function Bill_Product()
  11. {
  12. $this->db = new Database();
  13. }
  14. function create($value)
  15. {
  16. $query = "INSERT INTO ".$this->db->bill_product_table." VALUES(''";
  17. for($i = 0; $i < count($value); $i++)
  18. $query .= ", '".$value[$i]."'";
  19. $query .= ")";
  20. $this->db->query($query);
  21. }
  22. function update($bill_product_id, $value)
  23. {
  24. $query = "UPDATE ".$this->db->bill_product_table." SET ";
  25. $query .= "bill_id='".$value[0]."', ";
  26. $query .= "product_id='".$value[1]."', ";
  27. $query .= "amount='".$value[2]."', ";
  28. $query .= "details='".$value[3]."', ";
  29. $query .= "rabatt='".$value[4]."', ";
  30. $query .= "price='".$value[5]."', ";
  31. $query .= "tax='".$value[6]."' ";
  32. $query .= "WHERE bill_product_id='".$bill_product_id."'";
  33. $this->db->query($query);
  34. }
  35. function delete($bill_product_id)
  36. {
  37. $query = "DELETE FROM ".$this->db->bill_product_table." WHERE bill_product_id='$bill_product_id'";
  38. $this->db->query($query);
  39. }
  40. function get($bill_product_id = "", $row_names = array(), $search = "")
  41. {
  42. if($bill_product_id == "")
  43. {
  44. if(count($row_names) == 0)
  45. $query = "SELECT * FROM ".$this->db->bill_product_table;
  46. else
  47. {
  48. $query = "SELECT ".$row_names[0];
  49. for($i = 1; $i < count($row_names); $i++)
  50. $query .= ", ".$row_names[$i];
  51. $query .= " FROM ".$this->db->bill_product_table;
  52. }
  53. if($search != "")
  54. $query .= " WHERE ".$search;
  55. $query .= " ORDER BY product_id ASC";
  56. return $this->db->fetchRows($this->db->query($query));
  57. }
  58. else
  59. {
  60. $query = "SELECT * FROM ".$this->db->bill_product_table." WHERE bill_product_id='".$bill_product_id."'";
  61. return $this->db->fetchRows($this->db->query($query));
  62. }
  63. }
  64. function getByBillId($bill_id)
  65. {
  66. $query = "SELECT * FROM ".$this->db->bill_product_table." WHERE bill_id='".$bill_id."'";
  67. $query .= " ORDER BY product_id ASC";
  68. return $this->db->fetchRows($this->db->query($query));
  69. }
  70. function getByBillIdAndProductId($bill_id, $product_id)
  71. {
  72. $query = "SELECT * FROM ".$this->db->bill_product_table." WHERE bill_id='".$bill_id."' AND product_id='".$product_id."'";
  73. $query .= " ORDER BY product_id ASC";
  74. return $this->db->fetchRows($this->db->query($query));
  75. }
  76. function getByBillIdsAndProductId($bill_id, $product_id)
  77. {
  78. $query = "SELECT * FROM ".$this->db->bill_product_table." WHERE product_id='".$product_id."' AND";
  79. $query .=" (bill_id='".$bill_id[0][0]."'";
  80. for($i=1;$i<count($bill_id); $i++)
  81. $query.=" OR bill_id='".$bill_id[$i][0]."'";
  82. $query .= ") ORDER BY product_id ASC";
  83. return $this->db->fetchRows($this->db->query($query));
  84. }
  85. function fix($bill_id)
  86. {
  87. /*$products = $this->getByBillId($bill_id);
  88. $product = new Product();
  89. $price = new Price();
  90. $tax = new Tax();
  91. $bill = new Bill();
  92. $tmp = $bill->get($bill_id, array("customer_id"));
  93. $customer = new Customer();
  94. $tmp = $customer->get($tmp[0]);
  95. $customer_data = $tmp[0];
  96. for($i = 0; $i < count($products); $i++)
  97. {
  98. $tmp = $this->getByBillIdAndProductId($bill_id, $products[$i][2]);
  99. $bill_product_data = $tmp[0];
  100. $tmp = $product->get($products[$i][2], array("product_id","tax_id"));
  101. $product_data = $tmp[0];
  102. $tmp = $price->getPrice($customer_data[11], $product_data[0]);
  103. $price_data = $tmp[0];
  104. $tmp = $tax->get($product_data[1]);
  105. $tax_data = $tmp[0];
  106. $this->update($bill_product_data[0], array($bill_product_data[1], $bill_product_data[2], $bill_product_data[3], $bill_product_data[4], $bill_product_data[5], $price_data[3], $tax_data[2]));
  107. }*/
  108. $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";
  109. $result = $this->db->fetchRows($this->db->query($query));
  110. for($i = 0; $i < count($result); $i++)
  111. {
  112. $query = "UPDATE bill_product SET price='".$result[$i][1]."' WHERE product_id='".$result[$i][0]."' AND bill_id='".$bill_id."'";
  113. $this->db->query($query);
  114. }
  115. }
  116. function getTourZusammenfassung($tour_id, $date)
  117. {
  118. $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";
  119. return $this->db->fetchRows($this->db->query($query));
  120. }
  121. function getTourZusammenfassungFromTo($tour_id, $date_from, $date_to)
  122. {
  123. $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";
  124. return $this->db->fetchRows($this->db->query($query));
  125. }
  126. }
  127. ?>