document_items_section.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  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->isSalesOrder()) {
  11. $title = __("Sales Order 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" data-document-type="<?=$document->type?>">
  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-3">
  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. if($document->isDeliveryNote()) {
  53. ?>
  54. <col style="width: 15%"/>
  55. <?php
  56. }
  57. ?>
  58. <col style="width: 1%"/>
  59. </colgroup>
  60. <thead>
  61. <tr>
  62. <th>
  63. <!--suppress HtmlFormInputWithoutLabel -->
  64. <input class="form-check-input" id="all-items-checkbox" type="checkbox" />
  65. </th>
  66. <th><?=htmlspecialchars(__("Description"))?></th>
  67. <th><?=htmlspecialchars(__("Serial Number"))?></th>
  68. <th><?=htmlspecialchars(__("Quantity"))?></th>
  69. <?php
  70. if($document->hasCosts()) {
  71. ?>
  72. <th><?=htmlspecialchars(__("Unit Price"))?></th>
  73. <th><?=htmlspecialchars(__("Amount"))?></th>
  74. <?php
  75. }
  76. if($document->isDeliveryNote()) {
  77. ?>
  78. <th><?=htmlspecialchars(__("Insurance Value"))?></th>
  79. <?php
  80. }
  81. ?>
  82. <th><?=htmlspecialchars(__("Actions"))?></th>
  83. </tr>
  84. </thead>
  85. <tbody>
  86. <?php
  87. $formatter = new NumberFormatter("en_GB", NumberFormatter::CURRENCY);
  88. $currency = $document->currency;
  89. $subtotal = "0.00";
  90. foreach($document->getItems() as $item) {
  91. ?>
  92. <tr>
  93. <td>
  94. <!--suppress HtmlFormInputWithoutLabel -->
  95. <input class="form-check-input" type="checkbox" name="document_item_ids[]" value="<?=$item->id?>" />
  96. </td>
  97. <td>
  98. <?=htmlspecialchars($item->description)?>
  99. </td>
  100. <td>
  101. <?=htmlspecialchars($item->serial_number)?>
  102. </td>
  103. <td class="text-end">
  104. <?=$item->quantity?>
  105. </td>
  106. <?php
  107. if($document->hasCosts()) {
  108. ?>
  109. <td class="text-end">
  110. <?=htmlspecialchars($formatter->formatCurrency($item->unit_price, $currency))?>
  111. </td>
  112. <td class="text-end">
  113. <?=htmlspecialchars($formatter->formatCurrency($item->getAmount(), $currency))?>
  114. </td>
  115. <?php
  116. $subtotal = bcadd($subtotal, $item->getAmount());
  117. }
  118. if($document->isDeliveryNote()) {
  119. ?>
  120. <td class="text-end">
  121. <?=htmlspecialchars($formatter->formatCurrency($item->insurance_value, $currency))?>
  122. </td>
  123. <?php
  124. }
  125. ?>
  126. <td class="p-1 text-nowrap">
  127. <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-document-type="<?=$document->type?>" data-item="<?=htmlspecialchars(json_encode($item))?>">
  128. <i class="fa fa-fw fa-pencil"></i>
  129. </button>
  130. <button class="btn btn-sm btn-danger btn-delete-document-item" type="button" data-document-item-id="<?=$item->id?>">
  131. <i class="fa fa-fw fa-trash"></i>
  132. </button>
  133. </td>
  134. </tr>
  135. <?php
  136. }
  137. ?>
  138. </tbody>
  139. <?php
  140. if($document->hasCosts()) {
  141. $tax = bcmul($subtotal, $document->tax_rate / 100, 2);
  142. $total = bcadd($subtotal, $tax, 2);
  143. ?>
  144. <tfoot>
  145. <tr>
  146. <th colspan="5" class="text-end"><?=htmlspecialchars(__("Subtotal"))?></th>
  147. <td class="text-end"><?=htmlspecialchars($formatter->formatCurrency($subtotal, $currency))?></td>
  148. <td></td>
  149. </tr>
  150. <tr>
  151. <th colspan="5" class="text-end"><?=htmlspecialchars(__("Tax Rate"))?></th>
  152. <td class="text-end">
  153. <?=$document->tax_rate?>%
  154. </td>
  155. <td></td>
  156. </tr>
  157. <tr>
  158. <th colspan="5" class="text-end"><?=htmlspecialchars(__("Tax"))?></th>
  159. <td class="text-end">
  160. <?=htmlspecialchars($formatter->formatCurrency($tax, $currency))?>
  161. </td>
  162. <td></td>
  163. </tr>
  164. <tr>
  165. <th colspan="5" class="text-end"><?=htmlspecialchars(__("Total"))?></th>
  166. <td class="text-end">
  167. <?=htmlspecialchars($formatter->formatCurrency($total, $currency))?>
  168. </td>
  169. <td></td>
  170. </tr>
  171. </tfoot>
  172. <?php
  173. }
  174. ?>
  175. </table>
  176. <div class="mb-1">
  177. <?=htmlspecialchars(__("With selected items:"))?>
  178. </div>
  179. <?php
  180. if($document->isAru()) {
  181. ?>
  182. <button type="submit" class="btn btn-primary batch-action" name="batch_action" value="create-sales-order" disabled>
  183. <i class="fa fa-fw fa-file-invoice"></i>
  184. <?=htmlspecialchars(__("Create Sales Order"))?>
  185. </button>
  186. <button type="submit" class="btn btn-primary batch-action" name="batch_action" value="create-goods-in" disabled>
  187. <i class="fa fa-fw fa-truck"></i>
  188. <?=htmlspecialchars(__("Create Goods-In"))?>
  189. </button>
  190. <?php
  191. }
  192. if($document->hasCosts() && !$document->isPartOfAru()) {
  193. ?>
  194. <button type="submit" class="btn btn-primary batch-action" name="batch_action" value="create-delivery-note" disabled>
  195. <i class="fa fa-fw fa-file-invoice"></i>
  196. <?=htmlspecialchars(__("Create Delivery Note"))?>
  197. </button>
  198. <?php
  199. }
  200. ?>
  201. <button type="submit" class="btn btn-danger batch-action" name="batch_action" value="delete" disabled>
  202. <i class="fa fa-fw fa-trash"></i>
  203. <?=htmlspecialchars(__("Delete"))?>
  204. </button>
  205. </form>
  206. <?php
  207. }
  208. ?>
  209. </section>