printer bugfixes

This commit is contained in:
Martin Brodbeck 2018-08-06 20:57:12 +02:00
parent 88d7225e61
commit 4a92832e19
4 changed files with 52 additions and 31 deletions

View file

@ -238,6 +238,7 @@ void MainWindow::onPrintSaleReceiptButtonClicked([[maybe_unused]] bool checked)
auto indexes = selModel->selectedRows();
auto& sale = marketplace_->getSales().at(indexes[0].row());
PosPrinter printer;
if (printer.isValid())
printer.printSaleReceipt(sale.get());
}

View file

@ -14,12 +14,12 @@ SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(par
QSettings settings{};
int cashPointNo = settings.value("global/cashPointNo").toInt();
//QString posPrinterDevice = settings.value("global/posPrinterDevice").toString();
// QString posPrinterDevice = settings.value("global/posPrinterDevice").toString();
int feeInPercent = settings.value("global/feeInPercent").toInt();
int maxFeeInEuro = settings.value("global/maxFeeInEuro").toInt();
ui_.cashPointNoSpinBox->setValue(cashPointNo);
//ui_.posPrinterDeviceEdit->setText(posPrinterDevice);
// ui_.posPrinterDeviceEdit->setText(posPrinterDevice);
ui_.feePercentSpinBox->setValue(feeInPercent);
ui_.maxFeeSpinBox->setValue(maxFeeInEuro);
@ -28,14 +28,19 @@ SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(par
try {
PosPrinter printer;
printer.printTest();
if (printer.isValid())
this->ui_.posPrinterDeviceEdit->setText("<gefunden>");
else
this->ui_.posPrinterDeviceEdit->setText("<nicht gefunden>");
} catch (std::runtime_error& err) {
QMessageBox(QMessageBox::Icon::Warning, "Bondrucker Fehler",
QString("Test schlug fehl: ") + err.what(), QMessageBox::StandardButton::Ok, this)
QString("Test schlug fehl: ") + err.what(), QMessageBox::StandardButton::Ok,
this)
.exec();
this->ui_.posPrinterDeviceEdit->setText("<nicht gefunden>");
this->ui_.posPrinterDeviceEdit->setText("<Fehler>");
return;
}
this->ui_.posPrinterDeviceEdit->setText("<gefunden>");
});
}
@ -46,7 +51,7 @@ void SettingsDialog::accept()
int oldCashPointNo = settings.value("global/cashPointNo").toInt();
int newCashPointNo = ui_.cashPointNoSpinBox->value();
//settings.setValue("global/posPrinterDevice", ui_.posPrinterDeviceEdit->text());
// settings.setValue("global/posPrinterDevice", ui_.posPrinterDeviceEdit->text());
settings.setValue("global/feeInPercent", ui_.feePercentSpinBox->value());
settings.setValue("global/maxFeeInEuro", ui_.maxFeeSpinBox->value());

View file

@ -2,7 +2,7 @@
#include <marketplace.h>
#include "boost/date_time/posix_time/posix_time.hpp"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <algorithm>
#include <boost/algorithm/string.hpp>
@ -29,10 +29,6 @@ PosPrinter::PosPrinter()
throw std::runtime_error("Init error");
}
#if defined(_WIN32)
// libusb_set_option(contextPtr_, LIBUSB_OPTION_USE_USBDK);
#endif
libusb_device** devList;
int devCount = libusb_get_device_list(contextPtr_, &devList);
if (devCount <= 0) {
@ -52,7 +48,6 @@ PosPrinter::PosPrinter()
}
if (numDevice < 0) {
libusb_exit(contextPtr_);
return;
}
@ -81,6 +76,7 @@ PosPrinter::PosPrinter()
PosPrinter::~PosPrinter()
{
if (devicePtr_) {
int retValue;
retValue = libusb_release_interface(devicePtr_, 0); // release the claimed interface
if (retValue != 0) {
@ -90,7 +86,10 @@ PosPrinter::~PosPrinter()
}
libusb_close(devicePtr_); // close the device we opened
}
if (contextPtr_) {
libusb_exit(contextPtr_); // close the session
}
}
void PosPrinter::write(const std::string& text)
@ -147,8 +146,9 @@ void PosPrinter::printSaleReceipt(Sale* sale)
commandStream << Command::RESET << Command::ENCODING << Command::RIGHT_ALIGN;
commandStream << sale->getTimestamp() << "\n\n";
commandStream << Command::LEFT_ALIGN;
for(const auto& article : sale->getArticles()) {
commandStream << "Art. " << article->getCompleteArticleNo() << "........... " << article->getPriceAsString() << "\n";
for (const auto& article : sale->getArticles()) {
commandStream << "Art. " << article->getCompleteArticleNo() << "........... "
<< article->getPriceAsString() << "\n";
}
commandStream << "\nGesamt................. " << sale->sumAsString() << "\n";
commandStream << Command::CENTERING;
@ -162,22 +162,36 @@ void PosPrinter::printSellerReceipt(Seller* seller, int percent, int maxFee)
std::stringstream commandStream;
printHeader();
commandStream << Command::RESET << Command::ENCODING << Command::RIGHT_ALIGN;
std::string timeStr = boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time());
std::string timeStr =
boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time());
commandStream << timeStr << "\n\n";
commandStream << Command::LEFT_ALIGN;
commandStream << "Verkäufernummer: " << std::setw(4) << seller->getSellerNo() << "\n\n";
commandStream << "Anzahl Artikel geliefert: " << std::setw(4) << seller->numArticlesOffered() << "\n";
commandStream << "Anzahl Artikel verkauft: " << std::setw(4) << seller->numArticlesSold() << "\n\n";
commandStream << "Anzahl Artikel geliefert: " << std::setw(4) << seller->numArticlesOffered()
<< "\n";
commandStream << "Anzahl Artikel verkauft: " << std::setw(4) << seller->numArticlesSold()
<< "\n\n";
if (seller->getArticles(true).size() == 0) {
commandStream << "Verkaufte Artikel:\n *** keine ***\n";
} else {
commandStream << "Verkaufte Artikel:\n";
}
for (auto& article : seller->getArticles(true)) {
commandStream << "Art. " << article->getCompleteArticleNo() << "........... " << article->getPriceAsString() << "\n";
commandStream << "Art. " << article->getCompleteArticleNo() << "........... "
<< article->getPriceAsString() << "\n";
}
commandStream << "\nGesamt................." << seller->sumAsString() << "\n";
commandStream << "./. Gebühr............." << marketFeeAsString(seller->sumInCents(), percent, maxFee * 100) << "\n";
commandStream << "\nAuszahlung............." << paymentAsString(seller->sumInCents(), percent, maxFee * 100) << "\n";
commandStream << "./. Gebühr............."
<< marketFeeAsString(seller->sumInCents(), percent, maxFee * 100) << "\n";
commandStream << "\nAuszahlung............."
<< paymentAsString(seller->sumInCents(), percent, maxFee * 100) << "\n";
commandStream << Command::FEED;
}
bool PosPrinter::isValid()
{
if (devicePtr_)
return true;
else
return false;
}

View file

@ -26,6 +26,7 @@ class PosPrinter
void printTest();
void printSaleReceipt(Sale* sale);
void printSellerReceipt(Seller* seller, int percent, int maxFee);
bool isValid();
struct Command {
static const std::string RESET;