test_verify_form.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. /**
  3. * @controller test.php
  4. *
  5. * @var Test $test
  6. * @var User $tester
  7. * @var Location $location
  8. * @var Project $project
  9. * @var Project[] $future_projects
  10. * @var Customer $customer
  11. * @var Template $template
  12. * @var array $fields
  13. * @var string $tester_message
  14. */
  15. use Carbon\CarbonImmutable;
  16. $values = $test->getValues(true);
  17. $get_test_details = static function(Test $test) use ($project, $location): array {
  18. $test_details = [];
  19. $test_details["Project"] = sprintf('<a href="/account/projects/%d">%s</a>', $test->project_id, $project->getNameHtml());
  20. $test_details["Status"] = "<span class=\"badge badge-lg badge-" . $test->getStatusClass() . "\">" . $test->getStatusText() . "</span>";
  21. if($test->isVoid()) {
  22. $test_details["Result"] = "<span class=\"badge badge-lg badge-secondary\">Void</span>";
  23. }
  24. else {
  25. $test_details["Result"] = "<span class=\"badge badge-lg badge-" . $test->getPassClass() . "\">" . $test->getPassText() . "</span>";
  26. }
  27. $test_details["Location"] = "<a href=\"/account/locations/$location->id\" target=\"_blank\">" . htmlspecialchars($location->name) . "</a>";
  28. $test_details["Address"] = htmlspecialchars($location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]));
  29. if($test->dts_end) {
  30. $test_details = array_merge($test_details, [
  31. "Duration" => $test->getDisplayDuration(),
  32. "Start" => Util::getDisplayDateTime(strtotime($test->dts_start . " UTC")),
  33. "End" => Util::getDisplayDateTime(strtotime($test->dts_end . " UTC")),
  34. ]);
  35. }
  36. if(in_array($test->getStatus(), [Test::STATUS_CANCELLED, Test::STATUS_COMPLETED], true)) {
  37. $test_details["Verified"] = Util::getDisplayDateTime(strtotime($test->dts_verified . " UTC"));
  38. $test_details["Retest"] = $test->retest ? "Yes" : "No";
  39. }
  40. return $test_details;
  41. };
  42. $tester_details = [
  43. "Name" => "Unassigned"
  44. ];
  45. if($tester) {
  46. $tester_details = [
  47. "Name" => "<a href=\"/account/users/$tester->id\" target=\"_blank\">" . $tester->getDisplayName() . "</a>",
  48. "Date of Birth" => $tester->date_of_birth,
  49. "Gender" => $tester->getGenderText(),
  50. "Phone" => $tester->phone,
  51. "Score" => $tester->score,
  52. ];
  53. $tester_invoice_details = [
  54. "Status" => Test::getStatusTesterInvoiceText($test->status_tester_invoice),
  55. "Generated" => $test->dts_tester_invoice_generated ? Util::getDisplayDateTimeFromUTC($test->dts_tester_invoice_generated) : "N/A",
  56. "Paid" => $test->dts_tester_invoice_paid ? Util::getDisplayDateTimeFromUTC($test->dts_tester_invoice_paid) : "N/A",
  57. ];
  58. if($test->test_travel_cost) {
  59. $tester_invoice_details["Travel Costs"] = "£" . number_format($test->test_travel_cost, 2);
  60. }
  61. else {
  62. $tester_invoice_details["Travel Costs"] = "N/A";
  63. }
  64. if($test->test_travel_cost_description) {
  65. $tester_invoice_details["Travel Cost Description"] = htmlspecialchars($test->test_travel_cost_description);
  66. }
  67. else {
  68. $tester_invoice_details["Travel Cost Description"] = "N/A";
  69. }
  70. if($test->hasTesterInvoicePDF()) {
  71. $tester_invoice_details["PDF"] = "<a href=\"/account/tests/{$test->id}/invoice\" target=\"_blank\">Download Invoice</a>";
  72. }
  73. if($test->hasTravelCostsPhoto()) {
  74. $tester_invoice_details["Photo"] = "<a href=\"/account/tests/{$test->id}/files/travel_costs\" target=\"_blank\">View Photo</a>";
  75. }
  76. }
  77. function render_card_list_group($details) {
  78. ?>
  79. <div class="list-group list-group-flush">
  80. <?php
  81. foreach($details as $title => $html) {
  82. ?>
  83. <div class="list-group-item">
  84. <div class="row" style="overflow: hidden; text-overflow: ellipsis;">
  85. <div class="col-md-auto">
  86. <?=htmlspecialchars($title)?>
  87. </div>
  88. <div class="col-md text-right" style="width: auto; overflow: hidden; text-overflow: ellipsis;">
  89. <?=$html?>
  90. </div>
  91. </div>
  92. </div>
  93. <?php
  94. }
  95. ?>
  96. </div>
  97. <?php
  98. }
  99. ?>
  100. <div class="container mt-3 py-4">
  101. <div class="row">
  102. <div class="col">
  103. <h2>Edit/Verify Test</h2>
  104. </div>
  105. <div class="col-auto justify-self-center">
  106. <div class="dropdown">
  107. <button class="btn btn-secondary dropdown-toggle" type="button" id="actions-button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  108. Actions
  109. </button>
  110. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="actions-button">
  111. <a class="dropdown-item" href="/account/projects/<?=$test->project_id?>">View Project</a>
  112. <div class="dropdown-divider"></div>
  113. <a class="dropdown-item" href="/account/tests/<?=$test->id?>/pdf" target="_blank">Generate New PDF</a>
  114. <?php
  115. if($test->hasPDF()) {
  116. $pdf_url = $test->getPDFUrl();
  117. ?>
  118. <a class="dropdown-item" href="<?=$pdf_url?>" target="_blank">View Sent PDF</a>
  119. <?php
  120. }
  121. if($test->hasTesterInvoicePDF()) {
  122. ?>
  123. <a class="dropdown-item" href="/account/tests/<?=$test->id?>/invoice" target="_blank">Download Tester Invoice</a>
  124. <?php
  125. }
  126. if($test->hasTravelCostsPhoto()) {
  127. ?>
  128. <a class="dropdown-item" href="/account/tests/<?=$test->id?>/files/travel_costs" target="_blank">View Travel Costs Photo</a>
  129. <?php
  130. }
  131. ?>
  132. </div>
  133. </div>
  134. </div>
  135. </div>
  136. <form method="post">
  137. <input type="hidden" name="submit" value="<?=$_SESSION["csrf_token"]?>" />
  138. <div class="row">
  139. <div class="col-xl-6">
  140. <div class="card mb-3">
  141. <div class="card-header">
  142. Submitted Data
  143. </div>
  144. <div class="card-body">
  145. <?php
  146. $header_count = 0;
  147. foreach($fields as $field) {
  148. $field = $template->applyOverridesToField($field);
  149. if($field->type === "file") {
  150. $path = $test->getDirectory() . "/" . $field->name . ".jpg";
  151. ?>
  152. <div class="row mb-1">
  153. <label class="col-sm-8 col-form-label"><?=htmlspecialchars($field->label)?></label>
  154. <div class="col-sm-4">
  155. <a href="/account/tests/<?=$test->id?>/files/<?=$field->name?>" target="_blank">
  156. <img class="img-fluid rounded" src="/account/tests/<?=$test->id?>/files/<?=$field->name?>" alt="<?=htmlspecialchars($field->label)?>" />
  157. </a>
  158. </div>
  159. </div>
  160. <?php
  161. continue;
  162. }
  163. if(!empty($field->name)) {
  164. $name = $field->name;
  165. if(isset($test->$name)) $field->value = $test->$name;
  166. else if(isset($values[$name])) $field->value = $values[$name];
  167. }
  168. $field->template = $template;
  169. Form::renderField($field);
  170. if($field->type === "header") {
  171. $header_count++;
  172. }
  173. }
  174. Form::renderField((object) [
  175. "type" => "checkbox",
  176. "name" => "void",
  177. "value" => $test->void,
  178. "label" => __("Void"),
  179. ]);
  180. Form::renderField((object) [
  181. "type" => "textarea",
  182. "name" => "void_notes",
  183. "label" => __("Void Notes"),
  184. "value" => $test->void_notes,
  185. "maxLength" => 65535,
  186. "helpText" => __("You must fill in this field if Void is checked."),
  187. ]);
  188. ?>
  189. </div>
  190. </div>
  191. </div>
  192. <div class="col-xl-6">
  193. <div class="row">
  194. <div class="col-md col-xl-12">
  195. <div class="card mb-3">
  196. <div class="card-header">
  197. Info
  198. </div>
  199. <div class="card-body p-0">
  200. <div id="map" data-maps data-lat="<?=$location->latitude?>" data-lng="<?=$location->longitude?>" data-zoom="17" data-marker="true" style="height: 320px;">
  201. </div>
  202. </div>
  203. <?php
  204. render_card_list_group($get_test_details($test));
  205. ?>
  206. </div>
  207. </div>
  208. <div class="col-md col-xl-12">
  209. <div class="card mb-3">
  210. <div class="card-header">
  211. Tester
  212. </div>
  213. <?php
  214. render_card_list_group($tester_details);
  215. ?>
  216. </div>
  217. <?php
  218. if(isset($tester_invoice_details)) {
  219. ?>
  220. <div class="card mb-3">
  221. <div class="card-header">
  222. Tester Invoice
  223. </div>
  224. <?php
  225. render_card_list_group($tester_invoice_details);
  226. if($test->getTesterInvoiceStatus() === Test::STATUS_TESTER_INVOICE_PENDING) {
  227. ?>
  228. <div class="card-body text-center">
  229. <button class="btn btn-success" type="submit" name="accept_tester_invoice" value="1">
  230. Paid Invoice
  231. </button>
  232. <button class="btn btn-danger" type="submit" name="reject_tester_invoice" value="1">
  233. Reject Invoice
  234. </button>
  235. </div>
  236. <?php
  237. }
  238. ?>
  239. </div>
  240. <?php
  241. }
  242. ?>
  243. </div>
  244. </div>
  245. <?php
  246. if($test->verifier_id && $test->dts_verified) {
  247. $verifier = $test->getVerifier();
  248. $time_verified = CarbonImmutable::parse($test->dts_verified, "UTC")->getTimestamp();
  249. ?>
  250. <div class="card mb-3">
  251. <div class="card-header">
  252. <?=htmlspecialchars(__("Verification Info"))?>
  253. </div>
  254. <div class="list-group list-group-flush">
  255. <div class="list-group-item d-flex justify-content-between">
  256. <div>
  257. <?=htmlspecialchars(__("Verifier"))?>
  258. </div>
  259. <div>
  260. <?=htmlspecialchars($verifier->getDisplayName())?>
  261. </div>
  262. </div>
  263. <div class="list-group-item d-flex justify-content-between">
  264. <div>
  265. <?=htmlspecialchars(__("Verified Date/Time"))?>
  266. </div>
  267. <div>
  268. <?=htmlspecialchars(Util::getDisplayDateTime($time_verified))?>
  269. </div>
  270. </div>
  271. <div class="list-group-item d-flex justify-content-between">
  272. <div>
  273. <?=htmlspecialchars(__("Verifier Notes"))?>
  274. </div>
  275. <div>
  276. <?=$test->getVerifierNotesHtml()?>
  277. </div>
  278. </div>
  279. </div>
  280. </div>
  281. <?php
  282. }
  283. ?>
  284. <div class="card mb-3">
  285. <div class="card-header">
  286. Verification
  287. </div>
  288. <div class="card-body">
  289. <div class="row mb-1 align-items-center">
  290. <label class="col-sm-4 col-form-label">Verifier</label>
  291. <div class="col-sm">
  292. <?=htmlspecialchars(Core::$user->getDisplayName())?>
  293. </div>
  294. </div>
  295. <hr />
  296. <?php
  297. if($template->hasPassFail()) {
  298. ?>
  299. <div class="row mb-1">
  300. <label class="col-sm-4 col-form-label" for="pass-override">Pass Override</label>
  301. <div class="col-sm">
  302. <select class="form-control" name="pass_override" id="pass-override">
  303. <option value="">None</option>
  304. <option value="1">Pass</option>
  305. <option value="0">Fail</option>
  306. </select>
  307. </div>
  308. </div>
  309. <?php
  310. }
  311. ?>
  312. <div class="row mb-1">
  313. <label class="col-sm-4 col-form-label" for="start-override">Start Override</label>
  314. <div class="col-sm">
  315. <input class="form-control" type="datetime-local" name="start_override" id="start-override" />
  316. </div>
  317. </div>
  318. <div class="row mb-1">
  319. <label class="col-sm-4 col-form-label" for="end-override">End Override</label>
  320. <div class="col-sm">
  321. <input class="form-control" type="datetime-local" name="end_override" id="end-override" />
  322. </div>
  323. </div>
  324. <div class="row mb-1">
  325. <label class="col-sm-4 col-form-label" for="customer-fee">Customer Fee Override</label>
  326. <div class="col-sm">
  327. <div class="input-group">
  328. <div class="input-group-prepend">
  329. <span class="input-group-text">£</span>
  330. </div>
  331. <input class="form-control" type="number" step="0.01" min="0" name="customer_fee" id="customer-fee" placeholder="Enter customer fee override" value="<?=htmlspecialchars($test->customer_fee)?>" />
  332. </div>
  333. </div>
  334. </div>
  335. <div class="row mb-1">
  336. <label class="col-sm-4 col-form-label" for="tester-fee">Tester Fee Override</label>
  337. <div class="col-sm">
  338. <div class="input-group">
  339. <div class="input-group-prepend">
  340. <span class="input-group-text">£</span>
  341. </div>
  342. <input class="form-control" type="number" step="0.01" min="0" name="tester_fee" id="tester-fee" placeholder="Enter tester fee override" value="<?=htmlspecialchars($test->test_fee)?>" />
  343. </div>
  344. </div>
  345. </div>
  346. <row class="row mb-1">
  347. <label class="col-sm-4 col-form-label" for="travel-cost">Travel Costs</label>
  348. <div class="col-sm">
  349. <div class="input-group">
  350. <div class="input-group-prepend">
  351. <span class="input-group-text">£</span>
  352. </div>
  353. <input class="form-control" type="number" step="0.01" min="0" max="999.99" name="travel_cost" id="travel-cost" placeholder="Enter travel costs" value="<?=htmlspecialchars($test->test_travel_cost)?>" />
  354. </div>
  355. </div>
  356. </row>
  357. <div class="row mb-1">
  358. <label class="col-sm-4 col-form-label" for="verifier-notes">Verifier Notes</label>
  359. <div class="col-sm">
  360. <textarea class="form-control" name="verifier_notes" id="verifier-notes" placeholder="Enter verifier notes" rows="4"><?=htmlspecialchars($test->verifier_notes)?></textarea>
  361. </div>
  362. </div>
  363. <div class="row mb-1 align-items-center">
  364. <label class="col-sm-4 col-form-label" for="retest">Set As Retest</label>
  365. <div class="col-sm">
  366. <div class="custom-control custom-checkbox">
  367. <input class="custom-control-input" type="checkbox" name="retest" id="retest" value="1" <?=Form::checked($test->retest)?> />
  368. <label class="custom-control-label" for="retest">This test was a retest</label>
  369. </div>
  370. </div>
  371. </div>
  372. <div class="row mb-1">
  373. <label class="col-sm-4 col-form-label" for="new-test-project-id">Create New Test</label>
  374. <div class="col-sm">
  375. <div class="input-group">
  376. <select class="form-control" name="new_test_project_id" id="new-test-project-id">
  377. <option value="0">Do not create</option>
  378. <?php
  379. foreach($future_projects as $future_project) {
  380. ?>
  381. <option value="<?=$future_project->id?>"><?=htmlspecialchars($future_project->name)?></option>
  382. <?php
  383. }
  384. ?>
  385. </select>
  386. <div class="input-group-append">
  387. <div class="input-group-text">
  388. <div class="custom-control custom-checkbox">
  389. <input class="custom-control-input" type="checkbox" name="new_test_is_retest" id="new-test-is-retest" value="1" />
  390. <label class="custom-control-label" for="new-test-is-retest"><?=htmlspecialchars(__("Retest"))?></label>
  391. </div>
  392. </div>
  393. </div>
  394. </div>
  395. </div>
  396. </div>
  397. <?php
  398. if($test->getStatus() === Test::STATUS_PENDING_VERIFICATION) {
  399. ?>
  400. <?php
  401. if($customer->email) {
  402. ?>
  403. <div class="row mb-1">
  404. <div class="col-sm-4">
  405. <label class="form-check-label" for="email-customer">Email Headquarters</label>
  406. </div>
  407. <div class="col-sm">
  408. <div class="custom-control custom-checkbox">
  409. <input class="custom-control-input" type="checkbox" name="email_customer" id="email-customer" value="1" <?=Form::checked($customer->email_after_test)?> />
  410. <label class="custom-control-label" for="email-customer"><?=htmlspecialchars($customer->email)?></label>
  411. </div>
  412. </div>
  413. </div>
  414. <?php
  415. }
  416. if($location->email) {
  417. ?>
  418. <div class="row mb-1">
  419. <div class="col-sm-4">
  420. <label class="form-check-label" for="email-location">Email Venue</label>
  421. </div>
  422. <div class="col-sm">
  423. <div class="custom-control custom-checkbox">
  424. <input class="custom-control-input" type="checkbox" name="email_location" id="email-location" value="1" <?=Form::checked($customer->email_locations_after_test)?> />
  425. <label class="custom-control-label" for="email-location"><?=htmlspecialchars($location->email)?></label>
  426. </div>
  427. </div>
  428. </div>
  429. <?php
  430. }
  431. if($location->area_manager_email) {
  432. ?>
  433. <div class="row mb-1">
  434. <div class="col-sm-4">
  435. <label class="form-check-label" for="email-location-area-manager">Email Area Manager</label>
  436. </div>
  437. <div class="col-sm">
  438. <div class="custom-control custom-checkbox">
  439. <input class="custom-control-input" type="checkbox" name="email_location_area_manager" id="email-location-area-manager" value="1" <?=Form::checked($customer->email_locations_after_test)?> />
  440. <label class="custom-control-label" for="email-location-area-manager"><?=htmlspecialchars($location->area_manager_email)?></label>
  441. </div>
  442. </div>
  443. </div>
  444. <?php
  445. }
  446. ?>
  447. <div class="row mb-1">
  448. <div class="col-sm-4">
  449. <label class="form-check-label" for="include-previous-test"><?=htmlspecialchars(__("Previous Test"))?></label>
  450. </div>
  451. <div class="col-sm">
  452. <div class="custom-control custom-checkbox">
  453. <input class="custom-control-input" type="checkbox" name="include_previous_test" id="include-previous-test" value="1" checked />
  454. <label class="custom-control-label" for="include-previous-test">
  455. <?=htmlspecialchars(__("Attach PDF"))?>
  456. </label>
  457. </div>
  458. </div>
  459. </div>
  460. <div class="row mb-1">
  461. <label class="col-sm-4 col-form-label" for="tester-message">Message to Tester (if rejecting)</label>
  462. <div class="col-sm">
  463. <textarea class="form-control" name="tester_message" id="tester-message" placeholder="Enter message to tester" rows="4"><?=htmlspecialchars($tester_message)?></textarea>
  464. </div>
  465. </div>
  466. <div class="row mb-1">
  467. <div class="col-sm offset-sm-4">
  468. <button class="btn btn-success" type="submit" name="accept" value="1">Accept</button>
  469. <button class="btn btn-danger" type="submit" name="reject" value="1">Reject</button>
  470. </div>
  471. </div>
  472. <?php
  473. }
  474. else {
  475. ?>
  476. <div class="row mb-1">
  477. <div class="col-sm offset-sm-4">
  478. <button class="btn btn-primary" type="submit">Submit</button>
  479. </div>
  480. </div>
  481. <?php
  482. }
  483. ?>
  484. </div>
  485. </div>
  486. <?php
  487. $previous_test = $test->getPreviousTest();
  488. if($previous_test) {
  489. $dt = $previous_test->getDateTimeStart();
  490. $previous_test_details = $get_test_details($previous_test);
  491. $previous_test_details_subset = [
  492. "Date/Time" => $previous_test_details["Start"],
  493. "Result" => $previous_test_details["Result"],
  494. ];
  495. ?>
  496. <div class="card mb-3">
  497. <div class="card-header">
  498. <?=htmlspecialchars(__("Previous Test"))?>
  499. </div>
  500. <?php
  501. render_card_list_group($previous_test_details_subset);
  502. ?>
  503. </div>
  504. <?php
  505. }
  506. ?>
  507. </div>
  508. </div>
  509. </form>
  510. </div>