120 $("#ok_supplies").html("<img src='images/dialog-ok-apply.png'>"); |
120 $("#ok_supplies").html("<img src='images/dialog-ok-apply.png'>"); |
121 else |
121 else |
122 $("#ok_supplies").html("<img src='images/dialog-error.png'>"); |
122 $("#ok_supplies").html("<img src='images/dialog-error.png'>"); |
123 } |
123 } |
124 |
124 |
|
125 function calcPercentages() { |
|
126 |
|
127 console.log("calcPercentages()"); |
|
128 var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount; |
|
129 if (rowscount > 1) { |
|
130 var tw = 0; |
|
131 for (i = 0; i < rowscount; i++) { |
|
132 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i); |
|
133 if (rowdata.f_added < 4) |
|
134 tw += Math.round(rowdata.f_amount * 1000) / 1000; |
|
135 }; |
|
136 tw = Math.round(tw * 1000) / 1000; |
|
137 |
|
138 for (i = 0; i < rowscount; i++) { |
|
139 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i); |
|
140 if (rowdata.f_added < 4) { |
|
141 var percentage = Math.round(rowdata.f_amount / tw * 1000) / 10.0; |
|
142 $("#fermentableGrid").jqxGrid('setcellvalue', i, "f_percentage", percentage); |
|
143 } else { |
|
144 $("#fermentableGrid").jqxGrid('setcellvalue', i, "f_percentage", 0); |
|
145 } |
|
146 }; |
|
147 } else { |
|
148 $("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100); |
|
149 } |
|
150 } |
125 |
151 |
126 /* |
152 /* |
127 * All calculations that depend on changes in the fermentables, |
153 * All calculations that depend on changes in the fermentables, |
128 * volumes and equipments. |
154 * volumes and equipments. |
129 */ |
155 */ |
170 var s = 0; |
196 var s = 0; |
171 for (var i = 0; i < rows.length; i++) { |
197 for (var i = 0; i < rows.length; i++) { |
172 var row = rows[i]; |
198 var row = rows[i]; |
173 if (row.f_adjust_to_total_100) |
199 if (row.f_adjust_to_total_100) |
174 my_100 = true; |
200 my_100 = true; |
175 if (row.f_type == 1) // Sugar |
201 if (row.f_type == 1 && row.f_added < 4) // Sugar |
176 psugar += row.f_percentage; |
202 psugar += row.f_percentage; |
177 if (row.f_graintype == 2) // Crystal |
203 if (row.f_graintype == 2 && row.f_added < 4) // Crystal |
178 pcara += row.f_percentage; |
204 pcara += row.f_percentage; |
179 var d = row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100); |
205 var d = row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100); |
180 if (row.f_added == 0) { // Mash |
206 if (row.f_added == 0) { // Mash |
181 if (mvol > 0) { // Only if mash already known. |
207 if (mvol > 0) { // Only if mash already known. |
182 mvol += row.f_amount * row.f_moisture / 100; |
208 mvol += row.f_amount * row.f_moisture / 100; |
186 sugarsm += d; |
212 sugarsm += d; |
187 mashkg += row.f_amount; |
213 mashkg += row.f_amount; |
188 } |
214 } |
189 if (row.f_added == 0 || row.f_added == 1) // Mash or Boil |
215 if (row.f_added == 0 || row.f_added == 1) // Mash or Boil |
190 sugarsf += d; |
216 sugarsf += d; |
191 if (row.f_added == 2 || row.f_added == 3) { |
217 if (row.f_added == 2 || row.f_added == 3) { // Fermentation or lagering |
192 var x = (row.f_yield / 100) * (1 - row.f_moisture / 100); |
218 var x = (row.f_yield / 100) * (1 - row.f_moisture / 100); |
193 addedS += row.f_amount * x; |
219 addedS += row.f_amount * x; |
194 addedmass += row.f_amount; |
220 addedmass += row.f_amount; |
195 vol += (x * sugardensity + (1 - x) * 1) * row.f_amount; |
221 vol += (x * sugardensity + (1 - x) * 1) * row.f_amount; |
196 } |
222 } |
197 colort += row.f_amount * ebc_to_srm(row.f_color); |
223 if (row.f_added < 4) { |
198 colorh += row.f_amount * row.f_color * get_kt(row.f_color); |
224 colort += row.f_amount * ebc_to_srm(row.f_color); |
199 colorn += (row.f_percentage / 100) * row.f_color; // For 8.6 Pt wort. |
225 colorh += row.f_amount * row.f_color * get_kt(row.f_color); |
|
226 colorn += (row.f_percentage / 100) * row.f_color; // For 8.6 Pt wort. |
|
227 } |
200 // Check supplies. |
228 // Check supplies. |
201 if ((((dataRecord.inventory_reduced <= 2) && (row.f_added <= 1)) || // Mash or boil |
229 if ((((dataRecord.inventory_reduced <= 2) && (row.f_added <= 1)) || // Mash or boil |
202 ((dataRecord.inventory_reduced <= 3) && (row.f_added == 2)) || // Primary |
230 ((dataRecord.inventory_reduced <= 3) && (row.f_added == 2)) || // Primary |
203 ((dataRecord.inventory_reduced <= 5) && (row.f_added == 3)) || // Secondary or Tertiary |
231 ((dataRecord.inventory_reduced <= 5) && (row.f_added == 3)) || // Secondary or Tertiary |
204 ((dataRecord.inventory_reduced <= 6) && (row.f_added == 4))) && row.f_inventory < row.f_amount) { |
232 ((dataRecord.inventory_reduced <= 6) && (row.f_added == 4)) || // Bottle |
|
233 ((dataRecord.inventory_reduced <= 6) && (row.f_added == 5))) && row.f_inventory < row.f_amount) { |
205 ok_fermentables = 0; |
234 ok_fermentables = 0; |
206 } |
235 } |
207 if (row.f_added == 0 && (row.f_type == 0 || row.f_type == 4) && row.f_color < 50) { // Mash and Grain/Adjunct and Color < 50 |
236 if (row.f_added == 0 && (row.f_type == 0 || row.f_type == 4) && row.f_color < 50) { // Mash and Grain/Adjunct and Color < 50 |
208 lintner += row.f_diastatic_power * row.f_amount; |
237 lintner += row.f_diastatic_power * row.f_amount; |
209 // console.log("add "+row.f_name+" diastatic_power:"+row.f_diastatic_power*row.f_amount+" now:"+lintner); |
238 // console.log("add "+row.f_name+" diastatic_power:"+row.f_diastatic_power*row.f_amount+" now:"+lintner); |
391 var tot = 0; |
420 var tot = 0; |
392 var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount; |
421 var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount; |
393 |
422 |
394 for (var i = 0; i < rowscount; i++) { |
423 for (var i = 0; i < rowscount; i++) { |
395 var row = $("#fermentableGrid").jqxGrid('getrowdata', i); |
424 var row = $("#fermentableGrid").jqxGrid('getrowdata', i); |
396 var d = row.f_percentage / 100 * (row.f_yield / 100) * (1 - row.f_moisture / 100); |
425 if (row.f_added < 4) { |
397 if (row.f_added == 0) // Mash |
426 var d = row.f_percentage / 100 * (row.f_yield / 100) * (1 - row.f_moisture / 100); |
398 d = efficiency / 100 * d; |
427 if (row.f_added == 0) // Mash |
399 tot += d; |
428 d = efficiency / 100 * d; |
|
429 tot += d; |
|
430 } |
400 } |
431 } |
401 var totmass = 0; |
432 var totmass = 0; |
402 if (tot) |
433 if (tot) |
403 totmass = sug / tot; |
434 totmass = Math.round((sug / tot) * 1000) / 1000; |
404 |
435 |
405 if (totmass) { |
436 if (totmass) { |
406 for (i = 0; i < rowscount; i++) { |
437 for (i = 0; i < rowscount; i++) { |
407 var row = $("#fermentableGrid").jqxGrid('getrowdata', i); |
438 var row = $("#fermentableGrid").jqxGrid('getrowdata', i); |
408 var amount = row.f_percentage / 100 * totmass; |
439 if (row.f_added < 4) { |
409 $("#fermentableGrid").jqxGrid('setcellvalue', i, "f_amount", amount); |
440 var amount = Math.round(row.f_percentage * 10 * totmass) / 1000; |
|
441 $("#fermentableGrid").jqxGrid('setcellvalue', i, "f_amount", amount); |
|
442 } |
410 } |
443 } |
411 } |
444 } |
412 }; |
445 }; |
413 |
446 |
414 function getNeededYeastCells() { |
447 function getNeededYeastCells() { |
3188 { name: 'f_acid_to_ph_57', type: 'float' }, |
3221 { name: 'f_acid_to_ph_57', type: 'float' }, |
3189 { name: 'f_inventory', type: 'float' }, |
3222 { name: 'f_inventory', type: 'float' }, |
3190 { name: 'f_avail', type: 'int' } |
3223 { name: 'f_avail', type: 'int' } |
3191 ], |
3224 ], |
3192 addrow: function (rowid, rowdata, position, commit) { |
3225 addrow: function (rowid, rowdata, position, commit) { |
3193 console.log("fermentable addrow "+rowid); |
3226 //console.log("fermentable addrow "+rowid); |
3194 commit(true); |
3227 commit(true); |
3195 }, |
3228 }, |
3196 deleterow: function (rowid, commit) { |
3229 deleterow: function (rowid, commit) { |
3197 console.log("fermentable deleterow "+rowid); |
3230 //console.log("fermentable deleterow "+rowid); |
3198 commit(true); |
3231 commit(true); |
3199 }, |
3232 }, |
3200 updaterow: function (rowid, rowdata, commit) { |
3233 updaterow: function (rowid, rowdata, commit) { |
3201 console.log("fermentable updaterow "+rowid); |
3234 //console.log("fermentable updaterow "+rowid); |
3202 commit(true); |
3235 commit(true); |
3203 } |
3236 } |
3204 }; |
3237 }; |
3205 var fermentableAdapter = new $.jqx.dataAdapter(fermentableSource); |
3238 var fermentableAdapter = new $.jqx.dataAdapter(fermentableSource); |
3206 $("#fermentableGrid").jqxGrid({ |
3239 $("#fermentableGrid").jqxGrid({ |
3306 rowdata.f_percentage += percent; |
3339 rowdata.f_percentage += percent; |
3307 rowdata.f_amount += amount; |
3340 rowdata.f_amount += amount; |
3308 } |
3341 } |
3309 } |
3342 } |
3310 } else { |
3343 } else { |
3311 var tw = 0; |
3344 calcPercentages(); |
3312 for (i = 0; i < rowscount; i++) { |
|
3313 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i); |
|
3314 tw += rowdata.f_amount; |
|
3315 }; |
|
3316 for (i = 0; i < rowscount; i++) { |
|
3317 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i); |
|
3318 var percentage = Math.round(rowdata.f_amount / tw * 1000) / 10.0; |
|
3319 $("#fermentableGrid").jqxGrid('setcellvalue', i, "f_percentage", percentage); |
|
3320 }; |
|
3321 } |
3345 } |
3322 } else { |
3346 } else { |
3323 $("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100); |
3347 $("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100); |
3324 } |
3348 } |
3325 calcFermentables(); |
3349 calcFermentables(); |
3354 cellsrenderer: function (row, columnfield, value, defaulthtml, columnproperties, rowdata) { |
3378 cellsrenderer: function (row, columnfield, value, defaulthtml, columnproperties, rowdata) { |
3355 var color = '#ffffff'; |
3379 var color = '#ffffff'; |
3356 if (((dataRecord.inventory_reduced <= 2) && (rowdata.f_added <= 1)) || // Mash or boil |
3380 if (((dataRecord.inventory_reduced <= 2) && (rowdata.f_added <= 1)) || // Mash or boil |
3357 ((dataRecord.inventory_reduced <= 3) && (rowdata.f_added == 2)) || // Primary |
3381 ((dataRecord.inventory_reduced <= 3) && (rowdata.f_added == 2)) || // Primary |
3358 ((dataRecord.inventory_reduced <= 5) && (rowdata.f_added == 3)) || // Secondary or Tertiary |
3382 ((dataRecord.inventory_reduced <= 5) && (rowdata.f_added == 3)) || // Secondary or Tertiary |
3359 ((dataRecord.inventory_reduced <= 6) && (rowdata.f_added == 4))) { // Bottle |
3383 ((dataRecord.inventory_reduced <= 6) && (rowdata.f_added == 4)) || // Bottle |
|
3384 ((dataRecord.inventory_reduced <= 6) && (rowdata.f_added == 5))) { // Kegs |
3360 if (value < rowdata.f_amount) |
3385 if (value < rowdata.f_amount) |
3361 color = '#ff4040'; |
3386 color = '#ff4040'; |
3362 return '<span style="margin: 4px; margin-top: 6px; float: right; color: ' + |
3387 return '<span style="margin: 4px; margin-top: 6px; float: right; color: ' + |
3363 color + ';">' +fermentableAdapter.formatNumber(value, "f3") + '</span>'; |
3388 color + ';">' +fermentableAdapter.formatNumber(value, "f3") + '</span>'; |
3364 } else { |
3389 } else { |
3377 }, |
3402 }, |
3378 { text: '100%', align: 'center', datafield: 'f_adjust_to_total_100', columntype: 'checkbox', width: 70 }, |
3403 { text: '100%', align: 'center', datafield: 'f_adjust_to_total_100', columntype: 'checkbox', width: 70 }, |
3379 { text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', cellsrenderer: function () { |
3404 { text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', cellsrenderer: function () { |
3380 return "Wijzig"; |
3405 return "Wijzig"; |
3381 }, buttonclick: function (row) { |
3406 }, buttonclick: function (row) { |
|
3407 fermentableRow = row; |
|
3408 fermentableData = $("#fermentableGrid").jqxGrid('getrowdata', fermentableRow); |
3382 if (dataRecord.stage > 3) { |
3409 if (dataRecord.stage > 3) { |
3383 alert("Ingredieënt is al verwerkt."); |
3410 alert("Ingredieënt is al verwerkt."); |
|
3411 } else if (fermentableData.f_added >= 4) { |
|
3412 alert("Wijzig dit in de Verpakken tab"); |
3384 } else { |
3413 } else { |
3385 fermentableRow = row; |
|
3386 fermentableData = $("#fermentableGrid").jqxGrid('getrowdata', fermentableRow); |
|
3387 $("#wf_name").val(fermentableData.f_name); |
3414 $("#wf_name").val(fermentableData.f_name); |
3388 $("#wf_amount").val(fermentableData.f_amount); |
3415 $("#wf_amount").val(fermentableData.f_amount); |
3389 $("#wf_percentage").val(fermentableData.f_percentage); |
3416 $("#wf_percentage").val(fermentableData.f_percentage); |
3390 $("#wf_max_in_batch").val(fermentableData.f_max_in_batch); |
3417 $("#wf_max_in_batch").val(fermentableData.f_max_in_batch); |
3391 $("#wf_adjust_to_total_100").val(fermentableData.f_adjust_to_total_100); |
3418 $("#wf_adjust_to_total_100").val(fermentableData.f_adjust_to_total_100); |
4458 f_acid_to_ph_57: fermentableData.f_acid_to_ph_57, |
4485 f_acid_to_ph_57: fermentableData.f_acid_to_ph_57, |
4459 f_inventory: fermentableData.f_inventory, |
4486 f_inventory: fermentableData.f_inventory, |
4460 f_avail: fermentableData.f_avail |
4487 f_avail: fermentableData.f_avail |
4461 }; |
4488 }; |
4462 $("#fermentableGrid").jqxGrid('updaterow', rowID, row); |
4489 $("#fermentableGrid").jqxGrid('updaterow', rowID, row); |
4463 // Recalc percentages |
4490 calcPercentages(); |
4464 calcFermentables(); |
4491 calcFermentables(); |
4465 calcIBUs(); |
4492 calcIBUs(); |
4466 calcMash(); |
4493 calcMash(); |
4467 // Waters: yes there is impact. |
4494 // Waters: yes there is impact. |
4468 }); |
4495 }); |
4516 $('#wf_amount').on('change', function (event) { |
4543 $('#wf_amount').on('change', function (event) { |
4517 console.log("amount changed: "+event.args.value); |
4544 console.log("amount changed: "+event.args.value); |
4518 $("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_amount', event.args.value); |
4545 $("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_amount', event.args.value); |
4519 fermentableData.f_amount = event.args.value; |
4546 fermentableData.f_amount = event.args.value; |
4520 if (! to_100) { |
4547 if (! to_100) { |
4521 // Recalculate percentages |
4548 calcPercentages(); |
4522 console.log("adjust percentages"); |
|
4523 var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount; |
|
4524 if (rowscount > 1) { |
|
4525 var tw = 0; |
|
4526 for (i = 0; i < rowscount; i++) { |
|
4527 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i); |
|
4528 tw += rowdata.f_amount; |
|
4529 }; |
|
4530 for (i = 0; i < rowscount; i++) { |
|
4531 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i); |
|
4532 var percentage = Math.round(rowdata.f_amount / tw * 1000) / 10.0; |
|
4533 $("#fermentableGrid").jqxGrid('setcellvalue', i, "f_percentage", percentage); |
|
4534 // if (i == fermentableRow) // Will crash the script. |
|
4535 // $("#wf_percentage").val(percentage); |
|
4536 }; |
|
4537 } else { |
|
4538 $("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100); |
|
4539 } |
|
4540 calcFermentables(); |
4549 calcFermentables(); |
4541 calcIBUs(); |
4550 calcIBUs(); |
4542 calcMash(); |
4551 calcMash(); |
4543 }; |
4552 }; |
4544 }); |
4553 }); |
4556 } else { |
4565 } else { |
4557 var diff = newvalue - oldvalue; |
4566 var diff = newvalue - oldvalue; |
4558 var tw = 0; // total weight |
4567 var tw = 0; // total weight |
4559 for (i = 0; i < rowscount; i++) { |
4568 for (i = 0; i < rowscount; i++) { |
4560 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i); |
4569 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i); |
4561 tw += rowdata.f_amount; |
4570 if (rowdata.f_added < 4) |
|
4571 tw += Math.round(rowdata.f_amount * 1000) / 1000; |
4562 } |
4572 } |
|
4573 tw = Math.round(tw * 1000) / 1000; |
4563 if (to_100) { |
4574 if (to_100) { |
4564 // Adjust this row and the 100% row. |
4575 // Adjust this row and the 100% row. |
4565 var damount = tw * diff / 100; |
4576 var damount = Math.round(tw * diff *10) / 1000; |
4566 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', fermentableRow); |
4577 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', fermentableRow); |
4567 var namount = rowdata.f_amount + damount; |
4578 var namount = Math.round((rowdata.f_amount + damount) * 1000) / 1000; |
4568 $("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_amount', namount); |
4579 $("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_amount', namount); |
4569 $("#wf_amount").val(namount); |
4580 $("#wf_amount").val(namount); |
4570 $("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_percentage', rowdata.f_percentage + diff); |
4581 $("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_percentage', rowdata.f_percentage + diff); |
4571 for (i = 0; i < rowscount; i++) { |
4582 for (i = 0; i < rowscount; i++) { |
4572 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i); |
4583 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i); |
4582 } else { |
4593 } else { |
4583 // Adjust all the rows. |
4594 // Adjust all the rows. |
4584 var nw = tw * diff / 100; |
4595 var nw = tw * diff / 100; |
4585 for (i = 0; i < rowscount; i++) { |
4596 for (i = 0; i < rowscount; i++) { |
4586 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i); |
4597 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i); |
4587 if (i == fermentableRow) { |
4598 if (rowdata.f_added < 4) { |
4588 var namount = rowdata.f_amount + nw; |
4599 if (i == fermentableRow) { |
4589 $("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', namount); |
4600 var namount = Math.round((rowdata.f_amount + nw) * 1000) / 1000; |
4590 // $("#wf_amount").val(namount); // Will crash the script. |
4601 $("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', namount); |
4591 $("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', newvalue); |
4602 // $("#wf_amount").val(namount); // Will crash the script. |
|
4603 $("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', newvalue); |
|
4604 } else { |
|
4605 var namount = Math.round((rowdata.f_amount - (nw / (rowscount - 1))) * 1000) / 1000; |
|
4606 var newperc = Math.round((namount / tw) * 1000) / 10.0; |
|
4607 $("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', namount); |
|
4608 $("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', newperc); |
|
4609 } |
4592 } else { |
4610 } else { |
4593 var namount = rowdata.f_amount - (nw / (rowscount - 1)); |
4611 $("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', 0); |
4594 var newperc = Math.round((namount / tw) * 1000) / 10.0; |
|
4595 $("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', namount); |
|
4596 $("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', newperc); |
|
4597 } |
4612 } |
4598 } |
4613 } |
4599 calcFermentables(); |
4614 calcFermentables(); |
4600 calcIBUs(); |
4615 calcIBUs(); |
4601 calcMash(); |
4616 calcMash(); |