www/js/inv_equipments.js

Fri, 30 Nov 2018 17:40:39 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 30 Nov 2018 17:40:39 +0100
changeset 116
ac993ef43b13
parent 34
a720353fada9
child 117
9e378e37f20f
permissions
-rw-r--r--

Removed all calculations from the equipemnts database script and added missing fields. Added missing fields to the inventory equipemnts edit screen. Added conditional batch size calculation to the equipments editor. Added specific heat settings to the equipments editor.

/*****************************************************************************
 * Copyright (C) 2014-2018
 *   
 * Michiel Broek <mbroek at mbse dot eu>
 *
 * This file is part of BrewCloud
 *
 * 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({ width: '65px', theme: theme });
			$('#delCancel').jqxButton({ width: '65px', theme: theme });
			$('#delCancel').focus();
		}
	});
	$('#eventWindow').jqxWindow('hide');
}


$(document).ready(function () {

	function calcBatchVolume() {
		var	calc = $("#calc_boil_volume").val();
		var	boil_size = parseFloat($("#boil_size").jqxNumberInput('decimal'));
		var	evap_rate = parseFloat($("#evap_rate").jqxNumberInput('decimal'));
		var	boil_time = parseFloat($("#boil_time").jqxNumberInput('decimal'));
		
		if (calc) {	// If checked, calculate the batch size.
			var	batch = boil_size - (evap_rate * boil_time / 60);
			$("#batch_size").val(batch);
		}
	}

	var url = "includes/db_inventory_equipments.php";
	// tooltips
	$("#name").jqxTooltip({ content: 'The unique name of this brew equipment.' });
	$("#notes").jqxTooltip({ content: 'Some notes about the equipment.' });
	$("#tun_volume").jqxTooltip({ content: 'Mash TUN volume.' });
	$("#tun_height").jqxTooltip({ content: 'Mash TUN height in cm.' });
	$("#tun_weight").jqxTooltip({ content: 'Mash TUN weight in Kg.' });
	$("#tun_material").jqxTooltip({ content: 'Mash TUN material. Needed to calculate the right strike temperature.' });
	$("#mash_volume").jqxTooltip({ content: 'Mash water for the first step.' });
	$("#lauter_volume").jqxTooltip({ content: 'Total lauter volume.' });
	$("#lauter_height").jqxTooltip({ content: 'Height of the lauter TUN in cm.' });
	$("#lauter_deadspace").jqxTooltip({ content: 'Volume loss in the lauter TUN.' });
	$("#efficiency").jqxTooltip({ content: 'Average efficiency.' });
	$("#kettle_volume").jqxTooltip({ content: 'Boil kettle volume in liters.' });
	$("#kettle_height").jqxTooltip({ content: 'Boil kettle height in cm.' });
	$("#boil_size").jqxTooltip({ content: 'Normal boil volume in liters' });
	$("#evap_rate").jqxTooltip({ content: 'Evaporation in liters per hour.' });
	$("#boil_time").jqxTooltip({ content: 'Normal boil time in minutes.' });
	$("#top_up_kettle").jqxTooltip({ content: 'Extra water added to the boil.' });
	$("#hop_utilization").jqxTooltip({ content: '100% for smaller installations, higher for large breweries.' });
	$("#batch_size").jqxTooltip({ content: 'Calculated batch size, liters at end of the boil.' });
	$("#trub_chiller_loss").jqxTooltip({ content: 'Standard loss in liters during transfer to the fermenter.' });
	
	// prepare the data
	var 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: 'string' },
			{ 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: 'bool' },
			{ 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: '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,
				success: function (data, status, xhr) {
					// delete command is executed.
					commit(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,
                               	success: function (data, status, xhr) {
                                       	commit(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,
				success: function (data, status, xhr) {
					// update command is executed.
					commit(true);
				},
				error: function(jqXHR, textStatus, errorThrown) {
					commit(false);
				}
			});
		}
	};
	// initialize the input fields.
	var srcMaterial= [ "RVS", "Aluminium", "Kunststof", "Koper" ];

	$("#name").jqxInput({ theme: theme, width: 250, height: 23 });
	$("#boil_size").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 });
	$("#batch_size").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 2, spinButtons: true, spinButtonsStep: 0.5 });
	$("#tun_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 });
	$("#tun_weight").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 2, spinButtons: true });
	$("#tun_specific_heat").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 90, height: 23, decimalDigits: 3 });
	$("#tun_material").jqxDropDownList({ theme: theme, source: srcMaterial, selectedIndex: 0, width: 110, height: 23, dropDownHeight: 130 });
	$("#tun_height").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true });
	$("#top_up_water").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#trub_chiller_loss").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#evap_rate").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 2, spinButtons: true, spinButtonsStep: 0.05 });
	$("#boil_time").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 0, spinButtons: true });
	$("#calc_boil_volume").jqxCheckBox({ theme: theme, width: 120, height: 23 });
	$("#calc_boil_volume").on('checked', function (event) {
		$("#batch_size").jqxNumberInput({ readOnly: true, width: 70, spinButtons: false });
	});
	$("#calc_boil_volume").on('unchecked', function (event) {
		$("#batch_size").jqxNumberInput({ readOnly: false, width: 90, spinButtons: true });
	});
	$("#top_up_kettle").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#hop_utilization").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 0, spinButtons: true });
	$("#notes").jqxInput({ theme: theme, width: 640, height: 100 });
	$("#lauter_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 });
	$("#lauter_height").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true });
	$("#lauter_deadspace").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#kettle_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 });
	$("#kettle_height").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true });
	$("#mash_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 });
	$("#efficiency").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true });
	var dataAdapter = new $.jqx.dataAdapter(source);
	var editrow = -1;
	// initialize jqxGrid
	$("#jqxgrid").jqxGrid({
		width: 1280,
		height: 630,
		source: dataAdapter,
		theme: theme,
		showstatusbar: true,
		localization: getLocalization(),
		renderstatusbar: function (statusbar) {
			var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
			var 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: -3px;'>Nieuw</span></div>");
			container.append(addButton);
			statusbar.append(container);
			addButton.jqxButton({ theme: theme, width: 120, height: 20 });
			// add new row.
			addButton.click(function (event) {
				editrow = -1;
				$("#popupWindow").jqxWindow({ position: { x: 180, y: 30 } });
				$("#name").val('');
				$("#boil_size").val('18');
				$("#batch_size").val('15.3');
				$("#tun_volume").val('20');
				$("#tun_weight").val('2');
				$("#tun_specific_heat").val('0.11');
				$("#tun_material").val('RVS');
				$("#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('0');
				$("#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');
				$("#efficiency").val('75');
				$("#popupWindow").jqxWindow('open');
			});
		},
		filterable: true,
		filtermode: 'excel',
		ready: function() {
			$('#boil_size').on('change', function (event) { calcBatchVolume(); });
			$('#evap_rate').on('change', function (event) { calcBatchVolume(); });
			$('#boil_time').on('change', function (event) { calcBatchVolume(); });
			$("#calc_boil_volume").on('change', function (event) { calcBatchVolume(); });
			$('#tun_material').on('change', function (event) {
				switch ($('#tun_material').val()) {
					case 'RVS':		$("#tun_specific_heat").val('0.11');
								break;
					case 'Aluminium':	$("#tun_specific_heat").val('0.22');
								break;
					case 'Kunststof':	$("#tun_specific_heat").val('0.46');
								break;
					case 'Koper':		$("#tun_specific_heat").val('0.092');
								break;
				}
			});
		},
		columns: [
			{ text: 'Installatie naam', datafield: 'name', width: 200 },
			{ text: 'Kook volume', datafield: 'boil_size', width: 100, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
			{ text: 'Batch volume', datafield: 'batch_size', width: 100, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
			{ text: 'Opmerkingen', datafield: 'notes' },
			{ text: 'Wijzig', datafield: 'Edit', width: 120, 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: 180, y: 30 } });
					// get the clicked row's data and initialize the input fields.
					var 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);
					$("#efficiency").val(dataRecord.efficiency);
					// show the popup window.
					$("#popupWindow").jqxWindow('open');
				}
			}
		]
	});
	// initialize the popup window and buttons.
	$("#popupWindow").jqxWindow({
		width: 900, resizable: false, theme: theme, isModal: true, autoOpen: false, cancelButton: $("#Cancel"), modalOpacity: 0.40
	});
	$("#popupWindow").on('open', function () {
		$("#name").jqxInput('selectAll');
	});
	$("#Delete").jqxButton({ 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({ theme: theme });
	$("#Save").jqxButton({ theme: theme });
	// update the edited row when the user clicks the 'Save' button.
	$("#Save").click(function () {
		if (editrow >= 0) {
			var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
			var 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')),
				efficiency: parseFloat($("#efficiency").jqxNumberInput('decimal'))
			};
			$('#jqxgrid').jqxGrid('updaterow', rowID, row);
			$("#popupWindow").jqxWindow('hide');
		} else {
			// Insert a record
			var newrow = {
				record: -1,
				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')),
				efficiency: parseFloat($("#efficiency").jqxNumberInput('decimal'))
			};
			$('#jqxgrid').jqxGrid('addrow', null, newrow);
			$("#popupWindow").jqxWindow('hide');
		}
	});
	createDelElements();
});

mercurial