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 // tooltips |
|
48 $('#name').jqxTooltip({ content: 'De unieke naam van dit brouwwater.' }); |
|
49 $('#notes').jqxTooltip({ content: 'Extra opmerkingen over dit water.' }); |
|
50 $('#unlimited_stock').jqxTooltip({ content: 'Onbeperkte voorraad zoals kraanwater en bronnen.' }); |
|
51 $('#calcium').jqxTooltip({ content: 'Calcium (Ca).' }); |
|
52 $('#bicarbonate').jqxTooltip({ content: 'Bicarbonaat (HCO3). Berekend meteen de Totale alkaliteit.' }); |
|
53 $('#sulfate').jqxTooltip({ content: 'Calcium Sulfaat (CaSO4).' }); |
|
54 $('#chloride').jqxTooltip({ content: 'Chloride (Cl).' }); |
|
55 $('#sodium').jqxTooltip({ content: 'Natrium, oftewel keukenzout (Na). In berekeningen ook vaak als Sodium.' }); |
|
56 $('#magnesium').jqxTooltip({ content: 'Magnesium (Mg).' }); |
|
57 $('#ph').jqxTooltip({ content: 'De zuurgraad (pH).' }); |
|
58 $('#total_alkalinity').jqxTooltip({ content: 'Totale alkaliniteit. Berekend meteen de Bicarbonaat.' }); |
|
59 $('#balance').jqxTooltip({ content: 'De ionen balans van het water. Ideaal minder dan 0.1 verschil tussen kationen en anionen. Meer dan 0.5 is een fout in het waterraport.' }); |
|
60 $('#inventory').jqxTooltip({ content: 'Voorraad in liters.' }); |
|
61 $('#cost').jqxTooltip({ content: 'Kostprijs per liter. 5 cijfers achter de comma zodat het kraanwater er ook in kan.' }); |
|
62 |
|
63 var dataRecord = {}, |
|
64 url = 'includes/db_inventory_water.php', |
|
65 // prepare the data |
|
66 source = { |
|
67 datatype: 'json', |
|
68 cache: false, |
|
69 datafields: [ |
|
70 { name: 'record', type: 'number' }, |
|
71 { name: 'uuid', type: 'string' }, |
|
72 { name: 'name', type: 'string' }, |
|
73 { name: 'unlimited_stock', type: 'int' }, |
|
74 { name: 'calcium', type: 'float' }, |
|
75 { name: 'bicarbonate', type: 'float' }, |
|
76 { name: 'sulfate', type: 'float' }, |
|
77 { name: 'chloride', type: 'float' }, |
|
78 { name: 'sodium', type: 'float' }, |
|
79 { name: 'magnesium', type: 'float' }, |
|
80 { name: 'ph', type: 'float' }, |
|
81 { name: 'notes', type: 'string' }, |
|
82 { name: 'total_alkalinity', type: 'float' }, |
|
83 { name: 'inventory', type: 'float' }, |
|
84 { name: 'cost', type: 'float' } |
|
85 ], |
|
86 id: 'record', |
|
87 url: url, |
|
88 deleterow: function(rowid, commit) { |
|
89 // synchronize with the server - send delete command |
|
90 var data = 'delete=true&' + $.param({ record: rowid }); |
|
91 $.ajax({ |
|
92 dataType: 'json', |
|
93 url: url, |
|
94 cache: false, |
|
95 data: data, |
|
96 type: 'POST', |
|
97 success: function(data) { |
|
98 if (data.error) { |
|
99 console.log('delete: ' + data.msg); |
|
100 alert('Fout: ' + data.msg); |
|
101 } else { |
|
102 console.log('delete: success'); |
|
103 } |
|
104 location.reload(true); |
|
105 }, |
|
106 error: function(jqXHR, textStatus, errorThrown) { commit(false); } |
|
107 }); |
|
108 }, |
|
109 addrow: function(rowid, rowdata, position, commit) { |
|
110 var data = 'insert=true&' + $.param(rowdata); |
|
111 $.ajax({ |
|
112 dataType: 'json', |
|
113 url: url, |
|
114 cache: false, |
|
115 data: data, |
|
116 type: 'POST', |
|
117 success: function(data) { |
|
118 if (data.error) { |
|
119 console.log('insert: ' + data.msg); |
|
120 alert('Fout: ' + data.msg); |
|
121 } else { |
|
122 console.log('insert: success'); |
|
123 } |
|
124 location.reload(true); |
|
125 }, |
|
126 error: function(jqXHR, textStatus, errorThrown) { commit(false); } |
|
127 }); |
|
128 }, |
|
129 updaterow: function(rowid, rowdata, commit) { |
|
130 var data = 'update=true&' + $.param(rowdata); |
|
131 $.ajax({ |
|
132 dataType: 'json', |
|
133 url: url, |
|
134 cache: false, |
|
135 data: data, |
|
136 type: 'POST', |
|
137 success: function(data) { |
|
138 if (data.error) { |
|
139 console.log('updaterow: ' + data.msg); |
|
140 alert('Fout: ' + data.msg); |
|
141 } else { |
|
142 console.log('updaterow: success'); |
|
143 } |
|
144 location.reload(true); |
|
145 }, |
|
146 error: function(jqXHR, textStatus, errorThrown) { commit(false); } |
|
147 }); |
|
148 } |
|
149 }, |
|
150 dataAdapter = new $.jqx.dataAdapter(source), |
|
151 editrow = -1; |
|
152 |
|
153 // initialize the input fields. |
|
154 $('#name').jqxInput({ theme: theme, width: 640, height: 23 }); |
|
155 $('#notes').jqxInput({ theme: theme, width: 640, height: 100 }); |
|
156 $('#unlimited_stock').jqxCheckBox({ theme: theme, width: 120, height: 23 }); |
|
157 $('#calcium').jqxNumberInput(Spin1dec); |
|
158 $('#bicarbonate').jqxNumberInput(Spin1dec); |
|
159 $('#sulfate').jqxNumberInput(Spin1dec); |
|
160 $('#chloride').jqxNumberInput(Spin1dec); |
|
161 $('#sodium').jqxNumberInput(Spin1dec); |
|
162 $('#magnesium').jqxNumberInput(Spin1dec); |
|
163 $('#ph').jqxNumberInput(Spin2pH); |
|
164 $('#total_alkalinity').jqxNumberInput(Spin1dec); |
|
165 $('#balance').jqxNumberInput(Show2dec); |
|
166 $('#inventory').jqxNumberInput(Spin1dec); |
|
167 $('#cost').jqxNumberInput({inputMode: 'simple', theme: theme, width: 110, height: 23, min: 0, decimalDigits: 5, spinButtons: true }); |
|
168 |
|
169 // initialize jqxGrid |
|
170 $('#jqxgrid').jqxGrid({ |
|
171 width: 1280, |
|
172 height: 630, |
|
173 source: dataAdapter, |
|
174 theme: theme, |
|
175 showstatusbar: true, |
|
176 renderstatusbar: function(statusbar) { |
|
177 var rowCount = $("#jqxgrid").jqxGrid('getrows').length; |
|
178 statusbar.append('<div style="float: left; margin: 8px; color: orange !important;">Aantal items: ' + rowCount + '</div>'); |
|
179 var addButton, container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>'); |
|
180 addButton = $('<div style="float: right; margin-right: 15px;"><img style="position: relative; margin-top: 2px;" ' + |
|
181 'src="images/add.png"/><span style="margin-left: 4px; position: relative; top: -4px;">Nieuw</span></div>'); |
|
182 expButton = $('<div style="float: right; margin-right: 50px;"><img style="position: relative; margin-top: 2px;" ' + |
|
183 'src="images/database.png"/><span style="margin-left: 4px; position: relative; top: -10px;">Export</span></div>'); |
|
184 container.append(addButton); |
|
185 container.append(expButton); |
|
186 statusbar.append(container); |
|
187 addButton.jqxButton({ theme: theme, width: 90, height: 17 }); |
|
188 expButton.jqxButton({ theme: theme, width: 90, height: 17 }); |
|
189 // add new row. |
|
190 addButton.click(function(event) { |
|
191 editrow = -1; |
|
192 $('#popupWindow').jqxWindow({ position: { x: 110, y: 30 } }); |
|
193 $('#name').val('Nieuw brouwwater'); |
|
194 dataRecord.uuid = ''; |
|
195 $('#unlimited_stock').val(0); |
|
196 $('#calcium').val(0); |
|
197 $('#bicarbonate').val(0); |
|
198 $('#sulfate').val(0); |
|
199 $('#chloride').val(0); |
|
200 $('#sodium').val(0); |
|
201 $('#magnesium').val(0); |
|
202 $('#ph').val(7); |
|
203 $('#notes').val(''); |
|
204 $('#total_alkalinity').val(0); |
|
205 $('#inventory').val(0); |
|
206 $('#cost').val(0); |
|
207 $('#popupWindow').jqxWindow('open'); |
|
208 }); |
|
209 expButton.click(function(event) { |
|
210 window.open('export_waters.php'); |
|
211 }); |
|
212 }, |
|
213 filterable: false, |
|
214 columns: [ |
|
215 { text: 'Water leverancier', datafield: 'name', width: 225 }, |
|
216 { text: 'Opmerkingen', datafield: 'notes' }, |
|
217 { text: 'Onbeperkt', datafield: 'unlimited_stock', columntype: 'checkbox', width: 80 }, |
|
218 { text: 'Voorraad', datafield: 'inventory', width: 100, align: 'right', cellsalign: 'right', cellsformat: 'f1', |
|
219 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) { |
|
220 var amount = ''; |
|
221 if (value > 0 && rowdata.unlimited_stock == 0) |
|
222 amount = dataAdapter.formatNumber(value, 'f1') + ' L'; |
|
223 return '<span style="margin: 3px; margin-top: 6px; float: right;">' + amount + '</span>'; |
|
224 } |
|
225 }, |
|
226 { text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', |
|
227 cellsrenderer: function() { |
|
228 return 'Wijzig'; |
|
229 }, buttonclick: function(row) { |
|
230 // open the popup window when the user clicks a button. |
|
231 editrow = row; |
|
232 $('#popupWindow').jqxWindow({ position: { x: 110, y: 30 } }); |
|
233 // get the clicked row's data and initialize the input fields. |
|
234 dataRecord = $('#jqxgrid').jqxGrid('getrowdata', editrow); |
|
235 $('#name').val(dataRecord.name); |
|
236 $('#unlimited_stock').val(dataRecord.unlimited_stock); |
|
237 $('#calcium').val(dataRecord.calcium); |
|
238 $('#bicarbonate').val(dataRecord.bicarbonate); |
|
239 $('#sulfate').val(dataRecord.sulfate); |
|
240 $('#chloride').val(dataRecord.chloride); |
|
241 $('#sodium').val(dataRecord.sodium); |
|
242 $('#magnesium').val(dataRecord.magnesium); |
|
243 $('#ph').val(dataRecord.ph); |
|
244 $('#notes').val(dataRecord.notes); |
|
245 $('#total_alkalinity').val(dataRecord.total_alkalinity); |
|
246 $('#inventory').val(dataRecord.inventory); |
|
247 $('#cost').val(dataRecord.cost); |
|
248 // show the popup window. |
|
249 calcBalance(); |
|
250 $('#popupWindow').jqxWindow('open'); |
|
251 } |
|
252 } |
|
253 ] |
|
254 }); |
|
255 |
|
256 function calcBalance() { |
|
257 var cations = (dataRecord.calcium / 20.039) + (dataRecord.magnesium / 12.1525) + (dataRecord.sodium / 22.989); |
|
258 var anions = (dataRecord.bicarbonate / 61.016) + (dataRecord.sulfate / 48.031) + (dataRecord.chloride / 35.4527); |
|
259 var balance = Round(cations - anions, 2); |
|
260 $('#balance').val(balance); |
|
261 if (balance <= 0.1 && balance >= -0.1) |
|
262 $('#wr_balance').html("<img src='images/dialog-ok-apply.png'>"); |
|
263 else if (balance <= 0.5 && balance >= -0.5) |
|
264 $('#wr_balance').html("<img src='images/dialog-ok.png'>"); |
|
265 else |
|
266 $('#wr_balance').html("<img src='images/dialog-error.png'>"); |
|
267 } |
|
268 |
|
269 $('#calcium').on('change', function(event) { |
|
270 dataRecord.calcium = parseFloat(event.args.value); |
|
271 calcBalance(); |
|
272 }); |
|
273 $('#magnesium').on('change', function(event) { |
|
274 dataRecord.magnesium = parseFloat(event.args.value); |
|
275 calcBalance(); |
|
276 }); |
|
277 $('#sodium').on('change', function(event) { |
|
278 dataRecord.sodium = parseFloat(event.args.value); |
|
279 calcBalance(); |
|
280 }); |
|
281 $('#total_alkalinity').on('change', function(event) { |
|
282 dataRecord.total_alkalinity = parseFloat(event.args.value); |
|
283 dataRecord.bicarbonate = parseFloat(event.args.value) * 1.22; |
|
284 $('#bicarbonate').val(dataRecord.bicarbonate); |
|
285 calcBalance(); |
|
286 }); |
|
287 $('#bicarbonate').on('change', function(event) { |
|
288 dataRecord.bicarbonate = parseFloat(event.args.value); |
|
289 dataRecord.total_alkalinity = parseFloat(event.args.value) * 50 / 61; |
|
290 $('#total_alkalinity').val(dataRecord.total_alkalinity); |
|
291 calcBalance(); |
|
292 }); |
|
293 $('#sulfate').on('change', function(event) { |
|
294 dataRecord.sulfate = parseFloat(event.args.value); |
|
295 calcBalance(); |
|
296 }); |
|
297 $('#chloride').on('change', function(event) { |
|
298 dataRecord.chloride = parseFloat(event.args.value); |
|
299 calcBalance(); |
|
300 }); |
|
301 |
|
302 // initialize the popup window and buttons. |
|
303 $('#popupWindow').jqxWindow({ |
|
304 width: 1050, |
|
305 height: 550, |
|
306 resizable: false, |
|
307 theme: theme, |
|
308 isModal: true, |
|
309 autoOpen: false, |
|
310 cancelButton: $('#Cancel'), |
|
311 modalOpacity: 0.40 |
|
312 }); |
|
313 $('#popupWindow').on('open', function() { |
|
314 $('#name').jqxInput('selectAll'); |
|
315 }); |
|
316 $('#Delete').jqxButton({ template: 'danger', width: '90px', theme: theme }); |
|
317 $('#Delete').click(function() { |
|
318 if (editrow >= 0) { |
|
319 // Open a popup to confirm this action. |
|
320 $('#eventWindow').jqxWindow('open'); |
|
321 $('#delOk').click(function() { |
|
322 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
|
323 $('#jqxgrid').jqxGrid('deleterow', rowID); |
|
324 }); |
|
325 } |
|
326 $('#popupWindow').jqxWindow('hide'); |
|
327 }); |
|
328 $('#Cancel').jqxButton({ template: 'primary', width: '90px', theme: theme }); |
|
329 $('#Save').jqxButton({ template: 'success', width: '90px', theme: theme }); |
|
330 // update the edited row when the user clicks the 'Save' button. |
|
331 $('#Save').click(function() { |
|
332 var row, rowID = -1; |
|
333 if (editrow >= 0) { |
|
334 rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
|
335 } |
|
336 row = { |
|
337 record: rowID, |
|
338 name: $('#name').val(), |
|
339 uuid: dataRecord.uuid, |
|
340 unlimited_stock: $('#unlimited_stock').val(), |
|
341 calcium: parseFloat($('#calcium').jqxNumberInput('decimal')), |
|
342 bicarbonate: parseFloat($('#bicarbonate').jqxNumberInput('decimal')), |
|
343 sulfate: parseFloat($('#sulfate').jqxNumberInput('decimal')), |
|
344 chloride: parseFloat($('#chloride').jqxNumberInput('decimal')), |
|
345 sodium: parseFloat($('#sodium').jqxNumberInput('decimal')), |
|
346 magnesium: parseFloat($('#magnesium').jqxNumberInput('decimal')), |
|
347 ph: parseFloat($('#ph').jqxNumberInput('decimal')), |
|
348 notes: $('#notes').val(), |
|
349 total_alkalinity: parseFloat($('#total_alkalinity').jqxNumberInput('decimal')), |
|
350 inventory: parseFloat($('#inventory').jqxNumberInput('decimal')), |
|
351 cost: parseFloat($('#cost').jqxNumberInput('decimal')) |
|
352 }; |
|
353 if (editrow >= 0) { |
|
354 $('#jqxgrid').jqxGrid('updaterow', rowID, row); |
|
355 } else { |
|
356 $('#jqxgrid').jqxGrid('addrow', null, row); |
|
357 } |
|
358 $('#popupWindow').jqxWindow('hide'); |
|
359 }); |
|
360 createDelElements(); |
|
361 }); |
|
362 |
|