documents.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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_sale_order || $is_goods_in || $is_aru) {
  47. ?>
  48. <div class="col-auto">
  49. <button type="button" id="new-document-button" 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. </button>
  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. <thead>
  146. <tr>
  147. <th><?=htmlspecialchars(__("Ref."))?></th>
  148. <th><?=htmlspecialchars(__("Date"))?></th>
  149. <?php
  150. if(!$status_options) {
  151. if($is_goods_in) {
  152. $column_name = __("Location / Supplier");
  153. }
  154. else {
  155. $column_name = __("Location");
  156. }
  157. ?>
  158. <th><?=htmlspecialchars($column_name)?></th>
  159. <?php
  160. }
  161. else {
  162. ?>
  163. <th><?=htmlspecialchars(__("Location"))?></th>
  164. <th><?=htmlspecialchars(__("Status"))?></th>
  165. <?php
  166. }
  167. ?>
  168. <th><?=htmlspecialchars(__("Items"))?></th>
  169. <?php
  170. if($is_sale_order) {
  171. ?>
  172. <th><?=htmlspecialchars(__("Value"))?></th>
  173. <?php
  174. }
  175. ?>
  176. <th><?=htmlspecialchars(__("Actions"))?></th>
  177. </tr>
  178. </thead>
  179. <tbody>
  180. <?php
  181. foreach($documents as $document) {
  182. $location = $document->getLocation();
  183. $supplier = $document->getSupplier();
  184. ?>
  185. <tr>
  186. <td class="text-end">
  187. <a href="<?=htmlspecialchars($document->getUrl())?>"><?=$document->getReference()?></a>
  188. </td>
  189. <td>
  190. <?=htmlspecialchars($document->getDisplayDate())?>
  191. </td>
  192. <td>
  193. <?php
  194. if($location) {
  195. ?>
  196. <a href="<?=htmlspecialchars($location->getUrl())?>">
  197. <?=htmlspecialchars($location->getDisplayName())?>
  198. </a>
  199. <?php
  200. }
  201. if($supplier) {
  202. ?>
  203. <a href="<?=htmlspecialchars($supplier->getUrl())?>">
  204. <?=htmlspecialchars($supplier->name)?>
  205. </a>
  206. <?php
  207. }
  208. ?>
  209. </td>
  210. <?php
  211. if($status_options) {
  212. if($is_sale_order) {
  213. ?>
  214. <td>
  215. <?=htmlspecialchars($document->getDisplaySalesOrderStatus())?>
  216. </td>
  217. <?php
  218. }
  219. else {
  220. ?>
  221. <td>
  222. <?=htmlspecialchars($document->getDisplayAruStatus())?>
  223. </td>
  224. <?php
  225. }
  226. }
  227. ?>
  228. <td>
  229. <?php
  230. View::include("components/document_items_unstyled_list", ["items" => $document->getItems()]);
  231. ?>
  232. </td>
  233. <?php
  234. if($is_sale_order) {
  235. ?>
  236. <td class="text-end">
  237. <?=htmlspecialchars($document->getDisplaySubtotal())?>
  238. </td>
  239. <?php
  240. }
  241. ?>
  242. <td class="p-1">
  243. <a class="btn btn-sm btn-primary" href="<?=htmlspecialchars($document->getUrl())?>">
  244. <?=htmlspecialchars(__("View"))?>
  245. </a>
  246. </td>
  247. </tr>
  248. <?php
  249. }
  250. ?>
  251. </tbody>
  252. </table>
  253. <?php
  254. $pagination->render();
  255. }