File: /var/www/vhosts/creativefellows.nl/jhtaxatie.creativefellows.nl/classes/InspectionHoursPdf.php
<?php
/**
* Pdf Reader Service
*/
class InspectionHoursPdf
{
public function __construct($font_folder)
{
$this->font_folder = $font_folder;
$this->cell_width = 182.5;
$this->cell_half = 88.75;
$this->cell_height = 6;
// initiate PDF
$this->pdf = new Pdf();
$this->pdf->SetMargins(16, 14, 18);
// set document information
$this->pdf->SetCreator("");
$this->pdf->SetAuthor("");
$this->pdf->SetTitle("");
$this->pdf->SetSubject("");
$this->pdf->SetKeywords("");
// set default header data
$this->pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 010', PDF_HEADER_STRING);
// set header and footer fonts
$this->pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$this->pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$this->pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$this->pdf->SetMargins(17.5,17.5);
$this->pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$this->pdf->SetFooterMargin(80);
// set auto page breaks
$this->pdf->SetAutoPageBreak(TRUE, 0);
$this->pdf->setCellHeightRatio(1.5);
$this->pdf->setCellPaddings(2,0,2,0);
// gray border for tables
$this->pdf->SetLineStyle(array('width' => 0.1,'color' => array(0, 0, 0, 20)));
$this->pdf->SetProtection(array('modify', 'copy','annot-forms','fill-forms', 'extract', 'assemble', 'print-high'), '', null, 0, null);
// set fonts
$this->font_light = TCPDF_FONTS::addTTFfont('MuseoSans-300.ttf');
$this->font_bold = TCPDF_FONTS::addTTFfont('MuseoSans-700.ttf');
}
function setLightFont($size=8.5)
{
$this->pdf->SetFont($this->font_light ,"",$size,'',false);
}
function setBoldFont($size=8.5)
{
$this->pdf->SetFont($this->font_bold ,"",$size,'',false);
}
public function setSourceFile($pdf_source)
{
$this->pdf_source = $pdf_source;
}
public function addPage(int $template_page)
{
$this->pdf->setSourceFile($this->pdf_source);
$index = $this->pdf->ImportPage($template_page, '/MediaBox');
$size = $this->pdf->getTemplatesize($index);
$this->pdf->AddPage('P',$size);
$this->pdf->useTemplate($index);
}
public function create(InspectionEntity $inspection)
{
$this->addPage(4);
$this->pdf->setY(30);
// Page name
$this->pdf->setXY(15.5,13.75);
$this->setBoldFont(12);
$this->pdf->Cell(100, $this->cell_height, "Werkstaat", 0, 1, '', false);
// fields
$fields = [
"Bedrijfsnaam" => $inspection->getCompany(),
"Adres" => $inspection->getAddress(),
"Postcode" => $inspection->getZipcode(),
"Woonplaats" => $inspection->getCity(),
"Contactpersoon" => $inspection->getFullName(),
"Telefoon" => $inspection->getPhone(),
];
$cells = [
"Naam" => "inspector",
"Datum" => "date",
"Voorrijden" => "drive",
"Werkuren" => "hours",
];
// bold font
$this->setBoldFont();
$this->pdf->setY(30);
// Table header with grey background
$this->pdf->SetTextColor(0,0,0,100);
$this->pdf->setFillColor(0,0,0,10);
$this->pdf->Cell($this->cell_width, $this->cell_height, "Klantbedrijf", "TB", 1, '', true);
$this->pdf->setFillColor(0,0,0,0);
// set light font
$this->setLightFont();
foreach($fields as $element => $value)
{
$this->pdf->Cell($this->cell_width/4, $this->cell_height, $element, "TB", 0, '', true);
$this->pdf->Cell(($this->cell_width/4)*3, $this->cell_height, $value, "TB", 1, '', true);
}
$this->pdf->ln(8);
//$working_rows = 3;
$sum_voorrijden = 0;
$sum_werkuren = 0;
$working_rows = $inspection->workingHours();
for($i= -1; $i <= count($inspection->workingHours()); $i++){
$x = 0;
foreach($cells as $element => $val)
{
$border = "TB";
// table header
if($i == -1){
// Table header with grey background
$this->pdf->SetTextColor(0,0,0,100);
$this->pdf->setFillColor(0,0,0,10);
$this->setBoldFont();
$value = $element;
}
// sum last row
elseif($i == count($inspection->workingHours()))
{
$border = "TB";
switch($x){
default:
$value = "";
break;
case 0;
$this->setBoldFont();
$value = "Totaal";
break;
case 2:
$value = $sum_voorrijden;
break;
case 3:
$value = ceil($sum_werkuren * 2) / 2;
break;
}
}
// default rows
else{
$value = $inspection->workingHours()[$i][$val];
// count hours
if($x == 2) $sum_voorrijden += floatval($value);
if($x == 3) $sum_werkuren += floatval($value);
$this->setLightFont();
$this->pdf->setFillColor(0,0,0,0);
}
$ln = $x == 3 ? 1 : 0;
$this->pdf->Cell($this->cell_width/4, $this->cell_height, $value, $border, $ln, '', true);
$x++;
}
}
if($inspection->signRemarks())
{
$this->pdf->ln(8);
$this->pdf->SetTextColor(0,0,0,100);
$this->pdf->setFillColor(0,0,0,10);
$this->pdf->Cell($this->cell_width, $this->cell_height, "Opmerkingen", "TB", 1, '', true);
$this->pdf->setFillColor(0,0,0,0);
$this->setLightFont();
$this->pdf->Cell($this->cell_width, $this->cell_height, $inspection->signRemarks(), "TB", $ln, '', true);
}
$this->pdf->ln(8);
$this->setLightFont();
$this->pdf->MultiCell($this->cell_width, 0,"Werkuren ten behoeve van het uitwerken van de rapportage(s), aanmaken van kenplaten en andere werkzaamheden die niet op locatie van de klant zullen plaatsvinden, zijn niet opgenomen in deze werkstaat.", 0,"L");
$this->pdf->ln(1);
$this->pdf->SetLineStyle(array('width' => 0.1,'color' => array(0, 0, 0, 100)));
$this->setBoldFont();
$this->pdf->Cell($this->cell_width/2, $this->cell_height, "Namens Jungheinrich", "TR", 0, '', true);
$this->pdf->Cell($this->cell_width/2, $this->cell_height, "Namens klantbedrijf", "TL", 1, '', true);
$this->pdf->Cell($this->cell_width/2, 22, "", "R", 0, '', true);
$this->pdf->Cell($this->cell_width/2, 22, "", "L", 1, '', true);
$pos_y = $this->pdf->getY()-22;
$this->setLightFont();
$this->pdf->MultiCell($this->cell_width/2, 0,$inspection->getInspectorname()."\n".$inspection->dateSigned(), "R","L",0,0);
$this->pdf->MultiCell($this->cell_width/2, 0,$inspection->getUserName()."\n".$inspection->dateSigned() , "L","L",0,0);
if($inspection->getSignature("inspector")) $this->pdf->Image('@'.$inspection->getSignature("inspector"),17.5, $pos_y, '', 22, 'png');
if($inspection->getSignature("user")) $this->pdf->Image('@'.$inspection->getSignature("user"),113.5, $pos_y, '', 22, 'png');
return $this->pdf->Output($inspection->getPdfName(), 'S');
}
}