diff --git a/src/core/article.cpp b/src/core/article.cpp index 6309b32..6137549 100644 --- a/src/core/article.cpp +++ b/src/core/article.cpp @@ -11,18 +11,18 @@ void Article::setArticleNo(int articleNo) { m_articleNo = articleNo; } void Article::setPrice(int price) { m_price = price; } -void Article::setDescription(const std::string& description) { m_description = description; } +void Article::setDescription(const std::string &description) { m_description = description; } -void Article::setSale(Sale* salePtr) { m_salePtr = salePtr; } +void Article::setSale(Sale *salePtr) { m_salePtr = salePtr; } -void Article::setSeller(Seller* sellerPtr) { m_sellerPtr = sellerPtr; } +void Article::setSeller(Seller *sellerPtr) { m_sellerPtr = sellerPtr; } bool Article::isSold() { return m_salePtr ? true : false; } std::string Article::getDescription() { return m_description; } -Seller* Article::getSeller() { return m_sellerPtr; } -Sale* Article::getSale() { return m_salePtr; } +Seller *Article::getSeller() { return m_sellerPtr; } +Sale *Article::getSale() { return m_salePtr; } int Article::getPrice() const { return m_price; } diff --git a/src/core/article.h b/src/core/article.h index 30e7292..c9be086 100644 --- a/src/core/article.h +++ b/src/core/article.h @@ -11,30 +11,30 @@ class Sale; class Article : public EntityUuid { - public: +public: Article() = default; Article(int price); - Article(const Article&) = delete; + Article(const Article &) = delete; virtual ~Article() = default; void setArticleNo(int articleNo); void setPrice(int price); - void setDescription(const std::string& description); + void setDescription(const std::string &description); bool isSold(); - void setSale(Sale* salePtr); - void setSeller(Seller* sellerPtr); + void setSale(Sale *salePtr); + void setSeller(Seller *sellerPtr); int getArticleNo() const; std::string getCompleteArticleNo() const; std::string getDescription(); - Seller* getSeller(); - Sale* getSale(); + Seller *getSeller(); + Sale *getSale(); int getPrice() const; std::string getPriceAsString() const; - private: - Seller* m_sellerPtr{}; - Sale* m_salePtr{}; +private: + Seller *m_sellerPtr{}; + Sale *m_salePtr{}; int m_articleNo{}; int m_price{}; std::string m_description{}; diff --git a/src/core/csvreader.cpp b/src/core/csvreader.cpp index 6c384f7..18a0a04 100644 --- a/src/core/csvreader.cpp +++ b/src/core/csvreader.cpp @@ -11,7 +11,7 @@ namespace fs = std::filesystem; -std::size_t CsvReader::readSellersFromFile(const fs::path& filePath, Marketplace* market) +std::size_t CsvReader::readSellersFromFile(const fs::path &filePath, Marketplace *market) { csv::CSVFormat format; format.delimiter(';'); @@ -26,18 +26,18 @@ std::size_t CsvReader::readSellersFromFile(const fs::path& filePath, Marketplace csv::CSVReader csvReader(filePath.string(), format); #endif - for (auto& seller : market->getSellers()) { + 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; diff --git a/src/core/csvreader.h b/src/core/csvreader.h index 1f9d924..ff1901a 100644 --- a/src/core/csvreader.h +++ b/src/core/csvreader.h @@ -11,9 +11,9 @@ class CsvReader { - public: - static std::size_t readSellersFromFile(const std::filesystem::path& filePath, - Marketplace* market); +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/database.cpp b/src/core/database.cpp index 9d0df7d..f9ba43e 100644 --- a/src/core/database.cpp +++ b/src/core/database.cpp @@ -7,7 +7,7 @@ #include "boost/date_time/posix_time/posix_time.hpp" -Database::Database(const std::string& dbname) +Database::Database(const std::string &dbname) { dbname_ = dbname; init(); @@ -28,7 +28,7 @@ Database::Database() if (!fs::exists(dbpath)) { try { fs::create_directories(dbpath); - } catch (fs::filesystem_error& err) { + } catch (fs::filesystem_error &err) { throw err; } } @@ -57,9 +57,9 @@ void Database::newDb() Database::~Database() { sqlite3_close(db_); } -void Database::exec(const std::string& sql) +void Database::exec(const std::string &sql) { - char* errMsg; + char *errMsg; const int errCode = sqlite3_exec(db_, sql.c_str(), nullptr, nullptr, &errMsg); if (errCode) { std::string errMsgString(errMsg); // Make a C++ string of the errMsg, so that we can call @@ -120,7 +120,7 @@ void Database::createNew() sqlStrings.push_back(sqlInitialEntries); beginTransaction(); - for (const auto& sql : sqlStrings) { + for (const auto &sql : sqlStrings) { exec(sql); } endTransaction(); @@ -173,7 +173,7 @@ void Database::init() int Database::getVersion() { int retCode{}; - sqlite3_stmt* stmt; + sqlite3_stmt *stmt; // Check if there's already a kima2 table available. // If not, return version == 0. @@ -220,15 +220,15 @@ void Database::beginTransaction() { exec("BEGIN TRANSACTION"); } void Database::endTransaction() { exec("END TRANSACTION"); } -unsigned int Database::storeSellers(std::vector>& sellers, bool onlyDelete) +unsigned int Database::storeSellers(std::vector> &sellers, bool onlyDelete) { int retCode{}; int count{}; - sqlite3_stmt* stmt; + sqlite3_stmt *stmt; beginTransaction(); - for (auto& seller : sellers) { + for (auto &seller : sellers) { if (seller->getState() == Seller::State::NEW && !onlyDelete) { retCode = sqlite3_prepare_v2( db_, @@ -323,12 +323,12 @@ unsigned int Database::storeSellers(std::vector>& seller // Everything went fine, so we can now update our objects sellers.erase(std::remove_if(sellers.begin(), sellers.end(), - [](const std::unique_ptr& seller) { + [](const std::unique_ptr &seller) { return (seller->getState() == Seller::State::DELETE); }), sellers.end()); - for (auto& seller : sellers) { + for (auto &seller : sellers) { seller->cleanupArticles(); seller->setState(Seller::State::OK); } @@ -336,13 +336,13 @@ unsigned int Database::storeSellers(std::vector>& seller return count; } -unsigned int Database::storeArticles(std::vector articles) +unsigned int Database::storeArticles(std::vector
articles) { int retCode{}; int count{}; - sqlite3_stmt* stmt; + sqlite3_stmt *stmt; - for (auto& article : articles) { + for (auto &article : articles) { if (article->getState() == Article::State::NEW) { retCode = sqlite3_prepare_v2( db_, @@ -441,18 +441,18 @@ unsigned int Database::storeArticles(std::vector articles) return count; } -unsigned int Database::storeSales(std::vector>& sales) +unsigned int Database::storeSales(std::vector> &sales) { int retCode{}; int count{}; - sqlite3_stmt* stmt; + sqlite3_stmt *stmt; if (sales.size() == 0) return 0; beginTransaction(); - for (auto& sale : sales) { + for (auto &sale : sales) { if (sale->getState() == Sale::State::NEW) { retCode = sqlite3_prepare_v2(db_, "INSERT INTO sales" @@ -482,7 +482,7 @@ unsigned int Database::storeSales(std::vector>& sales) ++count; sqlite3_finalize(stmt); - for (const auto& article : sale->getArticles()) { + for (const auto &article : sale->getArticles()) { retCode = sqlite3_prepare_v2(db_, "INSERT INTO sales_items" " (sale_id, article_id)" @@ -535,21 +535,21 @@ unsigned int Database::storeSales(std::vector>& sales) // Everything went fine, so we can now update our objects sales.erase( std::remove_if(sales.begin(), sales.end(), - [](const auto& sale) { return (sale->getState() == Sale::State::DELETE); }), + [](const auto &sale) { return (sale->getState() == Sale::State::DELETE); }), sales.end()); - for (auto& sale : sales) { + for (auto &sale : sales) { sale->setState(Sale::State::OK); } return count; } -unsigned int Database::loadSellers(std::vector>& sellers) +unsigned int Database::loadSellers(std::vector> &sellers) { int retCode{}; int count{}; - sqlite3_stmt* stmt; + sqlite3_stmt *stmt; retCode = sqlite3_prepare_v2(db_, "SELECT seller_no, first_name, last_name, " @@ -566,8 +566,8 @@ unsigned int Database::loadSellers(std::vector>& sellers ++count; auto seller = std::make_unique(); seller->setSellerNo(sqlite3_column_int(stmt, 0)); - seller->setFirstName(reinterpret_cast(sqlite3_column_text(stmt, 1))); - seller->setLastName(reinterpret_cast(sqlite3_column_text(stmt, 2))); + seller->setFirstName(reinterpret_cast(sqlite3_column_text(stmt, 1))); + seller->setLastName(reinterpret_cast(sqlite3_column_text(stmt, 2))); seller->setNumArticlesOffered(sqlite3_column_int(stmt, 3)); seller->setState(Seller::State::OK); sellers.push_back(std::move(seller)); @@ -577,7 +577,7 @@ unsigned int Database::loadSellers(std::vector>& sellers sqlite3_finalize(stmt); - for (auto& seller : sellers) { + for (auto &seller : sellers) { retCode = sqlite3_prepare_v2(db_, "SELECT id, source_no, article_no, description, price" " FROM articles" @@ -594,11 +594,12 @@ unsigned int Database::loadSellers(std::vector>& sellers while (retCode != SQLITE_DONE) { ++count; auto article = std::make_unique
(); - article->setUuidFromString(reinterpret_cast(sqlite3_column_text(stmt, 0))); + article->setUuidFromString( + reinterpret_cast(sqlite3_column_text(stmt, 0))); article->setSeller(seller.get()); article->setSourceNo(sqlite3_column_int(stmt, 1)); article->setArticleNo(sqlite3_column_int(stmt, 2)); - article->setDescription(reinterpret_cast(sqlite3_column_text(stmt, 3))); + article->setDescription(reinterpret_cast(sqlite3_column_text(stmt, 3))); article->setPrice(sqlite3_column_int(stmt, 4)); article->setState(Article::State::OK); @@ -613,12 +614,12 @@ unsigned int Database::loadSellers(std::vector>& sellers return count; } -unsigned int Database::loadSales(std::vector>& sales, - std::vector>& sellers) +unsigned int Database::loadSales(std::vector> &sales, + std::vector> &sellers) { int retCode{}; int count{}; - sqlite3_stmt* stmt; + sqlite3_stmt *stmt; retCode = sqlite3_prepare_v2(db_, "SELECT id, source_no, sold_at" @@ -631,13 +632,13 @@ unsigned int Database::loadSales(std::vector>& sales, sales.clear(); - std::map saleMap; + std::map saleMap; while (retCode != SQLITE_DONE) { ++count; auto sale = std::make_unique(); - sale->setUuidFromString(reinterpret_cast(sqlite3_column_text(stmt, 0))); + sale->setUuidFromString(reinterpret_cast(sqlite3_column_text(stmt, 0))); sale->setSourceNo(sqlite3_column_int(stmt, 1)); - sale->setTimestamp(reinterpret_cast(sqlite3_column_text(stmt, 2))); + sale->setTimestamp(reinterpret_cast(sqlite3_column_text(stmt, 2))); sale->setState(Sale::State::OK); saleMap.insert(std::make_pair(sale->getUuidAsString(), sale.get())); sales.push_back(std::move(sale)); @@ -647,8 +648,8 @@ unsigned int Database::loadSales(std::vector>& sales, sqlite3_finalize(stmt); - std::map artMap; - for (const auto& seller : sellers) { + std::map artMap; + for (const auto &seller : sellers) { for (const auto article : seller->getArticles(false)) { artMap.insert(std::make_pair(article->getUuidAsString(), article)); } @@ -664,8 +665,8 @@ unsigned int Database::loadSales(std::vector>& sales, retCode = sqlite3_step(stmt); while (retCode != SQLITE_DONE) { - saleMap[reinterpret_cast(sqlite3_column_text(stmt, 0))]->addArticle( - artMap[reinterpret_cast(sqlite3_column_text(stmt, 1))]); + saleMap[reinterpret_cast(sqlite3_column_text(stmt, 0))]->addArticle( + artMap[reinterpret_cast(sqlite3_column_text(stmt, 1))]); retCode = sqlite3_step(stmt); } @@ -678,7 +679,7 @@ unsigned int Database::loadSales(std::vector>& sales, void Database::updateCashPointNo(int oldCashPointNo, int newCashPointNo) { int retCode{}; - sqlite3_stmt* stmt; + sqlite3_stmt *stmt; // Check if the new no ist already in use retCode = sqlite3_prepare_v2(db_, "SELECT COUNT() FROM articles WHERE source_no = :source_no", diff --git a/src/core/database.h b/src/core/database.h index 2cf1b63..af39f23 100644 --- a/src/core/database.h +++ b/src/core/database.h @@ -10,33 +10,33 @@ class Database { - public: - enum class InitResult {OK, OUTDATED_REPLACED}; - explicit Database(const std::string& dbname); +public: + enum class InitResult { OK, OUTDATED_REPLACED }; + explicit Database(const std::string &dbname); Database(); ~Database(); - Database(const Database&) = delete; - Database& operator=(const Database&) = delete; - void exec(const std::string& sql); - unsigned int storeSellers(std::vector>& sellers, + Database(const Database &) = delete; + Database &operator=(const Database &) = delete; + void exec(const std::string &sql); + unsigned int storeSellers(std::vector> &sellers, bool onlyDelete = false); - unsigned int loadSellers(std::vector>& sellers); - unsigned int storeSales(std::vector>& sales); - unsigned int loadSales(std::vector>& sales, - std::vector>& sellers); + unsigned int loadSellers(std::vector> &sellers); + unsigned int storeSales(std::vector> &sales); + unsigned int loadSales(std::vector> &sales, + std::vector> &sellers); void updateCashPointNo(int oldCashPointNo, int newCashPointNo); void newDb(); - InitResult getInitResult() {return initResult_;} + InitResult getInitResult() { return initResult_; } - private: - sqlite3* db_{nullptr}; +private: + sqlite3 *db_{nullptr}; std::string dbname_; void init(); void beginTransaction(); void endTransaction(); void createNew(); int getVersion(); - unsigned int storeArticles(std::vector articles); + unsigned int storeArticles(std::vector
articles); void updateDbToVer2(); void updateDbToVer3(); InitResult initResult_{InitResult::OK}; diff --git a/src/core/entity.h b/src/core/entity.h index 3517297..3b049ba 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -3,13 +3,13 @@ class Entity { - public: +public: enum class State { NEW, UPDATE, DELETE, OK }; virtual ~Entity() = default; void setState(State state) { m_state = state; } virtual State getState() const; - private: +private: State m_state{State::NEW}; }; diff --git a/src/core/entityint.h b/src/core/entityint.h index ea92937..82fac50 100644 --- a/src/core/entityint.h +++ b/src/core/entityint.h @@ -5,14 +5,14 @@ class EntityInt : public Entity { - public: +public: EntityInt() = default; virtual ~EntityInt() = default; EntityInt(int id); void setId(int id); int getId() const { return m_id; }; - protected: +protected: int m_id{}; }; diff --git a/src/core/entityuuid.cpp b/src/core/entityuuid.cpp index 7ae3163..eade2ac 100644 --- a/src/core/entityuuid.cpp +++ b/src/core/entityuuid.cpp @@ -11,7 +11,7 @@ void EntityUuid::createUuid() m_uuid = generator(); } -void EntityUuid::setUuidFromString(const std::string& uuidString) +void EntityUuid::setUuidFromString(const std::string &uuidString) { boost::uuids::string_generator generator{}; m_uuid = generator(uuidString); diff --git a/src/core/entityuuid.h b/src/core/entityuuid.h index bc6bf77..11b99d5 100644 --- a/src/core/entityuuid.h +++ b/src/core/entityuuid.h @@ -10,22 +10,22 @@ class EntityUuid : public Entity { - public: +public: EntityUuid() = default; virtual ~EntityUuid() = default; void createUuid(); - void setUuidFromString(const std::string& uuidString); + void setUuidFromString(const std::string &uuidString); void setSourceNo(int sourceNo); - const boost::uuids::uuid& getUuid() const { return m_uuid; }; + const boost::uuids::uuid &getUuid() const { return m_uuid; }; std::string getUuidAsString() const { return boost::uuids::to_string(m_uuid); } virtual int getSourceNo() const; - protected: +protected: int m_sourceNo{}; - private: +private: boost::uuids::uuid m_uuid{}; }; diff --git a/src/core/excelreader.cpp b/src/core/excelreader.cpp index 7c6abe2..82440ca 100644 --- a/src/core/excelreader.cpp +++ b/src/core/excelreader.cpp @@ -6,7 +6,7 @@ namespace fs = std::filesystem; -std::size_t ExcelReader::readSellersFromFile(const fs::path& filePath, Marketplace* market) +std::size_t ExcelReader::readSellersFromFile(const fs::path &filePath, Marketplace *market) { xlnt::workbook wb; std::ifstream mystream(filePath, std::ios::binary); @@ -15,7 +15,7 @@ std::size_t ExcelReader::readSellersFromFile(const fs::path& filePath, Marketpla } wb.load(mystream); - for (auto& seller : market->getSellers()) { + for (auto &seller : market->getSellers()) { seller->setState(Seller::State::DELETE); } @@ -28,7 +28,7 @@ std::size_t ExcelReader::readSellersFromFile(const fs::path& filePath, Marketpla continue; } - //Skip the row if the seller has neither a first name nor a surname + // Skip the row if the seller has neither a first name nor a surname if (row[2].value().empty() && row[3].value().empty()) { continue; } diff --git a/src/core/excelreader.h b/src/core/excelreader.h index 62f06c4..1d2eefd 100644 --- a/src/core/excelreader.h +++ b/src/core/excelreader.h @@ -11,9 +11,9 @@ class ExcelReader { - public: - static std::size_t readSellersFromFile(const std::filesystem::path& filePath, - Marketplace* market); +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/jsonutil.cpp b/src/core/jsonutil.cpp index 9a20603..bd24b4e 100644 --- a/src/core/jsonutil.cpp +++ b/src/core/jsonutil.cpp @@ -5,15 +5,14 @@ #include -namespace fs = std::filesystem; using json = nlohmann::json; -void JsonUtil::exportSellers(const std::filesystem::path& filePath, Marketplace* market) +void JsonUtil::exportSellers(const std::filesystem::path &filePath, Marketplace *market) { json root; std::ofstream file(filePath); - for (const auto& seller : market->getSellers()) { + for (const auto &seller : market->getSellers()) { json newEntry; newEntry["seller_no"] = seller->getSellerNo(); newEntry["last_name"] = seller->getLastName(); @@ -25,9 +24,9 @@ void JsonUtil::exportSellers(const std::filesystem::path& filePath, Marketplace* file << root.dump(4) << std::endl; } -std::size_t JsonUtil::importSellers(const std::filesystem::path& filePath, Marketplace* market) +std::size_t JsonUtil::importSellers(const std::filesystem::path &filePath, Marketplace *market) { - for (auto& seller : market->getSellers()) { + for (auto &seller : market->getSellers()) { seller->setState(Seller::State::DELETE); } market->storeToDb(true); @@ -61,7 +60,7 @@ std::size_t JsonUtil::importSellers(const std::filesystem::path& filePath, Marke return market->getSellers().size() - 1; // minus 1 because we don't count the "special" seller } -void JsonUtil::exportSales(const std::filesystem::path& filePath, Marketplace* market, +void JsonUtil::exportSales(const std::filesystem::path &filePath, Marketplace *market, int cashPointNo) { json root; @@ -69,7 +68,7 @@ void JsonUtil::exportSales(const std::filesystem::path& filePath, Marketplace* m root["source_no"] = cashPointNo; - for (const auto& sale : market->getSales()) { + for (const auto &sale : market->getSales()) { if (sale->getSourceNo() != cashPointNo) continue; @@ -77,7 +76,7 @@ void JsonUtil::exportSales(const std::filesystem::path& filePath, Marketplace* m newSale["uuid"] = sale->getUuidAsString(); newSale["timestamp"] = sale->getTimestamp(); - for (const auto& article : sale->getArticles()) { + for (const auto &article : sale->getArticles()) { json newArticle; newArticle["uuid"] = article->getUuidAsString(); newArticle["seller_no"] = article->getSeller()->getSellerNo(); @@ -95,7 +94,7 @@ void JsonUtil::exportSales(const std::filesystem::path& filePath, Marketplace* m file << root.dump(4) << std::endl; } -void JsonUtil::importSales(const std::filesystem::path& filePath, Marketplace* market, +void JsonUtil::importSales(const std::filesystem::path &filePath, Marketplace *market, int cashPointNo) { std::ifstream file(filePath); @@ -110,12 +109,12 @@ void JsonUtil::importSales(const std::filesystem::path& filePath, Marketplace* m market->setSalesToDelete(jsonValues["source_no"]); market->storeToDb(); - for (const auto& valSale : jsonValues["sales"]) { + for (const auto &valSale : jsonValues["sales"]) { auto sale = std::make_unique(); sale->setUuidFromString(valSale["uuid"]); sale->setSourceNo(jsonValues["source_no"]); sale->setTimestamp(valSale["timestamp"]); - for (const auto& valArticle : valSale["articles"]) { + for (const auto &valArticle : valSale["articles"]) { auto article = std::make_unique
(); article->setUuidFromString(valArticle["uuid"]); article->setSourceNo(jsonValues["source_no"]); diff --git a/src/core/jsonutil.h b/src/core/jsonutil.h index 2cc33a2..37190a0 100644 --- a/src/core/jsonutil.h +++ b/src/core/jsonutil.h @@ -8,12 +8,12 @@ class JsonUtil { - public: - static void exportSellers(const std::filesystem::path& filePath, Marketplace* market); - static std::size_t importSellers(const std::filesystem::path& filePath, Marketplace* market); - static void exportSales(const std::filesystem::path& filePath, Marketplace* market, +public: + static void exportSellers(const std::filesystem::path &filePath, Marketplace *market); + static std::size_t importSellers(const std::filesystem::path &filePath, Marketplace *market); + static void exportSales(const std::filesystem::path &filePath, Marketplace *market, int cashPointNo); - static void importSales(const std::filesystem::path& filePath, Marketplace* market, + static void importSales(const std::filesystem::path &filePath, Marketplace *market, int cashPointNo); }; diff --git a/src/core/marketplace.cpp b/src/core/marketplace.cpp index 3fe234a..a68242b 100644 --- a/src/core/marketplace.cpp +++ b/src/core/marketplace.cpp @@ -33,15 +33,15 @@ Database::InitResult Marketplace::loadFromDb() return db.getInitResult(); } -SellersVec& Marketplace::getSellers() { return sellers_; } +SellersVec &Marketplace::getSellers() { return sellers_; } -SalesVec& Marketplace::getSales() { return sales_; } +SalesVec &Marketplace::getSales() { return sales_; } int Marketplace::getNextSellerNo() { auto iter = std::max_element( sellers_.begin(), sellers_.end(), - [](const auto& a, const auto& b) -> bool { return a->getSellerNo() < b->getSellerNo(); }); + [](const auto &a, const auto &b) -> bool { return a->getSellerNo() < b->getSellerNo(); }); if (iter == sellers_.end()) return 1; return (*iter)->getSellerNo() + 1; @@ -53,14 +53,14 @@ int Marketplace::getNextArticleNo() int maxArtNoInBasket{0}; auto iter = std::max_element(sellers_.begin(), sellers_.end(), - [](const auto& a, const auto& b) -> bool { + [](const auto &a, const auto &b) -> bool { return a->getMaxArticleNo() < b->getMaxArticleNo(); }); if (iter != sellers_.end()) maxArtNoInDb = (*iter)->getMaxArticleNo(); auto iter2 = - std::max_element(basket_.begin(), basket_.end(), [](const auto& a, const auto& b) -> bool { + std::max_element(basket_.begin(), basket_.end(), [](const auto &a, const auto &b) -> bool { return a->getArticleNo() < b->getArticleNo(); }); @@ -73,13 +73,13 @@ int Marketplace::getNextArticleNo() int Marketplace::getNumSellersDelete() { int count = std::count_if(sellers_.begin(), sellers_.end(), - [](const auto& a) { return a->getState() == Seller::State::DELETE; }); + [](const auto &a) { return a->getState() == Seller::State::DELETE; }); return count; } int Marketplace::getNumArticlesSold() { - int sum = std::accumulate(sellers_.begin(), sellers_.end(), 0, [](int a, const auto& seller) { + int sum = std::accumulate(sellers_.begin(), sellers_.end(), 0, [](int a, const auto &seller) { return a + seller->numArticlesSold(); }); return sum; @@ -87,7 +87,7 @@ int Marketplace::getNumArticlesSold() int Marketplace::getNumArticlesOffered() { - int sum = std::accumulate(sellers_.begin(), sellers_.end(), 0, [](int a, const auto& seller) { + int sum = std::accumulate(sellers_.begin(), sellers_.end(), 0, [](int a, const auto &seller) { return a + seller->numArticlesOffered(); }); return sum; @@ -95,10 +95,10 @@ int Marketplace::getNumArticlesOffered() void Marketplace::sortSellers() { std::sort(sellers_.begin(), sellers_.end()); } -Seller* Marketplace::findSellerWithSellerNo(int sellerNo) +Seller *Marketplace::findSellerWithSellerNo(int sellerNo) { auto iter = std::find_if(sellers_.begin(), sellers_.end(), - [sellerNo](const auto& a) { return a->getSellerNo() == sellerNo; }); + [sellerNo](const auto &a) { return a->getSellerNo() == sellerNo; }); if (iter == sellers_.end()) return nullptr; return (*iter).get(); @@ -129,12 +129,12 @@ void Marketplace::finishCurrentSale(std::unique_ptr sale) storeToDb(); } -BasketVec& Marketplace::getBasket() { return basket_; } +BasketVec &Marketplace::getBasket() { return basket_; } int Marketplace::getBasketSumInCent() { int sum = std::accumulate(basket_.begin(), basket_.end(), 0, - [](int a, const auto& b) { return a + b->getPrice(); }); + [](int a, const auto &b) { return a + b->getPrice(); }); return sum; } @@ -148,23 +148,23 @@ std::string Marketplace::getBasketSumAsString() void Marketplace::removeSale(boost::uuids::uuid uuid) { sales_.erase(std::remove_if(sales_.begin(), sales_.end(), - [&uuid](const auto& a) { return a->getUuid() == uuid; }), + [&uuid](const auto &a) { return a->getUuid() == uuid; }), sales_.end()); } void Marketplace::setSalesToDelete(int cashPointNo) { - std::for_each(sales_.begin(), sales_.end(), [cashPointNo](auto& sale) { + std::for_each(sales_.begin(), sales_.end(), [cashPointNo](auto &sale) { if (sale->getSourceNo() == cashPointNo) { sale->setState(Sale::State::DELETE); - for (auto& article : sale->getArticles()) { + for (auto &article : sale->getArticles()) { article->setState(Article::State::DELETE); } } }); } -void Marketplace::exportReportToCSV(const fs::path& filePath, int feeInPercent, int maxFeeInEuro) +void Marketplace::exportReportToCSV(const fs::path &filePath, int feeInPercent, int maxFeeInEuro) { const char delimiter = ';'; std::ofstream file(filePath); @@ -173,7 +173,7 @@ void Marketplace::exportReportToCSV(const fs::path& filePath, int feeInPercent, << "Anz. gemeldet" << delimiter << "Anz. verkauft" << delimiter << "Umsatz" << delimiter << "Auszahlung\n"; - for (const auto& seller : sellers_) { + for (const auto &seller : sellers_) { file << seller->getSellerNo() << delimiter << escapeCsvValue(seller->getLastName(), delimiter) << delimiter << escapeCsvValue(seller->getFirstName(), delimiter) << delimiter @@ -189,7 +189,7 @@ void Marketplace::exportReportToCSV(const fs::path& filePath, int feeInPercent, int Marketplace::getOverallSumInCent() { int sum = std::accumulate(sellers_.begin(), sellers_.end(), 0, - [](int a, const auto& b) { return a + b->sumInCents(); }); + [](int a, const auto &b) { return a + b->sumInCents(); }); return sum; } @@ -202,7 +202,7 @@ std::string Marketplace::getOverallSumAsString() int Marketplace::getOverallPaymentInCent(int percent, int maxFee) { int sum = std::accumulate( - sellers_.begin(), sellers_.end(), 0, [percent, maxFee](int a, const auto& b) { + sellers_.begin(), sellers_.end(), 0, [percent, maxFee](int a, const auto &b) { return a + b->sumInCents() - marketFee(b->sumInCents(), percent, maxFee); }); return sum; @@ -240,7 +240,7 @@ std::string paymentAsString(int sumInCent, int percent, int maxFeeInCent) return formatCentAsEuroString(sumInCent - marketFee(sumInCent, percent, maxFeeInCent)); } -std::string escapeCsvValue(const std::string& value, const char delimiter) +std::string escapeCsvValue(const std::string &value, const char delimiter) { std::stringstream output; bool containsDelim{false}; @@ -250,7 +250,7 @@ std::string escapeCsvValue(const std::string& value, const char delimiter) output << '"'; } - for (auto& symbol : value) { + for (auto &symbol : value) { if (symbol == '"') { output << '"' << symbol; } else { diff --git a/src/core/marketplace.h b/src/core/marketplace.h index fe45e02..71a7aa6 100644 --- a/src/core/marketplace.h +++ b/src/core/marketplace.h @@ -20,26 +20,26 @@ using BasketVec = std::vector>; class Marketplace { - public: +public: Marketplace(); void storeToDb(bool onlyDelete = false); Database::InitResult loadFromDb(); - SellersVec& getSellers(); - SalesVec& getSales(); + SellersVec &getSellers(); + SalesVec &getSales(); int getNextSellerNo(); int getNextArticleNo(); int getNumSellersDelete(); int getNumArticlesSold(); int getNumArticlesOffered(); - BasketVec& getBasket(); + BasketVec &getBasket(); int getBasketSumInCent(); std::string getBasketSumAsString(); void sortSellers(); - Seller* findSellerWithSellerNo(int sellerNo); - Seller* findSellerWithUuid(const std::string& uuid); + Seller *findSellerWithSellerNo(int sellerNo); + Seller *findSellerWithUuid(const std::string &uuid); void addArticleToBasket(std::unique_ptr
article); size_t basketSize(); void finishCurrentSale(std::unique_ptr sale); @@ -54,12 +54,12 @@ class Marketplace void clear(); - void exportReportToCSV(const std::filesystem::path& filePath, int feeInPercent, + void exportReportToCSV(const std::filesystem::path &filePath, int feeInPercent, int maxFeeInEuro); friend class ExcelReader; - private: +private: SellersVec sellers_; SalesVec sales_; BasketVec basket_; @@ -68,6 +68,6 @@ class Marketplace double marketFee(int sumInCent, int percent, int maxFeeInCent); std::string marketFeeAsString(int sumInCent, int percent, int maxFeeInCent); std::string paymentAsString(int sumInCent, int percent, int maxFeeInCent); -std::string escapeCsvValue(const std::string& value, const char delimiter); +std::string escapeCsvValue(const std::string &value, const char delimiter); #endif diff --git a/src/core/sale.cpp b/src/core/sale.cpp index 1fce577..60e041a 100644 --- a/src/core/sale.cpp +++ b/src/core/sale.cpp @@ -3,41 +3,41 @@ #include -void Sale::addArticle(Article* articlePtr) +void Sale::addArticle(Article *articlePtr) { articlePtr->setSale(this); - articles_.push_back(articlePtr); + m_articles.push_back(articlePtr); } -ArticlesVec& Sale::getArticles() { return articles_; } +ArticlesVec &Sale::getArticles() { return m_articles; } -void Sale::removeArticle(const Article* articlePtr) +void Sale::removeArticle(const Article *articlePtr) { - auto it = std::find(articles_.begin(), articles_.end(), articlePtr); + auto it = std::find(m_articles.begin(), m_articles.end(), articlePtr); - if (it != articles_.end()) { + if (it != m_articles.end()) { (*it)->setSale(nullptr); (*it)->setState( Article::State::DELETE); // since we only have ad-hoc articles, that have all been sold - articles_.erase(it); + m_articles.erase(it); } } int Sale::sumInCents() { - int sum = std::accumulate(articles_.begin(), articles_.end(), 0, - [](int a, const Article* b) { return a + b->getPrice(); }); + int sum = std::accumulate(m_articles.begin(), m_articles.end(), 0, + [](int a, const Article *b) { return a + b->getPrice(); }); return sum; } std::string Sale::sumAsString() { return formatCentAsEuroString(sumInCents()); } -std::string Sale::getTimestamp() const { return timestamp_; } +std::string Sale::getTimestamp() const { return m_timestamp; } -void Sale::setTimestamp(const std::string& timestamp) { timestamp_ = timestamp; } +void Sale::setTimestamp(const std::string ×tamp) { m_timestamp = timestamp; } std::string Sale::getTimestampFormatted() const { - boost::posix_time::ptime time = boost::posix_time::from_iso_extended_string(timestamp_); + boost::posix_time::ptime time = boost::posix_time::from_iso_extended_string(m_timestamp); return boost::posix_time::to_simple_string(time); } diff --git a/src/core/sale.h b/src/core/sale.h index 02a960d..dd54f58 100644 --- a/src/core/sale.h +++ b/src/core/sale.h @@ -11,30 +11,30 @@ namespace { -using ArticlesVec = std::vector; +using ArticlesVec = std::vector
; } class Sale : public EntityUuid { - public: +public: Sale() = default; - Sale(const Sale&) = delete; + Sale(const Sale &) = delete; virtual ~Sale() = default; - void addArticle(Article* articlePtr); - void setTimestamp(const std::string& timestamp); + void addArticle(Article *articlePtr); + void setTimestamp(const std::string ×tamp); - ArticlesVec& getArticles(); + ArticlesVec &getArticles(); std::string getTimestamp() const; std::string getTimestampFormatted() const; int sumInCents(); std::string sumAsString(); - void removeArticle(const Article* articlePtr); + void removeArticle(const Article *articlePtr); - private: - std::string timestamp_{ +private: + std::string m_timestamp{ boost::posix_time::to_iso_extended_string(boost::posix_time::second_clock::local_time())}; - mutable ArticlesVec articles_{}; + mutable ArticlesVec m_articles{}; }; #endif diff --git a/src/core/seller.cpp b/src/core/seller.cpp index e5de07d..9cbb88d 100644 --- a/src/core/seller.cpp +++ b/src/core/seller.cpp @@ -5,32 +5,32 @@ #include #include -Seller::Seller(const std::string& firstName, const std::string& lastName, int sellerNo, +Seller::Seller(const std::string &firstName, const std::string &lastName, int sellerNo, int numArticlesOffered) : EntityInt(sellerNo) { - firstName_ = firstName; - lastName_ = lastName; - numArticlesOffered_ = numArticlesOffered; + m_firstName = firstName; + m_lastName = lastName; + m_numArticlesOffered = numArticlesOffered; } void Seller::setSellerNo(int seller_no) { setId(seller_no); } -void Seller::setFirstName(const std::string& firstName) { firstName_ = firstName; } +void Seller::setFirstName(const std::string &firstName) { m_firstName = firstName; } -void Seller::setLastName(const std::string& lastName) { lastName_ = lastName; } +void Seller::setLastName(const std::string &lastName) { m_lastName = lastName; } -void Seller::setNumArticlesOffered(int number) { numArticlesOffered_ = number; } +void Seller::setNumArticlesOffered(int number) { m_numArticlesOffered = number; } void Seller::addArticle(std::unique_ptr
article) { article->setSeller(this); - articles_.push_back(std::move(article)); + m_articles.push_back(std::move(article)); } -std::string Seller::getFirstName() const { return firstName_; } +std::string Seller::getFirstName() const { return m_firstName; } -std::string Seller::getLastName() const { return lastName_; } +std::string Seller::getLastName() const { return m_lastName; } int Seller::getSellerNo() const { return getId(); } @@ -44,10 +44,10 @@ std::string Seller::getSellerNoAsString() const ; } -std::vector Seller::getArticles(bool onlySold) const +std::vector
Seller::getArticles(bool onlySold) const { - std::vector articles; - for (const auto& article : articles_) { + std::vector
articles; + for (const auto &article : m_articles) { if (onlySold && article->isSold()) { articles.push_back(article.get()); } else if (!onlySold) { @@ -57,54 +57,54 @@ std::vector Seller::getArticles(bool onlySold) const return articles; } -Article* Seller::getArticleByUuid(const std::string& uuidString) +Article *Seller::getArticleByUuid(const std::string &uuidString) { - auto iter = std::find_if(articles_.begin(), articles_.end(), [&uuidString](const auto& art) { + auto iter = std::find_if(m_articles.begin(), m_articles.end(), [&uuidString](const auto &art) { return art->getUuidAsString() == uuidString; }); - if (iter == articles_.end()) + if (iter == m_articles.end()) return nullptr; return (*iter).get(); } int Seller::numArticlesSold() const { return static_cast(getArticles(true).size()); } -int Seller::numArticlesOffered() const { return numArticlesOffered_; } +int Seller::numArticlesOffered() const { return m_numArticlesOffered; } int Seller::getMaxArticleNo() const { auto iter = std::max_element( - articles_.begin(), articles_.end(), - [](const auto& a, const auto& b) -> bool { return a->getArticleNo() < b->getArticleNo(); }); - if (iter == articles_.end()) + m_articles.begin(), m_articles.end(), + [](const auto &a, const auto &b) -> bool { return a->getArticleNo() < b->getArticleNo(); }); + if (iter == m_articles.end()) return 0; return (*iter)->getArticleNo(); } void Seller::cleanupArticles() { - articles_.erase(std::remove_if(articles_.begin(), articles_.end(), - [](const auto& article) { + m_articles.erase(std::remove_if(m_articles.begin(), m_articles.end(), + [](const auto &article) { return article->getState() == Article::State::DELETE; }), - articles_.end()); + m_articles.end()); - for (auto& article : articles_) { + for (auto &article : m_articles) { article->setState(Article::State::OK); } } int Seller::sumInCents() { - int sum = std::accumulate(articles_.begin(), articles_.end(), 0, - [](int a, const auto& b) { return a + b->getPrice(); }); + int sum = std::accumulate(m_articles.begin(), m_articles.end(), 0, + [](int a, const auto &b) { return a + b->getPrice(); }); return sum; } std::string Seller::sumAsString() { return formatCentAsEuroString(sumInCents()); } -bool operator<(const Seller& li, const Seller& re) { return li.m_id < re.m_id; } -bool operator<(const std::unique_ptr& li, const std::unique_ptr& re) +bool operator<(const Seller &li, const Seller &re) { return li.m_id < re.m_id; } +bool operator<(const std::unique_ptr &li, const std::unique_ptr &re) { return li->m_id < re->m_id; } diff --git a/src/core/seller.h b/src/core/seller.h index e3dda18..f71b1eb 100644 --- a/src/core/seller.h +++ b/src/core/seller.h @@ -12,16 +12,16 @@ class Seller : public EntityInt { - public: +public: Seller() = default; - Seller(const Seller&) = delete; + Seller(const Seller &) = delete; virtual ~Seller() = default; - Seller(const std::string& firstName, const std::string& lastName, int sellerNo = 0, + Seller(const std::string &firstName, const std::string &lastName, int sellerNo = 0, int numArticlesOffered = 0); void setSellerNo(int sellerNo); - void setFirstName(const std::string& firstName); - void setLastName(const std::string& lastName); + void setFirstName(const std::string &firstName); + void setLastName(const std::string &lastName); void setNumArticlesOffered(int number); void addArticle(std::unique_ptr
article); void cleanupArticles(); @@ -32,20 +32,20 @@ class Seller : public EntityInt std::string getSellerNoAsString() const; int numArticlesOffered() const; int numArticlesSold() const; - std::vector getArticles(bool onlySold = true) const; - Article* getArticleByUuid(const std::string& uuidString); + std::vector
getArticles(bool onlySold = true) const; + Article *getArticleByUuid(const std::string &uuidString); int getMaxArticleNo() const; int sumInCents(); std::string sumAsString(); - friend bool operator<(const Seller& li, const Seller& re); - friend bool operator<(const std::unique_ptr& li, const std::unique_ptr& re); + friend bool operator<(const Seller &li, const Seller &re); + friend bool operator<(const std::unique_ptr &li, const std::unique_ptr &re); - private: - int numArticlesOffered_{}; - std::string firstName_{}; - std::string lastName_{}; - std::vector> articles_{}; +private: + int m_numArticlesOffered{}; + std::string m_firstName{}; + std::string m_lastName{}; + std::vector> m_articles{}; }; #endif diff --git a/src/core/utils.cpp b/src/core/utils.cpp index 83c7a3a..58985ef 100644 --- a/src/core/utils.cpp +++ b/src/core/utils.cpp @@ -13,7 +13,7 @@ std::string formatCentAsEuroString(const int cent, int width) currStream.imbue(myLocale); currStream << std::right << std::setw(width) << std::showbase << std::put_money(cent, false); - } catch (std::runtime_error& err) { + } catch (std::runtime_error &err) { currStream << std::fixed << std::setw(width >= 4 ? width - 4 : width) << std::setprecision(2) << cent / 100.0L << " €"; } @@ -21,19 +21,19 @@ std::string formatCentAsEuroString(const int cent, int width) return currStream.str(); } -std::string& ltrim(std::string& str, const std::string& chars) +std::string <rim(std::string &str, const std::string &chars) { str.erase(0, str.find_first_not_of(chars)); return str; } -std::string& rtrim(std::string& str, const std::string& chars) +std::string &rtrim(std::string &str, const std::string &chars) { str.erase(str.find_last_not_of(chars) + 1); return str; } -std::string& trim(std::string& str, const std::string& chars) +std::string &trim(std::string &str, const std::string &chars) { return ltrim(rtrim(str, chars), chars); } diff --git a/src/core/utils.h b/src/core/utils.h index 9ca2d32..36790d2 100644 --- a/src/core/utils.h +++ b/src/core/utils.h @@ -6,9 +6,9 @@ #include std::string formatCentAsEuroString(const int cent, int width = 10); -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 "); +std::string <rim(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/reportdialog.cpp b/src/gui/reportdialog.cpp index 02717aa..4ec1f8b 100644 --- a/src/gui/reportdialog.cpp +++ b/src/gui/reportdialog.cpp @@ -17,10 +17,10 @@ namespace fs = std::filesystem; -ReportDialog::ReportDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f) +ReportDialog::ReportDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) { ui_.setupUi(this); - market_ = dynamic_cast(parent)->getMarketplace(); + market_ = dynamic_cast(parent)->getMarketplace(); model_ = std::make_unique(market_, ui_.reportView); ui_.reportView->setModel(model_.get()); ui_.reportView->hideColumn(0); @@ -76,7 +76,7 @@ void ReportDialog::onPrintReportButtonClicked() int height = printer.height(); int width = printer.width(); const double ENTRIES_PER_PAGE = 51; - const auto& sellers = market_->getSellers(); + const auto &sellers = market_->getSellers(); unsigned int numPages = std::ceil(sellers.size() / ENTRIES_PER_PAGE); painter.begin(&printer); @@ -136,7 +136,7 @@ void ReportDialog::onPrintReportButtonClicked() QString content("Einzelteile ohne Nummer\n=======================\n\n"); unsigned int lines{0}; unsigned int pages{1}; - for (const auto& article : specialSeller->getArticles(true)) { + for (const auto &article : specialSeller->getArticles(true)) { content += QString("- %1:").arg(article->getDescription().substr(0, 45).c_str(), -45); content += QString("%1\n").arg(article->getPriceAsString().c_str(), 11); ++lines; @@ -201,7 +201,7 @@ void ReportDialog::onPrintSellerReceiptButtonClicked() return; auto indexes = selModel->selectedRows(); - auto& seller = market_->getSellers().at(indexes[0].row()); + auto &seller = market_->getSellers().at(indexes[0].row()); auto printerDevice = convertToPosPrinterDevice(posPrinterDevice.toStdString(), posPrinterEndpoint.toStdString()); @@ -220,8 +220,8 @@ void ReportDialog::onPrintSellerReceiptButtonClicked() settings.value("global/commune", "Dettingen").toString().toStdString()); } -void ReportDialog::onReportViewSelectionChanged(const QItemSelection& selected, - [[maybe_unused]] const QItemSelection& deselected) +void ReportDialog::onReportViewSelectionChanged(const QItemSelection &selected, + [[maybe_unused]] const QItemSelection &deselected) { if (selected.size() > 0) { ui_.printSellerReceiptButton->setEnabled(true);