delete sales
This commit is contained in:
parent
9ab8ca7a4b
commit
940688edd5
6 changed files with 27 additions and 6 deletions
|
@ -495,6 +495,12 @@ unsigned int Database::storeSales(std::vector<std::unique_ptr<Sale>>& sales)
|
|||
|
||||
endTransaction();
|
||||
|
||||
// Everything went fine, so we can now update our objects
|
||||
sales.erase(
|
||||
std::remove_if(sales.begin(), sales.end(),
|
||||
[](const auto& sale) { return (sale->getState() == Sale::State::DELETE); }),
|
||||
sales.end());
|
||||
|
||||
for (auto& sale : sales) {
|
||||
sale->setState(Sale::State::OK);
|
||||
}
|
||||
|
|
|
@ -124,7 +124,14 @@ std::string Marketplace::getBasketSumAsString()
|
|||
// sumStream << std::fixed << std::setprecision(2) << sumInEuro << " €";
|
||||
// return sumStream.str();
|
||||
std::stringstream sumStream;
|
||||
//sumStream.imbue(std::locale("de_DE.utf8"));
|
||||
// sumStream.imbue(std::locale("de_DE.utf8"));
|
||||
sumStream << std::right << std::setw(12) << std::showbase << std::put_money(sumInCent, false);
|
||||
return sumStream.str();
|
||||
}
|
||||
|
||||
void Marketplace::removeSale(boost::uuids::uuid uuid)
|
||||
{
|
||||
sales_.erase(std::remove_if(sales_.begin(), sales_.end(),
|
||||
[&uuid](const auto& a) { return a->getUuid() == uuid; }),
|
||||
sales_.end());
|
||||
}
|
|
@ -39,6 +39,7 @@ class Marketplace
|
|||
void addArticleToBasket(std::unique_ptr<Article> article);
|
||||
size_t basketSize();
|
||||
void finishCurrentSale();
|
||||
void removeSale(boost::uuids::uuid uuid);
|
||||
|
||||
private:
|
||||
SellersVec sellers_;
|
||||
|
|
|
@ -8,7 +8,7 @@ void Sale::addArticle(Article* articlePtr)
|
|||
articles_.push_back(articlePtr);
|
||||
}
|
||||
|
||||
std::vector<Article*>& Sale::getArticles() { return articles_; }
|
||||
ArticlesVec& Sale::getArticles() { return articles_; }
|
||||
|
||||
void Sale::removeArticle(const Article* articlePtr)
|
||||
{
|
||||
|
|
|
@ -7,9 +7,12 @@
|
|||
|
||||
#include "boost/date_time/posix_time/posix_time.hpp"
|
||||
|
||||
//class Article;
|
||||
// class Article;
|
||||
|
||||
namespace
|
||||
{
|
||||
using ArticlesVec = std::vector<Article*>;
|
||||
}
|
||||
|
||||
class Sale : public Entity
|
||||
{
|
||||
|
|
|
@ -175,14 +175,18 @@ bool SaleModel::removeRows(int row, int count, const QModelIndex& parent)
|
|||
} else if (!parent.parent().isValid()) {
|
||||
// remove one article from a sale
|
||||
auto sale = static_cast<Sale*>(parent.internalPointer());
|
||||
auto articles = sale->getArticles();
|
||||
emit beginRemoveRows(parent, row, row + count -1);
|
||||
auto& articles = sale->getArticles();
|
||||
articles.at(row)->setState(Article::State::DELETE);
|
||||
emit beginRemoveRows(parent, row, row + count - 1);
|
||||
sale->removeArticle(articles.at(row));
|
||||
marketplace_->storeToDb();
|
||||
emit endRemoveRows();
|
||||
if (articles.size() == 0) {
|
||||
std::cout << "No articles left.\n";
|
||||
// marketplace_->removeSale(sale->getUuid());
|
||||
sale->setState(Sale::State::DELETE);
|
||||
}
|
||||
emit beginRemoveRows(parent.parent(), 0, 0);
|
||||
marketplace_->storeToDb();
|
||||
emit endRemoveRows();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue