Compare commits

..

No commits in common. "2d670f4e184161cf10b94d67fd98585d351e6460" and "da4e223b16edffd6cd1cf5054fb5984e562e0b91" have entirely different histories.

7 changed files with 44 additions and 46 deletions

View file

@ -14,8 +14,7 @@ set(CORE_SOURCES
sale.cpp
marketplace.cpp
excelreader.cpp
jsonutil.cpp
utils.cpp
jsonutil
)
add_library(core STATIC ${CORE_SOURCES})

View file

@ -1,5 +1,4 @@
#include "article.h"
#include "utils.h"
#include <iomanip>
#include <sstream>
@ -31,7 +30,10 @@ int Article::getPrice() const { return price_; }
std::string Article::getPriceAsString() const
{
return formatCentAsEuroString(price_);
std::stringstream sumStream;
// sumStream.imbue(std::locale("de_DE.utf8"));
sumStream << std::right << std::setw(10) << std::showbase << std::put_money(price_, false);
return sumStream.str();
}
int Article::getArticleNo() const { return articleNo_; }

View file

@ -1,6 +1,5 @@
#include "marketplace.h"
#include "database.h"
#include "utils.h"
#include <algorithm>
#include <fstream>
@ -118,8 +117,14 @@ int Marketplace::getBasketSumInCent()
std::string Marketplace::getBasketSumAsString()
{
int sumInCent = getBasketSumInCent();
return formatCentAsEuroString(sumInCent);
// double sumInEuro = sumInCent / 100.0L;
// std::stringstream sumStream;
// sumStream << std::fixed << std::setprecision(2) << sumInEuro << " €";
// return sumStream.str();
std::stringstream sumStream;
// sumStream.imbue(std::locale("de_DE.utf8"));
sumStream << std::right << std::setw(10) << std::showbase << std::put_money(sumInCent, false);
return sumStream.str();
}
void Marketplace::removeSale(boost::uuids::uuid uuid)
@ -160,7 +165,9 @@ int Marketplace::getOverallSumInCent()
std::string Marketplace::getOverallSumAsString()
{
int sum = getOverallSumInCent();
return formatCentAsEuroString(sum);
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)
@ -175,14 +182,18 @@ int Marketplace::getOverallPaymentInCent(int percent, int maxFee)
std::string Marketplace::getOverallPaymentAsString(int percent, int maxFee)
{
int sum = getOverallPaymentInCent(percent, maxFee);
return formatCentAsEuroString(sum);
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);
return formatCentAsEuroString(sum - pay);
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)
@ -196,12 +207,18 @@ double marketFee(int sum, int percent, int maxFee)
std::string marketFeeAsString(int sum, int percent, int maxFee)
{
return formatCentAsEuroString(marketFee(sum, percent, maxFee));
std::stringstream feeStream;
feeStream << std::right << std::setw(10) << std::showbase
<< std::put_money(marketFee(sum, percent, maxFee), false);
return feeStream.str();
}
std::string paymentAsString(int sumInCent, int percent, int maxFeeInCent)
{
return formatCentAsEuroString(sumInCent - marketFee(sumInCent, percent, maxFeeInCent));
std::stringstream feeStream;
feeStream << std::right << std::setw(10) << std::showbase
<< std::put_money(sumInCent - marketFee(sumInCent, percent, maxFeeInCent), false);
return feeStream.str();
}
std::string escapeCsvValue(const std::string& value, const char delimiter)

View file

@ -1,5 +1,4 @@
#include "sale.h"
#include "utils.h"
#include <numeric>
@ -32,7 +31,12 @@ int Sale::sumInCents()
return sum;
}
std::string Sale::sumAsString() { return formatCentAsEuroString(sumInCents()); }
std::string Sale::sumAsString()
{
std::stringstream sumStream;
sumStream << std::right << std::setw(10) << std::showbase << std::put_money(sumInCents(), false);
return sumStream.str();
}
std::string Sale::getTimestamp() { return timestamp_; }

View file

@ -1,9 +1,8 @@
#include "seller.h"
#include "utils.h"
#include <iomanip>
#include <numeric>
#include <sstream>
#include <iomanip>
Seller::Seller(const std::string& firstName, const std::string& lastName, int sellerNo,
int numArticlesOffered)
@ -92,8 +91,14 @@ int Seller::sumInCents()
return sum;
}
std::string Seller::sumAsString() { return formatCentAsEuroString(sumInCents()); }
std::string Seller::sumAsString()
{
std::stringstream sumStream;
sumStream << std::right << std::setw(10) << 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_; }
bool operator<(const std::unique_ptr<Seller>& li, const std::unique_ptr<Seller>& re)

View file

@ -1,21 +0,0 @@
#include "utils.h"
#include <iomanip>
#include <numeric>
std::string formatCentAsEuroString(const int cent, int width)
{
std::stringstream currStream;
try {
std::locale myLocale("de_DE.utf8");
currStream.imbue(myLocale);
currStream << std::right << std::setw(width) << std::showbase
<< std::put_money(cent, false);
} catch (std::runtime_error& err) {
currStream << std::fixed << std::setw(width) << std::setprecision(2) << cent / 100.0L
<< "";
}
return currStream.str();
}

View file

@ -1,8 +0,0 @@
#ifndef UTILS_H
#define UTILS_H
#include <string>
std::string formatCentAsEuroString(const int cent, int width = 10);
#endif