diff -r 0a39cbdcf085 -r 082c23b26055 www/import/from_brouwhulp.php --- a/www/import/from_brouwhulp.php Mon Nov 12 11:32:16 2018 +0100 +++ b/www/import/from_brouwhulp.php Mon Nov 12 16:34:43 2018 +0100 @@ -18,6 +18,19 @@ $brouwhulp = '/home/mbroek/Documents/brouwhulp'; +function get_miscs_cost($miscname) { + global $db; + + if ($result = mysqli_query($db, "SELECT cost FROM inventory_miscs WHERE name='$miscname'")) { + if ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { + return floatval($row['cost']); + } + } + return 0.0; +} + + + function do_fermentables() { global $brouwhulp, $db; @@ -455,6 +468,7 @@ $pCara = 0; $pSugar = 0; $svg = 77; + $colorw = 0; $sql = "INSERT INTO recipes SET name='" . mysqli_real_escape_string($db, $recipe->NAME); if ($recipe->NOTES) @@ -477,11 +491,7 @@ $sql .= "', efficiency='" . $efficiency; /* Don't use $recipe->EST_OG but recalculate it */ /* Don't use $recipe->EST_FG but recalculate it */ - if ($recipe->EST_COLOR) { - $srm = floatval($recipe->EST_COLOR); - $ebc = srm_to_ebc($srm); - $sql .= "', est_color='" . $ebc; - } + /* Don't use $recipe->EST_COLOR but recalculate it */ if ($recipe->COLOR_METHOD) $sql .= "', color_method='" . mysqli_real_escape_string($db, $recipe->COLOR_METHOD); if ($recipe->IBU) @@ -561,6 +571,7 @@ $fermentables .= ',"f_yield":' . $fyield; if ($fermentable->COLOR) { $srm = floatval($fermentable->COLOR); + $colorw += ($famount * $srm / $batch_size) * 8.34436; /* Kleurwerking */ $ebc = srm_to_ebc($srm); $fermentables .= ',"f_color":' . $ebc; } @@ -684,12 +695,19 @@ if ($comma) $miscs .= ','; $comma = TRUE; - $miscs .= '{"m_name":"' . mysqli_real_escape_string($db, $misc->NAME) . '"'; + $mname = mysqli_real_escape_string($db, $misc->NAME); + $miscs .= '{"m_name":"' . $mname . '"'; $miscs .= ',"m_amount":' . floatval($misc->AMOUNT); - if ($misc->COST) + if ($misc->COST) { $miscs .= ',"m_cost":' . floatval($misc->COST); - else - $miscs .= ',"m_cost":0'; + } else { + /* Brouwhulp bug, added water agents have no cost field. */ + if ($misc->TYPE == "Water agent") { + $miscs .= ',"m_cost":'. get_miscs_cost($mname); + } else { + $miscs .= ',"m_cost":0'; + } + } $miscs .= ',"m_type":"' . mysqli_real_escape_string($db, $misc->TYPE) . '"'; $miscs .= ',"m_use_use":"' . mysqli_real_escape_string($db, $misc->USE) . '"'; ($misc->AMOUNT_IS_WEIGHT== "TRUE") ? $miscs .= ',"m_amount_is_weight":true' : $miscs.= ',"m_amount_is_weight":false'; @@ -839,7 +857,8 @@ $sql .= "', est_fg='" . floatval($fg); $abv = abvol($og, $fg); $sql .= "', est_abv='" . floatval($abv); - + $color = kw_to_ebc(mysqli_real_escape_string($db, $recipe->COLOR_METHOD), $colorw); + $sql .= "', est_color='" . floatval($color); $sql .= "';"; if (! $result = mysqli_query($db, $sql)) { printf("Error: %s\n", mysqli_error($db));