www/js/prod_edit.js

changeset 133
22d28dd9c041
parent 123
b4aaf52941e9
child 149
ff45488d480e
--- a/www/js/prod_edit.js	Sat Dec 08 17:30:09 2018 +0100
+++ b/www/js/prod_edit.js	Sun Dec 09 17:29:51 2018 +0100
@@ -90,6 +90,66 @@
 		$('#est_color').val(kw_to_ebc(dataRecord.color_method, colorw));
 	};
 
+	function calcFermentablesFromOG(OG) {
+
+		console.log("calcFermentablesFromOG("+OG+")");
+		var     i, j, sug, d, tot, totmass;
+		var     vol, vol1, vol2, sug2;
+		var     mass1, mass2, efficiency;
+
+		for (j = 1; j < 15; j++) {      // Maybe needed if there is equipment, not here.
+			vol = 0;
+			sug2 = 0;
+			efficiency = parseFloat($("#efficiency").jqxNumberInput('decimal'));
+			var rows = $('#fermentableGrid').jqxGrid('getrows');
+			for (i = 0; i < rows.length; i++) {
+				row = rows[i];
+				if ((row.f_added == "Fermentation") || (row.f_added == "Lagering") || (row.f_added == "Bottle")) {
+					var x = (row.f_yield / 100) * (1 - row.f_moisture / 100);
+					vol += row.f_amount / (x * sugardensity + (1 - x) * 1);
+					sug2 += row.f_amount * x;
+				}
+			}
+	//              if FEquipment <> NIL then               /* Use this for prod_edit.js
+	//              begin
+	//              	sug:= SGToPlato(OG) * OG / 100; //kg/l
+	//              	vol1:= FBatchSize.Value - FEquipment.TrubChillerLoss.Value;
+	//              	vol2:= vol1 + FEquipment.TopUpWater.Value + vol;
+	//              	sug:= sug * vol2; //kg in het gistvat
+	//              	sug:= sug - sug2; //kg voor toevoeging in gistvat
+	//              	if vol1 > 0 then
+	//              		sug:= sug * FBatchSize.Value / vol1; //kg in kookketel
+	//              	sug:= sug + sug2;
+	//              end
+	//              else
+				sug = sg_to_plato(OG) * parseFloat($("#batch_size").jqxNumberInput('decimal')) * OG / 100;      //total amount of sugars in kg
+
+			tot = 0;
+			d = 0;
+			for (i = 0; i < rows.length; i++) {
+				row = rows[i];
+				d = row.f_percentage / 100 * (row.f_yield / 100) * (1 - row.f_moisture / 100);
+				if (row.f_added == "Mash")
+					d = efficiency / 100 * d;
+				tot += d;
+			}
+			if (tot)
+				totmass = sug / tot;
+			else
+				totmass = 0;
+
+			if (totmass) {
+				console.log("pass:"+j+" totmass:"+totmass);
+				for (i = 0; i < rows.length; i++) {
+					row = rows[i];
+					row.f_amount = row.f_percentage / 100 * totmass;
+					$("#fermentableGrid").jqxGrid('setcellvalue', i, "f_amount", row.f_percentage / 100 * totmass);
+				}
+			}
+		};
+		//CalcWaterBalance;
+	};
+
 	function calcIBUs() {
 		var total_ibus = 0;
 		for (var i = 0; i < dataRecord.hops.length; i++) {

mercurial