Added fermentable added value 5 for kegs. Ignore bottle and kegs sugars when calculating fermentables. Better rounding of results when manipulating fermentables in the recipe.

Wed, 12 Jun 2019 16:41:38 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 12 Jun 2019 16:41:38 +0200
changeset 406
0ad967f2d6ee
parent 405
ef3f0274a1ea
child 407
9281bbbf26a6

Added fermentable added value 5 for kegs. Ignore bottle and kegs sugars when calculating fermentables. Better rounding of results when manipulating fermentables in the recipe.

README.design file | annotate | diff | comparison | revisions
www/js/global.js file | annotate | diff | comparison | revisions
www/js/prod_edit.js file | annotate | diff | comparison | revisions
www/js/rec_edit.js file | annotate | diff | comparison | revisions
--- a/README.design	Mon Jun 10 20:04:12 2019 +0200
+++ b/README.design	Wed Jun 12 16:41:38 2019 +0200
@@ -20,3 +20,19 @@
 
 Koolzuurdruk tabel inbouwen.
 
+Bottelsuiker:
+
+select name,type,yield,moisture from inventory_fermentables where type = 1 or type = 3;
+
+Dit geeft de suikers en droge malt extracten. Hieruit is ook de opbrengst te berekenen
+om de juiste hoeveelheid te bepalen. 
+De PrimingSugarSource kan vervallen zodra alle bottelsuikers in de database verwerkt
+zijn. Hiervoor een script maken om deze suikers als fermentable in het recept te zetten
+met  'added = 4'. 
+Toevoegen added = 5, voor kegs.
+In products vervallen de velden bottle_priming_sugar, bottle_priming_amount,
+keg_priming_sugar en keg_priming_amount. Deze waardes komen uit fermentables.
+Let op, de amount waardes zijn g/l dus omrekenen.
+Ook aanpassen de recept suikerstort, de added 4 of 5 niet meenemen.
+
+
--- a/www/js/global.js	Mon Jun 10 20:04:12 2019 +0200
+++ b/www/js/global.js	Wed Jun 12 16:41:38 2019 +0200
@@ -92,7 +92,8 @@
 	{ id: 1, en: 'Boil', nl: 'Koken' },
 	{ id: 2, en: 'Fermentation', nl: 'Vergisten' },
 	{ id: 3, en: 'Lagering', nl: 'Nagisten/lageren' },
-	{ id: 4, en: 'Bottle', nl: 'Bottelen' }
+	{ id: 4, en: 'Bottle', nl: 'Bottelen' },
+	{ id: 5, en: 'Kegs', nl: 'Fust' }
 ];
 var AddedSource = {
 	localdata: AddedData,
--- a/www/js/prod_edit.js	Mon Jun 10 20:04:12 2019 +0200
+++ b/www/js/prod_edit.js	Wed Jun 12 16:41:38 2019 +0200
@@ -122,6 +122,32 @@
                         $("#ok_supplies").html("<img src='images/dialog-error.png'>");
 	}
 
+	function calcPercentages() {
+
+		console.log("calcPercentages()");
+		var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
+		if (rowscount > 1) {
+			var tw = 0;
+			for (i = 0; i < rowscount; i++) {
+				var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
+				if (rowdata.f_added < 4)
+					tw += Math.round(rowdata.f_amount * 1000) / 1000;
+			};
+			tw = Math.round(tw * 1000) / 1000;
+
+			for (i = 0; i < rowscount; i++) {
+				var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
+				if (rowdata.f_added < 4) {
+					var percentage = Math.round(rowdata.f_amount / tw * 1000) / 10.0;
+					$("#fermentableGrid").jqxGrid('setcellvalue', i, "f_percentage", percentage);
+				} else {
+					$("#fermentableGrid").jqxGrid('setcellvalue', i, "f_percentage", 0);
+				}
+			};
+		} else {
+			$("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100);
+		}
+	}
 
 	/*
 	 * All calculations that depend on changes in the fermentables,
@@ -172,9 +198,9 @@
                         var row = rows[i];
                         if (row.f_adjust_to_total_100)
                                 my_100 = true;
-			if (row.f_type == 1)	// Sugar
+			if (row.f_type == 1 && row.f_added < 4)	// Sugar
 				psugar += row.f_percentage;
-			if (row.f_graintype == 2)	// Crystal
+			if (row.f_graintype == 2 && row.f_added < 4)	// Crystal
 				pcara += row.f_percentage;
 			var d = row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
 			if (row.f_added == 0) {	// Mash
@@ -188,20 +214,23 @@
 			}
 			if (row.f_added == 0 || row.f_added == 1)	// Mash or Boil
 				sugarsf += d;
-			if (row.f_added == 2 || row.f_added == 3) {
+			if (row.f_added == 2 || row.f_added == 3) {	// Fermentation or lagering
 				var x = (row.f_yield / 100) * (1 - row.f_moisture / 100);
 				addedS += row.f_amount * x;
 				addedmass += row.f_amount;
 				vol += (x * sugardensity + (1 - x) * 1) * row.f_amount;
 			}
-			colort += row.f_amount * ebc_to_srm(row.f_color);
-			colorh += row.f_amount * row.f_color * get_kt(row.f_color);
-			colorn += (row.f_percentage / 100) * row.f_color;	// For 8.6 Pt wort.
+			if (row.f_added < 4) {
+				colort += row.f_amount * ebc_to_srm(row.f_color);
+				colorh += row.f_amount * row.f_color * get_kt(row.f_color);
+				colorn += (row.f_percentage / 100) * row.f_color;	// For 8.6 Pt wort.
+			}
 			// Check supplies.
 			if ((((dataRecord.inventory_reduced <= 2) && (row.f_added <= 1)) ||  // Mash or boil
                              ((dataRecord.inventory_reduced <= 3) && (row.f_added == 2)) ||  // Primary
                              ((dataRecord.inventory_reduced <= 5) && (row.f_added == 3)) ||  // Secondary or Tertiary
-		    	     ((dataRecord.inventory_reduced <= 6) && (row.f_added == 4))) && row.f_inventory < row.f_amount) {
+		    	     ((dataRecord.inventory_reduced <= 6) && (row.f_added == 4)) ||  // Bottle
+			     ((dataRecord.inventory_reduced <= 6) && (row.f_added == 5))) && row.f_inventory < row.f_amount) {
 				ok_fermentables = 0;
 			}
 			if (row.f_added == 0 && (row.f_type == 0 || row.f_type == 4) && row.f_color < 50) { // Mash and Grain/Adjunct and Color < 50
@@ -393,20 +422,24 @@
 
 		for (var i = 0; i < rowscount; i++) {
 			var row = $("#fermentableGrid").jqxGrid('getrowdata', i);
-			var d = row.f_percentage / 100 * (row.f_yield / 100) * (1 - row.f_moisture / 100);
-			if (row.f_added == 0)	// Mash
-				d = efficiency / 100 * d;
-			tot += d;
+			if (row.f_added < 4) {
+				var d = row.f_percentage / 100 * (row.f_yield / 100) * (1 - row.f_moisture / 100);
+				if (row.f_added == 0)	// Mash
+					d = efficiency / 100 * d;
+				tot += d;
+			}
 		}
 		var totmass = 0;
 		if (tot)
-			totmass = sug / tot;
+			totmass = Math.round((sug / tot) * 1000) / 1000;
 
 		if (totmass) {
 			for (i = 0; i < rowscount; i++) {
 				var row = $("#fermentableGrid").jqxGrid('getrowdata', i);
-				var amount = row.f_percentage / 100 * totmass;
-				$("#fermentableGrid").jqxGrid('setcellvalue', i, "f_amount", amount);
+				if (row.f_added < 4) {
+					var amount = Math.round(row.f_percentage * 10 * totmass) / 1000;
+					$("#fermentableGrid").jqxGrid('setcellvalue', i, "f_amount", amount);
+				}
 			}
 		}
 	};
@@ -3190,15 +3223,15 @@
 				{ name: 'f_avail', type: 'int' }
                         ],
                         addrow: function (rowid, rowdata, position, commit) {
-				console.log("fermentable addrow "+rowid);
+				//console.log("fermentable addrow "+rowid);
                                 commit(true);
                         },
                         deleterow: function (rowid, commit) {
-				console.log("fermentable deleterow "+rowid);
+				//console.log("fermentable deleterow "+rowid);
                                 commit(true);
                         },
 			updaterow: function (rowid, rowdata, commit) {
-				console.log("fermentable updaterow "+rowid);
+				//console.log("fermentable updaterow "+rowid);
 				commit(true);
 			}
                 };
@@ -3308,16 +3341,7 @@
                                                                 }
                                                         }
                                                 } else {
-                                                        var tw = 0;
-                                                        for (i = 0; i < rowscount; i++) {
-                                                                var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
-                                                                tw += rowdata.f_amount;
-                                                        };
-                                                        for (i = 0; i < rowscount; i++) {
-                                                                var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
-                                                                var percentage = Math.round(rowdata.f_amount / tw * 1000) / 10.0;
-                                                                $("#fermentableGrid").jqxGrid('setcellvalue', i, "f_percentage", percentage);
-                                                        };
+							calcPercentages();
                                                 }
                                         } else {
                                                 $("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100);
@@ -3356,7 +3380,8 @@
 					if (((dataRecord.inventory_reduced <= 2) && (rowdata.f_added <= 1)) ||	// Mash or boil
 					    ((dataRecord.inventory_reduced <= 3) && (rowdata.f_added == 2)) ||	// Primary
 					    ((dataRecord.inventory_reduced <= 5) && (rowdata.f_added == 3)) ||	// Secondary or Tertiary
-					    ((dataRecord.inventory_reduced <= 6) && (rowdata.f_added == 4))) {	// Bottle
+					    ((dataRecord.inventory_reduced <= 6) && (rowdata.f_added == 4)) ||	// Bottle
+					    ((dataRecord.inventory_reduced <= 6) && (rowdata.f_added == 5))) {	// Kegs
 						if (value < rowdata.f_amount)
 							color = '#ff4040';
 						return  '<span style="margin: 4px; margin-top: 6px; float: right; color: ' +
@@ -3379,11 +3404,13 @@
 				{ text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', cellsrenderer: function () {
 					return "Wijzig";
 					}, buttonclick: function (row) {
+						fermentableRow = row;
+						fermentableData = $("#fermentableGrid").jqxGrid('getrowdata', fermentableRow);
 						if (dataRecord.stage > 3) {
 							alert("Ingredieënt is al verwerkt.");
+						} else if (fermentableData.f_added >= 4) {
+							alert("Wijzig dit in de Verpakken tab");
 						} else {
-							fermentableRow = row;
-							fermentableData = $("#fermentableGrid").jqxGrid('getrowdata', fermentableRow);
 							$("#wf_name").val(fermentableData.f_name);
 							$("#wf_amount").val(fermentableData.f_amount);
 							$("#wf_percentage").val(fermentableData.f_percentage);
@@ -4460,7 +4487,7 @@
 			f_avail: fermentableData.f_avail
 		};
 		$("#fermentableGrid").jqxGrid('updaterow', rowID, row);
-		// Recalc percentages
+		calcPercentages();
 		calcFermentables();
 		calcIBUs();
 		calcMash();
@@ -4518,25 +4545,7 @@
 		$("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_amount', event.args.value);
 		fermentableData.f_amount = event.args.value;
 		if (! to_100) {
-			// Recalculate percentages
-			console.log("adjust percentages");
-			var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
-			if (rowscount > 1) {
-				var tw = 0;
-				for (i = 0; i < rowscount; i++) {
-					var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
-					tw += rowdata.f_amount;
-				};
-				for (i = 0; i < rowscount; i++) {
-					var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
-					var percentage = Math.round(rowdata.f_amount / tw * 1000) / 10.0;
-					$("#fermentableGrid").jqxGrid('setcellvalue', i, "f_percentage", percentage);
-		//                      if (i == fermentableRow) // Will crash the script.
-		//                              $("#wf_percentage").val(percentage);
-				};
-			} else {
-				$("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100);
-			}
+			calcPercentages();
 			calcFermentables();
 			calcIBUs();
 			calcMash();
@@ -4558,13 +4567,15 @@
 				var tw = 0;     // total weight
 				for (i = 0; i < rowscount; i++) {
 					var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
-					tw += rowdata.f_amount;
+					if (rowdata.f_added < 4)
+						tw += Math.round(rowdata.f_amount * 1000) / 1000;
 				}
+				tw = Math.round(tw * 1000) / 1000;
 				if (to_100) {
 					// Adjust this row and the 100% row.
-					var damount = tw * diff / 100;
+					var damount = Math.round(tw * diff *10) / 1000;
 					var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', fermentableRow);
-					var namount = rowdata.f_amount + damount;
+					var namount = Math.round((rowdata.f_amount + damount) * 1000) / 1000;
 					$("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_amount', namount);
 					$("#wf_amount").val(namount);
 					$("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_percentage', rowdata.f_percentage + diff);
@@ -4584,16 +4595,20 @@
 					var nw = tw * diff / 100;
 					for (i = 0; i < rowscount; i++) {
 						var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
-						if (i == fermentableRow) {
-							var namount = rowdata.f_amount + nw;
-							$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', namount);
-		//                                      $("#wf_amount").val(namount); // Will crash the script.
-							$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', newvalue);
+						if (rowdata.f_added < 4) {
+							if (i == fermentableRow) {
+								var namount = Math.round((rowdata.f_amount + nw) * 1000) / 1000;
+								$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', namount);
+		//                                      	$("#wf_amount").val(namount); // Will crash the script.
+								$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', newvalue);
+							} else {
+								var namount = Math.round((rowdata.f_amount - (nw / (rowscount - 1))) * 1000) / 1000;
+								var newperc = Math.round((namount / tw) * 1000) / 10.0;
+								$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', namount);
+								$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', newperc);
+							}
 						} else {
-							var namount = rowdata.f_amount - (nw / (rowscount - 1));
-							var newperc = Math.round((namount / tw) * 1000) / 10.0;
-							$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', namount);
-							$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', newperc);
+							$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', 0);
 						}
 					}
 					calcFermentables();
--- a/www/js/rec_edit.js	Mon Jun 10 20:04:12 2019 +0200
+++ b/www/js/rec_edit.js	Wed Jun 12 16:41:38 2019 +0200
@@ -157,6 +157,33 @@
 		$("#sparge_acid_perc").jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
 	};
 
+	function calcPercentages() {
+
+		console.log("calcPercentages()");
+		var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
+		if (rowscount > 1) {
+			var tw = 0;
+			for (i = 0; i < rowscount; i++) {
+				var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
+				if (rowdata.f_added < 4)
+					tw += Math.round(rowdata.f_amount * 1000) / 1000;
+			};
+			tw = Math.round(tw * 1000) / 1000;
+
+			for (i = 0; i < rowscount; i++) {
+				var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
+				if (rowdata.f_added < 4) {
+					var percentage = Math.round(rowdata.f_amount / tw * 1000) / 10.0;
+					$("#fermentableGrid").jqxGrid('setcellvalue', i, "f_percentage", percentage);
+				} else {
+					$("#fermentableGrid").jqxGrid('setcellvalue', i, "f_percentage", 0);
+				}
+			};
+		} else {
+			$("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100);
+		}
+	}
+
 	function calcFermentables() {
 		console.log("calcFermentables()");
 		sugarsf = 0;		// fermentable sugars mash + boil
@@ -200,9 +227,9 @@
 			var row = rows[i];
 			if (row.f_adjust_to_total_100)
 				my_100 = true;
-			if (row.f_type == 1)		// Sugar
+			if (row.f_type == 1 && row.f_added < 4)		// Sugar
 				psugar += row.f_percentage;
-			if (row.f_graintype == 2)	// Crystal
+			if (row.f_graintype == 2 && row.f_added < 4)	// Crystal
 				pcara += row.f_percentage;
 			var d = row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
 			if (row.f_added == 0) {		// Mash
@@ -216,7 +243,7 @@
 			}
 			if (row.f_added == 0 || row.f_added == 1)	// Mash or Boil
 				sugarsf += d;
-			if (row.f_added == 2 || row.f_added == 3) {
+			if (row.f_added == 2 || row.f_added == 3) {	// Fermentation or lagering
 				var x = (row.f_yield / 100) * (1 - row.f_moisture / 100);
 				addedS += row.f_amount * x;
 				addedmass += row.f_amount;
@@ -225,9 +252,11 @@
 			if (row.f_added == 0 && (row.f_type == 0 || row.f_type == 4) && row.f_color < 50) { // Mash and Grain/Adjunct and Color < 50
 				lintner += row.f_diastatic_power * row.f_amount;
 			}
-			colort += row.f_amount * ebc_to_srm(row.f_color);
-			colorh += row.f_amount * row.f_color * get_kt(row.f_color);
-			colorn += (row.f_percentage / 100) * row.f_color;	// For 8.6 Pt wort.
+			if (row.f_added < 4) {
+				colort += row.f_amount * ebc_to_srm(row.f_color);
+				colorh += row.f_amount * row.f_color * get_kt(row.f_color);
+				colorn += (row.f_percentage / 100) * row.f_color;	// For 8.6 Pt wort.
+			}
 		}
 		$("#ferm_lintner").val(Math.round(parseFloat(lintner / mashkg)));
 		console.log("lintner:"+lintner+" kg:"+mashkg);
@@ -1196,20 +1225,24 @@
 
 		for (var i = 0; i < rowscount; i++) {
 			var row = $("#fermentableGrid").jqxGrid('getrowdata', i);
-			var d = row.f_percentage / 100 * (row.f_yield / 100) * (1 - row.f_moisture / 100);
-			if (row.f_added == 0)	// Mash
-				d = efficiency / 100 * d;
-			tot += d;
+			if (row.f_added < 4) {
+				var d = row.f_percentage / 100 * (row.f_yield / 100) * (1 - row.f_moisture / 100);
+				if (row.f_added == 0)	// Mash
+					d = efficiency / 100 * d;
+				tot += d;
+			}
 		}
 		var	totmass = 0;
 		if (tot)
-			totmass = sug / tot;
+			totmass = Math.round((sug / tot) * 1000) / 1000;
 
 		if (totmass) {
 			for (i = 0; i < rowscount; i++) {
 				var row = $("#fermentableGrid").jqxGrid('getrowdata', i);
-				var amount = row.f_percentage / 100 * totmass;
-				$("#fermentableGrid").jqxGrid('setcellvalue', i, "f_amount", amount);
+				if (row.f_added < 4) {
+					var amount = Math.round(row.f_percentage * 10 * totmass) / 1000;
+					$("#fermentableGrid").jqxGrid('setcellvalue', i, "f_amount", amount);
+				}
 			}
 		}
 	};
@@ -1809,15 +1842,15 @@
 				{ name: 'f_avail', type: 'int' }
 			],
 			addrow: function (rowid, rowdata, position, commit) {
-				console.log("fermentable addrow "+rowid);
+				//console.log("fermentable addrow "+rowid);
 				commit(true);
 			},
 			deleterow: function (rowid, commit) {
-				console.log("fermentable deleterow "+rowid);
+				//console.log("fermentable deleterow "+rowid);
 				commit(true);
 			},
 			updaterow: function (rowid, rowdata, commit) {
-				console.log("fermentable updaterow "+rowid);
+				//console.log("fermentable updaterow "+rowid);
 				commit(true);
 			}
 		};
@@ -1926,16 +1959,7 @@
 								}
 							}
 						} else {
-							var tw = 0;
-							for (i = 0; i < rowscount; i++) {
-								var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
-								tw += rowdata.f_amount;
-							};
-							for (i = 0; i < rowscount; i++) {
-								var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
-								var percentage = Math.round(rowdata.f_amount / tw * 1000) / 10.0;
-								$("#fermentableGrid").jqxGrid('setcellvalue', i, "f_percentage", percentage);
-							};
+							calcPercentages();
 						}
 					} else {
 						$("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100);
@@ -2965,7 +2989,7 @@
 			f_avail: fermentableData.f_avail
 		};
 		$("#fermentableGrid").jqxGrid('updaterow', rowID, row);
-		// Recalc percentages
+		calcPercentages();
 		calcFermentables();
 		calcIBUs();
 		calcMash();
@@ -3023,25 +3047,7 @@
 		$("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_amount', event.args.value);
 		fermentableData.f_amount = event.args.value;
 		if (! to_100) {
-			// Recalculate percentages
-			console.log("adjust percentages");
-			var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
-			if (rowscount > 1) {
-				var tw = 0;
-				for (i = 0; i < rowscount; i++) {
-					var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
-					tw += rowdata.f_amount;
-				};
-				for (i = 0; i < rowscount; i++) {
-					var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
-					var percentage = Math.round(rowdata.f_amount / tw * 1000) / 10.0;
-					$("#fermentableGrid").jqxGrid('setcellvalue', i, "f_percentage", percentage);
-		//			if (i == fermentableRow) // Will crash the script.
-		//				$("#wf_percentage").val(percentage);
-				};
-			} else {
-				$("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100);
-			}
+			calcPercentages();
 			calcFermentables();
 			calcMash();
 		};
@@ -3062,13 +3068,15 @@
 				var tw = 0;     // total weight
 				for (i = 0; i < rowscount; i++) {
 					var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
-					tw += rowdata.f_amount;
+					if (rowdata.f_added < 4)
+						tw += Math.round(rowdata.f_amount * 1000) / 1000;
 				}
+				tw = Math.round(tw * 1000) / 1000;
 				if (to_100) {
 					// Adjust this row and the 100% row.
-					var damount = tw * diff / 100;
+					var damount = Math.round(tw * diff *10) / 1000;
 					var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', fermentableRow);
-					var namount = rowdata.f_amount + damount;
+					var namount = Math.round((rowdata.f_amount + damount) * 1000) / 1000;					
 					$("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_amount', namount);
 					$("#wf_amount").val(namount);
 					$("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_percentage', rowdata.f_percentage + diff);
@@ -3087,16 +3095,20 @@
 					var nw = tw * diff / 100;
 					for (i = 0; i < rowscount; i++) {
 						var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
-						if (i == fermentableRow) {
-							var namount = rowdata.f_amount + nw;
-							$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', namount);
-		//					$("#wf_amount").val(namount); // Will crash the script.
-							$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', newvalue);
+						if (rowdata.f_added < 4) {
+							if (i == fermentableRow) {
+								var namount = Math.round((rowdata.f_amount + nw) * 1000) / 1000;
+								$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', namount);
+		//						$("#wf_amount").val(namount); // Will crash the script.
+								$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', newvalue);
+							} else {
+								var namount = Math.round((rowdata.f_amount - (nw / (rowscount - 1))) * 1000) / 1000;
+								var newperc = Math.round((namount / tw) * 1000) / 10.0;
+								$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', namount);
+								$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', newperc);
+							}
 						} else {
-							var namount = rowdata.f_amount - (nw / (rowscount - 1));
-							var newperc = Math.round((namount / tw) * 1000) / 10.0;
-							$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', namount);
-							$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', newperc);
+							$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', 0);
 						}
 					}
 					calcFermentables();

mercurial