test_list.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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?>"><?=htmlspecialchars($project->name)?></a><br />
  309. <strong>Deadline:</strong> <?=date("d/m/Y", strtotime($project->dts_deadline . " UTC"))?>
  310. </td>
  311. <td class="align-middle">
  312. <?php
  313. if($tester) {
  314. ?>
  315. <a href="/account/users/<?=$tester->id?>"><?=htmlspecialchars($tester->getDisplayName())?></a>
  316. <?php
  317. if($test->status_tester_invoice > 0) {
  318. $time = Util::getUnixTimeFromUTC($test->dts_tester_invoice_generated);
  319. $dts = Util::getDisplayDateTime($time);
  320. ?>
  321. <br />
  322. <span class="badge badge-<?=Test::getStatusTesterInvoiceClass($test->status_tester_invoice)?>" title="Generated on <?=$dts?>"><?=Test::getStatusTesterInvoiceText($test->status_tester_invoice)?></span>
  323. <?php
  324. }
  325. }
  326. else {
  327. ?>
  328. <small class="text-muted">N/A</small>
  329. <?php
  330. }
  331. ?>
  332. </td>
  333. <td class="align-middle <?=$due_class?>">
  334. <?php
  335. if($dt_due) {
  336. $days_overdue = $dt_due->diffInDays();
  337. ?>
  338. <strong><?=$dt_due->format("d/m/Y")?></strong>
  339. <?php
  340. if($is_overdue) {
  341. ?><br />
  342. <small>
  343. <?=htmlspecialchars(n__("%d day overdue", "%d days overdue", $days_overdue, $days_overdue))?>
  344. </small>
  345. <?php
  346. }
  347. }
  348. else {
  349. ?>
  350. <small class="text-muted">N/A</small>
  351. <?php
  352. }
  353. ?>
  354. </td>
  355. <td>
  356. <?php
  357. if($dt_end) {
  358. $dt_end = $dt_end->setTimezone(TIMEZONE);
  359. ?>
  360. <strong>
  361. <?=$dt_end->format("d/m/Y")?>
  362. </strong>
  363. <?php
  364. }
  365. ?>
  366. </td>
  367. <td class="text-right align-middle">
  368. <?php
  369. if($test->test_travel_cost > 0) {
  370. ?>
  371. £<?=number_format($test->test_travel_cost, 2)?>
  372. <?php
  373. }
  374. ?>
  375. </td>
  376. <td class="text-right align-middle">
  377. <?php
  378. $tester_invoice_costs = $test->getTesterInvoiceCosts();
  379. if($tester_invoice_costs > 0) {
  380. ?>
  381. £<?=number_format($tester_invoice_costs, 2)?>
  382. <?php
  383. }
  384. ?>
  385. </td>
  386. <td class="text-center align-middle">
  387. <span class="badge badge-<?=$test->getStatusClass()?>"><?=$test->getStatusText()?></span>
  388. </td>
  389. <td class="text-center align-middle text-<?=$test->getPassClass()?>">
  390. <div title="<?=$test->getPassText()?>">
  391. <i class="fas fa-2x fa-fw fa-<?=$test->getPassIcon()?>"></i>
  392. </div>
  393. </td>
  394. <td class="text-right align-middle">
  395. <div class="dropdown">
  396. <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">
  397. Actions
  398. </button>
  399. <div class="dropdown-menu" aria-labelledby="test-dropdown-<?=$test->id?>">
  400. <a class="dropdown-item" href="/account/tests/<?=$test->id?>">View</a>
  401. <?php
  402. if($test->hasTesterInvoicePDF()) {
  403. ?>
  404. <a class="dropdown-item" href="/account/tests/<?=$test->id?>/invoice">Download Tester Invoice</a>
  405. <?php
  406. }
  407. if($test->hasTravelCostsPhoto()) {
  408. ?>
  409. <a class="dropdown-item" href="/account/tests/<?=$test->id?>/files/travel_costs">View Travel Costs Photo</a>
  410. <?php
  411. }
  412. ?>
  413. </div>
  414. </div>
  415. </td>
  416. </tr>
  417. <?php
  418. }
  419. ?>
  420. </tbody>
  421. </table>
  422. </div>
  423. <div class="row">
  424. <div class="col-md">
  425. </div>
  426. <div class="col-md-auto">
  427. <div class="input-group">
  428. <div class="input-group-prepend">
  429. <label class="input-group-text" for="batch-action">
  430. Batch Action
  431. </label>
  432. </div>
  433. <select class="form-control" name="batch_action" id="batch-action" required>
  434. <option value="">Select Action</option>
  435. <option value="unassign">Unassign</option>
  436. <option value="mark_tester_invoice_paid">Mark Tester Invoice as Paid</option>
  437. <option value="reject_tester_invoice">Reject Tester Invoices</option>
  438. <option value="send_test_assigned_email">Send Test Assigned Email</option>
  439. </select>
  440. <div class="input-group-append">
  441. <button type="submit" class="btn btn-primary" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>">
  442. Submit
  443. </button>
  444. </div>
  445. </div>
  446. </div>
  447. </div>
  448. </form>
  449. <div class="mt-3">
  450. <?php
  451. View::include("pagination", compact("pagination_object"));
  452. ?>
  453. </div>
  454. <?php
  455. }
  456. ?>
  457. </div>
  458. </div>