show last sum

This commit is contained in:
Martin Brodbeck 2018-07-23 14:18:24 +02:00
parent 527241a0f3
commit 3efa289b5b
4 changed files with 48 additions and 47 deletions

View file

@ -2,6 +2,9 @@
#include "database.h"
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iomanip>
Marketplace::Marketplace()
{
@ -99,4 +102,20 @@ void Marketplace::finishCurrentSale()
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(); });
return sum;
}
std::string Marketplace::getBasketSumAsString()
{
int sumInCent = getBasketSumInCent();
double sumInEuro = sumInCent / 100.0L;
std::stringstream sumStream;
sumStream << std::fixed << std::setprecision(2) << sumInEuro << "";
return sumStream.str();
}

View file

@ -30,6 +30,8 @@ class Marketplace
int getNextArticleNo();
int getNumSellersDelete();
BasketVec& getBasket();
int getBasketSumInCent();
std::string getBasketSumAsString();
void sortSellers();
Seller* findSellerWithSellerNo(int sellerNo);