Printing: dynamically set template dyn-data using Ticket-class

See DC_printer_interface.graphml/pdf
This commit is contained in:
Siegfried Siegert 2024-03-11 14:06:05 +01:00
parent b7cedf5444
commit f94f33862f
Signed by: SiegfriedSiegert
GPG Key ID: 68371E015E8F0B03
2 changed files with 134 additions and 101 deletions

View File

@ -70,7 +70,7 @@ ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent)
// currentSelectedTicketType - number of used "Kombiticket" (deprecated) use TICKET_VARIANT in future // currentSelectedTicketType - number of used "Kombiticket" (deprecated) use TICKET_VARIANT in future
this->currentSelectedTicketType = 0; this->currentSelectedTicketType = 0;
this->currentTicketVariant = TICKET_VARIANT::PARKING_TICKET; this->currentTicket = new Ticket(TICKET_VARIANT::PARKING_TICKET, this);
this->currentCashState = CASH_STATE::CACHE_EMPTY; this->currentCashState = CASH_STATE::CACHE_EMPTY;
@ -558,48 +558,40 @@ void ATBDeviceControllerPlugin::onNewVoltage(uint32_t voltage)
/**
* @brief ATBDeviceControllerPlugin::requestPrintTicket
* @param ticketVariant
* @param printingData
*
* Setup (initNew()) Ticket-Object
*
*/
void ATBDeviceControllerPlugin::requestPrintTicket(nsDeviceControllerInterface::TICKET_VARIANT ticketVariant, const QHash<QString, QVariant> & printingData) void ATBDeviceControllerPlugin::requestPrintTicket(nsDeviceControllerInterface::TICKET_VARIANT ticketVariant, const QHash<QString, QVariant> & printingData)
{ {
struct T_dynDat *dynTicketData = new T_dynDat; QList<quint8> templateList;
memset(dynTicketData, 0, sizeof(*dynTicketData));
this->templateList.clear(); // TODO: read template list from .ini
this->currentTicketVariant = ticketVariant;
switch (ticketVariant) {
case nsDeviceControllerInterface::TICKET_VARIANT::START_RECEIPT:
qCritical() << " -> TICKET_VARIANT::START_RECEIPT";
this->private_setupDynTicketData_START_RECEIPT(dynTicketData, printingData);
this->templateList << 21 << 22 << 23;
break;
case nsDeviceControllerInterface::TICKET_VARIANT::STOP_RECEIPT:
qCritical() << " -> TICKET_VARIANT::STOP_RECEIPT";
this->private_setupDynTicketData_STOP_RECEIPT(dynTicketData, printingData);
this->templateList << 24 << 25 << 26;
break;
case nsDeviceControllerInterface::TICKET_VARIANT::RECEIPT:
break;
case nsDeviceControllerInterface::TICKET_VARIANT::ERROR_RECEIPT:
break;
case nsDeviceControllerInterface::TICKET_VARIANT::PARKING_TICKET:
break;
case nsDeviceControllerInterface::TICKET_VARIANT::FOOD_STAMP:
qCritical() << " -> TICKET_VARIANT::FOOD_STAMP";
this->private_setupDynTicketData_FOOD_STAMP(dynTicketData, printingData);
this->private_setupTemplateList_FOOD_STAMP(printingData);
break;
}
// DEBUG // DEBUG
qCritical() << "------------------------------------------------------------------------";
qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket()"; qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket()";
qCritical() << " TICKET_VARIANT: " << ticketVariant;
qCritical() << " dyn1_list: " << printingData["dyn1_list"].toStringList();
qCritical() << " dyn2_list: " << printingData["dyn2_list"].toStringList();
qCritical() << "------------------------------------------------------------------------";
for (int i =0; i < this->templateList.size(); ++i) {
qCritical() << " template: " << this->templateList.at(i); if (!this->currentTicket->initNew(ticketVariant, templateList, printingData)) {
this->errorCode = this->currentTicket->getErrorCode();
this->errorDescription = this->currentTicket->getErrorCode();
qCritical() << "ERROR: ticket->initNew: " << ticketVariant;
this->onPrintFinishedERR();
return;
} }
/* /*
if (!this->hw->dc_isPortOpen()) { if (!this->hw->dc_isPortOpen()) {
qCritical() << " ... serial port is not open!"; qCritical() << " ... serial port is not open!";
@ -608,26 +600,7 @@ void ATBDeviceControllerPlugin::requestPrintTicket(nsDeviceControllerInterface::
} }
*/ */
// TODO: wird hier nur 'licensePlate' gedruckt? this->prepareDynTemplateData();
if (!this->hw->prn_sendDynamicPrnValues(dynTicketData->licensePlate)) {
this->errorCode = "hwapi::prn_sendDynamicPrnValues";
this->errorDescription = "hwapi method 'hwapi::prn_sendDynamicPrnValues' result is false";
qCritical() << "ERROR:";
qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket( " << endl
<< " licenseplate = " << printingData["licenseplate"] << endl
<< " amount = " << printingData["amount"] << endl
<< " parkingEnd = " << printingData["parkingEnd"] << endl
<< " currentTime = " << printingData["currentTime"] << endl
<< " currentDate = " << printingData["currentDate"] << endl
<< " stan = " << printingData["STAN"] << endl;
this->onPrintFinishedERR();
return;
}
QTimer::singleShot(1000, this, SLOT(onPrinterDataPreparedForTemplates()));
} }
void ATBDeviceControllerPlugin::requestPrintReceipt(const QHash<QString, QVariant> & printingData) void ATBDeviceControllerPlugin::requestPrintReceipt(const QHash<QString, QVariant> & printingData)
@ -821,7 +794,7 @@ void ATBDeviceControllerPlugin::requestPrintTicket(const QHash<QString, QVariant
void ATBDeviceControllerPlugin::onPrinterDataPreparedForTemplates() void ATBDeviceControllerPlugin::onPrinterDataPreparedForTemplates()
{ {
if (this->templateList.isEmpty()) return; if (this->currentTicket->templateList()->isEmpty()) return;
this->onPrinterPrintNextTemplate(); this->onPrinterPrintNextTemplate();
} }
@ -866,30 +839,37 @@ void ATBDeviceControllerPlugin::onPrinterWaitForPrintingTicket()
void ATBDeviceControllerPlugin::onPrinterPrintNextTemplate() void ATBDeviceControllerPlugin::onPrinterPrintNextTemplate()
{ {
// template list must not be empty // template list must not be empty
if (this->templateList.isEmpty()) { if (this->currentTicket->templateList()->isEmpty()) {
this->onPrintFinishedERR(); this->onPrintFinishedERR();
return; return;
} }
qCritical() << " ... print template " << this->templateList.first(); qCritical() << " ... print template " << this->currentTicket->templateList()->first();
if (!this->hw->prn_printTemplate(this->templateList.first())) { if (!this->hw->prn_printTemplate(this->currentTicket->templateList()->first())) {
this->errorCode = "hwapi::prn_printTemplate"; this->errorCode = "hwapi::prn_printTemplate";
this->errorDescription = QString("hwapi method 'hwapi::onPrinterPrintNextTemplate(%1)' result is false").arg(this->templateList.first()); this->errorDescription = QString("hwapi method 'hwapi::onPrinterPrintNextTemplate(%1)' result is false").arg(this->currentTicket->templateList()->first());
this->onPrintFinishedERR(); this->onPrintFinishedERR();
return; return;
} }
this->templateList.removeFirst(); this->currentTicket->templateList()->removeFirst();
this->currentTicket->setCurrentTemplateProcessed();
if (templateList.isEmpty()) { if (this->currentTicket->templateList()->isEmpty()) {
// all templates are printed // all templates are printed
QTimer::singleShot(2000, this, SLOT(onPrinterWaitForPrintingTicket())); QTimer::singleShot(2000, this, SLOT(onPrinterWaitForPrintingTicket()));
} }
else {
if (this->currentTicket->hasTemplateDynData()) {
// set new dyn data:
QTimer::singleShot(2000, this, SLOT(onPrinterPrepareDynTemplateData()));
}
else { else {
// print next template // print next template
QTimer::singleShot(2000, this, SLOT(onPrinterPrintNextTemplate())); QTimer::singleShot(2000, this, SLOT(onPrinterPrintNextTemplate()));
} }
}
} }
/************************************************************************************************ /************************************************************************************************
@ -922,21 +902,71 @@ void ATBDeviceControllerPlugin::onPrintFinishedERR()
// private printer data setups void ATBDeviceControllerPlugin::onPrinterPrepareDynTemplateData()
void ATBDeviceControllerPlugin::private_setupDynTicketData_START_RECEIPT(struct T_dynDat *dynTicketData, const QHash<QString, QVariant> & printingData)
{ {
QDateTime parkingEndDateTime = QDateTime::fromString(printingData["parkingEnd"].toString(), Qt::ISODate); this->prepareDynTemplateData();
QDateTime currentDateTime = QDateTime::fromString(printingData["currentDateTime"].toString(), Qt::ISODate); }
void ATBDeviceControllerPlugin::prepareDynTemplateData()
{
struct T_dynDat *dynTicketData = new T_dynDat;
memset(dynTicketData, 0, sizeof(*dynTicketData));
// setup dynTicketData dependent on currentTicket
// DEBUG:
qCritical() << "---------------------------------------------------";
qCritical() << "ATBDeviceControllerPlugin::prepareDynTemplateData():";
qCritical() << " -> currentProcessedTemplateNumber: " << this->currentTicket->getCurrentProcessedTemplateNumber();
qCritical() << " -> this->currentTicket->variant(): " << this->currentTicket->variant();
qCritical() << "---------------------------------------------------";
switch (this->currentTicket->variant()) {
case nsDeviceControllerInterface::TICKET_VARIANT::START_RECEIPT:
private_setupDynTemplateData_START_RECEIPT(dynTicketData, this->currentTicket);
break;
case nsDeviceControllerInterface::TICKET_VARIANT::STOP_RECEIPT:
private_setupDynTemplatData_STOP_RECEIPT(dynTicketData, this->currentTicket);
break;
case nsDeviceControllerInterface::TICKET_VARIANT::RECEIPT:
break;
case nsDeviceControllerInterface::TICKET_VARIANT::ERROR_RECEIPT:
break;
case nsDeviceControllerInterface::TICKET_VARIANT::PARKING_TICKET:
break;
case nsDeviceControllerInterface::TICKET_VARIANT::FOOD_STAMP:
private_setupDynTemplatData_FOOD_STAMP(dynTicketData, this->currentTicket);
break;
}
// C-Programmierung: wird hier nur 'licensePlate' gedruckt?
if (!this->hw->prn_sendDynamicPrnValues(dynTicketData->licensePlate)) {
this->errorCode = "hwapi::prn_sendDynamicPrnValues";
this->errorDescription = "hwapi method 'hwapi::prn_sendDynamicPrnValues' result is false";
qCritical() << "ERROR: hw->prn_sendDynamicPrnValues";
this->onPrintFinishedERR();
return;
}
QTimer::singleShot(1000, this, SLOT(onPrinterDataPreparedForTemplates()));
}
void ATBDeviceControllerPlugin::private_setupDynTemplateData_START_RECEIPT(struct T_dynDat *dynTicketData, Ticket *ticket)
{
QDateTime parkingEndDateTime = QDateTime::fromString(ticket->getPrintingData()["parkingEnd"].toString(), Qt::ISODate);
QDateTime currentDateTime = QDateTime::fromString(ticket->getPrintingData()["currentDateTime"].toString(), Qt::ISODate);
QString parkingEndDateString = this->printerLocale.toString(parkingEndDateTime.date(), QLocale::ShortFormat); QString parkingEndDateString = this->printerLocale.toString(parkingEndDateTime.date(), QLocale::ShortFormat);
QString currentDateString = this->printerLocale.toString(currentDateTime.date(), QLocale::ShortFormat); QString currentDateString = this->printerLocale.toString(currentDateTime.date(), QLocale::ShortFormat);
// set dynamic printer data: // set dynamic printer data:
QByteArray ba_licenseplate = codec->fromUnicode(printingData["licenseplate"].toString()); QByteArray ba_licenseplate = codec->fromUnicode(ticket->getPrintingData()["licenseplate"].toString());
memcpy((char*)dynTicketData->licensePlate, ba_licenseplate.data(), std::min(ba_licenseplate.size(),8)); memcpy((char*)dynTicketData->licensePlate, ba_licenseplate.data(), std::min(ba_licenseplate.size(),8));
QByteArray ba_amount = codec->fromUnicode(printingData["amount"].toString()); QByteArray ba_amount = codec->fromUnicode(ticket->getPrintingData()["amount"].toString());
memcpy((char*)dynTicketData->vendingPrice, ba_amount.data(), std::min(ba_amount.size(),8)); // Szeged memcpy((char*)dynTicketData->vendingPrice, ba_amount.data(), std::min(ba_amount.size(),8)); // Szeged
memcpy((char*)dynTicketData->dynDat6, ba_amount.data(), std::min(ba_amount.size(),8)); // Schoenau memcpy((char*)dynTicketData->dynDat6, ba_amount.data(), std::min(ba_amount.size(),8)); // Schoenau
@ -951,7 +981,7 @@ void ATBDeviceControllerPlugin::private_setupDynTicketData_START_RECEIPT(struct
memcpy((char*)dynTicketData->currentDate, ba_currentDate.data(), std::min(ba_currentDate.size(),8)); memcpy((char*)dynTicketData->currentDate, ba_currentDate.data(), std::min(ba_currentDate.size(),8));
// STAN for Szeged Start/Stop: must be 9 digits // STAN for Szeged Start/Stop: must be 9 digits
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
QString stan = codec->fromUnicode(printingData["STAN"].toString()); QString stan = codec->fromUnicode(ticket->getPrintingData()["STAN"].toString());
qCritical() << " requestPrintTicket() STAN = " << stan; qCritical() << " requestPrintTicket() STAN = " << stan;
QString stan1; QString stan1;
QString stan2; QString stan2;
@ -972,40 +1002,39 @@ void ATBDeviceControllerPlugin::private_setupDynTicketData_START_RECEIPT(struct
memcpy((char*)dynTicketData->dynDat6, ba_stan1.data(), std::min(ba_stan1.size(),8)); memcpy((char*)dynTicketData->dynDat6, ba_stan1.data(), std::min(ba_stan1.size(),8));
memcpy((char*)dynTicketData->dynDat7, ba_stan2.data(), std::min(ba_stan2.size(),8)); memcpy((char*)dynTicketData->dynDat7, ba_stan2.data(), std::min(ba_stan2.size(),8));
} }
void ATBDeviceControllerPlugin::private_setupDynTicketData_STOP_RECEIPT(struct T_dynDat *dynTicketData, const QHash<QString, QVariant> & printingData) void ATBDeviceControllerPlugin::private_setupDynTemplatData_STOP_RECEIPT(struct T_dynDat *dynTicketData, Ticket *ticket)
{ {
// same as START_RECEIPT // same as START_RECEIPT
this->private_setupDynTicketData_START_RECEIPT(dynTicketData, printingData); this->private_setupDynTemplateData_START_RECEIPT(dynTicketData, ticket);
} }
void ATBDeviceControllerPlugin::private_setupDynTemplatData_FOOD_STAMP(struct T_dynDat *dynTicketData, Ticket *ticket)
void ATBDeviceControllerPlugin::private_setupDynTicketData_FOOD_STAMP(struct T_dynDat *dynTicketData, const QHash<QString, QVariant> & printingData)
{ {
// set dynamic printer data: quint8 currentProcessedTemplateNumber = ticket->getCurrentProcessedTemplateNumber();
QByteArray ba_licenseplate = codec->fromUnicode(printingData["employeeNr"].toString());
// TODO: check DynXList size / or ensure that DynXList has value
// "Mitarbeiter-Nummer": dynPr1 -> licenceplate
QString currentEMP_Nr = ticket->getDyn1List().at(currentProcessedTemplateNumber);
QByteArray ba_licenseplate = codec->fromUnicode(currentEMP_Nr);
memcpy((char*)dynTicketData->licensePlate, ba_licenseplate.data(), std::min(ba_licenseplate.size(),8)); memcpy((char*)dynTicketData->licensePlate, ba_licenseplate.data(), std::min(ba_licenseplate.size(),8));
// "Lauf.Nr": dynPr2 -> vendingPrice
QString currentStampNumber = ticket->getDyn2List().at(currentProcessedTemplateNumber);
QByteArray ba_amount = codec->fromUnicode(currentStampNumber);
memcpy((char*)dynTicketData->vendingPrice, ba_amount.data(), std::min(ba_amount.size(),8));
// DEBUG
qCritical() << "-------------------------------------------------------";
qCritical() << "private_setupDynTemplatData_FOOD_STAMP()";
qCritical() << " currentProcessedTemplateNumber: " << currentProcessedTemplateNumber;
qCritical() << " currentEMP_Nr: " << currentEMP_Nr;
qCritical() << " currentStampNumber: " << currentStampNumber;
qCritical() << "-------------------------------------------------------";
} }
// print 'multiplicator' x template 1
void ATBDeviceControllerPlugin::private_setupTemplateList_FOOD_STAMP(const QHash<QString, QVariant> & printingData)
{
int multiplicatorInt = printingData["multiplicator"].toInt();
qCritical() << "printingData[\"multiplicator\"]" << multiplicatorInt;
for (int i = 1; i < multiplicatorInt; i++) {
this->templateList << 1;
}
// last template:
this->templateList << 2;
}
/************************************************************************************************ /************************************************************************************************

View File

@ -7,6 +7,7 @@
#include "src/ATBAPP/DeviceControllerInterface.h" #include "src/ATBAPP/DeviceControllerInterface.h"
#include "src/ATBAPP/ATBAPPplugin.h" #include "src/ATBAPP/ATBAPPplugin.h"
#include "src/ATBAPP/DeviceControllerDiag.h" #include "src/ATBAPP/DeviceControllerDiag.h"
#include "src/ATBAPP/support/Ticket.h"
#include "version.h" #include "version.h"
@ -20,11 +21,11 @@
class DBusControllerInterface; class DBusControllerInterface;
class QTextCodec; class QTextCodec;
using namespace nsDeviceControllerInterface; using namespace nsDeviceControllerInterface;
class QSettings; class QSettings;
class ATBDeviceControllerPlugin : class ATBDeviceControllerPlugin :
public DeviceControllerInterface public DeviceControllerInterface
{ {
@ -94,8 +95,6 @@ private:
QString errorDescription; QString errorDescription;
QString pluginInfo; QString pluginInfo;
QList<int> templateList;
QString serialPortName; QString serialPortName;
bool useDebug; bool useDebug;
@ -131,13 +130,16 @@ private:
// dbus // dbus
int init_sc_dbus(); int init_sc_dbus();
// printer privates // printer privates ----------------------------------------------------------------------------
TICKET_VARIANT currentTicketVariant; Ticket * currentTicket;
QLocale printerLocale; QLocale printerLocale;
void private_setupDynTicketData_START_RECEIPT(struct T_dynDat *dynTicketData, const QHash<QString, QVariant> & printingData);
void private_setupDynTicketData_STOP_RECEIPT(struct T_dynDat *dynTicketData, const QHash<QString, QVariant> & printingData); void prepareDynTemplateData();
void private_setupDynTicketData_FOOD_STAMP(struct T_dynDat *dynTicketData, const QHash<QString, QVariant> & printingData);
void private_setupTemplateList_FOOD_STAMP(const QHash<QString, QVariant> & printingData); void private_setupDynTemplateData_START_RECEIPT(struct T_dynDat *dynTicketData, Ticket *ticket);
void private_setupDynTemplatData_STOP_RECEIPT(struct T_dynDat *dynTicketData, Ticket *ticket);
void private_setupDynTemplatData_FOOD_STAMP(struct T_dynDat *dynTicketData, Ticket *ticket);
// ---------------------------------------------------------------------------------------------
private slots: private slots:
// printer // printer
@ -148,6 +150,8 @@ private slots:
void onPrinterWaitForPrintingTicket(); void onPrinterWaitForPrintingTicket();
void onPrinterWaitForPrintingReceipt(); void onPrinterWaitForPrintingReceipt();
void onPrinterPrepareDynTemplateData();
void onPrintFinishedOK(); void onPrintFinishedOK();
void onPrintFinishedERR(); void onPrintFinishedERR();