Improved recipes import. Finished inventory_suppliers.

Sun, 23 Sep 2018 17:15:33 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 23 Sep 2018 17:15:33 +0200
changeset 64
5d5fc6f7cbfe
parent 63
1d1e3002f26b
child 65
5d5c67818d11

Improved recipes import. Finished inventory_suppliers.

www/import/from_brouwhulp.php file | annotate | diff | comparison | revisions
www/includes/db_inventory_suppliers.php file | annotate | diff | comparison | revisions
www/js/inv_suppliers.js file | annotate | diff | comparison | revisions
--- a/www/import/from_brouwhulp.php	Sat Sep 22 22:15:01 2018 +0200
+++ b/www/import/from_brouwhulp.php	Sun Sep 23 17:15:33 2018 +0200
@@ -185,7 +185,7 @@
 	if (! $result = mysqli_query($db, $sql)) {
 		printf("Error: %s\n", mysqli_error($db));
 	}
-	$sql = "TRUNCATE TABLE inventory_water_sources;";
+	$sql = "TRUNCATE TABLE inventory_waters;";
 	if (! $result = mysqli_query($db, $sql)) {
 		printf("Error: %s\n", mysqli_error($db));
 	}
@@ -197,9 +197,8 @@
 		if (($water->NAME == "Gedemineraliseerd water") || ($water->NAME == "Cristalline") || ($water->NAME == "Montille (Delhaize)") ||
 		    ($water->NAME == "Spa Reine") || ($water->NAME == "Velsen") || ($water->NAME == "Zutphen") || 
 		    ($water->NAME == "Aurele Bronwater (Colruyt)")) {
-		    $sql  = "INSERT INTO inventory_water_sources SET name='" . mysqli_real_escape_string($db, $water->NAME);
+		    $sql  = "INSERT INTO inventory_waters SET name='" . mysqli_real_escape_string($db, $water->NAME);
 		    ($water->DEFAULT_WATER == 'TRUE') ? $sql .= "', default_water='1" : $sql .= "', default_water='0";
-		    ($water->ALWAYS_ON_STOCK == 'TRUE') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0";
 		} else {
 			$sql  = "INSERT INTO profile_water SET name='" . mysqli_real_escape_string($db, $water->NAME);
 		}
@@ -452,18 +451,32 @@
 		$sql  = "INSERT INTO recipes SET name='" . mysqli_real_escape_string($db, $recipe->NAME);
 		if ($recipe->NOTES)
 			$sql .= "', notes='" . mysqli_real_escape_string($db, $recipe->NOTES);
+		else
+			$sql .= "', notes='";
 		if ($recipe->TYPE)
 			$sql .= "', type='" . mysqli_real_escape_string($db, $recipe->TYPE);
+		else
+			$sql .= "', type='";
 		if ($recipe->BATCH_SIZE)
 			$sql .= "', batch_size='" . floatval($recipe->BATCH_SIZE);
+		else
+			$sql .= "', batch_size='20.0";
 		if ($recipe->BOIL_TIME)
 			$sql .= "', boil_time='" . floatval($recipe->BOIL_TIME);
+		else
+			$sql .= "', boil_time='90";
 		if ($recipe->EFFICIENCY)
 			$sql .= "', efficiency='" . floatval($recipe->EFFICIENCY);
+		else
+			$sql .= "', efficiency='75";
 		if ($recipe->EST_OG)
 			$sql .= "', est_og='" . floatval($recipe->EST_OG);
+		else
+			$sql .= "', est_og='1.052";
 		if ($recipe->EST_FG)
 			$sql .= "', est_fg='" . floatval($recipe->EST_FG);
+		else
+			$sql .= "', est_fg='1.000";
 		if ($recipe->EST_COLOR) {
 			$srm = floatval($recipe->EST_COLOR);
 			$ebc = srm_to_ebc($srm);
@@ -542,37 +555,46 @@
 					$ebc = srm_to_ebc($srm);
 					$fermentables .= ',"f_color":' . $ebc;
 				}
-				if ($fermentable->COARSE_FINE_DIFF) {
+				if ($fermentable->COARSE_FINE_DIFF)
 					$fermentables .= ',"f_coarse_fine_diff":' . floatval($fermentable->COARSE_FINE_DIFF);
-				}
-				if ($fermentable->MOISTURE) {
+				else
+					$fermentables .= ',"f_coarse_fine_diff":0';
+				if ($fermentable->MOISTURE)
 					$fermentables .= ',"f_moisture":' . floatval($fermentable->MOISTURE);
-				}
-				if ($fermentable->DIASTATIC_POWER) {
+				else
+					$fermentables .= ',"f_moisture":0';
+				if ($fermentable->DIASTATIC_POWER)
 				        $fermentables .= ',"f_diastatic_power":' . floatval($fermentable->DIASTATIC_POWER);
-				}
-				if ($fermentable->PROTEIN) {
+				else
+					$fermentables .= ',"f_diastatic_power":0';
+				if ($fermentable->PROTEIN)
 					$fermentables .= ',"f_protein":' . floatval($fermentable->PROTEIN);
-				}
-				if ($fermentable->MAX_IN_BATCH) {
+				else
+					$fermentables .= ',"f_protein":0';
+				if ($fermentable->MAX_IN_BATCH)
 					$fermentables .= ',"f_max_in_batch":' . floatval($fermentable->MAX_IN_BATCH);
-				}
-				if ($fermentable->GRAINTYPE) {
+				else
+					$fermentables .= ',"f_max_in_batch":100.0';
+				if ($fermentable->GRAINTYPE)
 					$fermentables .= ',"f_graintype":"' . mysqli_real_escape_string($db, $fermentable->GRAINTYPE) . '"';
-				}
-				if ($fermentable->ADDED) {
+				else
+					$fermentables .= ',"f_graintype":"Base"';
+				if ($fermentable->ADDED)
 					$fermentables .= ',"f_added":"' . mysqli_real_escape_string($db, $fermentable->ADDED) . '"';
-				}
+				else
+					$fermentables .= ',"f_added":"Mash"';
 				($fermentable->ADD_AFTER_BOIL== "TRUE") ? $fermentables .= ',"f_add_after_boil":true' : $fermentables .= ',"f_add_after_boil":false';
 				($fermentable->RECOMMEND_MASH== "TRUE") ? $fermentables .= ',"f_recommend_mash":true' : $fermentables .= ',"f_recommend_mash":false';
-				if ($fermentable->DISSOLVED_PROTEIN) {
+				if ($fermentable->DISSOLVED_PROTEIN)
 					$fermentables .= ',"f_dissolved_protein":' . floatval($fermentable->DISSOLVED_PROTEIN);
-				}
+				else
+					$fermentables .= ',"f_dissolved_protein":0';
 				($fermentable->ADJUST_TO_TOTAL_100 == "TRUE") ? $fermentables .= ',"f_adjust_to_total_100":true' : $fermentables .= ',"f_adjust_to_total_100":false';
 				$fermentables .= ',"f_percentage":' . floatval($fermentable->PERCENTAGE);
-				if ($fermentable->DI_pH) {
+				if ($fermentable->DI_pH)
 					$fermentables .= ',"f_di_ph":' . floatval($fermentable->DI_pH);
-				}
+				else
+					$fermentables .= ',"f_di_ph":5.6';
 				$fermentables .= "}";
 			}
 
@@ -788,24 +810,24 @@
 			printf("Error: %s\n", mysqli_error($db));
 		}
 	}
-	echo "Fermentables: " . $len_fermentables . PHP_EOL;
-	echo "Hops:         " . $len_hops . PHP_EOL;
-	echo "Miscs:        " . $len_miscs . PHP_EOL;
-	echo "Yeasts:       " . $len_yeasts . PHP_EOL;
-	echo "Waters:       " . $len_waters . PHP_EOL;
-	echo "Mash:         " . $len_mash . PHP_EOL;
+//	echo "Fermentables: " . $len_fermentables . PHP_EOL;
+//	echo "Hops:         " . $len_hops . PHP_EOL;
+//	echo "Miscs:        " . $len_miscs . PHP_EOL;
+//	echo "Yeasts:       " . $len_yeasts . PHP_EOL;
+//	echo "Waters:       " . $len_waters . PHP_EOL;
+//	echo "Mash:         " . $len_mash . PHP_EOL;
 }
 
 
 
-//do_fermentables();
-//do_hops();
-//do_yeasts();
-//do_miscs();
-//do_waters();
-//do_equipments();
+do_fermentables();
+do_hops();
+do_yeasts();
+do_miscs();
+do_waters();
+do_equipments();
 do_styles();
-//do_mash();
+do_mash();
 do_recipes();
 
 
--- a/www/includes/db_inventory_suppliers.php	Sat Sep 22 22:15:01 2018 +0200
+++ b/www/includes/db_inventory_suppliers.php	Sun Sep 23 17:15:33 2018 +0200
@@ -10,56 +10,56 @@
 }
 
 // get data and store in a json array
-$query = "SELECT * FROM inventory_suppliers";
-if (isset($_GET['insert'])) {
+$query = "SELECT * FROM inventory_suppliers ORDER BY name";
+if (isset($_POST['insert'])) {
 	// INSERT COMMAND
-	$sql  = "INSERT INTO `inventory_suppliers` SET name='" . mysqli_real_escape_string($connect, $_GET['name']);
-	$sql .= "', address='" . mysqli_real_escape_string($connect, $_GET['address']);
-	$sql .= "', city='" . mysqli_real_escape_string($connect, $_GET['city']);
-	$sql .= "', zip='" . mysqli_real_escape_string($connect, $_GET['zip']);
-	$sql .= "', country='" . mysqli_real_escape_string($connect, $_GET['country']);
-	$sql .= "', website='" . mysqli_real_escape_string($connect, $_GET['website']);
-	$sql .= "', email='" . mysqli_real_escape_string($connect, $_GET['email']);
-	$sql .= "', phone='" . mysqli_real_escape_string($connect, $_GET['phone']);
-	$sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']);
+	$sql  = "INSERT INTO `inventory_suppliers` SET name='" . mysqli_real_escape_string($connect, $_POST['name']);
+	$sql .= "', address='" . mysqli_real_escape_string($connect, $_POST['address']);
+	$sql .= "', city='" . mysqli_real_escape_string($connect, $_POST['city']);
+	$sql .= "', zip='" . mysqli_real_escape_string($connect, $_POST['zip']);
+	$sql .= "', country='" . mysqli_real_escape_string($connect, $_POST['country']);
+	$sql .= "', website='" . mysqli_real_escape_string($connect, $_POST['website']);
+	$sql .= "', email='" . mysqli_real_escape_string($connect, $_POST['email']);
+	$sql .= "', phone='" . mysqli_real_escape_string($connect, $_POST['phone']);
+	$sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']);
 	$sql .= "';";
 	$result = mysqli_query($connect, $sql);
 	if (! $result) {
 		syslog(LOG_NOTICE, "db_inventory_suppliers: ".$sql." result: ".mysqli_error($connect));
 	} else {
-		syslog(LOG_NOTICE, "db_inventory_suppliers: inserted ".$_GET['name']);
+		syslog(LOG_NOTICE, "db_inventory_suppliers: inserted ".$_POST['name']);
 	}
 	echo $result;
 
-} else if (isset($_GET['update'])) {
+} else if (isset($_POST['update'])) {
 	// UPDATE COMMAND
-	$sql  = "UPDATE `inventory_suppliers` SET name='" . mysqli_real_escape_string($connect, $_GET['name']);
-	$sql .= "', address='" . mysqli_real_escape_string($connect, $_GET['address']);
-	$sql .= "', city='" . mysqli_real_escape_string($connect, $_GET['city']);
-	$sql .= "', zip='" . mysqli_real_escape_string($connect, $_GET['zip']);
-	$sql .= "', country='" . mysqli_real_escape_string($connect, $_GET['country']);
-	$sql .= "', website='" . mysqli_real_escape_string($connect, $_GET['website']);
-	$sql .= "', email='" . mysqli_real_escape_string($connect, $_GET['email']);
-	$sql .= "', phone='" . mysqli_real_escape_string($connect, $_GET['phone']);
-	$sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']);
-	$sql .= "' WHERE record='" . $_GET['record'] . "';";
+	$sql  = "UPDATE `inventory_suppliers` SET name='" . mysqli_real_escape_string($connect, $_POST['name']);
+	$sql .= "', address='" . mysqli_real_escape_string($connect, $_POST['address']);
+	$sql .= "', city='" . mysqli_real_escape_string($connect, $_POST['city']);
+	$sql .= "', zip='" . mysqli_real_escape_string($connect, $_POST['zip']);
+	$sql .= "', country='" . mysqli_real_escape_string($connect, $_POST['country']);
+	$sql .= "', website='" . mysqli_real_escape_string($connect, $_POST['website']);
+	$sql .= "', email='" . mysqli_real_escape_string($connect, $_POST['email']);
+	$sql .= "', phone='" . mysqli_real_escape_string($connect, $_POST['phone']);
+	$sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']);
+	$sql .= "' WHERE record='" . $_POST['record'] . "';";
 	$result = mysqli_query($connect, $sql);
 	if (! $result) {
 		syslog(LOG_NOTICE, "db_inventory_suppliers: ".$sql." result: ".mysqli_error($connect));
 	} else {
-		syslog(LOG_NOTICE, "db_inventory_suppliers: updated record ".$_GET['record']);
+		syslog(LOG_NOTICE, "db_inventory_suppliers: updated record ".$_POST['record']);
 	}
 	echo $result;
 
-} else if (isset($_GET['delete'])) {
+} else if (isset($_POST['delete'])) {
 	// DELETE COMMAND
 	// FIXME: need to check if the record is in use
-	$sql = "DELETE FROM `inventory_suppliers` WHERE record='".$_GET['record']."';";
+	$sql = "DELETE FROM `inventory_suppliers` WHERE record='".$_POST['record']."';";
 	$result = mysqli_query($connect, $sql);
 	if (! $result) {
 		syslog(LOG_NOTICE, "db_inventory_suppliers: ".$sql." result: ".mysqli_error($connect));
 	} else {
-		syslog(LOG_NOTICE, "db_inventory_suppliers: deleted record ".$_GET['record']);
+		syslog(LOG_NOTICE, "db_inventory_suppliers: deleted record ".$_POST['record']);
 	}
 	echo $result;
 
--- a/www/js/inv_suppliers.js	Sat Sep 22 22:15:01 2018 +0200
+++ b/www/js/inv_suppliers.js	Sun Sep 23 17:15:33 2018 +0200
@@ -34,8 +34,8 @@
 		okButton: $('#delOk'),
 		cancelButton: $('#delCancel'),
 		initContent: function () {
-			$('#delOk').jqxButton({ width: '65px', theme: theme }); 
-			$('#delCancel').jqxButton({ width: '65px', theme: theme });
+			$('#delOk').jqxButton({ template: "danger", width: '65px', theme: theme }); 
+			$('#delCancel').jqxButton({ template: "success", width: '65px', theme: theme });
 			$('#delCancel').focus();
 		}
 	});
@@ -82,6 +82,7 @@
 				url: url,
 				cache: false,
 				data: data,
+				type: "POST",
 				success: function (data, status, xhr) {
 					// delete command is executed.
 					commit(true);
@@ -98,6 +99,7 @@
 				url: url,
 				cache: false,
 				data: data,
+				type: "POST",
 				success: function (data, status, xhr) {
 					commit(true);
 				},
@@ -113,6 +115,7 @@
 				url: url,
 				cache: false,
 				data: data,
+				type: "POST",
 				success: function (data, status, xhr) {
 					// update command is executed.
 					commit(true);
@@ -124,14 +127,14 @@
 		}
 	};
 	// initialize the input fields.
-	$("#name").jqxInput({ theme: theme, width: 250, height: 23 });
-	$("#address").jqxInput({ theme: theme, width: 250, height: 23 });
+	$("#name").jqxInput({ theme: theme, width: 640, height: 23 });
+	$("#address").jqxInput({ theme: theme, width: 350, height: 23 });
 	$("#zip").jqxInput({ theme: theme, width: 120, height: 23 });
-	$("#city").jqxInput({ theme: theme, width: 250, height: 23 });
+	$("#city").jqxInput({ theme: theme, width: 350, height: 23 });
 	$("#country").jqxInput({ theme: theme, width: 250, height: 23 });
-	$("#website").jqxInput({ theme: theme, width: 250, height: 23 });
-	$("#email").jqxInput({ theme: theme, width: 250, height: 23 });
-	$("#phone").jqxInput({ theme: theme, width: 120, height: 23 });
+	$("#website").jqxInput({ theme: theme, width: 640, height: 23 });
+	$("#email").jqxInput({ theme: theme, width: 640, height: 23 });
+	$("#phone").jqxInput({ theme: theme, width: 175, height: 23 });
 	$("#notes").jqxInput({ theme: theme, width: 640, height: 48 });
 
 	var dataAdapter = new $.jqx.dataAdapter(source);
@@ -168,12 +171,12 @@
 		filterable: true,
 		filtermode: 'excel',
 		columns: [
-			{ text: 'Leverancier naam', datafield: 'name', width: 250 },
+			{ text: 'Leverancier naam', datafield: 'name' },
 			{ text: 'Adres', datafield: 'address', width: 300 },
 			{ text: 'Plaats', datafield: 'city', width: 250 },
-			{ text: 'Land', datafield: 'country', width: 250 },
-			{ text: 'Telefoon', datafield: 'phone', width: 100 },
-			{ text: 'Wijzig', datafield: 'Edit', columntype: 'button', cellsrenderer: function () {
+			{ text: 'Land', datafield: 'country', width: 200 },
+			{ text: 'Telefoon', datafield: 'phone', width: 175 },
+			{ text: 'Wijzig', datafield: 'Edit', width: 120, align: 'center', columntype: 'button', cellsrenderer: function () {
 				return "Wijzig";
 				}, buttonclick: function (row) {
 					// open the popup window when the user clicks a button.
@@ -203,7 +206,7 @@
 	$("#popupWindow").on('open', function () {
 		$("#name").jqxInput('selectAll');
 	});
-	$("#Delete").jqxButton({ theme: theme });
+	$("#Delete").jqxButton({ template: "danger", width: '80px', theme: theme });
 	$("#Delete").click(function () {
 		if (editrow >= 0) {
 			// Open a popup to confirm this action.
@@ -215,8 +218,8 @@
 		}
 		$("#popupWindow").jqxWindow('hide');
 	});
-	$("#Cancel").jqxButton({ theme: theme });
-	$("#Save").jqxButton({ theme: theme });
+	$("#Cancel").jqxButton({ template: "primary", width: '80px', theme: theme });
+	$("#Save").jqxButton({ template: "success", width: '80px', theme: theme });
 	// update the edited row when the user clicks the 'Save' button.
 	$("#Save").click(function () {
 		if (editrow >= 0) {

mercurial