export sellers as json file
This commit is contained in:
parent
b2d696ccb5
commit
045bc8dd20
8 changed files with 80 additions and 11 deletions
|
@ -3,7 +3,8 @@ set(Boost_USE_STATIC_LIBS ON)
|
||||||
find_package(Boost 1.62 COMPONENTS date_time REQUIRED)
|
find_package(Boost 1.62 COMPONENTS date_time REQUIRED)
|
||||||
find_package(SQLite3 REQUIRED)
|
find_package(SQLite3 REQUIRED)
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_check_modules(XLNT REQUIRED xlnt)
|
pkg_check_modules(XLNT REQUIRED xlnt>=1.3)
|
||||||
|
pkg_check_modules(JSONCPP REQUIRED jsoncpp)
|
||||||
|
|
||||||
set(CORE_SOURCES
|
set(CORE_SOURCES
|
||||||
database.cpp
|
database.cpp
|
||||||
|
@ -13,10 +14,11 @@ set(CORE_SOURCES
|
||||||
sale.cpp
|
sale.cpp
|
||||||
marketplace.cpp
|
marketplace.cpp
|
||||||
excelreader.cpp
|
excelreader.cpp
|
||||||
|
jsonutil
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(core STATIC ${CORE_SOURCES})
|
add_library(core STATIC ${CORE_SOURCES})
|
||||||
target_link_libraries(core Boost::boost Boost::date_time sqlite3 ${XLNT_LIBRARIES})
|
target_link_libraries(core Boost::boost Boost::date_time sqlite3 ${XLNT_LIBRARIES} ${JSONCPP_LIBRARIES})
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
target_link_libraries(core bcrypt)
|
target_link_libraries(core bcrypt)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -8,15 +8,19 @@ void ExcelReader::readSellersFromFile(const std::string& filename, Marketplace*
|
||||||
wb.load(filename);
|
wb.load(filename);
|
||||||
auto ws = wb.sheet_by_index(0);
|
auto ws = wb.sheet_by_index(0);
|
||||||
|
|
||||||
const int START_ROW = 6;
|
const int START_ROW = 5;
|
||||||
const int END_ROW = 349;
|
const int END_ROW = 350;
|
||||||
|
|
||||||
int rowCount{};
|
int rowCount{};
|
||||||
for (const auto& row : ws.rows(false)) {
|
for (const auto& row : ws.rows(false)) {
|
||||||
// auto test = row[0].value<int>();
|
// auto test = row[0].value<int>();
|
||||||
if (rowCount < START_ROW)
|
if (rowCount < START_ROW) {
|
||||||
|
rowCount++;
|
||||||
continue;
|
continue;
|
||||||
std::cout << row[0].to_string() << "\n";
|
} else if (rowCount > END_ROW) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::cout << row[0].value<int>() << "\n";
|
||||||
rowCount++;
|
rowCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
31
src/core/jsonutil.cpp
Normal file
31
src/core/jsonutil.cpp
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#include "jsonutil.h"
|
||||||
|
|
||||||
|
#include <json/json.h>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
void JsonUtil::exportSellers(const std::string& filename, Marketplace* market)
|
||||||
|
{
|
||||||
|
Json::Value root;
|
||||||
|
std::ofstream file(filename);
|
||||||
|
|
||||||
|
Json::StreamWriterBuilder builder;
|
||||||
|
builder["commentStyle"] = "None";
|
||||||
|
builder["indentation"] = " ";
|
||||||
|
|
||||||
|
std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
|
||||||
|
|
||||||
|
root["encoding"] = "UTF-8";
|
||||||
|
|
||||||
|
for (const auto& seller : market->getSellers()) {
|
||||||
|
Json::Value newEntry;
|
||||||
|
newEntry["uuid"] = seller->getUuidAsString();
|
||||||
|
newEntry["seller_no"] = seller->getSellerNo();
|
||||||
|
newEntry["last_name"] = seller->getLastName();
|
||||||
|
newEntry["first_name"] = seller->getFirstName();
|
||||||
|
newEntry["num_offered_articles"] = seller->getFirstName();
|
||||||
|
root["sellers"].append(newEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
writer->write(root, &file);
|
||||||
|
}
|
14
src/core/jsonutil.h
Normal file
14
src/core/jsonutil.h
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef JSON_H
|
||||||
|
#define JSON_H
|
||||||
|
|
||||||
|
#include "marketplace.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class JsonUtil
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void exportSellers(const std::string& filename, Marketplace* market);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -14,8 +14,8 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
// Set the locale to german, so that currency is correct
|
// Set the locale to german, so that currency is correct
|
||||||
// std::locale german("de_DE.utf-8");
|
// std::locale german("de_DE.utf-8");
|
||||||
std::locale myLocale("");
|
//std::locale myLocale("");
|
||||||
std::locale::global(myLocale);
|
//std::locale::global(myLocale);
|
||||||
|
|
||||||
QApplication kimaApp{argc, argv};
|
QApplication kimaApp{argc, argv};
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "basketmodel.h"
|
#include "basketmodel.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "jsonutil.h"
|
||||||
#include "pricedialog.h"
|
#include "pricedialog.h"
|
||||||
#include "reportdialog.h"
|
#include "reportdialog.h"
|
||||||
#include "salemodel.h"
|
#include "salemodel.h"
|
||||||
|
@ -62,7 +63,9 @@ MainWindow::MainWindow()
|
||||||
QSettings().value("global/cashPointNo").toString());
|
QSettings().value("global/cashPointNo").toString());
|
||||||
});
|
});
|
||||||
connect(ui_.importExcelAction, &QAction::triggered, this,
|
connect(ui_.importExcelAction, &QAction::triggered, this,
|
||||||
&MainWindow::onImportExcelActionTriggered);
|
&MainWindow::onImportSellerExcelActionTriggered);
|
||||||
|
connect(ui_.exportSellerJsonAction, &QAction::triggered, this,
|
||||||
|
&MainWindow::onExportSellerJsonActionTriggered);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onActionEditSellerTriggered()
|
void MainWindow::onActionEditSellerTriggered()
|
||||||
|
@ -239,7 +242,7 @@ void MainWindow::onAbout()
|
||||||
">info@rustysoft.de</a>></p>");
|
">info@rustysoft.de</a>></p>");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onImportExcelActionTriggered()
|
void MainWindow::onImportSellerExcelActionTriggered()
|
||||||
{
|
{
|
||||||
if (!marketplace_->getSales().empty()) {
|
if (!marketplace_->getSales().empty()) {
|
||||||
QMessageBox(QMessageBox::Icon::Information, "Import nicht möglich",
|
QMessageBox(QMessageBox::Icon::Information, "Import nicht möglich",
|
||||||
|
@ -254,3 +257,11 @@ void MainWindow::onImportExcelActionTriggered()
|
||||||
|
|
||||||
ExcelReader::readSellersFromFile(filename.toStdString(), marketplace_.get());
|
ExcelReader::readSellersFromFile(filename.toStdString(), marketplace_.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::onExportSellerJsonActionTriggered()
|
||||||
|
{
|
||||||
|
auto filename = QFileDialog::getSaveFileName(this, "Verkäufer exportieren", QString(),
|
||||||
|
"JSON Dateien (*.json)");
|
||||||
|
|
||||||
|
JsonUtil::exportSellers(filename.toStdString(), marketplace_.get());
|
||||||
|
}
|
|
@ -32,7 +32,8 @@ class MainWindow : public QMainWindow
|
||||||
void onActionEditSellerTriggered();
|
void onActionEditSellerTriggered();
|
||||||
void onSellerNoEditCheckSellerNo();
|
void onSellerNoEditCheckSellerNo();
|
||||||
void onPaidButtonTriggered();
|
void onPaidButtonTriggered();
|
||||||
void onImportExcelActionTriggered();
|
void onImportSellerExcelActionTriggered();
|
||||||
|
void onExportSellerJsonActionTriggered();
|
||||||
void setSaleModel();
|
void setSaleModel();
|
||||||
|
|
||||||
Ui::MainWindow ui_;
|
Ui::MainWindow ui_;
|
||||||
|
|
|
@ -405,6 +405,7 @@ drucken</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionEditSeller"/>
|
<addaction name="actionEditSeller"/>
|
||||||
<addaction name="importExcelAction"/>
|
<addaction name="importExcelAction"/>
|
||||||
|
<addaction name="exportSellerJsonAction"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuHilfe">
|
<widget class="QMenu" name="menuHilfe">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
|
@ -464,6 +465,11 @@ drucken</string>
|
||||||
<string>Importieren (Excel)</string>
|
<string>Importieren (Excel)</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="exportSellerJsonAction">
|
||||||
|
<property name="text">
|
||||||
|
<string>Exportieren (JSON)</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|
Loading…
Reference in a new issue