KIMA2 ist ein kleines Kassenprogramm für Kindersachenmärkte. https://www.rustysoft.de/?01_kima2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.9 KiB

#include "marketplace.h"
#include "database.h"
4 years ago
#include <algorithm>
Marketplace::Marketplace()
{
4 years ago
auto seller = std::make_unique<Seller>("Max", "Mustermann");
4 years ago
seller->createUuid();
4 years ago
sellers_.push_back(std::move(seller));
}
void Marketplace::storeToDb(bool onlyDelete)
{
Database db;
db.storeSellers(sellers_, onlyDelete);
}
4 years ago
void Marketplace::loadFromDb()
{
Database db;
db.loadSellers(sellers_);
}
4 years ago
4 years ago
SellersVec& Marketplace::getSellers() { return sellers_; }
4 years ago
int Marketplace::getNextSellerNo()
{
auto iter = std::max_element(
sellers_.begin(), sellers_.end(),
4 years ago
[](const auto& a, const auto& b) -> bool { return a->getSellerNo() < b->getSellerNo(); });
4 years ago
if (iter == sellers_.end())
return 1;
4 years ago
return (*iter)->getSellerNo() + 1;
}
int Marketplace::getNumSellersDelete()
{
4 years ago
int count = std::count_if(sellers_.begin(), sellers_.end(),
[](const auto& a) { return a->getState() == Seller::State::DELETE; });
return count;
4 years ago
}
void Marketplace::sortSellers() { std::sort(sellers_.begin(), sellers_.end()); }
Seller* Marketplace::findSellerWithSellerNo(int sellerNo)
{
auto iter = std::find_if(sellers_.begin(), sellers_.end(),
[sellerNo](const auto& a) { return a->getSellerNo() == sellerNo; });
if (iter == sellers_.end())
return nullptr;
return (*iter).get();
4 years ago
}
void Marketplace::addArticleToBasket(std::unique_ptr<Article> article)
{
basket_.push_back(std::move(article));
}
size_t Marketplace::basketSize() { return basket_.size(); }
void Marketplace::finishCurrentSale()
{
if (basket_.size() == 0)
return;
auto sale = std::make_unique<Sale>();
for (auto iter = basket_.begin(); iter != basket_.end(); ++iter) {
sale->addArticle((*iter).get());
(*iter)->getSeller()->addArticle(std::move(*iter));
}
sales_.push_back(std::move(sale));
}