diff --git a/.gitmodules b/.gitmodules index acf8bbe..d4f3b3c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,6 +4,3 @@ [submodule "3rdparty/singleapplication"] path = 3rdparty/singleapplication url = https://github.com/itay-grudev/SingleApplication.git -[submodule "3rdparty/csv-parser"] - path = 3rdparty/csv-parser - url = https://github.com/vincentlaucsb/csv-parser.git diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index 94fa640..ad35ca6 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -2,4 +2,3 @@ if(NOT KIMA2_USE_EXTERNAL_JSON) set(JSON_BuildTests OFF CACHE INTERNAL "") add_subdirectory(nlohmann_json EXCLUDE_FROM_ALL) endif() -add_subdirectory(csv-parser) diff --git a/3rdparty/csv-parser b/3rdparty/csv-parser deleted file mode 160000 index e4a899d..0000000 --- a/3rdparty/csv-parser +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e4a899dcafcfa14e448348e9b3c8c06d7697dbf8 diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 3d9fa92..cb0d4c1 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -18,20 +18,17 @@ set(CORE_SOURCES sale.cpp marketplace.cpp excelreader.cpp - csvreader.cpp jsonutil.cpp utils.cpp ) - add_library(core STATIC ${CORE_SOURCES}) -target_include_directories(core PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/csv-parser/include) + 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) 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() -#target_include_directories(core PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/csv-parser) target_include_directories(core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/core/csvreader.cpp b/src/core/csvreader.cpp deleted file mode 100644 index 285caa5..0000000 --- a/src/core/csvreader.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "csvreader.h" -#include "utils.h" - -#include -#include - -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().empty() && row[3].get().empty()) { - ++rowCount; - continue; - } - - auto seller = std::make_unique(); - seller->createUuid(); - seller->setSellerNo(row[0].get()); - if (row[1].is_int()) { - seller->setNumArticlesOffered(row[1].get()); - } else { - seller->setNumArticlesOffered(0); - } - std::string firstName = row[2].get(); - seller->setFirstName(trim(firstName)); - std::string lastName = row[3].get(); - 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->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 -} diff --git a/src/core/csvreader.h b/src/core/csvreader.h deleted file mode 100644 index 4c88551..0000000 --- a/src/core/csvreader.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef CSV_READER_H -#define CSV_READER_H - -#include "marketplace.h" -#include "seller.h" - -#include -#include -#include -#include - -class CsvReader -{ - public: - static std::size_t readSellersFromFile(const std::filesystem::path& filePath, Marketplace* market); -}; - -#endif \ No newline at end of file diff --git a/src/core/utils.cpp b/src/core/utils.cpp index 498e34f..ccb0d34 100644 --- a/src/core/utils.cpp +++ b/src/core/utils.cpp @@ -2,7 +2,6 @@ #include #include -#include std::string formatCentAsEuroString(const int cent, int width) { @@ -61,13 +60,4 @@ std::string& rtrim(std::string& str, const std::string& chars) std::string& trim(std::string& str, const std::string& 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 } \ No newline at end of file diff --git a/src/core/utils.h b/src/core/utils.h index 7ea6499..f227da4 100644 --- a/src/core/utils.h +++ b/src/core/utils.h @@ -13,6 +13,5 @@ std::optional convertToPosPrinterDevice(const std::string& vendor 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& trim(std::string& str, const std::string& chars = "\t\n\v\f\r "); -bool case_insensitive_match(std::string s1, std::string s2); #endif diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index c0fb637..1e63ea8 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include @@ -446,20 +445,14 @@ void MainWindow::onImportSellerExcelActionTriggered() .exec(); auto filename = QFileDialog::getOpenFileName(this, "Verkäufer importieren", QString(), - "Excel Dateien (*.xlsx);CSV Dateien (*.csv)"); + "Excel Dateien (*.xlsx *.xls)"); if (filename.isEmpty()) return; fs::path filePath(filename.toStdWString()); - std::size_t numImported{}; - if (case_insensitive_match(filePath.extension().string(), std::string("xslx"))) { - numImported = ExcelReader::readSellersFromFile(filePath, marketplace_.get()); - } else { - numImported = CsvReader::readSellersFromFile(filePath, marketplace_.get()); - } - + std::size_t numImported = ExcelReader::readSellersFromFile(filePath, marketplace_.get()); updateStatLabel(); using namespace std::string_literals;