importing sales started

This commit is contained in:
Martin Brodbeck 2018-08-02 15:28:35 +02:00
parent c82378dfa9
commit 0a91de4d86
5 changed files with 54 additions and 2 deletions

View file

@ -87,3 +87,18 @@ 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
}

View file

@ -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

View file

@ -12,6 +12,7 @@
#include <excelreader.h>
#include <regex>
#include <exception>
#include <QFileDialog>
#include <QMessageBox>
@ -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());
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();
}
}

View file

@ -36,6 +36,7 @@ class MainWindow : public QMainWindow
void onImportSellerJsonActionTriggered();
void onExportSellerJsonActionTriggered();
void onExportSalesJsonActionTriggered();
void onImportSalesJsonActionTriggered();
void setSaleModel();
Ui::MainWindow ui_;

View file

@ -426,6 +426,7 @@ drucken</string>
<string>&amp;Umsätze</string>
</property>
<addaction name="reportAction"/>
<addaction name="importSalesJsonAction"/>
<addaction name="exportSalesJsonAction"/>
</widget>
<addaction name="menu_Datei"/>
@ -488,6 +489,11 @@ drucken</string>
<string>Exportieren (JSON)</string>
</property>
</action>
<action name="importSalesJsonAction">
<property name="text">
<string>Importieren (JSON)</string>
</property>
</action>
</widget>
<resources/>
<connections/>