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