PageRenderTime 51ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/controller/JUNK/Product/Product.php

https://gitlab.com/MohammadShakil/POS_Management_System
PHP | 120 lines | 106 code | 9 blank | 5 comment | 15 complexity | c6acf483ce1923b4925dc70b71db038d MD5 | raw file
  1. <?php
  2. namespace App\Product;
  3. use App\Message\Message;
  4. use App\Utility\Utility;
  5. use App\Model\Database as DB;
  6. use MongoDB\Driver\Query;
  7. Class Product extends DB
  8. {
  9. public $id = "";
  10. public $CategoryID = "";
  11. public $name = "";
  12. public $code = "";
  13. public $size = "";
  14. public $price = "";
  15. public $sell_price = "";
  16. public $manufacture = "";
  17. public $exprie = "";
  18. public function __construct()
  19. {
  20. parent::__construct();
  21. }
  22. public function prepareData($data=array())
  23. {
  24. if (array_key_exists('CategoryID', $data)) {
  25. $this->CategoryID = filter_var($data['CategoryID'], FILTER_SANITIZE_STRING);
  26. }
  27. if (array_key_exists('name', $data)) {
  28. $this->name = filter_var($data['name'], FILTER_SANITIZE_STRING);
  29. }
  30. if (array_key_exists('code', $data)) {
  31. $this->code = filter_var($data['code'], FILTER_SANITIZE_STRING);
  32. }
  33. if (array_key_exists('size', $data)) {
  34. $this->size = filter_var($data['size'], FILTER_SANITIZE_STRING);
  35. }
  36. if (array_key_exists('price', $data)) {
  37. $this->price = filter_var($data['price'], FILTER_SANITIZE_STRING);
  38. }
  39. if (array_key_exists('sell_price', $data)) {
  40. $this->sell_price = filter_var($data['sell_price'], FILTER_SANITIZE_STRING);
  41. }
  42. if (array_key_exists('manufacture', $data)) {
  43. $this->manufacture = filter_var($data['manufacture'], FILTER_SANITIZE_STRING);
  44. }
  45. if (array_key_exists('exprie', $data)) {
  46. $this->exprie = filter_var($data['exprie'], FILTER_SANITIZE_STRING);
  47. }
  48. if (array_key_exists('id', $data)) {
  49. $this->id = $data['id'];
  50. }
  51. return $this;
  52. }
  53. public function create()
  54. {
  55. $query = "INSERT INTO `db_pos`.`products` (`category_id`, `product_name`, `product_code`, `product_size_id`, `product_price`, `product_sell_price`, `manufac_date`, `exp_date`) VALUES ( '{$this->CategoryID}', '{$this->name}', '{$this->code}', '{$this->size}', '{$this->price}', '{$this->sell_price}', '{$this->manufacture}', '{$this->exprie}');";
  56. //Utility::dd($query);
  57. $result = mysqli_query($this->conn, $query);
  58. if ($result) {
  59. // echo "Done";
  60. //Message::message("<div class='alert alert-success'><strong>Success !</strong> Successfully Category Added</div>");
  61. header('Location:product-list.php');
  62. } else {
  63. echo "Not Done";
  64. //Message::message("<div class='alert alert-success'><strong>Problem !</strong> Din not Successfully Inserted</div>");
  65. // header('Location:index.php');
  66. }
  67. }
  68. public function index(){
  69. $list_data = array();
  70. $query = "SELECT * FROM `products`";
  71. $result = mysqli_query($this->conn, $query);
  72. while($row = mysqli_fetch_assoc($result)){
  73. $list_data[]=$row;
  74. }
  75. return $list_data;
  76. }
  77. public function getCategoryValue(){
  78. $query ="SELECT c.category_name, p.product_name FROM producat_category AS c LEFT JOIN products AS p ON c.category_id = p.category_id";
  79. $result = mysqli_query($this->conn, $query);
  80. $row = mysqli_fetch_assoc($result);
  81. return $row;
  82. }
  83. public function view(){
  84. $query = "SELECT * FROM `products` WHERE `id`=".$this->id;
  85. $result = mysqli_query($this->Conn,$query);
  86. $row = mysqli_fetch_object($result);
  87. return $row;
  88. }
  89. public function update(){
  90. $query = "UPDATE `products` SET `name`='".$this->name."' WHERE `products`.`id`=".$this->id;
  91. $result = mysqli_query($this->Conn, $query);
  92. if ($result) {
  93. Message::message("<div class='alert alert-success'><strong>Success !</strong> Successfully Updated</div>");
  94. header('Location:index.php');
  95. } else {
  96. Message::message("<div class='alert alert-success'><strong>Problem !</strong> Din not Successfully Updated</div>");
  97. header('Location:index.php');
  98. }
  99. }
  100. public function delete(){
  101. $query="DELETE FROM `products` WHERE `products`.`id`=".$this->id;
  102. $result= mysqli_query($this->Conn, $query);
  103. if ($result) {
  104. Message::message("<div class='alert alert-success'><strong>Success !</strong> Successfully Deleted</div>");
  105. header('Location:viewTrash.php');
  106. } else {
  107. Message::message("<div class='alert alert-success'><strong>Problem Occured !</strong> Din not Successfully Deleted</div>");
  108. header('Location:index.php');
  109. }
  110. }
  111. }