test_verify_form.php 17 KB

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