test_list.php 17 KB

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