Compare commits

..

No commits in common. "8265212c114c9ac0684acb608a3208637db99c1c" and "79f1065868dfa3e8447867a166c65ae0fed15d32" have entirely different histories.

9 changed files with 5 additions and 115 deletions

3
.gitmodules vendored
View file

@ -4,6 +4,3 @@
[submodule "3rdparty/singleapplication"] [submodule "3rdparty/singleapplication"]
path = 3rdparty/singleapplication path = 3rdparty/singleapplication
url = https://github.com/itay-grudev/SingleApplication.git url = https://github.com/itay-grudev/SingleApplication.git
[submodule "3rdparty/csv-parser"]
path = 3rdparty/csv-parser
url = https://github.com/vincentlaucsb/csv-parser.git

View file

@ -2,4 +2,3 @@ if(NOT KIMA2_USE_EXTERNAL_JSON)
set(JSON_BuildTests OFF CACHE INTERNAL "") set(JSON_BuildTests OFF CACHE INTERNAL "")
add_subdirectory(nlohmann_json EXCLUDE_FROM_ALL) add_subdirectory(nlohmann_json EXCLUDE_FROM_ALL)
endif() endif()
add_subdirectory(csv-parser)

1
3rdparty/csv-parser vendored

@ -1 +0,0 @@
Subproject commit e4a899dcafcfa14e448348e9b3c8c06d7697dbf8

View file

@ -18,20 +18,17 @@ set(CORE_SOURCES
sale.cpp sale.cpp
marketplace.cpp marketplace.cpp
excelreader.cpp excelreader.cpp
csvreader.cpp
jsonutil.cpp jsonutil.cpp
utils.cpp utils.cpp
) )
add_library(core STATIC ${CORE_SOURCES}) add_library(core STATIC ${CORE_SOURCES})
target_include_directories(core PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/csv-parser/include)
if (WIN32) if (WIN32)
target_link_libraries(core PRIVATE printer Boost::boost Boost::date_time sqlite3 nlohmann_json::nlohmann_json ${XLNT_LIBRARY} csv) target_link_libraries(core PRIVATE printer Boost::boost Boost::date_time sqlite3 nlohmann_json::nlohmann_json ${XLNT_LIBRARY})
target_link_libraries(core PRIVATE bcrypt) target_link_libraries(core PRIVATE bcrypt)
else() else()
target_link_libraries(core PRIVATE printer Boost::boost Boost::date_time sqlite3 nlohmann_json::nlohmann_json ${XLNT_LIBRARIES} csv) target_link_libraries(core PRIVATE printer Boost::boost Boost::date_time sqlite3 nlohmann_json::nlohmann_json ${XLNT_LIBRARIES})
endif() endif()
#target_include_directories(core PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/csv-parser)
target_include_directories(core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

View file

@ -1,66 +0,0 @@
#include "csvreader.h"
#include "utils.h"
#include <fstream>
#include <csv.hpp>
namespace fs = std::filesystem;
std::size_t CsvReader::readSellersFromFile(const fs::path& filePath, Marketplace* market)
{
csv::CSVFormat format;
format.delimiter(';');
csv::CSVReader csvReader(filePath.string(), format);
for (auto& seller : market->getSellers()) {
seller->setState(Seller::State::DELETE);
}
market->storeToDb(true);
int rowCount{};
for (csv::CSVRow &row : csvReader) {
if (!row[0].is_int()) {
++rowCount;
continue;
}
if (row[2].get<std::string>().empty() && row[3].get<std::string>().empty()) {
++rowCount;
continue;
}
auto seller = std::make_unique<Seller>();
seller->createUuid();
seller->setSellerNo(row[0].get<int>());
if (row[1].is_int()) {
seller->setNumArticlesOffered(row[1].get<int>());
} else {
seller->setNumArticlesOffered(0);
}
std::string firstName = row[2].get<std::string>();
seller->setFirstName(trim(firstName));
std::string lastName = row[3].get<std::string>();
seller->setLastName(trim(lastName));
market->getSellers().push_back(std::move(seller));
rowCount++;
}
// If there was no special seller "Sonderkonto" in import data, then create one
auto specialSeller = market->findSellerWithUuid("11111111-1111-1111-1111-111111111111");
if (!specialSeller) {
auto seller = std::make_unique<Seller>();
seller->setUuidFromString("11111111-1111-1111-1111-111111111111");
seller->setSellerNo(0);
seller->setLastName("Sonderkonto");
seller->setFirstName("Sonderkonto");
seller->setNumArticlesOffered(0);
market->getSellers().push_back(std::move(seller));
}
market->sortSellers();
market->storeToDb();
return market->getSellers().size() - 1; // minus 1 because we don't count the "special" seller
}

View file

@ -1,18 +0,0 @@
#ifndef CSV_READER_H
#define CSV_READER_H
#include "marketplace.h"
#include "seller.h"
#include <filesystem>
#include <memory>
#include <string>
#include <vector>
class CsvReader
{
public:
static std::size_t readSellersFromFile(const std::filesystem::path& filePath, Marketplace* market);
};
#endif

View file

@ -2,7 +2,6 @@
#include <iomanip> #include <iomanip>
#include <numeric> #include <numeric>
#include <algorithm>
std::string formatCentAsEuroString(const int cent, int width) std::string formatCentAsEuroString(const int cent, int width)
{ {
@ -62,12 +61,3 @@ std::string& trim(std::string& str, const std::string& chars)
{ {
return ltrim(rtrim(str, chars), chars); return ltrim(rtrim(str, chars), chars);
} }
bool case_insensitive_match(std::string s1, std::string s2) {
//convert s1 and s2 into lower case strings
transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
if(s1.compare(s2) == 0)
return true; //The strings are same
return false; //not matched
}

View file

@ -13,6 +13,5 @@ std::optional<PrinterDevice> convertToPosPrinterDevice(const std::string& vendor
std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r "); std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r ");
std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r "); std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ");
std::string& trim(std::string& str, const std::string& chars = "\t\n\v\f\r "); std::string& trim(std::string& str, const std::string& chars = "\t\n\v\f\r ");
bool case_insensitive_match(std::string s1, std::string s2);
#endif #endif

View file

@ -12,7 +12,6 @@
#include <utils.h> #include <utils.h>
#include <excelreader.h> #include <excelreader.h>
#include <csvreader.h>
#include <posprinter.h> #include <posprinter.h>
#include <exception> #include <exception>
@ -446,20 +445,14 @@ void MainWindow::onImportSellerExcelActionTriggered()
.exec(); .exec();
auto filename = QFileDialog::getOpenFileName(this, "Verkäufer importieren", QString(), auto filename = QFileDialog::getOpenFileName(this, "Verkäufer importieren", QString(),
"Excel Dateien (*.xlsx);CSV Dateien (*.csv)"); "Excel Dateien (*.xlsx *.xls)");
if (filename.isEmpty()) if (filename.isEmpty())
return; return;
fs::path filePath(filename.toStdWString()); fs::path filePath(filename.toStdWString());
std::size_t numImported{}; std::size_t numImported = ExcelReader::readSellersFromFile(filePath, marketplace_.get());
if (case_insensitive_match(filePath.extension().string(), std::string("xslx"))) {
numImported = ExcelReader::readSellersFromFile(filePath, marketplace_.get());
} else {
numImported = CsvReader::readSellersFromFile(filePath, marketplace_.get());
}
updateStatLabel(); updateStatLabel();
using namespace std::string_literals; using namespace std::string_literals;