# HG changeset patch # User Michiel Broek # Date 1560454097 -7200 # Node ID 9281bbbf26a6fcb92005c178a0abdcb0538f8327 # Parent 0ad967f2d6eecd46f589100f96cfc31709a9f3e6 Added fermentablesugars dropdown table. The calcCarbonation function now works with the new dropdown lists. Selecting a priming sugar adds or updates the sugar in the fermentables table. diff -r 0ad967f2d6ee -r 9281bbbf26a6 README.design --- a/README.design Wed Jun 12 16:41:38 2019 +0200 +++ b/README.design Thu Jun 13 21:28:17 2019 +0200 @@ -22,17 +22,18 @@ Bottelsuiker: -select name,type,yield,moisture from inventory_fermentables where type = 1 or type = 3; +x 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. +x 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. +x Hiervoor een script maken om deze suikers als fermentable in het recept te zetten + met 'added = 4'. +x 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. +x Let op, de amount waardes zijn g/l dus omrekenen. +x Ook aanpassen de recept suikerstort, de added 4 of 5 niet meenemen. diff -r 0ad967f2d6ee -r 9281bbbf26a6 www/js/global.js --- a/www/js/global.js Wed Jun 12 16:41:38 2019 +0200 +++ b/www/js/global.js Thu Jun 13 21:28:17 2019 +0200 @@ -524,7 +524,21 @@ return data; }, loadError: function(jqXHR, status, error) { - $('#err').text(status + ' ' + error); + console.log(status + ' ' + error); + }, +}); +var fermentablesugars = new $.jqx.dataAdapter(fermentableInvSource, { + beforeLoadComplete: function (records) { + var data = new Array(); + for (var i = 0; i < records.length; i++) { + var row = records[i]; + if (row.type == 1 || row.type == 3) // Sugars or dry extract + data.push(row); + } + return data; + }, + loadError: function(jqXHR, status, error) { + console.log(status + ' ' + error); }, }); @@ -563,7 +577,7 @@ return data; }, loadError: function(jqXHR, status, error) { - $('#err').text(status + ' ' + error); + console.log(status + ' ' + error); }, }); @@ -594,7 +608,7 @@ return data; }, loadError: function(jqXHR, status, error) { - $('#err').text(status + ' ' + error); + console.log(status + ' ' + error); }, }); @@ -631,7 +645,7 @@ return data; }, loadError: function(jqXHR, status, error) { - $('#err').text(status + ' ' + error); + console.log(status + ' ' + error); }, }); @@ -666,7 +680,7 @@ return data; }, loadError: function(jqXHR, status, error) { - $('#err').text(status + ' ' + error); + console.log(status + ' ' + error); }, }); diff -r 0ad967f2d6ee -r 9281bbbf26a6 www/js/prod_edit.js --- a/www/js/prod_edit.js Wed Jun 12 16:41:38 2019 +0200 +++ b/www/js/prod_edit.js Thu Jun 13 21:28:17 2019 +0200 @@ -87,6 +87,7 @@ var fermentableRow = 0; var fermentableData = {}; + var fermentableInit = 1; var hopRow = 0; var hopData = {}; var miscRow = 0; @@ -225,6 +226,16 @@ 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 (fermentableInit) { + if (row.f_added == 4) { + $("#bottle_priming_total").val(row.f_amount * 1000); // Prevent clearing + $("#bottle_priming_sugar").jqxDropDownList('selectItem', row.f_name); + } + if (row.f_added == 5) { + $("#keg_priming_total").val(row.f_amount * 1000); + $("#keg_priming_sugar").jqxDropDownList('selectItem', row.f_name); + } + } // Check supplies. if ((((dataRecord.inventory_reduced <= 2) && (row.f_added <= 1)) || // Mash or boil ((dataRecord.inventory_reduced <= 3) && (row.f_added == 2)) || // Primary @@ -235,13 +246,10 @@ } 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; - // console.log("add "+row.f_name+" diastatic_power:"+row.f_diastatic_power*row.f_amount+" now:"+lintner); - // } else { - // console.log("ign "+row.f_name+" diastatic_power:"+row.f_diastatic_power*row.f_amount+" now:"+lintner); } } + fermentableInit = 0; $("#ferm_lintner").val(Math.round(parseFloat(lintner / mashkg))); - // console.log("lintner:"+lintner+" kg:"+mashkg); $("#mash_kg").val(mashkg); console.log("calcFermentables() supplies:"+ok_fermentables); to_100 = my_100; @@ -1780,13 +1788,11 @@ } function CarbCO2toS(CO2, T, SFactor) { - // Calcuation of disolved CO2 in the beer. - // Brewersfriend uses: 3.0378 - (0.050062 * temp) + (0.00026555 * temp^2) - // Brouwhulp uses: 0.000849151 * T * T - 0.0587512 * T + 1.71137) + // Calculation of disolved CO2 in the beer, brouwhulp. var sugar = SFactor * (CO2 - (0.000849151 * T * T - 0.0587512 * T + 1.71137)) / 0.286; if (sugar < 0) sugar = 0; - return sugar; + return Math.round(sugar * 1000) / 1000; } function CarbCO2ToPressure(CO2, T) { @@ -1804,40 +1810,56 @@ if (TSec < 1) TSec = 18; // Fallback to room temperature. - if (dataRecord.fg == 1.000) + if (dataRecord.fg == 0.000) var ABV = abvol(dataRecord.brew_fermenter_sg, parseFloat($("#est_fg").jqxNumberInput('decimal'))); else var ABV = abvol(dataRecord.brew_fermenter_sg, dataRecord.fg); + ABV = Math.round(ABV * 100) / 100; + + console.log("calcCarbonation() TSec:"+TSec+" ABV:"+ABV); + if (!(rows = $('#fermentableGrid').jqxGrid('getrows'))) { + return; // grid not yet loaded. + } // Bottles - var SFactor = PrimingSugarData[dataRecord.bottle_priming_sugar].factor; - var Amount = CarbCO2toS(dataRecord.bottle_carbonation, TSec, SFactor); - dataRecord.bottle_priming_amount = Amount; + dataRecord.bottle_priming_amount = 0; + dataRecord.bottle_priming_total = 0; + for (var i = 0; i < rows.length; i++) { + var row = rows[i]; + if (row.f_added == 4) { + var SFactor = 1 / ((row.f_yield / 100) * (1 - row.f_moisture / 100)); + dataRecord.bottle_priming_amount = CarbCO2toS(dataRecord.bottle_carbonation, TSec, SFactor); + dataRecord.bottle_priming_total = Math.round(dataRecord.bottle_amount * dataRecord.bottle_priming_amount * 100) / 100; + $("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', dataRecord.bottle_priming_total / 1000); + } + } $("#bottle_priming_amount").val(Math.round(dataRecord.bottle_priming_amount * 10) / 10); - $("#bottle_priming_total").val(Math.round(dataRecord.bottle_amount * dataRecord.bottle_priming_amount * 10) / 10); - $("#bottle_abv").val(Math.round((ABV + Amount * 0.47 / 7.907) * 10) / 10); + $("#bottle_priming_total").val(dataRecord.bottle_priming_total); + $("#bottle_abv").val(Math.round((ABV + dataRecord.bottle_priming_amount * 0.47 / 7.907) * 10) / 10); // Kegs - SFactor = PrimingSugarData[dataRecord.keg_priming_sugar].factor; - Amount = CarbCO2toS(dataRecord.keg_carbonation, TSec, SFactor); var Pressure = CarbCO2ToPressure(dataRecord.keg_carbonation, dataRecord.keg_carbonation_temp); if (Pressure < 0) Pressure = 0; dataRecord.keg_pressure = Pressure; $("#keg_pressure").val(Math.round(Pressure * 10) / 10); - if (dataRecord.keg_forced_carb) { - Amount = 0; - dataRecord.keg_priming_amount = 0; - $("#keg_priming_amount").val(0); - $("#keg_priming_total").val(0); - } else { - dataRecord.keg_priming_amount = Amount; - $("#keg_priming_amount").val(Math.round(dataRecord.keg_priming_amount * 10) / 10); - $("#keg_priming_total").val(Math.round(dataRecord.keg_amount * dataRecord.keg_priming_amount * 10) / 10); + dataRecord.keg_priming_amount = 0; + dataRecord.keg_priming_total = 0; + if (! dataRecord.keg_forced_carb) { + for (var i = 0; i < rows.length; i++) { + var row = rows[i]; + if (row.f_added == 5) { + var SFactor = 1 / ((row.f_yield / 100) * (1 - row.f_moisture / 100)); + dataRecord.keg_priming_amount = CarbCO2toS(dataRecord.keg_carbonation, TSec, SFactor); + dataRecord.keg_priming_total = Math.round(dataRecord.keg_amount * dataRecord.keg_priming_amount * 100) / 100; + $("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', dataRecord.keg_priming_total / 1000); + } + } } - - $("#keg_abv").val(Math.round((ABV + Amount * 0.47 / 7.907) * 10) / 10); + $("#keg_priming_amount").val(Math.round(dataRecord.keg_priming_amount * 10) / 10); + $("#keg_priming_total").val(dataRecord.keg_priming_total); + $("#keg_abv").val(Math.round((ABV + dataRecord.keg_priming_amount * 0.47 / 7.907) * 10) / 10); } function calcStage() { @@ -2340,18 +2362,14 @@ dataRecord.bottle_carbonation = parseFloat(event.args.value); calcCarbonation(); }); + $('#bottle_carbonation_temp').on('change', function (event) { + dataRecord.bottle_carbonation_temp = parseFloat(event.args.value); + calcCarbonation(); + }); $('#keg_carbonation').on('change', function (event) { dataRecord.keg_carbonation = parseFloat(event.args.value); calcCarbonation(); }); - $('#bottle_priming_sugar').on('change', function (event) { - dataRecord.bottle_priming_sugar = event.args.item.value; - calcCarbonation(); - }); - $('#keg_priming_sugar').on('change', function (event) { - dataRecord.keg_priming_sugar = event.args.item.value; - calcCarbonation(); - }); $("#keg_forced_carb").on('checked', function (event) { dataRecord.keg_forced_carb = 1; calcCarbonation(); @@ -2624,12 +2642,12 @@ package_date: $("#package_date").val(), bottle_amount: parseFloat($("#bottle_amount").jqxNumberInput('decimal')), bottle_carbonation: parseFloat($("#bottle_carbonation").jqxNumberInput('decimal')), - bottle_priming_sugar: $("#bottle_priming_sugar").val(), + //bottle_priming_sugar: $("#bottle_priming_sugar").val(), bottle_priming_amount: parseFloat($("#bottle_priming_amount").jqxNumberInput('decimal')), bottle_carbonation_temp: parseFloat($("#bottle_carbonation_temp").jqxNumberInput('decimal')), keg_amount: parseFloat($("#keg_amount").jqxNumberInput('decimal')), keg_carbonation: parseFloat($("#keg_carbonation").jqxNumberInput('decimal')), - keg_priming_sugar: $("#keg_priming_sugar").val(), + //keg_priming_sugar: $("#keg_priming_sugar").val(), keg_priming_amount: parseFloat($("#keg_priming_amount").jqxNumberInput('decimal')), keg_carbonation_temp: parseFloat($("#keg_carbonation_temp").jqxNumberInput('decimal')), keg_forced_carb: dataRecord.keg_forced_carb, @@ -3051,12 +3069,12 @@ $("#package_date").val(dataRecord.package_date); $("#bottle_amount").val(dataRecord.bottle_amount); $("#bottle_carbonation").val(dataRecord.bottle_carbonation); - $("#bottle_priming_sugar").val(dataRecord.bottle_priming_sugar); + //$("#bottle_priming_sugar").val(dataRecord.bottle_priming_sugar); $("#bottle_priming_amount").val(dataRecord.bottle_priming_amount); $("#bottle_carbonation_temp").val(dataRecord.bottle_carbonation_temp); $("#keg_amount").val(dataRecord.keg_amount); $("#keg_carbonation").val(dataRecord.keg_carbonation); - $("#keg_priming_sugar").val(dataRecord.keg_priming_sugar); + //$("#keg_priming_sugar").val(dataRecord.keg_priming_sugar); $("#keg_priming_amount").val(dataRecord.keg_priming_amount); $("#keg_carbonation_temp").val(dataRecord.keg_carbonation_temp); $("#keg_forced_carb").val(dataRecord.keg_forced_carb); @@ -5662,23 +5680,113 @@ $("#keg_carbonation").jqxNumberInput( Spin2dec ); $("#keg_carbonation").jqxNumberInput({ max: 5 }); $("#bottle_priming_sugar").jqxDropDownList({ + placeHolder: "Kies suiker:", theme: theme, - source: PrimingSugarAdapter, - valueMember: 'id', - displayMember: 'nl', - width: 180, + source: fermentablesugars, + displayMember: 'name', + width: 200, height: 23, - autoDropDownHeight: true + dropDownWidth: 300, + dropDownHeight: 400 + }); + $("#bottle_priming_sugar").on('select', function (event) { + if (event.args) { + var index = event.args.index; + var editrow = -1; + var datarecord = fermentablesugars.records[index]; + var rows = $('#fermentableGrid').jqxGrid('getrows'); + for (var i = 0; i < rows.length; i++) { + if (rows[i].f_added == 4) { + editrow = i; + } + } + var row = {}; + row["f_name"] = datarecord.name; + row["f_origin"] = datarecord.origin; + row["f_supplier"] = datarecord.supplier; + row["f_amount"] = parseFloat($("#bottle_priming_total").jqxNumberInput('decimal')) / 1000; + row["f_cost"] = datarecord.cost; + row["f_type"] = datarecord.type; + row["f_yield"] = datarecord.yield; + row["f_color"] = datarecord.color; + row["f_coarse_fine_diff"] = datarecord.coarse_fine_diff; + row["f_moisture"] = datarecord.moisture; + row["f_diastatic_power"] = datarecord.diastatic_power; + row["f_protein"] = datarecord.protein; + row["f_max_in_batch"] = datarecord.max_in_batch; + row["f_graintype"] = datarecord.graintype; + row["f_added"] = 4; + row["f_dissolved_protein"] = datarecord.dissolved_protein; + row["f_recommend_mash"] = datarecord.recommend_mash; + row["f_add_after_boil"] = 1; + row["f_adjust_to_total_100"] = 0; + row["f_percentage"] = 0; + row["f_di_ph"] = datarecord.di_ph; + row["f_acid_to_ph_57"] = datarecord.acid_to_ph_57; + row["f_inventory"] = datarecord.inventory; + if (editrow >= 0) { + var rowID = $('#fermentableGrid').jqxGrid('getrowid', editrow); + $('#fermentableGrid').jqxGrid('updaterow', rowID, row); + } else { + $("#fermentableGrid").jqxGrid('addrow', null, row); + } + calcCarbonation(); + } }); $("#keg_priming_sugar").jqxDropDownList({ + placeHolder: "Kies suiker:", theme: theme, - source: PrimingSugarAdapter, - valueMember: 'id', - displayMember: 'nl', - width: 180, + source: fermentablesugars, + displayMember: 'name', + width: 200, height: 23, - autoDropDownHeight: true + dropDownWidth: 300, + dropDownHeight: 400 }); + $("#keg_priming_sugar").on('select', function (event) { + if (event.args) { + var index = event.args.index; + var editrow = -1; + var datarecord = fermentablesugars.records[index]; + var rows = $('#fermentableGrid').jqxGrid('getrows'); + for (var i = 0; i < rows.length; i++) { + if (rows[i].f_added == 5) { + editrow = i; + } + } + var row = {}; + row["f_name"] = datarecord.name; + row["f_origin"] = datarecord.origin; + row["f_supplier"] = datarecord.supplier; + row["f_amount"] = parseFloat($("#keg_priming_total").jqxNumberInput('decimal')) / 1000; + row["f_cost"] = datarecord.cost; + row["f_type"] = datarecord.type; + row["f_yield"] = datarecord.yield; + row["f_color"] = datarecord.color; + row["f_coarse_fine_diff"] = datarecord.coarse_fine_diff; + row["f_moisture"] = datarecord.moisture; + row["f_diastatic_power"] = datarecord.diastatic_power; + row["f_protein"] = datarecord.protein; + row["f_max_in_batch"] = datarecord.max_in_batch; + row["f_graintype"] = datarecord.graintype; + row["f_added"] = 5; + row["f_dissolved_protein"] = datarecord.dissolved_protein; + row["f_recommend_mash"] = datarecord.recommend_mash; + row["f_add_after_boil"] = 1; + row["f_adjust_to_total_100"] = 0; + row["f_percentage"] = 0; + row["f_di_ph"] = datarecord.di_ph; + row["f_acid_to_ph_57"] = datarecord.acid_to_ph_57; + row["f_inventory"] = datarecord.inventory; + if (editrow >= 0) { + var rowID = $('#fermentableGrid').jqxGrid('getrowid', editrow); + $('#fermentableGrid').jqxGrid('updaterow', rowID, row); + } else { + $("#fermentableGrid").jqxGrid('addrow', null, row); + } + calcCarbonation(); + } + }); $("#bottle_priming_amount").jqxNumberInput( Show1dec ); $("#keg_priming_amount").jqxNumberInput( Show1dec ); $("#bottle_priming_total").jqxNumberInput( Show1dec ); diff -r 0ad967f2d6ee -r 9281bbbf26a6 www/prod_edit.php --- a/www/prod_edit.php Wed Jun 12 16:41:38 2019 +0200 +++ b/www/prod_edit.php Thu Jun 13 21:28:17 2019 +0200 @@ -727,7 +727,7 @@ Datum:
Aanbevolen koolzuur vol: -
+

@@ -749,9 +749,9 @@
- Suiker type: + Suiker:
- Suiker type: + Suiker:
@@ -761,9 +761,9 @@
- Suiker totaal gr: + Suiker totaal gram:
- Suiker totaal gr: + Suiker totaal gram:
diff -r 0ad967f2d6ee -r 9281bbbf26a6 www/prod_print.php --- a/www/prod_print.php Wed Jun 12 16:41:38 2019 +0200 +++ b/www/prod_print.php Thu Jun 13 21:28:17 2019 +0200 @@ -111,7 +111,7 @@ global $colorw; global $preboil_sg; global $mashkg; - $added = array( 'Maischen', 'Koken 10 min', 'Vergisten', 'Nagisten/lageren', 'Bottelen' ); + $added = array( 'Maischen', 'Koken 10 min', 'Vergisten', 'Nagisten/lageren', 'Bottelen', 'Op fust' ); $ftype = array( 'Mout', 'Suiker', 'Vloeibaar extract', 'Droog extract', 'Ongemout graan' ); $mtype = array( 'Basismout', 'Geroosterde mout', 'Cara- of crystalmout', 'Geƫeste mout', 'Zuurmout', 'Speciale mout', 'Geen mout' ); $vul = $this->w - $this->rMargin - $this->lMargin - 125;