more on sales
This commit is contained in:
parent
91357d7c7f
commit
f838977283
2 changed files with 24 additions and 4 deletions
|
@ -8,6 +8,16 @@ void Sale::addArticle(std::shared_ptr<Article> articlePtr)
|
|||
articles_.push_back(articlePtr);
|
||||
}
|
||||
|
||||
std::vector<Article*> Sale::getArticles()
|
||||
{
|
||||
std::vector<Article*> articles(articles_.size());
|
||||
for (const auto& article : articles_) {
|
||||
articles.push_back(article.get());
|
||||
}
|
||||
|
||||
return articles;
|
||||
}
|
||||
|
||||
void Sale::removeArticle(const Article* articlePtr)
|
||||
{
|
||||
auto it = std::find_if(articles_.begin(), articles_.end(),
|
||||
|
@ -23,4 +33,8 @@ int Sale::sumInCents()
|
|||
int sum = std::accumulate(articles_.begin(), articles_.end(), 0,
|
||||
[](int a, std::shared_ptr<Article> b) { return a + b->getPrice(); });
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Sale::getTimestamp() { return timestamp_; }
|
||||
|
||||
void Sale::setTimestamp(const std::string& timestamp) { timestamp_ = timestamp; }
|
|
@ -5,19 +5,25 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
#include <boost/date_time.hpp>
|
||||
#include "boost/date_time/posix_time/posix_time.hpp"
|
||||
|
||||
class Article;
|
||||
|
||||
class Sale : public Entity
|
||||
{
|
||||
public:
|
||||
int sumInCents();
|
||||
void addArticle(std::shared_ptr<Article> articlePtr);
|
||||
void setTimestamp(const std::string& timestamp);
|
||||
|
||||
std::vector<Article*> getArticles();
|
||||
std::string getTimestamp();
|
||||
int sumInCents();
|
||||
|
||||
void removeArticle(const Article* articlePtr);
|
||||
|
||||
private:
|
||||
boost::posix_time::ptime systemTime_{boost::posix_time::second_clock::local_time()};
|
||||
std::string timestamp_{
|
||||
boost::posix_time::to_iso_extended_string(boost::posix_time::second_clock::local_time())};
|
||||
std::vector<std::shared_ptr<Article>> articles_{};
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue