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 <algorithm>
#include <numeric>
#include <sstream>
#include <iomanip>
Marketplace::Marketplace()
{
@ -99,4 +102,20 @@ void Marketplace::finishCurrentSale()
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 getNumSellersDelete();
BasketVec& getBasket();
int getBasketSumInCent();
std::string getBasketSumAsString();
void sortSellers();
Seller* findSellerWithSellerNo(int sellerNo);

View File

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

View File

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