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();
|
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) {
|
for (auto& sale : sales) {
|
||||||
sale->setState(Sale::State::OK);
|
sale->setState(Sale::State::OK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,14 @@ std::string Marketplace::getBasketSumAsString()
|
||||||
// sumStream << std::fixed << std::setprecision(2) << sumInEuro << " €";
|
// sumStream << std::fixed << std::setprecision(2) << sumInEuro << " €";
|
||||||
// return sumStream.str();
|
// return sumStream.str();
|
||||||
std::stringstream sumStream;
|
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);
|
sumStream << std::right << std::setw(12) << std::showbase << std::put_money(sumInCent, false);
|
||||||
return sumStream.str();
|
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);
|
void addArticleToBasket(std::unique_ptr<Article> article);
|
||||||
size_t basketSize();
|
size_t basketSize();
|
||||||
void finishCurrentSale();
|
void finishCurrentSale();
|
||||||
|
void removeSale(boost::uuids::uuid uuid);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SellersVec sellers_;
|
SellersVec sellers_;
|
||||||
|
|
|
@ -8,7 +8,7 @@ void Sale::addArticle(Article* articlePtr)
|
||||||
articles_.push_back(articlePtr);
|
articles_.push_back(articlePtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Article*>& Sale::getArticles() { return articles_; }
|
ArticlesVec& Sale::getArticles() { return articles_; }
|
||||||
|
|
||||||
void Sale::removeArticle(const Article* articlePtr)
|
void Sale::removeArticle(const Article* articlePtr)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,9 +7,12 @@
|
||||||
|
|
||||||
#include "boost/date_time/posix_time/posix_time.hpp"
|
#include "boost/date_time/posix_time/posix_time.hpp"
|
||||||
|
|
||||||
//class Article;
|
// class Article;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
using ArticlesVec = std::vector<Article*>;
|
using ArticlesVec = std::vector<Article*>;
|
||||||
|
}
|
||||||
|
|
||||||
class Sale : public Entity
|
class Sale : public Entity
|
||||||
{
|
{
|
||||||
|
|
|
@ -175,14 +175,18 @@ bool SaleModel::removeRows(int row, int count, const QModelIndex& parent)
|
||||||
} else if (!parent.parent().isValid()) {
|
} else if (!parent.parent().isValid()) {
|
||||||
// remove one article from a sale
|
// remove one article from a sale
|
||||||
auto sale = static_cast<Sale*>(parent.internalPointer());
|
auto sale = static_cast<Sale*>(parent.internalPointer());
|
||||||
auto articles = sale->getArticles();
|
auto& articles = sale->getArticles();
|
||||||
emit beginRemoveRows(parent, row, row + count -1);
|
|
||||||
articles.at(row)->setState(Article::State::DELETE);
|
articles.at(row)->setState(Article::State::DELETE);
|
||||||
|
emit beginRemoveRows(parent, row, row + count - 1);
|
||||||
sale->removeArticle(articles.at(row));
|
sale->removeArticle(articles.at(row));
|
||||||
marketplace_->storeToDb();
|
emit endRemoveRows();
|
||||||
if (articles.size() == 0) {
|
if (articles.size() == 0) {
|
||||||
std::cout << "No articles left.\n";
|
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();
|
emit endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue