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

@ -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>");
});
}

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,8 +86,11 @@ 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)
{
@ -148,7 +147,8 @@ void PosPrinter::printSaleReceipt(Sale* sale)
commandStream << sale->getTimestamp() << "\n\n";
commandStream << Command::LEFT_ALIGN;
for (const auto& article : sale->getArticles()) {
commandStream << "Art. " << article->getCompleteArticleNo() << "........... " << article->getPriceAsString() << "\n";
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;