src/EditProductExport.cpp

changeset 271
f56c0dff0a3d
parent 270
a0f72d7ace1f
child 273
eb9b50a4bf35
equal deleted inserted replaced
270:a0f72d7ace1f 271:f56c0dff0a3d
885 disconnect(splitatEdit, nullptr, nullptr, nullptr); 885 disconnect(splitatEdit, nullptr, nullptr, nullptr);
886 disconnect(splitTable, nullptr, nullptr, nullptr); 886 disconnect(splitTable, nullptr, nullptr, nullptr);
887 887
888 if (! doit) 888 if (! doit)
889 return; 889 return;
890 qInfo() << "split starts now";
891 for (int i = 0; i < product->splits.size(); i++) { 890 for (int i = 0; i < product->splits.size(); i++) {
892 Product *sp = new Product; 891 Product *sp = new Product;
893 if (DB_product::load(sp, this, product->record)) { 892 if (DB_product::load(sp, this, product->record)) {
894 double factor = round((product->splits.at(i).size / vol_availEdit->value()) * 1000.0) / 1000.0; 893 double factor = round((product->splits.at(i).size / vol_availEdit->value()) * 1000.0) / 1000.0;
895 qDebug() << "split prep" << i + 1 << product->splits.at(i).code << "factor" << factor; 894 qInfo() << "Split create part" << i + 1 << "code" << product->splits.at(i).code << "factor" << factor;
896 sp->record = -1; 895 sp->record = -1;
897 sp->uuid = ""; 896 sp->uuid = "";
898 sp->name = product->splits.at(i).name; 897 sp->name = product->splits.at(i).name;
899 sp->code = product->splits.at(i).code; 898 sp->code = product->splits.at(i).code;
900 sp->divide_type = product->divide_type; 899 sp->divide_type = product->divide_type;
940 } 939 }
941 for (int j = 0; j < sp->mashs.size(); j++) { 940 for (int j = 0; j < sp->mashs.size(); j++) {
942 sp->mashs[j].step_volume = round(sp->mashs.at(j).step_volume * factor * 100) / 100; 941 sp->mashs[j].step_volume = round(sp->mashs.at(j).step_volume * factor * 100) / 100;
943 sp->mashs[j].step_infuse_amount = round(sp->mashs.at(j).step_infuse_amount * factor * 100) / 100; 942 sp->mashs[j].step_infuse_amount = round(sp->mashs.at(j).step_infuse_amount * factor * 100) / 100;
944 } 943 }
945 DB_product::save(sp, this); 944 doit = DB_product::save(sp, this);
946 } 945 }
947 delete sp; 946 delete sp;
948 } 947 if (! doit)
948 break; // If errors
949 }
950
951 if (doit) { // Still ok?
952 Product *sp = new Product;
953 if (DB_product::load(sp, this, product->record)) {
954 double factor = round((vol_leftEdit->value() / vol_availEdit->value()) * 1000.0) / 1000.0;
955 qInfo() << "Split update main" << sp->code << "factor" << factor;
956 sp->divide_type = product->divide_type;
957 sp->divide_size = vol_leftEdit->value();
958 sp->divide_factor = factor;
959 sp->divide_parts = product->splits.size();
960 sp->divide_part = 0;
961 /* Now adjust the volumes */
962 sp->brew_sparge_est = sp->brew_sparge_est * factor;
963 sp->brew_preboil_volume = sp->brew_preboil_volume * factor;
964 sp->brew_aboil_volume = sp->brew_aboil_volume * factor;
965 sp->brew_fermenter_volume = sp->brew_fermenter_volume * factor;
966 sp->brew_fermenter_extrawater = sp->brew_fermenter_extrawater * factor;
967 sp->brew_fermenter_tcloss = sp->brew_fermenter_tcloss * factor;
968 sp->package_volume = sp->package_volume * factor;
969 sp->package_infuse_amount = sp->package_infuse_amount * factor;
970 sp->bottle_amount = sp->bottle_amount * factor;
971 sp->bottle_priming_water = sp->bottle_priming_water * factor;
972 sp->keg_amount = sp->keg_amount * factor;
973 sp->keg_priming_water = sp->keg_priming_water * factor;
974 sp->batch_size = sp->batch_size * factor;
975 sp->boil_size = sp->boil_size * factor;
976 sp->sparge_volume = sp->sparge_volume * factor;
977 sp->sparge_acid_amount = sp->sparge_acid_amount * factor;
978 sp->w1_amount = sp->w1_amount * factor;
979 sp->w2_amount = sp->w2_amount * factor;
980 sp->wg_amount = sp->wg_amount * factor;
981 sp->prop_volume[0] = sp->prop_volume[0] * factor;
982 sp->prop_volume[1] = sp->prop_volume[1] * factor;
983 sp->prop_volume[2] = sp->prop_volume[2] * factor;
984 sp->prop_volume[3] = sp->prop_volume[3] * factor;
985 for (int j = 0; j < sp->fermentables.size(); j++) {
986 sp->fermentables[j].f_amount = round(sp->fermentables.at(j).f_amount * factor * 100000) / 100000;
987 }
988 for (int j = 0; j < sp->hops.size(); j++) {
989 sp->hops[j].h_amount = round(sp->hops.at(j).h_amount * factor * 100000) / 100000;
990 }
991 for (int j = 0; j < sp->miscs.size(); j++) {
992 sp->miscs[j].m_amount = round(sp->miscs.at(j).m_amount * factor * 100000) / 100000;
993 }
994 for (int j = 0; j < sp->yeasts.size(); j++) {
995 sp->yeasts[j].y_amount = round(sp->yeasts.at(j).y_amount * factor * 100000) / 100000;
996 }
997 for (int j = 0; j < sp->mashs.size(); j++) {
998 sp->mashs[j].step_volume = round(sp->mashs.at(j).step_volume * factor * 100) / 100;
999 sp->mashs[j].step_infuse_amount = round(sp->mashs.at(j).step_infuse_amount * factor * 100) / 100;
1000 }
1001 doit = DB_product::save(sp, this);
1002 }
1003 delete sp;
1004 }
1005 if (doit)
1006 qInfo() << "Split is finished and ok";
1007 else
1008 qWarning() << "Split errors were found";
949 1009
950 /* Make sure the product editor is closed after splitting */ 1010 /* Make sure the product editor is closed after splitting */
951 qInfo() << "split ready, destroy windows";
952 this->close(); 1011 this->close();
953 this->setResult(1); 1012 this->setResult(1);
954 } 1013 }
955 1014
956 1015

mercurial