test_verify_form.php 18 KB

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