選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Order.php 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace Shop\DB;
  3. use Shop\Model\Order as OrderModel;
  4. use Shop\Model\OrderCreate as OrderCreate;
  5. use Shop\DB\myDB;
  6. class Order
  7. {
  8. protected $container;
  9. protected $orderlines = [];
  10. protected $details = [];
  11. protected $clients = [];
  12. protected $product = [];
  13. public function __construct($container) {
  14. $this->container = $container;
  15. }
  16. public function getOrderLines($id)
  17. {
  18. $db = $this->container->get('db');
  19. $sql = "SELECT * FROM order_lines o LEFT JOIN products p on o.product_id = p.id where o.order_id = :id;";
  20. $stmt = $db->prepare($sql);
  21. $stmt->bindValue(':id', $id, SQLITE3_INTEGER);
  22. $res = $stmt->execute();
  23. while ($result = $res->fetchArray(SQLITE3_ASSOC)) {
  24. $orderLine = new OrderModel($this->container);
  25. $orderLine->setId($result['id']);
  26. $orderLine->setName($result['name']);
  27. $orderLine->setItemnumber($result['itemnumber']);
  28. $orderLine->setQty($result['qty']);
  29. $orderLine->setSubtotal($result['subtotal']);
  30. $orderLine->setVat($result['vat']);
  31. $orderLine->setTotal($result['total']);
  32. $this->orderlines[] = $orderLine;
  33. }
  34. return $this->orderlines;
  35. }
  36. public function getOrderDetail($id) {
  37. $db = $this->container->get('db');
  38. $stmt = $db->prepare("SELECT * FROM orders WHERE id = :id");
  39. $stmt->bindValue(':id', $id, SQLITE3_INTEGER);
  40. $res = $stmt->execute();
  41. while ($result = $res->fetchArray(SQLITE3_ASSOC)) {
  42. $detail = new OrderModel($this->container);
  43. $detail->setReference($result['reference']);
  44. $this->details[] = $detail;
  45. }
  46. return $this->details;
  47. }
  48. public function getProductDetails($id, $productid, $qty) {
  49. $db = $this->container->get('db');
  50. $sqlproduct = "select * from products where id = :id;";
  51. $stmtproduct = $db->prepare($sqlproduct);
  52. $stmtproduct->bindValue(':id', $productid, SQLITE3_INTEGER);
  53. $resproduct = $stmtproduct->execute();
  54. while ($product = $resproduct->fetchArray(SQLITE3_ASSOC)) {
  55. $order = new OrderModel($this->container);
  56. $order->setUnitprice($product['unitprice']);
  57. $order->setVatperc($product['vatperc']);
  58. $this->product[] = $order;
  59. }
  60. $order_id = $id;
  61. $unitprice = $product['unitprice'];
  62. $vatperc = $product['vatperc'];
  63. $subtotal = $qty * $unitprice;
  64. $vat = $subtotal * $vatperc / 100;
  65. $total = $subtotal + $vat;
  66. $sql = "insert into order_lines (order_id, product_id, qty, subtotal, vat, total) values ($order_id, $productid, $qty, $subtotal, $vat, $total)";
  67. $db->exec($sql);
  68. $sql = "update orders set total = total + $total, subtotal = subtotal + $subtotal, vat = vat + $vat where id = $order_id";
  69. $db->exec($sql);
  70. }
  71. public function getClient($id)
  72. {
  73. $db = $this->container->get('db');
  74. $sql = "SELECT * FROM clients WHERE id = :id;";
  75. $stmt = $db->prepare($sql);
  76. $stmt->bindValue(':id', $id, SQLITE3_INTEGER);
  77. $res = $stmt->execute();
  78. while ($result = $res->fetchArray(SQLITE3_ASSOC)) {
  79. $client = new OrderCreate($this->container);
  80. $client->setFirstname($result['firstname']);
  81. $client->setLastname($result['lastname']);
  82. $this->clients[] = $client;
  83. }
  84. return $this->clients;
  85. }
  86. }