diff --git a/src/core/marketplace.cpp b/src/core/marketplace.cpp index d59b281..818e614 100644 --- a/src/core/marketplace.cpp +++ b/src/core/marketplace.cpp @@ -134,4 +134,26 @@ void Marketplace::removeSale(boost::uuids::uuid uuid) sales_.erase(std::remove_if(sales_.begin(), sales_.end(), [&uuid](const auto& a) { return a->getUuid() == uuid; }), sales_.end()); +} + +double marketFee(int sum, int percent, int maxFee) +{ + int fee = (sum * percent) / 100.0L; + return fee > maxFee ? maxFee : fee; +} + +std::string marketFeeAsString(int sum, int percent, int maxFee) +{ + std::stringstream feeStream; + feeStream << std::right << std::setw(12) << std::showbase + << std::put_money(marketFee(sum, percent, maxFee), false); + return feeStream.str(); +} + +std::string paymentAsString(int sum, int percent) +{ + std::stringstream feeStream; + feeStream << std::right << std::setw(12) << std::showbase + << std::put_money(sum - marketFee(sum, percent), false); + return feeStream.str(); } \ No newline at end of file diff --git a/src/core/marketplace.h b/src/core/marketplace.h index ce27420..7bddb72 100644 --- a/src/core/marketplace.h +++ b/src/core/marketplace.h @@ -47,4 +47,8 @@ class Marketplace BasketVec basket_; }; +double marketFee(int sum, int percent, int maxFee = 5000); +std::string marketFeeAsString(int sum, int percent, int maxFee = 5000); +std::string paymentAsString(int sum, int percent); + #endif \ No newline at end of file diff --git a/src/core/seller.cpp b/src/core/seller.cpp index 82aaa6b..61e48ef 100644 --- a/src/core/seller.cpp +++ b/src/core/seller.cpp @@ -1,5 +1,9 @@ #include "seller.h" +#include +#include +#include + Seller::Seller(const std::string& firstName, const std::string& lastName, int sellerNo, int numArticlesOffered) : Entity() @@ -80,6 +84,20 @@ void Seller::cleanupArticles() } } +int Seller::sumInCents() +{ + int sum = std::accumulate(articles_.begin(), articles_.end(), 0, + [](int a, const auto& b) { return a + b->getPrice(); }); + return sum; +} + +std::string Seller::sumAsString() +{ + std::stringstream sumStream; + sumStream << std::right << std::setw(12) << std::showbase << std::put_money(sumInCents(), false); + return sumStream.str(); +} + // int Seller::numArticlesTotal() const { return static_cast(getArticles().size()); } bool operator<(const Seller& li, const Seller& re) { return li.sellerNo_ < re.sellerNo_; } diff --git a/src/core/seller.h b/src/core/seller.h index c51bccb..b46a055 100644 --- a/src/core/seller.h +++ b/src/core/seller.h @@ -34,6 +34,8 @@ class Seller : public Entity std::vector getArticles(bool onlySold = true) const; Article* getArticleByUuid(const std::string& uuidString); int getMaxArticleNo() const; + int sumInCents(); + std::string sumAsString(); friend bool operator<(const Seller& li, const Seller& re); friend bool operator<(const std::unique_ptr& li, const std::unique_ptr& re); diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 9770d58..f3d9914 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -19,6 +19,9 @@ set(GUI_SOURCES pricedialog.ui basketmodel.cpp salemodel.cpp + reportdialog.cpp + reportdialog.ui + reportmodel.cpp ) add_executable(kima2 ${GUI_SOURCES}) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index f79a472..ca0dd6c 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -2,6 +2,7 @@ #include "basketmodel.h" #include "pricedialog.h" +#include "reportdialog.h" #include "salemodel.h" #include "sellerdialog.h" @@ -47,6 +48,7 @@ MainWindow::MainWindow() connect(static_cast(ui_.basketView->model()), &BasketModel::basketDataChanged, static_cast(ui_.salesView->model()), &SaleModel::onBasketDataChanged); connect(ui_.aboutQtAction, &QAction::triggered, this, &MainWindow::onAboutQt); + connect(ui_.reportAction, &QAction::triggered, this, [=]() { ReportDialog(this).exec(); }); } void MainWindow::onActionEditSellerTriggered() diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index dfd7810..80b52d6 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -385,7 +385,7 @@ drucken 0 0 817 - 14 + 24 @@ -409,8 +409,15 @@ drucken + + + &Extras + + + + @@ -443,6 +450,11 @@ drucken Über Qt + + + Auswertung + + diff --git a/src/gui/reportdialog.cpp b/src/gui/reportdialog.cpp new file mode 100644 index 0000000..9d5e9e2 --- /dev/null +++ b/src/gui/reportdialog.cpp @@ -0,0 +1,12 @@ +#include "reportdialog.h" + +#include "mainwindow.h" + +ReportDialog::ReportDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f) +{ + ui_.setupUi(this); + market_ = dynamic_cast(parent)->getMarketplace(); + model_ = std::make_unique(market_, ui_.reportView); + ui_.reportView->setModel(model_.get()); + ui_.reportView->hideColumn(0); +} \ No newline at end of file diff --git a/src/gui/reportdialog.h b/src/gui/reportdialog.h new file mode 100644 index 0000000..987cf73 --- /dev/null +++ b/src/gui/reportdialog.h @@ -0,0 +1,26 @@ +#ifndef REPORT_DIALOG_H +#define REPORT_DIALOG_H + +#include "ui_reportdialog.h" + +#include "reportmodel.h" + +#include + +#include + +class ReportDialog : public QDialog +{ + Q_OBJECT + + public: + ReportDialog(QWidget* parent = nullptr, + Qt::WindowFlags f = Qt::WindowTitleHint | Qt::WindowSystemMenuHint); + + private: + Ui::ReportDialog ui_; + Marketplace* market_; + std::unique_ptr model_; +}; + +#endif \ No newline at end of file diff --git a/src/gui/reportdialog.ui b/src/gui/reportdialog.ui new file mode 100644 index 0000000..f19e7ab --- /dev/null +++ b/src/gui/reportdialog.ui @@ -0,0 +1,112 @@ + + + ReportDialog + + + + 0 + 0 + 800 + 600 + + + + Auswertung + + + + + + + + + + + + + false + + + Quittung drucken + + + + + + + Exportieren (.csv) + + + + + + + Übersicht drucken + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + + buttonBox + accepted() + ReportDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ReportDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/gui/reportmodel.cpp b/src/gui/reportmodel.cpp new file mode 100644 index 0000000..52d2b2b --- /dev/null +++ b/src/gui/reportmodel.cpp @@ -0,0 +1,99 @@ +#include "reportmodel.h" + +#include + +ReportModel::ReportModel(Marketplace* market, QObject* parent) + : QAbstractTableModel(parent), market_(market) +{ +} + +int ReportModel::rowCount([[maybe_unused]] const QModelIndex& parent) const +{ + return static_cast(market_->getSellers().size()); +} + +int ReportModel::columnCount([[maybe_unused]] const QModelIndex& parent) const { return 7; } + +QVariant ReportModel::data(const QModelIndex& index, int role) const +{ + if (role == Qt::FontRole) { + QFont myFont; + + switch (index.column()) { + case 4: + [[fallthrough]]; + case 5: + [[fallthrough]]; + case 6: + myFont.setFamily("monospace"); + return myFont; + default: + return myFont; + } + } + + if (role == Qt::TextAlignmentRole) { + switch (index.column()) { + case 4: + return Qt::AlignRight; + default: + return Qt::AlignLeft; + } + } + + if (role != Qt::DisplayRole) + return QVariant(); + + if (market_->getSellers().size() == 0) + return QVariant(); + + Seller* seller = market_->getSellers().at(index.row()).get(); + + switch (index.column()) { + case 0: + return seller->getUuidAsString().c_str(); + case 1: + return seller->getSellerNo(); + case 2: + return seller->getLastName().c_str(); + case 3: + return seller->getFirstName().c_str(); + case 4: + return seller->numArticlesSold(); + case 5: + return seller->sumAsString().c_str(); + case 6: + return paymentAsString(seller->sumInCents(), 20).c_str(); + default: + return "???"; + } +} + +QVariant ReportModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + if (orientation == Qt::Horizontal) { + switch (section) { + case 0: + return "ID"; + case 1: + return "Nummer"; + case 2: + return "Nachname"; + case 3: + return "Vorname"; + case 4: + return "verkauft"; + case 5: + return "Umsatz"; + case 6: + return "Auszahlung"; + default: + return "???"; + } + // return QStringLiteral("%1").arg(section); + } else + return ""; +} \ No newline at end of file diff --git a/src/gui/reportmodel.h b/src/gui/reportmodel.h new file mode 100644 index 0000000..f880e03 --- /dev/null +++ b/src/gui/reportmodel.h @@ -0,0 +1,21 @@ +#ifndef REPORT_MODEL_H +#define REPORT_MODEL_H + +#include + +#include + +class ReportModel : public QAbstractTableModel +{ + public: + explicit ReportModel(Marketplace* market, QObject* parent = nullptr); + virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override; + virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override; + virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + + private: + Marketplace* market_; +}; + +#endif \ No newline at end of file