www/js/inv_equipments.js

Tue, 31 Aug 2021 20:48:37 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 31 Aug 2021 20:48:37 +0200
changeset 774
92e1e8f175a2
parent 767
08c0343b622b
child 785
aa79acfdf8a9
permissions
-rw-r--r--

Split batch, adjust mash step volume. In the duplicated log_brew handle the missing values. In save product, round the mash step sg to 4 decimals. In prod_edit, ingredients are stored as strings, not arrays. This triggered a memory corruption that only happened in rare circumstances. Don't fix mash step fields in the javascript, it is already done during load from the database. Calculation of the mash volume is rounded to 6 decimals. Enter mash step Brix/Plato value, the SG result is rounded to 4 decimals.

/*****************************************************************************
 * Copyright (C) 2014-2021
 *
 * Michiel Broek <mbroek at mbse dot eu>
 *
 * This file is part of Brewery Management System
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * BrewCloud is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ThermFerm; see the file COPYING.  If not, write to the Free
 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *****************************************************************************/


function createDelElements() {
 $('#eventWindow').jqxWindow({
  theme: theme,
  position: { x: 490, y: 210 },
  width: 300,
  height: 175,
  resizable: false,
  isModal: true,
  modalOpacity: 0.4,
  okButton: $('#delOk'),
  cancelButton: $('#delCancel'),
  initContent: function() {
   $('#delOk').jqxButton({ template: 'danger', width: '65px', theme: theme });
   $('#delCancel').jqxButton({ template: 'success', width: '65px', theme: theme });
   $('#delCancel').focus();
  }
 });
 $('#eventWindow').jqxWindow('hide');
}


$(document).ready(function() {

 function calcBatchVolume() {
  var calc = $('#calc_boil_volume').val(),
  boil_size = parseFloat($('#boil_size').jqxNumberInput('decimal')),
  evap_rate = parseFloat($('#evap_rate').jqxNumberInput('decimal')),
  boil_time = parseFloat($('#boil_time').jqxNumberInput('decimal')),
  top_up = parseFloat($('#top_up_kettle').jqxNumberInput('decimal')),
  batch = parseFloat($('#batch_size').jqxNumberInput('decimal'));

  if (calc) { // If checked, calculate the batch size.
   batch = boil_size - (evap_rate * boil_time / 60) + top_up;
   $('#batch_size').val(batch);
  }
  $('#vol_fermenter').val((batch / 1.04) + parseFloat($('#top_up_water').jqxNumberInput('decimal')) - parseFloat($('#trub_chiller_loss').jqxNumberInput('decimal')));
 }

 // tooltips
 $('#name').jqxTooltip({ content: 'De unieke naam van deze brouw installatie.' });
 $('#notes').jqxTooltip({ content: 'Extra opmerkingen over deze installatie.' });
 $('#tun_volume').jqxTooltip({ content: 'Maisch kuip volume.' });
 $('#tun_height').jqxTooltip({ content: 'Maisch kuip hoogte in cm.' });
 $('#tun_weight').jqxTooltip({ content: 'Maisch kuip gewicht in Kg.' });
 $('#tun_material').jqxTooltip({ content: 'Maisch kuip materiaal. Nodig om de juiste inmaisch temperatuur te berekenen.' });
 $('#mash_volume').jqxTooltip({ content: 'Liters maisch water voor de eerste maisch stap.' });
 $('#mash_max').jqxTooltip({ content: 'Maximale moutstort voor deze installatie in Kg.' });
 $('#lauter_volume').jqxTooltip({ content: 'Totaal filter volume.' });
 $('#lauter_height').jqxTooltip({ content: 'Hoogte van de filterpan in cm.' });
 $('#lauter_deadspace').jqxTooltip({ content: 'Volume verlies in de filterpan.' });
 $('#efficiency').jqxTooltip({ content: 'Gemiddeld brouwzaalrendement.' });
 $('#kettle_volume').jqxTooltip({ content: 'Kook ketel volume in liters.' });
 $('#kettle_height').jqxTooltip({ content: 'Kook ketel hoogte in cm.' });
 $('#boil_size').jqxTooltip({ content: 'Volume in liters voor de kook bij 100&deg;C in de kook ketel.' });
 $('#evap_rate').jqxTooltip({ content: 'Verdamping in liters per uur.' });
 $('#boil_time').jqxTooltip({ content: 'Kooktijd in minuten.' });
 $('#top_up_kettle').jqxTooltip({ content: 'Extra water toevoegen tijdens het koken.' });
 $('#hop_utilization').jqxTooltip({ content: '100% voor kleinere installaties, hoger voor grote brouwerijen.' });
 $('#batch_size').jqxTooltip({ content: 'Volume bij 100&deg;C aan het einde van de kook.' });
 $('#trub_chiller_loss').jqxTooltip({ content: 'Standaard verlies in liters tijdens koelen en overbrengen van de wort naar het gistvat.' });
 $('#top_up_water').jqxTooltip({ content: 'Extra water toe te voegen in het gistvat.' });
 $('#vol_fermenter').jqxTooltip({ content: 'Het aantal liters in het gistvat.' });

 var dataRecord = {},
 url = 'includes/db_inventory_equipments.php',
 // prepare the data
 source = {
  datatype: 'json',
  cache: false,
  datafields: [
   { name: 'record', type: 'number' },
   { name: 'name', type: 'string' },
   { name: 'boil_size', type: 'float' },
   { name: 'batch_size', type: 'float' },
   { name: 'tun_volume', type: 'float' },
   { name: 'tun_weight', type: 'float' },
   { name: 'tun_specific_heat', type: 'float' },
   { name: 'tun_material', type: 'int' },
   { name: 'tun_height', type: 'float' },
   { name: 'top_up_water', type: 'float' },
   { name: 'trub_chiller_loss', type: 'float' },
   { name: 'evap_rate', type: 'float' },
   { name: 'boil_time', type: 'float' },
   { name: 'calc_boil_volume', type: 'int' },
   { name: 'top_up_kettle', type: 'float' },
   { name: 'hop_utilization', type: 'float' },
   { name: 'notes', type: 'string' },
   { name: 'lauter_volume', type: 'float' },
   { name: 'lauter_height', type: 'float' },
   { name: 'lauter_deadspace', type: 'float' },
   { name: 'kettle_volume', type: 'float' },
   { name: 'kettle_height', type: 'float' },
   { name: 'mash_volume', type: 'float' },
   { name: 'mash_max', type: 'float' },
   { name: 'efficiency', type: 'float' }
  ],
  id: 'record',
  url: url,
  deleterow: function(rowid, commit) {
   // synchronize with the server - send delete command
   var data = 'delete=true&' + $.param({ record: rowid });
   $.ajax({
    dataType: 'json',
    url: url,
    cache: false,
    data: data,
    type: 'POST',
    success: function(data) {
     if (data.error) {
      console.log('delete: ' + data.msg);
      alert('Fout: ' + data.msg);
     } else {
      console.log('delete: success');
     }
     //commit(true);
     location.reload(true);
    },
    error: function(jqXHR, textStatus, errorThrown) { commit(false); }
   });
  },
  addrow: function(rowid, rowdata, position, commit) {
   var data = 'insert=true&' + $.param(rowdata);
   $.ajax({
    dataType: 'json',
    url: url,
    cache: false,
    data: data,
    type: 'POST',
    success: function(data) {
     if (data.error) {
      console.log('insert: ' + data.msg);
      alert('Fout: ' + data.msg);
     } else {
      console.log('insert: success');
     }
     location.reload(true);
    },
    error: function(jqXHR, textStatus, errorThrown) { commit(false); }
   });
  },
  updaterow: function(rowid, rowdata, commit) {
   var data = 'update=true&' + $.param(rowdata);
   $.ajax({
    dataType: 'json',
    url: url,
    cache: false,
    data: data,
    type: 'POST',
    success: function(data) {
     if (data.error) {
      console.log('updaterow: ' + data.msg);
      alert('Fout: ' + data.msg);
     } else {
      console.log('updaterow: success');
     }
     //commit(true);
     location.reload(true);
    },
    error: function(jqXHR, textStatus, errorThrown) { console.log('updaterow: ' + textStatus); commit(false); }
   });
  }
 },
 dataAdapter = new $.jqx.dataAdapter(source),
 editrow = -1;

 // initialize the input fields.
 $('#name').jqxInput({ theme: theme, width: 250, height: 23 });
 $('#notes').jqxInput({ theme: theme, width: 640, height: 100 });
 $('#boil_size').jqxNumberInput(Spin1dec);
 $('#batch_size').jqxNumberInput(Spin2dec);
 $('#batch_size').jqxNumberInput({ spinButtonsStep: 0.5 });
 $('#tun_volume').jqxNumberInput(Spin1dec);
 $('#tun_weight').jqxNumberInput(Spin2dec);
 $('#tun_specific_heat').jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 3 });
 $('#tun_material').jqxDropDownList({
  theme: theme,
  source: MaterialAdapter,
  valueMember: 'id',
  displayMember: 'nl',
  width: 180,
  height: 23,
  autoDropDownHeight: true
 });
 $('#tun_height').jqxNumberInput(Spin1dec);
 $('#top_up_water').jqxNumberInput(Spin1dec);
 $('#trub_chiller_loss').jqxNumberInput(Spin1dec);
 $('#evap_rate').jqxNumberInput(Spin2dec);
 $('#boil_time').jqxNumberInput(PosInt);
 $('#boil_time').jqxNumberInput({ max: 1440 });
 $('#calc_boil_volume').jqxCheckBox({ theme: theme, width: 120, height: 23 });
 $('#calc_boil_volume').on('checked', function(event) {
  $('#batch_size').jqxNumberInput({ readOnly: true, width: 90, spinButtons: false });
 });
 $('#calc_boil_volume').on('unchecked', function(event) {
  $('#batch_size').jqxNumberInput({ readOnly: false, width: 110, spinButtons: true });
 });
 $('#top_up_kettle').jqxNumberInput(Spin1dec);
 $('#hop_utilization').jqxNumberInput(Perc0);
 $('#hop_utilization').jqxNumberInput({ Max: 200 });
 $('#lauter_volume').jqxNumberInput(Spin1dec);
 $('#lauter_height').jqxNumberInput(Spin1dec);
 $('#lauter_deadspace').jqxNumberInput(Spin1dec);
 $('#kettle_volume').jqxNumberInput(Spin1dec);
 $('#kettle_height').jqxNumberInput(Spin1dec);
 $('#mash_volume').jqxNumberInput(Spin1dec);
 $('#mash_max').jqxNumberInput(Spin1dec);
 $('#efficiency').jqxNumberInput(Perc1dec);
 $('#vol_fermenter').jqxNumberInput(Show2dec);

 // initialize jqxGrid
 $('#jqxgrid').jqxGrid({
  width: 1280,
  height: 630,
  source: dataAdapter,
  theme: theme,
  showstatusbar: true,
  renderstatusbar: function(statusbar) {
   var rowCount = $("#jqxgrid").jqxGrid('getrows').length;
   statusbar.append('<div style="float: left; margin: 8px; color: orange !important;">Aantal items: ' + rowCount + '</div>');
   var addButton, container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');
   addButton = $('<div style="float: right; margin-right: 15px;"><img style="position: relative; margin-top: 2px;" ' +
     'src="images/add.png"/><span style="margin-left: 4px; position: relative; top: -4px;">Nieuw</span></div>');
   expButton = $('<div style="float: right; margin-right: 50px;"><img style="position: relative; margin-top: 2px;" ' +
     'src="images/database.png"/><span style="margin-left: 4px; position: relative; top: -10px;">Export</span></div>');
   container.append(addButton);
   container.append(expButton);
   statusbar.append(container);
   addButton.jqxButton({ theme: theme, width: 90, height: 17 });
   expButton.jqxButton({ theme: theme, width: 90, height: 17 });
   // add new row.
   addButton.click(function(event) {
    editrow = -1;
    $('#popupWindow').jqxWindow({ position: { x: 110, y: 30 } });
    $('#name').val('Nieuwe brouwset');
    $('#boil_size').val(18);
    $('#batch_size').val(15.3);
    $('#vol_fermenter').val(14.2);
    $('#tun_volume').val(20);
    $('#tun_weight').val(2);
    $('#tun_specific_heat').val(0.11);
    $('#tun_material').val(0);
    $('#tun_height').val(20);
    $('#top_up_water').val(0);
    $('#trub_chiller_loss').val(0.5);
    $('#evap_rate').val(1.8);
    $('#boil_time').val(90);
    $('#calc_boil_volume').val(1);
    $('#top_up_kettle').val(0);
    $('#hop_utilization').val(100);
    $('#notes').val('');
    $('#lauter_volume').val(20);
    $('#lauter_height').val(20);
    $('#lauter_deadspace').val(0.5);
    $('#kettle_volume').val(20);
    $('#kettle_height').val(20);
    $('#mash_volume').val(18);
    $('#mash_max').val(6);
    $('#efficiency').val(75);
    $('#popupWindow').jqxWindow('open');
   });
   expButton.click(function(event) {
    window.open('export_equipments.php');
   });
  },
  filterable: false,
  ready: function() {
   $('#boil_size').on('change', function(event) { calcBatchVolume(); });
   $('#evap_rate').on('change', function(event) { calcBatchVolume(); });
   $('#boil_time').on('change', function(event) { calcBatchVolume(); });
   $('#top_up_kettle').on('change', function(event) { calcBatchVolume(); });
   $('#calc_boil_volume').on('change', function(event) { calcBatchVolume(); });
   $('#top_up_water').on('change', function(event) { calcBatchVolume(); });
   $('#trub_chiller_loss').on('change', function(event) { calcBatchVolume(); });
   $('#tun_material').on('select', function(event) {
    dataRecord.tun_specific_heat = MaterialData[event.args.index].sh;
    $('#tun_specific_heat').val(dataRecord.tun_specific_heat);
   });
  },
  columns: [
   { text: 'Installatie naam', datafield: 'name', width: 200 },
   { text: 'Kook volume', datafield: 'boil_size', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
   { text: 'Batch volume', datafield: 'batch_size', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
   { text: 'Opmerkingen', datafield: 'notes' },
   { text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', cellsrenderer: function() {
    return 'Wijzig';
    }, buttonclick: function(row) {
     // open the popup window when the user clicks a button.
     editrow = row;
     $('#popupWindow').jqxWindow({ position: { x: 110, y: 30 } });
     // get the clicked row's data and initialize the input fields.
     dataRecord = $('#jqxgrid').jqxGrid('getrowdata', editrow);
     $('#name').val(dataRecord.name);
     $('#boil_size').val(dataRecord.boil_size);
     $('#batch_size').val(dataRecord.batch_size);
     $('#tun_volume').val(dataRecord.tun_volume);
     $('#tun_weight').val(dataRecord.tun_weight);
     $('#tun_specific_heat').val(dataRecord.tun_specific_heat);
     $('#tun_material').val(dataRecord.tun_material);
     $('#tun_height').val(dataRecord.tun_height);
     $('#top_up_water').val(dataRecord.top_up_water);
     $('#trub_chiller_loss').val(dataRecord.trub_chiller_loss);
     $('#evap_rate').val(dataRecord.evap_rate);
     $('#boil_time').val(dataRecord.boil_time);
     $('#calc_boil_volume').val(dataRecord.calc_boil_volume);
     $('#top_up_kettle').val(dataRecord.top_up_kettle);
     $('#hop_utilization').val(dataRecord.hop_utilization);
     $('#notes').val(dataRecord.notes);
     $('#lauter_volume').val(dataRecord.lauter_volume);
     $('#lauter_height').val(dataRecord.lauter_height);
     $('#lauter_deadspace').val(dataRecord.lauter_deadspace);
     $('#kettle_volume').val(dataRecord.kettle_volume);
     $('#kettle_height').val(dataRecord.kettle_height);
     $('#mash_volume').val(dataRecord.mash_volume);
     $('#mash_max').val(dataRecord.mash_max);
     $('#efficiency').val(dataRecord.efficiency);
     // show the popup window.
     $('#popupWindow').jqxWindow('open');
    }
   }
  ]
 });
 // initialize the popup window and buttons.
 $('#popupWindow').jqxWindow({
  width: 1050,
  height: 600,
  resizable: false,
  theme: theme,
  isModal: true,
  autoOpen: false,
  cancelButton: $('#Cancel'),
  modalOpacity: 0.40
 });
 $('#popupWindow').on('open', function() {
  $('#name').jqxInput('selectAll');
 });
 $('#Delete').jqxButton({ template: 'danger', width: '90px', theme: theme });
 $('#Delete').click(function() {
  if (editrow >= 0) {
   // Open a popup to confirm this action.
   $('#eventWindow').jqxWindow('open');
   $('#delOk').click(function() {
    var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
    $('#jqxgrid').jqxGrid('deleterow', rowID);
   });
  }
  $('#popupWindow').jqxWindow('hide');
 });
 $('#Cancel').jqxButton({ template: 'primary', width: '90px', theme: theme });
 $('#Clone').jqxButton({ template: 'warning', width: '90px', theme: theme });
 $('#Clone').click(function() {
  var row = {
   record: -1,
   name: $('#name').val() + ' kopie',
   boil_size: parseFloat($('#boil_size').jqxNumberInput('decimal')),
   batch_size: parseFloat($('#batch_size').jqxNumberInput('decimal')),
   tun_volume: parseFloat($('#tun_volume').jqxNumberInput('decimal')),
   tun_weight: parseFloat($('#tun_weight').jqxNumberInput('decimal')),
   tun_specific_heat: parseFloat($('#tun_specific_heat').jqxNumberInput('decimal')),
   tun_material: $('#tun_material').val(),
   tun_height: parseFloat($('#tun_height').jqxNumberInput('decimal')),
   top_up_water: parseFloat($('#top_up_water').jqxNumberInput('decimal')),
   trub_chiller_loss: parseFloat($('#trub_chiller_loss').jqxNumberInput('decimal')),
   evap_rate: parseFloat($('#evap_rate').jqxNumberInput('decimal')),
   boil_time: parseFloat($('#boil_time').jqxNumberInput('decimal')),
   calc_boil_volume: $('#calc_boil_volume').val(),
   top_up_kettle: parseFloat($('#top_up_kettle').jqxNumberInput('decimal')),
   hop_utilization: parseFloat($('#hop_utilization').jqxNumberInput('decimal')),
   notes: $('#notes').val(),
   lauter_volume: parseFloat($('#lauter_volume').jqxNumberInput('decimal')),
   lauter_height: parseFloat($('#lauter_height').jqxNumberInput('decimal')),
   lauter_deadspace: parseFloat($('#lauter_deadspace').jqxNumberInput('decimal')),
   kettle_volume: parseFloat($('#kettle_volume').jqxNumberInput('decimal')),
   kettle_height: parseFloat($('#kettle_height').jqxNumberInput('decimal')),
   mash_volume: parseFloat($('#mash_volume').jqxNumberInput('decimal')),
   mash_max: parseFloat($('#mash_max').jqxNumberInput('decimal')),
   efficiency: parseFloat($('#efficiency').jqxNumberInput('decimal'))
  };
  $('#jqxgrid').jqxGrid('addrow', null, row);
  $('#popupWindow').jqxWindow('hide');
 });
 $('#Save').jqxButton({ template: 'success', width: '90px', theme: theme });
 // update the edited row when the user clicks the 'Save' button.
 $('#Save').click(function() {
  var row, rowID = -1;
  if (editrow >= 0) {
   rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
  }
  row = {
   record: rowID,
   name: $('#name').val(),
   boil_size: parseFloat($('#boil_size').jqxNumberInput('decimal')),
   batch_size: parseFloat($('#batch_size').jqxNumberInput('decimal')),
   tun_volume: parseFloat($('#tun_volume').jqxNumberInput('decimal')),
   tun_weight: parseFloat($('#tun_weight').jqxNumberInput('decimal')),
   tun_specific_heat: parseFloat($('#tun_specific_heat').jqxNumberInput('decimal')),
   tun_material: $('#tun_material').val(),
   tun_height: parseFloat($('#tun_height').jqxNumberInput('decimal')),
   top_up_water: parseFloat($('#top_up_water').jqxNumberInput('decimal')),
   trub_chiller_loss: parseFloat($('#trub_chiller_loss').jqxNumberInput('decimal')),
   evap_rate: parseFloat($('#evap_rate').jqxNumberInput('decimal')),
   boil_time: parseFloat($('#boil_time').jqxNumberInput('decimal')),
   calc_boil_volume: $('#calc_boil_volume').val(),
   top_up_kettle: parseFloat($('#top_up_kettle').jqxNumberInput('decimal')),
   hop_utilization: parseFloat($('#hop_utilization').jqxNumberInput('decimal')),
   notes: $('#notes').val(),
   lauter_volume: parseFloat($('#lauter_volume').jqxNumberInput('decimal')),
   lauter_height: parseFloat($('#lauter_height').jqxNumberInput('decimal')),
   lauter_deadspace: parseFloat($('#lauter_deadspace').jqxNumberInput('decimal')),
   kettle_volume: parseFloat($('#kettle_volume').jqxNumberInput('decimal')),
   kettle_height: parseFloat($('#kettle_height').jqxNumberInput('decimal')),
   mash_volume: parseFloat($('#mash_volume').jqxNumberInput('decimal')),
   mash_max: parseFloat($('#mash_max').jqxNumberInput('decimal')),
   efficiency: parseFloat($('#efficiency').jqxNumberInput('decimal'))
  };
  if (editrow >= 0) {
   $('#jqxgrid').jqxGrid('updaterow', rowID, row);
  } else {
   $('#jqxgrid').jqxGrid('addrow', null, row);
  }
  $('#popupWindow').jqxWindow('hide');
 });
 createDelElements();
});

mercurial