src/EditProduct.cpp

changeset 248
1a7a5dffba58
parent 227
7966bf14cc34
child 249
3c28dc8dd51d
equal deleted inserted replaced
247:a789ceedfe0c 248:1a7a5dffba58
18 #include "EditProduct.h" 18 #include "EditProduct.h"
19 #include "PrinterDialog.h" 19 #include "PrinterDialog.h"
20 #include "../ui/ui_EditProduct.h" 20 #include "../ui/ui_EditProduct.h"
21 #include "Utils.h" 21 #include "Utils.h"
22 #include "global.h" 22 #include "global.h"
23 23 #include "database/db_product.h"
24 24
25 25
26 EditProduct::EditProduct(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditProduct) 26 EditProduct::EditProduct(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditProduct)
27 { 27 {
28 QSqlQuery query, wquery, yquery; 28 QSqlQuery query, wquery, yquery;
107 ui->bottle_sugarEdit->addItem(query.value(0).toString()); 107 ui->bottle_sugarEdit->addItem(query.value(0).toString());
108 ui->keg_sugarEdit->addItem(query.value(0).toString()); 108 ui->keg_sugarEdit->addItem(query.value(0).toString());
109 } 109 }
110 110
111 if (id >= 0) { 111 if (id >= 0) {
112 query.prepare("SELECT * FROM products WHERE record = :recno"); 112 if (! DB_product::load(product, this, id))
113 query.bindValue(":recno", id);
114 query.exec();
115 if (! query.first()) {
116 qDebug() << "EditProduct seek error record" << id;
117 QMessageBox::warning(this, tr("Database error"), tr("MySQL error: record %1 not found").arg(id));
118 this->done(QDialog::Rejected); // At this stage, this doesn't work because the dialog is not yet visible.
119 return; 113 return;
120 }
121
122 QSqlRecord rec = query.record();
123 for (int i = 0; i < rec.count(); i++)
124 qDebug() << i << rec.fieldName(i) << query.value(i);
125
126 product->record = query.value("record").toInt();
127 product->uuid = query.value("uuid").toString();
128 product->name = query.value("name").toString();
129 product->code = query.value("code").toString();
130 product->birth = query.value("birth").toDate();
131 product->stage = query.value("stage").toInt();
132 product->notes = query.value("notes").toString();
133 product->log_brew = query.value("log_brew").toInt() ? true:false;
134 product->log_fermentation = query.value("log_fermentation").toInt() ? true:false;
135 product->log_ispindel = query.value("log_ispindel").toInt() ? true:false;
136 product->log_co2pressure = query.value("log_co2pressure").toInt() ? true:false;
137 product->inventory_reduced = query.value("inventory_reduced").toInt();
138 product->locked = query.value("locked").toInt() ? true:false;
139
140 product->eq_name = query.value("eq_name").toString();
141 product->eq_notes = query.value("eq_notes").toString();
142 product->eq_boil_size = query.value("eq_boil_size").toDouble();
143 product->eq_batch_size = query.value("eq_batch_size").toDouble();
144 product->eq_tun_volume = query.value("eq_tun_volume").toDouble();
145 product->eq_tun_weight = query.value("eq_tun_weight").toDouble();
146 product->eq_tun_specific_heat = query.value("eq_tun_specific_heat").toDouble();
147 product->eq_tun_material = query.value("eq_tun_material").toInt();
148 product->eq_tun_height = query.value("eq_tun_height").toDouble();
149 product->eq_top_up_water = query.value("eq_top_up_water").toDouble();
150 product->eq_trub_chiller_loss = query.value("eq_trub_chiller_loss").toDouble();
151 product->eq_evap_rate = query.value("eq_evap_rate").toDouble();
152 product->eq_boil_time = query.value("eq_boil_time").toDouble();
153 product->eq_calc_boil_volume = query.value("eq_calc_boil_volume").toInt() ? true:false;
154 product->eq_top_up_kettle = query.value("eq_top_up_kettle").toDouble();
155 product->eq_hop_utilization = query.value("eq_hop_utilization").toDouble();
156 product->eq_lauter_volume = query.value("eq_lauter_volume").toDouble();
157 product->eq_lauter_height = query.value("eq_lauter_height").toDouble();
158 product->eq_lauter_deadspace = query.value("eq_lauter_deadspace").toDouble();
159 product->eq_kettle_volume = query.value("eq_kettle_volume").toDouble();
160 product->eq_kettle_height = query.value("eq_kettle_height").toDouble();
161 product->eq_mash_volume = query.value("eq_mash_volume").toDouble();
162 product->eq_mash_max = query.value("eq_mash_max").toDouble();
163 product->eq_efficiency = query.value("eq_efficiency").toDouble();
164
165 product->brew_date_start = query.value("brew_date_start").toDateTime();
166 product->brew_mash_ph = query.value("brew_mash_ph").toDouble();
167 product->brew_mash_sg = query.value("brew_mash_sg").toDouble();
168 product->brew_mash_efficiency = query.value("brew_mash_efficiency").toDouble();
169 product->brew_sparge_temperature = query.value("brew_sparge_temperature").toDouble();
170 product->brew_sparge_volume = query.value("brew_sparge_volume").toDouble();
171 product->brew_sparge_est = query.value("brew_sparge_est").toDouble();
172 product->brew_sparge_ph = query.value("brew_sparge_ph").toDouble();
173 product->brew_preboil_volume = query.value("brew_preboil_volume").toDouble();
174 product->brew_preboil_sg = query.value("brew_preboil_sg").toDouble();
175 product->brew_preboil_ph = query.value("brew_preboil_ph").toDouble();
176 product->brew_preboil_efficiency = query.value("brew_preboil_efficiency").toDouble();
177 product->brew_aboil_volume = query.value("brew_aboil_volume").toDouble();
178 product->brew_aboil_sg = query.value("brew_aboil_sg").toDouble();
179 product->brew_aboil_ph = query.value("brew_aboil_ph").toDouble();
180 product->brew_aboil_efficiency = query.value("brew_aboil_efficiency").toDouble();
181 product->brew_cooling_method = query.value("brew_cooling_method").toInt();
182 product->brew_cooling_time = query.value("brew_cooling_time").toDouble();
183 product->brew_cooling_to = query.value("brew_cooling_to").toDouble();
184 product->brew_whirlpool9 = query.value("brew_whirlpool9").toDouble();
185 product->brew_whirlpool7 = query.value("brew_whirlpool7").toDouble();
186 product->brew_whirlpool6 = query.value("brew_whirlpool6").toDouble();
187 product->brew_whirlpool2 = query.value("brew_whirlpool2").toDouble();
188 product->brew_fermenter_volume = query.value("brew_fermenter_volume").toDouble();
189 product->brew_fermenter_extrawater = query.value("brew_fermenter_extrawater").toDouble();
190 product->brew_fermenter_tcloss = query.value("brew_fermenter_tcloss").toDouble();
191 product->brew_aeration_time = query.value("brew_aeration_time").toDouble();
192 product->brew_aeration_speed = query.value("brew_aeration_speed").toDouble();
193 product->brew_aeration_type = query.value("brew_aeration_type").toInt();
194 product->brew_fermenter_sg = query.value("brew_fermenter_sg").toDouble();
195 product->brew_fermenter_ibu = query.value("brew_fermenter_ibu").toDouble();
196 product->brew_fermenter_color = query.value("brew_fermenter_color").toDouble();
197 product->brew_date_end = query.value("brew_date_end").toDateTime();
198
199 product->og = query.value("og").toDouble();
200 product->fg = query.value("fg").toDouble();
201 product->primary_start_temp = query.value("primary_start_temp").toDouble();
202 product->primary_max_temp = query.value("primary_max_temp").toDouble();
203 product->primary_end_temp = query.value("primary_end_temp").toDouble();
204 product->primary_end_sg = query.value("primary_end_sg").toDouble();
205 product->primary_end_date = query.value("primary_end_date").toDate();
206 product->secondary_temp = query.value("secondary_temp").toDouble();
207 product->secondary_end_sg = query.value("secondary_end_sg").toDouble();
208 product->secondary_end_date = query.value("secondary_end_date").toDate();
209 product->tertiary_temp = query.value("tertiary_temp").toDouble();
210
211 product->package_date = query.value("package_date").toDate();
212 product->package_volume = query.value("package_volume").toDouble();
213 product->package_infuse_amount = query.value("package_infuse_amount").toDouble();
214 product->package_infuse_abv = query.value("package_infuse_abv").toDouble();
215 product->package_infuse_notes = query.value("package_infuse_notes").toString();
216 product->package_abv = query.value("package_abv").toDouble();
217 product->package_ph = query.value("package_ph").toDouble();
218
219 product->bottle_amount = query.value("bottle_amount").toDouble();
220 product->bottle_carbonation = query.value("bottle_carbonation").toDouble();
221 product->bottle_priming_sugar = query.value("bottle_priming_sugar").toInt();
222 product->bottle_priming_amount = query.value("bottle_priming_amount").toDouble();
223 product->bottle_priming_water = query.value("bottle_priming_water").toDouble();
224 product->bottle_carbonation_temp = query.value("bottle_carbonation_temp").toDouble();
225
226 product->keg_amount = query.value("keg_amount").toDouble();
227 product->keg_carbonation = query.value("keg_carbonation").toDouble();
228 product->keg_priming_sugar = query.value("keg_priming_sugar").toInt();
229 product->keg_priming_amount = query.value("keg_priming_amount").toDouble();
230 product->keg_priming_water = query.value("keg_priming_water").toDouble();
231 product->keg_carbonation_temp = query.value("keg_carbonation_temp").toDouble();
232 product->keg_forced_carb = query.value("keg_forced_carb").toInt() ? true:false;
233 product->keg_pressure = query.value("keg_pressure").toDouble();
234
235 product->taste_notes = query.value("taste_notes").toString();
236 product->taste_rate = query.value("taste_rate").toDouble();
237 product->taste_date = query.value("taste_date").toDate();
238 product->taste_color = query.value("taste_color").toString();
239 product->taste_transparency = query.value("taste_transparency").toString();
240 product->taste_head = query.value("taste_head").toString();
241 product->taste_aroma = query.value("taste_aroma").toString();
242 product->taste_taste = query.value("taste_taste").toString();
243 product->taste_mouthfeel = query.value("taste_mouthfeel").toString();
244 product->taste_aftertaste = query.value("taste_aftertaste").toString();
245
246 product->st_name = query.value("st_name").toString();
247 product->st_letter = query.value("st_letter").toString();
248 product->st_guide = query.value("st_guide").toString();
249 product->st_category = query.value("st_category").toString();
250 product->st_category_number = query.value("st_category_number").toInt();
251 product->st_type = query.value("st_type").toInt();
252 product->st_og_min = query.value("st_og_min").toDouble();
253 product->st_og_max = query.value("st_og_max").toDouble();
254 product->st_fg_min = query.value("st_fg_min").toDouble();
255 product->st_fg_max = query.value("st_fg_max").toDouble();
256 product->st_ibu_min = query.value("st_ibu_min").toDouble();
257 product->st_ibu_max = query.value("st_ibu_max").toDouble();
258 product->st_color_min = query.value("st_color_min").toDouble();
259 product->st_color_max = query.value("st_color_max").toDouble();
260 product->st_carb_min = query.value("st_carb_min").toDouble();
261 product->st_carb_max = query.value("st_carb_max").toDouble();
262 product->st_abv_min = query.value("st_abv_min").toDouble();
263 product->st_abv_max = query.value("st_abv_max").toDouble();
264
265 product->type = query.value("type").toInt();
266 product->batch_size = query.value("batch_size").toDouble();
267 product->boil_size = query.value("boil_size").toDouble();
268 product->boil_time = query.value("boil_time").toDouble();
269 product->efficiency = query.value("efficiency").toDouble();
270 product->est_og = query.value("est_og").toDouble();
271 product->est_og3 = query.value("est_og3").toDouble();
272 product->est_fg = query.value("est_fg").toDouble();
273 product->est_abv = query.value("est_abv").toDouble();
274 product->est_color = query.value("est_color").toDouble();
275 product->color_method = query.value("color_method").toInt();
276 product->est_ibu = query.value("est_ibu").toDouble();
277 product->ibu_method = query.value("ibu_method").toInt();
278 product->est_carb = query.value("est_carb").toDouble();
279
280 product->sparge_temp = query.value("sparge_temp").toDouble();
281 product->sparge_ph = query.value("sparge_ph").toDouble();
282 product->sparge_volume = query.value("sparge_volume").toDouble();
283 product->sparge_source = query.value("sparge_source").toInt();
284 product->sparge_acid_type = query.value("sparge_acid_type").toInt();
285 product->sparge_acid_perc = query.value("sparge_acid_perc").toDouble();
286 product->sparge_acid_amount = query.value("sparge_acid_amount").toDouble();
287 product->mash_ph = query.value("mash_ph").toDouble();
288 product->mash_name = query.value("mash_name").toString();
289 product->calc_acid = query.value("calc_acid").toInt() ? true:false;
290
291 product->w1_name = query.value("w1_name").toString();
292 product->w1_amount = query.value("w1_amount").toDouble();
293 product->w1_calcium = query.value("w1_calcium").toDouble();
294 product->w1_sulfate = query.value("w1_sulfate").toDouble();
295 product->w1_chloride = query.value("w1_chloride").toDouble();
296 product->w1_sodium = query.value("w1_sodium").toDouble();
297 product->w1_magnesium = query.value("w1_magnesium").toDouble();
298 product->w1_total_alkalinity = query.value("w1_total_alkalinity").toDouble();
299 product->w1_ph = query.value("w1_ph").toDouble();
300 product->w1_cost = query.value("w1_cost").toDouble();
301 product->w2_name = query.value("w2_name").toString();
302 product->w2_amount = query.value("w2_amount").toDouble();
303 product->w2_calcium = query.value("w2_calcium").toDouble();
304 product->w2_sulfate = query.value("w2_sulfate").toDouble();
305 product->w2_chloride = query.value("w2_chloride").toDouble();
306 product->w2_sodium = query.value("w2_sodium").toDouble();
307 product->w2_magnesium = query.value("w2_magnesium").toDouble();
308 product->w2_total_alkalinity = query.value("w2_total_alkalinity").toDouble();
309 product->w2_ph = query.value("w2_ph").toDouble();
310 product->w2_cost = query.value("w2_cost").toDouble();
311 product->wg_amount = query.value("wg_amount").toDouble();
312 product->wg_calcium = query.value("wg_calcium").toDouble();
313 product->wg_sulfate = query.value("wg_sulfate").toDouble();
314 product->wg_chloride = query.value("wg_chloride").toDouble();
315 product->wg_sodium = query.value("wg_sodium").toDouble();
316 product->wg_magnesium = query.value("wg_magnesium").toDouble();
317 product->wg_total_alkalinity = query.value("wg_total_alkalinity").toDouble();
318 product->wg_ph = query.value("wg_ph").toDouble();
319 product->wb_calcium = query.value("wb_calcium").toDouble();
320 product->wb_sulfate = query.value("wb_sulfate").toDouble();
321 product->wb_chloride = query.value("wb_chloride").toDouble();
322 product->wb_sodium = query.value("wb_sodium").toDouble();
323 product->wb_magnesium = query.value("wb_magnesium").toDouble();
324 product->wb_total_alkalinity = query.value("wb_total_alkalinity").toDouble();
325 product->wb_ph = query.value("wb_ph").toDouble();
326 product->wa_acid_name = query.value("wa_acid_name").toInt();
327 product->wa_acid_perc = query.value("wa_acid_perc").toDouble();
328 product->wa_base_name = query.value("wa_base_name").toInt();
329
330 product->starter_enable = query.value("starter_enable").toInt() ? true:false;
331 product->starter_type = query.value("starter_type").toInt();
332 product->starter_sg = query.value("starter_sg").toDouble();
333 product->starter_viability = query.value("starter_viability").toInt();
334 if (query.value("yeast_prod_date").toString().length() == 10)
335 product->yeast_prod_date = query.value("yeast_prod_date").toDate();
336 else
337 product->yeast_prod_date = QDate();
338 product->yeast_pitchrate = query.value("yeast_pitchrate").toDouble();
339 product->prop_type[0] = query.value("prop1_type").toInt();
340 product->prop_volume[0] = query.value("prop1_volume").toDouble();
341 product->prop_type[1] = query.value("prop2_type").toInt();
342 product->prop_volume[1] = query.value("prop2_volume").toDouble();
343 product->prop_type[2] = query.value("prop3_type").toInt();
344 product->prop_volume[2] = query.value("prop3_volume").toDouble();
345 product->prop_type[3] = query.value("prop4_type").toInt();
346 product->prop_volume[3] = query.value("prop4_volume").toDouble();
347
348 product->divide_type = query.value("divide_type").toInt();
349 product->divide_size = query.value("divide_size").toDouble();
350 product->divide_factor = query.value("divide_factor").toDouble();
351 product->divide_parts = query.value("divide_parts").toInt();
352 product->divide_part = query.value("divide_part").toInt();
353
354 QJsonParseError parseError;
355 const auto& f_json = query.value("json_fermentables").toString();
356 if (!f_json.trimmed().isEmpty()) {
357 const auto& formattedJson = QString("%1").arg(f_json);
358 QJsonDocument fermentables = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
359 if (parseError.error != QJsonParseError::NoError) {
360 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
361 } else if (fermentables.isArray()) {
362 double percentcheck = 0;
363 for (int i = 0; i < fermentables.array().size(); i++) {
364 QJsonObject obj = fermentables.array().at(i).toObject();
365 //qDebug() << i << obj;
366 Fermentables f;
367 f.f_inventory = 0;
368 f.f_avail = false;
369 f.f_name = obj["f_name"].toString();
370 f.f_origin = obj["f_origin"].toString();
371 f.f_supplier = obj["f_supplier"].toString();
372 f.f_amount = obj["f_amount"].toDouble();
373 f.f_cost = obj["f_cost"].toDouble();
374 f.f_type = obj["f_type"].toInt();
375 f.f_yield = obj["f_yield"].toDouble();
376 f.f_color = obj["f_color"].toDouble();
377 f.f_coarse_fine_diff = obj["f_coarse_fine_diff"].toDouble();
378 f.f_moisture = obj["f_moisture"].toDouble();
379 f.f_diastatic_power = obj["f_diastatic_power"].toDouble();
380 f.f_protein = obj["f_protein"].toDouble();
381 f.f_dissolved_protein = obj["f_dissolved_protein"].toDouble();
382 f.f_max_in_batch = obj["f_max_in_batch"].toDouble();
383 f.f_graintype = obj["f_graintype"].toInt();
384 f.f_added = obj["f_added"].toInt();
385 f.f_recommend_mash = obj["f_recommend_mash"].toInt() ? true:false;
386 f.f_add_after_boil = obj["f_add_after_boil"].toInt() ? true:false;
387 f.f_adjust_to_total_100 = obj["f_adjust_to_total_100"].toInt() ? true:false;
388 f.f_percentage = obj["f_percentage"].toDouble();
389 f.f_di_ph = obj["f_di_ph"].toDouble();
390 f.f_acid_to_ph_57 = obj["f_acid_to_ph_57"].toDouble();
391 if (f.f_adjust_to_total_100)
392 product->fermentables_use100 = true;
393 percentcheck += f.f_percentage;
394 /* Check and update inventory */
395 yquery.prepare("SELECT inventory FROM inventory_fermentables WHERE name=:name AND supplier=:supplier AND origin=:origin");
396 yquery.bindValue(":name", f.f_name);
397 yquery.bindValue(":supplier", f.f_supplier);
398 yquery.bindValue(":origin", f.f_origin);
399 yquery.exec();
400 if (yquery.first()) {
401 f.f_avail = true;
402 f.f_inventory = yquery.value(0).toDouble();
403 }
404 product->fermentables.append(f);
405 }
406 qDebug() << "fermentables" << product->fermentables.size() << percentcheck;
407 if (percentcheck == 0 && product->fermentables.size()) {
408 /* Missing percentages, fix it. */
409 double total = 0;
410 for (int i = 0; i < product->fermentables.size(); i++) {
411 if (product->fermentables.at(i).f_added < 4)
412 total += product->fermentables.at(i).f_amount;
413 }
414 for (int i = 0; i < product->fermentables.size(); i++) {
415 if (product->fermentables.at(i).f_added < 4)
416 product->fermentables[i].f_percentage = round((product->fermentables.at(i).f_amount / total) * 10000.0) / 100.0;
417 }
418 qDebug() << " fixed missing percentages";
419 is_changed();
420 }
421 }
422 } else {
423 qDebug() << "empty fermentables";
424 }
425
426 const auto& h_json = query.value("json_hops").toString();
427 if (!h_json.trimmed().isEmpty()) {
428 const auto& formattedJson = QString("%1").arg(h_json);
429 QJsonDocument hops = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
430 if (parseError.error != QJsonParseError::NoError) {
431 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset;
432 } else if (hops.isArray()) {
433 for (int i = 0; i < hops.array().size(); i++) {
434 QJsonObject obj = hops.array().at(i).toObject();
435 //qDebug() << i << obj;
436 Hops h;
437 h.h_avail = false;
438 h.h_inventory = 0;
439 h.h_name = obj["h_name"].toString();
440 h.h_origin = obj["h_origin"].toString();
441 h.h_amount = obj["h_amount"].toDouble();
442 h.h_cost = obj["h_cost"].toDouble();
443 h.h_type = obj["h_type"].toInt();
444 h.h_form = obj["h_form"].toInt();
445 h.h_useat = obj["h_useat"].toInt();
446 h.h_time = obj["h_time"].toInt();
447 h.h_alpha = obj["h_alpha"].toDouble();
448 h.h_beta = obj["h_beta"].toDouble();
449 h.h_hsi = obj["h_hsi"].toDouble();
450 h.h_humulene = obj["h_humulene"].toDouble();
451 h.h_caryophyllene = obj["h_caryophyllene"].toDouble();
452 h.h_cohumulone = obj["h_cohumulone"].toDouble();
453 h.h_myrcene = obj["h_myrcene"].toDouble();
454 h.h_total_oil = obj["h_total_oil"].toDouble();
455 /* Check and update inventory */
456 yquery.prepare("SELECT inventory FROM inventory_hops WHERE name=:name AND origin=:origin");
457 yquery.bindValue(":name", h.h_name);
458 yquery.bindValue(":origin", h.h_origin);
459 yquery.exec();
460 if (yquery.first()) {
461 h.h_avail = true;
462 h.h_inventory = yquery.value(0).toDouble();
463 }
464 product->hops.append(h);
465 }
466 qDebug() << "hops" << product->hops.size();
467 }
468 } else {
469 qDebug() << "empty hops";
470 }
471
472 const auto& m_json = query.value("json_miscs").toString();
473 if (!m_json.trimmed().isEmpty()) {
474 const auto& formattedJson = QString("%1").arg(m_json);
475 QJsonDocument miscs = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
476 if (parseError.error != QJsonParseError::NoError) {
477 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset;
478 } else if (miscs.isArray()) {
479 for (int i = 0; i < miscs.array().size(); i++) {
480 QJsonObject obj = miscs.array().at(i).toObject();
481 //qDebug() << i << obj;
482 Miscs m;
483 m.m_avail = false;
484 m.m_inventory = 0;
485 m.m_name = obj["m_name"].toString();
486 m.m_amount = obj["m_amount"].toDouble();
487 m.m_type = obj["m_type"].toInt();
488 m.m_use_use = obj["m_use_use"].toInt();
489 m.m_time = obj["m_time"].toDouble();
490 m.m_amount_is_weight = obj["m_amount_is_weight"].toInt() ? true:false;
491 m.m_cost = obj["m_cost"].toDouble();
492 /* Check and update inventory */
493 yquery.prepare("SELECT inventory FROM inventory_miscs WHERE name=:name");
494 yquery.bindValue(":name", m.m_name);
495 yquery.exec();
496 if (yquery.first()) {
497 m.m_avail = true;
498 m.m_inventory = yquery.value(0).toDouble();
499 }
500 product->miscs.append(m);
501 }
502 qDebug() << "miscs" << product->miscs.size();
503 }
504 } else {
505 qDebug() << "empty miscs";
506 }
507
508 const auto& y_json = query.value("json_yeasts").toString();
509 if (!y_json.trimmed().isEmpty()) {
510 const auto& formattedJson = QString("%1").arg(y_json);
511 QJsonDocument yeasts = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
512 if (parseError.error != QJsonParseError::NoError) {
513 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
514 } else if (yeasts.isArray()) {
515 for (int i = 0; i < yeasts.array().size(); i++) {
516 QJsonObject obj = yeasts.array().at(i).toObject();
517 //qDebug() << i << obj;
518 Yeasts y;
519 /* First some defaults for newer fields. */
520 y.y_tolerance = y.y_harvest_time = y.y_pitch_temperature = y.y_zymocide = 0;
521 y.y_avail = y.y_sta1 = y.y_bacteria = y.y_harvest_top = y.y_pofpos = false;
522 y.y_gr_hl_lo = 50;
523 y.y_sg_lo = 1.04;
524 y.y_gr_hl_hi = 80;
525 y.y_sg_hi = 1.08;
526 /* Now get what we have got */
527 y.y_name = obj["y_name"].toString();
528 y.y_laboratory = obj["y_laboratory"].toString();
529 y.y_product_id = obj["y_product_id"].toString();
530 y.y_amount = obj["y_amount"].toDouble();
531 y.y_type = obj["y_type"].toInt();
532 y.y_form = obj["y_form"].toInt();
533 y.y_min_temperature = obj["y_min_temperature"].toDouble();
534 y.y_max_temperature = obj["y_max_temperature"].toDouble();
535 y.y_flocculation = obj["y_flocculation"].toInt();
536 y.y_attenuation = obj["y_attenuation"].toDouble();
537 y.y_cells = obj["y_cells"].toDouble();
538 y.y_tolerance = obj["y_tolerance"].toDouble();
539 y.y_inventory = obj["y_inventory"].toDouble();
540 y.y_use = obj["y_use"].toInt();
541 y.y_sta1 = obj["y_sta1"].toInt() ? true:false;
542 y.y_bacteria = obj["y_bacteria"].toInt() ? true:false;
543 y.y_harvest_top = obj["y_harvest_top"].toInt() ? true:false;
544 y.y_harvest_time = obj["y_harvest_time"].toInt();
545 y.y_pitch_temperature = obj["y_pitch_temperature"].toDouble();
546 y.y_pofpos = obj["y_pofpos"].toInt() ? true:false;
547 y.y_zymocide = obj["y_zymocide"].toInt();
548 y.y_gr_hl_lo = obj["y_gr_hl_lo"].toInt();
549 y.y_sg_lo = obj["y_sg_lo"].toDouble();
550 y.y_gr_hl_hi = obj["y_gr_hl_hi"].toInt();
551 y.y_sg_hi = obj["y_sg_hi"].toDouble();
552 y.y_cost = obj["y_cost"].toDouble();
553 /*
554 * Possible data upgrade needed.
555 */
556 yquery.prepare("SELECT tolerance,cells,sta1,bacteria,harvest_top,harvest_time,pitch_temperature,"
557 "pofpos,zymocide,gr_hl_lo,sg_lo,gr_hl_hi,sg_hi,inventory "
558 "FROM inventory_yeasts WHERE name=:name AND laboratory=:laboratory AND product_id=:product_id");
559 yquery.bindValue(":name", y.y_name);
560 yquery.bindValue(":laboratory", y.y_laboratory);
561 yquery.bindValue(":product_id", y.y_product_id);
562 yquery.exec();
563 if (yquery.first()) {
564 if (y.y_tolerance == 0 || y.y_cells == 0) {
565 y.y_tolerance = yquery.value(0).toDouble();
566 y.y_cells = yquery.value(1).toDouble();
567 }
568 y.y_sta1 = yquery.value(2).toInt() ? true:false;
569 y.y_bacteria = yquery.value(3).toInt() ? true:false;
570 y.y_harvest_top = yquery.value(4).toInt() ? true:false;
571 y.y_harvest_time = yquery.value(5).toInt();
572 y.y_pitch_temperature = yquery.value(6).toDouble();
573 y.y_pofpos = yquery.value(7).toInt() ? true:false;
574 y.y_zymocide = yquery.value(8).toInt();
575 y.y_gr_hl_lo = yquery.value(9).toInt();
576 y.y_sg_lo = yquery.value(10).toDouble();
577 y.y_gr_hl_hi = yquery.value(11).toInt();
578 y.y_sg_hi = yquery.value(12).toDouble();
579 y.y_inventory = yquery.value(13).toDouble();
580 y.y_avail = true;
581 } else {
582 qDebug() << y.y_name << y.y_product_id << "not found for upgrade";
583 }
584 product->yeasts.append(y);
585 }
586 qDebug() << "yeasts" << product->yeasts.size();
587 }
588 } else {
589 qDebug() << "empty yeasts";
590 }
591
592 const auto& ma_json = query.value("json_mashs").toString().trimmed();
593 if (!ma_json.trimmed().isEmpty()) {
594 const auto& formattedJson = QString("%1").arg(ma_json);
595 QJsonDocument mashs = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
596 if (parseError.error != QJsonParseError::NoError) {
597 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
598 } else if (mashs.isArray()) {
599 for (int i = 0; i < mashs.array().size(); i++) {
600 QJsonObject obj = mashs.array().at(i).toObject();
601 qDebug() << i << obj;
602 Mashs m;
603 m.step_name = obj["step_name"].toString();
604 m.step_type = obj["step_type"].toInt();
605 m.step_volume = obj["step_volume"].toDouble();
606 m.step_infuse_amount = obj["step_infuse_amount"].toDouble();
607 m.step_infuse_temp = obj["step_infuse_temp"].toDouble();
608 m.step_temp = obj["step_temp"].toDouble();
609 m.step_time = obj["step_time"].toDouble();
610 m.ramp_time = obj["ramp_time"].toDouble();
611 m.end_temp = obj["end_temp"].toDouble();
612 m.step_wg_ratio = obj["step_wg_ratio"].toDouble();
613 m.step_ph = obj["step_ph"].toDouble();
614 m.step_sg = obj["step_sg"].toDouble();
615 product->mashs.append(m);
616 }
617 }
618 } else {
619 qDebug() << "empty mashs";
620 }
621 qDebug() << "mashs" << product->mashs.size();
622 114
623 } else { 115 } else {
624 /* New product, set some defaults */ 116 /* New product, set some defaults */
117 product->record = -1;
625 product->locked = product->log_brew = product->log_fermentation = product->log_ispindel = product->log_co2pressure = false; 118 product->locked = product->log_brew = product->log_fermentation = product->log_ispindel = product->log_co2pressure = false;
626 product->st_name = ""; 119 product->st_name = "";
627 product->st_letter = ""; 120 product->st_letter = "";
628 product->st_guide = ""; 121 product->st_guide = "";
629 product->st_category = ""; 122 product->st_category = "";
1259 } 752 }
1260 753
1261 754
1262 void EditProduct::on_saveButton_clicked() 755 void EditProduct::on_saveButton_clicked()
1263 { 756 {
1264 QSqlQuery query; 757 /*
1265 758 * If there are errors in the form, show a message and do "return;"
1266 /* If there are errors in the form, show a message and do "return;" */ 759 */
1267 if (ui->nameEdit->text().length() < 2) { 760 if (ui->nameEdit->text().length() < 2) {
1268 QMessageBox::warning(this, tr("Edit Product"), tr("Name empty or too short.")); 761 QMessageBox::warning(this, tr("Edit Product"), tr("Name empty or too short."));
1269 return; 762 return;
1270 } 763 }
1271 if (ui->st_nameEdit->text().length() < 2) { 764 if (ui->st_nameEdit->text().length() < 2) {
1272 QMessageBox::warning(this, tr("Edit Product"), tr("No beerstyle selected.")); 765 QMessageBox::warning(this, tr("Edit Product"), tr("No beerstyle selected."));
1273 return; 766 return;
1274 } 767 }
1275 768
1276 if (this->textIsChanged) { 769 if (this->textIsChanged) {
1277 if (this->recno == -1) { 770 product->record = this->recno;
1278 query.prepare("INSERT INTO products SET " 771 if (DB_product::save(product, this)) {
1279 "name=:name, code=:code, birth=:birth, stage=:stage, notes=:notes, log_brew=:log_brew, "
1280 "log_fermentation=:log_fermentation, log_ispindel=:log_ispindel, log_co2pressure=:log_co2pressure, "
1281 "inventory_reduced=:inventory_reduced, locked=:locked, "
1282 "eq_name=:eq_name, eq_boil_size=:eq_boil_size, eq_efficiency=:eq_efficiency, "
1283 "eq_batch_size=:eq_batch_size, eq_tun_volume=:eq_tun_volume, eq_tun_weight=:eq_tun_weight, "
1284 "eq_tun_specific_heat=:eq_tun_specific_heat, eq_tun_material=:eq_tun_material, eq_tun_height=:eq_tun_height, "
1285 "eq_top_up_water=:eq_top_up_water, eq_trub_chiller_loss=:eq_chiller_loss, eq_evap_rate=:eq_evap_rate, "
1286 "eq_boil_time=:eq_boil_time, eq_calc_boil_volume=:eq_calcboil, eq_top_up_kettle=:eq_top_up_kettle, "
1287 "eq_hop_utilization=:eq_hopfactor, eq_notes=:eq_notes, eq_lauter_volume=:eq_lauter_volume, "
1288 "eq_lauter_height=:eq_lauter_height, eq_lauter_deadspace=:eq_lauter_deadspace, eq_kettle_volume=:eq_kettle_volume, "
1289 "eq_kettle_height=:eq_kettle_height, eq_mash_volume=:eq_mash_volume, eq_mash_max=:eq_mash_max, "
1290 "brew_date_start=:brew_date_start, brew_mash_ph=:brew_mash_ph, brew_mash_sg=:brew_mash_sg, "
1291 "brew_mash_efficiency=:brew_mash_efficiency, brew_sparge_temperature=:brew_sparge_temperature, "
1292 "brew_sparge_volume=:brew_sparge_volume, brew_sparge_est=:brew_sparge_est, brew_sparge_ph=:brew_sparge_ph, "
1293 "brew_preboil_volume=:brew_preboil_volume, brew_preboil_sg=:brew_preboil_sg, brew_preboil_ph=:brew_preboil_ph, "
1294 "brew_preboil_efficiency=:brew_preboil_efficiency, brew_aboil_volume=:brew_aboil_volume, "
1295 "brew_aboil_sg=:brew_aboil_sg, brew_aboil_ph=:brew_aboil_ph, brew_aboil_efficiency=:brew_aboil_efficiency, "
1296 "brew_cooling_method=:brew_cooling_method, brew_cooling_time=:brew_cooling_time, brew_cooling_to=:brew_cooling_to, "
1297 "brew_whirlpool9=:brew_whirlpool9, brew_whirlpool7=:brew_whirlpool7, brew_whirlpool6=:brew_whirlpool6, "
1298 "brew_whirlpool2=:brew_whirlpool2, brew_fermenter_volume=:brew_fermenter_volume, "
1299 "brew_fermenter_extrawater=:brew_fermenter_extrawater, brew_fermenter_tcloss=:brew_fermenter_tcloss, "
1300 "brew_aeration_time=:brew_aeration_time, brew_aeration_speed=:brew_aeration_speed, "
1301 "brew_aeration_type=:brew_aeration_type, brew_fermenter_sg=:brew_fermenter_sg, brew_fermenter_ibu=:brew_fermenter_ibu, "
1302 "brew_fermenter_color=:brew_fermenter_color, brew_date_end=:brew_date_end, "
1303 "og=:og, fg=:fg, primary_start_temp=:primary_start_temp, primary_max_temp=:primary_max_temp, "
1304 "primary_end_temp=:primary_end_temp, primary_end_sg=:primary_end_sg, primary_end_date=:primary_end_date, "
1305 "secondary_temp=:secondary_temp, secondary_end_sg=:secondary_end_sg, secondary_end_date=:secondary_end_date, "
1306 "tertiary_temp=:tertiary_temp, package_date=:package_date, package_volume=:package_volume, "
1307 "package_infuse_amount=:package_infuse_amount, package_infuse_abv=:package_infuse_abv, "
1308 "package_infuse_notes=:package_infuse_notes, package_abv=:package_abv, package_ph=:package_ph, "
1309 "bottle_amount=:bottle_amount, bottle_carbonation=:bottle_carbonation, bottle_priming_sugar=:bottle_priming_sugar, "
1310 "bottle_priming_amount=:bottle_priming_amount, bottle_priming_water=:bottle_priming_water, "
1311 "bottle_carbonation_temp=:bottle_carbonation_temp, keg_amount=:keg_amount, keg_carbonation=:keg_carbonation, "
1312 "keg_priming_sugar=:keg_priming_sugar, keg_priming_amount=:keg_priming_amount, keg_priming_water=:keg_priming_water, "
1313 "keg_carbonation_temp=:keg_carbonation_temp, keg_forced_carb=:keg_forced_carb, keg_pressure=:keg_pressure, "
1314 "taste_notes=:taste_notes, taste_rate=:taste_rate, taste_date=:taste_date, taste_color=:taste_color, "
1315 "taste_transparency=:taste_transparency, taste_head=:taste_head, taste_aroma=:taste_aroma, "
1316 "taste_taste=:taste_taste, taste_mouthfeel=:taste_mouthfeel, taste_aftertaste=:taste_aftertaste, "
1317 "st_name=:st_name, st_letter=:st_letter, "
1318 "st_guide=:st_guide, st_category=:st_category, st_category_number=:st_catnr, st_type=:st_type, "
1319 "st_og_min=:st_og_min, st_og_max=:st_og_max, st_fg_min=:st_fg_min, st_fg_max=:st_fg_max, "
1320 "st_ibu_min=:st_ibu_min, st_ibu_max=:st_ibu_max, st_color_min=:st_color_min, st_color_max=:st_color_max, "
1321 "st_carb_min=:st_carb_min, st_carb_max=:st_carb_max, st_abv_min=:st_abv_min, st_abv_max=:st_abv_max, "
1322 "type=:type, batch_size=:batch_size, boil_size=:boil_size, "
1323 "boil_time=:boil_time, efficiency=:efficiency, est_og=:est_og, est_og3=:est_og3, est_fg=:est_fg, est_abv=:est_abv, "
1324 "est_color=:est_color, color_method=:color_method, est_ibu=:est_ibu, ibu_method=:ibu_method, "
1325 "est_carb=:est_carb, sparge_temp=:sparge_temp, sparge_ph=:sparge_ph, "
1326 "sparge_volume=:sparge_volume, sparge_source=:sparge_source, sparge_acid_type=:sparge_acid_type, "
1327 "sparge_acid_perc=:sparge_acid_perc, sparge_acid_amount=:sparge_acid_amount, mash_ph=:mash_ph, "
1328 "mash_name=:mash_name, calc_acid=:calc_acid, "
1329 "w1_name=:w1_name, w1_amount=:w1_amount, w1_calcium=:w1_calcium, w1_sulfate=:w1_sulfate, "
1330 "w1_chloride=:w1_chloride, w1_sodium=:w1_sodium, w1_magnesium=:w1_magnesium, "
1331 "w1_total_alkalinity=:w1_total_alkalinity, w1_ph=:w1_ph, w1_cost=:w1_cost, "
1332 "w2_name=:w2_name, w2_amount=:w2_amount, w2_calcium=:w2_calcium, w2_sulfate=:w2_sulfate, "
1333 "w2_chloride=:w2_chloride, w2_sodium=:w2_sodium, w2_magnesium=:w2_magnesium, "
1334 "w2_total_alkalinity=:w2_total_alkalinity, w2_ph=:w2_ph, w2_cost=:w2_cost, "
1335 "wg_amount=:wg_amount, wg_calcium=:wg_calcium, wg_sulfate=:wg_sulfate, "
1336 "wg_chloride=:wg_chloride, wg_sodium=:wg_sodium, wg_magnesium=:wg_magnesium, "
1337 "wg_total_alkalinity=:wg_total_alkalinity, wg_ph=:wg_ph, "
1338 "wb_calcium=:wb_calcium, wb_sulfate=:wb_sulfate, wb_chloride=:wb_chloride, wb_sodium=:wb_sodium, "
1339 "wb_magnesium=:wb_magnesium, wb_total_alkalinity=:wb_total_alkalinity, wb_ph=:wb_ph, "
1340 "wa_acid_name=:wa_acid_name, wa_acid_perc=:wa_acid_perc, wa_base_name=:wa_base_name, "
1341 "starter_enable=:starter_enable, starter_type=:starter_type, starter_sg=:starter_sg, "
1342 "starter_viability=:starter_viability, yeast_prod_date=:yeast_prod_date, yeast_pitchrate=:yeast_pitchrate, "
1343 "prop1_type=:prop1_type, prop1_volume=:prop1_volume, prop2_type=:prop2_type, prop2_volume=:prop2_volume, "
1344 "prop3_type=:prop3_type, prop3_volume=:prop3_volume, prop4_type=:prop4_type, prop4_volume=:prop4_volume, "
1345 "divide_type=:divide_type, divide_size=:divide_size, divide_factor=:divide_factor, "
1346 "divide_parts=:divide_parts, divide_part=:divide_part, "
1347 "json_fermentables=:json_fermentables, json_hops=:json_hops, json_miscs=:json_miscs, "
1348 "json_yeasts=:json_yeasts, json_mashs=:json_mashs, uuid=:uuid");
1349 } else {
1350 query.prepare("UPDATE products SET "
1351 "name=:name, code=:code, birth=:birth, stage=:stage, notes=:notes, log_brew=:log_brew, "
1352 "log_fermentation=:log_fermentation, log_ispindel=:log_ispindel, log_co2pressure=:log_co2pressure, "
1353 "inventory_reduced=:inventory_reduced, locked=:locked, "
1354 "eq_name=:eq_name, eq_boil_size=:eq_boil_size, eq_efficiency=:eq_efficiency, "
1355 "eq_batch_size=:eq_batch_size, eq_tun_volume=:eq_tun_volume, eq_tun_weight=:eq_tun_weight, "
1356 "eq_tun_specific_heat=:eq_tun_specific_heat, eq_tun_material=:eq_tun_material, eq_tun_height=:eq_tun_height, "
1357 "eq_top_up_water=:eq_top_up_water, eq_trub_chiller_loss=:eq_chiller_loss, eq_evap_rate=:eq_evap_rate, "
1358 "eq_boil_time=:eq_boil_time, eq_calc_boil_volume=:eq_calcboil, eq_top_up_kettle=:eq_top_up_kettle, "
1359 "eq_hop_utilization=:eq_hopfactor, eq_notes=:eq_notes, eq_lauter_volume=:eq_lauter_volume, "
1360 "eq_lauter_height=:eq_lauter_height, eq_lauter_deadspace=:eq_lauter_deadspace, eq_kettle_volume=:eq_kettle_volume, "
1361 "eq_kettle_height=:eq_kettle_height, eq_mash_volume=:eq_mash_volume, eq_mash_max=:eq_mash_max, "
1362 "brew_date_start=:brew_date_start, brew_mash_ph=:brew_mash_ph, brew_mash_sg=:brew_mash_sg, "
1363 "brew_mash_efficiency=:brew_mash_efficiency, brew_sparge_temperature=:brew_sparge_temperature, "
1364 "brew_sparge_volume=:brew_sparge_volume, brew_sparge_est=:brew_sparge_est, brew_sparge_ph=:brew_sparge_ph, "
1365 "brew_preboil_volume=:brew_preboil_volume, brew_preboil_sg=:brew_preboil_sg, brew_preboil_ph=:brew_preboil_ph, "
1366 "brew_preboil_efficiency=:brew_preboil_efficiency, brew_aboil_volume=:brew_aboil_volume, "
1367 "brew_aboil_sg=:brew_aboil_sg, brew_aboil_ph=:brew_aboil_ph, brew_aboil_efficiency=:brew_aboil_efficiency, "
1368 "brew_cooling_method=:brew_cooling_method, brew_cooling_time=:brew_cooling_time, brew_cooling_to=:brew_cooling_to, "
1369 "brew_whirlpool9=:brew_whirlpool9, brew_whirlpool7=:brew_whirlpool7, brew_whirlpool6=:brew_whirlpool6, "
1370 "brew_whirlpool2=:brew_whirlpool2, brew_fermenter_volume=:brew_fermenter_volume, "
1371 "brew_fermenter_extrawater=:brew_fermenter_extrawater, brew_fermenter_tcloss=:brew_fermenter_tcloss, "
1372 "brew_aeration_time=:brew_aeration_time, brew_aeration_speed=:brew_aeration_speed, "
1373 "brew_aeration_type=:brew_aeration_type, brew_fermenter_sg=:brew_fermenter_sg, brew_fermenter_ibu=:brew_fermenter_ibu, "
1374 "brew_fermenter_color=:brew_fermenter_color, brew_date_end=:brew_date_end, "
1375 "og=:og, fg=:fg, primary_start_temp=:primary_start_temp, primary_max_temp=:primary_max_temp, "
1376 "primary_end_temp=:primary_end_temp, primary_end_sg=:primary_end_sg, primary_end_date=:primary_end_date, "
1377 "secondary_temp=:secondary_temp, secondary_end_sg=:secondary_end_sg, secondary_end_date=:secondary_end_date, "
1378 "tertiary_temp=:tertiary_temp, package_date=:package_date, package_volume=:package_volume, "
1379 "package_infuse_amount=:package_infuse_amount, package_infuse_abv=:package_infuse_abv, "
1380 "package_infuse_notes=:package_infuse_notes, package_abv=:package_abv, package_ph=:package_ph, "
1381 "bottle_amount=:bottle_amount, bottle_carbonation=:bottle_carbonation, bottle_priming_sugar=:bottle_priming_sugar, "
1382 "bottle_priming_amount=:bottle_priming_amount, bottle_priming_water=:bottle_priming_water, "
1383 "bottle_carbonation_temp=:bottle_carbonation_temp, keg_amount=:keg_amount, keg_carbonation=:keg_carbonation, "
1384 "keg_priming_sugar=:keg_priming_sugar, keg_priming_amount=:keg_priming_amount, keg_priming_water=:keg_priming_water, "
1385 "keg_carbonation_temp=:keg_carbonation_temp, keg_forced_carb=:keg_forced_carb, keg_pressure=:keg_pressure, "
1386 "taste_notes=:taste_notes, taste_rate=:taste_rate, taste_date=:taste_date, taste_color=:taste_color, "
1387 "taste_transparency=:taste_transparency, taste_head=:taste_head, taste_aroma=:taste_aroma, "
1388 "taste_taste=:taste_taste, taste_mouthfeel=:taste_mouthfeel, taste_aftertaste=:taste_aftertaste, "
1389 "st_name=:st_name, st_letter=:st_letter, "
1390 "st_guide=:st_guide, st_category=:st_category, st_category_number=:st_catnr, st_type=:st_type, "
1391 "st_og_min=:st_og_min, st_og_max=:st_og_max, st_fg_min=:st_fg_min, st_fg_max=:st_fg_max, "
1392 "st_ibu_min=:st_ibu_min, st_ibu_max=:st_ibu_max, st_color_min=:st_color_min, st_color_max=:st_color_max, "
1393 "st_carb_min=:st_carb_min, st_carb_max=:st_carb_max, st_abv_min=:st_abv_min, st_abv_max=:st_abv_max, "
1394 "type=:type, batch_size=:batch_size, boil_size=:boil_size, "
1395 "boil_time=:boil_time, efficiency=:efficiency, est_og=:est_og, est_og3=:est_og3, est_fg=:est_fg, est_abv=:est_abv, "
1396 "est_color=:est_color, color_method=:color_method, est_ibu=:est_ibu, ibu_method=:ibu_method, "
1397 "est_carb=:est_carb, sparge_temp=:sparge_temp, sparge_ph=:sparge_ph, "
1398 "sparge_volume=:sparge_volume, sparge_source=:sparge_source, sparge_acid_type=:sparge_acid_type, "
1399 "sparge_acid_perc=:sparge_acid_perc, sparge_acid_amount=:sparge_acid_amount, mash_ph=:mash_ph, "
1400 "mash_name=:mash_name, calc_acid=:calc_acid, "
1401 "w1_name=:w1_name, w1_amount=:w1_amount, w1_calcium=:w1_calcium, w1_sulfate=:w1_sulfate, "
1402 "w1_chloride=:w1_chloride, w1_sodium=:w1_sodium, w1_magnesium=:w1_magnesium, "
1403 "w1_total_alkalinity=:w1_total_alkalinity, w1_ph=:w1_ph, w1_cost=:w1_cost, "
1404 "w2_name=:w2_name, w2_amount=:w2_amount, w2_calcium=:w2_calcium, w2_sulfate=:w2_sulfate, "
1405 "w2_chloride=:w2_chloride, w2_sodium=:w2_sodium, w2_magnesium=:w2_magnesium, "
1406 "w2_total_alkalinity=:w2_total_alkalinity, w2_ph=:w2_ph, w2_cost=:w2_cost, "
1407 "wg_amount=:wg_amount, wg_calcium=:wg_calcium, wg_sulfate=:wg_sulfate, "
1408 "wg_chloride=:wg_chloride, wg_sodium=:wg_sodium, wg_magnesium=:wg_magnesium, "
1409 "wg_total_alkalinity=:wg_total_alkalinity, wg_ph=:wg_ph, "
1410 "wb_calcium=:wb_calcium, wb_sulfate=:wb_sulfate, wb_chloride=:wb_chloride, wb_sodium=:wb_sodium, "
1411 "wb_magnesium=:wb_magnesium, wb_total_alkalinity=:wb_total_alkalinity, wb_ph=:wb_ph, "
1412 "wa_acid_name=:wa_acid_name, wa_acid_perc=:wa_acid_perc, wa_base_name=:wa_base_name, "
1413 "starter_enable=:starter_enable, starter_type=:starter_type, starter_sg=:starter_sg, "
1414 "starter_viability=:starter_viability, yeast_prod_date=:yeast_prod_date, yeast_pitchrate=:yeast_pitchrate, "
1415 "prop1_type=:prop1_type, prop1_volume=:prop1_volume, prop2_type=:prop2_type, prop2_volume=:prop2_volume, "
1416 "prop3_type=:prop3_type, prop3_volume=:prop3_volume, prop4_type=:prop4_type, prop4_volume=:prop4_volume, "
1417 "divide_type=:divide_type, divide_size=:divide_size, divide_factor=:divide_factor, "
1418 "divide_parts=:divide_parts, divide_part=:divide_part, "
1419 "json_fermentables=:json_fermentables, json_hops=:json_hops, json_miscs=:json_miscs, "
1420 "json_yeasts=:json_yeasts, json_mashs=:json_mashs WHERE record = :recno");
1421 }
1422
1423 query.bindValue(":name", product->name);
1424 query.bindValue(":code", product->code);
1425 query.bindValue(":birth", product->birth);
1426 query.bindValue(":stage", product->stage);
1427 query.bindValue(":notes", product->notes);
1428 query.bindValue(":log_brew", product->log_brew ? 1:0);
1429 query.bindValue(":log_fermentation", product->log_fermentation ? 1:0);
1430 query.bindValue(":log_ispindel", product->log_ispindel ? 1:0);
1431 query.bindValue(":log_co2pressure", product->log_co2pressure ? 1:0);
1432 query.bindValue(":inventory_reduced", product->inventory_reduced);
1433 query.bindValue(":locked", product->locked ? 1:0);
1434 query.bindValue(":eq_name", product->eq_name);
1435 query.bindValue(":eq_boil_size", round(product->eq_boil_size * 10) / 10);
1436 query.bindValue(":eq_batch_size", round(product->eq_batch_size * 100) / 100);
1437 query.bindValue(":eq_tun_volume", round(product->eq_tun_volume * 10) / 10);
1438 query.bindValue(":eq_tun_weight", round(product->eq_tun_weight * 10) / 10);
1439 query.bindValue(":eq_tun_specific_heat", round(product->eq_tun_specific_heat * 1000) / 1000);
1440 query.bindValue(":eq_tun_material", product->eq_tun_material);
1441 query.bindValue(":eq_tun_height", round(product->eq_tun_height * 1000) / 1000);
1442 query.bindValue(":eq_top_up_water", round(product->eq_top_up_water * 10) / 10);
1443 query.bindValue(":eq_chiller_loss", round(product->eq_trub_chiller_loss * 10) / 10);
1444 query.bindValue(":eq_evap_rate", round(product->eq_evap_rate * 100) / 100);
1445 query.bindValue(":eq_boil_time", round(product->eq_boil_time));
1446 query.bindValue(":eq_calcboil", product->eq_calc_boil_volume ? 1:0);
1447 query.bindValue(":eq_top_up_kettle", round(product->eq_top_up_kettle * 10) / 10);
1448 query.bindValue(":eq_hopfactor", round(product->eq_hop_utilization));
1449 query.bindValue(":eq_notes", product->eq_notes);
1450 query.bindValue(":eq_lauter_volume", round(product->eq_lauter_volume * 10) / 10);
1451 query.bindValue(":eq_lauter_height", round(product->eq_lauter_height * 1000) / 1000);
1452 query.bindValue(":eq_lauter_deadspace", round(product->eq_lauter_deadspace * 10) / 10);
1453 query.bindValue(":eq_kettle_volume", round(product->eq_kettle_volume * 10) / 10);
1454 query.bindValue(":eq_kettle_height", round(product->eq_kettle_height * 1000) / 1000);
1455 query.bindValue(":eq_mash_volume", round(product->eq_mash_volume * 10) / 10);
1456 query.bindValue(":eq_mash_max", round(product->eq_mash_max * 10) / 10);
1457 query.bindValue(":eq_efficiency", round(product->eq_efficiency * 10) / 10);
1458 query.bindValue(":brew_date_start", product->brew_date_start);
1459 query.bindValue(":brew_mash_ph", round(product->brew_mash_ph * 100) / 100);
1460 query.bindValue(":brew_mash_sg", round(product->brew_mash_sg * 1000) / 1000);
1461 query.bindValue(":brew_mash_efficiency", round(product->brew_mash_efficiency * 10) / 10);
1462 query.bindValue(":brew_sparge_temperature", round(product->brew_sparge_temperature * 10) / 10);
1463 query.bindValue(":brew_sparge_volume", round(product->brew_sparge_volume * 10) / 10);
1464 query.bindValue(":brew_sparge_est", round(product->brew_sparge_est * 10) / 10);
1465 query.bindValue(":brew_sparge_ph", round(product->brew_sparge_ph * 100) / 100);
1466 query.bindValue(":brew_preboil_volume", round(product->brew_preboil_volume * 10) / 10);
1467 query.bindValue(":brew_preboil_sg", round(product->brew_preboil_sg * 1000) / 1000);
1468 query.bindValue(":brew_preboil_ph", round(product->brew_preboil_ph * 100) / 100);
1469 query.bindValue(":brew_preboil_efficiency", round(product->brew_preboil_efficiency * 10) / 10);
1470 query.bindValue(":brew_aboil_volume", round(product->brew_aboil_volume * 10) / 10);
1471 query.bindValue(":brew_aboil_sg", round(product->brew_aboil_sg * 1000) / 1000);
1472 query.bindValue(":brew_aboil_ph", round(product->brew_aboil_ph * 100) / 100);
1473 query.bindValue(":brew_aboil_efficiency", round(product->brew_aboil_efficiency * 10) / 10);
1474 query.bindValue(":brew_cooling_method", product->brew_cooling_method);
1475 query.bindValue(":brew_cooling_time", round(product->brew_cooling_time * 10) / 10);
1476 query.bindValue(":brew_cooling_to", round(product->brew_cooling_to * 10) / 10);
1477 query.bindValue(":brew_whirlpool9", round(product->brew_whirlpool9));
1478 query.bindValue(":brew_whirlpool7", round(product->brew_whirlpool7));
1479 query.bindValue(":brew_whirlpool6", round(product->brew_whirlpool6));
1480 query.bindValue(":brew_whirlpool2", round(product->brew_whirlpool2));
1481 query.bindValue(":brew_fermenter_volume", round(product->brew_fermenter_volume * 10) / 10);
1482 query.bindValue(":brew_fermenter_extrawater", round(product->brew_fermenter_extrawater * 10) / 10);
1483 query.bindValue(":brew_fermenter_tcloss", round(product->brew_fermenter_tcloss * 10) / 10);
1484 query.bindValue(":brew_aeration_time", round(product->brew_aeration_time));
1485 query.bindValue(":brew_aeration_speed", round(product->brew_aeration_speed * 10) / 10);
1486 query.bindValue(":brew_aeration_type", product->brew_aeration_type);
1487 query.bindValue(":brew_fermenter_sg", round(product->brew_fermenter_sg * 1000) / 1000);
1488 query.bindValue(":brew_fermenter_ibu", round(product->brew_fermenter_ibu * 10) / 10);
1489 query.bindValue(":brew_fermenter_color", round(product->brew_fermenter_color * 10) / 10);
1490 query.bindValue(":brew_date_end", product->brew_date_end);
1491 query.bindValue(":og", round(product->og * 1000) / 1000);
1492 query.bindValue(":fg", round(product->fg * 1000) / 1000);
1493 query.bindValue(":primary_start_temp", round(product->primary_start_temp * 10) / 10);
1494 query.bindValue(":primary_max_temp", round(product->primary_max_temp * 10) / 10);
1495 query.bindValue(":primary_end_temp", round(product->primary_end_temp * 10) / 10);
1496 query.bindValue(":primary_end_sg", round(product->primary_end_sg * 1000) / 1000);
1497 query.bindValue(":primary_end_date", product->primary_end_date);
1498 query.bindValue(":secondary_temp", round(product->secondary_temp * 10) / 10);
1499 query.bindValue(":secondary_end_sg", round(product->secondary_end_sg * 1000) / 1000);
1500 query.bindValue(":secondary_end_date", product->secondary_end_date);
1501 query.bindValue(":tertiary_temp", round(product->tertiary_temp * 10) / 10);
1502 query.bindValue(":package_date", product->package_date);
1503 query.bindValue(":package_volume", round(product->package_volume * 10) / 10);
1504 query.bindValue(":package_infuse_amount", round(product->package_infuse_amount * 1000) / 1000);
1505 query.bindValue(":package_infuse_abv", round(product->package_infuse_abv * 100) / 100);
1506 query.bindValue(":package_infuse_notes", product->package_infuse_notes);
1507 query.bindValue(":package_abv", round(product->package_abv * 100) / 100);
1508 query.bindValue(":package_ph", round(product->package_ph * 100) / 100);
1509 query.bindValue(":bottle_amount", round(product->bottle_amount * 10) / 10);
1510 query.bindValue(":bottle_carbonation", round(product->bottle_carbonation * 100) / 100);
1511 query.bindValue(":bottle_priming_sugar", product->bottle_priming_sugar);
1512 query.bindValue(":bottle_priming_amount", round(product->bottle_priming_amount * 10) / 10);
1513 query.bindValue(":bottle_priming_water", round(product->bottle_priming_water * 1000) / 1000);
1514 query.bindValue(":bottle_carbonation_temp", round(product->bottle_carbonation_temp * 10) / 10);
1515 query.bindValue(":keg_amount", round(product->keg_amount * 10) / 10);
1516 query.bindValue(":keg_carbonation", round(product->keg_carbonation * 100) / 100);
1517 query.bindValue(":keg_priming_sugar", product->keg_priming_sugar);
1518 query.bindValue(":keg_priming_amount", round(product->keg_priming_amount * 10) / 10);
1519 query.bindValue(":keg_priming_water", round(product->keg_priming_water * 1000) / 1000);
1520 query.bindValue(":keg_carbonation_temp", round(product->keg_carbonation_temp * 10) / 10);
1521 query.bindValue(":keg_forced_carb", product->keg_forced_carb ? 1:0);
1522 query.bindValue(":keg_pressure", round(product->keg_pressure * 10) / 10);
1523 query.bindValue(":taste_notes", product->taste_notes);
1524 query.bindValue(":taste_rate", round(product->taste_rate * 10) / 10);
1525 query.bindValue(":taste_date", product->taste_date);
1526 query.bindValue(":taste_color", product->taste_color);
1527 query.bindValue(":taste_transparency", product->taste_transparency);
1528 query.bindValue(":taste_head", product->taste_head);
1529 query.bindValue(":taste_aroma", product->taste_aroma);
1530 query.bindValue(":taste_taste", product->taste_taste);
1531 query.bindValue(":taste_mouthfeel", product->taste_mouthfeel);
1532 query.bindValue(":taste_aftertaste", product->taste_aftertaste);
1533 query.bindValue(":st_name", product->st_name);
1534 query.bindValue(":st_letter", product->st_letter);
1535 query.bindValue(":st_guide", product->st_guide);
1536 query.bindValue(":st_category", product->st_category);
1537 query.bindValue(":st_catnr", product->st_category_number);
1538 query.bindValue(":st_type", product->st_type);
1539 query.bindValue(":st_og_min", round(product->st_og_min * 1000) / 1000);
1540 query.bindValue(":st_og_max", round(product->st_og_max * 1000) / 1000);
1541 query.bindValue(":st_fg_min", round(product->st_fg_min * 1000) / 1000);
1542 query.bindValue(":st_fg_max", round(product->st_fg_max * 1000) / 1000);
1543 query.bindValue(":st_ibu_min", round(product->st_ibu_min * 10) / 10);
1544 query.bindValue(":st_ibu_max", round(product->st_ibu_max * 10) / 10);
1545 query.bindValue(":st_color_min", round(product->st_color_min * 10) / 10);
1546 query.bindValue(":st_color_max", round(product->st_color_max * 10) / 10);
1547 query.bindValue(":st_carb_min", round(product->st_carb_min * 10) / 10);
1548 query.bindValue(":st_carb_max", round(product->st_carb_max * 10) / 10);
1549 query.bindValue(":st_abv_min", round(product->st_abv_min * 10) / 10);
1550 query.bindValue(":st_abv_max", round(product->st_abv_max * 10) / 10);
1551 query.bindValue(":type", product->type);
1552 query.bindValue(":batch_size", round(product->batch_size * 10) / 10);
1553 query.bindValue(":boil_size", round(product->boil_size * 10) / 10);
1554 query.bindValue(":boil_time", round(product->boil_time * 10) / 10);
1555 query.bindValue(":efficiency", round(product->efficiency * 10) / 10);
1556 query.bindValue(":est_og", round(product->est_og * 1000) / 1000);
1557 query.bindValue(":est_og3", round(product->est_og3 * 1000) / 1000);
1558 query.bindValue(":est_fg", round(product->est_fg * 1000) / 1000);
1559 query.bindValue(":est_abv", round(product->est_abv * 10) / 10);
1560 query.bindValue(":est_color", round(product->est_color * 10) / 10);
1561 query.bindValue(":color_method", product->color_method);
1562 query.bindValue(":est_ibu", round(product->est_ibu * 10) / 10);
1563 query.bindValue(":ibu_method", product->ibu_method);
1564 query.bindValue(":est_carb", round(product->est_carb * 10) / 10);
1565 query.bindValue(":sparge_temp", round(product->sparge_temp * 10) / 10);
1566 query.bindValue(":sparge_ph", round(product->sparge_ph * 100) / 100);
1567 query.bindValue(":sparge_volume", round(product->sparge_volume * 10) / 10);
1568 query.bindValue(":sparge_source", product->sparge_source);
1569 query.bindValue(":sparge_acid_type", product->sparge_acid_type);
1570 query.bindValue(":sparge_acid_perc", round(product->sparge_acid_perc * 10) / 10);
1571 query.bindValue(":sparge_acid_amount", round(product->sparge_acid_amount * 100000) / 100000);
1572 query.bindValue(":mash_ph", round(product->mash_ph * 100) / 100);
1573 query.bindValue(":mash_name", product->mash_name);
1574 query.bindValue(":calc_acid", product->calc_acid ?1:0);
1575 query.bindValue(":w1_name", product->w1_name);
1576 query.bindValue(":w1_amount", round(product->w1_amount * 10) / 10);
1577 query.bindValue(":w1_calcium", round(product->w1_calcium * 100000) / 100000);
1578 query.bindValue(":w1_sulfate", round(product->w1_sulfate * 100000) / 100000);
1579 query.bindValue(":w1_chloride", round(product->w1_chloride * 100000) / 100000);
1580 query.bindValue(":w1_sodium", round(product->w1_sodium * 100000) / 100000);
1581 query.bindValue(":w1_magnesium", round(product->w1_magnesium * 100000) / 100000);
1582 query.bindValue(":w1_total_alkalinity", round(product->w1_total_alkalinity * 100000) / 100000);
1583 query.bindValue(":w1_ph", round(product->w1_ph * 100) / 100);
1584 query.bindValue(":w1_cost", round(product->w1_cost * 100) / 100);
1585 query.bindValue(":w2_name", product->w2_name);
1586 query.bindValue(":w2_amount", round(product->w2_amount * 10) / 10);
1587 query.bindValue(":w2_calcium", round(product->w2_calcium * 100000) / 100000);
1588 query.bindValue(":w2_sulfate", round(product->w2_sulfate * 100000) / 100000);
1589 query.bindValue(":w2_chloride", round(product->w2_chloride * 100000) / 100000);
1590 query.bindValue(":w2_sodium", round(product->w2_sodium * 100000) / 100000);
1591 query.bindValue(":w2_magnesium", round(product->w2_magnesium * 100000) / 100000);
1592 query.bindValue(":w2_total_alkalinity", round(product->w2_total_alkalinity * 100000) / 100000);
1593 query.bindValue(":w2_ph", round(product->w2_ph * 100) / 100);
1594 query.bindValue(":w2_cost", round(product->w2_cost * 100) / 100);
1595 query.bindValue(":wg_amount", round(product->wg_amount * 10) / 10);
1596 query.bindValue(":wg_calcium", round(product->wg_calcium * 100000) / 100000);
1597 query.bindValue(":wg_sulfate", round(product->wg_sulfate * 100000) / 100000);
1598 query.bindValue(":wg_chloride", round(product->wg_chloride * 100000) / 100000);
1599 query.bindValue(":wg_sodium", round(product->wg_sodium * 100000) / 100000);
1600 query.bindValue(":wg_magnesium", round(product->wg_magnesium * 100000) / 100000);
1601 query.bindValue(":wg_total_alkalinity", round(product->wg_total_alkalinity * 100000) / 100000);
1602 query.bindValue(":wg_ph", round(product->wg_ph * 100) / 100);
1603 query.bindValue(":wb_calcium", round(product->wb_calcium * 100000) / 100000);
1604 query.bindValue(":wb_sulfate", round(product->wb_sulfate * 100000) / 100000);
1605 query.bindValue(":wb_chloride", round(product->wb_chloride * 100000) / 100000);
1606 query.bindValue(":wb_sodium", round(product->wb_sodium * 100000) / 100000);
1607 query.bindValue(":wb_magnesium", round(product->wb_magnesium * 100000) / 100000);
1608 query.bindValue(":wb_total_alkalinity", round(product->wb_total_alkalinity * 100000) / 100000);
1609 query.bindValue(":wb_ph", round(product->wb_ph * 100) / 100);
1610 query.bindValue(":wa_acid_name", product->wa_acid_name);
1611 query.bindValue(":wa_acid_perc", round(product->wa_acid_perc * 10) / 10);
1612 query.bindValue(":wa_base_name", product->wa_base_name);
1613 query.bindValue(":starter_enable", product->starter_enable ? 1:0);
1614 query.bindValue(":starter_type", product->starter_type);
1615 query.bindValue(":starter_sg", round(product->starter_sg * 1000) / 1000);
1616 query.bindValue(":starter_viability", product->starter_viability);
1617 query.bindValue(":yeast_prod_date", product->yeast_prod_date);
1618 query.bindValue(":yeast_pitchrate", round(product->yeast_pitchrate * 1000) / 1000);
1619 query.bindValue(":prop1_type", product->prop_type[0]);
1620 query.bindValue(":prop1_volume", round(product->prop_volume[0] * 1000) / 1000);
1621 query.bindValue(":prop2_type", product->prop_type[1]);
1622 query.bindValue(":prop2_volume", round(product->prop_volume[1] * 1000) / 1000);
1623 query.bindValue(":prop3_type", product->prop_type[2]);
1624 query.bindValue(":prop3_volume", round(product->prop_volume[2] * 1000) / 1000);
1625 query.bindValue(":prop4_type", product->prop_type[3]);
1626 query.bindValue(":prop4_volume", round(product->prop_volume[3] * 1000) / 1000);
1627 query.bindValue(":divide_type", product->divide_type);
1628 query.bindValue(":divide_size", round(product->divide_size * 10) / 10);
1629 query.bindValue(":divide_factor", round(product->divide_factor * 100) / 100);
1630 query.bindValue(":divide_parts", product->divide_parts);
1631 query.bindValue(":divide_part", product->divide_part);
1632
1633 if (product->fermentables.size() == 0) {
1634 query.bindValue(":json_fermentables", "[]");
1635 } else {
1636 QJsonArray array;
1637 for (int i = 0; i < product->fermentables.size(); i++) {
1638 QJsonObject obj;
1639 obj.insert("f_name", product->fermentables.at(i).f_name);
1640 obj.insert("f_origin", product->fermentables.at(i).f_origin);
1641 obj.insert("f_supplier", product->fermentables.at(i).f_supplier);
1642 obj.insert("f_amount", round(product->fermentables.at(i).f_amount * 100000) / 100000);
1643 obj.insert("f_cost", round(product->fermentables.at(i).f_cost * 1000) / 1000);
1644 obj.insert("f_type", product->fermentables.at(i).f_type);
1645 obj.insert("f_yield", round(product->fermentables.at(i).f_yield * 10) / 10);
1646 obj.insert("f_color", round(product->fermentables.at(i).f_color * 10) / 10);
1647 obj.insert("f_coarse_fine_diff", round(product->fermentables.at(i).f_coarse_fine_diff * 10) / 10);
1648 obj.insert("f_moisture", round(product->fermentables.at(i).f_moisture * 10) / 10);
1649 obj.insert("f_diastatic_power", round(product->fermentables.at(i).f_diastatic_power * 100000) / 100000);
1650 obj.insert("f_protein", round(product->fermentables.at(i).f_protein * 10) / 10);
1651 obj.insert("f_dissolved_protein", round(product->fermentables.at(i).f_dissolved_protein * 10) / 10);
1652 obj.insert("f_max_in_batch", product->fermentables.at(i).f_max_in_batch);
1653 obj.insert("f_graintype", product->fermentables.at(i).f_graintype);
1654 obj.insert("f_added", product->fermentables.at(i).f_added);
1655 obj.insert("f_recommend_mash", product->fermentables.at(i).f_recommend_mash ? 1:0);
1656 obj.insert("f_add_after_boil", product->fermentables.at(i).f_add_after_boil ? 1:0);
1657 obj.insert("f_adjust_to_total_100", product->fermentables.at(i).f_adjust_to_total_100 ? 1:0);
1658 obj.insert("f_percentage", round(product->fermentables.at(i).f_percentage * 10) / 10);
1659 obj.insert("f_di_ph", round(product->fermentables.at(i).f_di_ph * 100000) / 100000);
1660 obj.insert("f_acid_to_ph_57", round(product->fermentables.at(i).f_acid_to_ph_57 * 100000) / 100000);
1661 qDebug() << "fermentables_Json" << i << obj;
1662 array.append(obj); /* Append this object */
1663 }
1664 QJsonDocument doc;
1665 doc.setArray(array);
1666 // qDebug() << doc.toJson(QJsonDocument::Compact);
1667 query.bindValue(":json_fermentables", doc.toJson(QJsonDocument::Compact));
1668 }
1669
1670 if (product->hops.size() == 0) {
1671 query.bindValue(":json_hops", "[]");
1672 } else {
1673 QJsonArray array;
1674 for (int i = 0; i < product->hops.size(); i++) {
1675 QJsonObject obj;
1676 obj.insert("h_name", product->hops.at(i).h_name);
1677 obj.insert("h_origin", product->hops.at(i).h_origin);
1678 obj.insert("h_amount", round(product->hops.at(i).h_amount * 10000) / 10000);
1679 obj.insert("h_cost", round(product->hops.at(i).h_cost * 100) / 100);
1680 obj.insert("h_type", product->hops.at(i).h_type);
1681 obj.insert("h_form", product->hops.at(i).h_form);
1682 obj.insert("h_useat", product->hops.at(i).h_useat);
1683 obj.insert("h_time", round(product->hops.at(i).h_time));
1684 obj.insert("h_alpha", round(product->hops.at(i).h_alpha * 100) / 100);
1685 obj.insert("h_beta", round(product->hops.at(i).h_beta * 100) / 100);
1686 obj.insert("h_hsi", round(product->hops.at(i).h_hsi * 100) / 100);
1687 obj.insert("h_humulene", round(product->hops.at(i).h_humulene * 100) / 100);
1688 obj.insert("h_caryophyllene", round(product->hops.at(i).h_caryophyllene * 100) / 100);
1689 obj.insert("h_cohumulone", round(product->hops.at(i).h_cohumulone * 100) / 100);
1690 obj.insert("h_myrcene", round(product->hops.at(i).h_myrcene * 100) / 100);
1691 obj.insert("h_total_oil", round(product->hops.at(i).h_total_oil * 100) / 100);
1692 qDebug() << "hops_Json" << i << obj;
1693 array.append(obj); /* Append this object */
1694 }
1695 QJsonDocument doc;
1696 doc.setArray(array);
1697 query.bindValue(":json_hops", doc.toJson(QJsonDocument::Compact));
1698 }
1699
1700 if (product->miscs.size() == 0) {
1701 query.bindValue(":json_miscs", "[]");
1702 } else {
1703 QJsonArray array;
1704 for (int i = 0; i < product->miscs.size(); i++) {
1705 QJsonObject obj;
1706 obj.insert("m_name", product->miscs.at(i).m_name);
1707 obj.insert("m_amount", round(product->miscs.at(i).m_amount * 10000) / 10000);
1708 obj.insert("m_type", product->miscs.at(i).m_type);
1709 obj.insert("m_use_use", product->miscs.at(i).m_use_use);
1710 obj.insert("m_time", round(product->miscs.at(i).m_time));
1711 obj.insert("m_amount_is_weight", product->miscs.at(i).m_amount_is_weight ? 1:0);
1712 obj.insert("m_cost", round(product->miscs.at(i).m_cost * 10000) / 10000);
1713 qDebug() << "miscs_Json" << i << obj;
1714 array.append(obj); /* Append this object */
1715 }
1716 QJsonDocument doc;
1717 doc.setArray(array);
1718 // qDebug() << doc.toJson(QJsonDocument::Compact);
1719 query.bindValue(":json_miscs", doc.toJson(QJsonDocument::Compact));
1720 }
1721
1722 if (product->yeasts.size() == 0) {
1723 query.bindValue(":json_yeasts", "[]");
1724 } else {
1725 QJsonArray array;
1726 for (int i = 0; i < product->yeasts.size(); i++) {
1727 QJsonObject obj;
1728 obj.insert("y_name", product->yeasts.at(i).y_name);
1729 obj.insert("y_laboratory", product->yeasts.at(i).y_laboratory);
1730 obj.insert("y_product_id", product->yeasts.at(i).y_product_id);
1731 obj.insert("y_amount", round(product->yeasts.at(i).y_amount * 10000) / 10000);
1732 obj.insert("y_type", product->yeasts.at(i).y_type);
1733 obj.insert("y_form", product->yeasts.at(i).y_form);
1734 obj.insert("y_min_temperature", round(product->yeasts.at(i).y_min_temperature * 10) / 10);
1735 obj.insert("y_max_temperature", round(product->yeasts.at(i).y_max_temperature * 10) / 10);
1736 obj.insert("y_flocculation", product->yeasts.at(i).y_flocculation);
1737 obj.insert("y_attenuation", round(product->yeasts.at(i).y_attenuation * 10) / 10);
1738 obj.insert("y_cells", product->yeasts.at(i).y_cells);
1739 obj.insert("y_tolerance", round(product->yeasts.at(i).y_tolerance * 10) / 10);
1740 obj.insert("y_inventory", round(product->yeasts.at(i).y_inventory * 10000) / 10000);
1741 obj.insert("y_use", product->yeasts.at(i).y_use);
1742 obj.insert("y_sta1", product->yeasts.at(i).y_sta1 ? 1:0);
1743 obj.insert("y_bacteria", product->yeasts.at(i).y_bacteria ? 1:0);
1744 obj.insert("y_harvest_top", product->yeasts.at(i).y_harvest_top ? 1:0);
1745 obj.insert("y_harvest_time", product->yeasts.at(i).y_harvest_time);
1746 obj.insert("y_pitch_temperature", round(product->yeasts.at(i).y_pitch_temperature * 10) / 10);
1747 obj.insert("y_pofpos", product->yeasts.at(i).y_pofpos ? 1:0);
1748 obj.insert("y_zymocide", product->yeasts.at(i).y_zymocide);
1749 obj.insert("y_gr_hl_lo", product->yeasts.at(i).y_gr_hl_lo);
1750 obj.insert("y_sg_lo", round(product->yeasts.at(i).y_sg_lo * 1000) / 1000);
1751 obj.insert("y_gr_hl_hi", product->yeasts.at(i).y_gr_hl_hi);
1752 obj.insert("y_sg_hi", round(product->yeasts.at(i).y_sg_hi * 1000) / 1000);
1753 obj.insert("y_cost", round(product->yeasts.at(i).y_cost * 1000) / 1000);
1754 qDebug() << "yeasts_Json" << i << obj;
1755 array.append(obj); /* Append this object */
1756 }
1757 QJsonDocument doc;
1758 doc.setArray(array);
1759 // qDebug() << doc.toJson(QJsonDocument::Compact);
1760 query.bindValue(":json_yeasts", doc.toJson(QJsonDocument::Compact));
1761 }
1762
1763 if (product->mashs.size() == 0) {
1764 query.bindValue(":json_mashs", "[]");
1765 qDebug() << "Saved empty mashs";
1766 } else {
1767 QJsonArray array;
1768 for (int i = 0; i < product->mashs.size(); i++) {
1769 QJsonObject obj;
1770 obj.insert("step_name", product->mashs.at(i).step_name);
1771 obj.insert("step_type", product->mashs.at(i).step_type);
1772 obj.insert("step_volume", round(product->mashs.at(i).step_volume * 100) / 100);
1773 obj.insert("step_infuse_amount", round(product->mashs.at(i).step_infuse_amount * 100) / 100);
1774 obj.insert("step_infuse_temp", round(product->mashs.at(i).step_infuse_temp * 100) / 100);
1775 obj.insert("step_temp", round(product->mashs.at(i).step_temp * 100) / 100);
1776 obj.insert("step_time", round(product->mashs.at(i).step_time * 100) / 100);
1777 obj.insert("ramp_time", round(product->mashs.at(i).ramp_time * 100) / 100);
1778 obj.insert("end_temp", round(product->mashs.at(i).end_temp * 100) / 100);
1779 obj.insert("step_wg_ratio", round(product->mashs.at(i).step_wg_ratio * 100) / 100);
1780 obj.insert("step_ph", round(product->mashs.at(i).step_ph * 100) / 100);
1781 obj.insert("step_sg", round(product->mashs.at(i).step_sg * 10000) / 10000);
1782 qDebug() << "mashs_Json" << i << obj;
1783 array.append(obj); /* Append this object */
1784 }
1785 QJsonDocument doc;
1786 doc.setArray(array);
1787 qDebug() << doc.toJson(QJsonDocument::Compact);
1788 query.bindValue(":json_mashs", doc.toJson(QJsonDocument::Compact));
1789 }
1790
1791 if (this->recno == -1) {
1792 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36));
1793 } else {
1794 query.bindValue(":recno", this->recno);
1795 }
1796 query.exec();
1797 qDebug() << query.lastQuery();
1798 if (query.lastError().isValid()) {
1799 qDebug() << "EditProduct" << query.lastError();
1800 QMessageBox::warning(this, tr("Database error"),
1801 tr("MySQL error: %1\n%2\n%3")
1802 .arg(query.lastError().nativeErrorCode())
1803 .arg(query.lastError().driverText())
1804 .arg(query.lastError().databaseText()));
1805 } else {
1806 /* 772 /*
1807 * If this was a new product, find out what record number we 773 * If this was a new record, update the global recno.
1808 * have got and set it. So when the user saves this record
1809 * again, it will be updated instead of inserting a new copy.
1810 */ 774 */
1811 if (this->recno < 0) { 775 this->recno = product->record;
1812 QVariant id = query.lastInsertId();
1813 this->recno = product->record = id.toInt();
1814 qDebug() << "EditProduct Inserted record" << this->recno;
1815 } else {
1816 qDebug() << "EditProduct Updated record" << this->recno;
1817 }
1818 } 776 }
1819 } 777 }
1820 778
1821 ui->saveButton->setEnabled(false); 779 ui->saveButton->setEnabled(false);
1822 this->textIsChanged = false; 780 this->textIsChanged = false;
1839 #include "EditProductExport.cpp" 797 #include "EditProductExport.cpp"
1840 798
1841 799
1842 void EditProduct::on_deleteButton_clicked() 800 void EditProduct::on_deleteButton_clicked()
1843 { 801 {
1844 QSqlQuery query; 802 // QSqlQuery query;
1845 803
1846 int rc = QMessageBox::warning(this, tr("Delete product"), tr("Delete %1").arg(product->name), 804 int rc = QMessageBox::warning(this, tr("Delete product"), tr("Delete %1").arg(product->name),
1847 QMessageBox::Yes | QMessageBox::No, QMessageBox::No); 805 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
1848 if (rc == QMessageBox::No) 806 if (rc == QMessageBox::No)
1849 return; 807 return;
1850 808
1851 query.prepare("DELETE FROM products WHERE record = :recno"); 809 DB_product::dele(this, this->recno);
810 /* query.prepare("DELETE FROM products WHERE record = :recno");
1852 query.bindValue(":recno", this->recno); 811 query.bindValue(":recno", this->recno);
1853 query.exec(); 812 query.exec();
1854 if (query.lastError().isValid()) { 813 if (query.lastError().isValid()) {
1855 qDebug() << "EditProduct" << query.lastError(); 814 qDebug() << "EditProduct" << query.lastError();
1856 QMessageBox::warning(this, tr("Database error"), 815 QMessageBox::warning(this, tr("Database error"),
1859 .arg(query.lastError().driverText()) 818 .arg(query.lastError().driverText())
1860 .arg(query.lastError().databaseText())); 819 .arg(query.lastError().databaseText()));
1861 } else { 820 } else {
1862 qDebug() << "EditProduct Deleted" << this->recno; 821 qDebug() << "EditProduct Deleted" << this->recno;
1863 } 822 }
823 */
1864 824
1865 this->close(); 825 this->close();
1866 this->setResult(1); 826 this->setResult(1);
1867 } 827 }
1868 828

mercurial