Tax.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. require_once(__DIR__."/database.php");
  3. class Tax
  4. {
  5. function __construct()
  6. {
  7. $this->db = new Database();
  8. }
  9. function create($name, $rate)
  10. {
  11. $query = "INSERT INTO ".$this->db->tax_table." (name, tax_rate) VALUES ('".str_replace("'", "\'", $name)."', ".$rate.")";
  12. $this->db->query($query);
  13. }
  14. function update($tax_id, $value)
  15. {
  16. $query = "UPDATE ".$this->db->tax_table." SET ";
  17. $query .= "name='".str_replace("'", "\'", $value[0])."', ";
  18. $query .= "tax_rate=".$value[1]." ";
  19. $query .= "WHERE tax_id=".$tax_id."";
  20. $this->db->query($query);
  21. }
  22. function delete($tax_id)
  23. {
  24. $query = "DELETE FROM ".$this->db->tax_table." WHERE tax_id=".$tax_id."";
  25. $this->db->query($query);
  26. }
  27. function get($tax_id = "", $row_names = array(), $search = "")
  28. {
  29. if($tax_id == "")
  30. {
  31. if(count($row_names) == 0)
  32. $query = "SELECT * FROM ".$this->db->tax_table;
  33. else
  34. {
  35. $query = "SELECT ".$row_names[0];
  36. for($i = 1; $i < count($row_names); $i++)
  37. $query .= ", ".$row_names[$i];
  38. $query .= " FROM ".$this->db->tax_table;
  39. }
  40. if($search != "")
  41. $query .= " WHERE ".$search;
  42. $query .= " ORDER BY tax_id ASC";
  43. return $this->db->fetchRows($this->db->query($query));
  44. }
  45. else
  46. {
  47. $query = "SELECT * FROM ".$this->db->tax_table." WHERE tax_id=".$tax_id."";
  48. $query .= " ORDER BY tax_id ASC";
  49. return $this->db->fetchRows($this->db->query($query));
  50. }
  51. }
  52. }
  53. ?>