diff -r ec4f1d652ed7 -r f05ced2b5124 www/prod_r_yeast.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/prod_r_yeast.php Sat Aug 24 14:17:54 2019 +0200 @@ -0,0 +1,160 @@ +ProcessingTable) + $this->TableHeader(); + } + + function TableHeader() { + $this->SetFont('Helvetica','B',9); + $this->SetX($this->TableX); + $this->SetFillColor(255,150,100); + foreach($this->aCols as $col) + $this->Cell($col['w'],5,$col['c'],0,0,$col['a'],true); + $this->Ln(); + } + + function AddCol($width=-1, $caption='', $align='L') { + $this->aCols[]=array('c'=>$caption,'w'=>$width,'a'=>$align); + } + + function TableTotals() { + + global $link; + + $vul = $this->w - $this->rMargin - $this->lMargin - 151; + $this->AddCol(16,'Code','L'); + $this->AddCol($vul,'Naam','L'); + $this->AddCol(35,'Gist','L'); + $this->AddCol(20,'Hoofdgisting','R'); + $this->AddCol(20,'Nagisten','R'); + $this->AddCol(20,'Lageren','R'); + $this->AddCol(10,'Duur','R'); + $this->AddCol(10,'OG','R'); + $this->AddCol(10,'FG','R'); + $this->AddCol(12,'SVG','R'); + + $cMargin=$this->cMargin; + $this->cMargin=2; + $this->TableX=$this->lMargin; + $this->TableHeader(); + $this->ProcessingTable=true; + + $this->SetFont('Helvetica','',9); + $this->SetFillColor(210,245,255); + + $result = mysqli_query($link, "SELECT * FROM products WHERE package_date AND type='2' ORDER BY json_yeasts"); + while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { + /* + * Data is not always available, try to calculate the mssing pieces. + */ + $y_name = $y_lab = $y_product = ''; + $yeasts = json_decode($row['json_yeasts'], true); + foreach($yeasts as $item) { + if ($item['y_use'] == 0) { + $y_name = iconv('UTF-8','windows-1252',$item['y_name']); + $y_lab = iconv('UTF-8','windows-1252',$item['y_laboratory']); + $y_product = iconv('UTF-8','windows-1252',$item['y_product_id']); + break; + } + } + + // name,brew_date_end,primary_end_date,secondary_end_date,package_date + $d1 = new DateTime($row['brew_date_end']); + $d2 = new DateTime($row['primary_end_date']); + $d3 = new DateTime($row['secondary_end_date']); + $d4 = new DateTime($row['package_date']); + + $diff = $d2->diff($d1); + $primary_days = $diff->days; + $diff = $d3->diff($d2); + $secondary_days = $diff->days; + $diff = $d4->diff($d3); + $tertiary_days = $diff->days; + $diff = $d4->diff($d1); + $total_days = $diff->days; + + $og = floatval($row['brew_fermenter_sg']); + $fg = floatval($row['fg']); + $svg = 100 * ($og - $fg) / ($og - 1); + + $name = iconv('UTF-8','windows-1252',$row['name']); + $this->SetX($this->TableX); + $this->Cell(16,5,$row['code'],0,0,'L',true); + $this->Cell($vul,5,$name,0,0,'L',true); + $this->Cell(35,5,$y_lab.' '.$y_product,0,0,'L',true); + $this->Cell(13,5,sprintf("%.1f",$row['primary_end_temp']).DEG,0,0,'R',true); + $this->Cell( 7,5,sprintf("%d",$primary_days),0,0,'R',true); + $this->Cell(13,5,sprintf("%.1f",$row['secondary_temp']).DEG,0,0,'R',true); + $this->Cell( 7,5,sprintf("%d",$secondary_days),0,0,'R',true); + $this->Cell(13,5,sprintf("%.1f",$row['tertiary_temp']).DEG,0,0,'R',true); + $this->Cell( 7,5,sprintf("%d",$tertiary_days),0,0,'R',true); + $this->Cell(10,5,sprintf("%d",$total_days),0,0,'R',true); + $this->Cell(10,5,sprintf("%.3f",$og),0,0,'R',true); + $this->Cell(10,5,sprintf("%.3f",$fg),0,0,'R',true); + $this->Cell(12,5,sprintf("%.1f",$svg).'%',0,0,'R',true); + $this->Ln(); + } + $this->ProcessingTable=false; + $this->cMargin=$cMargin; + $this->aCols=array(); + $this->Ln(); + } +} + + + +class PDF extends PDF_MySQL_Table { + function Header() { + global $prdate; + global $my_brewery_name; + $this->Image('images/logo.png',10,10,30); + // Title + $this->SetFont('Helvetica','B',18); + $this->SetX(45); + $this->Cell(0,8,"Vergisting ".$my_brewery_name,0,1,'L'); + $this->Ln(1); + $this->SetFont('Helvetica','',10); + $this->SetX(45); + $this->Cell(17,5,'Datum:',0,0,'L'); + $this->Cell(0,5,$prdate,0,1,'L'); + $this->Ln(20); + // Ensure table header is printed + parent::Header(); + } +} + + + +/* + * Generate PDF + */ +$pdf = new PDF(); +$pdf->AddPage(); +$pdf->TableTotals(); +$pdf->Output();