src/database/db_product.cpp

changeset 432
f189af715073
parent 423
8cb46020796a
child 433
40d4d2bb5f11
equal deleted inserted replaced
431:bfac9a7008a3 432:f189af715073
31 QMessageBox::warning(dialog, QObject::tr("Database error"), QObject::tr("MySQL error: record %1 not found").arg(recno)); 31 QMessageBox::warning(dialog, QObject::tr("Database error"), QObject::tr("MySQL error: record %1 not found").arg(recno));
32 dialog->done(QDialog::Rejected); // At this stage, this doesn't work because the dialog is not yet visible. 32 dialog->done(QDialog::Rejected); // At this stage, this doesn't work because the dialog is not yet visible.
33 return false; 33 return false;
34 } 34 }
35 35
36 QSqlRecord rec = query.record(); 36 // QSqlRecord rec = query.record();
37 for (int i = 0; i < rec.count(); i++) 37 // for (int i = 0; i < rec.count(); i++)
38 qDebug() << i << rec.fieldName(i) << query.value(i); 38 // qDebug() << i << rec.fieldName(i) << query.value(i);
39 39
40 prod->record = query.value("record").toInt(); 40 prod->record = query.value("record").toInt();
41 prod->uuid = query.value("uuid").toString(); 41 prod->uuid = query.value("uuid").toString();
42 prod->name = query.value("name").toString(); 42 prod->name = query.value("name").toString();
43 prod->code = query.value("code").toString(); 43 prod->code = query.value("code").toString();
319 f.avail = true; 319 f.avail = true;
320 f.inventory = yquery.value(0).toDouble(); 320 f.inventory = yquery.value(0).toDouble();
321 } 321 }
322 prod->fermentables.append(f); 322 prod->fermentables.append(f);
323 } 323 }
324 qDebug() << "fermentables" << prod->fermentables.size() << percentcheck; 324 // qDebug() << "fermentables" << prod->fermentables.size() << percentcheck;
325 if (percentcheck == 0 && prod->fermentables.size()) { 325 if (percentcheck == 0 && prod->fermentables.size()) {
326 /* Missing percentages, fix it. */ 326 /* Missing percentages, fix it. */
327 double total = 0; 327 double total = 0;
328 for (int i = 0; i < prod->fermentables.size(); i++) { 328 for (int i = 0; i < prod->fermentables.size(); i++) {
329 if (prod->fermentables.at(i).added < 4) 329 if (prod->fermentables.at(i).added < 4)
332 for (int i = 0; i < prod->fermentables.size(); i++) { 332 for (int i = 0; i < prod->fermentables.size(); i++) {
333 if (prod->fermentables.at(i).added < 4) 333 if (prod->fermentables.at(i).added < 4)
334 prod->fermentables[i].percentage = round((prod->fermentables.at(i).amount / total) * 10000.0) / 100.0; 334 prod->fermentables[i].percentage = round((prod->fermentables.at(i).amount / total) * 10000.0) / 100.0;
335 } 335 }
336 qInfo() << " fixed missing percentages"; 336 qInfo() << " fixed missing percentages";
337 // is_changed();
338 } 337 }
339 } 338 }
340 } else { 339 } else {
341 qDebug() << "empty fermentables"; 340 qInfo() << "empty fermentables";
342 } 341 }
343 342
344 const auto& h_json = query.value("json_hops").toString(); 343 const auto& h_json = query.value("json_hops").toString();
345 if (!h_json.trimmed().isEmpty()) { 344 if (!h_json.trimmed().isEmpty()) {
346 const auto& formattedJson = QString("%1").arg(h_json); 345 const auto& formattedJson = QString("%1").arg(h_json);
387 h.utilisation = my_ut_pellet; 386 h.utilisation = my_ut_pellet;
388 h.bu_factor = 1.0; 387 h.bu_factor = 1.0;
389 } 388 }
390 prod->hops.append(h); 389 prod->hops.append(h);
391 } 390 }
392 qDebug() << "hops" << prod->hops.size(); 391 // qDebug() << "hops" << prod->hops.size();
393 } 392 }
394 } else { 393 } else {
395 qDebug() << "empty hops"; 394 qInfo() << "empty hops";
396 } 395 }
397 396
398 const auto& json = query.value("json_miscs").toString(); 397 const auto& json = query.value("json_miscs").toString();
399 if (!json.trimmed().isEmpty()) { 398 if (!json.trimmed().isEmpty()) {
400 const auto& formattedJson = QString("%1").arg(json); 399 const auto& formattedJson = QString("%1").arg(json);
422 m.avail = true; 421 m.avail = true;
423 m.inventory = yquery.value(0).toDouble(); 422 m.inventory = yquery.value(0).toDouble();
424 } 423 }
425 prod->miscs.append(m); 424 prod->miscs.append(m);
426 } 425 }
427 qDebug() << "miscs" << prod->miscs.size(); 426 // qDebug() << "miscs" << prod->miscs.size();
428 } 427 }
429 } else { 428 } else {
430 qDebug() << "empty miscs"; 429 qInfo() << "empty miscs";
431 } 430 }
432 431
433 const auto& y_json = query.value("json_yeasts").toString(); 432 const auto& y_json = query.value("json_yeasts").toString();
434 if (!y_json.trimmed().isEmpty()) { 433 if (!y_json.trimmed().isEmpty()) {
435 const auto& formattedJson = QString("%1").arg(y_json); 434 const auto& formattedJson = QString("%1").arg(y_json);
505 } else { 504 } else {
506 qDebug() << y.name << y.product_id << "not found for upgrade"; 505 qDebug() << y.name << y.product_id << "not found for upgrade";
507 } 506 }
508 prod->yeasts.append(y); 507 prod->yeasts.append(y);
509 } 508 }
510 qDebug() << "yeasts" << prod->yeasts.size(); 509 // qDebug() << "yeasts" << prod->yeasts.size();
511 } 510 }
512 } else { 511 } else {
513 qDebug() << "empty yeasts"; 512 qInfo() << "empty yeasts";
514 } 513 }
515 514
516 const auto& ma_json = query.value("json_mashs").toString().trimmed(); 515 const auto& ma_json = query.value("json_mashs").toString().trimmed();
517 if (!ma_json.trimmed().isEmpty()) { 516 if (!ma_json.trimmed().isEmpty()) {
518 const auto& formattedJson = QString("%1").arg(ma_json); 517 const auto& formattedJson = QString("%1").arg(ma_json);
537 m.step_sg = obj["step_sg"].toDouble(); 536 m.step_sg = obj["step_sg"].toDouble();
538 prod->mashs.append(m); 537 prod->mashs.append(m);
539 } 538 }
540 } 539 }
541 } else { 540 } else {
542 qDebug() << "empty mashs"; 541 qInfo() << "empty mashs";
543 } 542 }
544 qDebug() << "mashs" << prod->mashs.size(); 543 // qDebug() << "mashs" << prod->mashs.size();
545 544
546 return true; 545 return true;
547 } 546 }
548 547
549 548

mercurial