Browse Source

lots of smaller improvements

allow_new_sellers
Martin Brodbeck 4 years ago
parent
commit
84f71ea056
  1. 13
      src/core/article.cpp
  2. 3
      src/core/article.h
  3. 6
      src/core/entity.h
  4. 11
      src/core/marketplace.cpp
  5. 2
      src/core/marketplace.h
  6. 2
      src/core/sale.cpp
  7. 2
      src/core/seller.cpp
  8. 10
      src/gui/basketmodel.cpp
  9. 4
      src/gui/mainwindow.cpp
  10. 5
      src/gui/mainwindow.ui
  11. 9
      src/gui/reportdialog.ui
  12. 4
      src/gui/reportmodel.cpp
  13. 2
      src/gui/salemodel.cpp

13
src/core/article.cpp

@ -31,9 +31,16 @@ int Article::getPrice() const { return price_; }
std::string Article::getPriceAsString() const
{
std::stringstream sumStream;
//sumStream.imbue(std::locale("de_DE.utf8"));
sumStream << std::right << std::setw(12) << std::showbase << std::put_money(price_, false);
// sumStream.imbue(std::locale("de_DE.utf8"));
sumStream << std::right << std::setw(10) << std::showbase << std::put_money(price_, false);
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();
}

3
src/core/article.h

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

6
src/core/entity.h

@ -11,7 +11,7 @@ class Entity
public:
enum class State { NEW, UPDATE, DELETE, OK };
//Entity() = default;
// Entity() = default;
virtual ~Entity() = 0;
void createUuid();
@ -24,10 +24,12 @@ class Entity
virtual State getState() const;
virtual int getSourceNo() const;
protected:
int sourceNo_{};
private:
boost::uuids::uuid uuid_{};
State state_{State::NEW};
int sourceNo_{};
};
#endif // ENTITY_H

11
src/core/marketplace.cpp

@ -89,14 +89,11 @@ void Marketplace::addArticleToBasket(std::unique_ptr<Article> article)
size_t Marketplace::basketSize() { return basket_.size(); }
void Marketplace::finishCurrentSale()
void Marketplace::finishCurrentSale(std::unique_ptr<Sale> sale)
{
if (basket_.size() == 0)
return;
auto sale = std::make_unique<Sale>();
sale->createUuid();
for (auto iter = basket_.begin(); iter != basket_.end(); ++iter) {
sale->addArticle((*iter).get());
(*iter)->getSeller()->addArticle(std::move(*iter));
@ -125,7 +122,7 @@ std::string Marketplace::getBasketSumAsString()
// return sumStream.str();
std::stringstream sumStream;
// 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();
}
@ -148,7 +145,7 @@ double marketFee(int sum, int percent, int maxFee)
std::string marketFeeAsString(int sum, int percent, int maxFee)
{
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);
return feeStream.str();
}
@ -156,7 +153,7 @@ std::string marketFeeAsString(int sum, int percent, int maxFee)
std::string paymentAsString(int sum, int percent)
{
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);
return feeStream.str();
}

2
src/core/marketplace.h

@ -38,7 +38,7 @@ class Marketplace
Seller* findSellerWithSellerNo(int sellerNo);
void addArticleToBasket(std::unique_ptr<Article> article);
size_t basketSize();
void finishCurrentSale();
void finishCurrentSale(std::unique_ptr<Sale> sale);
void removeSale(boost::uuids::uuid uuid);
private:

2
src/core/sale.cpp

@ -34,7 +34,7 @@ int Sale::sumInCents()
std::string Sale::sumAsString()
{
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();
}

2
src/core/seller.cpp

@ -94,7 +94,7 @@ int Seller::sumInCents()
std::string Seller::sumAsString()
{
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();
}

10
src/gui/basketmodel.cpp

@ -24,7 +24,8 @@ QVariant BasketModel::data(const QModelIndex& index, int role) const
case 0:
[[fallthrough]];
case 1:
[[fallthrough]];
myFont.setFamily("monospace");
return myFont;
case 2:
return myFont;
case 3:
@ -45,7 +46,7 @@ QVariant BasketModel::data(const QModelIndex& index, int role) const
case 0:
return article->getUuidAsString().c_str();
case 1:
return article->getArticleNo();
return article->getCompleteArticleNo().c_str();
case 2:
return article->getSeller()->getSellerNo();
case 3:
@ -96,7 +97,10 @@ void BasketModel::addArticle(Seller* seller, int price)
void BasketModel::finishSale()
{
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 basketDataChanged();
}

4
src/gui/mainwindow.cpp

@ -96,6 +96,7 @@ void MainWindow::onPaidButtonTriggered()
dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale();
ui_.lastPriceLabel1->setText(lastPrice);
ui_.lastPriceLabel2->setText(lastPrice);
ui_.basketSumLabel->setText(" 0,00 €");
statusBar()->showMessage("Verkaufsvorgang erfolgreich durchgeführt.", STATUSBAR_TIMEOUT);
}
}
@ -128,8 +129,7 @@ void MainWindow::onSellerNoEditCheckSellerNo()
if (dialogResult == QDialog::Accepted) {
int price = priceDialog.getPrice();
dynamic_cast<BasketModel*>(ui_.basketView->model())->addArticle(seller, price);
std::string sumStr = "Gesamt: " + marketplace_->getBasketSumAsString();
ui_.basketSumLabel->setText(sumStr.c_str());
ui_.basketSumLabel->setText(marketplace_->getBasketSumAsString().c_str());
}
}

5
src/gui/mainwindow.ui

@ -33,6 +33,7 @@
<widget class="QLabel" name="basketSumLabel">
<property name="font">
<font>
<family>Monospace</family>
<pointsize>18</pointsize>
<weight>75</weight>
<bold>true</bold>
@ -42,7 +43,7 @@
<enum>QFrame::Box</enum>
</property>
<property name="text">
<string>Gesamt: ---</string>
<string> 0,00 €</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
@ -298,6 +299,7 @@ drucken</string>
<widget class="QLabel" name="lastPriceLabel1">
<property name="font">
<font>
<family>Monospace</family>
<pointsize>20</pointsize>
<weight>75</weight>
<bold>true</bold>
@ -351,6 +353,7 @@ drucken</string>
<widget class="QLabel" name="lastPriceLabel2">
<property name="font">
<font>
<family>Monospace</family>
<pointsize>20</pointsize>
<weight>75</weight>
<bold>true</bold>

9
src/gui/reportdialog.ui

@ -17,7 +17,14 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<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>
<layout class="QVBoxLayout" name="verticalLayout">

4
src/gui/reportmodel.cpp

@ -35,6 +35,10 @@ QVariant ReportModel::data(const QModelIndex& index, int role) const
if (role == Qt::TextAlignmentRole) {
switch (index.column()) {
case 4:
[[fallthrough]];
case 5:
[[fallthrough]];
case 6:
return Qt::AlignRight;
default:
return Qt::AlignLeft;

2
src/gui/salemodel.cpp

@ -108,7 +108,7 @@ QVariant SaleModel::data(const QModelIndex& index, int role) const
Article* article = static_cast<Article*>(index.internalPointer());
switch (index.column()) {
case 0:
return article->getArticleNo();
return article->getCompleteArticleNo().c_str();
case 1:
return article->getPriceAsString().c_str();
case 2:

Loading…
Cancel
Save