77 |
77 |
78 item = new QTableWidgetItem(misc_uses[product->miscs.at(i).m_use_use]); |
78 item = new QTableWidgetItem(misc_uses[product->miscs.at(i).m_use_use]); |
79 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
79 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
80 ui->miscsTable->setItem(i, 2, item); |
80 ui->miscsTable->setItem(i, 2, item); |
81 |
81 |
82 if (product->miscs.at(i).m_use_use == 2) { // Boil |
82 if (product->miscs.at(i).m_use_use == MISC_USES_BOIL) { |
83 item = new QTableWidgetItem(QString("%1 min.").arg(product->miscs.at(i).m_time, 1, 'f', 0, '0')); |
83 item = new QTableWidgetItem(QString("%1 min.").arg(product->miscs.at(i).m_time, 1, 'f', 0, '0')); |
84 } else if (product->miscs.at(i).m_use_use == 3 || product->miscs.at(i).m_use_use == 4) { // Primary or secondary |
84 } else if (product->miscs.at(i).m_use_use == MISC_USES_PRIMARY || product->miscs.at(i).m_use_use == MISC_USES_SECONDARY) { |
85 item = new QTableWidgetItem(QString("%1 days.").arg(product->miscs.at(i).m_time / 1440, 1, 'f', 0, '0')); |
85 item = new QTableWidgetItem(QString("%1 days.").arg(product->miscs.at(i).m_time / 1440, 1, 'f', 0, '0')); |
86 } else { |
86 } else { |
87 item = new QTableWidgetItem(QString("")); |
87 item = new QTableWidgetItem(QString("")); |
88 } |
88 } |
89 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
89 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
99 if (product->miscs.at(i).m_amount_is_weight) |
99 if (product->miscs.at(i).m_amount_is_weight) |
100 item = new QTableWidgetItem(QString("%1 gr").arg(product->miscs.at(i).m_inventory * 1000.0, 3, 'f', 2, '0')); |
100 item = new QTableWidgetItem(QString("%1 gr").arg(product->miscs.at(i).m_inventory * 1000.0, 3, 'f', 2, '0')); |
101 else |
101 else |
102 item = new QTableWidgetItem(QString("%1 ml").arg(product->miscs.at(i).m_inventory * 1000.0, 3, 'f', 2, '0')); |
102 item = new QTableWidgetItem(QString("%1 ml").arg(product->miscs.at(i).m_inventory * 1000.0, 3, 'f', 2, '0')); |
103 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
103 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
104 if (product->miscs.at(i).m_inventory < product->miscs.at(i).m_amount) |
|
105 item->setForeground(QBrush(QColor(Qt::red))); |
104 ui->miscsTable->setItem(i, 5, item); |
106 ui->miscsTable->setItem(i, 5, item); |
105 |
107 |
106 /* |
108 /* |
107 * Add the Delete and Edit row buttons. |
109 * Add the Delete and Edit row buttons. |
108 * Not for water agents, these are set on the water tab. |
110 * Not for water agents, these are set on the water tab. |
109 */ |
111 */ |
110 if (product->miscs.at(i).m_type == 4) { |
112 if (product->miscs.at(i).m_type == MISC_TYPES_WATER_AGENT) { |
111 item = new QTableWidgetItem(""); |
113 item = new QTableWidgetItem(""); |
112 item->setToolTip(tr("Edit this from the water tab")); |
114 item->setToolTip(tr("Edit this from the water tab")); |
113 ui->miscsTable->setItem(i, 6, item); |
115 ui->miscsTable->setItem(i, 6, item); |
114 item = new QTableWidgetItem(""); |
116 item = new QTableWidgetItem(""); |
115 item->setToolTip(tr("Edit this from the water tab")); |
117 item->setToolTip(tr("Edit this from the water tab")); |
139 } |
141 } |
140 |
142 |
141 /* |
143 /* |
142 * Update the water agents. |
144 * Update the water agents. |
143 */ |
145 */ |
144 if (product->miscs.at(i).m_type == 4) { |
146 if (product->miscs.at(i).m_type == MISC_TYPES_WATER_AGENT) { |
145 if (product->miscs.at(i).m_name == "CaCl2") { |
147 if (product->miscs.at(i).m_name == "CaCl2") { |
146 ui->bs_cacl2Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
148 ui->bs_cacl2Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
147 } else if (product->miscs.at(i).m_name == "CaSO4") { |
149 } else if (product->miscs.at(i).m_name == "CaSO4") { |
148 ui->bs_caso4Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
150 ui->bs_caso4Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
149 } else if (product->miscs.at(i).m_name == "MgSO4") { |
151 } else if (product->miscs.at(i).m_name == "MgSO4") { |
184 } |
186 } |
185 } |
187 } |
186 } |
188 } |
187 |
189 |
188 |
190 |
|
191 void EditProduct::calcMiscs() |
|
192 { |
|
193 product->miscs_ok = true; |
|
194 for (int i = 0; i < product->miscs.size(); i++) { |
|
195 if ((((product->inventory_reduced <= PROD_STAGE_BREW) && (product->miscs.at(i).m_use_use <= MISC_USES_BOIL)) || // Starter, Mash, Boil |
|
196 ((product->inventory_reduced <= PROD_STAGE_PRIMARY) && (product->miscs.at(i).m_use_use == MISC_USES_PRIMARY)) || |
|
197 ((product->inventory_reduced <= PROD_STAGE_TERTIARY) && (product->miscs.at(i).m_use_use == MISC_USES_SECONDARY)) || |
|
198 ((product->inventory_reduced <= PROD_STAGE_PACKAGE) && (product->miscs.at(i).m_use_use == MISC_USES_BOTTLING))) && |
|
199 (product->miscs.at(i).m_inventory < product->miscs.at(i).m_amount)) { |
|
200 product->miscs_ok = false; |
|
201 } |
|
202 } |
|
203 } |
|
204 |
|
205 |
189 /* |
206 /* |
190 * Manipulate the memory array and update the miscs table. |
207 * Manipulate the memory array and update the miscs table. |
191 */ |
208 */ |
192 void EditProduct::brewing_salt_sub(QString salt, double val) |
209 void EditProduct::brewing_salt_sub(QString salt, double val) |
193 { |
210 { |
243 m.m_type = query.value(2).toInt(); |
260 m.m_type = query.value(2).toInt(); |
244 m.m_use_use = query.value(3).toInt(); |
261 m.m_use_use = query.value(3).toInt(); |
245 m.m_time = query.value(4).toDouble(); |
262 m.m_time = query.value(4).toDouble(); |
246 m.m_amount_is_weight = query.value(5).toInt() ? true:false; |
263 m.m_amount_is_weight = query.value(5).toInt() ? true:false; |
247 m.m_cost = query.value(10).toDouble(); |
264 m.m_cost = query.value(10).toDouble(); |
|
265 m.m_inventory = query.value(9).toDouble(); |
248 product->miscs.append(m); |
266 product->miscs.append(m); |
249 refreshMiscs(); |
267 refreshMiscs(); |
250 return; |
268 return; |
251 } |
269 } |
252 } |
270 } |
277 return; // Add only one at a time. |
295 return; // Add only one at a time. |
278 } |
296 } |
279 |
297 |
280 newm.m_name = "Select one"; |
298 newm.m_name = "Select one"; |
281 newm.m_amount = 0; |
299 newm.m_amount = 0; |
282 newm.m_type = 0; |
300 newm.m_type = MISC_TYPES_SPICE; |
283 newm.m_use_use = 0; |
301 newm.m_use_use = MISC_USES_STARTER; |
284 newm.m_time = 0; |
302 newm.m_time = 0; |
285 newm.m_amount_is_weight = true; |
303 newm.m_amount_is_weight = true; |
286 newm.m_cost = 0; |
304 newm.m_cost = 0; |
287 product->miscs.append(newm); |
305 product->miscs.append(newm); |
288 is_changed(); |
306 is_changed(); |
333 { |
351 { |
334 QTableWidgetItem *item; |
352 QTableWidgetItem *item; |
335 |
353 |
336 qDebug() << "misc_time_changed()" << product->miscs_row << val; |
354 qDebug() << "misc_time_changed()" << product->miscs_row << val; |
337 |
355 |
338 if (product->miscs.at(product->miscs_row).m_use_use == 2) { // Boil |
356 if (product->miscs.at(product->miscs_row).m_use_use == MISC_USES_BOIL) { |
339 product->miscs[product->miscs_row].m_time = val; |
357 product->miscs[product->miscs_row].m_time = val; |
340 item = new QTableWidgetItem(QString("%1 min.").arg(val, 1, 'f', 0, '0')); |
358 item = new QTableWidgetItem(QString("%1 min.").arg(val, 1, 'f', 0, '0')); |
341 } else if (product->miscs.at(product->miscs_row).m_use_use == 3 || product->miscs.at(product->miscs_row).m_use_use == 4) { // Primary or secondary |
359 } else if (product->miscs.at(product->miscs_row).m_use_use == MISC_USES_PRIMARY || |
|
360 product->miscs.at(product->miscs_row).m_use_use == MISC_USES_SECONDARY) { |
342 product->miscs[product->miscs_row].m_time = val * 1440; |
361 product->miscs[product->miscs_row].m_time = val * 1440; |
343 item = new QTableWidgetItem(QString("%1 days.").arg(val, 1, 'f', 0, '0')); |
362 item = new QTableWidgetItem(QString("%1 days.").arg(val, 1, 'f', 0, '0')); |
344 } else { |
363 } else { |
345 item = new QTableWidgetItem(QString("")); |
364 item = new QTableWidgetItem(QString("")); |
346 } |
365 } |
364 qDebug() << "misc_select_changed()" << product->miscs_row << val << instock; |
383 qDebug() << "misc_select_changed()" << product->miscs_row << val << instock; |
365 |
384 |
366 /* |
385 /* |
367 * Search the misc ingredient pointed by the index and instock flag. |
386 * Search the misc ingredient pointed by the index and instock flag. |
368 */ |
387 */ |
369 QString sql = "SELECT name,type,use_use,time,amount_is_weight,cost FROM inventory_miscs WHERE "; |
388 QString sql = "SELECT name,type,use_use,time,amount_is_weight,cost,inventory FROM inventory_miscs WHERE "; |
370 if (instock) |
389 if (instock) |
371 sql.append("inventory > 0 AND "); |
390 sql.append("inventory > 0 AND "); |
372 sql.append("type != 4 ORDER BY name"); |
391 sql.append("type != 4 ORDER BY name"); |
373 qDebug() << sql; |
392 qDebug() << sql; |
374 query.prepare(sql); |
393 query.prepare(sql); |
386 product->miscs[product->miscs_row].m_type = query.value(1).toInt(); |
405 product->miscs[product->miscs_row].m_type = query.value(1).toInt(); |
387 product->miscs[product->miscs_row].m_use_use = query.value(2).toInt(); |
406 product->miscs[product->miscs_row].m_use_use = query.value(2).toInt(); |
388 product->miscs[product->miscs_row].m_time = query.value(3).toDouble(); |
407 product->miscs[product->miscs_row].m_time = query.value(3).toDouble(); |
389 product->miscs[product->miscs_row].m_amount_is_weight = query.value(4).toInt() ? true:false; |
408 product->miscs[product->miscs_row].m_amount_is_weight = query.value(4).toInt() ? true:false; |
390 product->miscs[product->miscs_row].m_cost = query.value(5).toDouble(); |
409 product->miscs[product->miscs_row].m_cost = query.value(5).toDouble(); |
|
410 product->miscs[product->miscs_row].m_inventory = query.value(6).toDouble(); |
391 |
411 |
392 /* |
412 /* |
393 * Update the visible fields |
413 * Update the visible fields |
394 */ |
414 */ |
395 mnameEdit->setText(product->miscs.at(product->miscs_row).m_name); |
415 mnameEdit->setText(product->miscs.at(product->miscs_row).m_name); |
430 item = new QTableWidgetItem(QString("%1 ml").arg(product->miscs.at(product->miscs_row).m_amount * 1000.0, 3, 'f', 2, '0')); |
450 item = new QTableWidgetItem(QString("%1 ml").arg(product->miscs.at(product->miscs_row).m_amount * 1000.0, 3, 'f', 2, '0')); |
431 } |
451 } |
432 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
452 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
433 ui->miscsTable->setItem(product->miscs_row, 4, item); |
453 ui->miscsTable->setItem(product->miscs_row, 4, item); |
434 |
454 |
|
455 if (product->miscs.at(product->miscs_row).m_amount_is_weight) |
|
456 item = new QTableWidgetItem(QString("%1 gr").arg(product->miscs.at(product->miscs_row).m_inventory * 1000.0, 3, 'f', 2, '0')); |
|
457 else |
|
458 item = new QTableWidgetItem(QString("%1 ml").arg(product->miscs.at(product->miscs_row).m_inventory * 1000.0, 3, 'f', 2, '0')); |
|
459 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
460 if (product->miscs.at(product->miscs_row).m_inventory < product->miscs.at(product->miscs_row).m_amount) |
|
461 item->setForeground(QBrush(QColor(Qt::red))); |
|
462 ui->miscsTable->setItem(product->miscs_row, 5, item); |
|
463 |
435 is_changed(); |
464 is_changed(); |
436 emit refreshAll(); |
465 emit refreshAll(); |
437 } |
466 } |
438 |
467 |
439 |
468 |
469 product->miscs[product->miscs_row].m_use_use = val; |
498 product->miscs[product->miscs_row].m_use_use = val; |
470 item = new QTableWidgetItem(misc_uses[val]); |
499 item = new QTableWidgetItem(misc_uses[val]); |
471 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
500 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
472 ui->miscsTable->setItem(product->miscs_row, 2, item); |
501 ui->miscsTable->setItem(product->miscs_row, 2, item); |
473 |
502 |
474 if (val == 3 || val == 4) { // Fermentation stages |
503 if (val == MISC_USES_PRIMARY || val == MISC_USES_SECONDARY) { |
475 product->miscs[product->miscs_row].m_time = mtimeEdit->value() * 1440; |
504 product->miscs[product->miscs_row].m_time = mtimeEdit->value() * 1440; |
476 mtimeEdit->setReadOnly(false); |
505 mtimeEdit->setReadOnly(false); |
477 mtimeLabel->setText(tr("Time in days:")); |
506 mtimeLabel->setText(tr("Time in days:")); |
478 item = new QTableWidgetItem(QString("%1 days.").arg(product->miscs.at(product->miscs_row).m_time / 1440, 1, 'f', 0, '0')); |
507 item = new QTableWidgetItem(QString("%1 days.").arg(product->miscs.at(product->miscs_row).m_time / 1440, 1, 'f', 0, '0')); |
479 } else if (val == 2) { // Boil |
508 } else if (val == MISC_USES_BOIL) { |
480 product->miscs[product->miscs_row].m_time = mtimeEdit->value(); |
509 product->miscs[product->miscs_row].m_time = mtimeEdit->value(); |
481 mtimeEdit->setReadOnly(false); |
510 mtimeEdit->setReadOnly(false); |
482 mtimeLabel->setText(tr("Time in minutes:")); |
511 mtimeLabel->setText(tr("Time in minutes:")); |
483 item = new QTableWidgetItem(QString("%1 min.").arg(product->miscs.at(product->miscs_row).m_time, 1, 'f', 0, '0')); |
512 item = new QTableWidgetItem(QString("%1 min.").arg(product->miscs.at(product->miscs_row).m_time, 1, 'f', 0, '0')); |
484 } else { |
513 } else { |
532 mamountLabel->setGeometry(QRect(10, 70, 141, 20)); |
561 mamountLabel->setGeometry(QRect(10, 70, 141, 20)); |
533 mamountLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
562 mamountLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
534 |
563 |
535 mtimeLabel = new QLabel(dialog); |
564 mtimeLabel = new QLabel(dialog); |
536 mtimeLabel->setObjectName(QString::fromUtf8("mtimeLabel")); |
565 mtimeLabel->setObjectName(QString::fromUtf8("mtimeLabel")); |
537 if (product->miscs.at(product->miscs_row).m_use_use == 3 || product->miscs.at(product->miscs_row).m_use_use == 4) // Fermentation stages |
566 if (product->miscs.at(product->miscs_row).m_use_use == MISC_USES_PRIMARY || product->miscs.at(product->miscs_row).m_use_use == MISC_USES_SECONDARY) |
538 mtimeLabel->setText(tr("Time in days:")); |
567 mtimeLabel->setText(tr("Time in days:")); |
539 else if (product->miscs.at(product->miscs_row).m_use_use == 2) // Boil |
568 else if (product->miscs.at(product->miscs_row).m_use_use == MISC_USES_BOIL) |
540 mtimeLabel->setText(tr("Time in minutes:")); |
569 mtimeLabel->setText(tr("Time in minutes:")); |
541 else |
570 else |
542 mtimeLabel->setText(""); |
571 mtimeLabel->setText(""); |
543 mtimeLabel->setGeometry(QRect(10, 100, 141, 20)); |
572 mtimeLabel->setGeometry(QRect(10, 100, 141, 20)); |
544 mtimeLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
573 mtimeLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
578 mtimeEdit->setObjectName(QString::fromUtf8("mtimeEdit")); |
607 mtimeEdit->setObjectName(QString::fromUtf8("mtimeEdit")); |
579 mtimeEdit->setGeometry(QRect(160, 100, 121, 24)); |
608 mtimeEdit->setGeometry(QRect(160, 100, 121, 24)); |
580 mtimeEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
609 mtimeEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
581 mtimeEdit->setAccelerated(true); |
610 mtimeEdit->setAccelerated(true); |
582 mtimeEdit->setMaximum(10000.0); |
611 mtimeEdit->setMaximum(10000.0); |
583 if (product->miscs.at(product->miscs_row).m_use_use == 3 || product->miscs.at(product->miscs_row).m_use_use == 4) { // Fermentation stages |
612 if (product->miscs.at(product->miscs_row).m_use_use == MISC_USES_PRIMARY || product->miscs.at(product->miscs_row).m_use_use == MISC_USES_SECONDARY) { |
584 mtimeEdit->setValue(product->miscs.at(product->miscs_row).m_time / 1440); |
613 mtimeEdit->setValue(product->miscs.at(product->miscs_row).m_time / 1440); |
585 mtimeEdit->setReadOnly(false); |
614 mtimeEdit->setReadOnly(false); |
586 } else if (product->miscs.at(product->miscs_row).m_use_use == 2) { // Boil |
615 } else if (product->miscs.at(product->miscs_row).m_use_use == MISC_USES_BOIL) { |
587 mtimeEdit->setValue(product->miscs.at(product->miscs_row).m_time); |
616 mtimeEdit->setValue(product->miscs.at(product->miscs_row).m_time); |
588 mtimeEdit->setReadOnly(false); |
617 mtimeEdit->setReadOnly(false); |
589 } else { |
618 } else { |
590 mtimeEdit->setReadOnly(true); |
619 mtimeEdit->setReadOnly(true); |
591 } |
620 } |
621 if (dialog->result() == QDialog::Rejected) { |
650 if (dialog->result() == QDialog::Rejected) { |
622 qDebug() << "reject and rollback"; |
651 qDebug() << "reject and rollback"; |
623 product->miscs[product->miscs_row] = backup; |
652 product->miscs[product->miscs_row] = backup; |
624 } else { |
653 } else { |
625 /* Clear time if misc is not used for boil or fermentation. */ |
654 /* Clear time if misc is not used for boil or fermentation. */ |
626 if (! (product->miscs.at(product->miscs_row).m_use_use == 2 || |
655 if (! (product->miscs.at(product->miscs_row).m_use_use == MISC_USES_BOIL || |
627 product->miscs.at(product->miscs_row).m_use_use == 3 || |
656 product->miscs.at(product->miscs_row).m_use_use == MISC_USES_PRIMARY || |
628 product->miscs.at(product->miscs_row).m_use_use == 4)) { |
657 product->miscs.at(product->miscs_row).m_use_use == MISC_USES_SECONDARY)) { |
629 if (product->miscs.at(product->miscs_row).m_time) { |
658 if (product->miscs.at(product->miscs_row).m_time) { |
630 product->miscs[product->miscs_row].m_time = 0; |
659 product->miscs[product->miscs_row].m_time = 0; |
631 is_changed(); |
660 is_changed(); |
632 } |
661 } |
633 } |
662 } |
665 product->miscs[i].m_amount = amount; |
694 product->miscs[i].m_amount = amount; |
666 |
695 |
667 /* |
696 /* |
668 * Update the water agents. |
697 * Update the water agents. |
669 */ |
698 */ |
670 if (product->miscs.at(i).m_type == 4) { |
699 if (product->miscs.at(i).m_type == MISC_TYPES_WATER_AGENT) { |
671 if (product->miscs.at(i).m_name == "CaCl2") { |
700 if (product->miscs.at(i).m_name == "CaCl2") { |
672 ui->bs_cacl2Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
701 ui->bs_cacl2Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
673 } else if (product->miscs.at(i).m_name == "CaSO4") { |
702 } else if (product->miscs.at(i).m_name == "CaSO4") { |
674 ui->bs_caso4Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
703 ui->bs_caso4Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
675 } else if (product->miscs.at(i).m_name == "MgSO4") { |
704 } else if (product->miscs.at(i).m_name == "MgSO4") { |