export sales works now

This commit is contained in:
Martin Brodbeck 2018-08-02 15:06:35 +02:00
parent dc54809146
commit c82378dfa9
5 changed files with 61 additions and 8 deletions

View file

@ -31,17 +31,16 @@ void JsonUtil::exportSellers(const std::string& filename, Marketplace* market)
void JsonUtil::importSellers(const std::string& filename, Marketplace* market)
{
for (auto& seller : market->getSellers())
{
for (auto& seller : market->getSellers()) {
seller->setState(Seller::State::DELETE);
}
market->storeToDb(true);
Json::Value jsonValues;
std::ifstream file(filename);
file >> jsonValues;
for(auto val : jsonValues["sellers"]) {
for (auto val : jsonValues["sellers"]) {
auto seller = std::make_unique<Seller>();
seller->setUuidFromString(val["uuid"].asString());
seller->setSellerNo(val["seller_no"].asInt());
@ -51,4 +50,40 @@ void JsonUtil::importSellers(const std::string& filename, Marketplace* market)
market->getSellers().push_back(std::move(seller));
}
market->storeToDb();
}
void JsonUtil::exportSales(const std::string& filename, Marketplace* market, int cashPointNo)
{
Json::Value root;
std::ofstream file(filename);
Json::StreamWriterBuilder builder;
builder["commentStyle"] = "None";
builder["indentation"] = " ";
std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
root["source_no"] = cashPointNo;
for (const auto& sale : market->getSales()) {
Json::Value newSale;
newSale["uuid"] = sale->getUuidAsString();
newSale["timestamp"] = sale->getTimestamp();
for (const auto& article : sale->getArticles()) {
Json::Value newArticle;
newArticle["uuid"] = article->getUuidAsString();
newArticle["seller_uuid"] = article->getSeller()->getUuidAsString();
newArticle["desc"] = article->getDescription();
newArticle["price"] = article->getPrice();
// newArticle["source_no"] = article->getSourceNo();
newArticle["article_no"] = article->getArticleNo();
newSale["articles"].append(newArticle);
}
root["sales"].append(newSale);
}
writer->write(root, &file);
}

View file

@ -10,6 +10,7 @@ class JsonUtil
public:
static void exportSellers(const std::string& filename, Marketplace* market);
static void importSellers(const std::string& filename, Marketplace* market);
static void exportSales(const std::string& filename, Marketplace* market, int cashPointNo);
};
#endif