www/includes/db_inventory_equipments.php

Sun, 02 Jun 2019 12:48:54 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 02 Jun 2019 12:48:54 +0200
changeset 392
544d7d0183b2
parent 296
69fadd1aded2
child 715
8fb922c00a2d
permissions
-rw-r--r--

Added 15 fields to the recipes table. Added 18 fields to the products table. These are calculated values that are now stored in the database so export programs can use these values without calculating them again. Product and recipe print have water and mash schedule added. Product print has brewday results added if the brewday is over. The ingredients layout changed in the product and recipe prints.

<?php
require($_SERVER['DOCUMENT_ROOT']."/config.php");
require($_SERVER['DOCUMENT_ROOT']."/version.php");

#Connect to the database
$connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
if (! $connect) {
	die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}
mysqli_set_charset($connect, "utf8" );

if (isset($_POST['insert']) || isset($_POST['update'])) {
	if (isset($_POST['insert'])) {
		// INSERT COMMAND
		$sql  = "INSERT INTO `inventory_equipments` SET ";
	}
	if (isset($_POST['update'])) {
		// UPDATE COMMAND
		$sql  = "UPDATE `inventory_equipments` SET ";
	}
	$sql .=    "name='" . mysqli_real_escape_string($connect, $_POST['name']);
	$sql .= "', boil_size='" . $_POST['boil_size'];
	$sql .= "', batch_size='" . $_POST['batch_size'];
	$sql .= "', tun_volume='" . $_POST['tun_volume'];
	$sql .= "', tun_weight='" . $_POST['tun_weight'];
	$sql .= "', tun_specific_heat='" .  $_POST['tun_specific_heat'];
	$sql .= "', tun_material='" . $_POST['tun_material'];
	$sql .= "', tun_height='" . floatval($_POST['tun_height']) / 100.0;
	$sql .= "', top_up_water='" . $_POST['top_up_water'];
	$sql .= "', trub_chiller_loss='" . $_POST['trub_chiller_loss'];
	$sql .= "', evap_rate='" . $_POST['evap_rate'];
	$sql .= "', boil_time='" . $_POST['boil_time'];
	($_POST['calc_boil_volume'] == 'true') ? $sql .= "', calc_boil_volume='1" : $sql .= "', calc_boil_volume='0";
	$sql .= "', top_up_kettle='" . $_POST['top_up_kettle'];
	$sql .= "', hop_utilization='" . $_POST['hop_utilization'];
	$sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']);
	$sql .= "', lauter_volume='" . $_POST['lauter_volume'];
	$sql .= "', lauter_height='" . floatval($_POST['lauter_height']) / 100.0;
	$sql .= "', lauter_deadspace='" . $_POST['lauter_deadspace'];
	$sql .= "', kettle_volume='" . $_POST['kettle_volume'];
	$sql .= "', kettle_height='" . floatval($_POST['kettle_height']) / 100.0;
	$sql .= "', mash_volume='" . $_POST['mash_volume'];
	$sql .= "', mash_max='" . $_POST['mash_max'];
	$sql .= "', efficiency='" . $_POST['efficiency'];
	if (isset($_POST['insert'])) {
		$sql .= "';";
	}
	if (isset($_POST['update'])) {
		$sql .= "' WHERE record='" . $_POST['record'] . "';";
	}
	$result = mysqli_query($connect, $sql);
	if (! $result) {
		syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect));
	} else {
		if (isset($_POST['update'])) {
			syslog(LOG_NOTICE, "db_inventory_equipment: updated record ".$_POST['record']);
		} else {
			$lastid = mysqli_insert_id($connect);
			syslog(LOG_NOTICE, "db_inventory_equipment: inserted record ".$lastid);
		}
	}
	echo $result;

} else if (isset($_POST['delete'])) {
	// DELETE COMMAND
	// FIXME: need to check if the record is in use
	$sql = "DELETE FROM `inventory_equipments` WHERE record='".$_POST['record']."';";
	$result = mysqli_query($connect, $sql);
	if (! $result) {
		syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect));
	} else {
		syslog(LOG_NOTICE, "db_inventory_equipment: deleted record ".$_POST['record']);
	}
	echo $result;

} else {
	// SELECT COMMAND
	$query = "SELECT * FROM inventory_equipments ORDER BY name";
	$result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
	while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
		$equipments[] = array(
			'record' => $row['record'],
			'name' => $row['name'],
			'boil_size' => $row['boil_size'],
			'batch_size' => $row['batch_size'],
			'tun_volume' => $row['tun_volume'],
			'tun_weight' => $row['tun_weight'],
			'tun_specific_heat' => $row['tun_specific_heat'],
			'tun_material' => $row['tun_material'],
			'tun_height' => floatval($row['tun_height']) * 100.0,
			'top_up_water' => $row['top_up_water'],
			'trub_chiller_loss' => $row['trub_chiller_loss'],
			'evap_rate' => $row['evap_rate'],
			'boil_time' => $row['boil_time'],
			'calc_boil_volume' => $row['calc_boil_volume'],
			'top_up_kettle' => $row['top_up_kettle'],
			'hop_utilization' => $row['hop_utilization'],
			'notes' => $row['notes'],
			'lauter_volume' => $row['lauter_volume'],
			'lauter_height' => floatval($row['lauter_height']) * 100.0,
			'lauter_deadspace' => $row['lauter_deadspace'],
			'kettle_volume' => $row['kettle_volume'],
			'kettle_height' => floatval($row['kettle_height']) * 100.0,
			'mash_volume' => $row['mash_volume'],
			'mash_max' => $row['mash_max'],
			'efficiency' => $row['efficiency']
		);
	}
	header("Content-type: application/json");
	echo json_encode($equipments);
}
?>

mercurial