finish current sale
This commit is contained in:
parent
8b534e1229
commit
150ce946d1
5 changed files with 81 additions and 11 deletions
|
@ -45,10 +45,8 @@ void Marketplace::sortSellers() { std::sort(sellers_.begin(), sellers_.end()); }
|
||||||
|
|
||||||
Seller* Marketplace::findSellerWithSellerNo(int sellerNo)
|
Seller* Marketplace::findSellerWithSellerNo(int sellerNo)
|
||||||
{
|
{
|
||||||
auto iter =
|
auto iter = std::find_if(sellers_.begin(), sellers_.end(),
|
||||||
std::find_if(sellers_.begin(), sellers_.end(), [sellerNo](const auto& a) {
|
[sellerNo](const auto& a) { return a->getSellerNo() == sellerNo; });
|
||||||
return a->getSellerNo() == sellerNo;
|
|
||||||
});
|
|
||||||
if (iter == sellers_.end())
|
if (iter == sellers_.end())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return (*iter).get();
|
return (*iter).get();
|
||||||
|
@ -58,3 +56,20 @@ void Marketplace::addArticleToBasket(std::unique_ptr<Article> article)
|
||||||
{
|
{
|
||||||
basket_.push_back(std::move(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:
|
public:
|
||||||
Marketplace();
|
Marketplace();
|
||||||
|
|
||||||
void storeToDb(bool onlyDelete = false);
|
void storeToDb(bool onlyDelete = false);
|
||||||
void loadFromDb();
|
void loadFromDb();
|
||||||
SellersVec& getSellers();
|
SellersVec& getSellers();
|
||||||
|
@ -29,6 +30,8 @@ class Marketplace
|
||||||
void sortSellers();
|
void sortSellers();
|
||||||
Seller* findSellerWithSellerNo(int sellerNo);
|
Seller* findSellerWithSellerNo(int sellerNo);
|
||||||
void addArticleToBasket(std::unique_ptr<Article> article);
|
void addArticleToBasket(std::unique_ptr<Article> article);
|
||||||
|
size_t basketSize();
|
||||||
|
void finishCurrentSale();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SellersVec sellers_;
|
SellersVec sellers_;
|
||||||
|
|
|
@ -11,9 +11,12 @@ find_package(Qt5Widgets CONFIG REQUIRED)
|
||||||
set(GUI_SOURCES
|
set(GUI_SOURCES
|
||||||
kima2.cpp
|
kima2.cpp
|
||||||
mainwindow.cpp
|
mainwindow.cpp
|
||||||
|
mainwindow.ui
|
||||||
sellerdialog.cpp
|
sellerdialog.cpp
|
||||||
|
sellerdialog.ui
|
||||||
sellermodel.cpp
|
sellermodel.cpp
|
||||||
pricedialog.cpp
|
pricedialog.cpp
|
||||||
|
pricedialog.ui
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(kima2 ${GUI_SOURCES})
|
add_executable(kima2 ${GUI_SOURCES})
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#include "sellerdialog.h"
|
|
||||||
#include "pricedialog.h"
|
#include "pricedialog.h"
|
||||||
|
#include "sellerdialog.h"
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
|
@ -45,24 +45,26 @@ void MainWindow::on_sellerNoEdit_checkSellerNo()
|
||||||
auto inputText = ui_.sellerNoEdit->text().toStdString();
|
auto inputText = ui_.sellerNoEdit->text().toStdString();
|
||||||
|
|
||||||
if (inputText.empty()) {
|
if (inputText.empty()) {
|
||||||
|
if (marketplace_->basketSize() > 0) {
|
||||||
|
marketplace_->finishCurrentSale();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
regex pattern{R"(\d{1,5})"};
|
regex pattern{R"(\d{1,5})"};
|
||||||
smatch result;
|
smatch result;
|
||||||
|
|
||||||
if (!regex_match(inputText, result, pattern)) {
|
if (!regex_match(inputText, result, pattern)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sellerNo = std::stoi(result[0]);
|
int sellerNo = std::stoi(result[0]);
|
||||||
|
|
||||||
auto seller = marketplace_->findSellerWithSellerNo(sellerNo);
|
auto seller = marketplace_->findSellerWithSellerNo(sellerNo);
|
||||||
if (seller) {
|
if (seller) {
|
||||||
std::cout << "!!! Seller gefunden: " << seller->getFirstName() << "\n";
|
|
||||||
PriceDialog priceDialog(this);
|
PriceDialog priceDialog(this);
|
||||||
auto dialogResult = priceDialog.exec();
|
auto dialogResult = priceDialog.exec();
|
||||||
if (dialogResult == QDialog::Accepted)
|
if (dialogResult == QDialog::Accepted) {
|
||||||
{
|
|
||||||
int price = priceDialog.getPrice();
|
int price = priceDialog.getPrice();
|
||||||
auto article = std::make_unique<Article>(price);
|
auto article = std::make_unique<Article>(price);
|
||||||
article->setSeller(seller);
|
article->setSeller(seller);
|
||||||
|
|
|
@ -52,7 +52,54 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
<item>
|
<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>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="paidButton">
|
<widget class="QPushButton" name="paidButton">
|
||||||
|
|
Loading…
Reference in a new issue