document_items_section.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. namespace App;
  3. use App\Helpers\HtmlHelper;
  4. use NumberFormatter;
  5. /**
  6. * @var Document $document
  7. */
  8. $items = $document->getItems();
  9. $title = __("Items");
  10. if($document->isInvoice()) {
  11. $title = __("Invoice Items");
  12. }
  13. if($document->isDeliveryNote()) {
  14. $title = __("Delivery Items");
  15. }
  16. if($document->isAru()) {
  17. $title = __("Return Items");
  18. }
  19. ?>
  20. <section class="mb-4" id="document-items-section">
  21. <div class="row mb-3">
  22. <div class="col">
  23. <h3><?=htmlspecialchars($title)?></h3>
  24. </div>
  25. <div class="col-auto">
  26. <button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#document-item-modal">
  27. <i class="fa fa-fw fa-plus"></i>
  28. <?=htmlspecialchars(__("Add Item"))?>
  29. </button>
  30. </div>
  31. </div>
  32. <?php
  33. if(empty($items)) {
  34. HtmlHelper::renderInfoAlert(__("No items to display."));
  35. }
  36. else {
  37. ?>
  38. <form action="<?=htmlspecialchars($document->getUrl())?>/items-batch-action" method="post">
  39. <table class="table table-bordered table-hover mb-2">
  40. <colgroup>
  41. <col style="width: 1%"/>
  42. <col style="width: 35%"/>
  43. <col style="width: 20%"/>
  44. <col style="width: 15%"/>
  45. <?php
  46. if($document->hasCosts()) {
  47. ?>
  48. <col style="width: 15%"/>
  49. <col style="width: 15%"/>
  50. <?php
  51. }
  52. ?>
  53. <col style="width: 1%"/>
  54. </colgroup>
  55. <thead>
  56. <tr>
  57. <th>
  58. <!--suppress HtmlFormInputWithoutLabel -->
  59. <input class="form-check-input" id="all-items-checkbox" type="checkbox" />
  60. </th>
  61. <th><?=htmlspecialchars(__("Description"))?></th>
  62. <th><?=htmlspecialchars(__("Serial Number"))?></th>
  63. <th><?=htmlspecialchars(__("Quantity"))?></th>
  64. <?php
  65. if($document->hasCosts()) {
  66. ?>
  67. <th><?=htmlspecialchars(__("Unit Price"))?></th>
  68. <th><?=htmlspecialchars(__("Amount"))?></th>
  69. <?php
  70. }
  71. ?>
  72. <th><?=htmlspecialchars(__("Actions"))?></th>
  73. </tr>
  74. </thead>
  75. <tbody>
  76. <?php
  77. $formatter = new NumberFormatter("en_GB", NumberFormatter::CURRENCY);
  78. $currency = $document->currency;
  79. $subtotal = "0.00";
  80. foreach($document->getItems() as $item) {
  81. ?>
  82. <tr>
  83. <td>
  84. <!--suppress HtmlFormInputWithoutLabel -->
  85. <input class="form-check-input" type="checkbox" name="document_item_ids[]" value="<?=$item->id?>" />
  86. </td>
  87. <td>
  88. <?=htmlspecialchars($item->description)?>
  89. </td>
  90. <td>
  91. <?=htmlspecialchars($item->serial_number)?>
  92. </td>
  93. <td class="text-end">
  94. <?=$item->quantity?>
  95. </td>
  96. <?php
  97. if($document->hasCosts()) {
  98. ?>
  99. <td class="text-end">
  100. <?=htmlspecialchars($formatter->formatCurrency($item->unit_price, $currency))?>
  101. </td>
  102. <td class="text-end">
  103. <?=htmlspecialchars($formatter->formatCurrency($item->getAmount(), $currency))?>
  104. </td>
  105. <?php
  106. $subtotal = bcadd($subtotal, $item->getAmount());
  107. }
  108. ?>
  109. <td class="p-1 text-nowrap">
  110. <button class="btn btn-sm btn-primary" type="button" data-bs-toggle="modal" data-bs-target="#document-item-modal" data-document-id="<?=$document->id?>" data-item="<?=htmlspecialchars(json_encode($item))?>">
  111. <i class="fa fa-fw fa-pencil"></i>
  112. </button>
  113. <button class="btn btn-sm btn-danger btn-delete-document-item" type="button" data-document-item-id="<?=$item->id?>">
  114. <i class="fa fa-fw fa-trash"></i>
  115. </button>
  116. </td>
  117. </tr>
  118. <?php
  119. }
  120. ?>
  121. </tbody>
  122. <?php
  123. if($document->hasCosts()) {
  124. $tax = bcmul($subtotal, $document->tax_rate / 100, 2);
  125. $total = bcadd($subtotal, $tax, 2);
  126. ?>
  127. <tfoot>
  128. <tr>
  129. <th colspan="5" class="text-end"><?=htmlspecialchars(__("Subtotal"))?></th>
  130. <td class="text-end"><?=htmlspecialchars($formatter->formatCurrency($subtotal, $currency))?></td>
  131. <td></td>
  132. </tr>
  133. <tr>
  134. <th colspan="5" class="text-end"><?=htmlspecialchars(__("Tax Rate"))?></th>
  135. <td class="text-end">
  136. <?=$document->tax_rate?>%
  137. </td>
  138. <td></td>
  139. </tr>
  140. <tr>
  141. <th colspan="5" class="text-end"><?=htmlspecialchars(__("Tax"))?></th>
  142. <td class="text-end">
  143. <?=htmlspecialchars($formatter->formatCurrency($tax, $currency))?>
  144. </td>
  145. <td></td>
  146. </tr>
  147. <tr>
  148. <th colspan="5" class="text-end"><?=htmlspecialchars(__("Total"))?></th>
  149. <td class="text-end">
  150. <?=htmlspecialchars($formatter->formatCurrency($total, $currency))?>
  151. </td>
  152. <td></td>
  153. </tr>
  154. </tfoot>
  155. <?php
  156. }
  157. ?>
  158. </table>
  159. <div class="mb-1">
  160. <?=htmlspecialchars(__("With selected items:"))?>
  161. </div>
  162. <?php
  163. if($document->isAru()) {
  164. ?>
  165. <button type="submit" class="btn btn-primary" name="batch_action" value="create-invoice">
  166. <i class="fa fa-fw fa-file-invoice"></i>
  167. <?=htmlspecialchars(__("Create Invoice"))?>
  168. </button>
  169. <?php
  170. }
  171. if($document->hasCosts() && !$document->isPartOfAru()) {
  172. ?>
  173. <button type="submit" class="btn btn-primary" name="batch_action" value="create-delivery-note">
  174. <i class="fa fa-fw fa-file-invoice"></i>
  175. <?=htmlspecialchars(__("Create Delivery Note"))?>
  176. </button>
  177. <?php
  178. }
  179. ?>
  180. <button type="submit" class="btn btn-danger" name="batch_action" value="delete">
  181. <i class="fa fa-fw fa-trash"></i>
  182. <?=htmlspecialchars(__("Delete"))?>
  183. </button>
  184. </form>
  185. <?php
  186. }
  187. ?>
  188. </section>