www/js/prod_edit.js

changeset 538
41d21817608e
parent 525
8bbc5730aaa8
child 539
fe9ac6d49c4f
equal deleted inserted replaced
531:7c37a6f85d55 538:41d21817608e
808 { name: 'h_amount', type: 'float' }, 808 { name: 'h_amount', type: 'float' },
809 { name: 'h_cost', type: 'float' }, 809 { name: 'h_cost', type: 'float' },
810 { name: 'h_type', type: 'int' }, 810 { name: 'h_type', type: 'int' },
811 { name: 'h_form', type: 'int' }, 811 { name: 'h_form', type: 'int' },
812 { name: 'h_useat', type: 'int' }, 812 { name: 'h_useat', type: 'int' },
813 { name: 'h_time', type: 'float' }, 813 { name: 'h_time', type: 'int' },
814 { name: 'h_alpha', type: 'float' }, 814 { name: 'h_alpha', type: 'float' },
815 { name: 'h_beta', type: 'float' }, 815 { name: 'h_beta', type: 'float' },
816 { name: 'h_hsi', type: 'float' }, 816 { name: 'h_hsi', type: 'float' },
817 { name: 'h_humulene', type: 'float' }, 817 { name: 'h_humulene', type: 'float' },
818 { name: 'h_caryophyllene', type: 'float' }, 818 { name: 'h_caryophyllene', type: 'float' },
911 } 911 }
912 calcIBUs(); 912 calcIBUs();
913 }); 913 });
914 }, 914 },
915 ready: function() { 915 ready: function() {
916 whirlpoolHops();
916 calcIBUs(); 917 calcIBUs();
917 $('#jqxTabs').jqxTabs('next'); 918 $('#jqxTabs').jqxTabs('next');
918 }, 919 },
919 columns: [ 920 columns: [
920 { text: 'Hop', datafield: 'h_name', 921 { text: 'Hop', datafield: 'h_name',
949 } 950 }
950 }, 951 },
951 { text: 'IBU', datafield: 'ibu', width: 80, align: 'right', 952 { text: 'IBU', datafield: 'ibu', width: 80, align: 'right',
952 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) { 953 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
953 var ibu = toIBU(rowdata.h_useat, rowdata.h_form, preboil_sg, parseFloat($('#batch_size').jqxNumberInput('decimal')), 954 var ibu = toIBU(rowdata.h_useat, rowdata.h_form, preboil_sg, parseFloat($('#batch_size').jqxNumberInput('decimal')),
954 parseFloat(rowdata.h_amount), parseFloat(rowdata.h_time), parseFloat(rowdata.h_alpha), $('#ibu_method').val()); 955 parseFloat(rowdata.h_amount), parseFloat(rowdata.h_time), parseFloat(rowdata.h_alpha), $('#ibu_method').val(),
956 dataRecord.brew_whirlpool9, dataRecord.brew_whirlpool7, dataRecord.brew_whirlpool6);
955 return '<span style="margin: 4px; margin-top: 6px; float: right;">' + dataAdapter.formatNumber(ibu, 'f1') + '</span>'; 957 return '<span style="margin: 4px; margin-top: 6px; float: right;">' + dataAdapter.formatNumber(ibu, 'f1') + '</span>';
956 } 958 }
957 }, 959 },
958 { text: 'Gewicht', datafield: 'h_amount', width: 110, align: 'right', 960 { text: 'Gewicht', datafield: 'h_amount', width: 110, align: 'right',
959 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) { 961 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
990 hopRow = row; 992 hopRow = row;
991 hopData = $('#hopGrid').jqxGrid('getrowdata', hopRow); 993 hopData = $('#hopGrid').jqxGrid('getrowdata', hopRow);
992 $('#wh_name').val(hopData.h_name); 994 $('#wh_name').val(hopData.h_name);
993 $('#wh_amount').val(hopData.h_amount * 1000); 995 $('#wh_amount').val(hopData.h_amount * 1000);
994 var ibu = toIBU(hopData.h_useat, hopData.h_form, preboil_sg, parseFloat($('#batch_size').jqxNumberInput('decimal')), 996 var ibu = toIBU(hopData.h_useat, hopData.h_form, preboil_sg, parseFloat($('#batch_size').jqxNumberInput('decimal')),
995 parseFloat(hopData.h_amount), parseFloat(hopData.h_time), parseFloat(hopData.h_alpha), $('#ibu_method').val()); 997 parseFloat(hopData.h_amount), parseFloat(hopData.h_time), parseFloat(hopData.h_alpha), $('#ibu_method').val(),
998 dataRecord.brew_whirlpool9, dataRecord.brew_whirlpool7, dataRecord.brew_whirlpool6);
996 $('#wh_ibu').val(ibu); 999 $('#wh_ibu').val(ibu);
997 if (hopData.h_useat == 5) // Dry hop 1000 if (hopData.h_useat == 5) // Dry hop
998 $('#wh_time').val(hopData.h_time / 1440); 1001 $('#wh_time').val(hopData.h_time / 1440);
999 else 1002 else
1000 $('#wh_time').val(hopData.h_time); 1003 $('#wh_time').val(hopData.h_time);
1986 } 1989 }
1987 1990
1988 function hopFlavourContribution(bt, vol, use, amount) { 1991 function hopFlavourContribution(bt, vol, use, amount) {
1989 var result; 1992 var result;
1990 1993
1994 if (use == 4 || use == 5) // Whirlpool or Dry-hop
1995 return 0;
1991 if (use == 1) { // First wort 1996 if (use == 1) { // First wort
1992 result = 0.15; // assume 15% flavourcontribution for fwh 1997 result = 0.15; // assume 15% flavourcontribution for fwh
1993 } else if (bt > 50) { 1998 } else if (bt > 50) {
1994 result = 0.10; // assume 10% flavourcontribution as a minimum 1999 result = 0.10; // assume 10% flavourcontribution as a minimum
1995 } else { 2000 } else {
2001 } 2006 }
2002 2007
2003 function hopAromaContribution(bt, vol, use, amount) { 2008 function hopAromaContribution(bt, vol, use, amount) {
2004 var result = 0; 2009 var result = 0;
2005 2010
2006 if (use == 5) { // Dry hop 2011 if (use == 5) { // Dry hop
2007 result = 1.33; 2012 result = 1.33;
2013 } else if (use == 4) { // Whirlpool
2014 if (bt > 30)
2015 bt = 30; // Max 30 minutes
2016 result = 0.62 * bt / 30;
2008 } else if (bt > 20) { 2017 } else if (bt > 20) {
2009 result = 0; 2018 result = 0;
2010 } else if (bt > 7.5) { 2019 } else if (bt > 7.5) {
2011 result = 10.03 / (4 * Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * Math.pow((bt - 7.5) / 4, 2)); 2020 result = 10.03 / (4 * Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * Math.pow((bt - 7.5) / 4, 2));
2012 } else if (use == 2) { // Boil 2021 } else if (use == 2) { // Boil
2013 result = 1; 2022 result = 1;
2014 } else if (use == 3) { // Aroma 2023 } else if (use == 3) { // Aroma
2015 result = 1.2; 2024 result = 1.2;
2016 } else if (use == 4) { // Whirlpool 2025 }
2017 result = 1.2; 2026 return (result * amount * 1000) / vol;
2018 }
2019 return (result * amount * 1000) / vol;
2020 } 2027 }
2021 2028
2022 function calcIBUs() { 2029 function calcIBUs() {
2023 var total_ibus = 0, ferm_ibus = 0, rows = {}, i, row; 2030 var total_ibus = 0, ferm_ibus = 0, rows = {}, i, row;
2024 hop_aroma = hop_flavour = 0; 2031 hop_aroma = hop_flavour = 0;
2027 } 2034 }
2028 ok_hops = 1; 2035 ok_hops = 1;
2029 for (i = 0; i < rows.length; i++) { 2036 for (i = 0; i < rows.length; i++) {
2030 row = rows[i]; 2037 row = rows[i];
2031 total_ibus += toIBU(row.h_useat, row.h_form, preboil_sg, parseFloat(dataRecord.batch_size), 2038 total_ibus += toIBU(row.h_useat, row.h_form, preboil_sg, parseFloat(dataRecord.batch_size),
2032 parseFloat(row.h_amount), parseFloat(row.h_time), parseFloat(row.h_alpha), dataRecord.ibu_method); 2039 parseFloat(row.h_amount), parseFloat(row.h_time), parseFloat(row.h_alpha), dataRecord.ibu_method,
2040 dataRecord.brew_whirlpool9, dataRecord.brew_whirlpool7, dataRecord.brew_whirlpool6);
2033 ferm_ibus += toIBU(row.h_useat, row.h_form, preboil_sg, 2041 ferm_ibus += toIBU(row.h_useat, row.h_form, preboil_sg,
2034 parseFloat(dataRecord.brew_fermenter_volume) + parseFloat(dataRecord.brew_fermenter_tcloss), 2042 parseFloat(dataRecord.brew_fermenter_volume) + parseFloat(dataRecord.brew_fermenter_tcloss),
2035 parseFloat(row.h_amount), parseFloat(row.h_time), parseFloat(row.h_alpha), dataRecord.ibu_method); 2043 parseFloat(row.h_amount), parseFloat(row.h_time), parseFloat(row.h_alpha), dataRecord.ibu_method,
2044 dataRecord.brew_whirlpool9, dataRecord.brew_whirlpool7, dataRecord.brew_whirlpool6);
2036 hop_flavour += hopFlavourContribution(parseFloat(row.h_time), parseFloat(dataRecord.batch_size), 2045 hop_flavour += hopFlavourContribution(parseFloat(row.h_time), parseFloat(dataRecord.batch_size),
2037 row.h_useat, parseFloat(row.h_amount)); 2046 row.h_useat, parseFloat(row.h_amount));
2038 hop_aroma += hopAromaContribution(parseFloat(row.h_time), parseFloat(dataRecord.batch_size), 2047 hop_aroma += hopAromaContribution(parseFloat(row.h_time), parseFloat(dataRecord.batch_size),
2039 row.h_useat, parseFloat(row.h_amount)); 2048 row.h_useat, parseFloat(row.h_amount));
2040 if ((((dataRecord.inventory_reduced <= 2) && (row.h_useat <= 4)) || // Mash, FW, Boil, Aroma, Whirlpool 2049 if ((((dataRecord.inventory_reduced <= 2) && (row.h_useat <= 4)) || // Mash, FW, Boil, Aroma, Whirlpool
2403 return; 2412 return;
2404 for (i = 0; i < rowscount; i++) { 2413 for (i = 0; i < rowscount; i++) {
2405 row = $('#hopGrid').jqxGrid('getrowdata', i); 2414 row = $('#hopGrid').jqxGrid('getrowdata', i);
2406 amount = row.h_amount * factor; 2415 amount = row.h_amount * factor;
2407 $('#hopGrid').jqxGrid('setcellvalue', i, 'h_amount', amount); 2416 $('#hopGrid').jqxGrid('setcellvalue', i, 'h_amount', amount);
2417 }
2418 };
2419
2420 function whirlpoolHops() {
2421 console.log('whirlpoolHops()');
2422 var row, i, time, rowscount;
2423 if (!(rowscount = $('#hopGrid').jqxGrid('getdatainformation').rowscount))
2424 return;
2425 if (rowscount == 0)
2426 return;
2427 for (i = 0; i < rowscount; i++) {
2428 row = $('#hopGrid').jqxGrid('getrowdata', i);
2429 if (row.h_useat == 4) {
2430 time = parseFloat(dataRecord.brew_whirlpool9) + parseFloat(dataRecord.brew_whirlpool7) + parseFloat(dataRecord.brew_whirlpool6);
2431 $('#hopGrid').jqxGrid('setcellvalue', i, 'h_time', time);
2432 }
2408 } 2433 }
2409 }; 2434 };
2410 2435
2411 function calcMiscs() { 2436 function calcMiscs() {
2412 2437
4059 } 4084 }
4060 }); 4085 });
4061 $('#fg').on('change', function(event) { 4086 $('#fg').on('change', function(event) {
4062 dataRecord.fg = parseFloat(event.args.value); 4087 dataRecord.fg = parseFloat(event.args.value);
4063 calcFermentation(); 4088 calcFermentation();
4089 });
4090 $('#brew_whirlpool9').on('valueChanged', function(event) {
4091 dataRecord.brew_whirlpool9 = event.args.value;
4092 whirlpoolHops();
4093 calcIBUs();
4094 });
4095 $('#brew_whirlpool7').on('valueChanged', function(event) {
4096 dataRecord.brew_whirlpool7 = event.args.value;
4097 whirlpoolHops();
4098 calcIBUs();
4099 });
4100 $('#brew_whirlpool6').on('valueChanged', function(event) {
4101 dataRecord.brew_whirlpool6 = event.args.value;
4102 whirlpoolHops();
4103 calcIBUs();
4064 }); 4104 });
4065 $('#BLog').jqxButton({ disabled: (dataRecord.log_brew) ? false : true}); 4105 $('#BLog').jqxButton({ disabled: (dataRecord.log_brew) ? false : true});
4066 $('#FLog').jqxButton({ disabled: (dataRecord.log_fermentation) ? false : true}); 4106 $('#FLog').jqxButton({ disabled: (dataRecord.log_fermentation) ? false : true});
4067 } 4107 }
4068 4108
4995 $('#wh_amount').jqxNumberInput(Spin1dec); 5035 $('#wh_amount').jqxNumberInput(Spin1dec);
4996 $('#wh_amount').on('change', function(event) { 5036 $('#wh_amount').on('change', function(event) {
4997 console.log('amount changed: ' + event.args.value + ' time:' + hopData.h_time + ' alpha:' + hopData.h_alpha); 5037 console.log('amount changed: ' + event.args.value + ' time:' + hopData.h_time + ' alpha:' + hopData.h_alpha);
4998 var ibu, amount = parseFloat(event.args.value) / 1000; 5038 var ibu, amount = parseFloat(event.args.value) / 1000;
4999 ibu = toIBU(hopData.h_useat, hopData.h_form, preboil_sg, parseFloat($('#batch_size').jqxNumberInput('decimal')), 5039 ibu = toIBU(hopData.h_useat, hopData.h_form, preboil_sg, parseFloat($('#batch_size').jqxNumberInput('decimal')),
5000 amount, parseFloat(hopData.h_time), parseFloat(hopData.h_alpha), $('#ibu_method').val() 5040 amount, parseFloat(hopData.h_time), parseFloat(hopData.h_alpha), $('#ibu_method').val(),
5041 dataRecord.brew_whirlpool9, dataRecord.brew_whirlpool7, dataRecord.brew_whirlpool6
5001 ); 5042 );
5002 hopData.h_amount = amount; 5043 hopData.h_amount = amount;
5003 $('#wh_ibu').val(ibu); 5044 $('#wh_ibu').val(ibu);
5004 }); 5045 });
5005 $('#wh_ibu').jqxNumberInput(Show1dec); 5046 $('#wh_ibu').jqxNumberInput(Show1dec);
5011 if (newtime > parseFloat($('#boil_time').jqxNumberInput('decimal'))) { 5052 if (newtime > parseFloat($('#boil_time').jqxNumberInput('decimal'))) {
5012 newtime = parseFloat($('#boil_time').jqxNumberInput('decimal')); 5053 newtime = parseFloat($('#boil_time').jqxNumberInput('decimal'));
5013 $('#wh_time').val(newtime); 5054 $('#wh_time').val(newtime);
5014 } 5055 }
5015 hopData.h_time = newtime; 5056 hopData.h_time = newtime;
5016 } else if (hopData.h_useat == 4) { // Whirlpool
5017 if (newtime > 120) {
5018 newtime = 120;
5019 $('#wh_time').val(newtime);
5020 }
5021 hopData.h_time = newtime;
5022 } else if (hopData.h_useat == 5) { // Dry hop 5057 } else if (hopData.h_useat == 5) { // Dry hop
5023 if (newtime > 21) { 5058 if (newtime > 21) {
5024 newtime = 21; 5059 newtime = 21;
5025 $('#wh_time').val(newtime); 5060 $('#wh_time').val(newtime);
5026 } 5061 }
5027 hopData.h_time = newtime * 1440; 5062 hopData.h_time = newtime * 1440;
5028 } 5063 }
5029 ibu = toIBU(hopData.h_useat, hopData.h_form, preboil_sg, parseFloat($('#batch_size').jqxNumberInput('decimal')), 5064 ibu = toIBU(hopData.h_useat, hopData.h_form, preboil_sg, parseFloat($('#batch_size').jqxNumberInput('decimal')),
5030 parseFloat(hopData.h_amount), parseFloat(hopData.h_time), parseFloat(hopData.h_alpha), $('#ibu_method').val()); 5065 parseFloat(hopData.h_amount), parseFloat(hopData.h_time), parseFloat(hopData.h_alpha), $('#ibu_method').val(),
5066 dataRecord.brew_whirlpool9, dataRecord.brew_whirlpool7, dataRecord.brew_whirlpool6);
5031 // console.log("time changed: "+newtime+" final:"+hopData.h_time+" ibu:"+ibu); 5067 // console.log("time changed: "+newtime+" final:"+hopData.h_time+" ibu:"+ibu);
5032 $('#wh_ibu').val(ibu); 5068 $('#wh_ibu').val(ibu);
5033 }); 5069 });
5034 $('#wh_useat').jqxDropDownList({ 5070 $('#wh_useat').jqxDropDownList({
5035 theme: theme, 5071 theme: theme,
5051 $('#wh_time').val(hopData.h_time); 5087 $('#wh_time').val(hopData.h_time);
5052 } else if (index == 3) { // Aroma 5088 } else if (index == 3) { // Aroma
5053 hopData.h_time = 0; 5089 hopData.h_time = 0;
5054 $('#wh_time').jqxNumberInput({ spinButtons: false, readOnly: true, width: 90 }); 5090 $('#wh_time').jqxNumberInput({ spinButtons: false, readOnly: true, width: 90 });
5055 $('#wh_time').val(0); 5091 $('#wh_time').val(0);
5056 } else { // Boil, Whirlpool or Dry hop 5092 } else if (index == 4) { // Whirlpool
5093 hopData.h_time = (parseFloat(dataRecord.brew_whirlpool9) + parseFloat(dataRecord.brew_whirlpool7) + parseFloat(dataRecord.brew_whirlpool6));
5094 $('#wh_time').jqxNumberInput({ spinButtons: false, readOnly: true, width: 90 });
5095 $('#wh_time').val(hopData.h_time);
5096 } else { // Boil, Dry hop
5057 $('#wh_time').jqxNumberInput({ spinButtons: true, readOnly: false, width: 110 }); 5097 $('#wh_time').jqxNumberInput({ spinButtons: true, readOnly: false, width: 110 });
5058 } 5098 }
5059 if (index == 5) // Dry hop 5099 if (index == 5) // Dry hop
5060 $('#wh_pmpt_time').html('Tijd in dagen'); 5100 $('#wh_pmpt_time').html('Tijd in dagen');
5061 else 5101 else

mercurial