2018-08-02 13:06:37 +02:00
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
#include <iomanip>
|
|
|
|
#include <numeric>
|
|
|
|
|
|
|
|
std::string formatCentAsEuroString(const int cent, int width)
|
|
|
|
{
|
|
|
|
std::stringstream currStream;
|
|
|
|
|
|
|
|
try {
|
|
|
|
std::locale myLocale("de_DE.utf8");
|
|
|
|
currStream.imbue(myLocale);
|
|
|
|
currStream << std::right << std::setw(width) << std::showbase
|
|
|
|
<< std::put_money(cent, false);
|
|
|
|
} catch (std::runtime_error& err) {
|
2018-08-08 15:55:35 +02:00
|
|
|
currStream << std::fixed << std::setw(width >= 4 ? width - 4 : width)
|
|
|
|
<< std::setprecision(2) << cent / 100.0L << " €";
|
2018-08-02 13:06:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return currStream.str();
|
2018-08-08 09:25:37 +02:00
|
|
|
}
|
2018-08-08 15:55:35 +02:00
|
|
|
|
2018-08-15 10:51:57 +02:00
|
|
|
std::optional<PrinterDevice> convertToPosPrinterDevice(const std::string& device,
|
|
|
|
const std::string& endpoint)
|
|
|
|
{
|
|
|
|
if (device.empty()) {
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrinterDevice printerDevice;
|
|
|
|
std::string delimiter = ":";
|
|
|
|
try {
|
|
|
|
printerDevice.idVendor = std::stoi(device.substr(0, device.find(delimiter)), 0, 16);
|
|
|
|
printerDevice.idProduct = std::stoi(device.substr(device.find(delimiter) + 1), 0, 16);
|
|
|
|
if (endpoint.empty()) {
|
|
|
|
printerDevice.endpoint = 0x03;
|
|
|
|
} else {
|
|
|
|
printerDevice.endpoint = std::stoi(endpoint, 0, 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (std::exception& ex) {
|
|
|
|
throw ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
return printerDevice;
|
|
|
|
}
|