344 qWarning() << "Parse error: " << parseError.errorString() << "at" << parseError.offset; |
344 qWarning() << "Parse error: " << parseError.errorString() << "at" << parseError.offset; |
345 } else if (hops.isArray()) { |
345 } else if (hops.isArray()) { |
346 for (int i = 0; i < hops.array().size(); i++) { |
346 for (int i = 0; i < hops.array().size(); i++) { |
347 QJsonObject obj = hops.array().at(i).toObject(); |
347 QJsonObject obj = hops.array().at(i).toObject(); |
348 Hops h; |
348 Hops h; |
349 h.h_avail = false; |
349 h.avail = false; |
350 h.h_inventory = 0; |
350 h.inventory = 0; |
351 h.h_name = obj["h_name"].toString(); |
351 h.name = obj["h_name"].toString(); |
352 h.h_origin = obj["h_origin"].toString(); |
352 h.origin = obj["h_origin"].toString(); |
353 h.h_amount = obj["h_amount"].toDouble(); |
353 h.amount = obj["h_amount"].toDouble(); |
354 h.h_cost = obj["h_cost"].toDouble(); |
354 h.cost = obj["h_cost"].toDouble(); |
355 h.h_type = obj["h_type"].toInt(); |
355 h.type = obj["h_type"].toInt(); |
356 h.h_form = obj["h_form"].toInt(); |
356 h.form = obj["h_form"].toInt(); |
357 h.h_useat = obj["h_useat"].toInt(); |
357 h.useat = obj["h_useat"].toInt(); |
358 h.h_time = obj["h_time"].toInt(); |
358 h.time = obj["h_time"].toInt(); |
359 h.h_alpha = obj["h_alpha"].toDouble(); |
359 h.alpha = obj["h_alpha"].toDouble(); |
360 h.h_beta = obj["h_beta"].toDouble(); |
360 h.beta = obj["h_beta"].toDouble(); |
361 h.h_hsi = obj["h_hsi"].toDouble(); |
361 h.hsi = obj["h_hsi"].toDouble(); |
362 h.h_humulene = obj["h_humulene"].toDouble(); |
362 h.humulene = obj["h_humulene"].toDouble(); |
363 h.h_caryophyllene = obj["h_caryophyllene"].toDouble(); |
363 h.caryophyllene = obj["h_caryophyllene"].toDouble(); |
364 h.h_cohumulone = obj["h_cohumulone"].toDouble(); |
364 h.cohumulone = obj["h_cohumulone"].toDouble(); |
365 h.h_myrcene = obj["h_myrcene"].toDouble(); |
365 h.myrcene = obj["h_myrcene"].toDouble(); |
366 h.h_total_oil = obj["h_total_oil"].toDouble(); |
366 h.total_oil = obj["h_total_oil"].toDouble(); |
367 /* Check and update inventory */ |
367 /* Check and update inventory */ |
368 yquery.prepare("SELECT inventory FROM inventory_hops WHERE name=:name AND origin=:origin"); |
368 yquery.prepare("SELECT inventory FROM inventory_hops WHERE name=:name AND origin=:origin"); |
369 yquery.bindValue(":name", h.h_name); |
369 yquery.bindValue(":name", h.name); |
370 yquery.bindValue(":origin", h.h_origin); |
370 yquery.bindValue(":origin", h.origin); |
371 yquery.exec(); |
371 yquery.exec(); |
372 if (yquery.first()) { |
372 if (yquery.first()) { |
373 h.h_avail = true; |
373 h.avail = true; |
374 h.h_inventory = yquery.value(0).toDouble(); |
374 h.inventory = yquery.value(0).toDouble(); |
375 } |
375 } |
376 prod->hops.append(h); |
376 prod->hops.append(h); |
377 } |
377 } |
378 qDebug() << "hops" << prod->hops.size(); |
378 qDebug() << "hops" << prod->hops.size(); |
379 } |
379 } |
873 query.bindValue(":json_hops", "[]"); |
873 query.bindValue(":json_hops", "[]"); |
874 } else { |
874 } else { |
875 QJsonArray array; |
875 QJsonArray array; |
876 for (int i = 0; i < prod->hops.size(); i++) { |
876 for (int i = 0; i < prod->hops.size(); i++) { |
877 QJsonObject obj; |
877 QJsonObject obj; |
878 obj.insert("h_name", prod->hops.at(i).h_name); |
878 obj.insert("h_name", prod->hops.at(i).name); |
879 obj.insert("h_origin", prod->hops.at(i).h_origin); |
879 obj.insert("h_origin", prod->hops.at(i).origin); |
880 obj.insert("h_amount", round(prod->hops.at(i).h_amount * 100000) / 100000); |
880 obj.insert("h_amount", round(prod->hops.at(i).amount * 100000) / 100000); |
881 obj.insert("h_cost", round(prod->hops.at(i).h_cost * 100) / 100); |
881 obj.insert("h_cost", round(prod->hops.at(i).cost * 100) / 100); |
882 obj.insert("h_type", prod->hops.at(i).h_type); |
882 obj.insert("h_type", prod->hops.at(i).type); |
883 obj.insert("h_form", prod->hops.at(i).h_form); |
883 obj.insert("h_form", prod->hops.at(i).form); |
884 obj.insert("h_useat", prod->hops.at(i).h_useat); |
884 obj.insert("h_useat", prod->hops.at(i).useat); |
885 obj.insert("h_time", round(prod->hops.at(i).h_time)); |
885 obj.insert("h_time", round(prod->hops.at(i).time)); |
886 obj.insert("h_alpha", round(prod->hops.at(i).h_alpha * 100) / 100); |
886 obj.insert("h_alpha", round(prod->hops.at(i).alpha * 100) / 100); |
887 obj.insert("h_beta", round(prod->hops.at(i).h_beta * 100) / 100); |
887 obj.insert("h_beta", round(prod->hops.at(i).beta * 100) / 100); |
888 obj.insert("h_hsi", round(prod->hops.at(i).h_hsi * 100) / 100); |
888 obj.insert("h_hsi", round(prod->hops.at(i).hsi * 100) / 100); |
889 obj.insert("h_humulene", round(prod->hops.at(i).h_humulene * 100) / 100); |
889 obj.insert("h_humulene", round(prod->hops.at(i).humulene * 100) / 100); |
890 obj.insert("h_caryophyllene", round(prod->hops.at(i).h_caryophyllene * 100) / 100); |
890 obj.insert("h_caryophyllene", round(prod->hops.at(i).caryophyllene * 100) / 100); |
891 obj.insert("h_cohumulone", round(prod->hops.at(i).h_cohumulone * 100) / 100); |
891 obj.insert("h_cohumulone", round(prod->hops.at(i).cohumulone * 100) / 100); |
892 obj.insert("h_myrcene", round(prod->hops.at(i).h_myrcene * 100) / 100); |
892 obj.insert("h_myrcene", round(prod->hops.at(i).myrcene * 100) / 100); |
893 obj.insert("h_total_oil", round(prod->hops.at(i).h_total_oil * 100) / 100); |
893 obj.insert("h_total_oil", round(prod->hops.at(i).total_oil * 100) / 100); |
894 // qDebug() << "hops_Json" << i << obj; |
894 // qDebug() << "hops_Json" << i << obj; |
895 array.append(obj); /* Append this object */ |
895 array.append(obj); /* Append this object */ |
896 } |
896 } |
897 QJsonDocument doc; |
897 QJsonDocument doc; |
898 doc.setArray(array); |
898 doc.setArray(array); |