test_pdf.php 11 KB

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