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 clearTable() { $query = "TRUNCATE TABLE ".$this->db->bill_table; $this->db->query($query); } function export($path) { $csv_data = ""; $file_access_ok = true; $file_open = false; clearstatcache(); // $query = "SELECT * FROM ".$this->db->bill_table; $query = "SELECT * FROM ".$this->db->bill_table." WHERE timestamp >= (UNIX_TIMESTAMP(NOW() - INTERVAL 1 MONTH))"; $result = $this->db->query($query); while ($row = mysqli_fetch_assoc($result)) $csv_data .= implode('|', $row)."\n"; $status = $this->db->writeToFile($path, $csv_data); return $status; // if($status) // $this->clearTable(); } } ?>