test_list.php 15 KB

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