From f94f33862fc66ed4ecc63be667319337d6e1aec8 Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Mon, 11 Mar 2024 14:06:05 +0100 Subject: [PATCH] Printing: dynamically set template dyn-data using Ticket-class See DC_printer_interface.graphml/pdf --- src/ATBAPP/ATBDeviceControllerPlugin.cpp | 213 +++++++++++++---------- src/ATBAPP/ATBDeviceControllerPlugin.h | 22 ++- 2 files changed, 134 insertions(+), 101 deletions(-) diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.cpp b/src/ATBAPP/ATBDeviceControllerPlugin.cpp index 85fd127..d7a8126 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.cpp +++ b/src/ATBAPP/ATBDeviceControllerPlugin.cpp @@ -70,7 +70,7 @@ ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent) // currentSelectedTicketType - number of used "Kombiticket" (deprecated) use TICKET_VARIANT in future this->currentSelectedTicketType = 0; - this->currentTicketVariant = TICKET_VARIANT::PARKING_TICKET; + this->currentTicket = new Ticket(TICKET_VARIANT::PARKING_TICKET, this); 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 & printingData) { - struct T_dynDat *dynTicketData = new T_dynDat; - memset(dynTicketData, 0, sizeof(*dynTicketData)); + QList templateList; - 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 + qCritical() << "------------------------------------------------------------------------"; 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()) { qCritical() << " ... serial port is not open!"; @@ -608,26 +600,7 @@ void ATBDeviceControllerPlugin::requestPrintTicket(nsDeviceControllerInterface:: } */ - // TODO: 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:"; - 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())); - + this->prepareDynTemplateData(); } void ATBDeviceControllerPlugin::requestPrintReceipt(const QHash & printingData) @@ -821,7 +794,7 @@ void ATBDeviceControllerPlugin::requestPrintTicket(const QHashtemplateList.isEmpty()) return; + if (this->currentTicket->templateList()->isEmpty()) return; this->onPrinterPrintNextTemplate(); } @@ -866,30 +839,37 @@ void ATBDeviceControllerPlugin::onPrinterWaitForPrintingTicket() void ATBDeviceControllerPlugin::onPrinterPrintNextTemplate() { // template list must not be empty - if (this->templateList.isEmpty()) { + if (this->currentTicket->templateList()->isEmpty()) { this->onPrintFinishedERR(); 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->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(); return; } - this->templateList.removeFirst(); + this->currentTicket->templateList()->removeFirst(); + this->currentTicket->setCurrentTemplateProcessed(); - if (templateList.isEmpty()) { + if (this->currentTicket->templateList()->isEmpty()) { // all templates are printed QTimer::singleShot(2000, this, SLOT(onPrinterWaitForPrintingTicket())); } else { - // print next template - QTimer::singleShot(2000, this, SLOT(onPrinterPrintNextTemplate())); - } + if (this->currentTicket->hasTemplateDynData()) { + // set new dyn data: + QTimer::singleShot(2000, this, SLOT(onPrinterPrepareDynTemplateData())); + } + else { + // print next template + QTimer::singleShot(2000, this, SLOT(onPrinterPrintNextTemplate())); + } + } } /************************************************************************************************ @@ -922,21 +902,71 @@ void ATBDeviceControllerPlugin::onPrintFinishedERR() -// private printer data setups -void ATBDeviceControllerPlugin::private_setupDynTicketData_START_RECEIPT(struct T_dynDat *dynTicketData, const QHash & printingData) +void ATBDeviceControllerPlugin::onPrinterPrepareDynTemplateData() { - QDateTime parkingEndDateTime = QDateTime::fromString(printingData["parkingEnd"].toString(), Qt::ISODate); - QDateTime currentDateTime = QDateTime::fromString(printingData["currentDateTime"].toString(), Qt::ISODate); + this->prepareDynTemplateData(); +} +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 currentDateString = this->printerLocale.toString(currentDateTime.date(), QLocale::ShortFormat); // 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)); - 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->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)); // 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; QString stan1; 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->dynDat7, ba_stan2.data(), std::min(ba_stan2.size(),8)); - - } -void ATBDeviceControllerPlugin::private_setupDynTicketData_STOP_RECEIPT(struct T_dynDat *dynTicketData, const QHash & printingData) +void ATBDeviceControllerPlugin::private_setupDynTemplatData_STOP_RECEIPT(struct T_dynDat *dynTicketData, Ticket *ticket) { // same as START_RECEIPT - this->private_setupDynTicketData_START_RECEIPT(dynTicketData, printingData); + this->private_setupDynTemplateData_START_RECEIPT(dynTicketData, ticket); } - - -void ATBDeviceControllerPlugin::private_setupDynTicketData_FOOD_STAMP(struct T_dynDat *dynTicketData, const QHash & printingData) +void ATBDeviceControllerPlugin::private_setupDynTemplatData_FOOD_STAMP(struct T_dynDat *dynTicketData, Ticket *ticket) { - // set dynamic printer data: - QByteArray ba_licenseplate = codec->fromUnicode(printingData["employeeNr"].toString()); + quint8 currentProcessedTemplateNumber = ticket->getCurrentProcessedTemplateNumber(); + + // 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)); + // "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 & 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; -} /************************************************************************************************ diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.h b/src/ATBAPP/ATBDeviceControllerPlugin.h index 3e11134..dbf3f8d 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.h +++ b/src/ATBAPP/ATBDeviceControllerPlugin.h @@ -7,6 +7,7 @@ #include "src/ATBAPP/DeviceControllerInterface.h" #include "src/ATBAPP/ATBAPPplugin.h" #include "src/ATBAPP/DeviceControllerDiag.h" +#include "src/ATBAPP/support/Ticket.h" #include "version.h" @@ -20,11 +21,11 @@ class DBusControllerInterface; class QTextCodec; - using namespace nsDeviceControllerInterface; class QSettings; + class ATBDeviceControllerPlugin : public DeviceControllerInterface { @@ -94,8 +95,6 @@ private: QString errorDescription; QString pluginInfo; - QList templateList; - QString serialPortName; bool useDebug; @@ -131,13 +130,16 @@ private: // dbus int init_sc_dbus(); - // printer privates - TICKET_VARIANT currentTicketVariant; + // printer privates ---------------------------------------------------------------------------- + Ticket * currentTicket; QLocale printerLocale; - void private_setupDynTicketData_START_RECEIPT(struct T_dynDat *dynTicketData, const QHash & printingData); - void private_setupDynTicketData_STOP_RECEIPT(struct T_dynDat *dynTicketData, const QHash & printingData); - void private_setupDynTicketData_FOOD_STAMP(struct T_dynDat *dynTicketData, const QHash & printingData); - void private_setupTemplateList_FOOD_STAMP(const QHash & printingData); + + void prepareDynTemplateData(); + + 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: // printer @@ -148,6 +150,8 @@ private slots: void onPrinterWaitForPrintingTicket(); void onPrinterWaitForPrintingReceipt(); + void onPrinterPrepareDynTemplateData(); + void onPrintFinishedOK(); void onPrintFinishedERR();