test_list.php 15 KB

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