documents.php 5.8 KB

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