Implemented products.secondary_end_sg field. The missing values are updated by the crontask.

Mon, 26 Aug 2019 16:01:27 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 26 Aug 2019 16:01:27 +0200
changeset 460
046ff5fdc96c
parent 459
53fafe474742
child 461
f147a3962775

Implemented products.secondary_end_sg field. The missing values are updated by the crontask.

www/crontasks.php file | annotate | diff | comparison | revisions
www/import/from_brouwhulp.php file | annotate | diff | comparison | revisions
www/includes/db_product.php file | annotate | diff | comparison | revisions
www/js/prod_edit.js file | annotate | diff | comparison | revisions
www/prod_duplicate.php file | annotate | diff | comparison | revisions
www/prod_edit.php file | annotate | diff | comparison | revisions
www/prod_print.php file | annotate | diff | comparison | revisions
www/rec_toproduct.php file | annotate | diff | comparison | revisions
--- a/www/crontasks.php	Sun Aug 25 14:04:25 2019 +0200
+++ b/www/crontasks.php	Mon Aug 26 16:01:27 2019 +0200
@@ -91,3 +91,15 @@
 	}
 }
 
+
+/*
+ * Check and update secondary_end_sg
+ */
+$query = "UPDATE products SET secondary_end_sg=fg WHERE stage > 5 AND secondary_end_sg='0';";
+$result = mysqli_query($connect, $query);
+$changed = mysqli_affected_rows($connect);
+if ($changed > 0) {
+        syslog(LOG_NOTICE, "Updated ".$changed." products with new secondary_end_sg value");
+}
+
+
--- a/www/import/from_brouwhulp.php	Sun Aug 25 14:04:25 2019 +0200
+++ b/www/import/from_brouwhulp.php	Mon Aug 26 16:01:27 2019 +0200
@@ -1685,6 +1685,7 @@
 				$sdate = new DateTime($brewdate);
 				$sdate->modify("+".floatval($recipe->SECONDARY_AGE)." days");
 				$sql .= "', secondary_temp='" . floatval($recipe->SECONDARY_TEMP);
+				$sql .= "', secondary_end_sg='" . floatval($recipe->FG);
 				$sql .= "', secondary_end_date='" . $sdate->format("Y-m-d");
 				$stage = 5;	// Tertiary
 
--- a/www/includes/db_product.php	Sun Aug 25 14:04:25 2019 +0200
+++ b/www/includes/db_product.php	Mon Aug 26 16:01:27 2019 +0200
@@ -116,6 +116,7 @@
 		$sql .= "', primary_end_date='" . $_POST['primary_end_date'] ."'";
 	$sql .=  ", primary_end_sg='" . $_POST['primary_end_sg'];
 	$sql .= "', secondary_temp='" . $_POST['secondary_temp'];
+	$sql .= "', secondary_end_sg='" . $_POST['secondary_end_sg'];
 	if ($_POST['secondary_end_date'] == '')
 		$sql .= "', secondary_end_date=NULL";
 	else
@@ -711,6 +712,7 @@
 		$brew .= ',"primary_end_sg":' . floatval($row['primary_end_sg']);
 		$brew .= ',"primary_end_date":"' . $row['primary_end_date'];
 		$brew .= '","secondary_temp":' . floatval($row['secondary_temp']);
+		$brew .= ',"secondary_end_sg":' . floatval($row['secondary_end_sg']);
 		$brew .= ',"secondary_end_date":"' . $row['secondary_end_date'];
 		$brew .= '","tertiary_temp":' . floatval($row['tertiary_temp']);
 		$brew .= ',"package_date":"' . $row['package_date'];
--- a/www/js/prod_edit.js	Sun Aug 25 14:04:25 2019 +0200
+++ b/www/js/prod_edit.js	Mon Aug 26 16:01:27 2019 +0200
@@ -1764,16 +1764,23 @@
 	}
 
 function calcFermentation(){
-if(dataRecord.brew_fermenter_sg<1.020)return;
-var obrix=sg_to_brix(dataRecord.brew_fermenter_sg);
-if ((dataRecord.primary_end_sg>0.990)&&(dataRecord.primary_end_sg<dataRecord.brew_fermenter_sg)){
-var primary_svg=Round(100*(dataRecord.brew_fermenter_sg-dataRecord.primary_end_sg)/(dataRecord.brew_fermenter_sg-1),1);
-$("#primary_svg").val(primary_svg);
-if((dataRecord.fg>0.990)&&(dataRecord.fg<dataRecord.brew_fermenter_sg)){
-var final_svg=Round(100*(dataRecord.brew_fermenter_sg-dataRecord.fg)/(dataRecord.brew_fermenter_sg-1),1);
-$("#final_svg").val(final_svg);
-var ABV=Round(abvol(dataRecord.brew_fermenter_sg,dataRecord.fg),2);
-$("#final_abv").val(ABV);}}}
+	if(dataRecord.brew_fermenter_sg<1.020)return;
+	var obrix=sg_to_brix(dataRecord.brew_fermenter_sg);
+	if ((dataRecord.primary_end_sg>0.990)&&(dataRecord.primary_end_sg<dataRecord.brew_fermenter_sg)){
+		var primary_svg=Round(100*(dataRecord.brew_fermenter_sg-dataRecord.primary_end_sg)/(dataRecord.brew_fermenter_sg-1),1);
+		$("#primary_svg").val(primary_svg);
+		if((dataRecord.secondary_end_sg>0.990)&&(dataRecord.secondary_end_sg<dataRecord.brew_fermenter_sg)){
+			var secondary_svg=Round(100*(dataRecord.brew_fermenter_sg-dataRecord.secondary_end_sg)/(dataRecord.brew_fermenter_sg-1),1);
+			$("#secondary_svg").val(secondary_svg);
+			if((dataRecord.fg>0.990)&&(dataRecord.fg<dataRecord.brew_fermenter_sg)){
+				var final_svg=Round(100*(dataRecord.brew_fermenter_sg-dataRecord.fg)/(dataRecord.brew_fermenter_sg-1),1);
+				$("#final_svg").val(final_svg);
+				var ABV=Round(abvol(dataRecord.brew_fermenter_sg,dataRecord.fg),2);
+				$("#final_abv").val(ABV);
+			}
+		}
+	}
+}
 
 	function ResCO2(CO2, T) {
 		//var resco2 = 0.000849151 * T * T - 0.0587512 * T + 1.71137; // brouwhulp
@@ -2053,6 +2060,7 @@
 		}
 		if (dataRecord.stage >= 6) {	// Packaged
 			$("#secondary_temp").jqxNumberInput({ spinButtons: false, readOnly: true, width: 90 });
+			$("#secondary_end_sg").jqxNumberInput({ spinButtons: false, readOnly: true, width: 90 });
 			$("#secondary_end_date").jqxDateTimeInput({ disabled: true });
 			$("#tertiary_temp").jqxNumberInput({ spinButtons: false, readOnly: true, width: 90 });
 			$("#fg").jqxNumberInput({ spinButtons: false, readOnly: true, width: 90 });
@@ -2528,6 +2536,17 @@
 				calcFermentation();
 			}
 		});
+		$("#secondary_end_sg").on('change',function (event){dataRecord.secondary_end_sg=parseFloat(event.args.value);calcFermentation();});
+		$("#secondary_end_brix").on('change', function (event) {
+                        if(dataRecord.brew_fermenter_sg>=1.020){
+                                OBrix=sg_to_brix(dataRecord.brew_fermenter_sg);
+                                FBrix=parseFloat(event.args.value);
+var FG=Round(1.0031-0.002318474*OBrix-0.000007775*(OBrix*OBrix)-0.000000034*Math.pow(OBrix,3)+0.00574*(FBrix)+0.00003344*(FBrix*FBrix)+0.000000086*Math.pow(FBrix,3),4);
+                                //console.log("OBrix:"+OBrix+" FBrix:"+FBrix+" FG:"+FG);
+                                if(FBrix>0.05){$("#secondary_end_sg").val(FG);dataRecord.secondary_end_sg=FG;}
+                                calcFermentation();
+                        }
+                });
 		$("#final_brix").on('change',function (event){
 			if(dataRecord.brew_fermenter_sg>=1.020){
 				OBrix=sg_to_brix(dataRecord.brew_fermenter_sg);
@@ -2739,6 +2758,7 @@
 			primary_end_sg: parseFloat($("#primary_end_sg").jqxNumberInput('decimal')),
 			primary_end_date: $("#primary_end_date").val(),
 			secondary_temp: parseFloat($("#secondary_temp").jqxNumberInput('decimal')),
+			secondary_end_sg: parseFloat($("#secondary_end_sg").jqxNumberInput('decimal')),
 			secondary_end_date: $("#secondary_end_date").val(),
 			tertiary_temp: parseFloat($("#tertiary_temp").jqxNumberInput('decimal')),
 			package_date: $("#package_date").val(),
@@ -2967,6 +2987,7 @@
 			{ name: 'primary_end_sg', type: 'float' },
 			{ name: 'primary_end_date', type: 'string' },
 			{ name: 'secondary_temp', type: 'float' },
+			{ name: 'secondary_end_sg', type: 'float' },
 			{ name: 'secondary_end_date', type: 'string' },
 			{ name: 'tertiary_temp', type: 'float' },
 			{ name: 'package_date', type: 'string' },
@@ -3178,6 +3199,7 @@
 			$("#primary_end_sg").val(dataRecord.primary_end_sg);
 			$("#primary_end_date").val(dataRecord.primary_end_date);
 			$("#secondary_temp").val(dataRecord.secondary_temp);
+			$("#secondary_end_sg").val(dataRecord.secondary_end_sg);
 			$("#secondary_end_date").val(dataRecord.secondary_end_date);
 			$("#tertiary_temp").val(dataRecord.tertiary_temp);
 			$("#package_date").val(dataRecord.package_date);
@@ -5774,6 +5796,12 @@
 	$("#primary_end_date").jqxDateTimeInput( Dateopts );
 	$('#primary_end_date').on('close', function (event) { calcStage(); });
 	$("#secondary_temp").jqxNumberInput( YeastT );
+	$("#secondary_end_sg").jqxTooltip({ content: 'Het gemeten SG aan het eind van de navergisting.' });
+        $("#secondary_end_sg").jqxNumberInput( SGopts );
+        $("#secondary_end_brix").jqxTooltip({ content: 'Hulpfinctie: de afgelezen &deg;Brix RI waarde met een refractometer.' });
+        $("#secondary_end_brix").jqxNumberInput( Spin1dec );
+        $("#secondary_svg").jqxTooltip({ content: 'De schijnbare vergisting graad behaald na de nagisting.' });
+        $("#secondary_svg").jqxNumberInput( Show1dec );
 	$("#secondary_end_date").jqxTooltip({ content: 'De eind datum van de navergisting en het begin van het lageren.' });
 	$("#secondary_end_date").jqxDateTimeInput( Dateopts );
 	$('#secondary_end_date').on('close', function (event) { calcStage(); });
--- a/www/prod_duplicate.php	Sun Aug 25 14:04:25 2019 +0200
+++ b/www/prod_duplicate.php	Mon Aug 26 16:01:27 2019 +0200
@@ -97,6 +97,7 @@
 $sql .= "', primary_end_date=NULL";
 $sql .=  ", primary_end_sg='0";
 $sql .= "', secondary_temp='0";
+$sql .= "', secondary_end_sg='0";
 $sql .= "', secondary_end_date=NULL";
 $sql .=  ", tertiary_temp='0";
 $sql .= "', package_date=NULL";
--- a/www/prod_edit.php	Sun Aug 25 14:04:25 2019 +0200
+++ b/www/prod_edit.php	Mon Aug 26 16:01:27 2019 +0200
@@ -683,8 +683,16 @@
         <td align="left" colspan="3" style="vertical-align: top;"><div id="secondary_temp"></div></td>
        </tr>
        <tr>
+        <td style="vertical-align: top; float: right; padding: 3px;">Eind nagisting SG:</td>
+        <td align="left" style="vertical-align: top;"><div id="secondary_end_sg"></div></td>
+        <td style="vertical-align: top; float: right; padding: 3px;">Afgelezen &deg;Brix RI:</td>
+        <td align="left" style="vertical-align: top;"><div id="secondary_end_brix"></div></td>
+       </tr>
+       <tr>
         <td style="vertical-align: top; float: right; padding: 3px;">Eind nagisting/start lageren:</td>
-        <td align="left" colspan="3" style="vertical-align: top;"><div id="secondary_end_date"></div></td>
+        <td align="left" style="vertical-align: top;"><div id="secondary_end_date"></div></td>
+        <td style="vertical-align: top; float: right; padding: 3px;">Schijnbare vergistingsgraad %:</td>
+        <td align="left" style="vertical-align: top;"><div id="secondary_svg"></div></td>
        </tr>
        <tr>
         <td colspan="4"><hr></td>
@@ -697,9 +705,6 @@
         <td align="left" colspan="3" style="vertical-align: top;"><div id="tertiary_temp"></div></td>
        </tr>
        <tr>
-        <th style="text-align: center;" colspan="4">&nbsp;</th>
-       </tr>
-       <tr>
         <td style="vertical-align: top; float: right; padding: 3px;">Het verwachte eind SG:</td>
         <td align="left" colspan="3" style="vertical-align: top;"><div id="est_fg3"></div></td>
        </tr>
@@ -716,7 +721,7 @@
         <td align="left" style="vertical-align: top;"><div id="final_svg"></div></td>
        </tr>
       </table>
-      <div style="float: right; margin-top: 80px; margin-bottom: 5px;">
+      <div style="float: right; margin-top: 55px; margin-bottom: 5px;">
        <input style="margin-right: 600px;" type="button" id="FLog"  value="Vergisting log" />
       </div>
      </div>
--- a/www/prod_print.php	Sun Aug 25 14:04:25 2019 +0200
+++ b/www/prod_print.php	Mon Aug 26 16:01:27 2019 +0200
@@ -834,46 +834,50 @@
                 $this->Cell(45,5,'Hoofdvergisting start temp.',0,0,'L',true);
                 $this->Cell(45,5,sprintf("%.1f",$row['primary_start_temp']).DEG.'C',0,0,'L',true);
                 $this->Cell($vul,5,'',0,0,'L',false);
-                $this->Cell(45,5,'Navergisting tempertuur',0,0,'L',true);
-                $this->Cell(45,5,sprintf("%.1f", $row['secondary_temp']).DEG.'C',0,0,'L',true);
-                $this->Ln();
-
-		$this->SetX($this->TableX);
                 $this->Cell(45,5,'Hoofdvergisting piek temp.',0,0,'L',true);
                 $this->Cell(45,5,sprintf("%.1f",$row['primary_max_temp']).DEG.'C',0,0,'L',true);
-                $this->Cell($vul,5,'',0,0,'L',false);
-                $this->Cell(45,5,'Navergisting einde',0,0,'L',true);
-                $this->Cell(45,5,$row['secondary_end_date'],0,0,'L',true);
                 $this->Ln();
 
 		$this->SetX($this->TableX);
                 $this->Cell(45,5,'Hoofdvergisting eind temp.',0,0,'L',true);
                 $this->Cell(45,5,sprintf("%.1f",$row['primary_end_temp']).DEG.'C',0,0,'L',true);
-                $this->Cell($vul,5,'',0,0,'L',false);
-                $this->Cell(45,5,'Lageren temperatuur',0,0,'L',true);
-                $this->Cell(45,5,sprintf("%.1f",$row['tertiary_temp']).DEG.'C',0,0,'L',true);
+		$this->Cell($vul,5,'',0,0,'L',false);
+		$this->Cell(45,5,'Hoofdvergisting densiteit',0,0,'L',true);
+                $this->Cell(45,5,sprintf("%.3f",floatval($row['primary_end_sg'])).' SG',0,0,'L',true);
                 $this->Ln();
 
 		$this->SetX($this->TableX);
-                $this->Cell(45,5,'Hoofdvergisting densiteit',0,0,'L',true);
-                $this->Cell(45,5,density_str(floatval($row['primary_end_sg'])),0,0,'L',true);
-                $this->Cell($vul,5,'',0,0,'L',false);
-                $this->Cell(45,5,'Lageren densiteit',0,0,'L',true);
-                $this->Cell(45,5,density_str(floatval($row['fg'])),0,0,'L',true);
-                $this->Ln();
+		$this->Cell(45,5,'Hoofdvergisting einde',0,0,'L',true);
+                $this->Cell(45,5,$row['primary_end_date'],0,0,'L',true);
+		$this->Ln();
+
+		$this->SetX($this->TableX);
+		$this->Cell(45,5,'Navergisting tempertuur',0,0,'L',true);
+                $this->Cell(45,5,sprintf("%.1f", $row['secondary_temp']).DEG.'C',0,0,'L',true);
+		$this->Cell($vul,5,'',0,0,'L',false);
+		$this->Cell(45,5,'Nagisten densiteit',0,0,'L',true);
+                $this->Cell(45,5,sprintf("%.3f",floatval($row['secondary_end_sg'])).' SG',0,0,'L',true);
+		$this->Ln();
 
 		$this->SetX($this->TableX);
-                $this->Cell(45,5,'Hoofdvergisting einde',0,0,'L',true);
-                $this->Cell(45,5,$row['primary_end_date'],0,0,'L',true);
-                $this->Cell($vul,5,'',0,0,'L',false);
+                $this->Cell(45,5,'Nagisten einde',0,0,'L',true);
+                $this->Cell(45,5,$row['secondary_end_date'],0,0,'L',true);
+		$this->Ln();
+
+		$this->SetX($this->TableX);
+		$this->Cell(45,5,'Lageren temperatuur',0,0,'L',true);
+                $this->Cell(45,5,sprintf("%.1f",$row['tertiary_temp']).DEG.'C',0,0,'L',true);
+		$this->Cell($vul,5,'',0,0,'L',false);
+		$this->Cell(45,5,'Lageren densiteit',0,0,'L',true);
+                $this->Cell(45,5,sprintf("%.3f",floatval($row['fg'])).' SG',0,0,'L',true);
+		$this->Ln();
+
+		$this->SetX($this->TableX);
                 $this->Cell(45,5,'Lageren einde',0,0,'L',true);
                 $this->Cell(45,5,$row['package_date'],0,0,'L',true);
-                $this->Ln();
-
+		$this->Cell($vul,5,'',0,0,'L',false);
 		$svg = 100 * (floatval($row['brew_fermenter_sg']) - floatval($row['fg'])) / (floatval($row['brew_fermenter_sg']) - 1);
-		$this->SetX($this->TableX);
-                $this->Cell($vul+90,5,'',0,0,'L',false);
-                $this->Cell(45,5,'Schijnbare vergistingsgraad',0,0,'L',true);
+		$this->Cell(45,5,'Schijnbare vergistingsgraad',0,0,'L',true);
                 $this->Cell(45,5,sprintf("%.1f",$svg).'%',0,0,'L',true);
                 $this->Ln();
 	}
--- a/www/rec_toproduct.php	Sun Aug 25 14:04:25 2019 +0200
+++ b/www/rec_toproduct.php	Mon Aug 26 16:01:27 2019 +0200
@@ -56,7 +56,7 @@
 $sql .= "', brew_fermenter_extrawater='0', brew_fermenter_tcloss='0.5', brew_fermenter_sg='0";
 $sql .= "', brew_fermenter_ibu='0', brew_fermenter_color='0', brew_date_end=NULL, og='0', fg='0";
 $sql .= "', primary_start_temp='0', primary_max_temp='0', primary_end_temp='0', primary_end_date=NULL, primary_end_sg='0";
-$sql .= "', secondary_temp='0', secondary_end_date=NULL, tertiary_temp='0";
+$sql .= "', secondary_temp='0', secondary_end_sg='0', secondary_end_date=NULL, tertiary_temp='0";
 $sql .= "', package_date=NULL, package_volume='0', package_infuse_amount='0', package_infuse_abv='0', package_infuse_notes='";
 $sql .= "', package_abv='0', package_ph='0";
 $sql .= "', bottle_amount='0', bottle_carbonation='0', bottle_priming_water='0', bottle_priming_amount='0', bottle_carbonation_temp='23";

mercurial