www/js/prod_edit.js

changeset 827
5df0d11ca02b
parent 826
4e681bc073bd
child 828
aa0a9b1a2dd7
equal deleted inserted replaced
826:4e681bc073bd 827:5df0d11ca02b
1146 whirlpoolHops(); 1146 whirlpoolHops();
1147 calcMiscs(); 1147 calcMiscs();
1148 calcViability(); 1148 calcViability();
1149 calcYeast(); 1149 calcYeast();
1150 kookTijd(); 1150 kookTijd();
1151 // calcInit(); 1151 $('#FLog').jqxButton({ disabled: (dataRecord.log_fermentation) ? false : true});
1152 $('#ILog').jqxButton({ disabled: (dataRecord.log_ispindel) ? false : true});
1153 $('#CLog').jqxButton({ disabled: (dataRecord.log_co2pressure) ? false : true});
1152 console.log('calculations ready'); 1154 console.log('calculations ready');
1153 $('#jqxLoader').jqxLoader('close'); 1155 $('#jqxLoader').jqxLoader('close');
1154 $('#jqxTabs').jqxTabs('first'); 1156 $('#jqxTabs').jqxTabs('first');
1155 }, 1157 },
1156 columns: [ 1158 columns: [
2176 } 2178 }
2177 } 2179 }
2178 calcSupplies(); 2180 calcSupplies();
2179 }; 2181 };
2180 2182
2181 function calcMashEfficiency() {
2182 var c, m;
2183 if (parseFloat($('#brew_mash_sg').jqxNumberInput('decimal')) < 1.002)
2184 return;
2185 c = sg_to_plato(est_mash_sg);
2186 m = sg_to_plato(parseFloat($('#brew_mash_sg').jqxNumberInput('decimal')));
2187 if (c > 0.5)
2188 $('#brew_mash_efficiency').val(100 * m / c);
2189 else
2190 $('#brew_mash_efficiency').val(0);
2191 };
2192
2193 function calcEfficiencyBeforeBoil() {
2194 var m = 0, i, row, tot, result = 0;
2195 if (!($('#fermentableGrid').jqxGrid('getrows')))
2196 return; // no grid loaded yet
2197 if (dataRecord.fermentables.length == 0)
2198 return; // no fermentables
2199 for (i = 0; i < dataRecord.fermentables.length; i++) {
2200 row = dataRecord.fermentables[i];
2201 if (row.f_added == 0) { // Mash
2202 m += row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
2203 }
2204 }
2205 tot = sg_to_plato(dataRecord.brew_preboil_sg) * (dataRecord.brew_preboil_volume / 1.04) * dataRecord.brew_preboil_sg * 10 / 1000;
2206 if (m > 0)
2207 result = Round((tot / m * 100), 1);
2208 if (result < 0)
2209 result = 0;
2210 $('#brew_preboil_efficiency').val(result);
2211 }
2212
2213 function calcEfficiencyAfterBoil() {
2214 var m = 0, // Sugars added at mash
2215 b = 0, // Sugars added at boil
2216 i, row, tot, result = 0;
2217 if (!($('#fermentableGrid').jqxGrid('getrows'))) {
2218 return; // grid not yet loaded.
2219 }
2220 for (i = 0; i < dataRecord.fermentables.length; i++) {
2221 row = dataRecord.fermentables[i];
2222 if (row.f_added == 0) { // Mash
2223 m += row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
2224 } else if (row.f_added == 1) { // Boil
2225 b += row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
2226 }
2227 }
2228 tot = sg_to_plato(dataRecord.brew_aboil_sg) * (dataRecord.brew_aboil_volume / 1.04) * dataRecord.brew_aboil_sg * 10 / 1000;
2229 tot -= b; // total sugars in wort minus added sugars.
2230 if (m > 0)
2231 result = Round((tot / m * 100), 1);
2232 if (result < 0)
2233 result = 0;
2234 dataRecord.brew_aboil_efficiency = result;
2235 $('#brew_aboil_efficiency').val(result);
2236 }
2237
2238 function GetBUGU() { 2183 function GetBUGU() {
2239 var gu = (dataRecord.est_og - 1) * 1000; 2184 var gu = (dataRecord.est_og - 1) * 1000;
2240 if (gu > 0) 2185 if (gu > 0)
2241 return dataRecord.est_ibu / gu; 2186 return dataRecord.est_ibu / gu;
2242 else 2187 else
2982 $('#keg_priming_total').val(0); 2927 $('#keg_priming_total').val(0);
2983 $('#keg_abv').val(ABV); 2928 $('#keg_abv').val(ABV);
2984 } 2929 }
2985 } 2930 }
2986 2931
2987 function en_stage_brewday(state) {
2988 $('#jqxTabs').jqxTabs((state) ? 'disableAt':'enableAt', 8); // Brewday tab
2989 }
2990
2991 function en_stage_afterbrew(state) {
2992 $('#jqxTabs').jqxTabs((state) ? 'enableAt':'disableAt', 9); // Fermentation tab
2993 }
2994
2995 function en_stage_tertiary(state) {
2996 $('#package_date').jqxDateTimeInput({ disabled: (state) ? false:true });
2997 }
2998
2999 function en_stage_aftertertiary(state) {
3000
3001 var spinstate = { spinButtons: (state) ? false:true, readOnly: (state) ? true:false, width: (state) ? 90:110 };
3002
3003 $('#primary_start_temp').jqxNumberInput(spinstate);
3004 $('#primary_max_temp').jqxNumberInput(spinstate);
3005 $('#primary_end_temp').jqxNumberInput(spinstate);
3006 $('#primary_end_sg').jqxNumberInput(spinstate);
3007 $('#primary_end_brix').jqxNumberInput(spinstate);
3008 $('#primary_end_date').jqxDateTimeInput({ disabled: (state) ? true:false });
3009 }
3010
3011 function en_stage_afterpackaging(state) {
3012
3013 var onval = { disabled: (state) ? true:false };
3014 var spinstate = { spinButtons: (state) ? false:true, readOnly: (state) ? true:false, width: (state) ? 90:110 };
3015
3016 $('#secondary_temp').jqxNumberInput(spinstate);
3017 $('#secondary_end_sg').jqxNumberInput(spinstate);
3018 $('#secondary_end_date').jqxDateTimeInput(onval);
3019 $('#secondary_end_brix').jqxNumberInput(spinstate);
3020 $('#tertiary_temp').jqxNumberInput(spinstate);
3021 $('#fg').jqxNumberInput(spinstate);
3022 $('#final_brix').jqxNumberInput(spinstate);
3023 $('#package_date').jqxDateTimeInput(onval);
3024 $('#package_volume').jqxNumberInput(spinstate);
3025 $('#package_infuse_amount').jqxNumberInput(spinstate);
3026 $('#package_infuse_abv').jqxNumberInput(spinstate);
3027 $('#package_infuse_notes').jqxInput(onval);
3028 $('#package_ph').jqxNumberInput(spinstate);
3029 $('#bottle_amount').jqxNumberInput(spinstate);
3030 $('#bottle_priming_water').jqxNumberInput(spinstate);
3031 $('#keg_priming_water').jqxNumberInput(spinstate);
3032 $('#keg_amount').jqxNumberInput(spinstate);
3033 $('#bottle_carbonation').jqxNumberInput(spinstate);
3034 $('#keg_carbonation').jqxNumberInput(spinstate);
3035 $('#bottle_priming_sugar').jqxDropDownList(onval);
3036 $('#keg_priming_sugar').jqxDropDownList(onval);
3037 $('#keg_forced_carb').jqxCheckBox(onval);
3038 $('#bottle_carbonation_temp').jqxNumberInput(spinstate);
3039 $('#keg_carbonation_temp').jqxNumberInput(spinstate);
3040 }
3041
3042 function en_stage_b4taste(state) {
3043 $('#jqxTabs').jqxTabs((state) ? 'disableAt':'enableAt', 11); // Tasting tab
3044 }
3045
3046 function en_stage_locked(state) {
3047
3048 var onval = { disabled: (state) ? true:false };
3049
3050 $('#taste_date').jqxDateTimeInput(onval);
3051 $('#taste_rate').jqxNumberInput({ spinButtons: (state) ? false:true, readOnly: (state) ? true:false, width: (state) ? 90:110 });
3052 $('#taste_color').jqxInput(onval);
3053 $('#taste_transparency').jqxInput(onval);
3054 $('#taste_head').jqxInput(onval);
3055 $('#taste_aroma').jqxInput(onval);
3056 $('#taste_taste').jqxInput(onval);
3057 $('#taste_aftertaste').jqxInput(onval);
3058 $('#taste_mouthfeel').jqxInput(onval);
3059 $('#taste_notes').jqxInput(onval);
3060 $('#notes').jqxInput(onval);
3061 }
3062
3063 function calcStage() { 2932 function calcStage() {
3064
3065 var newstage = dataRecord.stage, d, date1, date2, date1_unixtime, date2_unixtime, timeDifference, timeDifferenceInDays;
3066
3067 if (newstage == 0 && dataRecord.est_og > 1.005 && dataRecord.est_color > 3 && dataRecord.est_ibu > 3)
3068 newstage = 1;
3069 if (newstage == 1 && parseFloat($('#brew_date_start').val()) > 2000)
3070 newstage = 2; // Brewday
3071 if (newstage == 2 && ($('#brew_date_start').val() == ''))
3072 newstage = 1; // No brewday
3073 if (newstage == 2 && parseFloat(dataRecord.brew_date_end) > 2000)
3074 newstage = 3; // Primary
3075 if (newstage == 3 && parseFloat(dataRecord.primary_end_date) > 2000)
3076 newstage = 4; // Secondary
3077 if (newstage == 4 && parseFloat(dataRecord.secondary_end_date) > 2000)
3078 newstage = 5; // Tertiary
3079 if (newstage == 5 && parseFloat(dataRecord.package_date) > 2000)
3080 newstage = 6; // Package
3081 if (newstage >= 6 && newstage < 9) {
3082 d = new Date();
3083 date2 = dataRecord.package_date;
3084 date2 = date2.split('-');
3085 // Now we convert the array to a Date object
3086 date1 = new Date(d.getFullYear(), d.getMonth(), d.getDate());
3087 date2 = new Date(date2[0], date2[1] - 1, date2[2]);
3088 // We use the getTime() method and get the unixtime
3089 date1_unixtime = parseInt(date1.getTime() / 1000);
3090 date2_unixtime = parseInt(date2.getTime() / 1000);
3091 // This is the calculated difference in seconds
3092 timeDifference = date1_unixtime - date2_unixtime;
3093 timeDifferenceInDays = timeDifference / 60 / 60 / 24;
3094 if (timeDifferenceInDays > 0) { // At least one day
3095 if (timeDifferenceInDays >= 42) // 6 weeks
3096 newstage = 9; // Ready to taste
3097 else if (timeDifferenceInDays >= 14) // 14 days
3098 newstage = 8; // Mature
3099 else
3100 newstage = 7; // Carbonation
3101 }
3102 }
3103 if (newstage == 9 && parseFloat(dataRecord.taste_date) > 2000)
3104 newstage = 10; // Ready
3105
3106 if (newstage != dataRecord.stage) {
3107 console.log('calcStage() old: ' + dataRecord.stage + ' new: ' + newstage);
3108 dataRecord.stage = newstage;
3109 }
3110
3111 /* 2933 /*
3112 * Set stage and enable or disable parts of the screens. 2934 * Set stage and enable or disable parts of the screens.
3113 */ 2935 */
3114 $('#stage').val(StageData[dataRecord.stage].nl); 2936 $('#stage').val(StageData[dataRecord.stage].nl);
3115 if (dataRecord.stage >= 10) {
3116 $('#locked').jqxCheckBox({ disabled: false });
3117 }
3118 2937
3119 /* 2938 /*
3120 * Enable or disable parts of the screens. 2939 * Enable or disable parts of the screens.
3121 */ 2940 */
3122 en_stage_brewday(dataRecord.stage < 1); // Planning, no ingredients 2941 $('#jqxTabs').jqxTabs((dataRecord.stage < 1) ? 'disableAt':'enableAt', 8); // Brewday tab
3123 en_stage_afterbrew(dataRecord.stage > 2); // After the brew 2942 $('#jqxTabs').jqxTabs((dataRecord.stage > 2) ? 'enableAt':'disableAt', 9); // Fermentation tab
3124 en_stage_tertiary(dataRecord.stage == 5); // Tertiary, allow packaging 2943 $('#jqxTabs').jqxTabs((dataRecord.stage < 9) ? 'disableAt':'enableAt', 11); // Tasting tab
3125 en_stage_aftertertiary(dataRecord.stage >= 5); // After all fermentation steps
3126 en_stage_afterpackaging(dataRecord.stage >= 6); // After packaging
3127 en_stage_b4taste(dataRecord.stage < 9); // Taste when at least Mature.
3128 en_stage_locked(dataRecord.stage == 11); // Locked.
3129 }
3130
3131 function calcInit() {
3132
3133 console.log('** calcInit() start');
3134 calcMashEfficiency();
3135 calcEfficiencyBeforeBoil();
3136 calcEfficiencyAfterBoil();
3137 calcWater();
3138 calcFermentation();
3139 // calcCarbonation();
3140 calcIBUs();
3141 $('#BLog').jqxButton({ disabled: (dataRecord.log_brew) ? false : true});
3142 $('#FLog').jqxButton({ disabled: (dataRecord.log_fermentation) ? false : true});
3143 $('#ILog').jqxButton({ disabled: (dataRecord.log_ispindel) ? false : true});
3144 $('#CLog').jqxButton({ disabled: (dataRecord.log_co2pressure) ? false : true});
3145 console.log('** calcInit() ready');
3146 } 2944 }
3147 2945
3148 2946
3149 // initialize the input fields. 2947 // initialize the input fields.
3150 // Tab 1, Algemeen 2948 // Tab 1, Algemeen

mercurial