diff -r 28f0e43e9f08 -r 94b3def5d778 src/MainWindow.cpp --- a/src/MainWindow.cpp Sun Jan 29 14:40:43 2023 +0100 +++ b/src/MainWindow.cpp Mon Jan 30 17:05:13 2023 +0100 @@ -21,6 +21,7 @@ #include "InventoryFermentables.h" #include "InventoryHops.h" #include "InventoryYeasts.h" +#include "InventoryYeastPacks.h" #include "InventoryMiscs.h" #include "InventoryWaters.h" #include "InventoryEquipments.h" @@ -165,10 +166,12 @@ { QSqlQuery query1, query2, query3, query4; int count = 0; + bool added_packs = false; qDebug() << "updateDatabase() start"; /* + * Version 0.4.0. * Make sure we have the inventory_yeastpack with initial records. */ query1.exec("CREATE TABLE IF NOT EXISTS `inventory_yeastpack` (" @@ -182,8 +185,10 @@ "`viability` double NOT NULL DEFAULT 0.99," "`max` tinyint(4) NOT NULL DEFAULT 100," "`size` float NOT NULL DEFAULT 0," + "`used` int(11) NOT NULL DEFAULT 0," "PRIMARY KEY (`record`)," "UNIQUE KEY `uuid` (`uuid`)," + "UNIQUE KEY `package` (`laboratory`,`form`,`package`)," "KEY `lab_form` (`laboratory`,`form`) USING BTREE" ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Yeast packages data'"); if (query1.lastError().isValid()) { @@ -206,17 +211,31 @@ /* Should succeed */ query4.prepare("INSERT INTO inventory_yeastpack SET uuid=:uuid, laboratory=:laboratory, " - "form=:form, package=:package, cells=:cells"); + "form=:form, package=:package, cells=:cells, viability=:viability, max=:max"); query4.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); query4.bindValue(":laboratory", query1.value("laboratory").toString()); query4.bindValue(":form", query1.value("form").toInt()); query4.bindValue(":package", g_yeast_forms[query1.value("form").toInt()]); query4.bindValue(":cells", query3.value("cells").toDouble()); + switch (query1.value("form").toInt()) { + case YEAST_FORMS_LIQUID: query4.bindValue(":viability", 0.80); + query4.bindValue(":max", 97); + break; + case YEAST_FORMS_DRY: query4.bindValue(":viability", 0.998); + query4.bindValue(":max", 100); + break; + case YEAST_FORMS_DRIED: query4.bindValue(":viability", 0.92); + query4.bindValue(":max", 100); + break; + default: query4.bindValue(":viability", 0.99); + query4.bindValue(":max", 97); + } query4.exec(); if (query4.lastError().isValid()) { qWarning() << " add yeastpack" << query4.lastError(); } else { count++; + added_packs = true; } } } @@ -226,17 +245,14 @@ } -/* - * On the server where bmsd runs, there is a crontask.php that does these checks - * too. Here we do some of the same commands so that we have the results sooner. - * Currently this takes 6 to 9 mSecs. - */ void MainWindow::maintDataBase() { - QSqlQuery query; + QSqlQuery query, query1; /* - * Upgrade package values. + * On the server where bmsd runs, there is a crontask.php that does these checks + * too. Here we do some of the same commands so that we have the results sooner. + * Currently this takes 6 to 9 mSecs. */ query.exec("UPDATE products SET package_volume = bottle_amount + keg_amount WHERE package_volume='0'"); if (query.numRowsAffected()) @@ -267,6 +283,27 @@ query.exec("UPDATE products SET stage=9 WHERE stage = 8 AND DATEDIFF(CURDATE(), package_date) > 41"); if (query.numRowsAffected()) qInfo() << "Updated" << query.numRowsAffected() << "products to stage 9 (Taste)"; + + /* + * Count and update references in inventory_yeastpack to inventory_yeasts + */ + query.exec("SELECT laboratory,form FROM inventory_yeastpack"); + while (query.next()) { + query1.prepare("SELECT COUNT(*) FROM inventory_yeasts WHERE laboratory=:laboratory AND form=:form"); + query1.bindValue(":laboratory", query.value("laboratory").toString()); + query1.bindValue(":form", query.value("form").toInt()); + query1.exec(); + if (! query1.first()) { + qWarning() << "SELECT COUNT(*) FROM inventory_yeasts"; + } else { + int count = query1.value("COUNT(*)").toInt(); + query1.prepare("UPDATE inventory_yeastpack SET used=:used WHERE laboratory=:laboratory AND form=:form"); + query1.bindValue(":used", count); + query1.bindValue(":laboratory", query.value("laboratory").toString()); + query1.bindValue(":form", query.value("form").toInt()); + query1.exec(); + } + } } @@ -709,6 +746,28 @@ } +void MainWindow::fromInventoryYeastPacks() +{ + ui->mainStack->setCurrentIndex(-1); + ui->mainStack->removeWidget(InventoryYeastPacksWindow); + delete InventoryYeastPacksWindow; + setWindowTitle( QString("BMSapp - %1").arg(VERSIONSTRING) ); + ui->menuBar->setVisible(true); + statusBar()->clearMessage(); +} + + +void MainWindow::on_actionYeastPacks_triggered() +{ + InventoryYeastPacksWindow = new InventoryYeastPacks(this); + int index = ui->mainStack->count(); + ui->mainStack->addWidget(InventoryYeastPacksWindow); + ui->mainStack->setCurrentIndex(index); + setWindowTitle(QString("BMSapp - %1 - Inventory Yeasts").arg(VERSIONSTRING)); + ui->menuBar->setVisible(false); +} + + void MainWindow::fromInventoryMiscs() { ui->mainStack->setCurrentIndex(-1);