From f45e295c75515b1bcd47b2197db5548d2cf61389 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Mon, 6 Aug 2018 21:24:10 +0200 Subject: [PATCH] printing of seller receipt works now --- src/gui/reportdialog.cpp | 43 ++++++++++++++++++++++++++++++++++---- src/gui/reportdialog.h | 6 ++++-- src/gui/reportdialog.ui | 2 +- src/printer/posprinter.cpp | 8 ++++--- src/printer/posprinter.h | 2 +- 5 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/gui/reportdialog.cpp b/src/gui/reportdialog.cpp index f1e61a0..7b5aa02 100644 --- a/src/gui/reportdialog.cpp +++ b/src/gui/reportdialog.cpp @@ -2,6 +2,8 @@ #include "mainwindow.h" +#include + #include #include #include @@ -20,6 +22,10 @@ ReportDialog::ReportDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, &ReportDialog::onExportCsvButtonClicked); connect(ui_.printReportButton, &QPushButton::clicked, this, &ReportDialog::onPrintReportButtonClicked); + connect(ui_.printSellerReceiptButton, &QPushButton::clicked, this, + &ReportDialog::onPrintSellerReceiptButtonClicked); + connect(ui_.reportView->selectionModel(), &QItemSelectionModel::selectionChanged, this, + &ReportDialog::onReportViewSelectionChanged); } void ReportDialog::onExportCsvButtonClicked() @@ -106,11 +112,40 @@ void ReportDialog::onPrintReportButtonClicked() 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); + 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(); } + +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); + } +} \ No newline at end of file diff --git a/src/gui/reportdialog.h b/src/gui/reportdialog.h index 9ed9d38..64edc5c 100644 --- a/src/gui/reportdialog.h +++ b/src/gui/reportdialog.h @@ -20,9 +20,11 @@ class ReportDialog : public QDialog private slots: void onExportCsvButtonClicked(); void onPrintReportButtonClicked(); + void onPrintSellerReceiptButtonClicked(); + void onReportViewSelectionChanged(const QItemSelection& selected, + const QItemSelection& deselected); - private: - Ui::ReportDialog ui_; + private : Ui::ReportDialog ui_; Marketplace* market_; std::unique_ptr model_; }; diff --git a/src/gui/reportdialog.ui b/src/gui/reportdialog.ui index fbe0165..d5d27b6 100644 --- a/src/gui/reportdialog.ui +++ b/src/gui/reportdialog.ui @@ -29,7 +29,7 @@ - + false diff --git a/src/printer/posprinter.cpp b/src/printer/posprinter.cpp index a9a2cfc..732a519 100644 --- a/src/printer/posprinter.cpp +++ b/src/printer/posprinter.cpp @@ -157,7 +157,7 @@ void PosPrinter::printSaleReceipt(Sale* sale) write(commandStream.str()); } -void PosPrinter::printSellerReceipt(Seller* seller, int percent, int maxFee) +void PosPrinter::printSellerReceipt(Seller* seller, int percent, int maxFeeInCent) { std::stringstream commandStream; printHeader(); @@ -182,10 +182,12 @@ void PosPrinter::printSellerReceipt(Seller* seller, int percent, int maxFee) } commandStream << "\nGesamt................." << seller->sumAsString() << "\n"; commandStream << "./. Gebühr............." - << marketFeeAsString(seller->sumInCents(), percent, maxFee * 100) << "\n"; + << marketFeeAsString(seller->sumInCents(), percent, maxFeeInCent) << "\n"; commandStream << "\nAuszahlung............." - << paymentAsString(seller->sumInCents(), percent, maxFee * 100) << "\n"; + << paymentAsString(seller->sumInCents(), percent, maxFeeInCent) << "\n"; commandStream << Command::FEED; + + write(commandStream.str()); } bool PosPrinter::isValid() diff --git a/src/printer/posprinter.h b/src/printer/posprinter.h index eda0332..140b6cc 100644 --- a/src/printer/posprinter.h +++ b/src/printer/posprinter.h @@ -25,7 +25,7 @@ class PosPrinter void printHeader(); void printTest(); void printSaleReceipt(Sale* sale); - void printSellerReceipt(Seller* seller, int percent, int maxFee); + void printSellerReceipt(Seller* seller, int percent, int maxFeeInCent); bool isValid(); struct Command {