diff --git a/src/core/marketplace.cpp b/src/core/marketplace.cpp index a212363..ea93303 100644 --- a/src/core/marketplace.cpp +++ b/src/core/marketplace.cpp @@ -2,6 +2,9 @@ #include "database.h" #include +#include +#include +#include Marketplace::Marketplace() { @@ -99,4 +102,20 @@ void Marketplace::finishCurrentSale() storeToDb(); } -BasketVec& Marketplace::getBasket() { return basket_; } \ No newline at end of file +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(); +} \ No newline at end of file diff --git a/src/core/marketplace.h b/src/core/marketplace.h index 7b8c4ea..e515686 100644 --- a/src/core/marketplace.h +++ b/src/core/marketplace.h @@ -30,6 +30,8 @@ class Marketplace int getNextArticleNo(); int getNumSellersDelete(); BasketVec& getBasket(); + int getBasketSumInCent(); + std::string getBasketSumAsString(); void sortSellers(); Seller* findSellerWithSellerNo(int sellerNo); diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index fd73bab..1a4df3e 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -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(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(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(ui_.basketView->model())->cancelSale(); } \ No newline at end of file diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index d9f84f0..6491372 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -53,56 +53,31 @@ - - - - - - - 197 - 255 - 169 - - - - - - - - - 197 - 255 - 169 - - - - - - - - - 239 - 239 - 239 - - - - - - + 14 75 true - - Eingabe Verk.-Nr. + + Geben Sie hier die Verkäufernummer ein + + + Geben Sie hier die Verkäufernummer ein + + + + + + 14 + + Bezahlt! @@ -320,7 +295,7 @@ drucken - + 20 @@ -341,7 +316,7 @@ drucken -,-- € - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter 5 @@ -373,7 +348,7 @@ drucken - + 20 @@ -390,6 +365,9 @@ drucken -,-- € + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + 5