lots of smaller improvements

This commit is contained in:
Martin Brodbeck 2018-07-30 14:43:02 +02:00
parent c3b17fbb8b
commit 84f71ea056
13 changed files with 49 additions and 24 deletions

View file

@ -31,9 +31,16 @@ int Article::getPrice() const { return price_; }
std::string Article::getPriceAsString() const
{
std::stringstream sumStream;
//sumStream.imbue(std::locale("de_DE.utf8"));
sumStream << std::right << std::setw(12) << std::showbase << std::put_money(price_, false);
// 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() { return articleNo_; }
int Article::getArticleNo() const { return articleNo_; }
std::string Article::getCompleteArticleNo() const
{
std::stringstream artNoStream;
artNoStream << sourceNo_ << "K" << std::setfill('0') << std::setw(5) << articleNo_;
return artNoStream.str();
}

View file

@ -25,7 +25,8 @@ class Article : public Entity
void setSale(Sale* salePtr);
void setSeller(Seller* sellerPtr);
int getArticleNo();
int getArticleNo() const;
std::string getCompleteArticleNo() const;
std::string getDescription();
Seller* getSeller();
Sale* getSale();

View file

@ -11,7 +11,7 @@ class Entity
public:
enum class State { NEW, UPDATE, DELETE, OK };
//Entity() = default;
// Entity() = default;
virtual ~Entity() = 0;
void createUuid();
@ -24,10 +24,12 @@ class Entity
virtual State getState() const;
virtual int getSourceNo() const;
protected:
int sourceNo_{};
private:
boost::uuids::uuid uuid_{};
State state_{State::NEW};
int sourceNo_{};
};
#endif // ENTITY_H

View file

@ -89,14 +89,11 @@ void Marketplace::addArticleToBasket(std::unique_ptr<Article> article)
size_t Marketplace::basketSize() { return basket_.size(); }
void Marketplace::finishCurrentSale()
void Marketplace::finishCurrentSale(std::unique_ptr<Sale> sale)
{
if (basket_.size() == 0)
return;
auto sale = std::make_unique<Sale>();
sale->createUuid();
for (auto iter = basket_.begin(); iter != basket_.end(); ++iter) {
sale->addArticle((*iter).get());
(*iter)->getSeller()->addArticle(std::move(*iter));
@ -125,7 +122,7 @@ std::string Marketplace::getBasketSumAsString()
// return sumStream.str();
std::stringstream sumStream;
// sumStream.imbue(std::locale("de_DE.utf8"));
sumStream << std::right << std::setw(12) << std::showbase << std::put_money(sumInCent, false);
sumStream << std::right << std::setw(10) << std::showbase << std::put_money(sumInCent, false);
return sumStream.str();
}
@ -148,7 +145,7 @@ double marketFee(int sum, int percent, int maxFee)
std::string marketFeeAsString(int sum, int percent, int maxFee)
{
std::stringstream feeStream;
feeStream << std::right << std::setw(12) << std::showbase
feeStream << std::right << std::setw(10) << std::showbase
<< std::put_money(marketFee(sum, percent, maxFee), false);
return feeStream.str();
}
@ -156,7 +153,7 @@ std::string marketFeeAsString(int sum, int percent, int maxFee)
std::string paymentAsString(int sum, int percent)
{
std::stringstream feeStream;
feeStream << std::right << std::setw(12) << std::showbase
feeStream << std::right << std::setw(10) << std::showbase
<< std::put_money(sum - marketFee(sum, percent), false);
return feeStream.str();
}

View file

@ -38,7 +38,7 @@ class Marketplace
Seller* findSellerWithSellerNo(int sellerNo);
void addArticleToBasket(std::unique_ptr<Article> article);
size_t basketSize();
void finishCurrentSale();
void finishCurrentSale(std::unique_ptr<Sale> sale);
void removeSale(boost::uuids::uuid uuid);
private:

View file

@ -34,7 +34,7 @@ int Sale::sumInCents()
std::string Sale::sumAsString()
{
std::stringstream sumStream;
sumStream << std::right << std::setw(12) << std::showbase << std::put_money(sumInCents(), false);
sumStream << std::right << std::setw(10) << std::showbase << std::put_money(sumInCents(), false);
return sumStream.str();
}

View file

@ -94,7 +94,7 @@ int Seller::sumInCents()
std::string Seller::sumAsString()
{
std::stringstream sumStream;
sumStream << std::right << std::setw(12) << std::showbase << std::put_money(sumInCents(), false);
sumStream << std::right << std::setw(10) << std::showbase << std::put_money(sumInCents(), false);
return sumStream.str();
}