www/js/prod_edit.js

Wed, 05 Dec 2018 14:43:15 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 05 Dec 2018 14:43:15 +0100
changeset 121
875aeb365e1c
parent 119
ae5e8d740173
child 122
5d5bcab19b8f
permissions
-rw-r--r--

Added sparge pH during import. Added several calculations. Added calculated estimates to the brewday screen.

/*****************************************************************************
 * Copyright (C) 2018
 *
 * Michiel Broek <mbroek at mbse dot eu>
 *
 * This file is part of BMS
 *
 * 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 () {

	var	brewstage = 0;	// Numeric value of stage
	var     preboil_sg = 0;
	var	est_mash_sg = 0;
	var     sugarsm = 0;    // Sugars after mash
	var     sugarsf = 0;    // Sugars after boil
	var     psugar = 0;     // Percentage real sugars
	var     pcara = 0;      // Percentage cara/crystal malts
	var	old_efficiency;
	var	old_batch_size;
	var	old_boil_time;

	console.log("record:" + my_record + "  return:" + my_return + "  theme:" + theme);

	function calcFermentables() {
		console.log("calcFermentables()");
		sugarsf = 0;
		sugarsm = 0;
		psugar = 0;
		pcara = 0;
		var colorw = 0; // Colors working

		for (var i = 0; i < dataRecord.fermentables.length; i++) {
			var row = dataRecord.fermentables[i];
			if (row.f_type == "Sugar")
				psugar += row.f_percentage;
			if (row.f_type == "Crystal")
				pcara += row.f_percentage;
			var d = row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
			if (row.f_added == "Mash") {
				d = parseFloat(dataRecord.efficiency) / 100 * d;
				sugarsm += d;
			}
			sugarsf += d;
			colorw += row.f_amount * ebc_to_srm(row.f_color) / parseFloat(dataRecord.batch_size) * 8.34436;
		}
		console.log("sugarsm: " + sugarsm + "  sugarsf: " + sugarsf + "  batch: " + dataRecord.batch_size);
		console.log("est_og: " + estimate_sg(sugarsf, parseFloat(dataRecord.batch_size)));
		preboil_sg = estimate_sg(sugarsm, parseFloat(dataRecord.boil_size));
		console.log("preboil_sg: " + preboil_sg);
		console.log("est_color: " + kw_to_ebc(dataRecord.color_method, colorw));
		$("#est_og").val(estimate_sg(sugarsf, parseFloat(dataRecord.batch_size)));
		$('#est_color').val(kw_to_ebc(dataRecord.color_method, colorw));
	};

	function calcIBUs() {
		var total_ibus = 0;
		for (var i = 0; i < dataRecord.hops.length; i++) {
			var row = dataRecord.hops[i];
			total_ibus += toIBU(row.h_useat, row.h_form, preboil_sg, parseFloat(dataRecord.batch_size),
					parseFloat(row.h_amount), parseFloat(row.h_time), parseFloat(row.h_alpha), dataRecord.ibu_method);
		}
		console.log("calcIBUs(): " + total_ibus);
		$('#est_ibu').val(total_ibus);
	};

	function calcSGendMash() {
		est_mash_sg = 0;
		var	mvol = 0;	// Mash volume
		var	s = 0;
		var	gs = 0;		// Grain absorbtion
		for (var i = 0; i < dataRecord.mashs.length; i++) {
			var row = dataRecord.mashs[i];
//			console.log("step " + i + " " + row.step_name + " " + row.step_type);
			if (row.step_type == 'Infusion')
				mvol += parseFloat(row.step_infuse_amount);
		}
		if (mvol > 0) {
//			console.log("mash volume: " + mvol);
			for (var i = 0; i < dataRecord.fermentables.length; i++) {
				var row = dataRecord.fermentables[i];

				if (row.f_added == "Mash") {
					var d = row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
					mvol += row.f_amount * row.f_moisture / 100;
					gs += my_grain_absorbtion * row.f_amount;
					s += d;
				}
			}
//			console.log("mash volume: " + mvol + "  gs: " + gs + "  s: " + s);
			var v = s / sugardensity + mvol;
			s = 1000 * s / (v * 10); //deg. Plato
			est_mash_sg = plato_to_sg(s);
		}
		console.log("calcSGendMash(): " + est_mash_sg);
		$('#est_mash_sg').val(est_mash_sg);
	};

	function calcMashEfficiency() {
//		console.log("calcMashEfficiency()");
		var c = sg_to_plato(est_mash_sg);
		var m = sg_to_plato(parseFloat($("#brew_mash_sg").jqxNumberInput('decimal')));
//		console.log("c "+ c + "  m " + m + "  in " + parseFloat($("#brew_mash_sg").jqxNumberInput('decimal')));
		if (c > 0.5)
			$("#brew_mash_efficiency").val(100 * m / c);
		else
			$("#brew_mash_efficiency").val(0);
	};

	// Equipemnt dropdown list
	var equipmentUrl = "includes/db_inventory_equipments.php";
	var equipmentSource = {
		datatype: "json",
		datafields: [
			{ 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' }
		],
		url: equipmentUrl,
		async: true
	};
	var equipmentlist = new $.jqx.dataAdapter(equipmentSource);
	$("#equipmentSelect").jqxDropDownList({
		placeHolder: "Kies apparatuur:",
		theme: theme,
		source: equipmentlist,
		displayMember: "name",
		width: 150,
		height: 27,
		dropDownWidth: 300,
		renderer: function (index, label, value) {
			var datarecord = equipmentlist.records[index];
			return datarecord.batch_size + " liter " + datarecord.name;
		}
	});
	$("#equipmentSelect").on('select', function (event) {
		if (event.args) {
			var index = event.args.index;
			var datarecord = equipmentlist.records[index];
			$("#eq_name").val(datarecord.name);
			$("#eq_boil_size").val(datarecord.boil_size);
			$("#eq_batch_size").val(datarecord.batch_size);
			$("#eq_tun_volume").val(datarecord.tun_volume);
			$("#eq_tun_weight").val(datarecord.tun_weight);
			$("#eq_tun_specific_heat").val(datarecord.tun_specific_heat);
			$("#eq_tun_material").val(datarecord.tun_material);
			$("#eq_tun_height").val(datarecord.tun_height);
			$("#eq_top_up_water").val(datarecord.top_up_water);
			$("#eq_trub_chiller_loss").val(datarecord.trub_chiller_loss);
			$("#eq_evap_rate").val(datarecord.evap_rate);
			$("#eq_boil_time").val(datarecord.boil_time);
			$("#eq_calc_boil_volume").val(datarecord.calc_boil_volume);
			$("#eq_top_up_kettle").val(datarecord.top_up_kettle);
			$("#eq_hop_utilization").val(datarecord.hop_utilization);
			$("#eq_notes").val(datarecord.notes);
			$("#eq_lauter_volume").val(datarecord.lauter_volume);
			$("#eq_lauter_height").val(datarecord.lauter_height);
			$("#eq_lauter_deadspace").val(datarecord.lauter_deadspace);
			$("#eq_kettle_volume").val(datarecord.kettle_volume);
			$("#eq_kettle_height").val(datarecord.kettle_height);
			$("#eq_mash_volume").val(datarecord.mash_volume);
			$("#eq_efficiency").val(datarecord.efficiency);
		}
	});

	var dataRecord = {};
	var url = "includes/db_product.php";
	// tooltips
	$("#pname").jqxTooltip({ content: 'De naam voor dit product.' });
	$("#code").jqxTooltip({ content: 'Product code nummer.' });
	$("#birth").jqxTooltip({ content: 'De ontwerp datum van dit product.' });
	$("#stage").jqxTooltip({ content: 'De productie fase van dit product.' });
	$("#pnotes").jqxTooltip({ content: 'De uitgebreide opmerkingen over dit product.' });
	$("#eq_name").jqxTooltip({ content: 'De naam van deze brouw apparatuur.' });
	$("#eq_notes").jqxTooltip({ content: 'Opmerkingen over deze apparatuur.' });
	$("#eq_tun_volume").jqxTooltip({ content: 'Maisch ketel volume.' });
	$("#eq_tun_height").jqxTooltip({ content: 'Maisch ketel hoogte in cm.' });
	$("#eq_tun_weight").jqxTooltip({ content: 'Maisch ketel gewicht in Kg.' });
	$("#eq_tun_material").jqxTooltip({ content: 'Maisch ketel materiaal. Nodig om de juiste inmaisch temperatuur te berekenen.' });
	$("#eq_mash_volume").jqxTooltip({ content: 'Maisch water voor de eerste stap.' });
	$("#eq_lauter_volume").jqxTooltip({ content: 'Filterkuip volume.' });
	$("#eq_lauter_height").jqxTooltip({ content: 'Hoogte van de filterkuip in cm.' });
	$("#eq_lauter_deadspace").jqxTooltip({ content: 'Filterkuip verlies in liters.' });
	$("#eq_efficiency").jqxTooltip({ content: 'Gemiddeld brouwzaal rendement.' });
	$("#eq_kettle_volume").jqxTooltip({ content: 'Kook ketel volume in liters.' });
	$("#eq_kettle_height").jqxTooltip({ content: 'Kook ketel hoogte in cm.' });
	$("#eq_boil_size").jqxTooltip({ content: 'Normaal kook volume in liters' });
	$("#eq_evap_rate").jqxTooltip({ content: 'Verdamping in liters per uur.' });
	$("#eq_boil_time").jqxTooltip({ content: 'Normale kooktijd in minuten..' });
	$("#eq_top_up_kettle").jqxTooltip({ content: 'Extra water toevoegen tijdens de kook.' });
	$("#eq_hop_utilization").jqxTooltip({ content: '100% voor kleine installaties, hoger voor grote brouwerijen.' });
	$("#eq_batch_size").jqxTooltip({ content: 'Berekende batch grootte in liters aan het eind van de kook.' });
	$("#eq_trub_chiller_loss").jqxTooltip({ content: 'Standaard verlies bij het overbrengen naar het gistvat.' });

	// Prepare the data
	var source = {
		datatype: "json",
		cache: false,
		datafields: [
			// From prod_main
			{ name: 'record', type: 'number' },
			{ name: 'puuid', type: 'string' },
			{ name: 'pname', type: 'string' },
			{ name: 'code', type: 'string' },
			{ name: 'birth', type: 'string' },
			{ name: 'stage', type: 'string' },
			{ name: 'pnotes', type: 'string' },
			{ name: 'log_brew', type: 'bool' },
			{ name: 'log_fermentation', type: 'bool' },
			{ name: 'inventory_reduced', type: 'bool' },
			{ name: 'plocked', type: 'bool' },
			{ name: 'eq_name', type: 'string' },
			{ name: 'eq_boil_size', type: 'float' },
			{ name: 'eq_batch_size', type: 'float' },
			{ name: 'eq_tun_volume', type: 'float' },
			{ name: 'eq_tun_weight', type: 'float' },
			{ name: 'eq_tun_specific_heat', type: 'float' },
			{ name: 'eq_tun_material', type: 'string' },
			{ name: 'eq_tun_height', type: 'float' },
			{ name: 'eq_top_up_water', type: 'float' },
			{ name: 'eq_trub_chiller_loss', type: 'float' },
			{ name: 'eq_evap_rate', type: 'float' },
			{ name: 'eq_boil_time', type: 'float' },
			{ name: 'eq_calc_boil_volume', type: 'bool' },
			{ name: 'eq_top_up_kettle', type: 'float' },
			{ name: 'eq_hop_utilization', type: 'float' },
			{ name: 'eq_notes', type: 'string' },
			{ name: 'eq_lauter_volume', type: 'float' },
			{ name: 'eq_lauter_height', type: 'float' },
			{ name: 'eq_lauter_deadspace', type: 'float' },
			{ name: 'eq_kettle_volume', type: 'float' },
		        { name: 'eq_kettle_height', type: 'float' },
			{ name: 'eq_mash_volume', type: 'float' },
			{ name: 'eq_efficiency', type: 'float' },
			{ name: 'brew_date_start', type: 'string' },
			{ name: 'brew_mash_ph', type: 'float' },
			{ name: 'brew_mash_sg', type: 'float' },
			{ name: 'brew_sparge_temperature', type: 'float' },
			{ name: 'brew_sparge_volume', type: 'float' },
			{ name: 'brew_sparge_ph', type: 'float' },
			{ name: 'brew_preboil_volume', type: 'float' },
			{ name: 'brew_preboil_sg', type: 'float' },
			{ name: 'brew_preboil_ph', type: 'float' },
			{ name: 'brew_aboil_volume', type: 'float' },
			{ name: 'brew_aboil_sg', type: 'float' },
			{ name: 'brew_aboil_ph', type: 'float' },
			{ name: 'brew_aboil_efficiency', type: 'float' },
			{ name: 'brew_cooling_method', type: 'string' },
			{ name: 'brew_cooling_time', type: 'float' },
			{ name: 'brew_cooling_to', type: 'float' },
			{ name: 'brew_whirlpool9', type: 'float' },
			{ name: 'brew_whirlpool7', type: 'float' },
			{ name: 'brew_whirlpool6', type: 'float' },
			{ name: 'brew_whirlpool2', type: 'float' },
			{ name: 'brew_fermenter_volume', type: 'float' },
			{ name: 'brew_fermenter_extrawater', type: 'float' },
			{ name: 'brew_aeration_time', type: 'float' },
			{ name: 'brew_aeration_speed', type: 'float' },
			{ name: 'brew_aeration_type', type: 'string' },
			{ name: 'brew_fermenter_sg', type: 'float' },
			{ name: 'brew_fermenter_ibu', type: 'float' },
			{ name: 'brew_date_end', type: 'string' },
			{ name: 'brew_log_available', type: 'bool' },
			{ name: 'primary_start_temp', type: 'float' },
			{ name: 'primary_max_temp', type: 'float' },
			{ name: 'primary_end_temp', type: 'float' },
			{ name: 'primary_end_sg', type: 'float' },
			{ name: 'primary_end_date', type: 'string' },
			{ name: 'secondary_temp', type: 'float' },
			{ name: 'secondary_end_date', type: 'string' },
			{ name: 'tertiary_temp', type: 'float' },
			{ name: 'package_date', type: 'string' },
			{ name: 'bottle_amount', type: 'float' },
			{ name: 'bottle_carbonation', type: 'float' },
			{ name: 'bottle_priming_sugar', type: 'string' },
			{ name: 'bottle_priming_amount', type: 'float' },
			{ name: 'bottle_carbonation_temp', type: 'float' },
			{ name: 'keg_amount', type: 'float' },
			{ name: 'keg_carbonation', type: 'float' },
			{ name: 'keg_priming_sugar', type: 'string' },
			{ name: 'keg_priming_amount', type: 'float' },
			{ name: 'keg_carbonation_temp', type: 'float' },
			{ name: 'keg_forced_carb', type: 'bool' },
			{ name: 'keg_pressure', type: 'float' },
			{ name: 'keg_priming_factor', type: 'float' },
			{ name: 'taste_notes', type: 'string' },
			{ name: 'taste_rate', type: 'float' },
			{ name: 'taste_date', type: 'string' },
			{ name: 'taste_color', type: 'string' },
			{ name: 'taste_transparency', type: 'string' },
			{ name: 'taste_head', type: 'string' },
			{ name: 'taste_aroma', type: 'string' },
			{ name: 'taste_taste', type: 'string' },
			{ name: 'taste_mouthfeel', type: 'string' },
			{ name: 'taste_aftertaste', type: 'string' },
			// From prod_recipes
			{ name: 'uuid', type: 'string' },
			{ name: 'locked', type: 'bool' },
			{ name: 'st_name', type: 'string' },
			{ name: 'st_letter', type: 'string' },
			{ name: 'st_guide', type: 'string' },
			{ name: 'st_category', type: 'string' },
			{ name: 'st_category_number', type: 'float' },
			{ name: 'st_type', type: 'string' },
			{ name: 'st_og_min', type: 'float' },
			{ name: 'st_og_max', type: 'float' },
			{ name: 'st_fg_min', type: 'float' },
			{ name: 'st_fg_max', type: 'float' },
			{ name: 'st_ibu_min', type: 'float' },
			{ name: 'st_ibu_max', type: 'float' },
			{ name: 'st_color_min', type: 'float' },
			{ name: 'st_color_max', type: 'float' },
			{ name: 'st_carb_min', type: 'float' },
			{ name: 'st_carb_max', type: 'float' },
			{ name: 'st_abv_min', type: 'float' },
			{ name: 'st_abv_max', type: 'float' },
			{ name: 'name', type: 'string' },
			{ name: 'notes', type: 'string' },
			{ name: 'type', type: 'string' },
			{ name: 'batch_size', type: 'float' },
			{ name: 'boil_size', type: 'float' },
			{ name: 'boil_time', type: 'float' },
			{ name: 'efficiency', type: 'float' },
			{ name: 'est_og', type: 'float' },
			{ name: 'est_fg', type: 'float' },
			{ name: 'est_abv', type: 'float' },
			{ name: 'est_color', type: 'float' },
			{ name: 'color_method', type: 'string' },
			{ name: 'est_ibu', type: 'float' },
			{ name: 'ibu_method', type: 'string' },
			{ name: 'est_carb', type: 'float' },
			{ name: 'mash_sparge_temp', type: 'float' },
			{ name: 'mash_ph', type: 'float' },
			{ name: 'mash_name', type: 'string' },
			{ name: 'fermentables', type: 'array' },
			{ name: 'hops', type: 'string' },
			{ name: 'miscs', type: 'string' },
			{ name: 'yeasts', type: 'string' },
			{ name: 'waters', type: 'array' },
			{ name: 'mashs', type: 'string' }
		],
		id: 'record',
		url: url + '?record=' + my_record
	};
	// Load data and select one record.
	var dataAdapter = new $.jqx.dataAdapter(source, {
		loadComplete: function () {
			var records = dataAdapter.records;
			dataRecord = records[0];
			// Hidden record uuid
			$("#pname").val(dataRecord.pname);
			$("#code").val(dataRecord.code);
			$("#birth").val(dataRecord.birth);
			$("#stage").val(dataRecord.stage);
			$("#pnotes").val(dataRecord.pnotes);
			$("#log_brew").val(dataRecord.log_brew);
			$("#log_fermentation").val(dataRecord.log_fermentation);
			$("#inventory_reduced").val(dataRecord.inventory_reduced);
			$("#plocked").val(dataRecord.plocked);
			$("#eq_name").val(dataRecord.eq_name);
			$("#eq_notes").val(dataRecord.eq_notes);
			$("#eq_boil_size").val(dataRecord.eq_boil_size);
			$("#eq_batch_size").val(dataRecord.eq_batch_size);
			$("#eq_tun_volume").val(dataRecord.eq_tun_volume);
			$("#eq_tun_weight").val(dataRecord.eq_tun_weight);
			$("#eq_tun_specific_heat").val(dataRecord.eq_tun_specific_heat);
			$("#eq_tun_material").val(dataRecord.eq_tun_material);
			$("#eq_tun_height").val(dataRecord.eq_tun_height);
			$("#eq_top_up_water").val(dataRecord.eq_top_up_water);
			$("#eq_trub_chiller_loss").val(dataRecord.eq_trub_chiller_loss);
			$("#eq_evap_rate").val(dataRecord.eq_evap_rate);
			$("#eq_boil_time").val(dataRecord.eq_boil_time);
			$("#eq_calc_boil_volume").val(dataRecord.eq_calc_boil_volume);
			$("#eq_top_up_kettle").val(dataRecord.eq_top_up_kettle);
			$("#eq_hop_utilization").val(dataRecord.eq_hop_utilization);
			$("#eq_lauter_volume").val(dataRecord.eq_lauter_volume);
			$("#eq_lauter_height").val(dataRecord.eq_lauter_height);
			$("#eq_lauter_deadspace").val(dataRecord.eq_lauter_deadspace);
			$("#eq_kettle_volume").val(dataRecord.eq_kettle_volume);
			$("#eq_kettle_height").val(dataRecord.eq_kettle_height);
			$("#eq_mash_volume").val(dataRecord.eq_mash_volume);
			$("#eq_efficiency").val(dataRecord.eq_efficiency);
			// Brewdate
			$("#brew_date_start").val(dataRecord.brew_date_start);
			$("#brew_mash_ph").val(dataRecord.brew_mash_ph);
			$("#brew_mash_sg").val(dataRecord.brew_mash_sg);
			// brew_mash_efficiency to calculate on th fly.
			// Header Spoelen en filteren
			$("#brew_sparge_temperature").val(dataRecord.brew_sparge_temperature);
			$("#brew_sparge_volume").val(dataRecord.brew_sparge_volume);
			$("#brew_sparge_ph").val(dataRecord.brew_sparge_ph);
			// Header Beluchten
			$("#brew_aeration_type").val(dataRecord.brew_aeration_type);
			$("#brew_aeration_time").val(dataRecord.brew_aeration_time);
			$("#brew_aeration_speed").val(dataRecord.brew_aeration_speed);

			$("#brew_preboil_ph").val(dataRecord.brew_preboil_ph);
			$("#brew_preboil_sg").val(dataRecord.brew_preboil_sg);
			$("#brew_preboil_volume").val(dataRecord.brew_preboil_volume);
			//$("#brew_preboil_efficiency").val(dataRecord.brew_preboil_efficiency);
			// Header Koelen en whirlpoolen
			$("#brew_whirlpool9").val(dataRecord.brew_whirlpool9);
			$("#brew_whirlpool7").val(dataRecord.brew_whirlpool7);
			$("#brew_whirlpool6").val(dataRecord.brew_whirlpool6);
			$("#brew_whirlpool2").val(dataRecord.brew_whirlpool2);
			// Header Naar gistvat
			$("#brew_fermenter_volume").val(dataRecord.brew_fermenter_volume);
			$("#brew_fermenter_sg").val(dataRecord.brew_fermenter_sg);
			$("#brew_fermenter_ibu").val(dataRecord.brew_fermenter_ibu);

			$("#brew_aboil_ph").val(dataRecord.brew_aboil_ph);
			$("#brew_aboil_sg").val(dataRecord.brew_aboil_sg);
			$("#brew_aboil_volume").val(dataRecord.brew_aboil_volume);
			$("#brew_aboil_efficiency").val(dataRecord.brew_aboil_efficiency);
			// Header Koelen en whirlpoolen
			$("#brew_cooling_to").val(dataRecord.brew_cooling_to);
			$("#brew_cooling_method").val(dataRecord.brew_cooling_method);
			$("#brew_cooling_time").val(dataRecord.brew_cooling_time);
			// Niks
			// Header Naar gistvat
			$("#brew_fermenter_extrawater").val(dataRecord.brew_fermenter_extrawater);
			$("#brew_fermenter_extrasugar").val(dataRecord.brew_fermenter_extrasugar);
			$("#brew_fermenter_color").val(dataRecord.brew_fermenter_color);
			$("#brew_date_end").val(dataRecord.brew_date_end);

			// Recipe
			// locked
			// st_ style settings.
			// name
			// notes
			// type
			old_batch_size = dataRecord.batch_size;
			// boil_size
			old_boil_time = dataRecord.boil_time;
			old_efficiency = dataRecord.efficiency;
			// est_og
			// est_fg
			// est_abv
			// est_color
			// color_method
			// est_ibu
			// ibu_method
			// mash_sparge_temp
			// mash_ph
			// mash_name
			// fermentables
			// hops
			// miscs
			// yeasts
			// waters
			// mashs

			switch (dataRecord.stage) {
				case 'Plan':		brewstage = 0;	break;
				case 'Wait':		brewstage = 1;	break;
				case 'Brew':		brewstage = 2;	break;
				case 'Primary':		brewstage = 3;	break;
				case 'Secondary':	brewstage = 4;	break;
				case 'Tertiary':	brewstage = 5;	break;
				case 'Package':		brewstage = 6;	break;
				case 'Carbonation':	brewstage = 7;	break;
				case 'Mature':		brewstage = 8;	break;
				case 'Taste':		brewstage = 9;	break;
				case 'Ready':		brewstage = 10;
							$("#plocked").jqxCheckBox({ disabled:false });
							break;
				case 'Closed':		brewstage = 11;
							$("#plocked").jqxCheckBox({ disabled:false });
							break;
			}
			// Enable or Disable settings depending on the stage.
			if (brewstage > 1)
				$("#equipmentSelect").jqxDropDownList({ disabled: true });
			if (brewstage > 0) {
				$("#Delete").jqxButton({ disabled: true });
				$("#birth").jqxDateTimeInput({ disabled: true });
			}
			if (brewstage < 3) {
				$("#brew_log").jqxButton({ disabled: true });
				$("#ferment_log").jqxButton({ disabled: true });
			} else {
				if (! dataRecord.log_brew)
					$("#brew_log").jqxButton({ disabled: true });
				if (! dataRecord.log_fermentation)
					$("#ferment_log").jqxButton({ disabled: true });
			}
			if (brewstage < 6)
				$("#inventory_reduced").jqxCheckBox({ disabled : true });
			else if ($('#inventory_reduced').jqxCheckBox('checked'))
				$("#inventory_reduced").jqxCheckBox({ disabled : true });

			calcFermentables();
			calcIBUs();
			calcSGendMash();
			calcMashEfficiency();
		},
		loadError: function (jqXHR, status, error) {
		}
	});
	dataAdapter.dataBind();

	// initialize the input fields.
	var srcMaterial= [ "RVS", "Aluminium", "Kunststof", "Koper" ];
	var srcAeration= [ 'None', 'Air', 'Oxygen' ];
	var srcCooling= [ '-', 'Emersion chiller', 'Counterflow chiller', 'Au bain marie', 'Natural' ];
	//                '-', 'Dompelkoeler', 'Tegenstroomkoeler', 'Au bain marie', 'Laten afkoelen'
	$("#pname").jqxInput({ theme: theme, width: 640, height: 23 });
	$("#code").jqxInput({ theme: theme, width: 100, height: 23 });
	$("#birth").jqxDateTimeInput({ theme: theme, width: 150, height: 23, formatString: 'yyyy-MM-dd' });
	$("#stage").jqxInput({ theme: theme, width: 100, height: 23 });
	$("#pnotes").jqxInput({ theme: theme, width: 960, height: 200 });
	$("#log_brew").jqxCheckBox({ theme: theme, width: 120, height: 23, disabled : true });
	$("#log_fermentation").jqxCheckBox({ theme: theme, width: 120, height: 23, disabled : true });
	$("#inventory_reduced").jqxCheckBox({ theme: theme, width: 120, height: 23 });
	$('#inventory_reduced').on('checked', function (event) {
		// Call a script to do the work and block this.
		// Note that this script must set this flag too, so of the user doesn't Save it is still set.
		// Call the script with the uuid.
		$("#inventory_reduced").jqxCheckBox({ disabled : true });
	});
	$("#plocked").jqxCheckBox({ theme: theme, width: 120, height: 23, disabled : true });
	$('#plocked').on('checked', function (event) {
		if (brewstage >= 10) {
			$("#stage").val('Closed');
			brewstage = 11;
		}
	});
	$('#plocked').on('unchecked', function (event) {
		if (brewstage >= 10) {
			$("#stage").val('Ready');
			brewstage = 10;
		}
	});
	$("#eq_name").jqxInput({ theme: theme, width: 250, height: 23 });
	$("#eq_boil_size").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_batch_size").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_tun_volume").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_tun_weight").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 2 });
	$("#eq_tun_specific_heat").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 3 });
	$("#eq_tun_material").jqxInput({ theme: theme, width: 100, height: 23 });
	$("#eq_tun_height").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_top_up_water").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_trub_chiller_loss").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_evap_rate").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 2,  });
	$("#eq_boil_time").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 0 });
	$("#eq_calc_boil_volume").jqxCheckBox({ theme: theme, width: 120, height: 23 });
	$("#eq_top_up_kettle").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_hop_utilization").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 0 });
	$("#eq_notes").jqxInput({ theme: theme, width: 640, height: 100 });
	$("#eq_lauter_volume").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_lauter_height").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_lauter_deadspace").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_kettle_volume").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_kettle_height").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_mash_volume").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_efficiency").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	// Brewday
	$("#brew_date_start").jqxDateTimeInput({ theme: theme, width: 230, height: 23, formatString: 'yyyy-MM-dd HH:mm:ss', showTimeButton: true });
	$("#brew_mash_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_mash_sg").jqxNumberInput({ inputMode: 'simple',  spinMode: 'simple', theme: theme, width: 90, height: 23, min: 1.000, max: 1.200, decimalDigits: 3, spinButtons: true, spinButtonsStep: 0.001 });
	$("#brew_mash_sg").on('valueChanged', function () { calcMashEfficiency(); });
	$("#brew_mash_efficiency").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#brew_sparge_temperature").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_sparge_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_sparge_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, max: 14, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_preboil_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_preboil_sg").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 3, spinButtons: true, spinButtonsStep: 0.001 });
	$("#brew_preboil_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_preboil_efficiency").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#brew_aboil_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_aboil_sg").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 3, spinButtons: true, spinButtonsStep: 0.001 });
	$("#brew_aboil_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_aboil_efficiency").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#brew_whirlpool9").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, max: 120, decimalDigits: 0, spinButtons: true });
	$("#brew_whirlpool7").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, max: 120, decimalDigits: 0, spinButtons: true });
	$("#brew_whirlpool6").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, max: 120, decimalDigits: 0, spinButtons: true });
	$("#brew_whirlpool2").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, max: 120, decimalDigits: 0, spinButtons: true });
	$("#brew_cooling_method").jqxDropDownList({ theme: theme, source: srcCooling, width: 170, height: 23, dropDownHeight: 153 });
	$("#brew_cooling_to").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_cooling_time").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, max: 1440, decimalDigits: 0, spinButtons: true });
	$("#brew_aeration_type").jqxDropDownList({ theme: theme, source: srcAeration, width: 100, height: 23, dropDownHeight: 95 });
	$("#brew_aeration_time").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, max: 1440, decimalDigits: 0, spinButtons: true });
	$("#brew_aeration_speed").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, max: 1440, decimalDigits: 0, spinButtons: true });
	$("#brew_fermenter_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_fermenter_extrawater").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_fermenter_extrasugar").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_fermenter_sg").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 3 });
	$("#brew_fermenter_ibu").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 0 });
	$("#brew_fermenter_color").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 0 });
	$("#brew_date_end").jqxDateTimeInput({ theme: theme, width: 230, height: 23, formatString: 'yyyy-MM-dd HH:mm:ss', showTimeButton: true });
	// Vergisting
	// Packaging
	// Tasting

	// Recipe
	$("#est_og").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 3 });
	$("#est_ibu").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 0 });
	$("#est_color").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 0 });
	$("#est_mash_sg").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 3 });

	$('#jqxTabs').jqxTabs({
		theme: theme,
		width: 1280,
		height: 630,
		autoHeight: false,
		position: 'top'
	});

	// Buttons sidebar
	$("#rec_edit").jqxButton({ template: "primary", width: '140px', theme: theme });
	$("#brew_log").jqxButton({ template: "primary", width: '140px', theme: theme });
	$("#ferment_log").jqxButton({ template: "primary", width: '140px', theme: theme });

	// Buttons below
	$("#Delete").jqxButton({ template: "danger", width: '80px', theme: theme });
	$("#Delete").click(function () {
		// Open a popup to confirm this action.
		$('#eventWindow').jqxWindow('open');
		$("#delOk").click(function () {
			var data = "delete=true&" + $.param({ uuid: dataRecord.puuid });
			$.ajax({
				dataType: 'json',
				url: url,
				cache: false,
				data: data,
				type: "POST",
				success: function (data, status, xhr) {
					// delete command is executed.
					window.location.href = my_return;
				},
				error: function (jqXHR, textStatus, errorThrown) {
				}
			});
		});
	});

	$("#Cancel").jqxButton({ template: "primary", width: '80px', theme: theme });
	$("#Cancel").click(function () {
		window.location.href = my_return;
	});

	$("#Save").jqxButton({ template: "success", width: '90px', theme: theme });
	$("#Save").click(function () {
		console.log(dataRecord.puuid);

		var row = {
			record: my_record,
			puuid: dataRecord.puuid,
			pname: $("#pname").val(),
			code: $("#code").val(),
			birth: $("#birth").val(),
			stage: $("#stage").val(),
			pnotes: $("#pnotes").val(),
			log_brew: $("#log_brew").val(),
			log_fermentation: $("#log_fermentation").val(),
			inventory_reduced: $("#inventory_reduced").val(),
			plocked: $("#plocked").val(),
			eq_name: $("#eq_name").val(),
			eq_boil_size: parseFloat($("#eq_boil_size").jqxNumberInput('decimal')),
			eq_batch_size: parseFloat($("#eq_batch_size").jqxNumberInput('decimal')),
			eq_tun_volume: parseFloat($("#eq_tun_volume").jqxNumberInput('decimal')),
			eq_tun_weight: parseFloat($("#eq_tun_weight").jqxNumberInput('decimal')),
			eq_tun_specific_heat: parseFloat($("#eq_tun_specific_heat").jqxNumberInput('decimal')),
			eq_tun_material: $("#eq_tun_material").val(),
			eq_tun_height: parseFloat($("#eq_tun_height").jqxNumberInput('decimal')),
			eq_top_up_water: parseFloat($("#eq_top_up_water").jqxNumberInput('decimal')),
			eq_trub_chiller_loss: parseFloat($("#eq_trub_chiller_loss").jqxNumberInput('decimal')),
			eq_evap_rate: parseFloat($("#eq_evap_rate").jqxNumberInput('decimal')),
			eq_boil_time: parseFloat($("#eq_boil_time").jqxNumberInput('decimal')),
			eq_calc_boil_volume: $("#eq_calc_boil_volume").val(),
			eq_top_up_kettle: parseFloat($("#eq_top_up_kettle").jqxNumberInput('decimal')),
			eq_hop_utilization: parseFloat($("#eq_hop_utilization").jqxNumberInput('decimal')),
			eq_notes: $("#eq_notes").val(),
			eq_lauter_volume: parseFloat($("#eq_lauter_volume").jqxNumberInput('decimal')),
			eq_lauter_height: parseFloat($("#eq_lauter_height").jqxNumberInput('decimal')),
			eq_lauter_deadspace: parseFloat($("#eq_lauter_deadspace").jqxNumberInput('decimal')),
			eq_kettle_volume: parseFloat($("#eq_kettle_volume").jqxNumberInput('decimal')),
			eq_kettle_height: parseFloat($("#eq_kettle_height").jqxNumberInput('decimal')),
			eq_mash_volume: parseFloat($("#eq_mash_volume").jqxNumberInput('decimal')),
			eq_efficiency: parseFloat($("#eq_efficiency").jqxNumberInput('decimal'))
		};
		var data = "update=true&" + $.param(row);
		$.ajax({
			dataType: 'json',
			url: url,
			cache: false,
			data: data,
			type: "POST",
			success: function (data, status, xhr) {
				// update command is executed.
				window.location.href = my_return;
			},
			error: function(jqXHR, textStatus, errorThrown) {
			}
		});
	});	
	createDelElements();
});

mercurial