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,8 +31,7 @@ void JsonUtil::exportSellers(const std::string& filename, Marketplace* market)
void JsonUtil::importSellers(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); seller->setState(Seller::State::DELETE);
} }
market->storeToDb(true); market->storeToDb(true);
@ -52,3 +51,39 @@ void JsonUtil::importSellers(const std::string& filename, Marketplace* market)
} }
market->storeToDb(); 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: public:
static void exportSellers(const std::string& filename, Marketplace* market); static void exportSellers(const std::string& filename, Marketplace* market);
static void importSellers(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 #endif

View file

@ -68,6 +68,8 @@ MainWindow::MainWindow()
&MainWindow::onImportSellerJsonActionTriggered); &MainWindow::onImportSellerJsonActionTriggered);
connect(ui_.exportSellerJsonAction, &QAction::triggered, this, connect(ui_.exportSellerJsonAction, &QAction::triggered, this,
&MainWindow::onExportSellerJsonActionTriggered); &MainWindow::onExportSellerJsonActionTriggered);
connect(ui_.exportSalesJsonAction, &QAction::triggered, this,
&MainWindow::onExportSalesJsonActionTriggered);
} }
void MainWindow::onActionEditSellerTriggered() void MainWindow::onActionEditSellerTriggered()
@ -276,7 +278,6 @@ void MainWindow::onImportSellerJsonActionTriggered()
JsonUtil::importSellers(filename.toStdString(), marketplace_.get()); JsonUtil::importSellers(filename.toStdString(), marketplace_.get());
} }
void MainWindow::onExportSellerJsonActionTriggered() void MainWindow::onExportSellerJsonActionTriggered()
{ {
auto filename = QFileDialog::getSaveFileName(this, "Verkäufer exportieren", QString(), auto filename = QFileDialog::getSaveFileName(this, "Verkäufer exportieren", QString(),
@ -284,3 +285,12 @@ void MainWindow::onExportSellerJsonActionTriggered()
JsonUtil::exportSellers(filename.toStdString(), marketplace_.get()); 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());
}

View file

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

View file

@ -421,15 +421,16 @@ drucken</string>
<addaction name="aboutAction"/> <addaction name="aboutAction"/>
<addaction name="aboutQtAction"/> <addaction name="aboutQtAction"/>
</widget> </widget>
<widget class="QMenu" name="menuExtras"> <widget class="QMenu" name="menuSales">
<property name="title"> <property name="title">
<string>&amp;Extras</string> <string>&amp;Umsätze</string>
</property> </property>
<addaction name="reportAction"/> <addaction name="reportAction"/>
<addaction name="exportSalesJsonAction"/>
</widget> </widget>
<addaction name="menu_Datei"/> <addaction name="menu_Datei"/>
<addaction name="menu_Edit"/> <addaction name="menu_Edit"/>
<addaction name="menuExtras"/> <addaction name="menuSales"/>
<addaction name="menuHilfe"/> <addaction name="menuHilfe"/>
</widget> </widget>
<widget class="QStatusBar" name="statusbar"/> <widget class="QStatusBar" name="statusbar"/>
@ -482,6 +483,11 @@ drucken</string>
<string>Aus JSON-Datei</string> <string>Aus JSON-Datei</string>
</property> </property>
</action> </action>
<action name="exportSalesJsonAction">
<property name="text">
<string>Exportieren (JSON)</string>
</property>
</action>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>