delete sales

allow_new_sellers
Martin Brodbeck 4 years ago
parent 9ab8ca7a4b
commit 940688edd5
  1. 6
      src/core/database.cpp
  2. 9
      src/core/marketplace.cpp
  3. 1
      src/core/marketplace.h
  4. 2
      src/core/sale.cpp
  5. 5
      src/core/sale.h
  6. 10
      src/gui/salemodel.cpp

@ -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…
Cancel
Save