1
0

documents.php 7.7 KB

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