| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- require_once(__DIR__."/database.php");
- require_once(__DIR__."/Customer.php");
- require_once(__DIR__."/Bill.php");
- require_once(__DIR__."/Product.php");
- require_once(__DIR__."/Price.php");
- require_once(__DIR__."/Tax.php");
- class Bill_Product
- {
- function __construct()
- {
- $this->db = new Database();
- }
- function create($bill_id, $product_id, $amount, $details, $rabatt, $price, $tax)
- {
- $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.")";
- $this->db->query($query);
- }
- function update($bill_product_id, $value)
- {
- $query = "UPDATE ".$this->db->bill_product_table." SET ";
- $query .= "bill_id=".$value[0].", ";
- $query .= "product_id='".$value[1]."', ";
- $query .= "amount=".$value[2].", ";
- $query .= "details='".$value[3]."', ";
- $query .= "rabatt=".$value[4].", ";
- $query .= "price=".$value[5].", ";
- $query .= "tax=".$value[6]." ";
- $query .= "WHERE bill_product_id='".$bill_product_id."'";
- $this->db->query($query);
- }
- function delete($bill_product_id)
- {
- $query = "DELETE FROM ".$this->db->bill_product_table." WHERE bill_product_id='$bill_product_id'";
- $this->db->query($query);
- }
- function get($bill_product_id = "", $row_names = array(), $search = "")
- {
- if($bill_product_id == "")
- {
- if(count($row_names) == 0)
- $query = "SELECT * FROM ".$this->db->bill_product_table;
- else
- {
- $query = "SELECT ".$row_names[0];
- for($i = 1; $i < count($row_names); $i++)
- $query .= ", ".$row_names[$i];
- $query .= " FROM ".$this->db->bill_product_table;
- }
- if($search != "")
- $query .= " WHERE ".$search;
- $query .= " ORDER BY product_id ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- else
- {
- $query = "SELECT * FROM ".$this->db->bill_product_table." WHERE bill_product_id='".$bill_product_id."'";
- return $this->db->fetchRows($this->db->query($query));
- }
- }
- function getByBillId($bill_id)
- {
- $query = "SELECT * FROM ".$this->db->bill_product_table." WHERE bill_id='".$bill_id."'";
- $query .= " ORDER BY product_id ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- function getByBillIdAndProductId($bill_id, $product_id)
- {
- $query = "SELECT * FROM ".$this->db->bill_product_table." WHERE bill_id='".$bill_id."' AND product_id='".$product_id."'";
- $query .= " ORDER BY product_id ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- function getByBillIdsAndProductId($bill_id, $product_id)
- {
- $query = "SELECT * FROM ".$this->db->bill_product_table." WHERE product_id='".$product_id."' AND";
- $query .=" (bill_id='".$bill_id[0][0]."'";
- for($i=1;$i<count($bill_id); $i++)
- $query.=" OR bill_id='".$bill_id[$i][0]."'";
- $query .= ") ORDER BY product_id ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- function fix($bill_id)
- {
- $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";
- $result = $this->db->fetchRows($this->db->query($query));
- for($i = 0; $i < count($result); $i++)
- {
- $query = "UPDATE bill_product SET price='".$result[$i][1]."' WHERE product_id='".$result[$i][0]."' AND bill_id='".$bill_id."'";
- $this->db->query($query);
- }
- }
- function getTourZusammenfassung($tour_id, $date)
- {
- $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";
- return $this->db->fetchRows($this->db->query($query));
- }
- function getTourZusammenfassungFromTo($tour_id, $date_from, $date_to)
- {
- $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";
- return $this->db->fetchRows($this->db->query($query));
- }
- }
- ?>
|