test_list.php 18 KB

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