1
0

test_pdf.php 12 KB

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