www/js/prod_divide.js

changeset 499
4f14a18b581e
parent 498
10c6eeee60ce
child 500
8d53ad389204
equal deleted inserted replaced
498:10c6eeee60ce 499:4f14a18b581e
31 width: 180, 31 width: 180,
32 height: 23, 32 height: 23,
33 autoDropDownHeight: true 33 autoDropDownHeight: true
34 }); 34 });
35 35
36 // Calculate the volume in the main batch.
37 function calcLeftover() {
38 rows = $('#splitGrid').jqxGrid('getrows');
39 leftover = Round(available, 1);
40 for (i = 0; i < rows.length; i++) {
41 row = rows[i];
42 leftover -= row.split_size;
43 //console.log('i:' + i + ' split_size:' + row.split_size);
44 }
45 $('#leftover').val(leftover);
46 //console.log('calcLeftover():' + leftover);
47 }
48
49 // Calculate available volume but ignore the current row.
50 function calcRoom(r) {
51 var rows, row, i, vol = 0;
52
53 rows = $('#splitGrid').jqxGrid('getrows');
54 for (i = 0; i < rows.length; i++) {
55 row = rows[i];
56 if (i != r)
57 vol += row.split_size;
58 }
59 maxvolume = Round(available - minvolume - vol, 1);
60 console.log('calcRoom(' + r + '):' + vol + ' room:' + maxvolume);
61 }
62
36 var dataRecord = {}, 63 var dataRecord = {},
37 i, 64 i,
65 available = 0,
66 leftover = 0,
67 minvolume = 0,
68 maxvolume = 0,
38 url = 'includes/db_product.php', 69 url = 'includes/db_product.php',
39 70
40 // Prepare the data 71 // Prepare the data
41 source = { 72 source = {
42 datatype: 'json', 73 datatype: 'json',
243 { name: 'prop4_volume', type: 'float' }, 274 { name: 'prop4_volume', type: 'float' },
244 { name: 'divide_type', type: 'int' }, 275 { name: 'divide_type', type: 'int' },
245 { name: 'divide_size', type: 'float' }, 276 { name: 'divide_size', type: 'float' },
246 { name: 'divide_parts', type: 'int' }, 277 { name: 'divide_parts', type: 'int' },
247 { name: 'divide_from', type: 'string' }, 278 { name: 'divide_from', type: 'string' },
248 { name: 'fermentables', type: 'array' }, 279 { name: 'fermentables', type: 'string' },
249 { name: 'hops', type: 'array' }, 280 { name: 'hops', type: 'string' },
250 { name: 'miscs', type: 'array' }, 281 { name: 'miscs', type: 'string' },
251 { name: 'yeasts', type: 'array' }, 282 { name: 'yeasts', type: 'string' },
252 { name: 'mashs', type: 'array' } 283 { name: 'mashs', type: 'string' }
253 ], 284 ],
254 id: 'record', 285 id: 'record',
255 url: url + '?record=' + my_record 286 url: url + '?record=' + my_record
256 }, 287 },
257 288
282 var splitSource = { 313 var splitSource = {
283 datatype: 'local', 314 datatype: 'local',
284 cache: false, 315 cache: false,
285 async: false, 316 async: false,
286 datafields: [ 317 datafields: [
318 { name: 'split_code', type: 'string' },
287 { name: 'split_name', type: 'string' }, 319 { name: 'split_name', type: 'string' },
288 { name: 'split_size', type: 'float' } 320 { name: 'split_size', type: 'float' }
289 ], 321 ],
290 addrow: function(rowid, rowdata, position, commit) { 322 addrow: function(rowid, rowdata, position, commit) {
291 console.log('split addrow ' + rowid); 323 console.log('split addrow ' + rowid);
297 } 329 }
298 }, 330 },
299 splitAdapter = new $.jqx.dataAdapter(splitSource, {}); 331 splitAdapter = new $.jqx.dataAdapter(splitSource, {});
300 $('#splitGrid').jqxGrid({ 332 $('#splitGrid').jqxGrid({
301 width: 1240, 333 width: 1240,
302 height: 400, 334 height: 375,
303 source: splitAdapter, 335 source: splitAdapter,
336 editable: true,
337 enabletooltips: true,
338 selectionmode: 'singlecell',
339 editmode: 'click',
304 theme: theme, 340 theme: theme,
305 selectionmode: 'singlerow',
306 showtoolbar: true, 341 showtoolbar: true,
307 rendertoolbar: function(toolbar) { 342 rendertoolbar: function(toolbar) {
308 var container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>'); 343 var container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');
309 toolbar.append(container); 344 toolbar.append(container);
310 container.append('<input style="float: left; margin-left: 165px;" id="saddrowbutton" type="button" value="Nieuwe splitsing" />'); 345 container.append('<input style="float: left; margin-left: 165px;" id="saddrowbutton" type="button" value="Nieuwe splitsing" />');
311 container.append('<input style="float: left; margin-left: 565px;" id="sdeleterowbutton" type="button" value="Verwijder splitsing" />'); 346 container.append('<input style="float: left; margin-left: 565px;" id="sdeleterowbutton" type="button" value="Verwijder splitsing" />');
312 $('#saddrowbutton').jqxButton({ template: 'primary', theme: theme, height: 27, width: 150 }); 347 $('#saddrowbutton').jqxButton({ template: 'primary', theme: theme, disabled: true, height: 27, width: 150 });
313 $('#saddrowbutton').on('click', function() { 348 $('#saddrowbutton').on('click', function() {
314 var row = {}, rowscount = $('#splitGrid').jqxGrid('getdatainformation').rowscount; 349 var row = {}, rowscount = $('#splitGrid').jqxGrid('getdatainformation').rowscount;
350 row['split_code'] = dataRecord.code + '-' + (rowscount + 1);
315 row['split_name'] = dataRecord.name + ' ' + (rowscount + 1); 351 row['split_name'] = dataRecord.name + ' ' + (rowscount + 1);
316 row['split_size'] = 0; 352 row['split_size'] = 0;
317 $('#splitGrid').jqxGrid('addrow', null, row); 353 $('#splitGrid').jqxGrid('addrow', null, row);
354 $('#sdeleterowbutton').jqxButton({ disabled: false }); // Enable delete
355 $('#divide_type').jqxDropDownList({ disabled: true }); // Disable dropdown
318 }); 356 });
319 // delete selected split 357 // Delete last added split
320 $('#sdeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150 }); 358 $('#sdeleterowbutton').jqxButton({ template: 'danger', theme: theme, disabled: true, height: 27, width: 150 });
321 $('#sdeleterowbutton').on('click', function() { 359 $('#sdeleterowbutton').on('click', function() {
322 var rowscount, id, selectedrowindex = $('#splitGrid').jqxGrid('getselectedrowindex'); 360 var rowscount, id, row;
323 rowscount = $('#splitGrid').jqxGrid('getdatainformation').rowscount; 361 rowscount = $('#splitGrid').jqxGrid('getdatainformation').rowscount;
324 if (selectedrowindex >= 0 && selectedrowindex < rowscount) { 362 id = $('#splitGrid').jqxGrid('getrowid', rowscount - 1);
325 id = $('#splitGrid').jqxGrid('getrowid', selectedrowindex); 363 // First, give back this batch volume.
326 $('#splitGrid').jqxGrid('deleterow', id); 364 row = $('#splitGrid').jqxGrid('getrowdata', id);
365 leftover += row.split_size;
366 if (leftover > available)
367 leftover = available;
368 $('#leftover').val(leftover);
369 // Then delete the row.
370 $('#splitGrid').jqxGrid('deleterow', id);
371 if (rowscount == 1) {
372 $('#sdeleterowbutton').jqxButton({ disabled: true }); // No more rows
373 $('#divide_type').jqxDropDownList({ disabled: false });
327 } 374 }
328 }); 375 });
329 }, 376 },
330 columns: [ 377 columns: [
378 { text: 'Splits code', datafield: 'split_code', width: 120, editable: false },
331 { text: 'Splits naam', datafield: 'split_name' }, 379 { text: 'Splits naam', datafield: 'split_name' },
332 { text: 'Splits volume', datafield: 'split_size', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'f2' } 380 { text: 'Splits volume', datafield: 'split_size', width: 120, align: 'right', cellsalign: 'right', cellsformat: 'f1', columntype: 'numberinput',
381 validation: function (cell, value) {
382 if (value < 0 || value > maxvolume) {
383 return { result: false, message: 'Volume should be between 0 and ' + maxvolume + ' liter' };
384 }
385 return true;
386 },
387 createeditor: function (row, cellvalue, editor) {
388 editor.jqxNumberInput({ decimalDigits: 1, digits: 3 });
389 }
390 }
333 ] 391 ]
392 });
393 $('#splitGrid').on('cellbeginedit', function (event) {
394 var args = event.args;
395 calcRoom(args.rowindex); // Make maxvolume available.
396 });
397 $('#splitGrid').on('cellvaluechanged', function (event) {
398 var args = event.args;
399 //console.log("cellvaluechanged, Column: " + args.datafield + ", Row: " + (1 + args.rowindex) + ", Value: " + args.value);
400 calcLeftover();
334 }); 401 });
335 }; 402 };
336 403
337 dataAdapter.dataBind(); 404 dataAdapter.dataBind();
338 editSplit(dataRecord); 405 editSplit(dataRecord);
342 $('#name').jqxInput({ theme: theme, width: 640, height: 23 }); 409 $('#name').jqxInput({ theme: theme, width: 640, height: 23 });
343 $('#code').jqxTooltip({ content: 'Product code nummer.' }); 410 $('#code').jqxTooltip({ content: 'Product code nummer.' });
344 $('#code').jqxInput({ theme: theme, width: 100, height: 23 }); 411 $('#code').jqxInput({ theme: theme, width: 100, height: 23 });
345 $('#stage').jqxTooltip({ content: 'De productie fase van dit product.' }); 412 $('#stage').jqxTooltip({ content: 'De productie fase van dit product.' });
346 $('#stage').jqxInput({ theme: theme, width: 100, height: 23 }); 413 $('#stage').jqxInput({ theme: theme, width: 100, height: 23 });
414 $('#available').jqxNumberInput(Show1dec);
415 $('#leftover').jqxNumberInput(Show1dec);
347 $('#divide_type').val(0); 416 $('#divide_type').val(0);
348 $('#divide_type').on('change', function(event) { 417 $('#divide_type').on('change', function(event) {
349 dataRecord.divide_type = event.args.index; 418 var index = event.args.index;
419 console.log('divide_type:' + index);
420 dataRecord.divide_type = index;
421 switch (index) {
422 case 0:
423 available = 0;
424 break;
425 case 1:
426 available = dataRecord.boil_size;
427 break;
428 case 2:
429 available = dataRecord.batch_size;
430 break;
431 case 3:
432 available = dataRecord.brew_fermenter_volume;
433 break;
434 case 4:
435 case 5:
436 available = Round(dataRecord.brew_fermenter_volume * 0.92, 1); // Estimate volume without yeast trub
437 break;
438 case 6:
439 available = dataRecord.package_volume;
440 break;
441 }
442 leftover = available;
443 minvolume = Round(0.1 * available, 1);
444 $('#available').val(available);
445 $('#leftover').val(leftover);
446 if (index != 0) {
447 $('#saddrowbutton').jqxButton({ disabled: false });
448 } else {
449 $('#saddrowbutton').jqxButton({ disabled: true });
450 }
350 }); 451 });
351 452
352 $('#Cancel').jqxButton({ template: 'primary', width: '80px', theme: theme }); 453 $('#Cancel').jqxButton({ template: 'primary', width: '80px', theme: theme });
353 $('#Cancel').bind('click', function() { 454 $('#Cancel').bind('click', function() {
354 window.location.href = my_return; 455 window.location.href = my_return;
355 }); 456 });
356 457
357 $('#Save').jqxButton({ template: 'success', width: '80px', theme: theme }); 458 $('#Save').jqxButton({ template: 'success', width: '80px', theme: theme });
358 $('#Save').bind('click', function() { 459 $('#Save').bind('click', function() {
460 var rows, row, i, batch;
461 if (leftover != available) {
462 console.log('Save and there are splits');
463
464 rows = $('#splitGrid').jqxGrid('getrows');
465 for (i = 0; i < rows.length; i++) {
466 row = rows[i];
467 console.log('split ' + i);
468 // batch = dataRecord;
469 // batch.divide_from = batch.uuid;
470 // batch.divide_size = row.split_size;
471 // batch.divide_parts = rows.length;
472 // delete batch['uuid'];
473 // batch.record = -1;
474 // batch.name = row.split_name;
475 // batch.code = row.split_code;
476 }
477 }
359 // saveRecord(1); 478 // saveRecord(1);
360 }); 479 });
361 480
362 }); 481 });

mercurial