Compare commits

..

No commits in common. "84f71ea056cea23a10faa5a4302eea4abf51371d" and "9e85e2892dbdd9657eca8efb2148a2c237fc6d3c" have entirely different histories.

13 changed files with 39 additions and 51 deletions

View file

@ -32,15 +32,8 @@ 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(10) << std::showbase << std::put_money(price_, false); sumStream << std::right << std::setw(12) << std::showbase << std::put_money(price_, false);
return sumStream.str(); return sumStream.str();
} }
int Article::getArticleNo() const { return articleNo_; } int Article::getArticleNo() { return articleNo_; }
std::string Article::getCompleteArticleNo() const
{
std::stringstream artNoStream;
artNoStream << sourceNo_ << "K" << std::setfill('0') << std::setw(5) << articleNo_;
return artNoStream.str();
}

View file

@ -25,8 +25,7 @@ class Article : public Entity
void setSale(Sale* salePtr); void setSale(Sale* salePtr);
void setSeller(Seller* sellerPtr); void setSeller(Seller* sellerPtr);
int getArticleNo() const; int getArticleNo();
std::string getCompleteArticleNo() const;
std::string getDescription(); std::string getDescription();
Seller* getSeller(); Seller* getSeller();
Sale* getSale(); Sale* getSale();

View file

@ -24,12 +24,10 @@ 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

View file

@ -89,11 +89,14 @@ 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(std::unique_ptr<Sale> sale) void Marketplace::finishCurrentSale()
{ {
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));
@ -122,7 +125,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(10) << 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();
} }
@ -145,7 +148,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(10) << std::showbase feeStream << std::right << std::setw(12) << std::showbase
<< std::put_money(marketFee(sum, percent, maxFee), false); << std::put_money(marketFee(sum, percent, maxFee), false);
return feeStream.str(); return feeStream.str();
} }
@ -153,7 +156,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(10) << std::showbase feeStream << std::right << std::setw(12) << std::showbase
<< std::put_money(sum - marketFee(sum, percent), false); << std::put_money(sum - marketFee(sum, percent), false);
return feeStream.str(); return feeStream.str();
} }

View file

@ -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(std::unique_ptr<Sale> sale); void finishCurrentSale();
void removeSale(boost::uuids::uuid uuid); void removeSale(boost::uuids::uuid uuid);
private: private:

View file

@ -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(10) << std::showbase << std::put_money(sumInCents(), false); sumStream << std::right << std::setw(12) << std::showbase << std::put_money(sumInCents(), false);
return sumStream.str(); return sumStream.str();
} }

View file

@ -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(10) << std::showbase << std::put_money(sumInCents(), false); sumStream << std::right << std::setw(12) << std::showbase << std::put_money(sumInCents(), false);
return sumStream.str(); return sumStream.str();
} }

View file

@ -1,7 +1,6 @@
#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)
@ -24,8 +23,7 @@ QVariant BasketModel::data(const QModelIndex& index, int role) const
case 0: case 0:
[[fallthrough]]; [[fallthrough]];
case 1: case 1:
myFont.setFamily("monospace"); [[fallthrough]];
return myFont;
case 2: case 2:
return myFont; return myFont;
case 3: case 3:
@ -46,7 +44,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->getCompleteArticleNo().c_str(); return article->getArticleNo();
case 2: case 2:
return article->getSeller()->getSellerNo(); return article->getSeller()->getSellerNo();
case 3: case 3:
@ -81,6 +79,20 @@ 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(),
@ -88,8 +100,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();
} }
@ -97,10 +109,7 @@ 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);
auto sale = std::make_unique<Sale>(); marketplace_->finishCurrentSale();
sale->createUuid();
sale->setSourceNo(QSettings().value("global/cashPointNo").toInt());
marketplace_->finishCurrentSale(std::move(sale));
emit endRemoveRows(); emit endRemoveRows();
emit basketDataChanged(); emit basketDataChanged();
} }

View file

@ -96,7 +96,6 @@ 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);
} }
} }
@ -129,7 +128,8 @@ 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);
ui_.basketSumLabel->setText(marketplace_->getBasketSumAsString().c_str()); std::string sumStr = "Gesamt: " + marketplace_->getBasketSumAsString();
ui_.basketSumLabel->setText(sumStr.c_str());
} }
} }

View file

@ -33,7 +33,6 @@
<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>
@ -43,7 +42,7 @@
<enum>QFrame::Box</enum> <enum>QFrame::Box</enum>
</property> </property>
<property name="text"> <property name="text">
<string> 0,00 €</string> <string>Gesamt: ---</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>
@ -299,7 +298,6 @@ 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>
@ -353,7 +351,6 @@ 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>

View file

@ -17,14 +17,7 @@
<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">

View file

@ -35,10 +35,6 @@ 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;

View file

@ -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->getCompleteArticleNo().c_str(); return article->getArticleNo();
case 1: case 1:
return article->getPriceAsString().c_str(); return article->getPriceAsString().c_str();
case 2: case 2: