1
0

test_pdf.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <?php
  2. // Controller may be included directly and $pdf can be accessed.
  3. $test = Test::get($id);
  4. if(!$test) throw new Exception("Test not found.");
  5. if(!isset($output)) $output = true;
  6. $location = $test->getLocation();
  7. $tester = $test->getTester();
  8. $test_values = $test->getValues();
  9. $keys = array_column($test_values, "name");
  10. $values = array_column($test_values, "value");
  11. $values = array_combine($keys, $values);
  12. $values = array_filter($values, function($value) {
  13. return strlen($value) !== 0;
  14. });
  15. $tiny_font_size = 8;
  16. $small_font_size = 10;
  17. $normal_font_size = 10;
  18. $header_font_size = 14;
  19. $cell_height = 5;
  20. $cell_margin = 2;
  21. list($date_start, $time_start) = explode(" ", $test->dts_start);
  22. list($date_end, $time_end) = explode(" ", $test->dts_end);
  23. $dt_start = new DateTime($test->dts_start . " UTC");
  24. $dt_start->setTimezone(new DateTimeZone(TIMEZONE));
  25. $dt_end = new DateTime($test->dts_end . " UTC");
  26. $dt_end->setTimezone(new DateTimeZone(TIMEZONE));
  27. $time_start = $dt_start->format("H:i:s");
  28. $time_end = $dt_end->format("H:i:s");
  29. $diff = $dt_start->diff($dt_end, true);
  30. $date_start = date("d/m/Y", strtotime($test->dts_start . " UTC"));
  31. // A4 size: 210x297mm
  32. $pdf = new TestPDF("P", "mm", "A4");
  33. $pdf->SetSubject("Test Result");
  34. $pdf->SetCreator(APP_NAME);
  35. $pdf->SetAuthor(APP_NAME);
  36. $pdf->SetTitle($location->name . " Test Result @ $date_start");
  37. $pdf->AddPage();
  38. $pdf->SetFont("Arial");
  39. $pdf->SetDrawColor(240, 240, 240);
  40. $pdf->SetFillColor(226, 240, 217);
  41. $pdf->SetAutoPageBreak(false);
  42. // Logo
  43. $pdf->Image("public/img/logo.png", 11, 10, 60);
  44. // Right contact info
  45. $y = 10;
  46. $pdf->SetFont("Arial", "B", $tiny_font_size);
  47. $pdf->SetTextColor(255, 0, 0);
  48. $pdf->SetLeftMargin(120);
  49. $pdf->SetY(10);
  50. $pdf->Cell(80, 4, "Test / Location ID: $test->id / $location->id", 0, 1, "R");
  51. $pdf->SetFont("Arial", "");
  52. $pdf->SetTextColor(0, 0, 0);
  53. $pdf->Cell(80, 4, "Tel: 01579 342 104", 0, 1, "R", false, "tel:01579+342+104");
  54. $pdf->SetFont("Arial", "U");
  55. $pdf->SetTextColor(0, 128, 255);
  56. $pdf->Cell(80, 4, "check-policy.com", 0, 1, "R", false, "https://check-policy.com");
  57. $pdf->Cell(80, 4, "info@check-policy.com", 0, 1, "R");
  58. $pdf->SetLeftMargin(10);
  59. $pdf->SetXY(10, $pdf->GetY() + $cell_margin);
  60. // Header
  61. $pdf->SetTextColor(56, 87, 35);
  62. $pdf->SetFont("Arial", "B", $header_font_size);
  63. $pdf->Cell(190, 10, " Test Result", 0, 1, "L", true);
  64. // Pass/Fail
  65. $image_width = 130;
  66. if($test->pass) {
  67. $pdf->Image("public/img/pass.png", (210 - $image_width) / 2, $pdf->GetY() + 2, $image_width);
  68. }
  69. else {
  70. $pdf->Image("public/img/fail.png", (210 - $image_width) / 2, $pdf->GetY() + 2, $image_width);
  71. }
  72. $pdf->SetY($pdf->GetY() + 30);
  73. $pdf->SetTextColor(56, 87, 35);
  74. // Location / Tester Headers
  75. $pdf->SetFont("Arial", "B", $header_font_size);
  76. $tester_x = 150;
  77. $tester_y = $pdf->GetY();
  78. $header = " $location->name";
  79. if($location->internal_id) {
  80. $header .= " (ID: $location->internal_id)";
  81. }
  82. $pdf->Cell(135, 10, $header, 0, 1, "L", true);
  83. $pdf->SetY($pdf->GetY() + 2);
  84. $pdf->SetFont("Arial", "", $normal_font_size);
  85. $pdf->SetTextColor(0, 0, 0);
  86. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
  87. $pdf->Cell(30, $cell_height, "Region / Manager:", 0, 0);
  88. $pdf->SetX($pdf->GetX() + 5);
  89. $pdf->Write($cell_height, $location->region);
  90. $pdf->Write($cell_height, "/ ");
  91. $pdf->Write($cell_height, $location->area_manager);
  92. $pdf->SetY($pdf->GetY() + $cell_height);
  93. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
  94. $pdf->Cell(30, $cell_height, "Address:", 0, 0);
  95. $pdf->SetX($pdf->GetX() + 5);
  96. $pdf->MultiCell(100, $cell_height, $location->getDisplayAddress(["address_1", "address_2", "city"], "\n"), 0, 1);
  97. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
  98. $pdf->Cell(30, $cell_height, "Postcode:", 0, 0);
  99. $pdf->SetX($pdf->GetX() + 5);
  100. $pdf->Cell(100, $cell_height, $location->postal_code, 0, 1);
  101. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
  102. $pdf->Cell(30, $cell_height, "Shop Name - Left:", 0, 0);
  103. $pdf->SetX($pdf->GetX() + 5);
  104. $pdf->Cell(100, $cell_height, $test->shop_left, 0, 1);
  105. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
  106. $pdf->Cell(30, $cell_height, "Shop Name - Right:", 0, 0);
  107. $pdf->SetX($pdf->GetX() + 5);
  108. $pdf->Cell(100, $cell_height, $test->shop_right, 0, 1);
  109. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
  110. $test_details_y = $pdf->GetY();
  111. // Tester Info
  112. $pdf->SetXY($tester_x, $tester_y);
  113. $pdf->SetLeftMargin(150);
  114. $pdf->SetTextColor(56, 87, 35);
  115. $pdf->SetFont("Arial", "B", $header_font_size);
  116. $pdf->Cell(50, 10, " Tester", 0, 1, "L", true);
  117. $pdf->SetY($pdf->GetY() + 2);
  118. $pdf->SetFont("Arial", "", $normal_font_size);
  119. $pdf->SetTextColor(0, 0, 0);
  120. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 50, $pdf->GetY());
  121. $pdf->Cell(20, $cell_height, "Gender:", 0, 0);
  122. $pdf->SetX($pdf->GetX() + 5);
  123. $pdf->Cell(20, $cell_height, $tester->getGenderText(), 0, 1);
  124. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 50, $pdf->GetY());
  125. $pdf->Cell(20, $cell_height, "Attire:", 0, 1);
  126. $pdf->SetX(150);
  127. $pdf->SetFont("Arial", "", $small_font_size);
  128. $pdf->MultiCell(50, 4, $test->attire, 0, 1);
  129. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 50, $pdf->GetY());
  130. // Test Details
  131. $pdf->SetLeftMargin(10);
  132. $pdf->setXY(10, $test_details_y + 5 + 2);
  133. $pdf->SetTextColor(56, 87, 35);
  134. $pdf->SetFont("Arial", "B", $header_font_size);
  135. $pdf->Cell(190, 10, " Test Details", 0, 1, "L", true);
  136. $pdf->SetY($pdf->GetY() + 2);
  137. // Date / Time
  138. $id_requests_y = $pdf->GetY();
  139. $pdf->SetFont("Arial", "B", $normal_font_size);
  140. $pdf->SetTextColor(0, 0, 0);
  141. $pdf->Cell(95, $cell_height, "Date & Time", 0, 1);
  142. $pdf->SetY($pdf->GetY() + 2);
  143. $pdf->SetFont("Arial");
  144. $pdf->Cell(23, $cell_height, "Date");
  145. $pdf->Cell(23, $cell_height, "Entry");
  146. $pdf->Cell(23, $cell_height, "Exit");
  147. $pdf->Cell(23, $cell_height, "Duration", 0, 1);
  148. $pdf->SetFont("Arial", "", $small_font_size);
  149. $pdf->Cell(23, $cell_height, $date_start);
  150. $pdf->Cell(23, $cell_height, $time_start);
  151. $pdf->Cell(23, $cell_height, $time_end);
  152. $pdf->Cell(23, $cell_height, str_pad($diff->h, 2, "0", STR_PAD_LEFT) . ":" . str_pad($diff->i, 2, "0", STR_PAD_LEFT) . ":" . str_pad($diff->s, 2, "0", STR_PAD_LEFT), 0, 1);
  153. $pdf->SetY($pdf->GetY() + 2);
  154. // Staff
  155. $pdf->SetFont("Arial", "B", $normal_font_size);
  156. $pdf->Cell(95, $cell_height, "Staff", 0, 1);
  157. $pdf->SetY($pdf->GetY() + 2);
  158. $pdf->SetFont("Arial");
  159. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  160. $pdf->Cell(30, $cell_height, "Name:", 0, 0);
  161. $pdf->SetX($pdf->GetX() + 5);
  162. $pdf->Cell(57.5, $cell_height, $test->challenger_name, 0, 1);
  163. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  164. $pdf->Cell(30, $cell_height, "Gender:", 0, 0);
  165. $pdf->SetX($pdf->GetX() + 5);
  166. $pdf->Cell(57.5, $cell_height, $test->challenger_gender, 0, 1);
  167. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  168. $pdf->Cell(30, $cell_height, "Description:", 0, 1);
  169. $pdf->SetFont("Arial", "", $small_font_size);
  170. $pdf->MultiCell(90, 4, $test->challenger_description, 0, 1);
  171. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  172. $pdf->SetY($pdf->GetY() + 2);
  173. $pdf->SetFont("Arial", "B", $normal_font_size);
  174. $pdf->Cell(95, $cell_height, "Tester's Notes", 0, 1);
  175. $pdf->SetY($pdf->GetY() + 2);
  176. $pdf->SetFont("Arial");
  177. $pdf->SetFont("Arial", "", $small_font_size);
  178. $pdf->MultiCell(90, 4, $test->additional_notes, 0, 1);
  179. $pdf->SetY($pdf->GetY() + 2);
  180. // Challenge
  181. $pdf->SetLeftMargin(107.5);
  182. $pdf->SetY($id_requests_y);
  183. $pdf->SetFont("Arial", "B", $normal_font_size);
  184. $pdf->Cell(95, $cell_height, "ID Request", 0, 1);
  185. $pdf->SetY($pdf->GetY() + 2);
  186. $pdf->SetFont("Arial");
  187. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  188. $pdf->Cell(30, $cell_height, "Result:", 0, 0);
  189. $pdf->SetX($pdf->GetX() + 5);
  190. $pdf->Cell(60, $cell_height, $test->getPassText(), 0, 1);
  191. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  192. $pdf->Cell(30, $cell_height, "ID Stage:", 0, 0);
  193. $pdf->SetX($pdf->GetX() + 5);
  194. $pdf->Cell(60, $cell_height, $test->challenge_stage . " - " . $test->getChallengeStageText(), 0, 1);
  195. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  196. $pdf->SetY($pdf->GetY() + 2);
  197. $pdf->SetFont("Arial", "", $small_font_size);
  198. $pdf->SetTextColor(0, 128, 0);
  199. $pdf->MultiCell(95, 4, "1: Challenge on entry", 0, 1);
  200. $pdf->SetTextColor(255, 128, 0);
  201. $pdf->MultiCell(95, 4, "2: Challenge while browsing
  202. 3: Challenge during play", 0, 1);
  203. $pdf->SetTextColor(255, 0, 0);
  204. $pdf->MultiCell(95, 4, "4: Challenge on exit
  205. 5: No challenge", 0, 1);
  206. $pdf->SetFont("Arial", "", $normal_font_size);
  207. $pdf->SetTextColor(0, 0, 0);
  208. $pdf->SetY($pdf->GetY() + 2);
  209. $pdf->SetFont("Arial", "", $normal_font_size);
  210. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  211. $pdf->Cell(30, $cell_height, "Eye Contact:", 0, 0);
  212. $pdf->SetX($pdf->GetX() + 5);
  213. $pdf->Cell(60, $cell_height, $test->challenger_eye_contact ? "Y" : "N", 0, 1);
  214. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  215. $pdf->Cell(95, $cell_height, "Description:", 0, 1);
  216. $pdf->SetFont("Arial", "", $small_font_size);
  217. $pdf->MultiCell(90, 4, $test->challenge_description, 0, 1);
  218. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  219. $pdf->SetY($pdf->GetY() + 2);
  220. // Details / Signage
  221. $pdf->SetFont("Arial", "B", $normal_font_size);
  222. $pdf->Cell(95, $cell_height, "Play Details & Signage", 0, 1);
  223. $pdf->SetY($pdf->GetY() + 2);
  224. $pdf->SetFont("Arial");
  225. $field_width = 50;
  226. $value_width = 40;
  227. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  228. $pdf->Cell($field_width, $cell_height, "Machine Played:", 0, 0);
  229. $pdf->SetX($pdf->GetX() + 5);
  230. $pdf->Cell($value_width, $cell_height, $values["play_machine"] ?? "N/A", 0, 1);
  231. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  232. $value = $values["play_jackpot"] ?? "N/A";
  233. if($value != "N/A") $value = "\xa3" . number_format($value);
  234. $pdf->Cell($field_width, $cell_height, "Jackpot Value:", 0, 0);
  235. $pdf->SetX($pdf->GetX() + 5);
  236. $pdf->Cell($value_width, $cell_height, $value, 0, 1);
  237. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  238. $value = $values["play_machine_stake"] ?? "N/A";
  239. if($value != "N/A") $value = "\xa3" . number_format($value, 2);
  240. $pdf->Cell($field_width, $cell_height, "Stake Played:", 0, 0);
  241. $pdf->SetX($pdf->GetX() + 5);
  242. $pdf->Cell($value_width, $cell_height, $value, 0, 1);
  243. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  244. $pdf->Cell($field_width, $cell_height, "Minutes Played:", 0, 0);
  245. $pdf->SetX($pdf->GetX() + 5);
  246. $pdf->Cell($value_width, $cell_height, $values["play_minutes"] ?? "N/A", 0, 1);
  247. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  248. $value = $values["play_spent"] ?? "N/A";
  249. if($value != "N/A") $value = "\xa3" . number_format($value, 2);
  250. $pdf->Cell($field_width, $cell_height, "Amount Spent:", 0, 0);
  251. $pdf->SetX($pdf->GetX() + 5);
  252. $pdf->Cell($value_width, $cell_height, $value, 0, 1);
  253. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  254. $pdf->Cell($field_width, $cell_height, "Think 21/25:", 0, 0);
  255. $pdf->SetX($pdf->GetX() + 5);
  256. $pdf->Cell($value_width, $cell_height, $values["think_21_25"] ?? "N/A", 0, 1);
  257. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  258. $value = $values["citizen_card_brochure_displayed"] ?? "";
  259. if(strlen($value) > 0) $value = $value ? "Yes" : "No";
  260. $pdf->Cell($field_width, $cell_height, "Citizen Card Brochure Displayed:", 0, 0);
  261. $pdf->SetX($pdf->GetX() + 5);
  262. $pdf->Cell($value_width, $cell_height, $value ?? "N/A", 0, 1);
  263. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  264. $value = $values["think_21_badge"] ?? "";
  265. if(strlen($value) > 0) $value = $value ? "Yes" : "No";
  266. $pdf->Cell($field_width, $cell_height, "Think 21/25 Badge Worn by Staff:", 0, 0);
  267. $pdf->SetX($pdf->GetX() + 5);
  268. $pdf->Cell($value_width, $cell_height, $value ?? "N/A", 0, 1);
  269. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  270. $value = $values["think_21_poster"] ?? "";
  271. if(strlen($value) > 0) $value = $value ? "Yes" : "No";
  272. $pdf->Cell($field_width, $cell_height, "Think 21/25 Posters Displayed:", 0, 0);
  273. $pdf->SetX($pdf->GetX() + 5);
  274. $pdf->Cell($value_width, $cell_height, $value ?? "N/A", 0, 1);
  275. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  276. $pdf->Cell($field_width, $cell_height, "Think 21/25 Poster Notes:", 0, 1);
  277. $pdf->SetFont("Arial", "", $small_font_size);
  278. $pdf->MultiCell(95, 4, $values["think_21_poster_notes"] ?? "N/A", 0, 1);
  279. $pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
  280. // Output
  281. if($output) {
  282. $pdf->Output();
  283. }
  284. ?>