www/includes/db_inventory_yeasts.php

Sat, 11 May 2019 23:13:40 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 11 May 2019 23:13:40 +0200
changeset 358
3be8c2278fd7
parent 313
9f45d09c2071
child 512
4451af8b6295
permissions
-rw-r--r--

Added flags for each ingredient group for the supplies state. On the main screen show the state of the supplies if the product stage is not yet packaged. Calculate the state of the supplies for fermentables, hops, yeasts and miscs. In the grids don't show the inventory values after they are used and reduced. On the fermentables tab show the weight of the grains to mash.

<?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" );

// get data and store in a json array
if (isset($_POST['insert']) || isset($_POST['update'])) {
	if (isset($_POST['insert'])) {
		$sql  = "INSERT INTO `inventory_yeasts` SET ";
	}
	if (isset($_POST['update'])) {
		$sql  = "UPDATE `inventory_yeasts` SET ";
	}

	$sql .= "name='" . mysqli_real_escape_string($connect, $_POST['name']);
	$sql .= "', type='" . $_POST['type'];
	$sql .= "', form='" . $_POST['form'];
	$sql .= "', laboratory='" . mysqli_real_escape_string($connect, $_POST['laboratory']);
	$sql .= "', product_id='" . mysqli_real_escape_string($connect, $_POST['product_id']);
	$sql .= "', min_temperature='" . $_POST['min_temperature'];
	$sql .= "', max_temperature='" . $_POST['max_temperature'];
	$sql .= "', flocculation='" . $_POST['flocculation'];
	$sql .= "', attenuation='" . $_POST['attenuation'];
	$sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']);
	$sql .= "', best_for='" . mysqli_real_escape_string($connect, $_POST['best_for']);
	$sql .= "', max_reuse='" . $_POST['max_reuse'];
	$sql .= "', cells='" . floatval($_POST['cells']) * 1000000000.0;
	$sql .= "', tolerance='" . $_POST['tolerance'];
	$sql .= "', inventory='" . $_POST['inventory'];
	$sql .= "', cost='" . $_POST['cost'] . "'";
	if ($_POST['production_date'] == '')
		$sql .= ", production_date=NULL";
	else
		$sql .= ", production_date='" . $_POST['production_date'] . "'";
	if ($_POST['tht_date'] == '')
		$sql .= ", tht_date=NULL";
	else
		$sql .= ", tht_date='" . $_POST['tht_date'] . "'";
	if (isset($_POST['insert'])) {
		$sql .= ";";
	}
	if (isset($_POST['update'])) {
		$sql .= " WHERE record='" . $_POST['record'] . "';";
	}
	syslog(LOG_NOTICE, $sql);

	$result = mysqli_query($connect, $sql);
	if (! $result) {
		syslog(LOG_NOTICE, "db_inventory_yeasts: ".$sql." result: ".mysqli_error($connect));
	} else {
		if (isset($_POST['update'])) {
			syslog(LOG_NOTICE, "db_inventory_yeasts: updated record ".$_POST['record']);
		} else {
			$lastid = mysqli_insert_id($connect);
			syslog(LOG_NOTICE, "db_inventory_yeasts: inserted record ".$lastid);
		}
	}
	echo $result;

} else if (isset($_POST['delete'])) {
	// DELETE COMMAND
	$sql = "DELETE FROM `inventory_yeasts` WHERE record='".$_POST['record']."';";
	$result = mysqli_query($connect, $sql);
	if (! $result) {
		syslog(LOG_NOTICE, "db_inventory_yeasts: ".$sql." result: ".mysqli_error($connect));
	} else {
		syslog(LOG_NOTICE, "db_inventory_yeasts: deleted record ".$_POST['record']);
	}
	echo $result;

} else {
	// SELECT COMMAND
	$query = "SELECT * FROM inventory_yeasts ORDER BY laboratory,product_id,name";
	$result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
	while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
		$yeasts[] = array(
			'record' => $row['record'],
			'name' => $row['name'],
			'type' => $row['type'],
			'form' => $row['form'],
			'laboratory' => $row['laboratory'],
			'product_id' => $row['product_id'],
			'min_temperature' => $row['min_temperature'],
			'max_temperature' => $row['max_temperature'],
			'flocculation' => $row['flocculation'],
			'attenuation' => $row['attenuation'],
			'notes' => $row['notes'],
			'best_for' => $row['best_for'],
			'max_reuse' => $row['max_reuse'],
			'inventory' => $row['inventory'],
			'cost' => $row['cost'],
			'production_date' => $row['production_date'],
			'tht_date' => $row['tht_date'],
			'cells' => floatval($row['cells']) / 1000000000.0,
			'tolerance' => $row['tolerance']
		);
	}
	header("Content-type: application/json");
	echo json_encode($yeasts);
}
?>

mercurial