| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- require_once("DataBase/database.php");
- class Bill
- {
- function Bill()
- {
- $this->db = new Database();
- }
- function create($bill_id, $value)
- {
- $query = "INSERT INTO ".$this->db->bill_table." VALUES('".$bill_id."'";
- for($i = 0; $i < count($value); $i++)
- $query .= ", '".$value[$i]."'";
- $query .= ")";
- $this->db->query($query);
- $query = "SELECT bill_id from ".$this->db->bill_table." ORDER BY bill_id DESC";
- $tmp = $this->db->fetchRows($this->db->query($query));
- return $tmp[0][0];
- }
- function update($bill_id, $value)
- {
- $query = "UPDATE ".$this->db->bill_table." SET ";
- $query .= "customer_id='".$value[0]."', ";
- $query .= "tour_id='".$value[1]."', ";
- $query .= "date='".$value[2]."', ";
- $query .= "assistant_id='".$value[3]."', ";
- $query .= "bill_number='".$value[4]."' ";
- $query .= "WHERE bill_id='".$bill_id."'";
- $this->db->query($query);
- }
- function setNumber($bill_id)
- {
- $data = $this->get($bill_id);
- $query = "UPDATE ".$this->db->bill_table." SET ";
- $query .= "bill_number='".$this->getNextFreeNumberByAssistant($data[0][4])."' ";
- $query .= "WHERE bill_id='".$bill_id."'";
- $this->db->query($query);
- }
- function delete($bill_id)
- {
- $query = "DELETE FROM ".$this->db->bill_table." WHERE bill_id='$bill_id'";
- $this->db->query($query);
- }
- function get($bill_id = "", $row_names = array(), $search = "")
- {
- if($bill_id == "")
- {
- if(count($row_names) == 0)
- $query = "SELECT * FROM ".$this->db->bill_table.", ".$this->db->customer_table;
- else
- {
- $query = "SELECT ".$row_names[0];
- for($i = 1; $i < count($row_names); $i++)
- $query .= ", ".$row_names[$i];
- $query .= " FROM ".$this->db->bill_table.", ".$this->db->customer_table;
- }
- $query .= " WHERE bill.customer_id=customer.customer_id ";
- if($search != "")
- $query .= " AND ( ".$search." )";
- $query .= " ORDER BY bill_number ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- else
- {
- $query = "SELECT * FROM ".$this->db->bill_table." WHERE bill_id='".$bill_id."'";
- $query .= " ORDER BY bill_number ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- }
- function getNextFreeNumberByAssistant($assistant_id)
- {
- $query = "SELECT bill_number FROM ".$this->db->bill_table." WHERE assistant_id='".$assistant_id."' ORDER BY bill_number DESC";
- $result = $this->db->fetchRows($this->db->query($query));
- return $result[0][0]+1;
- }
- function hasTimestamp($timestamp)
- {
- $query = "SELECT * FROM ".$this->db->bill_table." WHERE timestamp='".$timestamp."'";
- if(count($this->db->fetchRows($this->db->query($query))) > 0)
- return True;
- else
- return False;
- }
- }
- ?>
|