19 #include "RecipesTree.h" |
19 #include "RecipesTree.h" |
20 #include "InventorySuppliers.h" |
20 #include "InventorySuppliers.h" |
21 #include "InventoryFermentables.h" |
21 #include "InventoryFermentables.h" |
22 #include "InventoryHops.h" |
22 #include "InventoryHops.h" |
23 #include "InventoryYeasts.h" |
23 #include "InventoryYeasts.h" |
|
24 #include "InventoryYeastPacks.h" |
24 #include "InventoryMiscs.h" |
25 #include "InventoryMiscs.h" |
25 #include "InventoryWaters.h" |
26 #include "InventoryWaters.h" |
26 #include "InventoryEquipments.h" |
27 #include "InventoryEquipments.h" |
27 #include "ProdInprod.h" |
28 #include "ProdInprod.h" |
28 #include "ProdOnName.h" |
29 #include "ProdOnName.h" |
163 */ |
164 */ |
164 void MainWindow::updateDataBase() |
165 void MainWindow::updateDataBase() |
165 { |
166 { |
166 QSqlQuery query1, query2, query3, query4; |
167 QSqlQuery query1, query2, query3, query4; |
167 int count = 0; |
168 int count = 0; |
|
169 bool added_packs = false; |
168 |
170 |
169 qDebug() << "updateDatabase() start"; |
171 qDebug() << "updateDatabase() start"; |
170 |
172 |
171 /* |
173 /* |
|
174 * Version 0.4.0. |
172 * Make sure we have the inventory_yeastpack with initial records. |
175 * Make sure we have the inventory_yeastpack with initial records. |
173 */ |
176 */ |
174 query1.exec("CREATE TABLE IF NOT EXISTS `inventory_yeastpack` (" |
177 query1.exec("CREATE TABLE IF NOT EXISTS `inventory_yeastpack` (" |
175 "`record` int(11) NOT NULL AUTO_INCREMENT," |
178 "`record` int(11) NOT NULL AUTO_INCREMENT," |
176 "`uuid` varchar(36) NOT NULL," |
179 "`uuid` varchar(36) NOT NULL," |
180 "`notes` text DEFAULT NULL," |
183 "`notes` text DEFAULT NULL," |
181 "`cells` double NOT NULL DEFAULT 0," |
184 "`cells` double NOT NULL DEFAULT 0," |
182 "`viability` double NOT NULL DEFAULT 0.99," |
185 "`viability` double NOT NULL DEFAULT 0.99," |
183 "`max` tinyint(4) NOT NULL DEFAULT 100," |
186 "`max` tinyint(4) NOT NULL DEFAULT 100," |
184 "`size` float NOT NULL DEFAULT 0," |
187 "`size` float NOT NULL DEFAULT 0," |
|
188 "`used` int(11) NOT NULL DEFAULT 0," |
185 "PRIMARY KEY (`record`)," |
189 "PRIMARY KEY (`record`)," |
186 "UNIQUE KEY `uuid` (`uuid`)," |
190 "UNIQUE KEY `uuid` (`uuid`)," |
|
191 "UNIQUE KEY `package` (`laboratory`,`form`,`package`)," |
187 "KEY `lab_form` (`laboratory`,`form`) USING BTREE" |
192 "KEY `lab_form` (`laboratory`,`form`) USING BTREE" |
188 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Yeast packages data'"); |
193 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Yeast packages data'"); |
189 if (query1.lastError().isValid()) { |
194 if (query1.lastError().isValid()) { |
190 qWarning() << " create inventory_yeastpack" << query1.lastError(); |
195 qWarning() << " create inventory_yeastpack" << query1.lastError(); |
191 } else { |
196 } else { |
204 query3.exec(); |
209 query3.exec(); |
205 query3.first(); |
210 query3.first(); |
206 /* Should succeed */ |
211 /* Should succeed */ |
207 |
212 |
208 query4.prepare("INSERT INTO inventory_yeastpack SET uuid=:uuid, laboratory=:laboratory, " |
213 query4.prepare("INSERT INTO inventory_yeastpack SET uuid=:uuid, laboratory=:laboratory, " |
209 "form=:form, package=:package, cells=:cells"); |
214 "form=:form, package=:package, cells=:cells, viability=:viability, max=:max"); |
210 query4.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); |
215 query4.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); |
211 query4.bindValue(":laboratory", query1.value("laboratory").toString()); |
216 query4.bindValue(":laboratory", query1.value("laboratory").toString()); |
212 query4.bindValue(":form", query1.value("form").toInt()); |
217 query4.bindValue(":form", query1.value("form").toInt()); |
213 query4.bindValue(":package", g_yeast_forms[query1.value("form").toInt()]); |
218 query4.bindValue(":package", g_yeast_forms[query1.value("form").toInt()]); |
214 query4.bindValue(":cells", query3.value("cells").toDouble()); |
219 query4.bindValue(":cells", query3.value("cells").toDouble()); |
|
220 switch (query1.value("form").toInt()) { |
|
221 case YEAST_FORMS_LIQUID: query4.bindValue(":viability", 0.80); |
|
222 query4.bindValue(":max", 97); |
|
223 break; |
|
224 case YEAST_FORMS_DRY: query4.bindValue(":viability", 0.998); |
|
225 query4.bindValue(":max", 100); |
|
226 break; |
|
227 case YEAST_FORMS_DRIED: query4.bindValue(":viability", 0.92); |
|
228 query4.bindValue(":max", 100); |
|
229 break; |
|
230 default: query4.bindValue(":viability", 0.99); |
|
231 query4.bindValue(":max", 97); |
|
232 } |
215 query4.exec(); |
233 query4.exec(); |
216 if (query4.lastError().isValid()) { |
234 if (query4.lastError().isValid()) { |
217 qWarning() << " add yeastpack" << query4.lastError(); |
235 qWarning() << " add yeastpack" << query4.lastError(); |
218 } else { |
236 } else { |
219 count++; |
237 count++; |
|
238 added_packs = true; |
220 } |
239 } |
221 } |
240 } |
222 } |
241 } |
223 } |
242 } |
224 |
243 |
225 qDebug() << "updateDatabase()" << count << "updates"; |
244 qDebug() << "updateDatabase()" << count << "updates"; |
226 } |
245 } |
227 |
246 |
228 |
247 |
229 /* |
|
230 * On the server where bmsd runs, there is a crontask.php that does these checks |
|
231 * too. Here we do some of the same commands so that we have the results sooner. |
|
232 * Currently this takes 6 to 9 mSecs. |
|
233 */ |
|
234 void MainWindow::maintDataBase() |
248 void MainWindow::maintDataBase() |
235 { |
249 { |
236 QSqlQuery query; |
250 QSqlQuery query, query1; |
237 |
251 |
238 /* |
252 /* |
239 * Upgrade package values. |
253 * On the server where bmsd runs, there is a crontask.php that does these checks |
|
254 * too. Here we do some of the same commands so that we have the results sooner. |
|
255 * Currently this takes 6 to 9 mSecs. |
240 */ |
256 */ |
241 query.exec("UPDATE products SET package_volume = bottle_amount + keg_amount WHERE package_volume='0'"); |
257 query.exec("UPDATE products SET package_volume = bottle_amount + keg_amount WHERE package_volume='0'"); |
242 if (query.numRowsAffected()) |
258 if (query.numRowsAffected()) |
243 qInfo() << "Updated" << query.numRowsAffected() << "products to new package_volume value"; |
259 qInfo() << "Updated" << query.numRowsAffected() << "products to new package_volume value"; |
244 query.exec("UPDATE products SET bottle_priming_water = bottle_amount * bottle_priming_amount / 500 WHERE bottle_priming_water = 0"); |
260 query.exec("UPDATE products SET bottle_priming_water = bottle_amount * bottle_priming_amount / 500 WHERE bottle_priming_water = 0"); |
265 if (query.numRowsAffected()) |
281 if (query.numRowsAffected()) |
266 qInfo() << "Updated" << query.numRowsAffected() << "products to stage 8 (Mature)"; |
282 qInfo() << "Updated" << query.numRowsAffected() << "products to stage 8 (Mature)"; |
267 query.exec("UPDATE products SET stage=9 WHERE stage = 8 AND DATEDIFF(CURDATE(), package_date) > 41"); |
283 query.exec("UPDATE products SET stage=9 WHERE stage = 8 AND DATEDIFF(CURDATE(), package_date) > 41"); |
268 if (query.numRowsAffected()) |
284 if (query.numRowsAffected()) |
269 qInfo() << "Updated" << query.numRowsAffected() << "products to stage 9 (Taste)"; |
285 qInfo() << "Updated" << query.numRowsAffected() << "products to stage 9 (Taste)"; |
|
286 |
|
287 /* |
|
288 * Count and update references in inventory_yeastpack to inventory_yeasts |
|
289 */ |
|
290 query.exec("SELECT laboratory,form FROM inventory_yeastpack"); |
|
291 while (query.next()) { |
|
292 query1.prepare("SELECT COUNT(*) FROM inventory_yeasts WHERE laboratory=:laboratory AND form=:form"); |
|
293 query1.bindValue(":laboratory", query.value("laboratory").toString()); |
|
294 query1.bindValue(":form", query.value("form").toInt()); |
|
295 query1.exec(); |
|
296 if (! query1.first()) { |
|
297 qWarning() << "SELECT COUNT(*) FROM inventory_yeasts"; |
|
298 } else { |
|
299 int count = query1.value("COUNT(*)").toInt(); |
|
300 query1.prepare("UPDATE inventory_yeastpack SET used=:used WHERE laboratory=:laboratory AND form=:form"); |
|
301 query1.bindValue(":used", count); |
|
302 query1.bindValue(":laboratory", query.value("laboratory").toString()); |
|
303 query1.bindValue(":form", query.value("form").toInt()); |
|
304 query1.exec(); |
|
305 } |
|
306 } |
270 } |
307 } |
271 |
308 |
272 |
309 |
273 bool MainWindow::openWS(bool develop) |
310 bool MainWindow::openWS(bool develop) |
274 { |
311 { |
707 setWindowTitle(QString("BMSapp - %1 - Inventory Yeasts").arg(VERSIONSTRING)); |
744 setWindowTitle(QString("BMSapp - %1 - Inventory Yeasts").arg(VERSIONSTRING)); |
708 ui->menuBar->setVisible(false); |
745 ui->menuBar->setVisible(false); |
709 } |
746 } |
710 |
747 |
711 |
748 |
|
749 void MainWindow::fromInventoryYeastPacks() |
|
750 { |
|
751 ui->mainStack->setCurrentIndex(-1); |
|
752 ui->mainStack->removeWidget(InventoryYeastPacksWindow); |
|
753 delete InventoryYeastPacksWindow; |
|
754 setWindowTitle( QString("BMSapp - %1").arg(VERSIONSTRING) ); |
|
755 ui->menuBar->setVisible(true); |
|
756 statusBar()->clearMessage(); |
|
757 } |
|
758 |
|
759 |
|
760 void MainWindow::on_actionYeastPacks_triggered() |
|
761 { |
|
762 InventoryYeastPacksWindow = new InventoryYeastPacks(this); |
|
763 int index = ui->mainStack->count(); |
|
764 ui->mainStack->addWidget(InventoryYeastPacksWindow); |
|
765 ui->mainStack->setCurrentIndex(index); |
|
766 setWindowTitle(QString("BMSapp - %1 - Inventory Yeasts").arg(VERSIONSTRING)); |
|
767 ui->menuBar->setVisible(false); |
|
768 } |
|
769 |
|
770 |
712 void MainWindow::fromInventoryMiscs() |
771 void MainWindow::fromInventoryMiscs() |
713 { |
772 { |
714 ui->mainStack->setCurrentIndex(-1); |
773 ui->mainStack->setCurrentIndex(-1); |
715 ui->mainStack->removeWidget(InventoryMiscsWindow); |
774 ui->mainStack->removeWidget(InventoryMiscsWindow); |
716 delete InventoryMiscsWindow; |
775 delete InventoryMiscsWindow; |