diff -r 45248acb6252 -r 4a4cc3497a57 www/js/prod_edit.js --- a/www/js/prod_edit.js Tue Jan 01 16:24:17 2019 +0100 +++ b/www/js/prod_edit.js Wed Jan 02 14:49:17 2019 +0100 @@ -985,8 +985,80 @@ $("#sparge_acid_amount").val(Acid); } + 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) + var sugar = SFactor * (CO2 - (0.000849151 * T * T - 0.0587512 * T + 1.71137)) / 0.286; + if (sugar < 0) + sugar = 0; + return sugar; + } + + function CarbCO2ToPressure(CO2, T) { + return (CO2 - (-0.000005594056 * Math.pow(T, 4) + 0.000144357886 * Math.pow(T, 3) + + 0.000362999168 * T * T - 0.064872987645 * T + 1.641145175049)) / + (0.00000498031 * Math.pow(T, 4) - 0.00024358267 * Math.pow(T, 3) + + 0.00385867329 * T * T - 0.05671206825 * T + 1.53801423376); + } + + function getSFactor(Sugar) { + switch (Sugar) { + case 'Kristalsuiker': return 1; + case 'Glucose/dextrose': return 1.16; + case 'Honing': return 1.28; + case 'Moutextract': return 1.74; + case 'Melasse': return 3.83; + } + return 1; + } + + function calcCarbonation() { + + var TSec = dataRecord.secondary_temp; // End fermentation temperature. + if (TSec < 1) + TSec = dataRecord.primary_end_temp; // Fallback + if (TSec < 1) + TSec = 18; // Fallback to room temperature. + + if (dataRecord.fg == 1.000) + var ABV = abvol(dataRecord.brew_fermenter_sg, parseFloat($("#est_fg").jqxNumberInput('decimal'))); + else + var ABV = abvol(dataRecord.brew_fermenter_sg, dataRecord.fg); + + // Bottles + var SFactor = getSFactor(dataRecord.bottle_priming_sugar); + var Amount = CarbCO2toS(dataRecord.bottle_carbonation, TSec, SFactor); + dataRecord.bottle_priming_amount = Amount; + $("#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); + + // Kegs + SFactor = getSFactor(dataRecord.keg_priming_sugar); + 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); + } + + $("#keg_abv").val(Math.round((ABV + Amount * 0.47 / 7.907) * 10) / 10); + } + function calcInit () { - console.log("calc.init()"); + console.log("calcInit()"); calcSGendMash(); calcMashEfficiency(); @@ -1137,6 +1209,44 @@ dataRecord.sparge_acid_perc = parseFloat(event.args.value); calcSparge(); }); + + calcCarbonation(); + $('#bottle_amount').on('change', function (event) { + dataRecord.bottle_amount = parseFloat(event.args.value); + calcCarbonation(); + }); + $('#keg_amount').on('change', function (event) { + dataRecord.keg_amount = parseFloat(event.args.value); + calcCarbonation(); + }); + $('#bottle_carbonation').on('change', function (event) { + dataRecord.bottle_carbonation = 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 = true; + calcCarbonation(); + }); + $("#keg_forced_carb").on('unchecked', function (event) { + dataRecord.keg_forced_carb = false; + calcCarbonation(); + }); + $('#keg_carbonation_temp').on('change', function (event) { + dataRecord.keg_carbonation_temp = parseFloat(event.args.value); + calcCarbonation(); + }); }; $("#styleSelect").jqxDropDownList({ @@ -1173,7 +1283,9 @@ $("#st_color_min").val(datarecord.color_min); $("#st_color_max").val(datarecord.color_max); $("#st_carb_min").val(datarecord.carb_min); + $("#st_carb_min2").val(datarecord.carb_min); $("#st_carb_max").val(datarecord.carb_max); + $("#st_carb_max2").val(datarecord.carb_max); $("#st_abv_min").val(datarecord.abv_min); $("#st_abv_max").val(datarecord.abv_max); } @@ -1344,6 +1456,8 @@ { name: 'brew_fermenter_ibu', type: 'float' }, { name: 'brew_date_end', type: 'string' }, { name: 'brew_log_available', type: 'bool' }, + { name: 'og', type: 'float' }, + { name: 'fg', type: 'float' }, { name: 'primary_start_temp', type: 'float' }, { name: 'primary_max_temp', type: 'float' }, { name: 'primary_end_temp', type: 'float' }, @@ -1365,7 +1479,6 @@ { name: 'keg_carbonation_temp', type: 'float' }, { name: 'keg_forced_carb', type: 'bool' }, { name: 'keg_pressure', type: 'float' }, - { name: 'keg_priming_factor', type: 'float' }, { name: 'taste_notes', type: 'string' }, { name: 'taste_rate', type: 'float' }, { name: 'taste_date', type: 'string' }, @@ -1520,7 +1633,21 @@ $("#brew_fermenter_extrasugar").val(dataRecord.brew_fermenter_extrasugar); $("#brew_fermenter_color").val(dataRecord.brew_fermenter_color); $("#brew_date_end").val(dataRecord.brew_date_end); - + $("#og").val(dataRecord.og); + $("#fg").val(dataRecord.fg); + $("#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_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_amount").val(dataRecord.keg_priming_amount); + $("#keg_carbonation_temp").val(dataRecord.keg_carbonation_temp); + $("#keg_forced_carb").val(dataRecord.keg_forced_carb); + $("#keg_pressure").val(dataRecord.keg_pressure); $("#taste_notes").val(dataRecord.taste_notes); $("#taste_rate").val(dataRecord.taste_rate); $("#taste_date").val(dataRecord.taste_date); @@ -1550,7 +1677,9 @@ $("#st_ibu_min").val(dataRecord.st_ibu_min); $("#st_ibu_max").val(dataRecord.st_ibu_max); $("#st_carb_min").val(dataRecord.st_carb_min); + $("#st_carb_min2").val(dataRecord.st_carb_min); $("#st_carb_max").val(dataRecord.st_carb_max); + $("#st_carb_max2").val(dataRecord.st_carb_max); $("#type").val(dataRecord.type); $("#batch_size").val(dataRecord.batch_size); $("#boil_size").val(dataRecord.boil_size); @@ -2744,6 +2873,7 @@ var srcBase = [ "NaHCO3", "Na2CO3", "CaCO3", "Ca(OH)2" ]; var srcAcid = [ "Melkzuur", "Zoutzuur", "Fosforzuur", "Zwavelzuur" ]; var srcSource = [ "Bron 1", "Bron 2", "Gemengd" ]; + var srcSugar = [ "Kristalsuiker", "Glucose/dextrose", "Honing", "Moutextract", "Melasse" ]; var srcMaterial= [ "RVS", "Aluminium", "Kunststof", "Koper" ]; var srcAeration= [ 'None', 'Air', 'Oxygen' ]; var srcCooling= [ '-', 'Emersion chiller', 'Counterflow chiller', 'Au bain marie', 'Natural' ]; @@ -3112,8 +3242,45 @@ $("#brew_fermenter_color").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 0 }); // Tab 10, Fermentation + // Note, fermentation temps changes must do calcCarbonation() + $("#fg").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 3, spinButtons: true, spinButtonsStep: 0.001 }); // Tab 11, Packaging + $("#package_date").jqxTooltip({ content: 'De verpakkings datum van dit bier.' }); + $("#package_date").jqxDateTimeInput({ + theme: theme, + width: 150, + height: 23, + allowNullDate: true, + todayString: 'Vandaag', + clearString: 'Wissen', + showFooter: true, + formatString: 'yyyy-MM-dd' + }); + $("#st_carb_min2").jqxTooltip({ content: 'Het minimum aanbevolen koolzuur volume voor deze bierstijl.'}); + $("#st_carb_min2").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true }); + $("#st_carb_max2").jqxTooltip({ content: 'Het maximum aamnevolen koolzuur volume voor deze bierstijl.'}); + $("#st_carb_max2").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true }); + $("#bottle_amount").jqxTooltip({ content: 'De totale hoeveelheid te bottelen bier.' }); + $("#bottle_amount").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 }); + $("#keg_amount").jqxTooltip({ content: 'De totale hoeveelheid op fust te zetten bier.' }); + $("#keg_amount").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 }); + $("#bottle_carbonation").jqxTooltip({ content: 'Het gewenste CO2 volume in de flessen.' }); + $("#bottle_carbonation").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, max: 5, decimalDigits: 2, spinButtons: true, spinButtonsStep: 0.05 }); + $("#keg_carbonation").jqxTooltip({ content: 'Het gewenste CO2 volume door de suiker in de fusten.' }); + $("#keg_carbonation").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, max: 5, decimalDigits: 2, spinButtons: true, spinButtonsStep: 0.05 }); + $("#bottle_priming_sugar").jqxDropDownList({ theme: theme, source: srcSugar, width: 175, height: 23, dropDownHeight: 150 }); + $("#keg_priming_sugar").jqxDropDownList({ theme: theme, source: srcSugar, width: 175, height: 23, dropDownHeight: 150 }); + $("#bottle_priming_amount").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 70, height: 23, decimalDigits: 1, readOnly: true }); + $("#keg_priming_amount").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 70, height: 23, decimalDigits: 1, readOnly: true }); + $("#bottle_priming_total").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 70, height: 23, decimalDigits: 1, readOnly: true }); + $("#keg_priming_total").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 70, height: 23, decimalDigits: 1, readOnly: true }); + $("#keg_forced_carb").jqxCheckBox({ theme: theme, width: 120, height: 23 }); + $("#keg_pressure").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 70, height: 23, decimalDigits: 1, readOnly: true }); + $("#bottle_abv").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 70, height: 23, decimalDigits: 1, readOnly: true }); + $("#keg_abv").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 70, height: 23, decimalDigits: 1, readOnly: true }); + $("#bottle_carbonation_temp").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0.5, max: 40, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 }); + $("#keg_carbonation_temp").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0.5, max: 40, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 }); // Tab 12, Tasting $("#taste_date").jqxTooltip({ content: 'De proef datum van dit bier.' }); @@ -3233,6 +3400,22 @@ 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')), + + og: dataRecord.og, + fg: parseFloat($("#fg").jqxNumberInput('decimal')), + 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_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_amount: parseFloat($("#keg_priming_amount").jqxNumberInput('decimal')), + keg_carbonation_temp: parseFloat($("#keg_carbonation_temp").jqxNumberInput('decimal')), + keg_forced_carb: $("#keg_forced_carb").val(), + keg_pressure: parseFloat($("#keg_pressure").jqxNumberInput('decimal')), taste_notes: $("#taste_notes").val(), taste_rate: parseFloat($("#taste_rate").jqxNumberInput('decimal')), taste_date: $("#taste_date").val(),