src/EditProduct.cpp

changeset 179
512f492358e3
parent 178
1091fd9feffe
child 181
14a1f7bca79b
--- a/src/EditProduct.cpp	Fri Apr 29 21:42:00 2022 +0200
+++ b/src/EditProduct.cpp	Fri Apr 29 22:49:32 2022 +0200
@@ -457,6 +457,8 @@
 		    QJsonObject obj = miscs.array().at(i).toObject();
 		    //qDebug() << i << obj;
 		    Miscs m;
+		    m.m_avail = false;
+		    m.m_inventory = 0;
 		    m.m_name = obj["m_name"].toString();
 		    m.m_amount = obj["m_amount"].toDouble();
 		    m.m_type = obj["m_type"].toInt();
@@ -464,6 +466,14 @@
 		    m.m_time = obj["m_time"].toDouble();
 		    m.m_amount_is_weight = obj["m_amount_is_weight"].toInt() ? true:false;
 		    m.m_cost = obj["m_cost"].toDouble();
+		    /* Check and update inventory */
+                    yquery.prepare("SELECT inventory FROM inventory_miscs WHERE name=:name");
+                    yquery.bindValue(":name", m.m_name);
+                    yquery.exec();
+                    if (yquery.first()) {
+                        m.m_avail = true;
+                        m.m_inventory = yquery.value(0).toDouble();
+                    }
 		    product->miscs.append(m);
 		}
 		qDebug() << "miscs" << product->miscs.size();
@@ -485,7 +495,7 @@
 		    Yeasts y;
 		    /* First some defaults for newer fields. */
 		    y.y_tolerance = y.y_harvest_time = y.y_pitch_temperature = y.y_zymocide = 0;
-                    y.y_sta1 = y.y_bacteria = y.y_harvest_top = y.y_pofpos = false;
+                    y.y_avail = y.y_sta1 = y.y_bacteria = y.y_harvest_top = y.y_pofpos = false;
 		    y.y_gr_hl_lo = 50;
                     y.y_sg_lo = 1.04;
                     y.y_gr_hl_hi = 80;
@@ -517,35 +527,36 @@
 		    y.y_gr_hl_hi = obj["y_gr_hl_hi"].toInt();
 		    y.y_sg_hi = obj["y_sg_hi"].toDouble();
 		    y.y_cost = obj["y_cost"].toDouble();
-
-		    if (y.y_tolerance == 0 || y.y_cells == 0) {	// More and better tests?
-			/*
-			 * Possible data upgrade needed.
-			 */
-			yquery.prepare("SELECT tolerance,cells,sta1,bacteria,harvest_top,harvest_time,pitch_temperature,"
-				       "pofpos,zymocide,gr_hl_lo,sg_lo,gr_hl_hi,sg_hi "
+		    /*
+		     * Possible data upgrade needed.
+		     */
+		    yquery.prepare("SELECT tolerance,cells,sta1,bacteria,harvest_top,harvest_time,pitch_temperature,"
+				       "pofpos,zymocide,gr_hl_lo,sg_lo,gr_hl_hi,sg_hi,inventory "
 				       "FROM inventory_yeasts WHERE name=:name AND laboratory=:laboratory AND product_id=:product_id");
-			yquery.bindValue(":name", y.y_name);
-			yquery.bindValue(":laboratory", y.y_laboratory);
-			yquery.bindValue(":product_id", y.y_product_id);
-            		yquery.exec();
-            		if (yquery.first()) {
+		    yquery.bindValue(":name", y.y_name);
+		    yquery.bindValue(":laboratory", y.y_laboratory);
+		    yquery.bindValue(":product_id", y.y_product_id);
+            	    yquery.exec();
+            	    if (yquery.first()) {
+			if (y.y_tolerance == 0 || y.y_cells == 0) {
 			    y.y_tolerance = yquery.value(0).toDouble();
 			    y.y_cells = yquery.value(1).toDouble();
-			    y.y_sta1 = yquery.value(2).toInt() ? true:false;
-			    y.y_bacteria = yquery.value(3).toInt() ? true:false;
-			    y.y_harvest_top = yquery.value(4).toInt() ? true:false;
-			    y.y_harvest_time = yquery.value(5).toInt();
-			    y.y_pitch_temperature = yquery.value(6).toDouble();
-			    y.y_pofpos = yquery.value(7).toInt() ? true:false;
-			    y.y_zymocide = yquery.value(8).toInt();
-			    y.y_gr_hl_lo = yquery.value(9).toInt();
-			    y.y_sg_lo = yquery.value(10).toDouble();
-			    y.y_gr_hl_hi = yquery.value(11).toInt();
-			    y.y_sg_hi = yquery.value(12).toDouble();
-			} else {
-			    qDebug() << y.y_name << y.y_product_id << "not found for upgrade";
 			}
+			y.y_sta1 = yquery.value(2).toInt() ? true:false;
+			y.y_bacteria = yquery.value(3).toInt() ? true:false;
+			y.y_harvest_top = yquery.value(4).toInt() ? true:false;
+			y.y_harvest_time = yquery.value(5).toInt();
+			y.y_pitch_temperature = yquery.value(6).toDouble();
+			y.y_pofpos = yquery.value(7).toInt() ? true:false;
+			y.y_zymocide = yquery.value(8).toInt();
+			y.y_gr_hl_lo = yquery.value(9).toInt();
+			y.y_sg_lo = yquery.value(10).toDouble();
+			y.y_gr_hl_hi = yquery.value(11).toInt();
+			y.y_sg_hi = yquery.value(12).toDouble();
+			y.y_inventory = yquery.value(13).toDouble();
+			y.y_avail = true;
+		    } else {
+			qDebug() << y.y_name << y.y_product_id << "not found for upgrade";
 		    }
 		    product->yeasts.append(y);
 		}

mercurial