now printing reports

This commit is contained in:
Martin Brodbeck 2018-07-31 16:15:48 +02:00
parent a6c5366b63
commit 4a41036aec
6 changed files with 138 additions and 5 deletions

View file

@ -155,6 +155,47 @@ void Marketplace::exportReportToCSV(const std::string& filename, int feeInPercen
}
}
int Marketplace::getOverallSumInCent()
{
int sum = std::accumulate(sellers_.begin(), sellers_.end(), 0,
[](int a, const auto& b) { return a + b->sumInCents(); });
return sum;
}
std::string Marketplace::getOverallSumAsString()
{
int sum = getOverallSumInCent();
std::stringstream sumStream;
sumStream << std::right << std::setw(10) << std::showbase << std::put_money(sum, false);
return sumStream.str();
}
int Marketplace::getOverallPaymentInCent(int percent, int maxFee)
{
int sum = std::accumulate(
sellers_.begin(), sellers_.end(), 0, [percent, maxFee](int a, const auto& b) {
return a + b->sumInCents() - marketFee(b->sumInCents(), percent, maxFee);
});
return sum;
}
std::string Marketplace::getOverallPaymentAsString(int percent, int maxFee)
{
int sum = getOverallPaymentInCent(percent, maxFee);
std::stringstream sumStream;
sumStream << std::right << std::setw(10) << std::showbase << std::put_money(sum, false);
return sumStream.str();
}
std::string Marketplace::getOverallRevenueAsString(int percent, int maxFee)
{
int sum = getOverallSumInCent();
int pay = getOverallPaymentInCent(percent, maxFee);
std::stringstream sumStream;
sumStream << std::right << std::setw(10) << std::showbase << std::put_money(sum - pay, false);
return sumStream.str();
}
double marketFee(int sum, int percent, int maxFee)
{
int fee = (sum * percent) / 100.0L;

View file

@ -41,6 +41,12 @@ class Marketplace
void finishCurrentSale(std::unique_ptr<Sale> sale);
void removeSale(boost::uuids::uuid uuid);
int getOverallSumInCent();
std::string getOverallSumAsString();
int getOverallPaymentInCent(int percent, int maxFee);
std::string getOverallPaymentAsString(int percent, int maxFee);
std::string getOverallRevenueAsString(int percent, int maxFee);
void exportReportToCSV(const std::string& filename, int feeInPercent, int maxFeeInEuro);
private: