Added print private yeastbank

Mon, 14 Mar 2022 16:05:11 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 14 Mar 2022 16:05:11 +0100
changeset 54
bba7be9034be
parent 53
d36879f13d32
child 55
2d8dbbc1ffab

Added print private yeastbank

src/PrinterDialog.cpp file | annotate | diff | comparison | revisions
--- a/src/PrinterDialog.cpp	Mon Mar 14 14:00:28 2022 +0100
+++ b/src/PrinterDialog.cpp	Mon Mar 14 16:05:11 2022 +0100
@@ -52,6 +52,7 @@
     QRect boundingRect;
     QPainter painter;
     QString w;
+    QSqlQuery query;
 
     const QColor c_header(255, 150, 100, 255);
     const QColor c_line1(210, 245, 255, 255);
@@ -59,14 +60,18 @@
     const QStringList f_types({tr("Grain"), tr("Sugar"), tr("Extract"), tr("Dry extract"), tr("Adjunct")});
     const QStringList h_form({tr("Pellet"), tr("Plug"), tr("Leaf"), tr("Leaf Wet"), tr("Cryo")});
     const QStringList m_types({tr("Spice"), tr("Herb"), tr("Flavor"), tr("Fining"), tr("Water agent"), tr("Yeast nutrient"), tr("Other")});
-    const QStringList y_form({tr("pkg"), tr("gr"), tr("ml"), tr("ml"), tr("ml"), tr("ml"), tr("gr")});
+    const QStringList y_unit({tr("pkg"), tr("gr"), tr("ml"), tr("ml"), tr("ml"), tr("ml"), tr("gr")});
+    const QStringList y_types({tr("Lager"), tr("Ale"), tr("Wheat"), tr("Wine"), tr("Champagne"), tr("Brett"), tr("Kveik"), tr("Hybrid")});
+    const QStringList y_form({tr("Liquid"), tr("Dry"), tr("Slant"), tr("Culture"), tr("Frozen"), tr("Bottle"), tr("Dried")});
 
     painter.begin(printer);
     bool firstPage = true;
     qreal y = 0;
 
     if (p_job == PR_SUPPLIES) {
-
+	/*
+	 * Print supplies in stock
+	 */
 	double	tot_fermentables = 0, tot_hops = 0, tot_yeasts = 0, tot_miscs = 0;
 
 	printHeader(&painter);
@@ -83,7 +88,7 @@
 	painter.drawText(655, y+4,  80, 20, Qt::AlignRight, tr("Value"));
 	y += 20;
 	painter.setFont(QFont("Helvetica", 9, QFont::Normal));
-	QSqlQuery query("SELECT type,name,supplier,inventory,cost FROM inventory_fermentables WHERE inventory > 0 ORDER BY type,supplier,name");
+	query.exec("SELECT type,name,supplier,inventory,cost FROM inventory_fermentables WHERE inventory > 0 ORDER BY type,supplier,name");
 	query.first();
 	for (int i = 0 ; i < query.size() ; i++ ) {
 	    if ((y + 20) > painter.device()->height()) {
@@ -193,9 +198,9 @@
 	    painter.drawText(120, y+4, 120, 20, Qt::AlignLeft, query.value(2).toString());
 	    painter.drawText(240, y+4, 220, 20, Qt::AlignLeft, query.value(0).toString());
 	    if (query.value(3).toInt() == 0)
-		w = QString("%1 %2").arg(query.value(4).toDouble(), 10, 'f', 1).arg(y_form[query.value(3).toInt()]);
+		w = QString("%1 %2").arg(query.value(4).toDouble(), 10, 'f', 1).arg(y_unit[query.value(3).toInt()]);
 	    else
-		w = QString("%1 %2").arg(query.value(4).toDouble() * 1000.0, 10, 'f', 1).arg(y_form[query.value(3).toInt()]);
+		w = QString("%1 %2").arg(query.value(4).toDouble() * 1000.0, 10, 'f', 1).arg(y_unit[query.value(3).toInt()]);
             painter.drawText(460, y+4, 115, 20, Qt::AlignRight, w);
             w = QString("%1 €").arg(query.value(5).toDouble(), 8, 'f', 2);
             painter.drawText(575, y+4,  80, 20, Qt::AlignRight, w);
@@ -258,6 +263,50 @@
         w = QString("%1 €").arg(tot_miscs, 8, 'f', 2);
         painter.drawText(655, y+4,  80, 20, Qt::AlignRight, w);
         y += 20;
+
+    } else if (p_job == PR_YEASTBANK) {
+	/*
+	 * Print yeast in the private yeast bank.
+	 */
+	query.exec("SELECT brewery_name,my_yeastlab FROM profile_setup WHERE record = '1'");
+	query.first();
+	QString my_lab = query.value(1).toString();
+	qDebug() << my_lab;
+	printHeader(&painter);
+        y = 120;
+
+	painter.setFont(QFont("Helvetica", 9, QFont::Bold));
+        painter.setPen(Qt::black);
+        painter.fillRect(  0, y,   735, 20, c_header);
+        painter.drawText(  0, y+4, 200, 20, Qt::AlignLeft, tr("Yeast"));
+        painter.drawText(200, y+4, 230, 20, Qt::AlignLeft, tr("Description"));
+	painter.drawText(430, y+4,  80, 20, Qt::AlignCenter, tr("Type"));
+	painter.drawText(510, y+4,  80, 20, Qt::AlignCenter, tr("Form"));
+        painter.drawText(590, y+4,  70, 20, Qt::AlignRight, tr("Stock"));
+        painter.drawText(665, y+4,  70, 20, Qt::AlignLeft, tr("Date"));
+        y += 20;
+        painter.setFont(QFont("Helvetica", 9, QFont::Normal));
+	query.prepare("SELECT name,type,form,inventory,production_date,short_desc "
+		       "FROM inventory_yeasts WHERE inventory > 0 AND laboratory = :my_lab ORDER BY product_id");
+	query.bindValue(":my_lab", my_lab);
+	query.exec();
+        query.first();
+	for (int i = 0; i < query.size(); i++) {
+	    painter.fillRect(  0, y,   735, 20, (i % 2) ? c_line1:c_line2);
+            painter.drawText(  0, y+4, 200, 20, Qt::AlignLeft, query.value(0).toString());
+	    painter.drawText(200, y+4, 230, 20, Qt::AlignLeft, query.value(5).toString());
+	    painter.drawText(430, y+4,  80, 20, Qt::AlignCenter, y_types[query.value(1).toInt()]);
+	    painter.drawText(510, y+4,  80, 20, Qt::AlignCenter, y_form[query.value(2).toInt()]);
+
+	    if (query.value(2).toInt() == 0)
+                w = QString("%1 %2").arg(query.value(3).toDouble(), 10, 'f', 1).arg(y_unit[query.value(2).toInt()]);
+            else
+                w = QString("%1 %2").arg(query.value(3).toDouble() * 1000.0, 10, 'f', 1).arg(y_unit[query.value(2).toInt()]);
+	    painter.drawText(590, y+4,  70, 20, Qt::AlignRight, w);
+	    painter.drawText(665, y+4,  70, 20, Qt::AlignLeft, query.value(4).toString());
+	    query.next();
+	    y += 20;
+	}
     }
 
 
@@ -288,6 +337,8 @@
     painter->setFont(QFont("Helvetica",18, QFont::Bold));
     if (p_job == PR_SUPPLIES) {
 	painter->drawText(120, 0,  500, 40, Qt::AlignLeft, tr("Inventory") + " " + query.value(1).toString());
+    } else if (p_job == PR_YEASTBANK) {
+	painter->drawText(120, 0,  500, 40, Qt::AlignLeft, tr("Yeast bank") + " " + query.value(1).toString());
     } else {
         painter->drawText(120, 0,  500, 40, Qt::AlignLeft, "?? " + query.value(1).toString());
     }

mercurial