www/import/from_brouwhulp.php

changeset 150
159d7a89fcef
parent 149
ff45488d480e
child 151
2c9cfe2f0860
equal deleted inserted replaced
149:ff45488d480e 150:159d7a89fcef
993 $boil_size = 22; 993 $boil_size = 22;
994 $pCara = 0; 994 $pCara = 0;
995 $pSugar = 0; 995 $pSugar = 0;
996 $svg = 77; 996 $svg = 77;
997 $colorw = 0; 997 $colorw = 0;
998 $stageno = 0;
998 $stage = "Plan"; // Default value. 999 $stage = "Plan"; // Default value.
999 $uuid = str_replace("\n", "", file_get_contents('/proc/sys/kernel/random/uuid')); 1000 $uuid = str_replace("\n", "", file_get_contents('/proc/sys/kernel/random/uuid'));
1000 1001
1001 $psql = "INSERT INTO prod_main SET puuid='" . $uuid; // So we can link the records. 1002 $psql = "INSERT INTO prod_main SET puuid='" . $uuid; // So we can link the records.
1002 $rsql = "INSERT INTO prod_recipes SET uuid='" . $uuid; 1003 $rsql = "INSERT INTO prod_recipes SET uuid='" . $uuid;
1237 } 1238 }
1238 1239
1239 if (($recipe->DATE) && (! $recipe->TIME_STARTED) && (! $recipe->TIME_ENDED)) { 1240 if (($recipe->DATE) && (! $recipe->TIME_STARTED) && (! $recipe->TIME_ENDED)) {
1240 /* We have a plan date but haven't brewed yet, use current date */ 1241 /* We have a plan date but haven't brewed yet, use current date */
1241 $psql .= "', birth='" . date("Y-m-d"); 1242 $psql .= "', birth='" . date("Y-m-d");
1243 $stageno= 1;
1242 $stage = "Wait"; 1244 $stage = "Wait";
1243 } 1245 }
1244 1246
1245 if (($recipe->DATE) && ($recipe->TIME_STARTED) && ($recipe->TIME_ENDED)) { 1247 if (($recipe->DATE) && ($recipe->TIME_STARTED) && ($recipe->TIME_ENDED)) {
1246 /* We have brew data */ 1248 /* We have brew data */
1249 $stageno = 3;
1247 $stage = "Primary"; // Need to think about during a brew... 1250 $stage = "Primary"; // Need to think about during a brew...
1248 $brewdate = substr($recipe->DATE, 6, 4).substr($recipe->DATE,2,4).substr($recipe->DATE,0,2); 1251 $brewdate = substr($recipe->DATE, 6, 4).substr($recipe->DATE,2,4).substr($recipe->DATE,0,2);
1249 $psql .= "', birth='" . $brewdate; 1252 $psql .= "', birth='" . $brewdate;
1250 $date_start = $brewdate.' '.$recipe->TIME_STARTED; 1253 $date_start = $brewdate.' '.$recipe->TIME_STARTED;
1251 $date_end = $brewdate.' '.$recipe->TIME_ENDED; 1254 $date_end = $brewdate.' '.$recipe->TIME_ENDED;
1290 $psql .= "', brew_aeration_time='" . floatval($recipe->AERATION_TIME); 1293 $psql .= "', brew_aeration_time='" . floatval($recipe->AERATION_TIME);
1291 } 1294 }
1292 $psql .= "', brew_date_end='" . $date_end; 1295 $psql .= "', brew_date_end='" . $date_end;
1293 } 1296 }
1294 1297
1295 if ($recipe->PRIMARY_AGE) { 1298 if ($recipe->PRIMARY_AGE && ($stageno >= 3)) {
1296 /* PRIMARY_TEMP is the average of START_TEMP_PRIMARY MAX_TEMP_PRIMARY END_TEMP_PRIMARY */ 1299 /* PRIMARY_TEMP is the average of START_TEMP_PRIMARY MAX_TEMP_PRIMARY END_TEMP_PRIMARY */
1297 $pdate = new DateTime($brewdate); 1300 $pdate = new DateTime($brewdate);
1298 $pdate->modify("+".floatval($recipe->PRIMARY_AGE)." days"); 1301 $pdate->modify("+".floatval($recipe->PRIMARY_AGE)." days");
1299 $psql .= "', primary_start_temp='" . floatval($recipe->START_TEMP_PRIMARY); 1302 $psql .= "', primary_start_temp='" . floatval($recipe->START_TEMP_PRIMARY);
1300 $psql .= "', primary_max_temp='" . floatval($recipe->MAX_TEMP_PRIMARY); 1303 $psql .= "', primary_max_temp='" . floatval($recipe->MAX_TEMP_PRIMARY);
1301 $psql .= "', primary_end_temp='" . floatval($recipe->END_TEMP_PRIMARY); 1304 $psql .= "', primary_end_temp='" . floatval($recipe->END_TEMP_PRIMARY);
1302 $psql .= "', primary_end_sg='" . floatval($recipe->SG_END_PRIMARY); 1305 $psql .= "', primary_end_sg='" . floatval($recipe->SG_END_PRIMARY);
1303 $psql .= "', primary_end_date='" . $pdate->format("Y-m-d"); 1306 $psql .= "', primary_end_date='" . $pdate->format("Y-m-d");
1307 $stageno = 4;
1304 $stage = "Secondary"; 1308 $stage = "Secondary";
1305 1309
1306 if ($recipe->SECONDARY_AGE) { 1310 if ($recipe->SECONDARY_AGE && ($stageno >= 4)) {
1307 $sdate = new DateTime($brewdate); 1311 $sdate = new DateTime($brewdate);
1308 $sdate->modify("+".floatval($recipe->SECONDARY_AGE)." days"); 1312 $sdate->modify("+".floatval($recipe->SECONDARY_AGE)." days");
1309 $psql .= "', secondary_temp='" . floatval($recipe->SECONDARY_TEMP); 1313 $psql .= "', secondary_temp='" . floatval($recipe->SECONDARY_TEMP);
1310 $psql .= "', secondary_end_date='" . $sdate->format("Y-m-d"); 1314 $psql .= "', secondary_end_date='" . $sdate->format("Y-m-d");
1315 $stageno = 5;
1311 $stage = "Tertiary"; 1316 $stage = "Tertiary";
1312 1317
1313 if ($recipe->TERTIARY_TEMP) { 1318 if ($recipe->TERTIARY_TEMP && ($stageno >= 5)) {
1314 $psql .= "', tertiary_temp='" . floatval($recipe->TERTIARY_TEMP); 1319 $psql .= "', tertiary_temp='" . floatval($recipe->TERTIARY_TEMP);
1315 } 1320 }
1316 } 1321 }
1317 } 1322 }
1318 1323
1319 if ($recipe->DATE_BOTTLING && ($recipe->AMOUNT_BOTTLING || $recipe->AMOUNT_KEGGED) && 1324 if ($recipe->DATE_BOTTLING && ($recipe->AMOUNT_BOTTLING || $recipe->AMOUNT_KEGGED) &&
1320 ($recipe->AMOUNT_PRIMING || $recipe->AMOUNT_PRIMING_KEGS)) { 1325 ($recipe->AMOUNT_PRIMING || $recipe->AMOUNT_PRIMING_KEGS) && ($stageno >= 5)) {
1321 $bdate = substr($recipe->DATE_BOTTLING, 6, 4).substr($recipe->DATE_BOTTLING,2,4).substr($recipe->DATE_BOTTLING,0,2); 1326 $bdate = substr($recipe->DATE_BOTTLING, 6, 4).substr($recipe->DATE_BOTTLING,2,4).substr($recipe->DATE_BOTTLING,0,2);
1322 $psql .= "', package_date='" . $bdate; 1327 $psql .= "', package_date='" . $bdate;
1323 $stage = "Package"; 1328 $stage = "Package";
1329 $stageno = 6;
1324 $dStart = new DateTime($bdate); 1330 $dStart = new DateTime($bdate);
1325 $dEnd = new DateTime(''); 1331 $dEnd = new DateTime('');
1326 $dDiff = $dStart->diff($dEnd); 1332 $dDiff = $dStart->diff($dEnd);
1327 $age = floatval($dDiff->days); 1333 $age = floatval($dDiff->days);
1328 if ($age == 0) // Package day 1334 if ($age == 0) { // Package day
1329 $stage = "Package"; 1335 $stage = "Package";
1330 else if ($age < 14) // Carbonation period 1336 $stageno = 6;
1337 } else if ($age < 14) { // Carbonation period
1331 $stage = "Carbonation"; 1338 $stage = "Carbonation";
1332 else if ($age < 42) // Mature, fixed 6 weeks 1339 $stageno = 7;
1340 } else if ($age < 42) { // Mature, fixed 6 weeks
1333 $stage = "Mature"; 1341 $stage = "Mature";
1334 else // Ready for tasting. 1342 $stageno = 8;
1343 } else { // Ready for tasting.
1335 $stage = "Taste"; 1344 $stage = "Taste";
1345 $stageno = 9;
1346 }
1336 1347
1337 if ($recipe->AMOUNT_BOTTLING && $recipe->AMOUNT_PRIMING) { 1348 if ($recipe->AMOUNT_BOTTLING && $recipe->AMOUNT_PRIMING) {
1338 $psql .= "', bottle_amount='" . floatval($recipe->AMOUNT_BOTTLING); 1349 $psql .= "', bottle_amount='" . floatval($recipe->AMOUNT_BOTTLING);
1339 $psql .= "', bottle_carbonation='" . floatval($recipe->CARBONATION); 1350 $psql .= "', bottle_carbonation='" . floatval($recipe->CARBONATION);
1340 $psql .= "', bottle_priming_sugar='" . mysqli_real_escape_string($db, $recipe->PRIMING_SUGAR_BOTTLES); 1351 $psql .= "', bottle_priming_sugar='" . mysqli_real_escape_string($db, $recipe->PRIMING_SUGAR_BOTTLES);
1351 $psql .= "', keg_pressure='" . floatval($recipe->KEG_PRESSURE); 1362 $psql .= "', keg_pressure='" . floatval($recipe->KEG_PRESSURE);
1352 $psql .= "', keg_priming_factor='" . floatval($recipe->KEG_PRIMING_FACTOR); 1363 $psql .= "', keg_priming_factor='" . floatval($recipe->KEG_PRIMING_FACTOR);
1353 } 1364 }
1354 } 1365 }
1355 1366
1356 if ($recipe->TASTE_NOTES && $recipe->TASTING_RATE && $recipe->TASTE_DATE) { 1367 if ($recipe->TASTE_NOTES && $recipe->TASTING_RATE && $recipe->TASTE_DATE && ($stageno >= 9)) {
1357 $stage = "Ready"; // Ready if tasted. 1368 $stage = "Ready"; // Ready if tasted.
1369 $stageno = 10;
1358 $psql .= "', taste_notes='" . mysqli_real_escape_string($db, $recipe->TASTE_NOTES); 1370 $psql .= "', taste_notes='" . mysqli_real_escape_string($db, $recipe->TASTE_NOTES);
1359 $psql .= "', taste_rate='" . floatval($recipe->TASTING_RATE); 1371 $psql .= "', taste_rate='" . floatval($recipe->TASTING_RATE);
1360 $tdate = substr($recipe->TASTE_DATE, 6, 4).substr($recipe->TASTE_DATE,2,4).substr($recipe->TASTE_DATE,0,2); 1372 $tdate = substr($recipe->TASTE_DATE, 6, 4).substr($recipe->TASTE_DATE,2,4).substr($recipe->TASTE_DATE,0,2);
1361 $psql .= "', taste_date='" . $tdate; 1373 $psql .= "', taste_date='" . $tdate;
1362 $psql .= "', taste_color='" . mysqli_real_escape_string($db, $recipe->TASTE_COLOR); 1374 $psql .= "', taste_color='" . mysqli_real_escape_string($db, $recipe->TASTE_COLOR);
1371 ($recipe->INVENTORY_REDUCED == 'TRUE') ? $psql .= "', inventory_reduced='1" : $psql .= "', inventory_reduced='0"; 1383 ($recipe->INVENTORY_REDUCED == 'TRUE') ? $psql .= "', inventory_reduced='1" : $psql .= "', inventory_reduced='0";
1372 if (($recipe->LOCKED == 'TRUE') && ($stage == 'Ready')) { 1384 if (($recipe->LOCKED == 'TRUE') && ($stage == 'Ready')) {
1373 $psql .= "', plocked='1"; 1385 $psql .= "', plocked='1";
1374 $rsql .= "', locked='1"; 1386 $rsql .= "', locked='1";
1375 $stage = "Closed"; 1387 $stage = "Closed";
1388 $stageno = 11;
1376 } else { 1389 } else {
1377 $psql .= "', plocked='0"; 1390 $psql .= "', plocked='0";
1378 $rsql .= "', locked='0"; 1391 $rsql .= "', locked='0";
1379 } 1392 }
1380 1393

mercurial