Compare commits
3 commits
67643c665f
...
0a91de4d86
Author | SHA1 | Date | |
---|---|---|---|
0a91de4d86 | |||
c82378dfa9 | |||
dc54809146 |
6 changed files with 115 additions and 11 deletions
|
@ -18,14 +18,13 @@ void ExcelReader::readSellersFromFile(const std::string& filename, Marketplace*
|
|||
|
||||
int rowCount{};
|
||||
for (const auto& row : ws.rows(false)) {
|
||||
// auto test = row[0].value<int>();
|
||||
if (rowCount < START_ROW) {
|
||||
++rowCount;
|
||||
continue;
|
||||
} else if (rowCount > END_ROW) {
|
||||
break;
|
||||
}
|
||||
if(row[2].value<std::string>().empty() && row[3].value<std::string>().empty()) {
|
||||
if (row[2].value<std::string>().empty() && row[3].value<std::string>().empty()) {
|
||||
++rowCount;
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -31,8 +31,7 @@ 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);
|
||||
|
@ -41,7 +40,7 @@ void JsonUtil::importSellers(const std::string& filename, Marketplace* market)
|
|||
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());
|
||||
|
@ -52,3 +51,54 @@ void JsonUtil::importSellers(const std::string& filename, Marketplace* market)
|
|||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
}
|
|
@ -10,6 +10,8 @@ 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);
|
||||
static void importSales(const std::string& filename, Marketplace* market, int cashPointNo);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -12,6 +12,7 @@
|
|||
#include <excelreader.h>
|
||||
|
||||
#include <regex>
|
||||
#include <exception>
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
|
@ -68,6 +69,10 @@ MainWindow::MainWindow()
|
|||
&MainWindow::onImportSellerJsonActionTriggered);
|
||||
connect(ui_.exportSellerJsonAction, &QAction::triggered, this,
|
||||
&MainWindow::onExportSellerJsonActionTriggered);
|
||||
connect(ui_.exportSalesJsonAction, &QAction::triggered, this,
|
||||
&MainWindow::onExportSalesJsonActionTriggered);
|
||||
connect(ui_.importSalesJsonAction, &QAction::triggered, this,
|
||||
&MainWindow::onImportSalesJsonActionTriggered);
|
||||
}
|
||||
|
||||
void MainWindow::onActionEditSellerTriggered()
|
||||
|
@ -276,7 +281,6 @@ void MainWindow::onImportSellerJsonActionTriggered()
|
|||
JsonUtil::importSellers(filename.toStdString(), marketplace_.get());
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::onExportSellerJsonActionTriggered()
|
||||
{
|
||||
auto filename = QFileDialog::getSaveFileName(this, "Verkäufer exportieren", QString(),
|
||||
|
@ -284,3 +288,38 @@ void MainWindow::onExportSellerJsonActionTriggered()
|
|||
|
||||
JsonUtil::exportSellers(filename.toStdString(), marketplace_.get());
|
||||
}
|
||||
|
||||
void MainWindow::onExportSalesJsonActionTriggered()
|
||||
{
|
||||
QSettings settings;
|
||||
|
||||
auto filename = QFileDialog::getSaveFileName(this, "Umsätze/Transaktionen exportieren",
|
||||
QString(), "JSON Dateien (*.json)");
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@ class MainWindow : public QMainWindow
|
|||
void onImportSellerExcelActionTriggered();
|
||||
void onImportSellerJsonActionTriggered();
|
||||
void onExportSellerJsonActionTriggered();
|
||||
void onExportSalesJsonActionTriggered();
|
||||
void onImportSalesJsonActionTriggered();
|
||||
void setSaleModel();
|
||||
|
||||
Ui::MainWindow ui_;
|
||||
|
|
|
@ -421,15 +421,17 @@ drucken</string>
|
|||
<addaction name="aboutAction"/>
|
||||
<addaction name="aboutQtAction"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuExtras">
|
||||
<widget class="QMenu" name="menuSales">
|
||||
<property name="title">
|
||||
<string>&Extras</string>
|
||||
<string>&Umsätze</string>
|
||||
</property>
|
||||
<addaction name="reportAction"/>
|
||||
<addaction name="importSalesJsonAction"/>
|
||||
<addaction name="exportSalesJsonAction"/>
|
||||
</widget>
|
||||
<addaction name="menu_Datei"/>
|
||||
<addaction name="menu_Edit"/>
|
||||
<addaction name="menuExtras"/>
|
||||
<addaction name="menuSales"/>
|
||||
<addaction name="menuHilfe"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
|
@ -482,6 +484,16 @@ drucken</string>
|
|||
<string>Aus JSON-Datei</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="exportSalesJsonAction">
|
||||
<property name="text">
|
||||
<string>Exportieren (JSON)</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="importSalesJsonAction">
|
||||
<property name="text">
|
||||
<string>Importieren (JSON)</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
Loading…
Reference in a new issue