test_list.php 16 KB

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