now printing reports
This commit is contained in:
parent
a6c5366b63
commit
4a41036aec
6 changed files with 138 additions and 5 deletions
|
@ -155,6 +155,47 @@ void Marketplace::exportReportToCSV(const std::string& filename, int feeInPercen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Marketplace::getOverallSumInCent()
|
||||||
|
{
|
||||||
|
int sum = std::accumulate(sellers_.begin(), sellers_.end(), 0,
|
||||||
|
[](int a, const auto& b) { return a + b->sumInCents(); });
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Marketplace::getOverallSumAsString()
|
||||||
|
{
|
||||||
|
int sum = getOverallSumInCent();
|
||||||
|
std::stringstream sumStream;
|
||||||
|
sumStream << std::right << std::setw(10) << std::showbase << std::put_money(sum, false);
|
||||||
|
return sumStream.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
int Marketplace::getOverallPaymentInCent(int percent, int maxFee)
|
||||||
|
{
|
||||||
|
int sum = std::accumulate(
|
||||||
|
sellers_.begin(), sellers_.end(), 0, [percent, maxFee](int a, const auto& b) {
|
||||||
|
return a + b->sumInCents() - marketFee(b->sumInCents(), percent, maxFee);
|
||||||
|
});
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Marketplace::getOverallPaymentAsString(int percent, int maxFee)
|
||||||
|
{
|
||||||
|
int sum = getOverallPaymentInCent(percent, maxFee);
|
||||||
|
std::stringstream sumStream;
|
||||||
|
sumStream << std::right << std::setw(10) << std::showbase << std::put_money(sum, false);
|
||||||
|
return sumStream.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Marketplace::getOverallRevenueAsString(int percent, int maxFee)
|
||||||
|
{
|
||||||
|
int sum = getOverallSumInCent();
|
||||||
|
int pay = getOverallPaymentInCent(percent, maxFee);
|
||||||
|
std::stringstream sumStream;
|
||||||
|
sumStream << std::right << std::setw(10) << std::showbase << std::put_money(sum - pay, false);
|
||||||
|
return sumStream.str();
|
||||||
|
}
|
||||||
|
|
||||||
double marketFee(int sum, int percent, int maxFee)
|
double marketFee(int sum, int percent, int maxFee)
|
||||||
{
|
{
|
||||||
int fee = (sum * percent) / 100.0L;
|
int fee = (sum * percent) / 100.0L;
|
||||||
|
|
|
@ -41,6 +41,12 @@ class Marketplace
|
||||||
void finishCurrentSale(std::unique_ptr<Sale> sale);
|
void finishCurrentSale(std::unique_ptr<Sale> sale);
|
||||||
void removeSale(boost::uuids::uuid uuid);
|
void removeSale(boost::uuids::uuid uuid);
|
||||||
|
|
||||||
|
int getOverallSumInCent();
|
||||||
|
std::string getOverallSumAsString();
|
||||||
|
int getOverallPaymentInCent(int percent, int maxFee);
|
||||||
|
std::string getOverallPaymentAsString(int percent, int maxFee);
|
||||||
|
std::string getOverallRevenueAsString(int percent, int maxFee);
|
||||||
|
|
||||||
void exportReportToCSV(const std::string& filename, int feeInPercent, int maxFeeInEuro);
|
void exportReportToCSV(const std::string& filename, int feeInPercent, int maxFeeInEuro);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -7,6 +7,7 @@ set(CMAKE_AUTOUIC ON)
|
||||||
|
|
||||||
# Find the QtWidgets library
|
# Find the QtWidgets library
|
||||||
find_package(Qt5Widgets CONFIG REQUIRED)
|
find_package(Qt5Widgets CONFIG REQUIRED)
|
||||||
|
find_package(Qt5PrintSupport CONFIG REQUIRED)
|
||||||
|
|
||||||
set(GUI_SOURCES
|
set(GUI_SOURCES
|
||||||
kima2.cpp
|
kima2.cpp
|
||||||
|
@ -28,4 +29,4 @@ set(GUI_SOURCES
|
||||||
|
|
||||||
add_executable(kima2 ${GUI_SOURCES})
|
add_executable(kima2 ${GUI_SOURCES})
|
||||||
target_include_directories(kima2 PRIVATE ${PROJECT_BINARY_DIR})
|
target_include_directories(kima2 PRIVATE ${PROJECT_BINARY_DIR})
|
||||||
target_link_libraries(kima2 core Qt5::Widgets stdc++fs)
|
target_link_libraries(kima2 core Qt5::Widgets Qt5::PrintSupport stdc++fs)
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QPainter>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QtPrintSupport/QPrintDialog>
|
||||||
|
#include <QtPrintSupport/QPrinter>
|
||||||
|
|
||||||
ReportDialog::ReportDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
|
ReportDialog::ReportDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
|
||||||
{
|
{
|
||||||
|
@ -13,7 +16,10 @@ ReportDialog::ReportDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent,
|
||||||
ui_.reportView->setModel(model_.get());
|
ui_.reportView->setModel(model_.get());
|
||||||
ui_.reportView->hideColumn(0);
|
ui_.reportView->hideColumn(0);
|
||||||
|
|
||||||
connect(ui_.exportCsvButton, &QPushButton::clicked, this, &ReportDialog::onExportCsvButtonClicked);
|
connect(ui_.exportCsvButton, &QPushButton::clicked, this,
|
||||||
|
&ReportDialog::onExportCsvButtonClicked);
|
||||||
|
connect(ui_.printReportButton, &QPushButton::clicked, this,
|
||||||
|
&ReportDialog::onPrintReportButtonClicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReportDialog::onExportCsvButtonClicked()
|
void ReportDialog::onExportCsvButtonClicked()
|
||||||
|
@ -27,6 +33,84 @@ void ReportDialog::onExportCsvButtonClicked()
|
||||||
fileDialog.setNameFilter("CSV Files (*.csv)");
|
fileDialog.setNameFilter("CSV Files (*.csv)");
|
||||||
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
|
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||||
if (fileDialog.exec()) {
|
if (fileDialog.exec()) {
|
||||||
market_->exportReportToCSV(fileDialog.selectedFiles().at(0).toStdString(), feeInPercent, maxFeeInEuro);
|
market_->exportReportToCSV(fileDialog.selectedFiles().at(0).toStdString(), feeInPercent,
|
||||||
|
maxFeeInEuro);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReportDialog::onPrintReportButtonClicked()
|
||||||
|
{
|
||||||
|
QPrinter printer;
|
||||||
|
|
||||||
|
QPrintDialog dialog(&printer, this);
|
||||||
|
dialog.setWindowTitle("Bericht drucken");
|
||||||
|
|
||||||
|
if (dialog.exec() != QDialog::Accepted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSettings settings;
|
||||||
|
int feeInPercent = settings.value("global/feeInPercent").toInt();
|
||||||
|
int maxFeeInEuro = settings.value("global/maxFeeInEuro").toInt();
|
||||||
|
|
||||||
|
QPainter painter;
|
||||||
|
int height = printer.height();
|
||||||
|
int width = printer.width();
|
||||||
|
const double ENTRIES_PER_PAGE = 50.0;
|
||||||
|
const auto& sellers = market_->getSellers();
|
||||||
|
unsigned int numPages = std::ceil(sellers.size() / ENTRIES_PER_PAGE);
|
||||||
|
|
||||||
|
painter.begin(&printer);
|
||||||
|
|
||||||
|
for (unsigned int i = 1; i <= numPages; ++i) {
|
||||||
|
if (i > 1)
|
||||||
|
printer.newPage();
|
||||||
|
painter.setFont(QFont("Arial", 16, QFont::Bold));
|
||||||
|
painter.drawText(QRect(0, 0, width, height), Qt::AlignTop | Qt::AlignHCenter,
|
||||||
|
"Auswertung Kindersachenmarkt");
|
||||||
|
painter.setFont(QFont("monospace", 12));
|
||||||
|
QString content;
|
||||||
|
content += QString("%1 %2 %3 %4 %5 %6 %7")
|
||||||
|
.arg("Nr.", -3)
|
||||||
|
.arg("Nachname", -14)
|
||||||
|
.arg("Vorname", -14)
|
||||||
|
.arg("geliefert", -9)
|
||||||
|
.arg("verkauft", -8)
|
||||||
|
.arg("Umsatz", -10)
|
||||||
|
.arg("Auszahlung\n", -11);
|
||||||
|
content.append(
|
||||||
|
"---------------------------------------------------------------------------\n");
|
||||||
|
for (unsigned int j = 0; j < ENTRIES_PER_PAGE && (i * j) < sellers.size(); ++j) {
|
||||||
|
content += QString("%1 %2 %3 %4 %5 %6 %7\n")
|
||||||
|
.arg(sellers.at(i * j)->getSellerNo(), 3)
|
||||||
|
.arg(sellers.at(i * j)->getLastName().c_str(), -14)
|
||||||
|
.arg(sellers.at(i * j)->getFirstName().c_str(), -14)
|
||||||
|
.arg(sellers.at(i * j)->numArticlesOffered(), 9)
|
||||||
|
.arg(sellers.at(i * j)->numArticlesSold(), 8)
|
||||||
|
.arg(sellers.at(i * j)->sumAsString().c_str(), 10)
|
||||||
|
.arg(paymentAsString(sellers.at(i * j)->sumInCents(), feeInPercent,
|
||||||
|
maxFeeInEuro * 100)
|
||||||
|
.c_str(),
|
||||||
|
11);
|
||||||
|
}
|
||||||
|
painter.drawText(QRect(0, 50, width, height), Qt::AlignLeft, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// now print the overall statistics
|
||||||
|
printer.newPage();
|
||||||
|
painter.setFont(QFont("Arial", 16, QFont::Bold));
|
||||||
|
painter.drawText(QRect(0, 0, width, height), Qt::AlignTop | Qt::AlignHCenter,
|
||||||
|
"Auswertung Kindersachenmarkt");
|
||||||
|
painter.setFont(QFont("monospace", 12));
|
||||||
|
QString content("Gesamtstatistik\n---------------\n\n");
|
||||||
|
content += QString("Registrierte Verkäufer: %1\n").arg(sellers.size(), 6);
|
||||||
|
content += QString("Verkaufte Artikel: %1\n\n").arg(6, 6);
|
||||||
|
content += QString("Gesamtumsatz: %1\n").arg(market_->getOverallSumAsString().c_str(), 10);
|
||||||
|
content += QString("Ausgezahlt: %1\n")
|
||||||
|
.arg(market_->getOverallPaymentAsString(feeInPercent, maxFeeInEuro * 100).c_str(), 10);
|
||||||
|
content += QString("Verbleibend: %1\n")
|
||||||
|
.arg(market_->getOverallRevenueAsString(feeInPercent, maxFeeInEuro * 100).c_str(), 10);
|
||||||
|
painter.drawText(QRect(0, 50, width, height), Qt::AlignLeft, content);
|
||||||
|
|
||||||
|
painter.end();
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ class ReportDialog : public QDialog
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onExportCsvButtonClicked();
|
void onExportCsvButtonClicked();
|
||||||
|
void onPrintReportButtonClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ReportDialog ui_;
|
Ui::ReportDialog ui_;
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_3">
|
<widget class="QPushButton" name="printReportButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Übersicht drucken</string>
|
<string>Übersicht drucken</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
Loading…
Reference in a new issue