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 calcTotal(cost, inventory) { |
|
48 $('#totval').val(cost * inventory); |
|
49 } |
|
50 |
|
51 var dataRecord = {}, |
|
52 url = 'includes/db_inventory_fermentables.php', |
|
53 source = { |
|
54 datatype: 'json', |
|
55 cache: false, |
|
56 datafields: [ |
|
57 { name: 'record', type: 'number' }, |
|
58 { name: 'uuid', type: 'string' }, |
|
59 { name: 'name', type: 'string' }, |
|
60 { name: 'type', type: 'string' }, |
|
61 { name: 'yield', type: 'float' }, |
|
62 { name: 'color', type: 'float' }, |
|
63 { name: 'add_after_boil', type: 'int' }, |
|
64 { name: 'origin', type: 'string' }, |
|
65 { name: 'supplier', type: 'string' }, |
|
66 { name: 'notes', type: 'string' }, |
|
67 { name: 'coarse_fine_diff', type: 'float' }, |
|
68 { name: 'moisture', type: 'float' }, |
|
69 { name: 'diastatic_power', type: 'float' }, |
|
70 { name: 'protein', type: 'float' }, |
|
71 { name: 'dissolved_protein', type: 'float' }, |
|
72 { name: 'max_in_batch', type: 'float' }, |
|
73 { name: 'recommend_mash', type: 'int' }, |
|
74 { name: 'added', type: 'string' }, |
|
75 { name: 'always_on_stock', type: 'int' }, |
|
76 { name: 'di_ph', type: 'float' }, |
|
77 { name: 'acid_to_ph_57', type: 'float' }, |
|
78 { name: 'graintype', type: 'string' }, |
|
79 { name: 'inventory', type: 'float' }, |
|
80 { name: 'cost', type: 'float' }, |
|
81 { name: 'production_date', type: 'string' }, |
|
82 { name: 'tht_date', type: 'string' } |
|
83 ], |
|
84 id: 'record', |
|
85 url: url, |
|
86 deleterow: function(rowid, commit) { |
|
87 var data = 'delete=true&' + $.param({ record: rowid }); |
|
88 $.ajax({ |
|
89 dataType: 'json', |
|
90 url: url, |
|
91 cache: false, |
|
92 data: data, |
|
93 type: 'POST', |
|
94 success: function(data) { |
|
95 if (data.error) { |
|
96 console.log('delete: ' + data.msg); |
|
97 alert('Fout: ' + data.msg); |
|
98 } else { |
|
99 console.log('delete: success'); |
|
100 } |
|
101 location.reload(true); |
|
102 }, |
|
103 error: function(jqXHR, textStatus, errorThrown) { commit(false); } |
|
104 }); |
|
105 }, |
|
106 addrow: function(rowid, rowdata, position, commit) { |
|
107 var data = 'insert=true&' + $.param(rowdata); |
|
108 $.ajax({ |
|
109 dataType: 'json', |
|
110 url: url, |
|
111 cache: false, |
|
112 data: data, |
|
113 type: 'POST', |
|
114 success: function(data) { |
|
115 if (data.error) { |
|
116 console.log('insert: ' + data.msg); |
|
117 alert('Fout: ' + data.msg); |
|
118 } else { |
|
119 console.log('insert: success'); |
|
120 } |
|
121 location.reload(true); |
|
122 }, |
|
123 error: function(jqXHR, textStatus, errorThrown) { commit(false); } |
|
124 }); |
|
125 }, |
|
126 updaterow: function(rowid, rowdata, commit) { |
|
127 var data = 'update=true&' + $.param(rowdata); |
|
128 $.ajax({ |
|
129 dataType: 'json', |
|
130 url: url, |
|
131 cache: false, |
|
132 data: data, |
|
133 type: 'POST', |
|
134 success: function(data) { |
|
135 if (data.error) { |
|
136 console.log('updaterow: ' + data.msg); |
|
137 alert('Fout: ' + data.msg); |
|
138 } else { |
|
139 console.log('updaterow: success'); |
|
140 } |
|
141 location.reload(true); |
|
142 }, |
|
143 error: function(jqXHR, textStatus, errorThrown) { commit(false); } |
|
144 }); |
|
145 } |
|
146 }, |
|
147 dataAdapter = new $.jqx.dataAdapter(source), |
|
148 editrow = -1; |
|
149 |
|
150 // initialize the input fields. |
|
151 $('#name').jqxInput({ theme: theme, width: 640, height: 23 }); |
|
152 $('#type').jqxDropDownList({ |
|
153 theme: theme, |
|
154 source: FermentableTypeAdapter, |
|
155 valueMember: 'nl', |
|
156 displayMember: 'nl', |
|
157 width: 180, |
|
158 height: 23, |
|
159 autoDropDownHeight: true |
|
160 }); |
|
161 $('#yield').jqxNumberInput(Spin1dec); |
|
162 $('#color').jqxNumberInput(Spin1dec); |
|
163 $('#add_after_boil').jqxCheckBox({ theme: theme, width: 120, height: 23 }); |
|
164 $('#origin').jqxInput({ theme: theme, width: 250, height: 23 }); |
|
165 $('#supplier').jqxInput({ theme: theme, width: 250, height: 23 }); |
|
166 $('#notes').jqxInput({ theme: theme, width: 640, height: 100 }); |
|
167 $('#coarse_fine_diff').jqxNumberInput(Spin1dec); |
|
168 $('#moisture').jqxNumberInput(Spin1dec); |
|
169 $('#diastatic_power').jqxNumberInput(PosInt); |
|
170 $('#protein').jqxNumberInput(Spin1dec); |
|
171 $('#dissolved_protein').jqxNumberInput(Spin1dec); |
|
172 $('#max_in_batch').jqxNumberInput(Perc1dec); |
|
173 $('#recommend_mash').jqxCheckBox({ theme: theme, width: 120, height: 23 }); |
|
174 $('#added').jqxDropDownList({ |
|
175 theme: theme, |
|
176 source: AddedAdapter, |
|
177 valueMember: 'nl', |
|
178 displayMember: 'nl', |
|
179 width: 180, |
|
180 height: 23, |
|
181 autoDropDownHeight: true |
|
182 }); |
|
183 $('#always_on_stock').jqxCheckBox({ theme: theme, width: 120, height: 23 }); |
|
184 $('#di_ph').jqxNumberInput(Spin2pH); |
|
185 $('#acid_to_ph_57').jqxNumberInput({ inputMode: 'simple', theme: theme, width: 110, height: 23, min: -1000, max: 1000, decimalDigits: 4, spinButtons: true }); |
|
186 $('#graintype').jqxDropDownList({ |
|
187 theme: theme, |
|
188 source: GrainTypeAdapter, |
|
189 valueMember: 'nl', |
|
190 displayMember: 'nl', |
|
191 width: 180, |
|
192 height: 23, |
|
193 autoDropDownHeight: true |
|
194 }); |
|
195 $('#inventory').jqxNumberInput(Spin3dec); |
|
196 $('#production_date').jqxDateTimeInput(Dateopts); |
|
197 $('#cost').jqxNumberInput(Spin2dec); |
|
198 $('#tht_date').jqxDateTimeInput(Dateopts); |
|
199 $('#totval').jqxNumberInput(Show2dec); |
|
200 |
|
201 var localizationobj = {}; |
|
202 localizationobj.filterchoosestring= "Keuze:"; |
|
203 |
|
204 // initialize jqxGrid |
|
205 $('#jqxgrid').jqxGrid({ |
|
206 width: 1280, |
|
207 height: 630, |
|
208 source: dataAdapter, |
|
209 theme: theme, |
|
210 showstatusbar: true, |
|
211 renderstatusbar: function(statusbar) { |
|
212 var rowCount = $("#jqxgrid").jqxGrid('getrows').length; |
|
213 statusbar.append('<div style="float: left; margin: 8px; color: orange !important;">Aantal items: ' + rowCount + '</div>'); |
|
214 var container, addButton, impButton; |
|
215 container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>'); |
|
216 addButton = $('<div style="float: right; margin-right: 15px;"><img style="position: relative; margin-top: 2px;" ' + |
|
217 'src="images/add.png"/><span style="margin-left: 4px; position: relative; top: -4px;">Nieuw</span></div>'); |
|
218 impButton = $('<div style="float: right; margin-right: 50px;"><img style="position: relative; margin-top: 2px;" ' + |
|
219 'src="images/add.png"/><span style="margin-left: 4px; position: relative; top: -4px;">Import</span></div>'); |
|
220 expButton = $('<div style="float: right; margin-right: 50px;"><img style="position: relative; margin-top: 2px;" ' + |
|
221 'src="images/database.png"/><span style="margin-left: 4px; position: relative; top: -10px;">Export</span></div>'); |
|
222 container.append(addButton); |
|
223 container.append(impButton); |
|
224 container.append(expButton); |
|
225 statusbar.append(container); |
|
226 addButton.jqxButton({ theme: theme, width: 90, height: 17 }); |
|
227 impButton.jqxButton({ theme: theme, width: 90, height: 17 }); |
|
228 expButton.jqxButton({ theme: theme, width: 90, height: 17 }); |
|
229 // add new row. |
|
230 addButton.click(function(event) { |
|
231 editrow = -1; |
|
232 $('#popupWindow').jqxWindow({ position: { x: 110, y: 30 } }); |
|
233 $('#name').val('Nieuw product'); |
|
234 dataRecord.uuid = ''; |
|
235 $('#type').val('Mout'); |
|
236 $('#origin').val(''); |
|
237 $('#supplier').val(''); |
|
238 $('#notes').val(''); |
|
239 $('#yield').val(80); |
|
240 $('#color').val(3); |
|
241 $('#coarse_fine_diff').val(3); |
|
242 $('#moisture').val(4); |
|
243 $('#diastatic_power').val(0); |
|
244 $('#protein').val(0); |
|
245 $('#dissolved_protein').val(0); |
|
246 $('#max_in_batch').val(100); |
|
247 $('#recommend_mash').val(1); |
|
248 $('#always_on_stock').val(0); |
|
249 $('#di_ph').val(0); |
|
250 $('#acid_to_ph_57').val(0); |
|
251 $('#graintype').val('Basismout'); |
|
252 $('#add_after_boil').val(0); |
|
253 $('#added').val('Maischen'); |
|
254 $('#inventory').val(0); |
|
255 $('#cost').val(0); |
|
256 $('#production_date').val(''); |
|
257 $('#tht_date').val(''); |
|
258 $('#popupWindow').jqxWindow('open'); |
|
259 }); |
|
260 impButton.click(function(event) { |
|
261 window.location.href = 'import_ingredients.php?select=fermentables'; |
|
262 }); |
|
263 expButton.click(function(event) { |
|
264 window.open('export_fermentables.php'); |
|
265 }); |
|
266 }, |
|
267 ready: function () { |
|
268 $("#jqxgrid").jqxGrid('localizestrings', localizationobj); |
|
269 }, |
|
270 filterable: true, |
|
271 showfilterrow: true, |
|
272 columns: [ |
|
273 { text: 'Herkomst', datafield: 'origin', width: 150, filtertype: 'list' }, |
|
274 { text: 'Producent', datafield: 'supplier', width: 140, filtertype: 'list' }, |
|
275 { text: 'Vergistbaar product', datafield: 'name', filtertype: 'textbox' }, |
|
276 { text: 'Soort', datafield: 'type', width: 135, filtertype: 'list' }, |
|
277 { text: 'Graan type', datafield: 'graintype', width: 125, align: 'center', cellsalign: 'center', filtertype: 'list' }, |
|
278 { text: 'EBC', datafield: 'color', width: 70, align: 'right', cellsalign: 'right', filtertype: 'number' }, |
|
279 { text: 'Opbrengst', datafield: 'yield', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'p1', filterable: false }, |
|
280 { text: 'Voorraad', datafield: 'inventory', width: 100, align: 'right', filtertype: 'number', filtercondition: 'not_equal', |
|
281 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) { |
|
282 var amount = ''; |
|
283 if (value > 0) { |
|
284 if (value < 1.000) |
|
285 amount = dataAdapter.formatNumber(value * 1000, 'f0') + ' gr'; |
|
286 else |
|
287 amount = dataAdapter.formatNumber(value, 'f1') + ' kg'; |
|
288 } |
|
289 return '<span style="margin: 3px; margin-top: 6px; float: right;">' + amount + '</span>'; |
|
290 } |
|
291 }, |
|
292 { text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', filterable: false, |
|
293 cellsrenderer: function() { |
|
294 return 'Wijzig'; |
|
295 }, buttonclick: function(row) { |
|
296 // open the popup window when the user clicks a button. |
|
297 editrow = row; |
|
298 $('#popupWindow').jqxWindow({ position: { x: 110, y: 30 } }); |
|
299 // get the clicked row's data and initialize the input fields. |
|
300 dataRecord = $('#jqxgrid').jqxGrid('getrowdata', editrow); |
|
301 $('#name').val(dataRecord.name); |
|
302 $('#type').val(dataRecord.type); |
|
303 $('#yield').val(dataRecord.yield); |
|
304 $('#color').val(dataRecord.color); |
|
305 $('#add_after_boil').val(dataRecord.add_after_boil); |
|
306 $('#origin').val(dataRecord.origin); |
|
307 $('#supplier').val(dataRecord.supplier); |
|
308 $('#notes').val(dataRecord.notes); |
|
309 $('#coarse_fine_diff').val(dataRecord.coarse_fine_diff); |
|
310 $('#moisture').val(dataRecord.moisture); |
|
311 $('#diastatic_power').val(lintner_to_kolbach(dataRecord.diastatic_power)); |
|
312 $('#protein').val(dataRecord.protein); |
|
313 $('#dissolved_protein').val(dataRecord.dissolved_protein); |
|
314 $('#max_in_batch').val(dataRecord.max_in_batch); |
|
315 $('#recommend_mash').val(dataRecord.recommend_mash); |
|
316 $('#added').val(dataRecord.added); |
|
317 $('#always_on_stock').val(dataRecord.always_on_stock); |
|
318 $('#di_ph').val(dataRecord.di_ph); |
|
319 $('#acid_to_ph_57').val(dataRecord.acid_to_ph_57); |
|
320 $('#graintype').val(dataRecord.graintype); |
|
321 $('#inventory').val(dataRecord.inventory); |
|
322 $('#cost').val(dataRecord.cost); |
|
323 $('#production_date').val(dataRecord.production_date); |
|
324 $('#tht_date').val(dataRecord.tht_date); |
|
325 calcTotal(dataRecord.cost, dataRecord.inventory); |
|
326 // show the popup window. |
|
327 $('#popupWindow').jqxWindow('open'); |
|
328 } |
|
329 } |
|
330 ] |
|
331 }); |
|
332 |
|
333 $('#cost').on('change', function(event) { |
|
334 dataRecord.cost = parseFloat(event.args.value); |
|
335 calcTotal(dataRecord.cost, dataRecord.inventory); |
|
336 }); |
|
337 $('#inventory').on('change', function(event) { |
|
338 dataRecord.inventory = parseFloat(event.args.value); |
|
339 calcTotal(dataRecord.cost, dataRecord.inventory); |
|
340 }); |
|
341 |
|
342 // initialize the popup window and buttons. |
|
343 $('#popupWindow').jqxWindow({ |
|
344 width: 1050, |
|
345 height: 550, |
|
346 resizable: false, |
|
347 theme: theme, |
|
348 isModal: true, |
|
349 autoOpen: false, |
|
350 cancelButton: $('#Cancel'), |
|
351 modalOpacity: 0.40 |
|
352 }); |
|
353 $('#popupWindow').on('open', function() { |
|
354 $('#name').jqxInput('selectAll'); |
|
355 }); |
|
356 $('#Delete').jqxButton({ template: 'danger', width: '90px', theme: theme }); |
|
357 $('#Delete').click(function() { |
|
358 if (editrow >= 0) { |
|
359 // Open a popup to confirm this action. |
|
360 $('#eventWindow').jqxWindow('open'); |
|
361 $('#delOk').click(function() { |
|
362 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
|
363 $('#jqxgrid').jqxGrid('deleterow', rowID); |
|
364 }); |
|
365 } |
|
366 $('#popupWindow').jqxWindow('hide'); |
|
367 }); |
|
368 $('#Cancel').jqxButton({ template: 'primary', width: '90px', theme: theme }); |
|
369 $('#Clone').jqxButton({ template: 'warning', width: '90px', theme: theme }); |
|
370 $('#Clone').click(function() { |
|
371 var row = { |
|
372 record: -1, |
|
373 name: $('#name').val() + ' kopie', |
|
374 uuid: '', |
|
375 type: $('#type').val(), |
|
376 yield: parseFloat($('#yield').jqxNumberInput('decimal')), |
|
377 color: parseFloat($('#color').jqxNumberInput('decimal')), |
|
378 add_after_boil: $('#add_after_boil').val(), |
|
379 origin: $('#origin').val(), |
|
380 supplier: $('#supplier').val(), |
|
381 notes: $('#notes').val(), |
|
382 coarse_fine_diff: parseFloat($('#coarse_fine_diff').jqxNumberInput('decimal')), |
|
383 moisture: parseFloat($('#moisture').jqxNumberInput('decimal')), |
|
384 diastatic_power: kolbach_to_lintner(parseFloat($('#diastatic_power').jqxNumberInput('decimal'))), |
|
385 protein: parseFloat($('#protein').jqxNumberInput('decimal')), |
|
386 dissolved_protein: parseFloat($('#dissolved_protein').jqxNumberInput('decimal')), |
|
387 max_in_batch: parseFloat($('#max_in_batch').jqxNumberInput('decimal')), |
|
388 recommend_mash: $('#recommend_mash').val(), |
|
389 added: $('#added').val(), |
|
390 always_on_stock: $('#always_on_stock').val(), |
|
391 di_ph: parseFloat($('#di_ph').jqxNumberInput('decimal')), |
|
392 acid_to_ph_57: parseFloat($('#acid_to_ph_57').jqxNumberInput('decimal')), |
|
393 graintype: $('#graintype').val(), |
|
394 inventory: 0, |
|
395 cost: parseFloat($('#cost').jqxNumberInput('decimal')), |
|
396 production_date: '', |
|
397 tht_date: '' |
|
398 }; |
|
399 $('#jqxgrid').jqxGrid('addrow', null, row); |
|
400 $('#popupWindow').jqxWindow('hide'); |
|
401 }); |
|
402 $('#Save').jqxButton({ template: 'success', width: '90px', theme: theme }); |
|
403 // update the edited row when the user clicks the 'Save' button. |
|
404 $('#Save').click(function() { |
|
405 var row, rowID = -1; |
|
406 if (editrow >= 0) { |
|
407 rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
|
408 } |
|
409 row = { |
|
410 record: rowID, |
|
411 name: $('#name').val(), |
|
412 uuid: dataRecord.uuid, |
|
413 type: $('#type').val(), |
|
414 yield: parseFloat($('#yield').jqxNumberInput('decimal')), |
|
415 color: parseFloat($('#color').jqxNumberInput('decimal')), |
|
416 add_after_boil: $('#add_after_boil').val(), |
|
417 origin: $('#origin').val(), |
|
418 supplier: $('#supplier').val(), |
|
419 notes: $('#notes').val(), |
|
420 coarse_fine_diff: parseFloat($('#coarse_fine_diff').jqxNumberInput('decimal')), |
|
421 moisture: parseFloat($('#moisture').jqxNumberInput('decimal')), |
|
422 diastatic_power: kolbach_to_lintner(parseFloat($('#diastatic_power').jqxNumberInput('decimal'))), |
|
423 protein: parseFloat($('#protein').jqxNumberInput('decimal')), |
|
424 dissolved_protein: parseFloat($('#dissolved_protein').jqxNumberInput('decimal')), |
|
425 max_in_batch: parseFloat($('#max_in_batch').jqxNumberInput('decimal')), |
|
426 recommend_mash: $('#recommend_mash').val(), |
|
427 added: $('#added').val(), |
|
428 always_on_stock: $('#always_on_stock').val(), |
|
429 di_ph: parseFloat($('#di_ph').jqxNumberInput('decimal')), |
|
430 acid_to_ph_57: parseFloat($('#acid_to_ph_57').jqxNumberInput('decimal')), |
|
431 graintype: $('#graintype').val(), |
|
432 inventory: parseFloat($('#inventory').jqxNumberInput('decimal')), |
|
433 cost: parseFloat($('#cost').jqxNumberInput('decimal')), |
|
434 production_date: $('#production_date').val(), |
|
435 tht_date: $('#tht_date').val(), |
|
436 }; |
|
437 if (editrow >= 0) { |
|
438 $('#jqxgrid').jqxGrid('updaterow', rowID, row); |
|
439 } else { |
|
440 $('#jqxgrid').jqxGrid('addrow', null, row); |
|
441 } |
|
442 $('#popupWindow').jqxWindow('hide'); |
|
443 }); |
|
444 createDelElements(); |
|
445 }); |
|
446 |
|