www/includes/db_product.php

changeset 740
04c0e444e48e
parent 738
11e6bd8d8107
child 757
d13be50c0049
--- a/www/includes/db_product.php	Thu Apr 15 13:10:21 2021 +0200
+++ b/www/includes/db_product.php	Sun May 02 22:03:25 2021 +0200
@@ -911,6 +911,7 @@
 		$brew .= ',"divide_part":' . $row['divide_part'];
 
 		if (isset($_GET['record'])) {
+			$mashkg = 0.0;
 			// Append stock information.
 			$fermentables = json_decode($row['json_fermentables'], true);
 			for ($i = 0; $i < count($fermentables); $i++) {
@@ -926,6 +927,9 @@
 					}
 					mysqli_free_result($result2);
 				}
+				if ($fermentables[$i]['f_added'] == 0) {
+					$mashkg += floatval($fermentables[$i]['f_amount']);
+				}
 			}
 			$brew .= ',"fermentables":' . json_encode($fermentables, JSON_UNESCAPED_UNICODE);
 
@@ -1033,14 +1037,40 @@
 				}
 			}
 			$brew .= ',"yeasts":' . json_encode($yeasts, JSON_UNESCAPED_UNICODE);
+
+        		//syslog(LOG_NOTICE, $row['json_mashs']);
+			$mashs = json_decode($row['json_mashs'], true);
+			$mashvol = 0.0;
+			for ($i = 0; $i < count($mashs); $i++) {
+				/* Upgrade missing data */
+				if (($mashs[$i]['step_type'] == 0) && (floatval($mashs[$i]['step_infuse_amount']) > 0))
+					$mashvol += floatval($mashs[$i]['step_infuse_amount']);
+				if (($mashs[$i]['step_type'] == 0) && (! isset($mashs[$i]['step_infuse_temp']))) {
+					if ($i == 0)
+						$mashs[$i]['step_infuse_temp'] = floatval($mashs[$i]['step_temp']) + 0.5;
+					else
+						$mashs[$i]['step_infuse_temp'] = 99.0;
+				}
+				if (! isset($mashs[$i]['step_volume']))
+					$mashs[$i]['step_volume'] = $mashvol;
+				if (! isset($mashs[$i]['step_wg_ratio']))
+					$mashs[$i]['step_wg_ratio'] = round(($mashvol / $mashkg) * 1000000) / 1000000;
+				if (! isset($mashs[$i]['step_ph']))
+					$mashs[$i]['step_ph'] = 0.0;
+				if (! isset($mashs[$i]['step_sg']))
+					$mashs[$i]['step_sg'] = 0.0;
+			}
+			$brew .= ',"mashs":' . json_encode($mashs, JSON_UNESCAPED_UNICODE);
+
 		} else {
 			// Just leave it
 			$brew .= ',"fermentables":' . $row['json_fermentables'];
 			$brew .= ',"hops":' . $row['json_hops'];
 			$brew .= ',"miscs":' . $row['json_miscs'];
 			$brew .= ',"yeasts":' . $row['json_yeasts'];
+			$brew .= ',"mashs":' . $row['json_mashs'];
 		}
-		$brew .= ',"mashs":' . $row['json_mashs'];
+
 		$brew .= '}';
 //		syslog(LOG_NOTICE, $brew);
 		$brews .= $brew;

mercurial