www/js/inv_equipments.js

changeset 801
55c2510891b8
parent 800
3775ee26657f
child 802
4a9f469d2201
equal deleted inserted replaced
800:3775ee26657f 801:55c2510891b8
1 /*****************************************************************************
2 * Copyright (C) 2014-2022
3 *
4 * Michiel Broek <mbroek at mbse dot eu>
5 *
6 * This file is part of Brewery Management System
7 *
8 * This is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * BrewCloud is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with ThermFerm; see the file COPYING. If not, write to the Free
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *****************************************************************************/
22
23
24 function createDelElements() {
25 $('#eventWindow').jqxWindow({
26 theme: theme,
27 position: { x: 490, y: 210 },
28 width: 300,
29 height: 175,
30 resizable: false,
31 isModal: true,
32 modalOpacity: 0.4,
33 okButton: $('#delOk'),
34 cancelButton: $('#delCancel'),
35 initContent: function() {
36 $('#delOk').jqxButton({ template: 'danger', width: '65px', theme: theme });
37 $('#delCancel').jqxButton({ template: 'success', width: '65px', theme: theme });
38 $('#delCancel').focus();
39 }
40 });
41 $('#eventWindow').jqxWindow('hide');
42 }
43
44
45 $(document).ready(function() {
46
47 function calcBatchVolume() {
48 var calc = $('#calc_boil_volume').val(),
49 boil_size = parseFloat($('#boil_size').jqxNumberInput('decimal')),
50 evap_rate = parseFloat($('#evap_rate').jqxNumberInput('decimal')),
51 boil_time = parseFloat($('#boil_time').jqxNumberInput('decimal')),
52 top_up = parseFloat($('#top_up_kettle').jqxNumberInput('decimal')),
53 batch = parseFloat($('#batch_size').jqxNumberInput('decimal'));
54
55 if (calc) { // If checked, calculate the batch size.
56 batch = boil_size - (evap_rate * boil_time / 60) + top_up;
57 $('#batch_size').val(batch);
58 }
59 $('#vol_fermenter').val((batch / 1.04) + parseFloat($('#top_up_water').jqxNumberInput('decimal')) - parseFloat($('#trub_chiller_loss').jqxNumberInput('decimal')));
60 }
61
62 // tooltips
63 $('#name').jqxTooltip({ content: 'De unieke naam van deze brouw installatie.' });
64 $('#notes').jqxTooltip({ content: 'Extra opmerkingen over deze installatie.' });
65 $('#tun_volume').jqxTooltip({ content: 'Maisch kuip volume.' });
66 $('#tun_height').jqxTooltip({ content: 'Maisch kuip hoogte in cm.' });
67 $('#tun_weight').jqxTooltip({ content: 'Maisch kuip gewicht in Kg.' });
68 $('#tun_material').jqxTooltip({ content: 'Maisch kuip materiaal. Nodig om de juiste inmaisch temperatuur te berekenen.' });
69 $('#mash_volume').jqxTooltip({ content: 'Liters maisch water voor de eerste maisch stap.' });
70 $('#mash_max').jqxTooltip({ content: 'Maximale moutstort voor deze installatie in Kg.' });
71 $('#lauter_volume').jqxTooltip({ content: 'Totaal filter volume.' });
72 $('#lauter_height').jqxTooltip({ content: 'Hoogte van de filterpan in cm.' });
73 $('#lauter_deadspace').jqxTooltip({ content: 'Volume verlies in de filterpan.' });
74 $('#efficiency').jqxTooltip({ content: 'Gemiddeld brouwzaalrendement.' });
75 $('#kettle_volume').jqxTooltip({ content: 'Kook ketel volume in liters.' });
76 $('#kettle_height').jqxTooltip({ content: 'Kook ketel hoogte in cm.' });
77 $('#boil_size').jqxTooltip({ content: 'Volume in liters voor de kook bij 100&deg;C in de kook ketel.' });
78 $('#evap_rate').jqxTooltip({ content: 'Verdamping in liters per uur.' });
79 $('#boil_time').jqxTooltip({ content: 'Kooktijd in minuten.' });
80 $('#top_up_kettle').jqxTooltip({ content: 'Extra water toevoegen tijdens het koken.' });
81 $('#hop_utilization').jqxTooltip({ content: '100% voor kleinere installaties, hoger voor grote brouwerijen.' });
82 $('#batch_size').jqxTooltip({ content: 'Volume bij 100&deg;C aan het einde van de kook.' });
83 $('#trub_chiller_loss').jqxTooltip({ content: 'Standaard verlies in liters tijdens koelen en overbrengen van de wort naar het gistvat.' });
84 $('#top_up_water').jqxTooltip({ content: 'Extra water toe te voegen in het gistvat.' });
85 $('#vol_fermenter').jqxTooltip({ content: 'Het aantal liters in het gistvat.' });
86
87 var dataRecord = {},
88 url = 'includes/db_inventory_equipments.php',
89 // prepare the data
90 source = {
91 datatype: 'json',
92 cache: false,
93 datafields: [
94 { name: 'record', type: 'number' },
95 { name: 'uuid', type: 'string' },
96 { name: 'name', type: 'string' },
97 { name: 'boil_size', type: 'float' },
98 { name: 'batch_size', type: 'float' },
99 { name: 'tun_volume', type: 'float' },
100 { name: 'tun_weight', type: 'float' },
101 { name: 'tun_specific_heat', type: 'float' },
102 { name: 'tun_material', type: 'int' },
103 { name: 'tun_height', type: 'float' },
104 { name: 'top_up_water', type: 'float' },
105 { name: 'trub_chiller_loss', type: 'float' },
106 { name: 'evap_rate', type: 'float' },
107 { name: 'boil_time', type: 'float' },
108 { name: 'calc_boil_volume', type: 'int' },
109 { name: 'top_up_kettle', type: 'float' },
110 { name: 'hop_utilization', type: 'float' },
111 { name: 'notes', type: 'string' },
112 { name: 'lauter_volume', type: 'float' },
113 { name: 'lauter_height', type: 'float' },
114 { name: 'lauter_deadspace', type: 'float' },
115 { name: 'kettle_volume', type: 'float' },
116 { name: 'kettle_height', type: 'float' },
117 { name: 'mash_volume', type: 'float' },
118 { name: 'mash_max', type: 'float' },
119 { name: 'efficiency', type: 'float' }
120 ],
121 id: 'record',
122 url: url,
123 deleterow: function(rowid, commit) {
124 // synchronize with the server - send delete command
125 var data = 'delete=true&' + $.param({ record: rowid });
126 $.ajax({
127 dataType: 'json',
128 url: url,
129 cache: false,
130 data: data,
131 type: 'POST',
132 success: function(data) {
133 if (data.error) {
134 console.log('delete: ' + data.msg);
135 alert('Fout: ' + data.msg);
136 } else {
137 console.log('delete: success');
138 }
139 //commit(true);
140 location.reload(true);
141 },
142 error: function(jqXHR, textStatus, errorThrown) { commit(false); }
143 });
144 },
145 addrow: function(rowid, rowdata, position, commit) {
146 var data = 'insert=true&' + $.param(rowdata);
147 $.ajax({
148 dataType: 'json',
149 url: url,
150 cache: false,
151 data: data,
152 type: 'POST',
153 success: function(data) {
154 if (data.error) {
155 console.log('insert: ' + data.msg);
156 alert('Fout: ' + data.msg);
157 } else {
158 console.log('insert: success');
159 }
160 location.reload(true);
161 },
162 error: function(jqXHR, textStatus, errorThrown) { commit(false); }
163 });
164 },
165 updaterow: function(rowid, rowdata, commit) {
166 var data = 'update=true&' + $.param(rowdata);
167 $.ajax({
168 dataType: 'json',
169 url: url,
170 cache: false,
171 data: data,
172 type: 'POST',
173 success: function(data) {
174 if (data.error) {
175 console.log('updaterow: ' + data.msg);
176 alert('Fout: ' + data.msg);
177 } else {
178 console.log('updaterow: success');
179 }
180 //commit(true);
181 location.reload(true);
182 },
183 error: function(jqXHR, textStatus, errorThrown) { console.log('updaterow: ' + textStatus); commit(false); }
184 });
185 }
186 },
187 dataAdapter = new $.jqx.dataAdapter(source),
188 editrow = -1;
189
190 // initialize the input fields.
191 $('#name').jqxInput({ theme: theme, width: 250, height: 23 });
192 $('#notes').jqxInput({ theme: theme, width: 640, height: 100 });
193 $('#boil_size').jqxNumberInput(Spin1dec);
194 $('#batch_size').jqxNumberInput(Spin2dec);
195 $('#batch_size').jqxNumberInput({ spinButtonsStep: 0.5 });
196 $('#tun_volume').jqxNumberInput(Spin1dec);
197 $('#tun_weight').jqxNumberInput(Spin2dec);
198 $('#tun_specific_heat').jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 3 });
199 $('#tun_material').jqxDropDownList({
200 theme: theme,
201 source: MaterialAdapter,
202 valueMember: 'id',
203 displayMember: 'nl',
204 width: 180,
205 height: 23,
206 autoDropDownHeight: true
207 });
208 $('#tun_height').jqxNumberInput(Spin1dec);
209 $('#top_up_water').jqxNumberInput(Spin1dec);
210 $('#trub_chiller_loss').jqxNumberInput(Spin1dec);
211 $('#evap_rate').jqxNumberInput(Spin2dec);
212 $('#boil_time').jqxNumberInput(PosInt);
213 $('#boil_time').jqxNumberInput({ max: 1440 });
214 $('#calc_boil_volume').jqxCheckBox({ theme: theme, width: 120, height: 23 });
215 $('#calc_boil_volume').on('checked', function(event) {
216 $('#batch_size').jqxNumberInput({ readOnly: true, width: 90, spinButtons: false });
217 });
218 $('#calc_boil_volume').on('unchecked', function(event) {
219 $('#batch_size').jqxNumberInput({ readOnly: false, width: 110, spinButtons: true });
220 });
221 $('#top_up_kettle').jqxNumberInput(Spin1dec);
222 $('#hop_utilization').jqxNumberInput(Perc0);
223 $('#hop_utilization').jqxNumberInput({ Max: 200 });
224 $('#lauter_volume').jqxNumberInput(Spin1dec);
225 $('#lauter_height').jqxNumberInput(Spin1dec);
226 $('#lauter_deadspace').jqxNumberInput(Spin1dec);
227 $('#kettle_volume').jqxNumberInput(Spin1dec);
228 $('#kettle_height').jqxNumberInput(Spin1dec);
229 $('#mash_volume').jqxNumberInput(Spin1dec);
230 $('#mash_max').jqxNumberInput(Spin1dec);
231 $('#efficiency').jqxNumberInput(Perc1dec);
232 $('#vol_fermenter').jqxNumberInput(Show2dec);
233
234 // initialize jqxGrid
235 $('#jqxgrid').jqxGrid({
236 width: 1280,
237 height: 630,
238 source: dataAdapter,
239 theme: theme,
240 showstatusbar: true,
241 renderstatusbar: function(statusbar) {
242 var rowCount = $("#jqxgrid").jqxGrid('getrows').length;
243 statusbar.append('<div style="float: left; margin: 8px; color: orange !important;">Aantal items: ' + rowCount + '</div>');
244 var addButton, container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');
245 addButton = $('<div style="float: right; margin-right: 15px;"><img style="position: relative; margin-top: 2px;" ' +
246 'src="images/add.png"/><span style="margin-left: 4px; position: relative; top: -4px;">Nieuw</span></div>');
247 expButton = $('<div style="float: right; margin-right: 50px;"><img style="position: relative; margin-top: 2px;" ' +
248 'src="images/database.png"/><span style="margin-left: 4px; position: relative; top: -10px;">Export</span></div>');
249 container.append(addButton);
250 container.append(expButton);
251 statusbar.append(container);
252 addButton.jqxButton({ theme: theme, width: 90, height: 17 });
253 expButton.jqxButton({ theme: theme, width: 90, height: 17 });
254 // add new row.
255 addButton.click(function(event) {
256 editrow = -1;
257 $('#popupWindow').jqxWindow({ position: { x: 110, y: 30 } });
258 $('#name').val('Nieuwe brouwset');
259 dataRecord.uuid = '';
260 $('#boil_size').val(18);
261 $('#batch_size').val(15.3);
262 $('#vol_fermenter').val(14.2);
263 $('#tun_volume').val(20);
264 $('#tun_weight').val(2);
265 $('#tun_specific_heat').val(0.11);
266 $('#tun_material').val(0);
267 $('#tun_height').val(20);
268 $('#top_up_water').val(0);
269 $('#trub_chiller_loss').val(0.5);
270 $('#evap_rate').val(1.8);
271 $('#boil_time').val(90);
272 $('#calc_boil_volume').val(1);
273 $('#top_up_kettle').val(0);
274 $('#hop_utilization').val(100);
275 $('#notes').val('');
276 $('#lauter_volume').val(20);
277 $('#lauter_height').val(20);
278 $('#lauter_deadspace').val(0.5);
279 $('#kettle_volume').val(20);
280 $('#kettle_height').val(20);
281 $('#mash_volume').val(18);
282 $('#mash_max').val(6);
283 $('#efficiency').val(75);
284 $('#popupWindow').jqxWindow('open');
285 });
286 expButton.click(function(event) {
287 window.open('export_equipments.php');
288 });
289 },
290 filterable: false,
291 ready: function() {
292 $('#boil_size').on('change', function(event) { calcBatchVolume(); });
293 $('#evap_rate').on('change', function(event) { calcBatchVolume(); });
294 $('#boil_time').on('change', function(event) { calcBatchVolume(); });
295 $('#top_up_kettle').on('change', function(event) { calcBatchVolume(); });
296 $('#calc_boil_volume').on('change', function(event) { calcBatchVolume(); });
297 $('#top_up_water').on('change', function(event) { calcBatchVolume(); });
298 $('#trub_chiller_loss').on('change', function(event) { calcBatchVolume(); });
299 $('#tun_material').on('select', function(event) {
300 dataRecord.tun_specific_heat = MaterialData[event.args.index].sh;
301 $('#tun_specific_heat').val(dataRecord.tun_specific_heat);
302 });
303 },
304 columns: [
305 { text: 'Installatie naam', datafield: 'name', width: 200 },
306 { text: 'Kook volume', datafield: 'boil_size', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
307 { text: 'Batch volume', datafield: 'batch_size', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
308 { text: 'Opmerkingen', datafield: 'notes' },
309 { text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', cellsrenderer: function() {
310 return 'Wijzig';
311 }, buttonclick: function(row) {
312 // open the popup window when the user clicks a button.
313 editrow = row;
314 $('#popupWindow').jqxWindow({ position: { x: 110, y: 30 } });
315 // get the clicked row's data and initialize the input fields.
316 dataRecord = $('#jqxgrid').jqxGrid('getrowdata', editrow);
317 $('#name').val(dataRecord.name);
318 $('#boil_size').val(dataRecord.boil_size);
319 $('#batch_size').val(dataRecord.batch_size);
320 $('#tun_volume').val(dataRecord.tun_volume);
321 $('#tun_weight').val(dataRecord.tun_weight);
322 $('#tun_specific_heat').val(dataRecord.tun_specific_heat);
323 $('#tun_material').val(dataRecord.tun_material);
324 $('#tun_height').val(dataRecord.tun_height);
325 $('#top_up_water').val(dataRecord.top_up_water);
326 $('#trub_chiller_loss').val(dataRecord.trub_chiller_loss);
327 $('#evap_rate').val(dataRecord.evap_rate);
328 $('#boil_time').val(dataRecord.boil_time);
329 $('#calc_boil_volume').val(dataRecord.calc_boil_volume);
330 $('#top_up_kettle').val(dataRecord.top_up_kettle);
331 $('#hop_utilization').val(dataRecord.hop_utilization);
332 $('#notes').val(dataRecord.notes);
333 $('#lauter_volume').val(dataRecord.lauter_volume);
334 $('#lauter_height').val(dataRecord.lauter_height);
335 $('#lauter_deadspace').val(dataRecord.lauter_deadspace);
336 $('#kettle_volume').val(dataRecord.kettle_volume);
337 $('#kettle_height').val(dataRecord.kettle_height);
338 $('#mash_volume').val(dataRecord.mash_volume);
339 $('#mash_max').val(dataRecord.mash_max);
340 $('#efficiency').val(dataRecord.efficiency);
341 // show the popup window.
342 $('#popupWindow').jqxWindow('open');
343 }
344 }
345 ]
346 });
347 // initialize the popup window and buttons.
348 $('#popupWindow').jqxWindow({
349 width: 1050,
350 height: 600,
351 resizable: false,
352 theme: theme,
353 isModal: true,
354 autoOpen: false,
355 cancelButton: $('#Cancel'),
356 modalOpacity: 0.40
357 });
358 $('#popupWindow').on('open', function() {
359 $('#name').jqxInput('selectAll');
360 });
361 $('#Delete').jqxButton({ template: 'danger', width: '90px', theme: theme });
362 $('#Delete').click(function() {
363 if (editrow >= 0) {
364 // Open a popup to confirm this action.
365 $('#eventWindow').jqxWindow('open');
366 $('#delOk').click(function() {
367 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
368 $('#jqxgrid').jqxGrid('deleterow', rowID);
369 });
370 }
371 $('#popupWindow').jqxWindow('hide');
372 });
373 $('#Cancel').jqxButton({ template: 'primary', width: '90px', theme: theme });
374 $('#Clone').jqxButton({ template: 'warning', width: '90px', theme: theme });
375 $('#Clone').click(function() {
376 var row = {
377 record: -1,
378 name: $('#name').val() + ' kopie',
379 uuid: '',
380 boil_size: parseFloat($('#boil_size').jqxNumberInput('decimal')),
381 batch_size: parseFloat($('#batch_size').jqxNumberInput('decimal')),
382 tun_volume: parseFloat($('#tun_volume').jqxNumberInput('decimal')),
383 tun_weight: parseFloat($('#tun_weight').jqxNumberInput('decimal')),
384 tun_specific_heat: parseFloat($('#tun_specific_heat').jqxNumberInput('decimal')),
385 tun_material: $('#tun_material').val(),
386 tun_height: parseFloat($('#tun_height').jqxNumberInput('decimal')),
387 top_up_water: parseFloat($('#top_up_water').jqxNumberInput('decimal')),
388 trub_chiller_loss: parseFloat($('#trub_chiller_loss').jqxNumberInput('decimal')),
389 evap_rate: parseFloat($('#evap_rate').jqxNumberInput('decimal')),
390 boil_time: parseFloat($('#boil_time').jqxNumberInput('decimal')),
391 calc_boil_volume: $('#calc_boil_volume').val(),
392 top_up_kettle: parseFloat($('#top_up_kettle').jqxNumberInput('decimal')),
393 hop_utilization: parseFloat($('#hop_utilization').jqxNumberInput('decimal')),
394 notes: $('#notes').val(),
395 lauter_volume: parseFloat($('#lauter_volume').jqxNumberInput('decimal')),
396 lauter_height: parseFloat($('#lauter_height').jqxNumberInput('decimal')),
397 lauter_deadspace: parseFloat($('#lauter_deadspace').jqxNumberInput('decimal')),
398 kettle_volume: parseFloat($('#kettle_volume').jqxNumberInput('decimal')),
399 kettle_height: parseFloat($('#kettle_height').jqxNumberInput('decimal')),
400 mash_volume: parseFloat($('#mash_volume').jqxNumberInput('decimal')),
401 mash_max: parseFloat($('#mash_max').jqxNumberInput('decimal')),
402 efficiency: parseFloat($('#efficiency').jqxNumberInput('decimal'))
403 };
404 $('#jqxgrid').jqxGrid('addrow', null, row);
405 $('#popupWindow').jqxWindow('hide');
406 });
407 $('#Save').jqxButton({ template: 'success', width: '90px', theme: theme });
408 // update the edited row when the user clicks the 'Save' button.
409 $('#Save').click(function() {
410 var row, rowID = -1;
411 if (editrow >= 0) {
412 rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
413 }
414 row = {
415 record: rowID,
416 name: $('#name').val(),
417 uuid: dataRecord.uuid,
418 boil_size: parseFloat($('#boil_size').jqxNumberInput('decimal')),
419 batch_size: parseFloat($('#batch_size').jqxNumberInput('decimal')),
420 tun_volume: parseFloat($('#tun_volume').jqxNumberInput('decimal')),
421 tun_weight: parseFloat($('#tun_weight').jqxNumberInput('decimal')),
422 tun_specific_heat: parseFloat($('#tun_specific_heat').jqxNumberInput('decimal')),
423 tun_material: $('#tun_material').val(),
424 tun_height: parseFloat($('#tun_height').jqxNumberInput('decimal')),
425 top_up_water: parseFloat($('#top_up_water').jqxNumberInput('decimal')),
426 trub_chiller_loss: parseFloat($('#trub_chiller_loss').jqxNumberInput('decimal')),
427 evap_rate: parseFloat($('#evap_rate').jqxNumberInput('decimal')),
428 boil_time: parseFloat($('#boil_time').jqxNumberInput('decimal')),
429 calc_boil_volume: $('#calc_boil_volume').val(),
430 top_up_kettle: parseFloat($('#top_up_kettle').jqxNumberInput('decimal')),
431 hop_utilization: parseFloat($('#hop_utilization').jqxNumberInput('decimal')),
432 notes: $('#notes').val(),
433 lauter_volume: parseFloat($('#lauter_volume').jqxNumberInput('decimal')),
434 lauter_height: parseFloat($('#lauter_height').jqxNumberInput('decimal')),
435 lauter_deadspace: parseFloat($('#lauter_deadspace').jqxNumberInput('decimal')),
436 kettle_volume: parseFloat($('#kettle_volume').jqxNumberInput('decimal')),
437 kettle_height: parseFloat($('#kettle_height').jqxNumberInput('decimal')),
438 mash_volume: parseFloat($('#mash_volume').jqxNumberInput('decimal')),
439 mash_max: parseFloat($('#mash_max').jqxNumberInput('decimal')),
440 efficiency: parseFloat($('#efficiency').jqxNumberInput('decimal'))
441 };
442 if (editrow >= 0) {
443 $('#jqxgrid').jqxGrid('updaterow', rowID, row);
444 } else {
445 $('#jqxgrid').jqxGrid('addrow', null, row);
446 }
447 $('#popupWindow').jqxWindow('hide');
448 });
449 createDelElements();
450 });
451

mercurial