documents.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. $show_batch_actions = $is_sale_order && $documents;
  41. ?>
  42. <div class="row mb-3">
  43. <div class="col">
  44. <h3><?=htmlspecialchars($title)?></h3>
  45. </div>
  46. <?php
  47. if($is_sale_order || $is_goods_in || $is_aru) {
  48. ?>
  49. <div class="col-auto">
  50. <button type="button" id="new-document-button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#new-document-modal" data-type="<?=$type?>">
  51. <i class="fa fa-fw fa-plus"></i>
  52. <?=htmlspecialchars(__("Add"))?>
  53. </button>
  54. </div>
  55. <?php
  56. }
  57. ?>
  58. </div>
  59. <form method="post">
  60. <div class="card mb-3">
  61. <div class="card-header">
  62. <?=htmlspecialchars(__("Filters"))?>
  63. </div>
  64. <div class="card-body">
  65. <div class="row">
  66. <?php
  67. if($is_goods_in) {
  68. ?>
  69. <div class="col-sm-4">
  70. <?php
  71. View::include("components/supplier_id_field", compact("supplier_id"));
  72. ?>
  73. </div>
  74. <?php
  75. }
  76. ?>
  77. <div class="col-sm-4">
  78. <?php
  79. View::include("components/customer_id_field", compact("customer_id"));
  80. ?>
  81. </div>
  82. <div class="col-sm-4">
  83. <?php
  84. View::include("components/location_id_field", compact("location_id"));
  85. ?>
  86. </div>
  87. <?php
  88. if($status_options) {
  89. ?>
  90. <div class="col-sm-4">
  91. <div class="mb-3">
  92. <label class="form-label" for="status"><?=htmlspecialchars(__("Status"))?></label>
  93. <select class="form-select" name="status" id="status">
  94. <option value=""><?=htmlspecialchars(__("Any Status"))?></option>
  95. <?php
  96. HtmlHelper::renderOptions($status_options, $status);
  97. ?>
  98. </select>
  99. </div>
  100. </div>
  101. <?php
  102. }
  103. ?>
  104. <div class="col-sm-4">
  105. <div class="mb-3">
  106. <label class="form-label" for="number"><?=htmlspecialchars(__("Number"))?></label>
  107. <input class="form-control" type="number" name="number" id="number" value="<?=htmlspecialchars($number)?>" placeholder="<?=htmlspecialchars(__("Type number"))?>" />
  108. </div>
  109. </div>
  110. <?php
  111. if($custom_filter_options) {
  112. ?>
  113. <div class="col-sm-4">
  114. <div class="mb-3">
  115. <label class="form-label" for="custom-filter"><?=htmlspecialchars(__("Custom Filter"))?></label>
  116. <select class="form-select" name="custom_filter" id="custom-filter">
  117. <option value=""><?=htmlspecialchars(__("All %s", $title))?></option>
  118. <?php
  119. HtmlHelper::renderOptions($custom_filter_options, $custom_filter);
  120. ?>
  121. </select>
  122. </div>
  123. </div>
  124. <?php
  125. }
  126. ?>
  127. </div>
  128. <button class="btn btn-primary" type="submit">
  129. <?=htmlspecialchars(__("Submit"))?>
  130. </button>
  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. <?php
  148. if($show_batch_actions) {
  149. ?>
  150. <th class="text-center">
  151. <label>
  152. <input type="checkbox" id="documents-table-select-all" />
  153. </label>
  154. </th>
  155. <?php
  156. }
  157. ?>
  158. <th><?=htmlspecialchars(__("Ref."))?></th>
  159. <th><?=htmlspecialchars(__("Date"))?></th>
  160. <?php
  161. if(!$status_options) {
  162. if($is_goods_in) {
  163. $column_name = __("Location / Supplier");
  164. }
  165. else {
  166. $column_name = __("Location");
  167. }
  168. ?>
  169. <th><?=htmlspecialchars($column_name)?></th>
  170. <?php
  171. }
  172. else {
  173. ?>
  174. <th><?=htmlspecialchars(__("Location"))?></th>
  175. <th><?=htmlspecialchars(__("Status"))?></th>
  176. <?php
  177. }
  178. ?>
  179. <th><?=htmlspecialchars(__("Items"))?></th>
  180. <?php
  181. if($is_sale_order) {
  182. ?>
  183. <th><?=htmlspecialchars(__("Value"))?></th>
  184. <?php
  185. }
  186. ?>
  187. <th><?=htmlspecialchars(__("Actions"))?></th>
  188. </tr>
  189. </thead>
  190. <tbody>
  191. <?php
  192. foreach($documents as $document) {
  193. $location = $document->getLocation();
  194. $supplier = $document->getSupplier();
  195. ?>
  196. <tr>
  197. <?php
  198. if($show_batch_actions) {
  199. ?>
  200. <td class="text-center">
  201. <label>
  202. <input type="checkbox" name="document_ids[]" value="<?=$document->id?>" />
  203. </label>
  204. </td>
  205. <?php
  206. }
  207. ?>
  208. <td class="text-end">
  209. <a href="<?=htmlspecialchars($document->getUrl())?>"><?=$document->getReference()?></a>
  210. </td>
  211. <td>
  212. <?=htmlspecialchars($document->getDisplayDate())?>
  213. </td>
  214. <td>
  215. <?php
  216. if($location) {
  217. ?>
  218. <a href="<?=htmlspecialchars($location->getUrl())?>">
  219. <?=htmlspecialchars($location->getDisplayName())?>
  220. </a>
  221. <?php
  222. }
  223. if($supplier) {
  224. ?>
  225. <a href="<?=htmlspecialchars($supplier->getUrl())?>">
  226. <?=htmlspecialchars($supplier->name)?>
  227. </a>
  228. <?php
  229. }
  230. ?>
  231. </td>
  232. <?php
  233. if($status_options) {
  234. if($is_sale_order) {
  235. ?>
  236. <td>
  237. <?=htmlspecialchars($document->getDisplaySalesOrderStatus())?>
  238. </td>
  239. <?php
  240. }
  241. else {
  242. ?>
  243. <td>
  244. <?=htmlspecialchars($document->getDisplayAruStatus())?>
  245. </td>
  246. <?php
  247. }
  248. }
  249. ?>
  250. <td>
  251. <?php
  252. View::include("components/document_items_unstyled_list", ["items" => $document->getItems()]);
  253. ?>
  254. </td>
  255. <?php
  256. if($is_sale_order) {
  257. ?>
  258. <td class="text-end">
  259. <?=htmlspecialchars($document->getDisplaySubtotal())?>
  260. </td>
  261. <?php
  262. }
  263. ?>
  264. <td class="p-1">
  265. <a class="btn btn-sm btn-primary" href="<?=htmlspecialchars($document->getUrl())?>">
  266. <?=htmlspecialchars(__("View"))?>
  267. </a>
  268. </td>
  269. </tr>
  270. <?php
  271. }
  272. ?>
  273. </tbody>
  274. </table>
  275. <?php
  276. $pagination->render();
  277. if($show_batch_actions) {
  278. ?>
  279. <div class="card mb-3">
  280. <div class="card-header">
  281. <?=htmlspecialchars(__("Batch Actions"))?>
  282. </div>
  283. <div class="card-body">
  284. <label class="sr-only" for="batch-action"><?=htmlspecialchars(__("Batch Action"))?></label>
  285. <div class="input-group">
  286. <select class="form-control" name="batch_action" id="batch-action">
  287. <option value=""><?=htmlspecialchars(__("Select Batch Action"))?></option>
  288. <option value="mark-draft"><?=htmlspecialchars(__("Mark As Draft"))?></option>
  289. <option value="mark-shipped"><?=htmlspecialchars(__("Mark As Shipped"))?></option>
  290. <option value="mark-paid"><?=htmlspecialchars(__("Mark As Paid"))?></option>
  291. <option value="mark-void"><?=htmlspecialchars(__("Mark As Void"))?></option>
  292. <option value="mark-uncollectible"><?=htmlspecialchars(__("Mark As Uncollectible"))?></option>
  293. </select>
  294. <button type="submit" class="btn btn-primary">
  295. <?=htmlspecialchars(__("Submit"))?>
  296. </button>
  297. </div>
  298. </div>
  299. </div>
  300. <?php
  301. }
  302. ?>
  303. <?php
  304. }
  305. ?>
  306. </form>