www/includes/db_recipes.php

changeset 221
a8aabb63fbcc
parent 220
14e349ff2a10
child 222
78946739b3a6
--- a/www/includes/db_recipes.php	Tue Jan 29 21:52:08 2019 +0100
+++ b/www/includes/db_recipes.php	Wed Jan 30 16:40:23 2019 +0100
@@ -328,10 +328,34 @@
 		$recipes .= ',"wa_acid_name":' . $row['wa_acid_name'];
 		$recipes .= ',"wa_acid_perc":' . $row['wa_acid_perc'];
 		$recipes .= ',"wa_base_name":' . $row['wa_base_name'];
-		$recipes .= ',"fermentables":' . $row['json_fermentables'];
-		$recipes .= ',"hops":' . $row['json_hops'];
-		$recipes .= ',"miscs":' . $row['json_miscs'];
-		$recipes .= ',"yeasts":' . $row['json_yeasts'];
+		if (isset($_GET['record'])) {
+			// Append stock information.
+			$fermentables = json_decode($row['json_fermentables'], true);
+			for ($i = 0; $i < count($fermentables); $i++) {
+				$fermentables[$i]['f_inventory'] = 0;	// Not in stock
+				$fermentables[$i]['f_avail'] = 0;	// Ingredient not in db
+				$sql2 = "SELECT inventory FROM inventory_fermentables ";
+				$sql2 .= "WHERE name='".$fermentables[$i]['f_name']."' AND supplier='".$fermentables[$i]['f_supplier']."'";
+				if ($result2 = mysqli_query($connect, $sql2)) {
+					if ($obj = mysqli_fetch_object($result2)) {
+						$fermentables[$i]['f_inventory'] = $obj->inventory;
+						$fermentables[$i]['f_avail'] = 1;
+					}
+					mysqli_free_result($result2);
+				}
+			}
+			syslog(LOG_NOTICE, json_encode($fermentables, JSON_UNESCAPED_UNICODE));
+			$recipes .= ',"fermentables":' . json_encode($fermentables, JSON_UNESCAPED_UNICODE);
+			$recipes .= ',"hops":' . $row['json_hops'];
+			$recipes .= ',"miscs":' . $row['json_miscs'];
+			$recipes .= ',"yeasts":' . $row['json_yeasts'];
+		} else {
+			// Just leave it.
+			$recipes .= ',"fermentables":' . $row['json_fermentables'];
+			$recipes .= ',"hops":' . $row['json_hops'];
+			$recipes .= ',"miscs":' . $row['json_miscs'];
+			$recipes .= ',"yeasts":' . $row['json_yeasts'];
+		}
 		$recipes .= ',"mashs":' . $row['json_mashs'];
 		$recipes .= '}';
 	}

mercurial