document_items_section.php 4.9 KB

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