test_list.php 16 KB

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