An easy point of sale system with automatic inventory tracking. https://netsyms.biz/apps/nickelbox/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

item.php 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /*
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. */
  7. require_once __DIR__ . "/../required.php";
  8. class Item {
  9. private $itemid = null;
  10. private $itemdata = [];
  11. function __construct($itemid) {
  12. global $binstack;
  13. $this->itemdata = $binstack->get('items', ['itemid', 'catid', 'name', 'text1', 'qty', 'want', 'cost', 'price'], ['itemid' => $itemid]);
  14. $this->itemid = $itemid;
  15. }
  16. function getId() {
  17. return $this->itemid;
  18. }
  19. function getPrice($customer = null) {
  20. global $database;
  21. $binprice = $this->itemdata['price'];
  22. if (!is_null($customer)) {
  23. if ($database->has('customer_pricing', ['AND' => ['itemid' => $this->itemid, 'customerid' => $customer]])) {
  24. return $database->get('customer_pricing', 'price', ['AND' => ['itemid' => $this->itemid, 'customerid' => $customer]]);
  25. }
  26. }
  27. return $binprice;
  28. }
  29. function getName() {
  30. return $this->itemdata['name'];
  31. }
  32. function getDescription() {
  33. return $this->itemdata['text1'];
  34. }
  35. function getQty() {
  36. return $this->itemdata['qty'];
  37. }
  38. function getWant() {
  39. return $this->itemdata['want'];
  40. }
  41. function getCategoryName() {
  42. global $binstack;
  43. return $binstack->get('items', ['[>]categories' => 'catid'], 'catname', ['itemid' => $this->itemid]);
  44. }
  45. function getCategoryId() {
  46. return $this->itemdata['catid'];
  47. }
  48. }
  49. class RenderItem {
  50. static function card(Item $item) {
  51. $id = $item->getId();
  52. $name = $item->getName();
  53. $catid = $item->getCategoryId();
  54. $catname = $item->getCategoryName();
  55. $price = $item->getPrice();
  56. $html = <<<END
  57. <div class="card m-2">
  58. <div class="card-body text-center">
  59. <a href="./?page=item&id=$id" class="font-weight-bold">$name</a><br />
  60. <span>$$price</span>
  61. </div>
  62. </div>
  63. END;
  64. return $html;
  65. }
  66. static function line(Item $item) {
  67. $id = $item->getId();
  68. $name = $item->getName();
  69. $catid = $item->getCategoryId();
  70. $catname = $item->getCategoryName();
  71. $price = $item->getPrice();
  72. $html = <<<END
  73. <div class="list-group-item d-flex flex-wrap">
  74. <div>
  75. <h4><a href="./?page=item&id=$id">$name</a></h4>
  76. <span>$$price</span>
  77. </div>
  78. <div class="ml-auto">
  79. <form action="./action.php" method="POST">
  80. <div class="input-group">
  81. <input type="number" name="qty" class="form-control mb-2" placeholder="Quantity" value="1" />
  82. <div class="input-group-addon">
  83. <button type="submit" class="btn btn-primary"><i class="fas fa-cart-plus"></i> Add</button>
  84. </div>
  85. </div>
  86. <input type="hidden" name="item" value="$id" />
  87. <input type="hidden" name="action" value="addtocart" />
  88. </form>
  89. </div>
  90. </div>
  91. END;
  92. return $html;
  93. }
  94. static function cart(Item $item, int $qty) {
  95. $id = $item->getId();
  96. $name = $item->getName();
  97. $catid = $item->getCategoryId();
  98. $catname = $item->getCategoryName();
  99. $price = $item->getPrice();
  100. $linetotal = number_format($price * $qty, 2);
  101. $html = <<<END
  102. <div class="list-group-item d-flex flex-wrap">
  103. <div>
  104. <h4><a href="./?page=item&id=$id">$name</a></h4>
  105. <span>$$price</span>
  106. </div>
  107. <div class="ml-auto">
  108. <form action="./action.php" method="POST">
  109. <div class="input-group">
  110. <input type="number" name="qty" class="form-control mb-2" placeholder="Quantity" value="$qty" />
  111. <div class="input-group-addon">
  112. <button type="submit" class="btn btn-primary"><i class="fas fa-sync"></i> Update</button>
  113. </div>
  114. </div>
  115. <input type="hidden" name="item" value="$id" />
  116. <input type="hidden" name="action" value="updatecart" />
  117. </form>
  118. <div class="text-right"><b>$$linetotal</b></div>
  119. </div>
  120. </div>
  121. END;
  122. return $html;
  123. }
  124. }