test_list.php 16 KB

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