sale_items_section.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. namespace App;
  3. use App\Helpers\HtmlHelper;
  4. use NumberFormatter;
  5. /**
  6. * @var Sale $sale
  7. */
  8. ?>
  9. <section id="sale-items-section" class="mb-4">
  10. <div class="row mb-3">
  11. <div class="col">
  12. <h3><?=htmlspecialchars("Lead Items")?></h3>
  13. </div>
  14. <div class="col-auto">
  15. <button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#sale-item-modal" data-sale-number="<?=$sale->getNumber()?>">
  16. <i class="fa fa-fw fa-plus"></i>
  17. <?=htmlspecialchars(__("Add Item"))?>
  18. </button>
  19. </div>
  20. </div>
  21. <?php
  22. $items = $sale->getItems();
  23. if(empty($items)) {
  24. HtmlHelper::renderInfoAlert(__("No items to display."));
  25. }
  26. else {
  27. $subtotal = "0.00";
  28. $formatter = new NumberFormatter("en_GB", NumberFormatter::CURRENCY);
  29. $currency = $sale->getCurrency();
  30. ?>
  31. <form action="<?=$sale->getUrl()?>/items-batch-action" method="post">
  32. <table id="sale-items-table" class="table table-bordered table-hover mb-3">
  33. <colgroup>
  34. <col style="width: 1%"/>
  35. <col style="width: 40%"/>
  36. <col style="width: 20%"/>
  37. <col style="width: 20%"/>
  38. <col style="width: 20%"/>
  39. <col style="width: 1%"/>
  40. </colgroup>
  41. <thead>
  42. <tr>
  43. <th>
  44. <!--suppress HtmlFormInputWithoutLabel -->
  45. <input class="form-check-input" id="sale-items-all-checkbox" type="checkbox" />
  46. </th>
  47. <th><?=htmlspecialchars(__("Product"))?></th>
  48. <th><?=htmlspecialchars(__("Quantity"))?></th>
  49. <th><?=htmlspecialchars(__("Unit Price"))?></th>
  50. <th><?=htmlspecialchars(__("Amount"))?></th>
  51. <th><?=htmlspecialchars(__("Actions"))?></th>
  52. </tr>
  53. </thead>
  54. <tbody>
  55. <?php
  56. foreach($items as $item) {
  57. $product = $item->getProduct();
  58. $supplier = $product->getSupplier();
  59. ?>
  60. <tr>
  61. <td>
  62. <!--suppress HtmlFormInputWithoutLabel -->
  63. <input class="form-check-input" type="checkbox" value="<?=$item->id?>" name="sale_item_ids[]" />
  64. </td>
  65. <td>
  66. <small class="text-uppercase text-muted"><?=htmlspecialchars($supplier->name)?></small><br />
  67. <?=htmlspecialchars($product->name)?>
  68. </td>
  69. <td class="text-end">
  70. <?=$item->quantity?>
  71. </td>
  72. <td class="text-end">
  73. <?=htmlspecialchars($formatter->formatCurrency($item->unit_price, $currency))?>
  74. </td>
  75. <td class="text-end">
  76. <?=htmlspecialchars($formatter->formatCurrency($item->getAmount(), $currency))?>
  77. </td>
  78. <td class="p-1 text-nowrap">
  79. <button class="btn btn-sm btn-primary" type="button" data-bs-toggle="modal" data-bs-target="#sale-item-modal" data-sale-number="<?=$sale->getNumber()?>" data-supplier-id="<?=$supplier->id?>" data-item="<?=htmlspecialchars(json_encode($item))?>">
  80. <i class="fa fa-fw fa-pencil"></i>
  81. </button>
  82. <button class="btn btn-sm btn-danger btn-delete-sale-item" type="button" data-sale-item-id="<?=$item->id?>">
  83. <i class="fa fa-fw fa-trash"></i>
  84. </button>
  85. </td>
  86. </tr>
  87. <?php
  88. $subtotal = bcadd($subtotal, $item->getAmount(), 2);
  89. }
  90. $tax = bcmul($subtotal, $sale->tax_rate / 100, 2);
  91. $total = bcadd($subtotal, $tax, 2);
  92. ?>
  93. </tbody>
  94. <tfoot>
  95. <tr>
  96. <th colspan="4" class="text-end"><?=htmlspecialchars(__("Subtotal"))?></th>
  97. <td class="text-end"><?=htmlspecialchars($formatter->formatCurrency($subtotal, $currency))?></td>
  98. <td></td>
  99. </tr>
  100. <tr>
  101. <th colspan="4" class="text-end"><?=htmlspecialchars(__("Tax Rate"))?></th>
  102. <td class="text-end">
  103. <?=$sale->tax_rate?>%
  104. </td>
  105. <td></td>
  106. </tr>
  107. <tr>
  108. <th colspan="4" class="text-end"><?=htmlspecialchars(__("Tax"))?></th>
  109. <td class="text-end">
  110. <?=htmlspecialchars($formatter->formatCurrency($tax, $currency))?>
  111. </td>
  112. <td></td>
  113. </tr>
  114. <tr>
  115. <th colspan="4" class="text-end"><?=htmlspecialchars(__("Total"))?></th>
  116. <td class="text-end">
  117. <?=htmlspecialchars($formatter->formatCurrency($total, $currency))?>
  118. </td>
  119. <td></td>
  120. </tr>
  121. </tfoot>
  122. </table>
  123. <div class="mb-1">
  124. <?=htmlspecialchars(__("With selected items:"))?>
  125. </div>
  126. <button type="submit" class="btn btn-primary batch-action" name="batch_action" value="create-sales-order" disabled>
  127. <i class="fa fa-fw fa-file-invoice"></i>
  128. <?=htmlspecialchars(__("Create Sales Order"))?>
  129. </button>
  130. <button type="submit" class="btn btn-danger batch-action" name="batch_action" value="delete" disabled>
  131. <i class="fa fa-fw fa-trash"></i>
  132. <?=htmlspecialchars(__("Delete"))?>
  133. </button>
  134. </form>
  135. <?php
  136. }
  137. ?>
  138. </section>