www/rec_print.php

changeset 87
7f1d0abe5571
parent 86
e977a505ea8c
child 88
0a39cbdcf085
--- a/www/rec_print.php	Sun Nov 11 17:53:33 2018 +0100
+++ b/www/rec_print.php	Sun Nov 11 23:15:46 2018 +0100
@@ -24,6 +24,9 @@
 $cost_hops = 0.0;
 $cost_yeasts = 0.0;
 $cost_miscs = 0.0;
+$pSugar = 0;
+$pCara = 0;
+$svg = 77;
 
 
 class PDF_MySQL_Table extends FPDF
@@ -84,39 +87,6 @@
 		$this->Cell(35,5,'Brouwzaal rendement',0,0,'L',true);
 		$this->Cell(25,5,$row['efficiency'].' %',0,0,'L',true);
 		$this->Cell(25,5,'',0,0,'L',true);
-		$this->Ln();
-
-		$this->SetX($this->TableX);
-		$this->Cell(35,5,'Start SG',0,0,'L',true);
-		$this->Cell(25,5,sprintf("%.3f",$row['est_og']),0,0,'L',true);
-		$this->Cell(25,5,'('.sprintf("%.3f",$row['st_og_min']).' - '.sprintf("%.3f",$row['st_og_max']).')',0,0,'L',true);
-		$this->Cell($vul,5,'',0,0,'L',false);
-		$this->Cell(35,5,'Eind SG',0,0,'L',true);
-		$this->Cell(25,5,sprintf("%.3f",$row['est_fg']),0,0,'L',true);
-		$this->Cell(25,5,'('.sprintf("%.3f",$row['st_fg_min']).' - '.sprintf("%.3f",$row['st_fg_max']).')',0,0,'L',true);
-		$this->Ln();
-
-		$this->SetX($this->TableX);
-		$this->Cell(35,5,'Geschat alcohol',0,0,'L',true);
-		$this->Cell(25,5,sprintf("%.1f",$row['est_abv']).'%',0,0,'L',true);
-		$this->Cell(25,5,'('.sprintf("%.1f",$row['st_abv_min']).' - '.sprintf("%.1f",$row['st_abv_max']).'%)',0,0,'L',true);
-		$this->Cell($vul,5,'',0,0,'L',false);
-		$this->Cell(35,5,'CO2',0,0,'L',true);
-		$this->Cell(25,5,sprintf("%.1f",$row['est_carb']).'%',0,0,'L',true);
-		$this->Cell(25,5,'('.sprintf("%.1f",$row['st_carb_min']).' - '.sprintf("%.1f",$row['st_carb_max']).'%)',0,0,'L',true);
-		$this->Ln();
-
-		$this->SetX($this->TableX);
-		$this->Cell(35,5,'Kleur ('.$row['color_method'].')',0,0,'L',true);
-		$beercolor = ebc_to_color($row['est_color']);
-		$this->SetFillColor($beercolor[0],$beercolor[1],$beercolor[2]);
-		$this->Cell(25,5,$row['est_color'].' EBC',0,0,'L',true);
-		$this->Cell(25,5,'('.$row['st_color_min'].' - '.$row['st_color_max'].' EBC)',0,0,'L',true);
-		$this->SetFillColor(210,245,255);
-		$this->Cell($vul,5,'',0,0,'L',false);
-		$this->Cell(35,5,'Bitterheid ('.$row['ibu_method'].')',0,0,'L',true);
-		$this->Cell(25,5,sprintf("%.0f",$row['est_ibu']).' IBU',0,0,'L',true);
-		$this->Cell(25,5,'('.$row['st_ibu_min'].' - '.$row['st_ibu_max'].' IBU)',0,0,'L',true);
 		$this->Ln(10);
 
 		$this->cMargin=$cMargin;
@@ -125,6 +95,8 @@
 	function TableFermentables($row) {
 		global $cost_fermentables;
 		global $total_fermentables;
+		global $pSugar;
+		global $pCara;
 		$vul = $this->w - $this->rMargin - $this->lMargin - 132;
 		$this->AddCol($vul,'Grondstof','L');
 		$this->AddCol(30,'Leverancier','L');
@@ -142,7 +114,6 @@
 		$this->ProcessingTable=true;
 
 		$sugf = 0;
-//		$tot = 0;
 		$this->SetFont('Helvetica','',9);
 		$this->SetFillColor(250, 195, 65);
 		$arr = json_decode($row['json_fermentables'], true);
@@ -150,12 +121,20 @@
 			$name     = iconv('UTF-8','windows-1252',$item['f_name']);
 			$supplier = iconv('UTF-8','windows-1252',$item['f_supplier']);
 			$added    = iconv('UTF-8','windows-1252',$item['f_added']);
+			$type     = iconv('UTF-8','windows-1252',$item['f_type']);
+			$graintype     = iconv('UTF-8','windows-1252',$item['f_graintype']);
 			$amount   = floatval($item['f_amount']);
 			$costkg   = floatval($item['f_cost']);
 			$yield    = floatval($item['f_yield']);
 			$moisture = floatval($item['f_moisture']);
 			$color    = floatval($item['f_color']);
 			$percent  = floatval($item['f_percentage']);
+
+			if ($type == "Sugar")
+				$pSugar += $percent;
+			if ($graintype == "Crystal")
+				$pCara += $percent;
+
 			$cost = $amount * $costkg;
 			$cost_fermentables += $cost;
 			$total_fermentables += $amount;
@@ -164,10 +143,6 @@
 			if ($added == "Mash")
 				$d = floatval($row['efficiency']) / 100 * $d;
 			$sugf += $d;
-//			$tot += $amount;
-			//$plato = 100 * $d / $amount;
-			//$this->Cell(0,5,$tot.' sugf: '.$sugf.' d: '.$d.' pt: '.$plato.' moisture: '.$moisture,0,0,'L',false);
-			//$this->Ln();
 
 			$this->Cell($vul,5,$name,0,0,'L',true);
 			$this->Cell(30,5,$supplier,0,0,'L',true);
@@ -180,17 +155,9 @@
 			$this->Ln();
 		}
 
-		$plato = 100 * $sugf / floatval($row['batch_size']);
-		$sg = plato_to_sg($plato);
-		/* Average loops, HansH 5x. Brouwhulp 20x, about 10x is enough so keep 20. */
-		for ($i = 0; $i < 20; $i++) {
-			if ($sg > 0)
-				$plato = 100 * $sugf / (floatval($row['batch_size']) * $sg);
-			$sg = plato_to_sg($plato);
-		}
+		$row['est_og'] = estimate_og($sugf, floatval($row['batch_size']));
 		$this->SetFillColor(210,245,255);
-		$this->Cell($vul,5,sprintf("%.1f",$plato).' Plato, OG: '.sprintf("%.3f",$sg),0,0,'L',true);
-		$this->Cell(62,5,'',0,0,'L',false);
+		$this->Cell($vul+62,5,'',0,0,'L',false);
 		$this->Cell(20,5,sprintf("%8.3f",$total_fermentables),0,0,'R',true);
 		$this->Cell(30,5,'',0,0,'L',false);
 		$this->Cell(20,5,sprintf("%8.3f",$cost_fermentables).EURO,0,0,'R',true);
@@ -290,6 +257,7 @@
 
 	function TableYeasts($row) {
 		global $cost_yeasts;
+		global $svg;
 		$vul = $this->w - $this->rMargin - $this->lMargin - 140;
 		$this->AddCol(27,'Laboratorium','L');
 		$this->AddCol(18,'Product','L');
@@ -308,7 +276,6 @@
 
 		$this->SetFont('Helvetica','',9);
 		$this->SetFillColor(175, 175, 255);
-		$svg = 70;	/* Conservative SVG% as default */
 
 		$arr = json_decode($row['json_yeasts'], true);
 		foreach($arr as $item) { //foreach element in $arr
@@ -340,11 +307,6 @@
 		$this->SetFillColor(210,245,255);
 		$this->Cell($vul+120,5,'',0,0,'L',false);
 		$this->Cell(20,5,sprintf("%8.3f",$cost_yeasts).EURO,0,0,'R',true);
-		$this->Ln();
-
-		$og = floatval($row['est_og']);
-		$fg = $og - ($svg * ($og - 1.0)) / 100;
-		$this->Cell(0,5,'FG: '.sprintf("%5.3f",$fg),0,0,'L',false);
 		$this->Ln(10);
 		$this->ProcessingTable=false;
 		$this->cMargin=$cMargin;
@@ -415,6 +377,62 @@
 	}
 
 	// Watercolor $this->SetFillColor(120,255,250);
+
+	function TableSummary($row) {
+		global $pSugar;
+		global $pCara;
+		global $svg;
+		/* 2 Columns */
+		$vul = $this->w - $this->rMargin - $this->lMargin - 170;
+		$cMargin=$this->cMargin;
+		$this->cMargin=2;
+		$this->TableX=$this->lMargin;
+		$this->SetFont('Helvetica','B',9);
+		$this->SetX($this->TableX);
+		$this->SetFillColor(255,150,100);
+		$this->Cell(0, 5, 'Recept samenvatting',0,0,'C',true);
+		$this->Ln();
+
+		$this->SetFont('Helvetica','',9);
+		$this->SetFillColor(210,245,255);
+
+		$row['est_fg'] = estimate_fg($pSugar, $pCara, 0, 0, 0, $svg, $row['est_og']);
+
+		$this->SetX($this->TableX);
+		$this->Cell(35,5,'Start SG',0,0,'L',true);
+		$this->Cell(25,5,sprintf("%.3f",$row['est_og']),0,0,'L',true);
+		$this->Cell(25,5,'('.sprintf("%.3f",$row['st_og_min']).' - '.sprintf("%.3f",$row['st_og_max']).')',0,0,'L',true);
+		$this->Cell($vul,5,'',0,0,'L',false);
+		$this->Cell(35,5,'Eind SG',0,0,'L',true);
+		$this->Cell(25,5,sprintf("%.3f",$row['est_fg']),0,0,'L',true);
+		$this->Cell(25,5,'('.sprintf("%.3f",$row['st_fg_min']).' - '.sprintf("%.3f",$row['st_fg_max']).')',0,0,'L',true);
+		$this->Ln();
+
+		$this->SetX($this->TableX);
+		$this->Cell(35,5,'Geschat alcohol',0,0,'L',true);
+		$this->Cell(25,5,sprintf("%.1f",$row['est_abv']).'%',0,0,'L',true);
+		$this->Cell(25,5,'('.sprintf("%.1f",$row['st_abv_min']).' - '.sprintf("%.1f",$row['st_abv_max']).'%)',0,0,'L',true);
+		$this->Cell($vul,5,'',0,0,'L',false);
+		$this->Cell(35,5,'CO2',0,0,'L',true);
+		$this->Cell(25,5,sprintf("%.1f",$row['est_carb']).'%',0,0,'L',true);
+		$this->Cell(25,5,'('.sprintf("%.1f",$row['st_carb_min']).' - '.sprintf("%.1f",$row['st_carb_max']).'%)',0,0,'L',true);
+		$this->Ln();
+
+		$this->SetX($this->TableX);
+		$this->Cell(35,5,'Kleur ('.$row['color_method'].')',0,0,'L',true);
+		$beercolor = ebc_to_color($row['est_color']);
+		$this->SetFillColor($beercolor[0],$beercolor[1],$beercolor[2]);
+		$this->Cell(25,5,$row['est_color'].' EBC',0,0,'L',true);
+		$this->Cell(25,5,'('.$row['st_color_min'].' - '.$row['st_color_max'].' EBC)',0,0,'L',true);
+		$this->SetFillColor(210,245,255);
+		$this->Cell($vul,5,'',0,0,'L',false);
+		$this->Cell(35,5,'Bitterheid ('.$row['ibu_method'].')',0,0,'L',true);
+		$this->Cell(25,5,sprintf("%.0f",$row['est_ibu']).' IBU',0,0,'L',true);
+		$this->Cell(25,5,'('.$row['st_ibu_min'].' - '.$row['st_ibu_max'].' IBU)',0,0,'L',true);
+		$this->Ln(10);
+		// Kostprijs per liter, calorieren
+		$this->cMargin=$cMargin;
+	}
 }
 
 
@@ -444,9 +462,14 @@
 $pdf->TableHops($row);
 $pdf->TableYeasts($row);
 $pdf->TableMiscs($row);
-
-//$pdf->SetFont('Helvetica','',10);
-//$pdf->Cell(0,10,'Receptje '.$record,0,1,'C');
-// Disclaimer toeveogen dat dit alleen recept ontwikkeling is.
-// Footer sectie met berekende/geschatte uitkomsten zoals FG, ABV, kostprijs per liter enz. 
+$pdf->TableSummary($row);
+if (strlen($row['notes'])) {
+	$pdf->SetFillColor(255,150,100);
+	$pdf->Cell(0, 5, 'Recept opmerkingen',0,0,'C',true);
+	$pdf->Ln();
+	$pdf->SetFillColor(210,245,255);
+	$pdf->MultiCell(0,4,$row['notes'],0,'L',true);
+}
+// Disclaimer toevoegen dat dit alleen recept ontwikkeling is. Uitkomsten zoals IBU zijn een berekende schatting.
+// Footer sectie met berekende/geschatte uitkomsten zoals ABV, kostprijs per liter enz. 
 $pdf->Output();

mercurial