339 double percentcheck = 0; |
339 double percentcheck = 0; |
340 for (int i = 0; i < fermentables.array().size(); i++) { |
340 for (int i = 0; i < fermentables.array().size(); i++) { |
341 QJsonObject obj = fermentables.array().at(i).toObject(); |
341 QJsonObject obj = fermentables.array().at(i).toObject(); |
342 //qDebug() << i << obj; |
342 //qDebug() << i << obj; |
343 Fermentables f; |
343 Fermentables f; |
|
344 f.f_inventory = 0; |
|
345 f.f_avail = false; |
344 f.f_name = obj["f_name"].toString(); |
346 f.f_name = obj["f_name"].toString(); |
345 f.f_origin = obj["f_origin"].toString(); |
347 f.f_origin = obj["f_origin"].toString(); |
346 f.f_supplier = obj["f_supplier"].toString(); |
348 f.f_supplier = obj["f_supplier"].toString(); |
347 f.f_amount = obj["f_amount"].toDouble(); |
349 f.f_amount = obj["f_amount"].toDouble(); |
348 f.f_cost = obj["f_cost"].toDouble(); |
350 f.f_cost = obj["f_cost"].toDouble(); |
364 f.f_di_ph = obj["f_di_ph"].toDouble(); |
366 f.f_di_ph = obj["f_di_ph"].toDouble(); |
365 f.f_acid_to_ph_57 = obj["f_acid_to_ph_57"].toDouble(); |
367 f.f_acid_to_ph_57 = obj["f_acid_to_ph_57"].toDouble(); |
366 if (f.f_adjust_to_total_100) |
368 if (f.f_adjust_to_total_100) |
367 product->fermentables_use100 = true; |
369 product->fermentables_use100 = true; |
368 percentcheck += f.f_percentage; |
370 percentcheck += f.f_percentage; |
|
371 /* Check and update inventory */ |
|
372 yquery.prepare("SELECT inventory FROM inventory_fermentables WHERE name=:name AND supplier=:supplier AND origin=:origin"); |
|
373 yquery.bindValue(":name", f.f_name); |
|
374 yquery.bindValue(":supplier", f.f_supplier); |
|
375 yquery.bindValue(":origin", f.f_origin); |
|
376 yquery.exec(); |
|
377 if (yquery.first()) { |
|
378 f.f_avail = true; |
|
379 f.f_inventory = yquery.value(0).toDouble(); |
|
380 } |
369 product->fermentables.append(f); |
381 product->fermentables.append(f); |
370 } |
382 } |
371 qDebug() << "fermentables" << product->fermentables.size() << percentcheck; |
383 qDebug() << "fermentables" << product->fermentables.size() << percentcheck; |
372 if (percentcheck == 0) { |
384 if (percentcheck == 0) { |
373 /* Missing percentages, fix it. */ |
385 /* Missing percentages, fix it. */ |