Allow adding sellers during sale phase
This commit is contained in:
parent
1aa56f24a3
commit
04de363af5
3 changed files with 27 additions and 7 deletions
|
@ -31,18 +31,24 @@ void JsonUtil::exportSellers(const fs::path& filePath, Marketplace* market)
|
||||||
writer->write(root, &file);
|
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()) {
|
if (cleanup) {
|
||||||
seller->setState(Seller::State::DELETE);
|
for (auto& seller : market->getSellers()) {
|
||||||
|
seller->setState(Seller::State::DELETE);
|
||||||
|
}
|
||||||
|
market->storeToDb(true);
|
||||||
}
|
}
|
||||||
market->storeToDb(true);
|
|
||||||
|
|
||||||
Json::Value jsonValues;
|
Json::Value jsonValues;
|
||||||
std::ifstream file(filePath);
|
std::ifstream file(filePath);
|
||||||
file >> jsonValues;
|
file >> jsonValues;
|
||||||
|
|
||||||
for (auto val : jsonValues["sellers"]) {
|
for (auto val : jsonValues["sellers"]) {
|
||||||
|
auto sellerExist = market->findSellerWithUuid(val["uuid"].asString());
|
||||||
|
if (sellerExist) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
auto seller = std::make_unique<Seller>();
|
auto seller = std::make_unique<Seller>();
|
||||||
seller->setUuidFromString(val["uuid"].asString());
|
seller->setUuidFromString(val["uuid"].asString());
|
||||||
seller->setSellerNo(val["seller_no"].asInt());
|
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());
|
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;
|
root["source_no"] = cashPointNo;
|
||||||
|
|
||||||
for (const auto& sale : market->getSales()) {
|
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)
|
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;
|
Json::Value jsonValues;
|
||||||
std::ifstream file(filePath);
|
std::ifstream file(filePath);
|
||||||
file >> jsonValues;
|
file >> jsonValues;
|
||||||
|
|
|
@ -10,7 +10,7 @@ class JsonUtil
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void exportSellers(const std::filesystem::path& filePath, Marketplace* market);
|
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 exportSales(const std::filesystem::path& filePath, Marketplace* market, int cashPointNo);
|
||||||
static void importSales(const std::filesystem::path& filePath, Marketplace* market, int cashPointNo);
|
static void importSales(const std::filesystem::path& filePath, Marketplace* market, int cashPointNo);
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,14 +25,14 @@ SellerDialog::SellerDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent,
|
||||||
void SellerDialog::on_newButton_clicked()
|
void SellerDialog::on_newButton_clicked()
|
||||||
{
|
{
|
||||||
// Don't allow new seller if market has already started
|
// 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",
|
QMessageBox(QMessageBox::Icon::Warning, "Hinweis",
|
||||||
"Da die Verkaufsphase schon begonnen hat (Artikel wurden bereits verkauft) "
|
"Da die Verkaufsphase schon begonnen hat (Artikel wurden bereits verkauft) "
|
||||||
"können Sie keine Verkäufer mehr hinzufügen.",
|
"können Sie keine Verkäufer mehr hinzufügen.",
|
||||||
QMessageBox::StandardButton::Ok, this)
|
QMessageBox::StandardButton::Ok, this)
|
||||||
.exec();
|
.exec();
|
||||||
return;
|
return;
|
||||||
}
|
} */
|
||||||
|
|
||||||
ui_.tableView->reset();
|
ui_.tableView->reset();
|
||||||
ui_.tableView->model()->insertRows(ui_.tableView->model()->rowCount(), 1);
|
ui_.tableView->model()->insertRows(ui_.tableView->model()->rowCount(), 1);
|
||||||
|
|
Loading…
Reference in a new issue