printing of seller receipt works now

This commit is contained in:
Martin Brodbeck 2018-08-06 21:24:10 +02:00
parent 4a92832e19
commit f45e295c75
5 changed files with 50 additions and 11 deletions

View file

@ -2,6 +2,8 @@
#include "mainwindow.h"
#include <posprinter.h>
#include <QFileDialog>
#include <QPainter>
#include <QSettings>
@ -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")
content +=
QString("Ausgezahlt: %1\n")
.arg(market_->getOverallPaymentAsString(feeInPercent, maxFeeInEuro * 100).c_str(), 10);
content += QString("Verbleibend: %1\n")
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);
}
}

View file

@ -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<ReportModel> model_;
};

View file

@ -29,7 +29,7 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="printSellerReceiptButton">
<property name="enabled">
<bool>false</bool>
</property>

View file

@ -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()

View file

@ -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 {