show last sum

This commit is contained in:
Martin Brodbeck 2018-07-23 14:18:24 +02:00
parent 527241a0f3
commit 3efa289b5b
4 changed files with 48 additions and 47 deletions

View file

@ -2,6 +2,9 @@
#include "database.h" #include "database.h"
#include <algorithm> #include <algorithm>
#include <numeric>
#include <sstream>
#include <iomanip>
Marketplace::Marketplace() Marketplace::Marketplace()
{ {
@ -99,4 +102,20 @@ void Marketplace::finishCurrentSale()
storeToDb(); storeToDb();
} }
BasketVec& Marketplace::getBasket() { return basket_; } BasketVec& Marketplace::getBasket() { return basket_; }
int Marketplace::getBasketSumInCent()
{
int sum = std::accumulate(basket_.begin(), basket_.end(), 0,
[](int a, const auto& b) { return a + b->getPrice(); });
return sum;
}
std::string Marketplace::getBasketSumAsString()
{
int sumInCent = getBasketSumInCent();
double sumInEuro = sumInCent / 100.0L;
std::stringstream sumStream;
sumStream << std::fixed << std::setprecision(2) << sumInEuro << "";
return sumStream.str();
}

View file

@ -30,6 +30,8 @@ class Marketplace
int getNextArticleNo(); int getNextArticleNo();
int getNumSellersDelete(); int getNumSellersDelete();
BasketVec& getBasket(); BasketVec& getBasket();
int getBasketSumInCent();
std::string getBasketSumAsString();
void sortSellers(); void sortSellers();
Seller* findSellerWithSellerNo(int sellerNo); Seller* findSellerWithSellerNo(int sellerNo);

View file

@ -55,7 +55,10 @@ void MainWindow::on_actionEditSeller_triggered()
void MainWindow::on_paidButton_triggered() void MainWindow::on_paidButton_triggered()
{ {
if (marketplace_->basketSize() > 0) { if (marketplace_->basketSize() > 0) {
QString lastPrice{marketplace_->getBasketSumAsString().c_str()};
dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale(); dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale();
ui_.lastPriceLabel1->setText(lastPrice);
ui_.lastPriceLabel2->setText(lastPrice);
} }
} }
@ -66,9 +69,7 @@ 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) { on_paidButton_triggered();
dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale();
}
return; return;
} }
@ -76,6 +77,7 @@ void MainWindow::on_sellerNoEdit_checkSellerNo()
smatch result; smatch result;
if (!regex_match(inputText, result, pattern)) { if (!regex_match(inputText, result, pattern)) {
ui_.sellerNoEdit->clear();
return; return;
} }
@ -139,6 +141,6 @@ void MainWindow::onCancelAllArticlesButtonClicked([[maybe_unused]] bool checked)
.exec(); .exec();
if (dlgResult == QMessageBox::No) if (dlgResult == QMessageBox::No)
return; return;
dynamic_cast<BasketModel*>(ui_.basketView->model())->cancelSale(); dynamic_cast<BasketModel*>(ui_.basketView->model())->cancelSale();
} }

View file

@ -53,56 +53,31 @@
<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"> <property name="font">
<font> <font>
<pointsize>14</pointsize>
<weight>75</weight> <weight>75</weight>
<bold>true</bold> <bold>true</bold>
</font> </font>
</property> </property>
<property name="placeholderText"> <property name="toolTip">
<string>Eingabe Verk.-Nr.</string> <string>Geben Sie hier die Verkäufernummer ein</string>
</property>
<property name="statusTip">
<string>Geben Sie hier die Verkäufernummer ein</string>
</property>
<property name="whatsThis">
<string/>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="paidButton"> <widget class="QPushButton" name="paidButton">
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
<property name="text"> <property name="text">
<string>Bezahlt!</string> <string>Bezahlt!</string>
</property> </property>
@ -320,7 +295,7 @@ drucken</string>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_6"> <widget class="QLabel" name="lastPriceLabel1">
<property name="font"> <property name="font">
<font> <font>
<pointsize>20</pointsize> <pointsize>20</pointsize>
@ -341,7 +316,7 @@ drucken</string>
<string>-,-- €</string> <string>-,-- €</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property> </property>
<property name="margin"> <property name="margin">
<number>5</number> <number>5</number>
@ -373,7 +348,7 @@ drucken</string>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_8"> <widget class="QLabel" name="lastPriceLabel2">
<property name="font"> <property name="font">
<font> <font>
<pointsize>20</pointsize> <pointsize>20</pointsize>
@ -390,6 +365,9 @@ drucken</string>
<property name="text"> <property name="text">
<string>-,-- €</string> <string>-,-- €</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="margin"> <property name="margin">
<number>5</number> <number>5</number>
</property> </property>