455 } else if (miscs.isArray()) { |
455 } else if (miscs.isArray()) { |
456 for (int i = 0; i < miscs.array().size(); i++) { |
456 for (int i = 0; i < miscs.array().size(); i++) { |
457 QJsonObject obj = miscs.array().at(i).toObject(); |
457 QJsonObject obj = miscs.array().at(i).toObject(); |
458 //qDebug() << i << obj; |
458 //qDebug() << i << obj; |
459 Miscs m; |
459 Miscs m; |
|
460 m.m_avail = false; |
|
461 m.m_inventory = 0; |
460 m.m_name = obj["m_name"].toString(); |
462 m.m_name = obj["m_name"].toString(); |
461 m.m_amount = obj["m_amount"].toDouble(); |
463 m.m_amount = obj["m_amount"].toDouble(); |
462 m.m_type = obj["m_type"].toInt(); |
464 m.m_type = obj["m_type"].toInt(); |
463 m.m_use_use = obj["m_use_use"].toInt(); |
465 m.m_use_use = obj["m_use_use"].toInt(); |
464 m.m_time = obj["m_time"].toDouble(); |
466 m.m_time = obj["m_time"].toDouble(); |
465 m.m_amount_is_weight = obj["m_amount_is_weight"].toInt() ? true:false; |
467 m.m_amount_is_weight = obj["m_amount_is_weight"].toInt() ? true:false; |
466 m.m_cost = obj["m_cost"].toDouble(); |
468 m.m_cost = obj["m_cost"].toDouble(); |
|
469 /* Check and update inventory */ |
|
470 yquery.prepare("SELECT inventory FROM inventory_miscs WHERE name=:name"); |
|
471 yquery.bindValue(":name", m.m_name); |
|
472 yquery.exec(); |
|
473 if (yquery.first()) { |
|
474 m.m_avail = true; |
|
475 m.m_inventory = yquery.value(0).toDouble(); |
|
476 } |
467 product->miscs.append(m); |
477 product->miscs.append(m); |
468 } |
478 } |
469 qDebug() << "miscs" << product->miscs.size(); |
479 qDebug() << "miscs" << product->miscs.size(); |
470 } |
480 } |
471 } else { |
481 } else { |
515 y.y_gr_hl_lo = obj["y_gr_hl_lo"].toInt(); |
525 y.y_gr_hl_lo = obj["y_gr_hl_lo"].toInt(); |
516 y.y_sg_lo = obj["y_sg_lo"].toDouble(); |
526 y.y_sg_lo = obj["y_sg_lo"].toDouble(); |
517 y.y_gr_hl_hi = obj["y_gr_hl_hi"].toInt(); |
527 y.y_gr_hl_hi = obj["y_gr_hl_hi"].toInt(); |
518 y.y_sg_hi = obj["y_sg_hi"].toDouble(); |
528 y.y_sg_hi = obj["y_sg_hi"].toDouble(); |
519 y.y_cost = obj["y_cost"].toDouble(); |
529 y.y_cost = obj["y_cost"].toDouble(); |
520 |
530 /* |
521 if (y.y_tolerance == 0 || y.y_cells == 0) { // More and better tests? |
531 * Possible data upgrade needed. |
522 /* |
532 */ |
523 * Possible data upgrade needed. |
533 yquery.prepare("SELECT tolerance,cells,sta1,bacteria,harvest_top,harvest_time,pitch_temperature," |
524 */ |
534 "pofpos,zymocide,gr_hl_lo,sg_lo,gr_hl_hi,sg_hi,inventory " |
525 yquery.prepare("SELECT tolerance,cells,sta1,bacteria,harvest_top,harvest_time,pitch_temperature," |
|
526 "pofpos,zymocide,gr_hl_lo,sg_lo,gr_hl_hi,sg_hi " |
|
527 "FROM inventory_yeasts WHERE name=:name AND laboratory=:laboratory AND product_id=:product_id"); |
535 "FROM inventory_yeasts WHERE name=:name AND laboratory=:laboratory AND product_id=:product_id"); |
528 yquery.bindValue(":name", y.y_name); |
536 yquery.bindValue(":name", y.y_name); |
529 yquery.bindValue(":laboratory", y.y_laboratory); |
537 yquery.bindValue(":laboratory", y.y_laboratory); |
530 yquery.bindValue(":product_id", y.y_product_id); |
538 yquery.bindValue(":product_id", y.y_product_id); |
531 yquery.exec(); |
539 yquery.exec(); |
532 if (yquery.first()) { |
540 if (yquery.first()) { |
|
541 if (y.y_tolerance == 0 || y.y_cells == 0) { |
533 y.y_tolerance = yquery.value(0).toDouble(); |
542 y.y_tolerance = yquery.value(0).toDouble(); |
534 y.y_cells = yquery.value(1).toDouble(); |
543 y.y_cells = yquery.value(1).toDouble(); |
535 y.y_sta1 = yquery.value(2).toInt() ? true:false; |
|
536 y.y_bacteria = yquery.value(3).toInt() ? true:false; |
|
537 y.y_harvest_top = yquery.value(4).toInt() ? true:false; |
|
538 y.y_harvest_time = yquery.value(5).toInt(); |
|
539 y.y_pitch_temperature = yquery.value(6).toDouble(); |
|
540 y.y_pofpos = yquery.value(7).toInt() ? true:false; |
|
541 y.y_zymocide = yquery.value(8).toInt(); |
|
542 y.y_gr_hl_lo = yquery.value(9).toInt(); |
|
543 y.y_sg_lo = yquery.value(10).toDouble(); |
|
544 y.y_gr_hl_hi = yquery.value(11).toInt(); |
|
545 y.y_sg_hi = yquery.value(12).toDouble(); |
|
546 } else { |
|
547 qDebug() << y.y_name << y.y_product_id << "not found for upgrade"; |
|
548 } |
544 } |
|
545 y.y_sta1 = yquery.value(2).toInt() ? true:false; |
|
546 y.y_bacteria = yquery.value(3).toInt() ? true:false; |
|
547 y.y_harvest_top = yquery.value(4).toInt() ? true:false; |
|
548 y.y_harvest_time = yquery.value(5).toInt(); |
|
549 y.y_pitch_temperature = yquery.value(6).toDouble(); |
|
550 y.y_pofpos = yquery.value(7).toInt() ? true:false; |
|
551 y.y_zymocide = yquery.value(8).toInt(); |
|
552 y.y_gr_hl_lo = yquery.value(9).toInt(); |
|
553 y.y_sg_lo = yquery.value(10).toDouble(); |
|
554 y.y_gr_hl_hi = yquery.value(11).toInt(); |
|
555 y.y_sg_hi = yquery.value(12).toDouble(); |
|
556 y.y_inventory = yquery.value(13).toDouble(); |
|
557 y.y_avail = true; |
|
558 } else { |
|
559 qDebug() << y.y_name << y.y_product_id << "not found for upgrade"; |
549 } |
560 } |
550 product->yeasts.append(y); |
561 product->yeasts.append(y); |
551 } |
562 } |
552 qDebug() << "yeasts" << product->yeasts.size(); |
563 qDebug() << "yeasts" << product->yeasts.size(); |
553 } |
564 } |