www/js/inv_miscs.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 calcTotal(cost, inventory) {
48
49 $('#totval').val(cost * (inventory / 1000));
50 }
51
52 function prompts(isweight) {
53
54 if (isweight) {
55 $('#pmpt_cost').html('Prijs per kg:');
56 $('#pmpt_inventory').html('Voorraad gram:');
57 } else {
58 $('#pmpt_cost').html('Prijs per liter:');
59 $('#pmpt_inventory').html('Voorraad ml:');
60 }
61 }
62
63 var dataRecord = {},
64 url = 'includes/db_inventory_miscs.php',
65 // prepare the data
66 source = {
67 datatype: 'json',
68 cache: false,
69 datafields: [
70 { name: 'record', type: 'number' },
71 { name: 'name', type: 'string' },
72 { name: 'uuid', type: 'string' },
73 { name: 'type', type: 'string' },
74 { name: 'use_use', type: 'string' },
75 { name: 'time', type: 'int' },
76 { name: 'amount', type: 'float' },
77 { name: 'amount_is_weight', type: 'int' },
78 { name: 'use_for', type: 'string' },
79 { name: 'notes', type: 'string' },
80 { name: 'always_on_stock', type: 'int' },
81 { name: 'inventory', type: 'float' },
82 { name: 'cost', type: 'float' },
83 { name: 'production_date', type: 'string' },
84 { name: 'tht_date', type: 'string' }
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: 800, height: 100 });
156
157 $('#type').jqxDropDownList({theme: theme,
158 source: MiscTypeAdapter,
159 valueMember: 'nl',
160 displayMember: 'nl',
161 width: 180,
162 height: 23,
163 autoDropDownHeight: true
164 });
165 $('#use_use').jqxDropDownList({
166 theme: theme,
167 source: MiscUseAdapter,
168 valueMember: 'nl',
169 displayMember: 'nl',
170 width: 180,
171 height: 23,
172 autoDropDownHeight: true
173 });
174 $('#time').jqxNumberInput(PosInt);
175 $('#amount_is_weight').jqxCheckBox({ theme: theme, width: 120, height: 23 });
176 $('#use_for').jqxInput({ theme: theme, width: 640, height: 48 });
177 $('#always_on_stock').jqxCheckBox({ theme: theme, width: 120, height: 23 });
178 $('#inventory').jqxNumberInput(Spin1dec);
179 $('#production_date').jqxDateTimeInput(Dateopts);
180 $('#cost').jqxNumberInput(Spin2dec);
181 $('#tht_date').jqxDateTimeInput(Dateopts);
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 = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');
198 var addButton = $('<div style="float: right; margin-right: 15px;"><img style="position: relative; margin-top: 2px;" ' +
199 'src="images/add.png"/><span style="margin-left: 4px; position: relative; top: -4px;">Nieuw</span></div>');
200 var impButton = $('<div style="float: right; margin-right: 50px;"><img style="position: relative; margin-top: 2px;" ' +
201 'src="images/add.png"/><span style="margin-left: 4px; position: relative; top: -4px;">Import</span></div>');
202 var expButton = $('<div style="float: right; margin-right: 50px;"><img style="position: relative; margin-top: 2px;" ' +
203 'src="images/database.png"/><span style="margin-left: 4px; position: relative; top: -10px;">Export</span></div>');
204 container.append(addButton);
205 container.append(impButton);
206 container.append(expButton);
207 statusbar.append(container);
208 addButton.jqxButton({ theme: theme, width: 90, height: 17 });
209 impButton.jqxButton({ theme: theme, width: 90, height: 17 });
210 expButton.jqxButton({ theme: theme, width: 90, height: 17 });
211 // add new row.
212 addButton.click(function(event) {
213 editrow = -1;
214 $('#popupWindow').jqxWindow({ position: { x: 110, y: 30 } });
215 $('#name').val('');
216 dataRecord.uuid = '';
217 $('#type').val('Specerij');
218 $('#use_use').val('Starter');
219 $('#time').val(0);
220 $('#amount_is_weight').val(1);
221 $('#use_for').val('');
222 $('#notes').val('');
223 $('#always_on_stock').val(0);
224 $('#inventory').val(0);
225 $('#cost').val(0);
226 $('#production_date').val('');
227 $('#tht_date').val('');
228 $('#popupWindow').jqxWindow('open');
229 });
230 impButton.click(function(event) {
231 window.location.href = 'import_ingredients.php?select=miscs';
232 });
233 expButton.click(function(event) {
234 window.open('export_miscs.php');
235 });
236 },
237 ready: function () {
238 $("#jqxgrid").jqxGrid('localizestrings', localizationobj);
239 },
240 filterable: true,
241 showfilterrow: true,
242 columns: [
243 { text: 'Ingredient naam', datafield: 'name', filtertype: 'textbox' },
244 { text: 'Type', datafield: 'type', align: 'left', width: 120, filtertype: 'list' },
245 { text: 'Gebruik', datafield: 'use_use', align: 'left', width: 120, filtertype: 'list' },
246 { text: 'Tijd', datafield: 'time', width: 90, align: 'left', filterable: false,
247 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
248 var duration = '';
249 if (value > 0) {
250 if (value == 1)
251 duration = '1 minuut';
252 else if (value < 60)
253 duration = dataAdapter.formatNumber(value, 'f0') + ' minuten';
254 else if (value == 60)
255 duration = '1 uur';
256 else if (value < 1440)
257 duration = dataAdapter.formatNumber(value / 60, 'f0') + ' uren';
258 else if (value == 1440)
259 duration = '1 dag';
260 else
261 duration = dataAdapter.formatNumber(value / 1440, 'f0') + ' dagen';
262 }
263 return '<span style="margin: 3px; margin-top: 6px; float: left;">' + duration + '</span>';
264 }
265 },
266 { text: 'Voorraad', datafield: 'inventory', width: 110, align: 'right', filtertype: 'number', filtercondition: 'not_equal',
267 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
268 var amount = '';
269 if (value > 0) {
270 if (rowdata.amount_is_weight)
271 amount = dataAdapter.formatNumber(value, 'f1') + ' gr';
272 else
273 amount = dataAdapter.formatNumber(value, 'f1') + ' ml';
274 }
275 return '<span style="margin: 3px; margin-top: 6px; float: right;">' + amount + '</span>';
276 }
277 },
278 { text: 'THT datum', datafield: 'tht_date', width: 100, align: 'center', cellsalign: 'center', filtertype: 'date' },
279 { text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', filterable: false,
280 cellsrenderer: function() {
281 return 'Wijzig';
282 }, buttonclick: function(row) {
283 // open the popup window when the user clicks a button.
284 editrow = row;
285 $('#popupWindow').jqxWindow({ position: { x: 110, y: 30 } });
286 // get the clicked row's data and initialize the input fields.
287 dataRecord = $('#jqxgrid').jqxGrid('getrowdata', editrow);
288 $('#name').val(dataRecord.name);
289 $('#type').val(dataRecord.type);
290 $('#use_use').val(dataRecord.use_use);
291 $('#time').val(dataRecord.time);
292 $('#amount_is_weight').val(dataRecord.amount_is_weight);
293 $('#use_for').val(dataRecord.use_for);
294 $('#notes').val(dataRecord.notes);
295 $('#always_on_stock').val(dataRecord.always_on_stock);
296 $('#inventory').val(dataRecord.inventory);
297 $('#cost').val(dataRecord.cost);
298 $('#production_date').val(dataRecord.production_date);
299 $('#tht_date').val(dataRecord.tht_date);
300 calcTotal(dataRecord.cost, dataRecord.inventory);
301 prompts(dataRecord.amount_is_weight);
302 // show the popup window.
303 $('#popupWindow').jqxWindow('open');
304 }
305 }
306 ]
307 });
308
309 $('#cost').on('change', function(event) {
310 dataRecord.cost = parseFloat(event.args.value);
311 calcTotal(dataRecord.cost, dataRecord.inventory);
312 });
313 $('#inventory').on('change', function(event) {
314 dataRecord.inventory = parseFloat(event.args.value);
315 calcTotal(dataRecord.cost, dataRecord.inventory);
316 });
317 $('#amount_is_weight').on('checked', function(event) {
318 dataRecord.amount_is_weight = true;
319 prompts(true);
320 });
321 $('#amount_is_weight').on('unchecked', function(event) {
322 dataRecord.amount_is_weight = false;
323 prompts(false);
324 });
325
326 // initialize the popup window and buttons.
327 $('#popupWindow').jqxWindow({
328 width: 1050,
329 height: 550,
330 resizable: false,
331 theme: theme,
332 isModal: true,
333 autoOpen: false,
334 cancelButton: $('#Cancel'),
335 modalOpacity: 0.40
336 });
337 $('#popupWindow').on('open', function() {
338 $('#name').jqxInput('selectAll');
339 });
340 $('#Delete').jqxButton({ template: 'danger', width: '90px', theme: theme });
341 $('#Delete').click(function() {
342 if (editrow >= 0) {
343 // Open a popup to confirm this action.
344 $('#eventWindow').jqxWindow('open');
345 $('#delOk').click(function() {
346 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
347 $('#jqxgrid').jqxGrid('deleterow', rowID);
348 });
349 }
350 $('#popupWindow').jqxWindow('hide');
351 });
352 $('#Cancel').jqxButton({ template: 'primary', width: '90px', theme: theme });
353 $('#Clone').jqxButton({ template: 'warning', width: '90px', theme: theme });
354 $('#Clone').click(function() {
355 var row = {
356 record: -1,
357 name: $('#name').val() + ' kopie',
358 uuid: '',
359 type: $('#type').val(),
360 use_use: $('#use_use').val(),
361 time: parseFloat($('#time').jqxNumberInput('decimal')),
362 amount_is_weight: $('#amount_is_weight').val(),
363 use_for: $('#use_for').val(),
364 notes: $('#notes').val(),
365 always_on_stock: $('#always_on_stock').val(),
366 inventory: 0,
367 cost: parseFloat($('#cost').jqxNumberInput('decimal')),
368 production_date: '',
369 tht_date: ''
370 };
371 $('#jqxgrid').jqxGrid('addrow', null, row);
372 $('#popupWindow').jqxWindow('hide');
373 });
374 $('#Save').jqxButton({ template: 'success', width: '90px', theme: theme });
375 // update the edited row when the user clicks the 'Save' button.
376 $('#Save').click(function() {
377 var row, rowID = -1;
378 if (editrow >= 0) {
379 rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
380 }
381 row = {
382 record: rowID,
383 name: $('#name').val(),
384 uuid: dataRecord.uuid,
385 type: $('#type').val(),
386 use_use: $('#use_use').val(),
387 time: parseFloat($('#time').jqxNumberInput('decimal')),
388 amount_is_weight: $('#amount_is_weight').val(),
389 use_for: $('#use_for').val(),
390 notes: $('#notes').val(),
391 always_on_stock: $('#always_on_stock').val(),
392 inventory: parseFloat($('#inventory').jqxNumberInput('decimal')),
393 cost: parseFloat($('#cost').jqxNumberInput('decimal')),
394 production_date: $('#production_date').val(),
395 tht_date: $('#tht_date').val()
396 };
397 if (editrow >= 0) {
398 $('#jqxgrid').jqxGrid('updaterow', rowID, row);
399 } else {
400 $('#jqxgrid').jqxGrid('addrow', null, row);
401 }
402 $('#popupWindow').jqxWindow('hide');
403 });
404 createDelElements();
405 });
406

mercurial