Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.

Mon, 12 Nov 2018 16:34:43 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 12 Nov 2018 16:34:43 +0100
changeset 89
082c23b26055
parent 88
0a39cbdcf085
child 90
d4246abee34e

Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.

www/import/from_brouwhulp.php file | annotate | diff | comparison | revisions
www/includes/formulas.php file | annotate | diff | comparison | revisions
www/rec_print.php file | annotate | diff | comparison | revisions
--- a/www/import/from_brouwhulp.php	Mon Nov 12 11:32:16 2018 +0100
+++ b/www/import/from_brouwhulp.php	Mon Nov 12 16:34:43 2018 +0100
@@ -18,6 +18,19 @@
 $brouwhulp = '/home/mbroek/Documents/brouwhulp';
 
 
+function get_miscs_cost($miscname) {
+	global $db;
+
+	if ($result = mysqli_query($db, "SELECT cost FROM inventory_miscs WHERE name='$miscname'")) {
+		if ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+			return floatval($row['cost']);
+		}
+	}
+	return 0.0;
+}
+
+
+
 function do_fermentables()
 {
 	global $brouwhulp, $db;
@@ -455,6 +468,7 @@
 		$pCara = 0;
 		$pSugar = 0;
 		$svg = 77;
+		$colorw = 0;
 
 		$sql  = "INSERT INTO recipes SET name='" . mysqli_real_escape_string($db, $recipe->NAME);
 		if ($recipe->NOTES)
@@ -477,11 +491,7 @@
 		$sql .= "', efficiency='" . $efficiency;
 		/* Don't use $recipe->EST_OG but recalculate it */
 		/* Don't use $recipe->EST_FG but recalculate it */
-		if ($recipe->EST_COLOR) {
-			$srm = floatval($recipe->EST_COLOR);
-			$ebc = srm_to_ebc($srm);
-			$sql .= "', est_color='" . $ebc;
-		}
+		/* Don't use $recipe->EST_COLOR but recalculate it */
 		if ($recipe->COLOR_METHOD)
 			$sql .= "', color_method='" . mysqli_real_escape_string($db, $recipe->COLOR_METHOD);
 		if ($recipe->IBU)
@@ -561,6 +571,7 @@
 				$fermentables .= ',"f_yield":' . $fyield;
 				if ($fermentable->COLOR) {
 					$srm = floatval($fermentable->COLOR);
+					$colorw += ($famount * $srm / $batch_size) * 8.34436;	/* Kleurwerking */
 					$ebc = srm_to_ebc($srm);
 					$fermentables .= ',"f_color":' . $ebc;
 				}
@@ -684,12 +695,19 @@
 				if ($comma)
 					$miscs .= ',';
 				$comma = TRUE;
-				$miscs .= '{"m_name":"' . mysqli_real_escape_string($db, $misc->NAME) . '"';
+				$mname = mysqli_real_escape_string($db, $misc->NAME);
+				$miscs .= '{"m_name":"' . $mname . '"';
 				$miscs .= ',"m_amount":' . floatval($misc->AMOUNT);
-				if ($misc->COST)
+				if ($misc->COST) {
 					$miscs .= ',"m_cost":' . floatval($misc->COST);
-				else
-					$miscs .= ',"m_cost":0';
+				} else {
+					/* Brouwhulp bug, added water agents have no cost field. */
+					if ($misc->TYPE == "Water agent") {
+						$miscs .= ',"m_cost":'. get_miscs_cost($mname);
+					} else {
+						$miscs .= ',"m_cost":0';
+					}
+				}
 				$miscs .= ',"m_type":"' . mysqli_real_escape_string($db, $misc->TYPE) . '"';
 				$miscs .= ',"m_use_use":"' . mysqli_real_escape_string($db, $misc->USE) . '"';
 				($misc->AMOUNT_IS_WEIGHT== "TRUE") ? $miscs .= ',"m_amount_is_weight":true' : $miscs.= ',"m_amount_is_weight":false';
@@ -839,7 +857,8 @@
 		$sql .= "', est_fg='" . floatval($fg);
 		$abv = abvol($og, $fg);
 		$sql .= "', est_abv='" . floatval($abv);
-
+		$color = kw_to_ebc(mysqli_real_escape_string($db, $recipe->COLOR_METHOD), $colorw);
+		$sql .= "', est_color='" . floatval($color);
 		$sql .= "';";
 		if (! $result = mysqli_query($db, $sql)) {
 			printf("Error: %s\n", mysqli_error($db));
--- a/www/includes/formulas.php	Mon Nov 12 11:32:16 2018 +0100
+++ b/www/includes/formulas.php	Mon Nov 12 16:34:43 2018 +0100
@@ -175,6 +175,26 @@
 }
 
 
+/*
+ * Kleurwerking naar SRM
+ */
+function kw_to_srm($colormethod, $c) {
+
+	if ($colormethod == "Morey")
+		return 1.49 * pow($c, 0.69);
+	if ($colormethod == "Mosher")
+		return 0.3 * $c + 4.7;
+	if ($colormethod == "Daniels")
+		return 0.2 * $c + 8.4;
+}
+
+
+
+function kw_to_ebc($colormethod, $c) {
+	return srm_to_ebc(kw_to_srm($colormethod, $c));
+}
+
+
 
 /*
 
@@ -537,7 +557,6 @@
 end;
 
 
-  CalcOG;
   CalcBitterness;
 
         // Get concentration of ions in diluted brewwater (1) and target water (2) in mmol/l
--- a/www/rec_print.php	Mon Nov 12 11:32:16 2018 +0100
+++ b/www/rec_print.php	Mon Nov 12 16:34:43 2018 +0100
@@ -27,6 +27,7 @@
 $pSugar = 0;
 $pCara = 0;
 $svg = 77;
+$colorw = 0;
 
 
 class PDF_MySQL_Table extends FPDF
@@ -56,7 +57,7 @@
 
 	function TableGlobal($row) {
 		/* 2 Columns */
-		$vul = $this->w - $this->rMargin - $this->lMargin - 170;
+		$vul = $this->w - $this->rMargin - $this->lMargin - 120;
 		$cMargin=$this->cMargin;
 		$this->cMargin=2;
 		$this->TableX=$this->lMargin;
@@ -72,21 +73,17 @@
 		$this->SetX($this->TableX);
 		$this->Cell(35,5,'Type',0,0,'L',true);
 		$this->Cell(25,5,$row['type'],0,0,'L',true);
-		$this->Cell(25,5,'',0,0,'L',true);
 		$this->Cell($vul,5,'',0,0,'L',false);
 		$this->Cell(35,5,'Batch grootte',0,0,'L',true);
 		$this->Cell(25,5,$row['batch_size'].' liter',0,0,'L',true);
-		$this->Cell(25,5,'',0,0,'L',true);
 		$this->Ln();
 
 		$this->SetX($this->TableX);
 		$this->Cell(35,5,'Kooktijd',0,0,'L',true);
 		$this->Cell(25,5,$row['boil_time'].' minuten',0,0,'L',true);
-		$this->Cell(25,5,'',0,0,'L',true);
 		$this->Cell($vul,5,'',0,0,'L',false);
 		$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(10);
 
 		$this->cMargin=$cMargin;
@@ -97,6 +94,7 @@
 		global $total_fermentables;
 		global $pSugar;
 		global $pCara;
+		global $colorw;
 		$vul = $this->w - $this->rMargin - $this->lMargin - 132;
 		$this->AddCol($vul,'Grondstof','L');
 		$this->AddCol(30,'Leverancier','L');
@@ -143,6 +141,7 @@
 			if ($added == "Mash")
 				$d = floatval($row['efficiency']) / 100 * $d;
 			$sugf += $d;
+			$colorw += ($amount * ebc_to_srm($color) / $row['batch_size']) * 8.34436;
 
 			$this->Cell($vul,5,$name,0,0,'L',true);
 			$this->Cell(30,5,$supplier,0,0,'L',true);
@@ -382,6 +381,7 @@
 		global $pSugar;
 		global $pCara;
 		global $svg;
+		global $colorw;
 		/* 2 Columns */
 		$vul = $this->w - $this->rMargin - $this->lMargin - 170;
 		$cMargin=$this->cMargin;
@@ -419,12 +419,16 @@
 		$this->Cell(25,5,'('.sprintf("%.1f",$row['st_carb_min']).' - '.sprintf("%.1f",$row['st_carb_max']).'%)',0,0,'L',true);
 		$this->Ln();
 
+		$row['est_color'] = kw_to_ebc($row['color_method'], $colorw);
 		$this->SetX($this->TableX);
 		$this->Cell(35,5,'Kleur ('.$row['color_method'].')',0,0,'L',true);
 		$beercolor = ebc_to_color($row['est_color']);
+		if ($row['est_color'] > 30)
+			$this->SetTextColor(250);
 		$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->SetTextColor(0);
 		$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);

mercurial