Import from brouwhulp fix style color ranges. Added calcSVG and calcABV calculation. Added batch size, time, efficiency and og change actions. Added style select and redesigned the first tab to fit this in. When equipment is changed, recalculate the recipe. Added print button.

Tue, 25 Dec 2018 13:42:36 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 25 Dec 2018 13:42:36 +0100
changeset 152
2e4249add363
parent 151
2c9cfe2f0860
child 153
15fe253ffa83

Import from brouwhulp fix style color ranges. Added calcSVG and calcABV calculation. Added batch size, time, efficiency and og change actions. Added style select and redesigned the first tab to fit this in. When equipment is changed, recalculate the recipe. Added print button.

www/import/from_brouwhulp.php file | annotate | diff | comparison | revisions
www/js/prod_edit.js file | annotate | diff | comparison | revisions
www/prod_edit.php file | annotate | diff | comparison | revisions
--- a/www/import/from_brouwhulp.php	Mon Dec 24 23:10:52 2018 +0100
+++ b/www/import/from_brouwhulp.php	Tue Dec 25 13:42:36 2018 +0100
@@ -366,8 +366,8 @@
 		$sql .= "', fg_max='" . floatval($style->FG_MAX);
 		$sql .= "', ibu_min='" . floatval($style->IBU_MIN);
 		$sql .= "', ibu_max='" . floatval($style->IBU_MAX);
-		$sql .= "', color_min='" . floatval($style->COLOR_MIN);
-		$sql .= "', color_max='" . floatval($style->COLOR_MAX);
+		$sql .= "', color_min='" . srm_to_ebc(floatval($style->COLOR_MIN));
+		$sql .= "', color_max='" . srm_to_ebc(floatval($style->COLOR_MAX));
 		$sql .= "', carb_min='" . floatval($style->CARB_MIN);
 		$sql .= "', carb_max='" . floatval($style->CARB_MAX);
 		$sql .= "', abv_min='" . floatval($style->ABV_MIN);
--- a/www/js/prod_edit.js	Mon Dec 24 23:10:52 2018 +0100
+++ b/www/js/prod_edit.js	Tue Dec 25 13:42:36 2018 +0100
@@ -77,10 +77,6 @@
         var     MMNaCl = 58.443;
         var     MMCaOH2 = 74.06268;
 
-	var	old_efficiency;
-	var	old_batch_size;
-	var	old_boil_time;
-
 	console.log("record:" + my_record + "  return:" + my_return + "  theme:" + theme);
         $("#jqxLoader").jqxLoader({
                 width: 250,
@@ -130,6 +126,7 @@
                 document.getElementById("bcolor").style.background= scolor;
                 document.getElementById("bcolor2").style.background= scolor;
                 pmalts = mashkg / dataRecord.eq_mash_max * 100;
+		console.log("mash kg: "+mashkg+" max: "+dataRecord.eq_mash_max+" perc: "+pmalts);
                 $("#perc_malts").jqxProgressBar('val', pmalts);
                 $("#perc_sugars").jqxProgressBar('val', psugar);
                 $("#perc_cara").jqxProgressBar('val', pcara);
@@ -142,7 +139,7 @@
 		var     vol, vol1, vol2, sug2;
 		var     mass1, mass2, efficiency;
 
-		for (j = 1; j < 15; j++) {      // Maybe needed if there is equipment, not here.
+		for (j = 1; j < 15; j++) {
 			vol = 0;
 			sug2 = 0;
 			efficiency = parseFloat(dataRecord.efficiency);
@@ -195,6 +192,10 @@
 		//CalcWaterBalance;
 	};
 
+	function calcABV() {
+		$("#est_abv").val(abvol(parseFloat($("#est_og").jqxNumberInput('decimal')), parseFloat($("#est_fg").jqxNumberInput('decimal'))));
+	};
+
 	function hopFlavourContribution(bt, vol, use, amount) {
 		var result;
 
@@ -255,6 +256,15 @@
 		$("#hop_aroma").jqxProgressBar('val', hop_aroma * 10);
 	};
 
+	function calcSVG() {
+		var rows = $('#yeastGrid').jqxGrid('getrows');
+		for (var i = 0; i < rows.length; i++) {
+			var row = rows[i];
+			if (row.y_use == "Primary")
+				svg = parseFloat(row.y_attenuation);
+		}
+	}
+
 	function calcSGendMash() {
 		est_mash_sg = 0;
 		var	mvol = 0;	// Mash volume
@@ -305,8 +315,95 @@
 		calcSGendMash();
 		calcMashEfficiency();
 
+		$('#batch_size').on('change', function (event) {
+			console.log("batch_size change:"+event.args.value+" old:"+dataRecord.batch_size);
+			var new_boil = parseFloat(event.args.value) + dataRecord.boil_size - dataRecord.batch_size;
+			dataRecord.boil_size = new_boil;
+			$("#boil_size").val(Math.round(new_boil * 100) / 100);
+			dataRecord.batch_size = parseFloat(event.args.value);
+			calcFermentablesFromOG(parseFloat($("#est_og").jqxNumberInput('decimal')));     // Keep the OG
+			calcFermentables();
+			calcSVG();
+			calcABV();
+			// TODO: adjust the hops, miscs, yeast, water.
+			calcIBUs();
+		});
+		$('#boil_time').on('change', function (event) {
+			console.log("boil_time change:"+parseFloat(event.args.value)+" old:"+dataRecord.boil_time);
+			var old_evap = parseFloat(dataRecord.boil_size) - parseFloat(dataRecord.batch_size);
+			var new_evap = old_evap * (parseFloat(event.args.value) / dataRecord.boil_time);
+			var new_boil = parseFloat(dataRecord.batch_size) + new_evap;
+			dataRecord.boil_time = parseFloat(event.args.value);
+			dataRecord.boil_size = new_boil;
+			$("#boil_size").val(Math.round(new_boil * 100) / 100);
+			calcFermentables();
+			calcSVG();
+			calcABV();
+			// TODO: adjust the hops, miscs, yeast, water.
+			calcIBUs();
+		});
+		$('#efficiency').on('change', function (event) {
+			console.log("efficiency change:"+event.args.value);
+			calcFermentables();
+			calcSVG();
+			calcABV();
+			calcIBUs();
+		});
+		$('#est_og').on('change', function (event) {
+			console.log("est_og change:"+event.args.value);
+			calcFermentablesFromOG(event.args.value);       // Adjust fermentables amounts
+			calcFermentables();                             // Update the recipe details
+			calcSVG();
+			calcABV();                                      // and ABV
+			calcIBUs();                                     // and the IBU's.
+		});
+		$('#mash_ph').on('change', function (event) {
+			dataRecord.mash_ph = parseFloat(event.args.value);
+			$("#tgt_mash_ph").val(parseFloat(event.args.value));
+	//		calcWater();
+		});
 	};
 
+	$("#styleSelect").jqxDropDownList({
+		placeHolder: "Kies bierstijl:",
+		theme: theme,
+		source: styleslist,
+		displayMember: "name",
+		width: 150,
+		height: 27,
+		dropDownVerticalAlignment: 'top',
+		dropDownWidth: 500,
+		dropDownHeight: 380,
+		renderer: function (index, label, value) {
+			var datarecord = styleslist.records[index];
+			return datarecord.style_guide + " " + datarecord.style_letter+ " " + datarecord.name;
+		}
+	});
+	$("#styleSelect").on('select', function (event) {
+		if (event.args) {
+			var index = event.args.index;
+			var datarecord = styleslist.records[index];
+			$("#st_name").val(datarecord.name);
+			$("#st_category").val(datarecord.category);
+			$("#st_category_number").val(datarecord.category_number);
+			$("#st_letter").val(datarecord.style_letter);
+			$("#st_guide").val(datarecord.style_guide);
+			$("#st_type").val(datarecord.type);
+			$("#st_og_min").val(datarecord.og_min);
+			$("#st_og_max").val(datarecord.og_max);
+			$("#st_fg_min").val(datarecord.fg_min);
+			$("#st_fg_max").val(datarecord.fg_max);
+			$("#st_ibu_min").val(datarecord.ibu_min);
+			$("#st_ibu_max").val(datarecord.ibu_max);
+			$("#st_color_min").val(datarecord.color_min);
+			$("#st_color_max").val(datarecord.color_max);
+			$("#st_carb_min").val(datarecord.carb_min);
+			$("#st_carb_max").val(datarecord.carb_max);
+			$("#st_abv_min").val(datarecord.abv_min);
+			$("#st_abv_max").val(datarecord.abv_max);
+		}
+	});
+
 	// Equipemnt dropdown list
 	var equipmentUrl = "includes/db_inventory_equipments.php";
 	var equipmentSource = {
@@ -334,6 +431,7 @@
 			{ name: 'kettle_volume', type: 'float' },
 			{ name: 'kettle_height', type: 'float' },
 			{ name: 'mash_volume', type: 'float' },
+			{ name: 'mash_max', type: 'float' },
 			{ name: 'efficiency', type: 'float' }
 		],
 		url: equipmentUrl,
@@ -359,7 +457,11 @@
 			var datarecord = equipmentlist.records[index];
 			$("#eq_name").val(datarecord.name);
 			$("#eq_boil_size").val(datarecord.boil_size);
+			dataRecord.boil_size = datarecord.boil_size;
+			$("#boil_size").val(datarecord.boil_size);
 			$("#eq_batch_size").val(datarecord.batch_size);
+			dataRecord.batch_size = datarecord.batch_size;
+			$("#batch_size").val(datarecord.batch_size);
 			$("#eq_tun_volume").val(datarecord.tun_volume);
 			dataRecord.eq_tun_weight = datarecord.tun_weight;
 			dataRecord.eq_tun_specific_heat = datarecord.tun_specific_heat;
@@ -380,7 +482,18 @@
 			dataRecord.eq_kettle_height = datarecord.kettle_height / 100.0;
 			$("#eq_mash_volume").val(datarecord.mash_volume);
 			$("#eq_mash_max").val(datarecord.mash_max);
+			dataRecord.eq_mash_max = datarecord.mash_max;
+			$("#mash_max").val(datarecord.mash_max);
 			$("#eq_efficiency").val(datarecord.efficiency);
+			dataRecord.efficiency = datarecord.efficiency;
+			$("#efficiency").val(datarecord.efficiency);
+
+			calcFermentablesFromOG(parseFloat($("#est_og").jqxNumberInput('decimal')));     // Keep the OG
+			calcFermentables();
+			calcSVG();
+			calcABV();
+			// TODO: adjust the hops, miscs, yeast, water.
+			calcIBUs();
 		}
 	});
 
@@ -422,12 +535,12 @@
 	$("#est_ibu2").jqxTooltip({ content: 'De bitterheid in IBU. Dit wordt automatisch berekend.' });
 	$("#est_abv").jqxTooltip({ content: 'Alcohol volume %. Dit wordt automatisch berekend.' });
 	$("#est_carb").jqxTooltip({ content: 'Koolzuur volume. Dit wordt automatisch berekend.' });
-//	$("#st_name").jqxTooltip({ content: 'De bierstijl naam voor dit recept.'});
-//	$("#st_letter").jqxTooltip({ content: 'De bierstijl letter voor dit recept.'});
-//	$("#st_guide").jqxTooltip({ content: 'De bierstijl gids voor dit recept.'});
-//	$("#st_category").jqxTooltip({ content: 'De Amerikaanse bierstijl categorie.'});
-//	$("#st_category_number").jqxTooltip({ content: 'De Amerikaanse bierstijl categorie sub nummer.'});
-//	$("#st_type").jqxTooltip({ content: 'Het bierstijl type.'});
+	$("#st_name").jqxTooltip({ content: 'De bierstijl naam voor dit recept.'});
+	$("#st_letter").jqxTooltip({ content: 'De bierstijl letter voor dit recept.'});
+	$("#st_guide").jqxTooltip({ content: 'De bierstijl gids voor dit recept.'});
+	$("#st_category").jqxTooltip({ content: 'De Amerikaanse bierstijl categorie.'});
+	$("#st_category_number").jqxTooltip({ content: 'De Amerikaanse bierstijl categorie sub nummer.'});
+	$("#st_type").jqxTooltip({ content: 'Het bierstijl type.'});
 	$("#st_og_min").jqxTooltip({ content: 'Het minimum begin SG voor deze bierstijl.'});
 	$("#st_og_max").jqxTooltip({ content: 'Het maximum begin SG voor deze bierstijl.'});
 	$("#st_fg_min").jqxTooltip({ content: 'Het minimum eind SG voor deze bierstijl.'});
@@ -718,12 +831,9 @@
 			$("#st_carb_max").val(dataRecord.st_carb_max);
 			$("#type").val(dataRecord.type);
 			$("#batch_size").val(dataRecord.batch_size);
-			old_batch_size = dataRecord.batch_size;
 			$("#boil_size").val(dataRecord.boil_size);
 			$("#boil_time").val(dataRecord.boil_time);
-			old_boil_time = dataRecord.boil_time;
 			$("#efficiency").val(dataRecord.efficiency);
-			old_efficiency = dataRecord.efficiency;
 			$("#est_og").val(dataRecord.est_og);
 			$("#est_og2").val(dataRecord.est_og);
 			$("#est_fg").val(dataRecord.est_fg);
@@ -1690,7 +1800,7 @@
                                 });
                         },
                         ready: function() {
-//                                calcSVG();
+                                calcSVG();
                                 $('#jqxTabs').jqxTabs('next');
                         },
                         columns: [
@@ -1903,7 +2013,7 @@
 	$("#code").jqxInput({ theme: theme, width: 100, height: 23 });
 	$("#birth").jqxDateTimeInput({ theme: theme, width: 150, height: 23, formatString: 'yyyy-MM-dd' });
 	$("#stage").jqxInput({ theme: theme, width: 100, height: 23 });
-	$("#notes").jqxInput({ theme: theme, width: 960, height: 200 });
+	$("#notes").jqxInput({ theme: theme, width: 960, height: 100 });
 	$("#log_brew").jqxCheckBox({ theme: theme, width: 120, height: 23, disabled : true });
 	$("#log_fermentation").jqxCheckBox({ theme: theme, width: 120, height: 23, disabled : true });
 	$("#inventory_reduced").jqxCheckBox({ theme: theme, width: 120, height: 23 });
@@ -1936,7 +2046,7 @@
 	$("#eq_boil_time").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 0 });
 	$("#eq_top_up_kettle").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
 	$("#eq_hop_utilization").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 0 });
-	$("#eq_notes").jqxInput({ theme: theme, width: 800, height: 100 });
+	$("#eq_notes").jqxInput({ theme: theme, width: 960, height: 200 });
 	$("#eq_lauter_volume").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
 	$("#eq_lauter_deadspace").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
 	$("#eq_kettle_volume").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
@@ -1981,11 +2091,18 @@
 	// Packaging
 	// Tasting
 
+	$("#st_name").jqxInput({ theme: theme, width: 250, height: 23 });
+	$("#st_letter").jqxInput({ theme: theme, width: 100, height: 23 });
+	$("#st_guide").jqxInput({ theme: theme, width: 250, height: 23 });
+	$("#st_category").jqxInput({ theme: theme, width: 250, height: 23 });
+	$("#st_category_number").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true });
+	$("#st_type").jqxInput({ theme: theme, width: 90, height: 23 });
+	$("#type").jqxDropDownList({ theme: theme, source: srcType, width: 125, height: 23, dropDownHeight: 95 });
 	$("#batch_size").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 4, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: 'L', symbolPosition: 'right' });
 	$("#boil_size").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 100, height: 23, decimalDigits: 2, readOnly: true, symbol: 'L', symbolPosition: 'right' });
 	$("#boil_time").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 4, max: 360, decimalDigits: 0, spinButtons: true });
 	$("#efficiency").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 40, max: 100, decimalDigits: 0, spinButtons: true, symbol: '%', symbolPosition: 'right'  });
-	$("#est_og").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 3 });
+	$("#est_og").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 1.000, max: 1.200, decimalDigits: 3, spinButtons: true, spinButtonsStep: 0.001 });
 	$("#est_og2").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 100, height: 23, decimalDigits: 3, readOnly: true });
 	$("#st_og_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
 	$("#st_og_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
@@ -2185,6 +2302,13 @@
 	});
 
 	// Buttons below
+	$("#Print").jqxButton({ template: "info", width: '80px', theme: theme });
+	$("#Print").click(function () {
+		// Open print in a new tab.
+		var url="prod_print.php?record=" + my_record;
+		window.open(url);
+	});
+
 	$("#Delete").jqxButton({ template: "danger", width: '80px', theme: theme });
 	$("#Delete").click(function () {
 		// Open a popup to confirm this action.
@@ -2256,12 +2380,12 @@
 			eq_mash_volume: parseFloat($("#eq_mash_volume").jqxNumberInput('decimal')),
 			eq_mash_max: parseFloat($("#eq_mash_max").jqxNumberInput('decimal')),
 			eq_efficiency: parseFloat($("#eq_efficiency").jqxNumberInput('decimal')),
-	//		st_name: $('#st_name').val(),
-	//		st_letter: $('#st_letter').val(),
-	//		st_guide: $('#st_guide').val(),
-	//		st_type: $('#st_type').val(),
-	//		st_category: $('#st_category').val(),
-	//		st_category_number: parseFloat($("#st_category_number").jqxNumberInput('decimal')),
+			st_name: $('#st_name').val(),
+			st_letter: $('#st_letter').val(),
+			st_guide: $('#st_guide').val(),
+			st_type: $('#st_type').val(),
+			st_category: $('#st_category').val(),
+			st_category_number: parseFloat($("#st_category_number").jqxNumberInput('decimal')),
 			st_og_min: parseFloat($("#st_og_min").jqxNumberInput('decimal')),
 			st_og_max: parseFloat($("#st_og_max").jqxNumberInput('decimal')),
 			st_fg_min: parseFloat($("#st_fg_min").jqxNumberInput('decimal')),
--- a/www/prod_edit.php	Mon Dec 24 23:10:52 2018 +0100
+++ b/www/prod_edit.php	Tue Dec 25 13:42:36 2018 +0100
@@ -65,6 +65,31 @@
         <td style="padding: 3px;"><div id="boil_size"></div></td>
        </tr>
        <tr>
+        <td colspan="6"><hr></td>
+       </tr>
+       <tr>
+        <td></td>
+        <th>Bierstijl gegevens</th>
+        <td></td>
+        <td align="left" colspan="3"><div id="styleSelect">Stylenlijst</div></td>
+       </tr>
+       <tr>
+        <td style="vertical-align: top; float: right; padding: 3px;">Stijlgids:</td>
+        <td align="left" style="vertical-align: top; padding: 3px;"><input readonly="1" id="st_guide" /></td>
+        <td style="vertical-align: top; float: right; padding: 3px;">Bier stijl:</td>
+        <td align="left" style="vertical-align: top; padding: 3px;"><input readonly="1" id="st_name" /></td>
+        <td style="vertical-align: top; float: right; padding: 3px;">Bier groep:</td>
+        <td align="left" style="vertical-align: top; padding: 3px;"><input readonly="1" id="st_letter" /></td>
+       </tr>
+       <tr>
+        <td style="vertical-align: top; float: right; padding: 3px;">Stijl type:</td>
+        <td align="left" style="vertical-align: top; padding: 3px;"><input readonly="1"  id="st_type" /></td>
+        <td style="vertical-align: top; float: right; padding: 3px;">Categorie:</td>
+        <td align="left" style="vertical-align: top; padding: 3px;"><input readonly="1" id="st_category" /></td>
+        <td style="vertical-align: top; float: right; padding: 3px;">Categorie nr:</td>
+        <td style="padding: 3px;"><div id="st_category_number"></div></td>
+       </tr>
+       <tr>
         <td style="vertical-align: top; float: right; padding: 3px;">Start SG:</td>
         <td style="padding: 3px;"><div style="float: left;" id="est_og"></div><div style="float: left; margin-left: 15px;" id="st_og_min"></div><div style="float: left; margin-left: 5px;" id="st_og_max"></div></td>
         <td style="vertical-align: top; float: right; padding: 3px;">Eind SG:</td>
@@ -89,10 +114,11 @@
         <td></td>
        </tr>
       </table>
-      <div style="float: right; margin-top: 30px; margin-bottom: 10px;">
+      <div style="float: right; margin-top: 20px; margin-bottom: 5px;">
+       <input style="margin-right: 100px;" type="button" id="Print"  value="Print" />
        <input style="margin-right: 100px;" type="button" id="Delete" value="Delete" />
        <input style="margin-right: 100px;" type="button" id="Save"   value="Save" />
-       <input style="margin-right: 410px;" type="button" id="Cancel" value="Cancel" />
+       <input style="margin-right: 320px;" type="button" id="Cancel" value="Cancel" />
       </div>
      </div>
      <div id="hintBase" class="hint">

mercurial