test_list.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  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. <?php
  352. if($is_staff) {
  353. ?>
  354. <th>Actions</th>
  355. <?php
  356. }
  357. ?>
  358. </tr>
  359. </thead>
  360. <tbody>
  361. <?php
  362. foreach($tests as $test) {
  363. $location = $test->getLocation();
  364. $project = $test->getProject();
  365. $tester = $test->getTester();
  366. $dt_due = $test->getDateTimeDue();
  367. $is_overdue = $test->isOverdue();
  368. $due_class = $is_overdue ? "text-danger" : "";
  369. $dt_end = $test->getDateTimeEnd();
  370. ?>
  371. <tr>
  372. <?php
  373. if($is_staff) {
  374. ?>
  375. <td>
  376. <label for="test-checkbox-<?=$test->id?>" class="sr-only">
  377. <?=htmlspecialchars(__("Select Test ID %d", $test->id))?>
  378. </label>
  379. <input type="checkbox" name="test_ids[]" id="test-checkbox-<?=$test->id?>" value="<?=$test->id?>" />
  380. </td>
  381. <?php
  382. }
  383. ?>
  384. <td>
  385. <?=$test->id?>
  386. </td>
  387. <td class="align-middle">
  388. <a href="/account/locations/<?=$location->id?>">
  389. <?=htmlspecialchars($location->name)?>
  390. </a>
  391. <?php
  392. if($location->internal_id) {
  393. ?>
  394. <small class="text-muted">Internal ID: <?=htmlspecialchars($location->internal_id)?></small>
  395. <?php
  396. }
  397. ?>
  398. <br />
  399. <?=htmlspecialchars($location->getDisplayAddress(["address_1", "address_2", "city"]))?>
  400. </td>
  401. <td class="align-middle">
  402. <a href="/account/projects/<?=$project->id?>?location_id=<?=$test->location_id?>">
  403. <?=htmlspecialchars($project->name)?>
  404. </a>
  405. <?php
  406. if($is_staff) {
  407. ?>
  408. <br />
  409. <strong>Deadline:</strong> <?=date("d/m/Y", strtotime($project->dts_deadline . " UTC"))?>
  410. <?php
  411. }
  412. ?>
  413. </td>
  414. <?php
  415. if($is_staff) {
  416. ?>
  417. <td class="align-middle">
  418. <?php
  419. if($tester) {
  420. ?>
  421. <a href="/account/users/<?=$tester->id?>"><?=htmlspecialchars($tester->getDisplayName())?></a>
  422. <?php
  423. if($test->status_tester_invoice > 0) {
  424. $time = Util::getUnixTimeFromUTC($test->dts_tester_invoice_generated);
  425. $dts = Util::getDisplayDateTime($time);
  426. ?>
  427. <br />
  428. <span class="badge badge-<?=Test::getStatusTesterInvoiceClass($test->status_tester_invoice)?>" title="Generated on <?=$dts?>"><?=Test::getStatusTesterInvoiceText($test->status_tester_invoice)?></span>
  429. <?php
  430. }
  431. }
  432. else {
  433. ?>
  434. <small class="text-muted">N/A</small>
  435. <?php
  436. }
  437. ?>
  438. </td>
  439. <td class="align-middle <?=$due_class?>">
  440. <?php
  441. if($dt_due) {
  442. $days_overdue = $dt_due->diffInDays();
  443. ?>
  444. <strong><?=$dt_due->format("d/m/Y")?></strong>
  445. <?php
  446. if($is_overdue && !$test->isDone()) {
  447. ?><br />
  448. <small>
  449. <?=htmlspecialchars(n__("%d day overdue", "%d days overdue", $days_overdue, $days_overdue))?>
  450. </small>
  451. <?php
  452. }
  453. }
  454. else {
  455. ?>
  456. <small class="text-muted">N/A</small>
  457. <?php
  458. }
  459. ?>
  460. </td>
  461. <?php
  462. }
  463. ?>
  464. <td>
  465. <?php
  466. if($dt_end) {
  467. $dt_end = $dt_end->setTimezone(TIMEZONE);
  468. ?>
  469. <strong>
  470. <?=$dt_end->format("d/m/Y")?>
  471. </strong>
  472. <?php
  473. }
  474. ?>
  475. </td>
  476. <?php
  477. if($is_staff) {
  478. ?>
  479. <td class="text-right align-middle">
  480. <?php
  481. if($test->test_travel_cost > 0) {
  482. ?>
  483. £<?=number_format($test->test_travel_cost, 2)?>
  484. <?php
  485. }
  486. ?>
  487. </td>
  488. <td class="text-right align-middle">
  489. <?php
  490. $tester_invoice_costs = $test->getTesterInvoiceCosts();
  491. if($tester_invoice_costs > 0) {
  492. ?>
  493. £<?=number_format($tester_invoice_costs, 2)?>
  494. <?php
  495. }
  496. ?>
  497. </td>
  498. <td class="text-center align-middle">
  499. <span class="badge badge-<?=$test->getStatusClass()?>"><?=$test->getStatusText()?></span>
  500. </td>
  501. <?php
  502. }
  503. ?>
  504. <td class="text-center align-middle text-<?=$test->getPassClass()?>">
  505. <div title="<?=$test->getPassText()?>">
  506. <i class="fas fa-2x fa-fw fa-<?=$test->getPassIcon()?>"></i>
  507. </div>
  508. </td>
  509. <td class="text-center align-middle">
  510. <?php
  511. if($test->retest) {
  512. ?>
  513. <i class="fa fa-fw fa-check fa-2x text-success"></i>
  514. <?php
  515. }
  516. ?>
  517. </td>
  518. <?php
  519. if($is_staff) {
  520. ?>
  521. <td class="text-right align-middle">
  522. <div class="dropdown">
  523. <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">
  524. Actions
  525. </button>
  526. <div class="dropdown-menu" aria-labelledby="test-dropdown-<?=$test->id?>">
  527. <a class="dropdown-item" href="/account/tests/<?=$test->id?>">View</a>
  528. <?php
  529. if($test->hasTesterInvoicePDF()) {
  530. ?>
  531. <a class="dropdown-item" href="/account/tests/<?=$test->id?>/invoice">Download Tester Invoice</a>
  532. <?php
  533. }
  534. if($test->hasTravelCostsPhoto()) {
  535. ?>
  536. <a class="dropdown-item" href="/account/tests/<?=$test->id?>/files/travel_costs">View Travel Costs Photo</a>
  537. <?php
  538. }
  539. ?>
  540. </div>
  541. </div>
  542. </td>
  543. <?php
  544. }
  545. ?>
  546. </tr>
  547. <?php
  548. }
  549. ?>
  550. </tbody>
  551. </table>
  552. </div>
  553. <?php
  554. if($is_staff) {
  555. ?>
  556. <div class="row">
  557. <div class="col-md">
  558. </div>
  559. <div class="col-md-auto">
  560. <div class="input-group">
  561. <div class="input-group-prepend">
  562. <label class="input-group-text" for="batch-action">
  563. Batch Action
  564. </label>
  565. </div>
  566. <select class="form-control" name="batch_action" id="batch-action" required>
  567. <option value="">Select Action</option>
  568. <option value="unassign">Unassign</option>
  569. <option value="mark_tester_invoice_paid">Mark Tester Invoice as Paid</option>
  570. <option value="reject_tester_invoice">Reject Tester Invoices</option>
  571. <option value="send_test_assigned_email">Send Test Assigned Email</option>
  572. </select>
  573. <div class="input-group-append">
  574. <button type="submit" class="btn btn-primary" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>">
  575. Submit
  576. </button>
  577. </div>
  578. </div>
  579. </div>
  580. </div>
  581. <?php
  582. }
  583. ?>
  584. </form>
  585. <div class="mt-3">
  586. <?php
  587. View::include("pagination", compact("pagination_object"));
  588. ?>
  589. </div>
  590. <?php
  591. }
  592. ?>
  593. </div>
  594. </div>