2018-07-30 09:50:54 +02:00
|
|
|
#include "reportdialog.h"
|
|
|
|
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
2018-08-06 21:24:10 +02:00
|
|
|
#include <posprinter.h>
|
|
|
|
|
2018-07-31 10:28:07 +02:00
|
|
|
#include <QFileDialog>
|
2018-08-08 09:16:23 +02:00
|
|
|
#include <QFontDatabase>
|
2018-07-31 16:15:48 +02:00
|
|
|
#include <QPainter>
|
2018-07-31 10:28:07 +02:00
|
|
|
#include <QSettings>
|
2018-07-31 16:15:48 +02:00
|
|
|
#include <QtPrintSupport/QPrintDialog>
|
|
|
|
#include <QtPrintSupport/QPrinter>
|
2018-07-31 10:28:07 +02:00
|
|
|
|
2018-07-30 09:50:54 +02:00
|
|
|
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);
|
2018-07-31 10:28:07 +02:00
|
|
|
|
2018-07-31 16:15:48 +02:00
|
|
|
connect(ui_.exportCsvButton, &QPushButton::clicked, this,
|
|
|
|
&ReportDialog::onExportCsvButtonClicked);
|
|
|
|
connect(ui_.printReportButton, &QPushButton::clicked, this,
|
|
|
|
&ReportDialog::onPrintReportButtonClicked);
|
2018-08-06 21:24:10 +02:00
|
|
|
connect(ui_.printSellerReceiptButton, &QPushButton::clicked, this,
|
|
|
|
&ReportDialog::onPrintSellerReceiptButtonClicked);
|
|
|
|
connect(ui_.reportView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
|
|
|
&ReportDialog::onReportViewSelectionChanged);
|
2018-07-31 10:28:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReportDialog::onExportCsvButtonClicked()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
int feeInPercent = settings.value("global/feeInPercent").toInt();
|
|
|
|
int maxFeeInEuro = settings.value("global/maxFeeInEuro").toInt();
|
|
|
|
|
|
|
|
QFileDialog fileDialog(this);
|
|
|
|
fileDialog.setFileMode(QFileDialog::AnyFile);
|
|
|
|
fileDialog.setNameFilter("CSV Files (*.csv)");
|
|
|
|
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
|
|
|
|
if (fileDialog.exec()) {
|
2018-07-31 16:15:48 +02:00
|
|
|
market_->exportReportToCSV(fileDialog.selectedFiles().at(0).toStdString(), feeInPercent,
|
|
|
|
maxFeeInEuro);
|
2018-07-31 10:28:07 +02:00
|
|
|
}
|
2018-07-31 16:15:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2018-08-08 09:30:48 +02:00
|
|
|
QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
|
|
|
|
fixedFont.setPointSize(12);
|
2018-07-31 16:15:48 +02:00
|
|
|
|
|
|
|
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");
|
2018-08-08 09:30:48 +02:00
|
|
|
painter.setFont(fixedFont);
|
2018-07-31 16:15:48 +02:00
|
|
|
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)
|
2018-08-07 09:30:06 +02:00
|
|
|
.arg(sellers.at(i * j)->getLastName().substr(0, 14).c_str(), -14)
|
|
|
|
.arg(sellers.at(i * j)->getFirstName().substr(0, 14).c_str(), -14)
|
2018-07-31 16:15:48 +02:00
|
|
|
.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);
|
|
|
|
}
|
|
|
|
|
2018-08-07 08:53:31 +02:00
|
|
|
// pieces booked on the special account "Sonderkonto"
|
|
|
|
const auto specialSeller = market_->findSellerWithUuid("11111111-1111-1111-1111-111111111111");
|
|
|
|
if (specialSeller && specialSeller->numArticlesSold() > 0) {
|
|
|
|
printer.newPage();
|
|
|
|
painter.setFont(QFont("Arial", 16, QFont::Bold));
|
|
|
|
painter.drawText(QRect(0, 0, width, height), Qt::AlignTop | Qt::AlignHCenter,
|
|
|
|
"Auswertung Kindersachenmarkt");
|
2018-08-08 09:30:48 +02:00
|
|
|
painter.setFont(fixedFont);
|
2018-08-07 08:53:31 +02:00
|
|
|
QString content("Einzelteile ohne Nummer\n=======================\n\n");
|
2018-08-07 09:27:15 +02:00
|
|
|
unsigned int lines{0};
|
|
|
|
unsigned int pages{1};
|
2018-08-07 08:53:31 +02:00
|
|
|
for (const auto& article : specialSeller->getArticles(true)) {
|
2018-08-07 09:27:15 +02:00
|
|
|
content += QString("- %1:").arg(article->getDescription().substr(0, 45).c_str(), -45);
|
2018-08-07 08:53:31 +02:00
|
|
|
content += QString("%1\n").arg(article->getPriceAsString().c_str(), 11);
|
2018-08-07 09:27:15 +02:00
|
|
|
++lines;
|
|
|
|
if (lines % static_cast<int>(ENTRIES_PER_PAGE) == 0 &&
|
|
|
|
(pages * lines) < specialSeller->getArticles(true).size()) {
|
|
|
|
painter.drawText(QRect(0, 50, width, height), Qt::AlignLeft, content);
|
|
|
|
lines = 0;
|
|
|
|
++pages;
|
|
|
|
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));
|
|
|
|
content = "Einzelteile ohne Nummer\n=======================\n\n";
|
|
|
|
}
|
2018-08-07 08:53:31 +02:00
|
|
|
}
|
|
|
|
painter.drawText(QRect(0, 50, width, height), Qt::AlignLeft, content);
|
|
|
|
}
|
|
|
|
|
|
|
|
// overall statistics
|
2018-07-31 16:15:48 +02:00
|
|
|
printer.newPage();
|
|
|
|
painter.setFont(QFont("Arial", 16, QFont::Bold));
|
|
|
|
painter.drawText(QRect(0, 0, width, height), Qt::AlignTop | Qt::AlignHCenter,
|
|
|
|
"Auswertung Kindersachenmarkt");
|
2018-08-08 09:30:48 +02:00
|
|
|
painter.setFont(fixedFont);
|
2018-08-07 08:53:31 +02:00
|
|
|
QString content("Gesamtstatistik\n===============\n\n");
|
2018-07-31 16:15:48 +02:00
|
|
|
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);
|
2018-08-06 21:24:10 +02:00
|
|
|
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);
|
2018-07-31 16:15:48 +02:00
|
|
|
painter.drawText(QRect(0, 50, width, height), Qt::AlignLeft, content);
|
|
|
|
|
|
|
|
painter.end();
|
|
|
|
}
|
2018-08-06 21:24:10 +02:00
|
|
|
|
|
|
|
void ReportDialog::onPrintSellerReceiptButtonClicked()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
int feeInPercent = settings.value("global/feeInPercent").toInt();
|
|
|
|
int maxFeeInEuro = settings.value("global/maxFeeInEuro").toInt();
|
|
|
|
|
|
|
|
auto selModel = ui_.reportView->selectionModel();
|
|
|
|
if (selModel->hasSelection() == false)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto indexes = selModel->selectedRows();
|
|
|
|
auto& seller = market_->getSellers().at(indexes[0].row());
|
|
|
|
PosPrinter printer;
|
|
|
|
if (printer.isValid())
|
|
|
|
printer.printSellerReceipt(seller.get(), feeInPercent, maxFeeInEuro * 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReportDialog::onReportViewSelectionChanged(const QItemSelection& selected,
|
|
|
|
[[maybe_unused]] const QItemSelection& deselected)
|
|
|
|
{
|
|
|
|
if (selected.size() > 0) {
|
|
|
|
ui_.printSellerReceiptButton->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
ui_.printSellerReceiptButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|