| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- use \Mpdf\Mpdf;
- // Controller may be included directly and $pdf can be accessed.
- $test = Test::get($id);
- if(!$test) throw new Exception(__("Test not found."));
- $project = $test->getProject();
- $customer = $project->getCustomer();
- $template = $project->getTemplate();
- $template->setOverrides($project->getTemplateOverrides());
- $template_parts = json_decode($template->getJSON());
- $fields = array_merge($template_parts->beforeTest, $template_parts->duringTest);
- $field_name_label_map = [];
- foreach($fields as $field) {
- if(empty($field->name)) continue;
- $field = $template->applyOverridesToField($field);
- $field_name_label_map[$field->name] = $field->label;
- }
- if(!isset($output)) $output = true;
- $location = $test->getLocation();
- $tester = $test->getTester();
- $test_values = $test->getValues();
- $keys = array_column($test_values, "name");
- $values = array_column($test_values, "value");
- $values = array_combine($keys, $values);
- $values = array_filter($values, function($value) {
- return strlen($value) !== 0;
- });
- list($date_start, $time_start) = explode(" ", $test->dts_start);
- list($date_end, $time_end) = explode(" ", $test->dts_end);
- $dt_start = new DateTime($test->dts_start . " UTC");
- $dt_start->setTimezone(new DateTimeZone(TIMEZONE));
- $dt_end = new DateTime($test->dts_end . " UTC");
- $dt_end->setTimezone(new DateTimeZone(TIMEZONE));
- $time_start = $dt_start->format("H:i:s");
- $time_end = $dt_end->format("H:i:s");
- $diff = $dt_start->diff($dt_end, true);
- $date_start = date("d/m/Y", strtotime($test->dts_start . " UTC"));
- $duration_text = 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);
- $location_text = " $location->name";
- if($location->internal_id) {
- $location_text .= " ({$customer->internal_id_field_name}: {$location->internal_id})";
- }
- $template_processing_file_path = $template->getProcessingFilePath("test_pdf.php");
- // A4 size: 210x297mm
- // Start PDF Building
- $mpdf = new Mpdf([
- "margin_top" => 26,
- "margin_bottom" => 15,
- "margin_left" => 15,
- "margin_right" => 15,
- ]);
- $mpdf->SetSubject("Test Result");
- $mpdf->SetCreator(APP_NAME);
- $mpdf->SetAuthor(APP_NAME);
- $mpdf->SetTitle("{$location->name} Test Result @ {$date_start}");
- $mpdf->useSubstitutions = true;
- ob_start()
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- body {
- font-family: sans-serif;
- font-size: 0.75rem;
- }
- a {
- color: blue;
- }
- .bl {
- border-bottom: 1px solid #eee;
- }
- .section {
- background: #e2f0d9;
- color: #385723;
- padding: 4px 8px;
- margin-bottom: 8px;
- font-size: 1.25rem;
- }
- .subheader {
- text-transform: uppercase;
- color: #888;
- padding: 4px 8px;
- background: #eee;
- margin-bottom: 8px;
- }
- div.field {
- float: left;
- width: 29%;
- font-weight: bold;
- }
- div.value {
- float: left;
- padding-left: 1%;
- width: 69%;
- }
- .wide-field-names div.field {
- width: 59%;
- }
- .wide-field-names div.value {
- width: 39%;
- }
- div.clear {
- clear: both;
- }
- .text-muted {
- color: #ccc;
- }
- .hr {
- border-bottom: 2px solid #39b549;
- margin-bottom: 1rem;
- }
- </style>
- </head>
- <body>
- <!--mpdf
- <htmlpageheader name="Header">
- <table class="header" width="100%">
- <tr>
- <td width="33%">
- <img src="/img/logo.png" height="50" />
- </td>
- <td width="34%" align="center">
- <?php
- if($test->retest) {
- ?>
- <img src="/img/retest.png" height="38" />
- <?php
- }
- ?>
- </td>
- <td width="33%" align="right">
- <strong color="red">Test / Location ID: <?=$test->id?> / <?=$location->id?></strong><br />
- Tel: 01579 342 104<br />
- <a href="https://check-policy.com">check-policy.com</a><br />
- <a href="mailto:info@check-policy.com">info@check-policy.com</a>
- </td>
- </tr>
- </table>
- </htmlpageheader>
- <htmlpagefooter name="Footer">
- <div class="hr"></div>
- <br />
- <table width="100%">
- <tr>
- <td width="33%"><strong><?=htmlspecialchars(COMPANY_NAME)?></strong></td>
- <td width="33%" align="middle"><?=htmlspecialchars(ADDRESS)?></td>
- <td width="33%" align="right">Company Number: <?=htmlspecialchars(COMPANY_NUMBER)?></td>
- </tr>
- </table>
- </htmlpagefooter>
- <sethtmlpageheader name="Header" value="on" show-this-page="1" />
- <sethtmlpagefooter name="Footer" value="on" />
- mpdf-->
- <?php
- require $template_processing_file_path;
- ?>
- </body>
- </html>
- <?php
- $html = ob_get_clean();
- $mpdf->WriteHTML($html);
- // Output
- if($output) {
- $mpdf->Output();
- }
|