import export nearly finished
This commit is contained in:
parent
de91a804a0
commit
3ba230d9b9
5 changed files with 72 additions and 5 deletions
|
@ -491,8 +491,6 @@ unsigned int Database::storeSales(std::vector<std::unique_ptr<Sale>>& sales)
|
||||||
++count;
|
++count;
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maybe not necessary (because of DELETE CASCADE): Delete here individual articles
|
|
||||||
}
|
}
|
||||||
|
|
||||||
endTransaction();
|
endTransaction();
|
||||||
|
|
|
@ -66,6 +66,9 @@ void JsonUtil::exportSales(const std::string& filename, Marketplace* market, int
|
||||||
root["source_no"] = cashPointNo;
|
root["source_no"] = cashPointNo;
|
||||||
|
|
||||||
for (const auto& sale : market->getSales()) {
|
for (const auto& sale : market->getSales()) {
|
||||||
|
if (sale->getSourceNo() != cashPointNo)
|
||||||
|
continue;
|
||||||
|
|
||||||
Json::Value newSale;
|
Json::Value newSale;
|
||||||
newSale["uuid"] = sale->getUuidAsString();
|
newSale["uuid"] = sale->getUuidAsString();
|
||||||
newSale["timestamp"] = sale->getTimestamp();
|
newSale["timestamp"] = sale->getTimestamp();
|
||||||
|
@ -100,5 +103,33 @@ void JsonUtil::importSales(const std::string& filename, Marketplace* market, int
|
||||||
"hier bereits verwendet.");
|
"hier bereits verwendet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Import sales
|
market->setSalesToDelete(jsonValues["source_no"].asInt());
|
||||||
|
market->storeToDb();
|
||||||
|
|
||||||
|
for (const auto& valSale : jsonValues["sales"]) {
|
||||||
|
auto sale = std::make_unique<Sale>();
|
||||||
|
sale->setUuidFromString(valSale["uuid"].asString());
|
||||||
|
sale->setSourceNo(jsonValues["source_no"].asInt());
|
||||||
|
sale->setTimestamp(valSale["timestamp"].asString());
|
||||||
|
for (const auto& valArticle : valSale["articles"]) {
|
||||||
|
auto article = std::make_unique<Article>();
|
||||||
|
article->setUuidFromString(valArticle["uuid"].asString());
|
||||||
|
article->setSourceNo(jsonValues["source_no"].asInt());
|
||||||
|
article->setArticleNo(valArticle["article_no"].asInt());
|
||||||
|
article->setDescription(valArticle["desc"].asString());
|
||||||
|
article->setPrice(valArticle["price"].asInt());
|
||||||
|
auto seller = market->findSellerWithUuid(valArticle["seller_uuid"].asString());
|
||||||
|
if (seller == nullptr) {
|
||||||
|
throw std::runtime_error(
|
||||||
|
"Die zu importierenden Daten verweisen auf einen nicht vorhandenen Verkäufer. "
|
||||||
|
"Die Daten konnten nicht importiert werden.");
|
||||||
|
// continue;
|
||||||
|
}
|
||||||
|
sale->addArticle(article.get());
|
||||||
|
seller->addArticle(std::move(article));
|
||||||
|
}
|
||||||
|
market->getSales().push_back(std::move(sale));
|
||||||
|
}
|
||||||
|
|
||||||
|
market->storeToDb();
|
||||||
}
|
}
|
|
@ -84,6 +84,15 @@ Seller* Marketplace::findSellerWithSellerNo(int sellerNo)
|
||||||
return (*iter).get();
|
return (*iter).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Seller* Marketplace::findSellerWithUuid(const std::string& uuid)
|
||||||
|
{
|
||||||
|
auto iter = std::find_if(sellers_.begin(), sellers_.end(),
|
||||||
|
[uuid](const auto& a) { return a->getUuidAsString() == uuid; });
|
||||||
|
if (iter == sellers_.end())
|
||||||
|
return nullptr;
|
||||||
|
return (*iter).get();
|
||||||
|
}
|
||||||
|
|
||||||
void Marketplace::addArticleToBasket(std::unique_ptr<Article> article)
|
void Marketplace::addArticleToBasket(std::unique_ptr<Article> article)
|
||||||
{
|
{
|
||||||
basket_.push_back(std::move(article));
|
basket_.push_back(std::move(article));
|
||||||
|
@ -129,6 +138,18 @@ void Marketplace::removeSale(boost::uuids::uuid uuid)
|
||||||
sales_.end());
|
sales_.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Marketplace::setSalesToDelete(int cashPointNo)
|
||||||
|
{
|
||||||
|
std::for_each(sales_.begin(), sales_.end(), [cashPointNo](auto& sale) {
|
||||||
|
if (sale->getSourceNo() == cashPointNo) {
|
||||||
|
sale->setState(Sale::State::DELETE);
|
||||||
|
for (auto& article : sale->getArticles()) {
|
||||||
|
article->setState(Article::State::DELETE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void Marketplace::exportReportToCSV(const std::string& filename, int feeInPercent, int maxFeeInEuro)
|
void Marketplace::exportReportToCSV(const std::string& filename, int feeInPercent, int maxFeeInEuro)
|
||||||
{
|
{
|
||||||
const char delimiter = ',';
|
const char delimiter = ',';
|
||||||
|
|
|
@ -35,10 +35,12 @@ class Marketplace
|
||||||
|
|
||||||
void sortSellers();
|
void sortSellers();
|
||||||
Seller* findSellerWithSellerNo(int sellerNo);
|
Seller* findSellerWithSellerNo(int sellerNo);
|
||||||
|
Seller* findSellerWithUuid(const std::string& uuid);
|
||||||
void addArticleToBasket(std::unique_ptr<Article> article);
|
void addArticleToBasket(std::unique_ptr<Article> article);
|
||||||
size_t basketSize();
|
size_t basketSize();
|
||||||
void finishCurrentSale(std::unique_ptr<Sale> sale);
|
void finishCurrentSale(std::unique_ptr<Sale> sale);
|
||||||
void removeSale(boost::uuids::uuid uuid);
|
void removeSale(boost::uuids::uuid uuid);
|
||||||
|
void setSalesToDelete(int cashPointNo);
|
||||||
|
|
||||||
int getOverallSumInCent();
|
int getOverallSumInCent();
|
||||||
std::string getOverallSumAsString();
|
std::string getOverallSumAsString();
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
|
|
||||||
#include <excelreader.h>
|
#include <excelreader.h>
|
||||||
|
|
||||||
#include <regex>
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
@ -278,6 +278,9 @@ void MainWindow::onImportSellerJsonActionTriggered()
|
||||||
auto filename = QFileDialog::getOpenFileName(this, "Verkäufer importieren", QString(),
|
auto filename = QFileDialog::getOpenFileName(this, "Verkäufer importieren", QString(),
|
||||||
"JSON Dateien (*.json)");
|
"JSON Dateien (*.json)");
|
||||||
|
|
||||||
|
if (filename.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
JsonUtil::importSellers(filename.toStdString(), marketplace_.get());
|
JsonUtil::importSellers(filename.toStdString(), marketplace_.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,6 +289,9 @@ void MainWindow::onExportSellerJsonActionTriggered()
|
||||||
auto filename = QFileDialog::getSaveFileName(this, "Verkäufer exportieren", QString(),
|
auto filename = QFileDialog::getSaveFileName(this, "Verkäufer exportieren", QString(),
|
||||||
"JSON Dateien (*.json)");
|
"JSON Dateien (*.json)");
|
||||||
|
|
||||||
|
if (filename.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
JsonUtil::exportSellers(filename.toStdString(), marketplace_.get());
|
JsonUtil::exportSellers(filename.toStdString(), marketplace_.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,6 +301,10 @@ void MainWindow::onExportSalesJsonActionTriggered()
|
||||||
|
|
||||||
auto filename = QFileDialog::getSaveFileName(this, "Umsätze/Transaktionen exportieren",
|
auto filename = QFileDialog::getSaveFileName(this, "Umsätze/Transaktionen exportieren",
|
||||||
QString(), "JSON Dateien (*.json)");
|
QString(), "JSON Dateien (*.json)");
|
||||||
|
|
||||||
|
if (filename.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
JsonUtil::exportSales(filename.toStdString(), marketplace_.get(),
|
JsonUtil::exportSales(filename.toStdString(), marketplace_.get(),
|
||||||
settings.value("global/cashPointNo").toInt());
|
settings.value("global/cashPointNo").toInt());
|
||||||
}
|
}
|
||||||
|
@ -314,12 +324,17 @@ void MainWindow::onImportSalesJsonActionTriggered()
|
||||||
auto filename = QFileDialog::getOpenFileName(this, "Umsätze/Transaktionen importieren",
|
auto filename = QFileDialog::getOpenFileName(this, "Umsätze/Transaktionen importieren",
|
||||||
QString(), "JSON Dateien (*.json)");
|
QString(), "JSON Dateien (*.json)");
|
||||||
|
|
||||||
|
if (filename.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
delete ui_.salesView->model();
|
||||||
try {
|
try {
|
||||||
JsonUtil::importSales(filename.toStdString(), marketplace_.get(),
|
JsonUtil::importSales(filename.toStdString(), marketplace_.get(),
|
||||||
settings.value("global/cashPointNo").toInt());
|
settings.value("global/cashPointNo").toInt());
|
||||||
} catch (std::runtime_error& err) {
|
} catch (std::runtime_error& err) {
|
||||||
QMessageBox(QMessageBox::Icon::Warning, "Import nicht möglich", err.what(), QMessageBox::Ok,
|
QMessageBox(QMessageBox::Icon::Warning, "Import nicht möglich", err.what(), QMessageBox::Ok,
|
||||||
this)
|
this)
|
||||||
.exec();
|
.exec();
|
||||||
}
|
}
|
||||||
|
setSaleModel();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue