documents.php 6.1 KB

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