new report dialog
This commit is contained in:
parent
efb1f3ffbf
commit
06c99052df
12 changed files with 334 additions and 1 deletions
|
@ -134,4 +134,26 @@ void Marketplace::removeSale(boost::uuids::uuid uuid)
|
||||||
sales_.erase(std::remove_if(sales_.begin(), sales_.end(),
|
sales_.erase(std::remove_if(sales_.begin(), sales_.end(),
|
||||||
[&uuid](const auto& a) { return a->getUuid() == uuid; }),
|
[&uuid](const auto& a) { return a->getUuid() == uuid; }),
|
||||||
sales_.end());
|
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();
|
||||||
}
|
}
|
|
@ -47,4 +47,8 @@ class Marketplace
|
||||||
BasketVec basket_;
|
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
|
#endif
|
|
@ -1,5 +1,9 @@
|
||||||
#include "seller.h"
|
#include "seller.h"
|
||||||
|
|
||||||
|
#include <numeric>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
Seller::Seller(const std::string& firstName, const std::string& lastName, int sellerNo,
|
Seller::Seller(const std::string& firstName, const std::string& lastName, int sellerNo,
|
||||||
int numArticlesOffered)
|
int numArticlesOffered)
|
||||||
: Entity()
|
: 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<int>(getArticles().size()); }
|
// int Seller::numArticlesTotal() const { return static_cast<int>(getArticles().size()); }
|
||||||
|
|
||||||
bool operator<(const Seller& li, const Seller& re) { return li.sellerNo_ < re.sellerNo_; }
|
bool operator<(const Seller& li, const Seller& re) { return li.sellerNo_ < re.sellerNo_; }
|
||||||
|
|
|
@ -34,6 +34,8 @@ class Seller : public Entity
|
||||||
std::vector<Article*> getArticles(bool onlySold = true) const;
|
std::vector<Article*> getArticles(bool onlySold = true) const;
|
||||||
Article* getArticleByUuid(const std::string& uuidString);
|
Article* getArticleByUuid(const std::string& uuidString);
|
||||||
int getMaxArticleNo() const;
|
int getMaxArticleNo() const;
|
||||||
|
int sumInCents();
|
||||||
|
std::string sumAsString();
|
||||||
|
|
||||||
friend bool operator<(const Seller& li, const Seller& re);
|
friend bool operator<(const Seller& li, const Seller& re);
|
||||||
friend bool operator<(const std::unique_ptr<Seller>& li, const std::unique_ptr<Seller>& re);
|
friend bool operator<(const std::unique_ptr<Seller>& li, const std::unique_ptr<Seller>& re);
|
||||||
|
|
|
@ -19,6 +19,9 @@ set(GUI_SOURCES
|
||||||
pricedialog.ui
|
pricedialog.ui
|
||||||
basketmodel.cpp
|
basketmodel.cpp
|
||||||
salemodel.cpp
|
salemodel.cpp
|
||||||
|
reportdialog.cpp
|
||||||
|
reportdialog.ui
|
||||||
|
reportmodel.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(kima2 ${GUI_SOURCES})
|
add_executable(kima2 ${GUI_SOURCES})
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "basketmodel.h"
|
#include "basketmodel.h"
|
||||||
#include "pricedialog.h"
|
#include "pricedialog.h"
|
||||||
|
#include "reportdialog.h"
|
||||||
#include "salemodel.h"
|
#include "salemodel.h"
|
||||||
#include "sellerdialog.h"
|
#include "sellerdialog.h"
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ MainWindow::MainWindow()
|
||||||
connect(static_cast<BasketModel*>(ui_.basketView->model()), &BasketModel::basketDataChanged,
|
connect(static_cast<BasketModel*>(ui_.basketView->model()), &BasketModel::basketDataChanged,
|
||||||
static_cast<SaleModel*>(ui_.salesView->model()), &SaleModel::onBasketDataChanged);
|
static_cast<SaleModel*>(ui_.salesView->model()), &SaleModel::onBasketDataChanged);
|
||||||
connect(ui_.aboutQtAction, &QAction::triggered, this, &MainWindow::onAboutQt);
|
connect(ui_.aboutQtAction, &QAction::triggered, this, &MainWindow::onAboutQt);
|
||||||
|
connect(ui_.reportAction, &QAction::triggered, this, [=]() { ReportDialog(this).exec(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onActionEditSellerTriggered()
|
void MainWindow::onActionEditSellerTriggered()
|
||||||
|
|
|
@ -385,7 +385,7 @@ drucken</string>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>817</width>
|
<width>817</width>
|
||||||
<height>14</height>
|
<height>24</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menu_Datei">
|
<widget class="QMenu" name="menu_Datei">
|
||||||
|
@ -409,8 +409,15 @@ drucken</string>
|
||||||
<addaction name="aboutAction"/>
|
<addaction name="aboutAction"/>
|
||||||
<addaction name="aboutQtAction"/>
|
<addaction name="aboutQtAction"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuExtras">
|
||||||
|
<property name="title">
|
||||||
|
<string>&Extras</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="reportAction"/>
|
||||||
|
</widget>
|
||||||
<addaction name="menu_Datei"/>
|
<addaction name="menu_Datei"/>
|
||||||
<addaction name="menu_Edit"/>
|
<addaction name="menu_Edit"/>
|
||||||
|
<addaction name="menuExtras"/>
|
||||||
<addaction name="menuHilfe"/>
|
<addaction name="menuHilfe"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar"/>
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
@ -443,6 +450,11 @@ drucken</string>
|
||||||
<string>Über Qt</string>
|
<string>Über Qt</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="reportAction">
|
||||||
|
<property name="text">
|
||||||
|
<string>Auswertung</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|
12
src/gui/reportdialog.cpp
Normal file
12
src/gui/reportdialog.cpp
Normal file
|
@ -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<MainWindow*>(parent)->getMarketplace();
|
||||||
|
model_ = std::make_unique<ReportModel>(market_, ui_.reportView);
|
||||||
|
ui_.reportView->setModel(model_.get());
|
||||||
|
ui_.reportView->hideColumn(0);
|
||||||
|
}
|
26
src/gui/reportdialog.h
Normal file
26
src/gui/reportdialog.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#ifndef REPORT_DIALOG_H
|
||||||
|
#define REPORT_DIALOG_H
|
||||||
|
|
||||||
|
#include "ui_reportdialog.h"
|
||||||
|
|
||||||
|
#include "reportmodel.h"
|
||||||
|
|
||||||
|
#include <marketplace.h>
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
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<ReportModel> model_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
112
src/gui/reportdialog.ui
Normal file
112
src/gui/reportdialog.ui
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>ReportDialog</class>
|
||||||
|
<widget class="QDialog" name="ReportDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>600</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Auswertung</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTableView" name="reportView"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Quittung drucken</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Exportieren (.csv)</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Übersicht drucken</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Close</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>ReportDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>ReportDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
99
src/gui/reportmodel.cpp
Normal file
99
src/gui/reportmodel.cpp
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
#include "reportmodel.h"
|
||||||
|
|
||||||
|
#include <QFont>
|
||||||
|
|
||||||
|
ReportModel::ReportModel(Marketplace* market, QObject* parent)
|
||||||
|
: QAbstractTableModel(parent), market_(market)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int ReportModel::rowCount([[maybe_unused]] const QModelIndex& parent) const
|
||||||
|
{
|
||||||
|
return static_cast<int>(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 "";
|
||||||
|
}
|
21
src/gui/reportmodel.h
Normal file
21
src/gui/reportmodel.h
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#ifndef REPORT_MODEL_H
|
||||||
|
#define REPORT_MODEL_H
|
||||||
|
|
||||||
|
#include <marketplace.h>
|
||||||
|
|
||||||
|
#include <QAbstractTableModel>
|
||||||
|
|
||||||
|
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
|
Loading…
Reference in a new issue