From 0a91de4d8697b6cfe0b7cf5b8bde96f23ec2c7d9 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Thu, 2 Aug 2018 15:28:35 +0200 Subject: [PATCH] importing sales started --- src/core/jsonutil.cpp | 15 +++++++++++++++ src/core/jsonutil.h | 1 + src/gui/mainwindow.cpp | 33 +++++++++++++++++++++++++++++++-- src/gui/mainwindow.h | 1 + src/gui/mainwindow.ui | 6 ++++++ 5 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/core/jsonutil.cpp b/src/core/jsonutil.cpp index 8935760..5acadee 100644 --- a/src/core/jsonutil.cpp +++ b/src/core/jsonutil.cpp @@ -86,4 +86,19 @@ void JsonUtil::exportSales(const std::string& filename, Marketplace* market, int } writer->write(root, &file); +} + +void JsonUtil::importSales(const std::string& filename, Marketplace* market, int cashPointNo) +{ + Json::Value jsonValues; + std::ifstream file(filename); + file >> jsonValues; + + int source_no = jsonValues["source_no"].asInt(); + if (source_no == cashPointNo) { + throw std::runtime_error("Die Kassen-Nr. der zu imporierenden Daten wird von dieser Kasse " + "hier bereits verwendet."); + } + + // TODO: Import sales } \ No newline at end of file diff --git a/src/core/jsonutil.h b/src/core/jsonutil.h index 45403e1..1f0335d 100644 --- a/src/core/jsonutil.h +++ b/src/core/jsonutil.h @@ -11,6 +11,7 @@ class JsonUtil 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); + static void importSales(const std::string& filename, Marketplace* market, int cashPointNo); }; #endif \ No newline at end of file diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 52247e6..8447b59 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -70,6 +71,8 @@ MainWindow::MainWindow() &MainWindow::onExportSellerJsonActionTriggered); connect(ui_.exportSalesJsonAction, &QAction::triggered, this, &MainWindow::onExportSalesJsonActionTriggered); + connect(ui_.importSalesJsonAction, &QAction::triggered, this, + &MainWindow::onImportSalesJsonActionTriggered); } void MainWindow::onActionEditSellerTriggered() @@ -292,5 +295,31 @@ void MainWindow::onExportSalesJsonActionTriggered() auto filename = QFileDialog::getSaveFileName(this, "Umsätze/Transaktionen exportieren", QString(), "JSON Dateien (*.json)"); - JsonUtil::exportSales(filename.toStdString(), marketplace_.get(), settings.value("global/cashPointNo").toInt()); -} \ No newline at end of file + JsonUtil::exportSales(filename.toStdString(), marketplace_.get(), + settings.value("global/cashPointNo").toInt()); +} + +void MainWindow::onImportSalesJsonActionTriggered() +{ + /* if (!marketplace_->getSales().empty()) { + QMessageBox(QMessageBox::Icon::Information, "Import nicht möglich", + "Der Import ist nicht möglich, da schon Verkäufe getätigt wurden.", + QMessageBox::StandardButton::Ok, this) + .exec(); + return; + } */ + + QSettings settings; + + auto filename = QFileDialog::getOpenFileName(this, "Umsätze/Transaktionen importieren", + QString(), "JSON Dateien (*.json)"); + + try { + JsonUtil::importSales(filename.toStdString(), marketplace_.get(), + settings.value("global/cashPointNo").toInt()); + } catch (std::runtime_error& err) { + QMessageBox(QMessageBox::Icon::Warning, "Import nicht möglich", err.what(), QMessageBox::Ok, + this) + .exec(); + } +} diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 300f039..f928e6b 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -36,6 +36,7 @@ class MainWindow : public QMainWindow void onImportSellerJsonActionTriggered(); void onExportSellerJsonActionTriggered(); void onExportSalesJsonActionTriggered(); + void onImportSalesJsonActionTriggered(); void setSaleModel(); Ui::MainWindow ui_; diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 6af5b36..2e7d874 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -426,6 +426,7 @@ drucken &Umsätze + @@ -488,6 +489,11 @@ drucken Exportieren (JSON) + + + Importieren (JSON) + +