printing sale receipt

This commit is contained in:
Martin Brodbeck 2018-08-06 16:14:45 +02:00
parent 23659078b4
commit 6e6510ebcf
8 changed files with 53 additions and 10 deletions

View file

@ -1,18 +1,19 @@
#include "posprinter.h"
#include <algorithm>
#include <boost/algorithm/string.hpp>
#include <exception>
#include <iostream>
#include <sstream>
#include <string>
#include <boost/algorithm/string.hpp>
const std::string PosPrinter::Command::RESET = {0x1b, 0x40};
const std::string PosPrinter::Command::ENCODING = {'\x1b', '\x74', 16};
const std::string PosPrinter::Command::CENTERING = {'\x1b', '\x61', '\x01'};
const std::string PosPrinter::Command::LEFT_ALIGN = {0x1b, 0x61, 0x00};
const std::string PosPrinter::Command::RIGHT_ALIGN = {0x1b, 0x61, 0x02};
const std::string PosPrinter::Command::FONT_SIZE_BIG = {'\x1b', '\x21', '\x10'};
const std::string PosPrinter::Command::FONT_SIZE_NORMAL = {'\x1b', '\x21', '\x00'};
const std::string PosPrinter::Command::LEFT_ALIGN = {'\x1b', '\x61', '\x00'};
const std::string PosPrinter::Command::FEED = {0x1b, 0x64, 0x03};
PosPrinter::PosPrinter()
@ -25,7 +26,7 @@ PosPrinter::PosPrinter()
}
#if defined(_WIN32)
libusb_set_option(contextPtr_, LIBUSB_OPTION_USE_USBDK);
// libusb_set_option(contextPtr_, LIBUSB_OPTION_USE_USBDK);
#endif
libusb_device** devList;
@ -126,7 +127,6 @@ void PosPrinter::printHeader()
void PosPrinter::printTest()
{
using namespace std::string_literals;
std::stringstream commandStream;
commandStream << Command::ENCODING;
commandStream << "Der Drucker kann von KIMA2\nangesprochen werden.\n\n"
@ -134,4 +134,21 @@ void PosPrinter::printTest()
commandStream << Command::FEED;
printHeader();
write(commandStream.str());
}
void PosPrinter::printReceipt(Sale* sale)
{
std::stringstream commandStream;
printHeader();
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";
}
commandStream << "\nGesamt................. " << sale->sumAsString() << "\n";
commandStream << Command::CENTERING;
commandStream << "\n\nVielen Dank für Ihren Einkauf!";
commandStream << Command::LEFT_ALIGN << Command::FEED;
write(commandStream.str());
}