Allow adding sellers during sale phase

This commit is contained in:
Martin Brodbeck 2018-10-01 11:29:41 +02:00
parent 2e6e2f9c09
commit a10ba7d7f6
3 changed files with 27 additions and 7 deletions

View file

@ -31,18 +31,24 @@ void JsonUtil::exportSellers(const fs::path& filePath, Marketplace* market)
writer->write(root, &file);
}
void JsonUtil::importSellers(const fs::path& filePath, Marketplace* market)
void JsonUtil::importSellers(const fs::path& filePath, Marketplace* market, bool cleanup)
{
for (auto& seller : market->getSellers()) {
seller->setState(Seller::State::DELETE);
if (cleanup) {
for (auto& seller : market->getSellers()) {
seller->setState(Seller::State::DELETE);
}
market->storeToDb(true);
}
market->storeToDb(true);
Json::Value jsonValues;
std::ifstream file(filePath);
file >> jsonValues;
for (auto val : jsonValues["sellers"]) {
auto sellerExist = market->findSellerWithUuid(val["uuid"].asString());
if (sellerExist) {
continue;
}
auto seller = std::make_unique<Seller>();
seller->setUuidFromString(val["uuid"].asString());
seller->setSellerNo(val["seller_no"].asInt());
@ -80,6 +86,17 @@ void JsonUtil::exportSales(const fs::path& filePath, Marketplace* market, int ca
std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
// Do export sellers (maybe there are new sellers created during sale)
for (const auto& seller : market->getSellers()) {
Json::Value newEntry;
newEntry["uuid"] = seller->getUuidAsString();
newEntry["seller_no"] = seller->getSellerNo();
newEntry["last_name"] = seller->getLastName();
newEntry["first_name"] = seller->getFirstName();
newEntry["num_offered_articles"] = seller->numArticlesOffered();
root["sellers"].append(newEntry);
}
root["source_no"] = cashPointNo;
for (const auto& sale : market->getSales()) {
@ -110,6 +127,9 @@ void JsonUtil::exportSales(const fs::path& filePath, Marketplace* market, int ca
void JsonUtil::importSales(const fs::path& filePath, Marketplace* market, int cashPointNo)
{
// First import newly created sellers during the sale phase
importSellers(filePath, market, false);
Json::Value jsonValues;
std::ifstream file(filePath);
file >> jsonValues;

View file

@ -10,7 +10,7 @@ class JsonUtil
{
public:
static void exportSellers(const std::filesystem::path& filePath, Marketplace* market);
static void importSellers(const std::filesystem::path& filePath, Marketplace* market);
static void importSellers(const std::filesystem::path& filePath, Marketplace* market, bool cleanup = true);
static void exportSales(const std::filesystem::path& filePath, Marketplace* market, int cashPointNo);
static void importSales(const std::filesystem::path& filePath, Marketplace* market, int cashPointNo);
};

View file

@ -25,14 +25,14 @@ SellerDialog::SellerDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent,
void SellerDialog::on_newButton_clicked()
{
// Don't allow new seller if market has already started
if (market_->getSales().size() > 0) {
/* if (market_->getSales().size() > 0) {
QMessageBox(QMessageBox::Icon::Warning, "Hinweis",
"Da die Verkaufsphase schon begonnen hat (Artikel wurden bereits verkauft) "
"können Sie keine Verkäufer mehr hinzufügen.",
QMessageBox::StandardButton::Ok, this)
.exec();
return;
}
} */
ui_.tableView->reset();
ui_.tableView->model()->insertRows(ui_.tableView->model()->rowCount(), 1);