printing sale receipt
This commit is contained in:
parent
23659078b4
commit
6e6510ebcf
8 changed files with 53 additions and 10 deletions
|
@ -9,5 +9,5 @@ set(PRINTER_SOURCES
|
|||
)
|
||||
|
||||
add_library(printer STATIC ${PRINTER_SOURCES})
|
||||
target_link_libraries(printer ${LIBUSB_1_LIBRARIES})
|
||||
target_link_libraries(printer core ${LIBUSB_1_LIBRARIES})
|
||||
target_include_directories(printer PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
|
@ -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());
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef POS_PRINTER_H
|
||||
#define POS_PRINTER_H
|
||||
|
||||
#include <sale.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
@ -21,14 +23,16 @@ class PosPrinter
|
|||
void write(const std::string& text);
|
||||
void printHeader();
|
||||
void printTest();
|
||||
void printReceipt(Sale* sale);
|
||||
|
||||
struct Command {
|
||||
static const std::string RESET;
|
||||
static const std::string ENCODING;
|
||||
static const std::string CENTERING;
|
||||
static const std::string LEFT_ALIGN;
|
||||
static const std::string RIGHT_ALIGN;
|
||||
static const std::string FONT_SIZE_BIG;
|
||||
static const std::string FONT_SIZE_NORMAL;
|
||||
static const std::string LEFT_ALIGN;
|
||||
static const std::string FEED;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue