printer bugfixes
This commit is contained in:
parent
88d7225e61
commit
4a92832e19
4 changed files with 52 additions and 31 deletions
|
@ -238,6 +238,7 @@ void MainWindow::onPrintSaleReceiptButtonClicked([[maybe_unused]] bool checked)
|
||||||
auto indexes = selModel->selectedRows();
|
auto indexes = selModel->selectedRows();
|
||||||
auto& sale = marketplace_->getSales().at(indexes[0].row());
|
auto& sale = marketplace_->getSales().at(indexes[0].row());
|
||||||
PosPrinter printer;
|
PosPrinter printer;
|
||||||
|
if (printer.isValid())
|
||||||
printer.printSaleReceipt(sale.get());
|
printer.printSaleReceipt(sale.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,12 @@ SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(par
|
||||||
|
|
||||||
QSettings settings{};
|
QSettings settings{};
|
||||||
int cashPointNo = settings.value("global/cashPointNo").toInt();
|
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 feeInPercent = settings.value("global/feeInPercent").toInt();
|
||||||
int maxFeeInEuro = settings.value("global/maxFeeInEuro").toInt();
|
int maxFeeInEuro = settings.value("global/maxFeeInEuro").toInt();
|
||||||
|
|
||||||
ui_.cashPointNoSpinBox->setValue(cashPointNo);
|
ui_.cashPointNoSpinBox->setValue(cashPointNo);
|
||||||
//ui_.posPrinterDeviceEdit->setText(posPrinterDevice);
|
// ui_.posPrinterDeviceEdit->setText(posPrinterDevice);
|
||||||
ui_.feePercentSpinBox->setValue(feeInPercent);
|
ui_.feePercentSpinBox->setValue(feeInPercent);
|
||||||
ui_.maxFeeSpinBox->setValue(maxFeeInEuro);
|
ui_.maxFeeSpinBox->setValue(maxFeeInEuro);
|
||||||
|
|
||||||
|
@ -28,14 +28,19 @@ SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(par
|
||||||
try {
|
try {
|
||||||
PosPrinter printer;
|
PosPrinter printer;
|
||||||
printer.printTest();
|
printer.printTest();
|
||||||
|
if (printer.isValid())
|
||||||
|
this->ui_.posPrinterDeviceEdit->setText("<gefunden>");
|
||||||
|
else
|
||||||
|
this->ui_.posPrinterDeviceEdit->setText("<nicht gefunden>");
|
||||||
|
|
||||||
} catch (std::runtime_error& err) {
|
} catch (std::runtime_error& err) {
|
||||||
QMessageBox(QMessageBox::Icon::Warning, "Bondrucker Fehler",
|
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();
|
.exec();
|
||||||
this->ui_.posPrinterDeviceEdit->setText("<nicht gefunden>");
|
this->ui_.posPrinterDeviceEdit->setText("<Fehler>");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this->ui_.posPrinterDeviceEdit->setText("<gefunden>");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +51,7 @@ void SettingsDialog::accept()
|
||||||
int oldCashPointNo = settings.value("global/cashPointNo").toInt();
|
int oldCashPointNo = settings.value("global/cashPointNo").toInt();
|
||||||
int newCashPointNo = ui_.cashPointNoSpinBox->value();
|
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/feeInPercent", ui_.feePercentSpinBox->value());
|
||||||
settings.setValue("global/maxFeeInEuro", ui_.maxFeeSpinBox->value());
|
settings.setValue("global/maxFeeInEuro", ui_.maxFeeSpinBox->value());
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include <marketplace.h>
|
#include <marketplace.h>
|
||||||
|
|
||||||
#include "boost/date_time/posix_time/posix_time.hpp"
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
@ -29,10 +29,6 @@ PosPrinter::PosPrinter()
|
||||||
throw std::runtime_error("Init error");
|
throw std::runtime_error("Init error");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
// libusb_set_option(contextPtr_, LIBUSB_OPTION_USE_USBDK);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
libusb_device** devList;
|
libusb_device** devList;
|
||||||
int devCount = libusb_get_device_list(contextPtr_, &devList);
|
int devCount = libusb_get_device_list(contextPtr_, &devList);
|
||||||
if (devCount <= 0) {
|
if (devCount <= 0) {
|
||||||
|
@ -52,7 +48,6 @@ PosPrinter::PosPrinter()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numDevice < 0) {
|
if (numDevice < 0) {
|
||||||
libusb_exit(contextPtr_);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +76,7 @@ PosPrinter::PosPrinter()
|
||||||
|
|
||||||
PosPrinter::~PosPrinter()
|
PosPrinter::~PosPrinter()
|
||||||
{
|
{
|
||||||
|
if (devicePtr_) {
|
||||||
int retValue;
|
int retValue;
|
||||||
retValue = libusb_release_interface(devicePtr_, 0); // release the claimed interface
|
retValue = libusb_release_interface(devicePtr_, 0); // release the claimed interface
|
||||||
if (retValue != 0) {
|
if (retValue != 0) {
|
||||||
|
@ -90,7 +86,10 @@ PosPrinter::~PosPrinter()
|
||||||
}
|
}
|
||||||
|
|
||||||
libusb_close(devicePtr_); // close the device we opened
|
libusb_close(devicePtr_); // close the device we opened
|
||||||
|
}
|
||||||
|
if (contextPtr_) {
|
||||||
libusb_exit(contextPtr_); // close the session
|
libusb_exit(contextPtr_); // close the session
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PosPrinter::write(const std::string& text)
|
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 << Command::RESET << Command::ENCODING << Command::RIGHT_ALIGN;
|
||||||
commandStream << sale->getTimestamp() << "\n\n";
|
commandStream << sale->getTimestamp() << "\n\n";
|
||||||
commandStream << Command::LEFT_ALIGN;
|
commandStream << Command::LEFT_ALIGN;
|
||||||
for(const auto& article : sale->getArticles()) {
|
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 << "\nGesamt................. " << sale->sumAsString() << "\n";
|
||||||
commandStream << Command::CENTERING;
|
commandStream << Command::CENTERING;
|
||||||
|
@ -162,22 +162,36 @@ void PosPrinter::printSellerReceipt(Seller* seller, int percent, int maxFee)
|
||||||
std::stringstream commandStream;
|
std::stringstream commandStream;
|
||||||
printHeader();
|
printHeader();
|
||||||
commandStream << Command::RESET << Command::ENCODING << Command::RIGHT_ALIGN;
|
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 << timeStr << "\n\n";
|
||||||
commandStream << Command::LEFT_ALIGN;
|
commandStream << Command::LEFT_ALIGN;
|
||||||
commandStream << "Verkäufernummer: " << std::setw(4) << seller->getSellerNo() << "\n\n";
|
commandStream << "Verkäufernummer: " << std::setw(4) << seller->getSellerNo() << "\n\n";
|
||||||
commandStream << "Anzahl Artikel geliefert: " << std::setw(4) << seller->numArticlesOffered() << "\n";
|
commandStream << "Anzahl Artikel geliefert: " << std::setw(4) << seller->numArticlesOffered()
|
||||||
commandStream << "Anzahl Artikel verkauft: " << std::setw(4) << seller->numArticlesSold() << "\n\n";
|
<< "\n";
|
||||||
|
commandStream << "Anzahl Artikel verkauft: " << std::setw(4) << seller->numArticlesSold()
|
||||||
|
<< "\n\n";
|
||||||
if (seller->getArticles(true).size() == 0) {
|
if (seller->getArticles(true).size() == 0) {
|
||||||
commandStream << "Verkaufte Artikel:\n *** keine ***\n";
|
commandStream << "Verkaufte Artikel:\n *** keine ***\n";
|
||||||
} else {
|
} else {
|
||||||
commandStream << "Verkaufte Artikel:\n";
|
commandStream << "Verkaufte Artikel:\n";
|
||||||
}
|
}
|
||||||
for (auto& article : seller->getArticles(true)) {
|
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 << "\nGesamt................." << seller->sumAsString() << "\n";
|
||||||
commandStream << "./. Gebühr............." << marketFeeAsString(seller->sumInCents(), percent, maxFee * 100) << "\n";
|
commandStream << "./. Gebühr............."
|
||||||
commandStream << "\nAuszahlung............." << paymentAsString(seller->sumInCents(), percent, maxFee * 100) << "\n";
|
<< marketFeeAsString(seller->sumInCents(), percent, maxFee * 100) << "\n";
|
||||||
|
commandStream << "\nAuszahlung............."
|
||||||
|
<< paymentAsString(seller->sumInCents(), percent, maxFee * 100) << "\n";
|
||||||
commandStream << Command::FEED;
|
commandStream << Command::FEED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PosPrinter::isValid()
|
||||||
|
{
|
||||||
|
if (devicePtr_)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ class PosPrinter
|
||||||
void printTest();
|
void printTest();
|
||||||
void printSaleReceipt(Sale* sale);
|
void printSaleReceipt(Sale* sale);
|
||||||
void printSellerReceipt(Seller* seller, int percent, int maxFee);
|
void printSellerReceipt(Seller* seller, int percent, int maxFee);
|
||||||
|
bool isValid();
|
||||||
|
|
||||||
struct Command {
|
struct Command {
|
||||||
static const std::string RESET;
|
static const std::string RESET;
|
||||||
|
|
Loading…
Reference in a new issue