Compare commits
2 commits
9e85e2892d
...
84f71ea056
Author | SHA1 | Date | |
---|---|---|---|
84f71ea056 | |||
c3b17fbb8b |
13 changed files with 51 additions and 39 deletions
|
@ -31,9 +31,16 @@ int Article::getPrice() const { return price_; }
|
||||||
std::string Article::getPriceAsString() const
|
std::string Article::getPriceAsString() const
|
||||||
{
|
{
|
||||||
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(price_, false);
|
sumStream << std::right << std::setw(10) << std::showbase << std::put_money(price_, false);
|
||||||
return sumStream.str();
|
return sumStream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Article::getArticleNo() { return articleNo_; }
|
int Article::getArticleNo() const { return articleNo_; }
|
||||||
|
|
||||||
|
std::string Article::getCompleteArticleNo() const
|
||||||
|
{
|
||||||
|
std::stringstream artNoStream;
|
||||||
|
artNoStream << sourceNo_ << "K" << std::setfill('0') << std::setw(5) << articleNo_;
|
||||||
|
return artNoStream.str();
|
||||||
|
}
|
|
@ -25,7 +25,8 @@ class Article : public Entity
|
||||||
void setSale(Sale* salePtr);
|
void setSale(Sale* salePtr);
|
||||||
void setSeller(Seller* sellerPtr);
|
void setSeller(Seller* sellerPtr);
|
||||||
|
|
||||||
int getArticleNo();
|
int getArticleNo() const;
|
||||||
|
std::string getCompleteArticleNo() const;
|
||||||
std::string getDescription();
|
std::string getDescription();
|
||||||
Seller* getSeller();
|
Seller* getSeller();
|
||||||
Sale* getSale();
|
Sale* getSale();
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Entity
|
||||||
public:
|
public:
|
||||||
enum class State { NEW, UPDATE, DELETE, OK };
|
enum class State { NEW, UPDATE, DELETE, OK };
|
||||||
|
|
||||||
//Entity() = default;
|
// Entity() = default;
|
||||||
virtual ~Entity() = 0;
|
virtual ~Entity() = 0;
|
||||||
|
|
||||||
void createUuid();
|
void createUuid();
|
||||||
|
@ -24,10 +24,12 @@ class Entity
|
||||||
virtual State getState() const;
|
virtual State getState() const;
|
||||||
virtual int getSourceNo() const;
|
virtual int getSourceNo() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int sourceNo_{};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::uuids::uuid uuid_{};
|
boost::uuids::uuid uuid_{};
|
||||||
State state_{State::NEW};
|
State state_{State::NEW};
|
||||||
int sourceNo_{};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ENTITY_H
|
#endif // ENTITY_H
|
|
@ -89,14 +89,11 @@ void Marketplace::addArticleToBasket(std::unique_ptr<Article> article)
|
||||||
|
|
||||||
size_t Marketplace::basketSize() { return basket_.size(); }
|
size_t Marketplace::basketSize() { return basket_.size(); }
|
||||||
|
|
||||||
void Marketplace::finishCurrentSale()
|
void Marketplace::finishCurrentSale(std::unique_ptr<Sale> sale)
|
||||||
{
|
{
|
||||||
if (basket_.size() == 0)
|
if (basket_.size() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto sale = std::make_unique<Sale>();
|
|
||||||
sale->createUuid();
|
|
||||||
|
|
||||||
for (auto iter = basket_.begin(); iter != basket_.end(); ++iter) {
|
for (auto iter = basket_.begin(); iter != basket_.end(); ++iter) {
|
||||||
sale->addArticle((*iter).get());
|
sale->addArticle((*iter).get());
|
||||||
(*iter)->getSeller()->addArticle(std::move(*iter));
|
(*iter)->getSeller()->addArticle(std::move(*iter));
|
||||||
|
@ -125,7 +122,7 @@ std::string Marketplace::getBasketSumAsString()
|
||||||
// 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(10) << std::showbase << std::put_money(sumInCent, false);
|
||||||
return sumStream.str();
|
return sumStream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +145,7 @@ double marketFee(int sum, int percent, int maxFee)
|
||||||
std::string marketFeeAsString(int sum, int percent, int maxFee)
|
std::string marketFeeAsString(int sum, int percent, int maxFee)
|
||||||
{
|
{
|
||||||
std::stringstream feeStream;
|
std::stringstream feeStream;
|
||||||
feeStream << std::right << std::setw(12) << std::showbase
|
feeStream << std::right << std::setw(10) << std::showbase
|
||||||
<< std::put_money(marketFee(sum, percent, maxFee), false);
|
<< std::put_money(marketFee(sum, percent, maxFee), false);
|
||||||
return feeStream.str();
|
return feeStream.str();
|
||||||
}
|
}
|
||||||
|
@ -156,7 +153,7 @@ std::string marketFeeAsString(int sum, int percent, int maxFee)
|
||||||
std::string paymentAsString(int sum, int percent)
|
std::string paymentAsString(int sum, int percent)
|
||||||
{
|
{
|
||||||
std::stringstream feeStream;
|
std::stringstream feeStream;
|
||||||
feeStream << std::right << std::setw(12) << std::showbase
|
feeStream << std::right << std::setw(10) << std::showbase
|
||||||
<< std::put_money(sum - marketFee(sum, percent), false);
|
<< std::put_money(sum - marketFee(sum, percent), false);
|
||||||
return feeStream.str();
|
return feeStream.str();
|
||||||
}
|
}
|
|
@ -38,7 +38,7 @@ class Marketplace
|
||||||
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();
|
size_t basketSize();
|
||||||
void finishCurrentSale();
|
void finishCurrentSale(std::unique_ptr<Sale> sale);
|
||||||
void removeSale(boost::uuids::uuid uuid);
|
void removeSale(boost::uuids::uuid uuid);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -34,7 +34,7 @@ int Sale::sumInCents()
|
||||||
std::string Sale::sumAsString()
|
std::string Sale::sumAsString()
|
||||||
{
|
{
|
||||||
std::stringstream sumStream;
|
std::stringstream sumStream;
|
||||||
sumStream << std::right << std::setw(12) << std::showbase << std::put_money(sumInCents(), false);
|
sumStream << std::right << std::setw(10) << std::showbase << std::put_money(sumInCents(), false);
|
||||||
return sumStream.str();
|
return sumStream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ int Seller::sumInCents()
|
||||||
std::string Seller::sumAsString()
|
std::string Seller::sumAsString()
|
||||||
{
|
{
|
||||||
std::stringstream sumStream;
|
std::stringstream sumStream;
|
||||||
sumStream << std::right << std::setw(12) << std::showbase << std::put_money(sumInCents(), false);
|
sumStream << std::right << std::setw(10) << std::showbase << std::put_money(sumInCents(), false);
|
||||||
return sumStream.str();
|
return sumStream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "basketmodel.h"
|
#include "basketmodel.h"
|
||||||
|
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
BasketModel::BasketModel(Marketplace* market, QObject* parent)
|
BasketModel::BasketModel(Marketplace* market, QObject* parent)
|
||||||
: QAbstractTableModel(parent), marketplace_(market)
|
: QAbstractTableModel(parent), marketplace_(market)
|
||||||
|
@ -23,7 +24,8 @@ QVariant BasketModel::data(const QModelIndex& index, int role) const
|
||||||
case 0:
|
case 0:
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
case 1:
|
case 1:
|
||||||
[[fallthrough]];
|
myFont.setFamily("monospace");
|
||||||
|
return myFont;
|
||||||
case 2:
|
case 2:
|
||||||
return myFont;
|
return myFont;
|
||||||
case 3:
|
case 3:
|
||||||
|
@ -44,7 +46,7 @@ QVariant BasketModel::data(const QModelIndex& index, int role) const
|
||||||
case 0:
|
case 0:
|
||||||
return article->getUuidAsString().c_str();
|
return article->getUuidAsString().c_str();
|
||||||
case 1:
|
case 1:
|
||||||
return article->getArticleNo();
|
return article->getCompleteArticleNo().c_str();
|
||||||
case 2:
|
case 2:
|
||||||
return article->getSeller()->getSellerNo();
|
return article->getSeller()->getSellerNo();
|
||||||
case 3:
|
case 3:
|
||||||
|
@ -79,20 +81,6 @@ QVariant BasketModel::headerData(int section, Qt::Orientation orientation, int r
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* bool BasketModel::insertRows(int row, int count, const QModelIndex& parent)
|
|
||||||
{
|
|
||||||
//emit beginInsertRows(parent, row, row + count - 1);
|
|
||||||
//auto article = std::make_unique<Article>();
|
|
||||||
//article->createUuid();
|
|
||||||
//article->setArticleNo(marketplace_->getNextArticleNo());
|
|
||||||
//marketplace_->addArticleToBasket(std::move(article));
|
|
||||||
//emit endInsertRows();
|
|
||||||
|
|
||||||
emit layoutChanged();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} */
|
|
||||||
|
|
||||||
void BasketModel::addArticle(Seller* seller, int price)
|
void BasketModel::addArticle(Seller* seller, int price)
|
||||||
{
|
{
|
||||||
emit beginInsertRows(QModelIndex(), marketplace_->getBasket().size(),
|
emit beginInsertRows(QModelIndex(), marketplace_->getBasket().size(),
|
||||||
|
@ -100,8 +88,8 @@ void BasketModel::addArticle(Seller* seller, int price)
|
||||||
auto article = std::make_unique<Article>(price);
|
auto article = std::make_unique<Article>(price);
|
||||||
article->createUuid();
|
article->createUuid();
|
||||||
article->setArticleNo(marketplace_->getNextArticleNo());
|
article->setArticleNo(marketplace_->getNextArticleNo());
|
||||||
|
article->setSourceNo(QSettings().value("global/cashPointNo").toInt());
|
||||||
article->setSeller(seller);
|
article->setSeller(seller);
|
||||||
// std::cout << "!!! Neuer Artikel: " << article->getPrice() << " Cent \n";
|
|
||||||
marketplace_->addArticleToBasket(std::move(article));
|
marketplace_->addArticleToBasket(std::move(article));
|
||||||
emit endInsertRows();
|
emit endInsertRows();
|
||||||
}
|
}
|
||||||
|
@ -109,7 +97,10 @@ void BasketModel::addArticle(Seller* seller, int price)
|
||||||
void BasketModel::finishSale()
|
void BasketModel::finishSale()
|
||||||
{
|
{
|
||||||
emit beginRemoveRows(QModelIndex(), 0, marketplace_->getBasket().size() - 1);
|
emit beginRemoveRows(QModelIndex(), 0, marketplace_->getBasket().size() - 1);
|
||||||
marketplace_->finishCurrentSale();
|
auto sale = std::make_unique<Sale>();
|
||||||
|
sale->createUuid();
|
||||||
|
sale->setSourceNo(QSettings().value("global/cashPointNo").toInt());
|
||||||
|
marketplace_->finishCurrentSale(std::move(sale));
|
||||||
emit endRemoveRows();
|
emit endRemoveRows();
|
||||||
emit basketDataChanged();
|
emit basketDataChanged();
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,7 @@ void MainWindow::onPaidButtonTriggered()
|
||||||
dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale();
|
dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale();
|
||||||
ui_.lastPriceLabel1->setText(lastPrice);
|
ui_.lastPriceLabel1->setText(lastPrice);
|
||||||
ui_.lastPriceLabel2->setText(lastPrice);
|
ui_.lastPriceLabel2->setText(lastPrice);
|
||||||
|
ui_.basketSumLabel->setText(" 0,00 €");
|
||||||
statusBar()->showMessage("Verkaufsvorgang erfolgreich durchgeführt.", STATUSBAR_TIMEOUT);
|
statusBar()->showMessage("Verkaufsvorgang erfolgreich durchgeführt.", STATUSBAR_TIMEOUT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,8 +129,7 @@ void MainWindow::onSellerNoEditCheckSellerNo()
|
||||||
if (dialogResult == QDialog::Accepted) {
|
if (dialogResult == QDialog::Accepted) {
|
||||||
int price = priceDialog.getPrice();
|
int price = priceDialog.getPrice();
|
||||||
dynamic_cast<BasketModel*>(ui_.basketView->model())->addArticle(seller, price);
|
dynamic_cast<BasketModel*>(ui_.basketView->model())->addArticle(seller, price);
|
||||||
std::string sumStr = "Gesamt: " + marketplace_->getBasketSumAsString();
|
ui_.basketSumLabel->setText(marketplace_->getBasketSumAsString().c_str());
|
||||||
ui_.basketSumLabel->setText(sumStr.c_str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
<widget class="QLabel" name="basketSumLabel">
|
<widget class="QLabel" name="basketSumLabel">
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
|
<family>Monospace</family>
|
||||||
<pointsize>18</pointsize>
|
<pointsize>18</pointsize>
|
||||||
<weight>75</weight>
|
<weight>75</weight>
|
||||||
<bold>true</bold>
|
<bold>true</bold>
|
||||||
|
@ -42,7 +43,7 @@
|
||||||
<enum>QFrame::Box</enum>
|
<enum>QFrame::Box</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Gesamt: ---</string>
|
<string> 0,00 €</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignCenter</set>
|
<set>Qt::AlignCenter</set>
|
||||||
|
@ -298,6 +299,7 @@ drucken</string>
|
||||||
<widget class="QLabel" name="lastPriceLabel1">
|
<widget class="QLabel" name="lastPriceLabel1">
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
|
<family>Monospace</family>
|
||||||
<pointsize>20</pointsize>
|
<pointsize>20</pointsize>
|
||||||
<weight>75</weight>
|
<weight>75</weight>
|
||||||
<bold>true</bold>
|
<bold>true</bold>
|
||||||
|
@ -351,6 +353,7 @@ drucken</string>
|
||||||
<widget class="QLabel" name="lastPriceLabel2">
|
<widget class="QLabel" name="lastPriceLabel2">
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
|
<family>Monospace</family>
|
||||||
<pointsize>20</pointsize>
|
<pointsize>20</pointsize>
|
||||||
<weight>75</weight>
|
<weight>75</weight>
|
||||||
<bold>true</bold>
|
<bold>true</bold>
|
||||||
|
|
|
@ -17,7 +17,14 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableView" name="reportView"/>
|
<widget class="QTableView" name="reportView">
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::SingleSelection</enum>
|
||||||
|
</property>
|
||||||
|
<property name="selectionBehavior">
|
||||||
|
<enum>QAbstractItemView::SelectRows</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
|
|
@ -35,6 +35,10 @@ QVariant ReportModel::data(const QModelIndex& index, int role) const
|
||||||
if (role == Qt::TextAlignmentRole) {
|
if (role == Qt::TextAlignmentRole) {
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 4:
|
case 4:
|
||||||
|
[[fallthrough]];
|
||||||
|
case 5:
|
||||||
|
[[fallthrough]];
|
||||||
|
case 6:
|
||||||
return Qt::AlignRight;
|
return Qt::AlignRight;
|
||||||
default:
|
default:
|
||||||
return Qt::AlignLeft;
|
return Qt::AlignLeft;
|
||||||
|
|
|
@ -108,7 +108,7 @@ QVariant SaleModel::data(const QModelIndex& index, int role) const
|
||||||
Article* article = static_cast<Article*>(index.internalPointer());
|
Article* article = static_cast<Article*>(index.internalPointer());
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0:
|
case 0:
|
||||||
return article->getArticleNo();
|
return article->getCompleteArticleNo().c_str();
|
||||||
case 1:
|
case 1:
|
||||||
return article->getPriceAsString().c_str();
|
return article->getPriceAsString().c_str();
|
||||||
case 2:
|
case 2:
|
||||||
|
|
Loading…
Reference in a new issue