Log product code and name instead of record number. Added water supply check.

Fri, 24 Jun 2022 11:07:34 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 24 Jun 2022 11:07:34 +0200
changeset 307
afd711e37f68
parent 306
d45c502ce77f
child 308
79f100a84f65

Log product code and name instead of record number. Added water supply check.

src/EditProduct.cpp file | annotate | diff | comparison | revisions
src/EditProduct.h file | annotate | diff | comparison | revisions
src/EditProductTab7.cpp file | annotate | diff | comparison | revisions
src/EditProductTab8.cpp file | annotate | diff | comparison | revisions
--- a/src/EditProduct.cpp	Thu Jun 23 16:56:07 2022 +0200
+++ b/src/EditProduct.cpp	Fri Jun 24 11:07:34 2022 +0200
@@ -29,7 +29,7 @@
 {
     QSqlQuery query, wquery, yquery;
 
-    qInfo() << "EditProduct record:" << id;
+    qDebug() << "EditProduct record:" << id;
     product = new Product;
     ui->setupUi(this);
     product->fermentables_row = product->hops_row = product->miscs_row = product->yeasts_row = product->mashs_row = -1;
@@ -113,6 +113,8 @@
     if (id >= 0) {
 	if (! DB_product::load(product, this, id))
 	    return;
+	qInfo() << "EditProduct" << product->code << "," << product->name;
+
 	/*
 	 * Check status of logfiles.
 	 */
@@ -155,6 +157,7 @@
 
     } else {
 	/* New product, set some defaults */
+	qInfo() << "EditProduct, start new product";
 	product->record = -1;
 	product->locked = product->log_brew = product->log_fermentation = product->log_ispindel = product->log_co2pressure = false;
 	product->st_name = "";
@@ -458,6 +461,7 @@
     ui->sp_acidtypeEdit->setCurrentIndex(product->sparge_acid_type);
     ui->sp_acidpercEdit->setValue(product->sparge_acid_perc);
     ui->sp_acidvolEdit->setValue(product->sparge_acid_amount);
+    check_waters();
 
     // Tab brewday.
     updateBrewday();
@@ -750,8 +754,8 @@
 	return;
     }
 
-    qDebug() << "calcSupplies() f:" << product->fermentables_ok << "h:" << product->hops_ok << "m:" << product->miscs_ok << "y:" << product->yeasts_ok /*<< "w:" << product->waters_ok*/;
-    if (product->fermentables_ok && product->hops_ok && product->miscs_ok && product->yeasts_ok /*&& product->waters_ok */) {
+    qDebug() << "calcSupplies() f:" << product->fermentables_ok << "h:" << product->hops_ok << "m:" << product->miscs_ok << "y:" << product->yeasts_ok << "w:" << product->waters_ok;
+    if (product->fermentables_ok && product->hops_ok && product->miscs_ok && product->yeasts_ok && product->waters_ok) {
 	ui->ok_pmptIcon->setPixmap(QPixmap(QString::fromUtf8(":/icons/silk/tick.png")));
     } else {
 	ui->ok_pmptIcon->setPixmap(QPixmap(QString::fromUtf8(":/icons/silk/cancel.png")));
--- a/src/EditProduct.h	Thu Jun 23 16:56:07 2022 +0200
+++ b/src/EditProduct.h	Fri Jun 24 11:07:34 2022 +0200
@@ -332,6 +332,7 @@
     bool block_hop(int stage, int useat);
     bool block_misc(int stage, int use_use);
     bool block_yeast(int stage, int use);
+    void check_waters();
 };
 
 #endif
--- a/src/EditProductTab7.cpp	Thu Jun 23 16:56:07 2022 +0200
+++ b/src/EditProductTab7.cpp	Fri Jun 24 11:07:34 2022 +0200
@@ -439,6 +439,7 @@
     product->wg_amount = volume;
     ui->w1_volEdit->setValue(product->w1_amount);
 
+    check_waters();
     is_changed();
     emit refreshAll();
 }
--- a/src/EditProductTab8.cpp	Thu Jun 23 16:56:07 2022 +0200
+++ b/src/EditProductTab8.cpp	Fri Jun 24 11:07:34 2022 +0200
@@ -635,11 +635,45 @@
     }
     ui->w2_volEdit->setValue(product->w2_amount);
 
+    check_waters();
     calcWater();
     is_changed();
 }
 
 
+void EditProduct::check_waters()
+{
+    QSqlQuery query;
+    product->waters_ok = true;
+
+    if (product->w1_name != "") {
+	qDebug() << "check_waters 1" << product->w1_name;
+    	query.prepare("SELECT unlimited_stock,inventory FROM inventory_waters WHERE name=:name");
+    	query.bindValue(":name", product->w1_name);
+    	query.exec();
+	if (query.first()) {
+	    if ((query.value("unlimited_stock").toInt() == 0) && (query.value("inventory").toDouble() < product->w1_amount)) {
+		product->waters_ok = false;
+		qDebug() << "w1_amount too low";
+	    }
+	}
+    }
+
+    if ((product->w2_name != "") && (product->w2_amount > 0)) {
+        qDebug() << "check_waters 2" << product->w2_name;
+        query.prepare("SELECT unlimited_stock,inventory FROM inventory_waters WHERE name=:name");
+        query.bindValue(":name", product->w2_name);
+        query.exec();
+        if (query.first()) {
+            if ((query.value("unlimited_stock").toInt() == 0) && (query.value("inventory").toDouble() < product->w2_amount)) {
+                product->waters_ok = false;
+                qDebug() << "w2_amount too low";
+            }
+        }
+    }
+}
+
+
 void EditProduct::w1_name_changed(int val)
 {
     QSqlQuery query;
@@ -660,16 +694,16 @@
     for (int i = 0; i < (val - 1); i++) {
 	query.next();
     }
-    qDebug() << "set water" << query.value(1).toString();
+    qDebug() << "set water" << query.value("name").toString();
 
-    product->w1_name = query.value(1).toString();
-    product->w1_calcium = query.value(3).toDouble();
-    product->w1_magnesium = query.value(8).toDouble();
-    product->w1_total_alkalinity = query.value(11).toDouble();
-    product->w1_sodium = query.value(7).toDouble();
-    product->w1_chloride = query.value(6).toDouble();
-    product->w1_sulfate = query.value(5).toDouble();
-    product->w1_ph = query.value(9).toDouble();
+    product->w1_name = query.value("name").toString();
+    product->w1_calcium = query.value("calcium").toDouble();
+    product->w1_magnesium = query.value("magnesium").toDouble();
+    product->w1_total_alkalinity = query.value("total_alkalinity").toDouble();
+    product->w1_sodium = query.value("sodium").toDouble();
+    product->w1_chloride = query.value("chloride").toDouble();
+    product->w1_sulfate = query.value("sulfate").toDouble();
+    product->w1_ph = query.value("ph").toDouble();
 
     ui->w1_caEdit->setValue(product->w1_calcium);
     ui->w1_mgEdit->setValue(product->w1_magnesium);
@@ -680,6 +714,7 @@
     ui->w1_so4Edit->setValue(product->w1_sulfate);
     ui->w1_phEdit->setValue(product->w1_ph);
 
+    check_waters();
     is_changed();
     calcWater();
 }
@@ -731,6 +766,7 @@
     ui->w2_so4Edit->setValue(product->w2_sulfate);
     ui->w2_phEdit->setValue(product->w2_ph);
 
+    check_waters();
     is_changed();
     calcWater();
 }

mercurial