finish current sale

allow_new_sellers
Martin Brodbeck 4 years ago
parent 8b534e1229
commit 150ce946d1
  1. 23
      src/core/marketplace.cpp
  2. 3
      src/core/marketplace.h
  3. 3
      src/gui/CMakeLists.txt
  4. 14
      src/gui/mainwindow.cpp
  5. 49
      src/gui/mainwindow.ui

@ -45,10 +45,8 @@ void Marketplace::sortSellers() { std::sort(sellers_.begin(), sellers_.end()); }
Seller* Marketplace::findSellerWithSellerNo(int sellerNo)
{
auto iter =
std::find_if(sellers_.begin(), sellers_.end(), [sellerNo](const auto& a) {
return a->getSellerNo() == sellerNo;
});
auto iter = std::find_if(sellers_.begin(), sellers_.end(),
[sellerNo](const auto& a) { return a->getSellerNo() == sellerNo; });
if (iter == sellers_.end())
return nullptr;
return (*iter).get();
@ -57,4 +55,21 @@ Seller* Marketplace::findSellerWithSellerNo(int sellerNo)
void Marketplace::addArticleToBasket(std::unique_ptr<Article> article)
{
basket_.push_back(std::move(article));
}
size_t Marketplace::basketSize() { return basket_.size(); }
void Marketplace::finishCurrentSale()
{
if (basket_.size() == 0)
return;
auto sale = std::make_unique<Sale>();
for (auto iter = basket_.begin(); iter != basket_.end(); ++iter) {
sale->addArticle((*iter).get());
(*iter)->getSeller()->addArticle(std::move(*iter));
}
sales_.push_back(std::move(sale));
}

@ -21,6 +21,7 @@ class Marketplace
{
public:
Marketplace();
void storeToDb(bool onlyDelete = false);
void loadFromDb();
SellersVec& getSellers();
@ -29,6 +30,8 @@ class Marketplace
void sortSellers();
Seller* findSellerWithSellerNo(int sellerNo);
void addArticleToBasket(std::unique_ptr<Article> article);
size_t basketSize();
void finishCurrentSale();
private:
SellersVec sellers_;

@ -11,9 +11,12 @@ find_package(Qt5Widgets CONFIG REQUIRED)
set(GUI_SOURCES
kima2.cpp
mainwindow.cpp
mainwindow.ui
sellerdialog.cpp
sellerdialog.ui
sellermodel.cpp
pricedialog.cpp
pricedialog.ui
)
add_executable(kima2 ${GUI_SOURCES})

@ -1,7 +1,7 @@
#include "mainwindow.h"
#include "sellerdialog.h"
#include "pricedialog.h"
#include "sellerdialog.h"
#include <regex>
@ -45,28 +45,30 @@ void MainWindow::on_sellerNoEdit_checkSellerNo()
auto inputText = ui_.sellerNoEdit->text().toStdString();
if (inputText.empty()) {
if (marketplace_->basketSize() > 0) {
marketplace_->finishCurrentSale();
}
return;
}
regex pattern{R"(\d{1,5})"};
smatch result;
if (!regex_match(inputText, result, pattern)) {
return;
}
int sellerNo = std::stoi(result[0]);
auto seller = marketplace_->findSellerWithSellerNo(sellerNo);
if (seller) {
std::cout << "!!! Seller gefunden: " << seller->getFirstName() << "\n";
PriceDialog priceDialog(this);
auto dialogResult = priceDialog.exec();
if (dialogResult == QDialog::Accepted)
{
if (dialogResult == QDialog::Accepted) {
int price = priceDialog.getPrice();
auto article = std::make_unique<Article>(price);
article->setSeller(seller);
std::cout << "!!! Neuer Artikel: " << article->getPrice() << "Cent \n";
std::cout << "!!! Neuer Artikel: " << article->getPrice() << " Cent \n";
marketplace_->addArticleToBasket(std::move(article));
}
}

@ -52,7 +52,54 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLineEdit" name="sellerNoEdit"/>
<widget class="QLineEdit" name="sellerNoEdit">
<property name="palette">
<palette>
<active>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>197</red>
<green>255</green>
<blue>169</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>197</red>
<green>255</green>
<blue>169</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>239</red>
<green>239</green>
<blue>239</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="placeholderText">
<string>Eingabe Verk.-Nr.</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="paidButton">

Loading…
Cancel
Save