documents.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. namespace App;
  3. use App\Enums\AruStatuses;
  4. use App\Enums\DocumentTypes;
  5. use App\Enums\InvoiceStatuses;
  6. use App\Helpers\HtmlHelper;
  7. /**
  8. * @var string $title
  9. * @var string $type_string
  10. * @var int $type
  11. * @var Document[] $documents
  12. * @var Pagination $pagination
  13. * @var int $supplier_id
  14. * @var int $customer_id
  15. * @var int $location_id
  16. * @var int $status
  17. * @var int $number
  18. * @var int $custom_filter
  19. */
  20. $is_invoice = ($type === DocumentTypes::INVOICE);
  21. $is_goods_in = ($type === DocumentTypes::GOODS_IN);
  22. $is_aru = ($type === DocumentTypes::ADVANCE_REPLACEMENT_UNIT);
  23. $status_options = [];
  24. $custom_filter_options = [];
  25. if($is_invoice) {
  26. $status_options = InvoiceStatuses::options();
  27. $custom_filter_options = [
  28. "open" => "Open Invoices",
  29. ];
  30. }
  31. if($is_aru) {
  32. $status_options = AruStatuses::options();
  33. $custom_filter_options = [
  34. "open" => "Open ARUs",
  35. ];
  36. }
  37. ?>
  38. <div class="row mb-3">
  39. <div class="col">
  40. <h3><?=htmlspecialchars($title)?></h3>
  41. </div>
  42. <?php
  43. if($is_goods_in || $is_aru) {
  44. ?>
  45. <div class="col-auto">
  46. <a class="btn btn-success" data-bs-toggle="modal" data-bs-target="#new-document-modal" data-type="<?=$type?>">
  47. <i class="fa fa-fw fa-plus"></i>
  48. <?=htmlspecialchars(__("Add"))?>
  49. </a>
  50. </div>
  51. <?php
  52. }
  53. ?>
  54. </div>
  55. <div class="card mb-3">
  56. <div class="card-header">
  57. <?=htmlspecialchars(__("Filters"))?>
  58. </div>
  59. <div class="card-body">
  60. <form action="/<?=$type_string?>" method="post">
  61. <div class="row">
  62. <?php
  63. if($is_goods_in) {
  64. ?>
  65. <div class="col-sm-4">
  66. <?php
  67. View::include("components/supplier_id_field", compact("supplier_id"));
  68. ?>
  69. </div>
  70. <?php
  71. }
  72. ?>
  73. <div class="col-sm-4">
  74. <?php
  75. View::include("components/customer_id_field", compact("customer_id"));
  76. ?>
  77. </div>
  78. <div class="col-sm-4">
  79. <?php
  80. View::include("components/location_id_field", compact("location_id"));
  81. ?>
  82. </div>
  83. <?php
  84. if($status_options) {
  85. ?>
  86. <div class="col-sm-4">
  87. <div class="mb-3">
  88. <label class="form-label" for="status"><?=htmlspecialchars(__("Status"))?></label>
  89. <select class="form-control" name="status" id="status">
  90. <option value=""><?=htmlspecialchars(__("Any Status"))?></option>
  91. <?php
  92. HtmlHelper::renderOptions($status_options, $status);
  93. ?>
  94. </select>
  95. </div>
  96. </div>
  97. <?php
  98. }
  99. ?>
  100. <div class="col-sm-4">
  101. <div class="mb-3">
  102. <label class="form-label" for="number"><?=htmlspecialchars(__("Number"))?></label>
  103. <input class="form-control" type="number" name="number" id="number" value="<?=htmlspecialchars($number)?>" placeholder="<?=htmlspecialchars(__("Type number"))?>" />
  104. </div>
  105. </div>
  106. <?php
  107. if($custom_filter_options) {
  108. ?>
  109. <div class="col-sm-4">
  110. <div class="mb-3">
  111. <label class="form-label" for="custom-filter"><?=htmlspecialchars(__("Custom Filter"))?></label>
  112. <select class="form-control" name="custom_filter" id="custom-filter">
  113. <option value=""><?=htmlspecialchars(__("All %s", $title))?></option>
  114. <?php
  115. HtmlHelper::renderOptions($custom_filter_options, $custom_filter);
  116. ?>
  117. </select>
  118. </div>
  119. </div>
  120. <?php
  121. }
  122. ?>
  123. </div>
  124. <button class="btn btn-primary" type="submit">
  125. <?=htmlspecialchars(__("Submit"))?>
  126. </button>
  127. </form>
  128. </div>
  129. </div>
  130. <?php
  131. if(empty($documents)) {
  132. ?>
  133. <div class="alert alert-info">
  134. <i class="fa fa-fw fa-info-circle"></i>
  135. <?=htmlspecialchars(__("No %s to display.", $title))?>
  136. </div>
  137. <?php
  138. }
  139. else {
  140. ?>
  141. <table class="table table-bordered table-hover mb-3">
  142. <colgroup>
  143. <col style="width: 1%"/>
  144. <?php
  145. if($is_goods_in) {
  146. ?>
  147. <col style="width: 20%"/>
  148. <?php
  149. }
  150. else {
  151. ?>
  152. <col style="width: 20%"/>
  153. <col style="width: 20%"/>
  154. <?php
  155. }
  156. ?>
  157. <col style="width: 60%"/>
  158. <col style="width: 1%"/>
  159. </colgroup>
  160. <thead>
  161. <tr>
  162. <th><?=htmlspecialchars(__("No."))?></th>
  163. <?php
  164. if($is_goods_in) {
  165. ?>
  166. <th><?=htmlspecialchars(__("Location / Supplier"))?></th>
  167. <?php
  168. }
  169. else {
  170. ?>
  171. <th><?=htmlspecialchars(__("Location"))?></th>
  172. <th><?=htmlspecialchars(__("Status"))?></th>
  173. <?php
  174. }
  175. ?>
  176. <th><?=htmlspecialchars(__("Items"))?></th>
  177. <th><?=htmlspecialchars(__("Actions"))?></th>
  178. </tr>
  179. </thead>
  180. <tbody>
  181. <?php
  182. foreach($documents as $document) {
  183. $location = $document->getLocation();
  184. $supplier = $document->getSupplier();
  185. ?>
  186. <tr>
  187. <td class="text-end">
  188. <a href="<?=htmlspecialchars($document->getUrl())?>"><?=$document->number?></a>
  189. </td>
  190. <td>
  191. <?php
  192. if($location) {
  193. ?>
  194. <a href="<?=htmlspecialchars($location->getUrl())?>">
  195. <?=htmlspecialchars($location->getDisplayName())?>
  196. </a>
  197. <?php
  198. }
  199. if($supplier) {
  200. ?>
  201. <a href="<?=htmlspecialchars($supplier->getUrl())?>">
  202. <?=htmlspecialchars($supplier->name)?>
  203. </a>
  204. <?php
  205. }
  206. ?>
  207. </td>
  208. <?php
  209. if(!$is_goods_in) {
  210. if($is_invoice) {
  211. ?>
  212. <td>
  213. <?=htmlspecialchars($document->getDisplayInvoiceStatus())?>
  214. </td>
  215. <?php
  216. }
  217. else {
  218. ?>
  219. <td>
  220. <?=htmlspecialchars($document->getDisplayAruStatus())?>
  221. </td>
  222. <?php
  223. }
  224. }
  225. ?>
  226. <td>
  227. <?php
  228. View::include("components/document_items_unstyled_list", ["items" => $document->getItems()]);
  229. ?>
  230. </td>
  231. <td class="p-1">
  232. <a class="btn btn-sm btn-primary" href="<?=htmlspecialchars($document->getUrl())?>">
  233. <?=htmlspecialchars(__("View"))?>
  234. </a>
  235. </td>
  236. </tr>
  237. <?php
  238. }
  239. ?>
  240. </tbody>
  241. </table>
  242. <?php
  243. $pagination->render();
  244. }