test_list.php 15 KB

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