Bill.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. require_once("../DataBase/database.php");
  3. class Bill
  4. {
  5. function Bill()
  6. {
  7. $this->db = new Database();
  8. }
  9. function create($bill_id, $value)
  10. {
  11. $query = "INSERT INTO ".$this->db->bill_table." VALUES('".$bill_id."'";
  12. for($i = 0; $i < count($value); $i++)
  13. $query .= ", '".$value[$i]."'";
  14. $query .= ")";
  15. $this->db->query($query);
  16. $query = "SELECT bill_id from ".$this->db->bill_table." ORDER BY bill_id DESC";
  17. $tmp = $this->db->fetchRows($this->db->query($query));
  18. return $tmp[0][0];
  19. }
  20. function update($bill_id, $value)
  21. {
  22. $query = "UPDATE ".$this->db->bill_table." SET ";
  23. $query .= "customer_id='".$value[0]."', ";
  24. $query .= "tour_id='".$value[1]."', ";
  25. $query .= "date='".$value[2]."', ";
  26. $query .= "assistant_id='".$value[3]."', ";
  27. $query .= "bill_number='".$value[4]."' ";
  28. $query .= "WHERE bill_id='".$bill_id."'";
  29. $this->db->query($query);
  30. }
  31. function setNumber($bill_id)
  32. {
  33. $data = $this->get($bill_id);
  34. $query = "UPDATE ".$this->db->bill_table." SET ";
  35. $query .= "bill_number='".$this->getNextFreeNumberByAssistant($data[0][4])."' ";
  36. $query .= "WHERE bill_id='".$bill_id."'";
  37. $this->db->query($query);
  38. }
  39. function delete($bill_id)
  40. {
  41. $query = "DELETE FROM ".$this->db->bill_table." WHERE bill_id='$bill_id'";
  42. $this->db->query($query);
  43. }
  44. function get($bill_id = "", $row_names = array(), $search = "")
  45. {
  46. if($bill_id == "")
  47. {
  48. if(count($row_names) == 0)
  49. $query = "SELECT * FROM ".$this->db->bill_table.", ".$this->db->customer_table;
  50. else
  51. {
  52. $query = "SELECT ".$row_names[0];
  53. for($i = 1; $i < count($row_names); $i++)
  54. $query .= ", ".$row_names[$i];
  55. $query .= " FROM ".$this->db->bill_table.", ".$this->db->customer_table;
  56. }
  57. $query .= " WHERE bill.customer_id=customer.customer_id ";
  58. if($search != "")
  59. $query .= " AND ( ".$search." )";
  60. $query .= " ORDER BY bill_number ASC";
  61. return $this->db->fetchRows($this->db->query($query));
  62. }
  63. else
  64. {
  65. $query = "SELECT * FROM ".$this->db->bill_table." WHERE bill_id='".$bill_id."'";
  66. $query .= " ORDER BY bill_number ASC";
  67. return $this->db->fetchRows($this->db->query($query));
  68. }
  69. }
  70. function getNextFreeNumberByAssistant($assistant_id)
  71. {
  72. $query = "SELECT bill_number FROM ".$this->db->bill_table." WHERE assistant_id='".$assistant_id."' ORDER BY bill_number DESC";
  73. $result = $this->db->fetchRows($this->db->query($query));
  74. return $result[0][0]+1;
  75. }
  76. function hasTimestamp($timestamp)
  77. {
  78. $query = "SELECT * FROM ".$this->db->bill_table." WHERE timestamp='".$timestamp."'";
  79. if(count($this->db->fetchRows($this->db->query($query))) > 0)
  80. return True;
  81. else
  82. return False;
  83. }
  84. }
  85. ?>