new report dialog

This commit is contained in:
Martin Brodbeck 2018-07-30 09:50:54 +02:00
parent efb1f3ffbf
commit 06c99052df
12 changed files with 334 additions and 1 deletions

View file

@ -134,4 +134,26 @@ void Marketplace::removeSale(boost::uuids::uuid uuid)
sales_.erase(std::remove_if(sales_.begin(), sales_.end(),
[&uuid](const auto& a) { return a->getUuid() == uuid; }),
sales_.end());
}
double marketFee(int sum, int percent, int maxFee)
{
int fee = (sum * percent) / 100.0L;
return fee > maxFee ? maxFee : fee;
}
std::string marketFeeAsString(int sum, int percent, int maxFee)
{
std::stringstream feeStream;
feeStream << std::right << std::setw(12) << std::showbase
<< std::put_money(marketFee(sum, percent, maxFee), false);
return feeStream.str();
}
std::string paymentAsString(int sum, int percent)
{
std::stringstream feeStream;
feeStream << std::right << std::setw(12) << std::showbase
<< std::put_money(sum - marketFee(sum, percent), false);
return feeStream.str();
}

View file

@ -47,4 +47,8 @@ class Marketplace
BasketVec basket_;
};
double marketFee(int sum, int percent, int maxFee = 5000);
std::string marketFeeAsString(int sum, int percent, int maxFee = 5000);
std::string paymentAsString(int sum, int percent);
#endif

View file

@ -1,5 +1,9 @@
#include "seller.h"
#include <numeric>
#include <sstream>
#include <iomanip>
Seller::Seller(const std::string& firstName, const std::string& lastName, int sellerNo,
int numArticlesOffered)
: Entity()
@ -80,6 +84,20 @@ void Seller::cleanupArticles()
}
}
int Seller::sumInCents()
{
int sum = std::accumulate(articles_.begin(), articles_.end(), 0,
[](int a, const auto& b) { return a + b->getPrice(); });
return sum;
}
std::string Seller::sumAsString()
{
std::stringstream sumStream;
sumStream << std::right << std::setw(12) << std::showbase << std::put_money(sumInCents(), false);
return sumStream.str();
}
// int Seller::numArticlesTotal() const { return static_cast<int>(getArticles().size()); }
bool operator<(const Seller& li, const Seller& re) { return li.sellerNo_ < re.sellerNo_; }

View file

@ -34,6 +34,8 @@ class Seller : public Entity
std::vector<Article*> 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<Seller>& li, const std::unique_ptr<Seller>& re);