test_list.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. /**
  3. * @var int $filter_count
  4. * @var array $sorts
  5. * @var string $sort
  6. * @var int $status
  7. * @var int $status_tester_invoice
  8. * @var Customer[] $customers
  9. * @var int $customer_id
  10. * @var Project[] $projects
  11. * @var int $project_id
  12. * @var bool $pass
  13. * @var int $test_id
  14. * @var int $tester_id
  15. * @var int $location_id
  16. * @var int $location_internal_id
  17. * @var int $custom
  18. * @var object $pagination_object
  19. */
  20. $filters_collapse = $filter_count ? "collapse show" : "collapse";
  21. $query = $_GET;
  22. unset($query["path"]);
  23. $query["sort"] = "SORT";
  24. $results = [
  25. "" => "Any",
  26. "1" => "Pass",
  27. "0" => "Fail",
  28. ];
  29. $custom_filters = [
  30. "overdue_project" => "Overdue (Project Deadline)",
  31. "overdue_test" => "Overdue (Test Due Date)",
  32. ];
  33. ?>
  34. <div class="mt-3 py-4">
  35. <div class="container-fluid">
  36. <div class="row">
  37. <div class="col-sm">
  38. <h2>
  39. Tests
  40. </h2>
  41. </div>
  42. <div class="col-sm-auto">
  43. <div class="row">
  44. <div class="col-auto">
  45. <a class="btn btn-outline-primary" href="#filters" data-toggle="collapse">
  46. Toggle Filters <span class="badge badge-pill badge-danger"><?=$filter_count?></span>
  47. </a>
  48. </div>
  49. <div class="col">
  50. <div class="input-group">
  51. <div class="input-group-prepend">
  52. <label for="sort-dropdown" class="input-group-text">
  53. Sort
  54. </label>
  55. </div>
  56. <select class="form-control" id="sort-dropdown" data-url-template="/account/tests?<?=htmlspecialchars(http_build_query($query))?>">
  57. <?php
  58. foreach($sorts as $value => $display) {
  59. $selected = ($value == $sort) ? "selected" : "";
  60. ?>
  61. <option value="<?=$value?>" <?=$selected?>><?=$display?></option>
  62. <?php
  63. }
  64. ?>
  65. </select>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. <div class="row my-3">
  72. <div class="col mb-1">
  73. <a class="btn btn-block btn-primary" href="/account/tests">Show All</a>
  74. </div>
  75. <div class="col mb-1">
  76. <a class="btn btn-block btn-secondary" href="/account/tests?status=<?=Test::STATUS_UNASSIGNED?>">Unassigned</a>
  77. </div>
  78. <div class="col mb-1">
  79. <a class="btn btn-block btn-warning" href="/account/tests?status=<?=Test::STATUS_CONFIRMED?>">Confirmed</a>
  80. </div>
  81. <div class="col mb-1">
  82. <a class="btn btn-block btn-success" href="/account/tests?status=<?=Test::STATUS_PENDING_VERIFICATION?>">Pending Verification</a>
  83. </div>
  84. <div class="col mb-1">
  85. <a class="btn btn-block btn-danger" href="/account/tests?pass=0">Fails</a>
  86. </div>
  87. </div>
  88. <div class="<?=$filters_collapse?>" id="filters">
  89. <form method="get">
  90. <div class="card card-body bg-light text-dark mb-3">
  91. <h3>Filters</h3>
  92. <div class="row mb-1">
  93. <div class="col-lg-6">
  94. <div class="row mb-1">
  95. <label class="col-form-label col-sm-4" for="status">Status</label>
  96. <div class="col-sm">
  97. <select class="form-control" name="status" id="status">
  98. <option value="">Any not cancelled</option>
  99. <?php
  100. foreach(Test::STATUSES as $value => $display) {
  101. $selected = ($value === $status) ? "selected" : "";
  102. ?>
  103. <option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  104. <?php
  105. }
  106. ?>
  107. </select>
  108. </div>
  109. </div>
  110. <div class="row mb-1">
  111. <label class="col-form-label col-sm-4" for="status-tester-invoice">Tester Invoice Status</label>
  112. <div class="col-sm">
  113. <select class="form-control" name="status_tester_invoice" id="status-tester-invoice">
  114. <option value="">Any</option>
  115. <?php
  116. foreach(Test::STATUSES_TESTER_INVOICE as $value) {
  117. $display = Test::getStatusTesterInvoiceText($value);
  118. $selected = ($value === $status_tester_invoice) ? "selected" : "";
  119. ?>
  120. <option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  121. <?php
  122. }
  123. ?>
  124. </select>
  125. </div>
  126. </div>
  127. <div class="row mb-1">
  128. <label class="col-form-label col-sm-4" for="customer-id">Customer</label>
  129. <div class="col-sm">
  130. <select class="form-control" name="customer_id" id="customer-id">
  131. <option value="">Select customer</option>
  132. <?php
  133. foreach($customers as $customer) {
  134. $selected = ($customer->id == $customer_id) ? "selected" : "";
  135. ?>
  136. <option value="<?=$customer->id?>" <?=$selected?>><?=htmlspecialchars($customer->name)?></option>
  137. <?php
  138. }
  139. ?>
  140. </select>
  141. </div>
  142. </div>
  143. <div class="row mb-1">
  144. <label class="col-form-label col-sm-4" for="project-id">Project</label>
  145. <div class="col-sm">
  146. <select class="form-control" name="project_id" id="project-id">
  147. <option value="">Select project</option>
  148. <?php
  149. foreach($projects as $project) {
  150. $selected = ($project->id == $project_id) ? "selected" : "";
  151. ?>
  152. <option value="<?=$project->id?>" <?=$selected?>><?=htmlspecialchars($project->name)?></option>
  153. <?php
  154. }
  155. ?>
  156. </select>
  157. </div>
  158. </div>
  159. <div class="row mb-1">
  160. <label class="col-sm-4 col-form-label" for="pass">Result</label>
  161. <div class="col-sm">
  162. <select class="form-control" name="pass" id="pass">
  163. <?php
  164. foreach($results as $value => $display) {
  165. $selected = (strval($value) === strval($pass)) ? "selected" : "";
  166. ?>
  167. <option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  168. <?php
  169. }
  170. ?>
  171. </select>
  172. </div>
  173. </div>
  174. </div>
  175. <div class="col-lg">
  176. <div class="row mb-1">
  177. <label class="col-sm-4 col-form-label" for="test-id">Test ID</label>
  178. <div class="col-sm">
  179. <input class="form-control" type="text" name="test_id" id="test-id" placeholder="Enter test ID" value="<?=$test_id?>" />
  180. </div>
  181. </div>
  182. <div class="row mb-1">
  183. <label class="col-sm-4 col-form-label" for="tester-id">Tester ID</label>
  184. <div class="col-sm">
  185. <input class="form-control" type="text" name="tester_id" id="tester-id" placeholder="Enter tester ID" value="<?=$tester_id?>" />
  186. </div>
  187. </div>
  188. <div class="row mb-1">
  189. <label class="col-sm-4 col-form-label" for="location-id">Location ID</label>
  190. <div class="col-sm">
  191. <input class="form-control" type="text" name="location_id" id="location-id" placeholder="Enter location ID" value="<?=$location_id?>" />
  192. </div>
  193. </div>
  194. <div class="row mb-1">
  195. <label class="col-sm-4 col-form-label" for="location-internal-id">Internal ID</label>
  196. <div class="col-sm">
  197. <input class="form-control" type="text" name="location_internal_id" id="location-internal-id" placeholder="Enter location internal ID" value="<?=$location_internal_id?>" />
  198. </div>
  199. </div>
  200. <div class="row mb-1">
  201. <label class="col-sm-4 col-form-label" for="custom">Custom Filter</label>
  202. <div class="col-sm">
  203. <select class="form-control" name="custom" id="custom">
  204. <option value="">Select custom filter</option>
  205. <?php
  206. foreach($custom_filters as $value => $display) {
  207. $selected = (strval($value) === strval($custom)) ? "selected" : "";
  208. ?>
  209. <option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  210. <?php
  211. }
  212. ?>
  213. </select>
  214. </div>
  215. </div>
  216. </div>
  217. </div>
  218. <div class="row">
  219. <div class="col-lg">
  220. <div class="row">
  221. <div class="col-sm offset-sm-4">
  222. <button class="btn btn-primary" type="submit">Filter</button>
  223. <a class="btn btn-secondary" href="/account/tests">Clear Filters</a>
  224. </div>
  225. </div>
  226. </div>
  227. <div class="col-lg">
  228. </div>
  229. </div>
  230. </div>
  231. <input type="hidden" name="sort" value="<?=$sort?>" />
  232. </form>
  233. </div>
  234. <?php
  235. if(empty($tests)) {
  236. ?>
  237. <div class="alert alert-info">
  238. There are no tests to display.
  239. </div>
  240. <?php
  241. }
  242. else {
  243. ?>
  244. <div class="mb-3">
  245. <?php
  246. View::include("pagination", compact("pagination_object"));
  247. ?>
  248. </div>
  249. <form method="post">
  250. <div class="table-responsive mb-3" style="min-height: 224px;">
  251. <table class="table table-sm table-sm-text table-hover" style="min-width: 1024px;">
  252. <thead>
  253. <tr>
  254. <th>
  255. <label for="tests-table-select-all" class="sr-only">
  256. <?=htmlspecialchars(__("Select All"))?>
  257. </label>
  258. <input type="checkbox" id="tests-table-select-all" />
  259. </th>
  260. <th>ID</th>
  261. <th>Location</th>
  262. <th>Project</th>
  263. <th>Tester</th>
  264. <th>Due Date</th>
  265. <th>Status</th>
  266. <th>Result</th>
  267. <th></th>
  268. </tr>
  269. </thead>
  270. <tbody>
  271. <?php
  272. foreach($tests as $test) {
  273. $location = $test->getLocation();
  274. $project = $test->getProject();
  275. $tester = $test->getTester();
  276. $unix_start = strtotime($test->dts_start . " UTC");
  277. $unix_end = strtotime($test->dts_end . " UTC");
  278. ?>
  279. <tr>
  280. <td>
  281. <label for="test-checkbox-<?=$test->id?>" class="sr-only">
  282. <?=htmlspecialchars(__("Select Test ID %d", $test->id))?>
  283. </label>
  284. <input type="checkbox" name="test_ids[]" id="test-checkbox-<?=$test->id?>" value="<?=$test->id?>" />
  285. </td>
  286. <td>
  287. <?=$test->id?>
  288. </td>
  289. <td class="align-middle">
  290. <a href="/account/locations/<?=$location->id?>">
  291. <?=htmlspecialchars($location->name)?>
  292. <?php
  293. if($location->internal_id) {
  294. ?>
  295. (Internal ID: <?=htmlspecialchars($location->internal_id)?>)
  296. <?php
  297. }
  298. ?>
  299. </a><br />
  300. <?=htmlspecialchars($location->getDisplayAddress(["address_1", "address_2", "city"]))?>
  301. </td>
  302. <td class="align-middle">
  303. <a href="/account/projects/<?=$project->id?>"><?=htmlspecialchars($project->name)?></a><br />
  304. <strong>Deadline:</strong> <?=date("d/m/Y", strtotime($project->dts_deadline . " UTC"))?>
  305. </td>
  306. <td class="align-middle">
  307. <?php
  308. if($tester) {
  309. ?>
  310. <a href="/account/users/<?=$tester->id?>"><?=htmlspecialchars($tester->getDisplayName())?></a>
  311. <?php
  312. if($test->status_tester_invoice > 0) {
  313. $time = Util::getUnixTimeFromUTC($test->dts_tester_invoice_generated);
  314. $dts = Util::getDisplayDateTime($time);
  315. ?>
  316. <br />
  317. <span class="badge badge-<?=Test::getStatusTesterInvoiceClass($test->status_tester_invoice)?>" title="Generated on <?=$dts?>"><?=Test::getStatusTesterInvoiceText($test->status_tester_invoice)?></span>
  318. <?php
  319. }
  320. }
  321. else {
  322. ?>
  323. <small class="text-muted">N/A</small>
  324. <?php
  325. }
  326. ?>
  327. </td>
  328. <td class="text-center align-middle">
  329. <?php
  330. if(is_null($test->dts_due)) {
  331. ?>
  332. <small class="text-muted">N/A</small>
  333. <?php
  334. }
  335. else {
  336. ?>
  337. <?=explode(" ", $test->dts_due)[0]?>
  338. <?php
  339. }
  340. ?>
  341. </td>
  342. <td class="text-center align-middle">
  343. <span class="badge badge-<?=$test->getStatusClass()?>"><?=$test->getStatusText()?></span>
  344. </td>
  345. <td class="text-center align-middle text-<?=$test->getPassClass()?>">
  346. <div title="<?=$test->getPassText()?>">
  347. <i class="fas fa-2x fa-fw fa-<?=$test->getPassIcon()?>"></i>
  348. </div>
  349. </td>
  350. <td class="text-right align-middle">
  351. <div class="dropdown">
  352. <button class="btn btn-sm btn-secondary dropdown-toggle" type="button" id="test-dropdown-<?=$test->id?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  353. Actions
  354. </button>
  355. <div class="dropdown-menu" aria-labelledby="test-dropdown-<?=$test->id?>">
  356. <a class="dropdown-item" href="/account/tests/<?=$test->id?>">View</a>
  357. <?php
  358. if($test->hasTesterInvoicePDF()) {
  359. ?>
  360. <a class="dropdown-item" href="/account/tests/<?=$test->id?>/invoice">Download Tester Invoice</a>
  361. <?php
  362. }
  363. if($test->hasTravelCostsPhoto()) {
  364. ?>
  365. <a class="dropdown-item" href="/account/tests/<?=$test->id?>/files/travel_costs">View Travel Costs Photo</a>
  366. <?php
  367. }
  368. ?>
  369. </div>
  370. </div>
  371. </td>
  372. </tr>
  373. <?php
  374. }
  375. ?>
  376. </tbody>
  377. </table>
  378. </div>
  379. <div class="row">
  380. <div class="col-md">
  381. </div>
  382. <div class="col-md-auto">
  383. <div class="input-group">
  384. <div class="input-group-prepend">
  385. <label class="input-group-text" for="batch-action">
  386. Batch Action
  387. </label>
  388. </div>
  389. <select class="form-control" name="batch_action" id="batch-action" required>
  390. <option value="">Select Action</option>
  391. <option value="unassign">Unassign</option>
  392. <option value="mark_tester_invoice_paid">Mark Tester Invoice as Paid</option>
  393. <option value="reject_tester_invoice">Reject Tester Invoices</option>
  394. </select>
  395. <div class="input-group-append">
  396. <button type="submit" class="btn btn-primary" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>">
  397. Submit
  398. </button>
  399. </div>
  400. </div>
  401. </div>
  402. </div>
  403. </form>
  404. <div class="mt-3">
  405. <?php
  406. View::include("pagination", compact("pagination_object"));
  407. ?>
  408. </div>
  409. <?php
  410. }
  411. ?>
  412. </div>
  413. </div>