| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php
- require_once("../DataBase/database.php");
- require_once("../DataBase/Customer.php");
- require_once("../DataBase/Bill.php");
- require_once("../DataBase/Product.php");
- require_once("../DataBase/Price.php");
- require_once("../DataBase/Tax.php");
- class Bill_Product
- {
- function Bill_Product()
- {
- $this->db = new Database();
- }
- function create($value)
- {
- $query = "INSERT INTO ".$this->db->bill_product_table." VALUES(''";
- for($i = 0; $i < count($value); $i++)
- $query .= ", '".$value[$i]."'";
- $query .= ")";
- $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)
- {
- /*$products = $this->getByBillId($bill_id);
- $product = new Product();
- $price = new Price();
- $tax = new Tax();
- $bill = new Bill();
- $tmp = $bill->get($bill_id, array("customer_id"));
- $customer = new Customer();
- $tmp = $customer->get($tmp[0]);
- $customer_data = $tmp[0];
- for($i = 0; $i < count($products); $i++)
- {
- $tmp = $this->getByBillIdAndProductId($bill_id, $products[$i][2]);
- $bill_product_data = $tmp[0];
- $tmp = $product->get($products[$i][2], array("product_id","tax_id"));
- $product_data = $tmp[0];
- $tmp = $price->getPrice($customer_data[11], $product_data[0]);
- $price_data = $tmp[0];
- $tmp = $tax->get($product_data[1]);
- $tax_data = $tmp[0];
- $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]));
- }*/
- $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));
- }
- }
- ?>
|