test_pdf.php 12 KB

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