diff -r 0e44535f7435 -r c314277905e6 www/includes/db_recipes.php --- a/www/includes/db_recipes.php Tue Apr 30 16:12:09 2019 +0200 +++ b/www/includes/db_recipes.php Wed May 08 22:22:20 2019 +0200 @@ -244,9 +244,9 @@ $mash .= ',"step_infuse_amount":0'; $mash .= ',"step_temp":' . $item['step_temp']; $mash .= ',"step_time":' . $item['step_time']; + $mash .= ',"step_thickness":' . $item['step_thickness']; $mash .= ',"ramp_time":' . $item['ramp_time']; $mash .= ',"end_temp":' . $item['end_temp'] . '}'; - //syslog(LOG_NOTICE, $mash); $mashs .= $mash; } } @@ -297,6 +297,7 @@ $recipes = '['; $comma = FALSE; while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { + $mashkg = 0; // Manual encode to JSON. if ($comma) { $recipes .= ','; @@ -375,6 +376,9 @@ // Append stock information. $fermentables = json_decode($row['json_fermentables'], true); for ($i = 0; $i < count($fermentables); $i++) { + if ($fermentables[$i]['f_added'] == 0) { + $mashkg += $fermentables[$i]['f_amount']; + } $fermentables[$i]['f_inventory'] = 0; // Not in stock $fermentables[$i]['f_avail'] = 0; // Ingredient not in db $sql2 = "SELECT inventory FROM inventory_fermentables "; @@ -453,7 +457,20 @@ $recipes .= ',"miscs":' . $row['json_miscs']; $recipes .= ',"yeasts":' . $row['json_yeasts']; } - $recipes .= ',"mashs":' . $row['json_mashs']; + if (isset($_GET['record'])) { + $volume = 0; + $mashs = json_decode($row['json_mashs'], true); + for ($i = 0; $i < count($mashs); $i++) { + $volume += $mashs[$i]['step_infuse_amount']; + if ($mashkg > 0) + $mashs[$i]['step_thickness'] = floatval(sprintf("%.3f", $volume / $mashkg)); + else + $mashs[$i]['step_thickness'] = 0; + } + $recipes .= ',"mashs":' . json_encode($mashs, JSON_UNESCAPED_UNICODE); + } else { + $recipes .= ',"mashs":' . $row['json_mashs']; + } $recipes .= '}'; } $recipes .= ']';