Rework Printing: add private methods depending on TICKET_VARIANT

This commit is contained in:
Siegfried Siegert 2024-03-08 13:06:53 +01:00
parent 8659627171
commit 6072970bf0
Signed by: SiegfriedSiegert
GPG Key ID: 68371E015E8F0B03
2 changed files with 93 additions and 48 deletions

View File

@ -564,50 +564,6 @@ void ATBDeviceControllerPlugin::requestPrintTicket(nsDeviceControllerInterface::
struct T_dynDat *dynTicketData = new T_dynDat;
memset(dynTicketData, 0, sizeof(*dynTicketData));
QDateTime parkingEndDateTime = QDateTime::fromString(printingData["parkingEnd"].toString(), Qt::ISODate);
QDateTime currentDateTime = QDateTime::fromString(printingData["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());
memcpy((char*)dynTicketData->licensePlate, ba_licenseplate.data(), std::min(ba_licenseplate.size(),8));
QByteArray ba_amount = codec->fromUnicode(printingData["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
QByteArray ba_parkingEndTime = codec->fromUnicode(parkingEndDateTime.toString("hh:mm"));
memcpy((char*)dynTicketData->parkingEnd, ba_parkingEndTime.data(), std::min(ba_parkingEndTime.size(),8));
QByteArray ba_parkingEndDate = codec->fromUnicode(parkingEndDateString);
memcpy((char*)dynTicketData->currentTime, ba_parkingEndDate.data(), std::min(ba_parkingEndDate.size(),8));
// ! and yes... 'ParkingEndDate' is 'currentTime'
QByteArray ba_currentDate = codec->fromUnicode(currentDateString);
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());
qCritical() << " requestPrintTicket() STAN = " << stan;
QString stan1;
QString stan2;
if (stan.length() == 9) {
stan1 = " " + stan.mid(0,3);
stan2 = stan.mid(3,3) + " " + stan.mid(6,3);
}
else {
qCritical() << "ASSERT: ATBDeviceControllerPlugin::requestPrintTicket() invalid STAN: " << stan;
stan1 = " 000";
stan2 = "000 000";
}
QByteArray ba_stan1 = codec->fromUnicode(stan1);
QByteArray ba_stan2 = codec->fromUnicode(stan2);
// --------------------------------------------------------------------------------------
this->templateList.clear();
this->currentTicketVariant = ticketVariant;
@ -615,14 +571,12 @@ void ATBDeviceControllerPlugin::requestPrintTicket(nsDeviceControllerInterface::
switch (ticketVariant) {
case nsDeviceControllerInterface::TICKET_VARIANT::START_RECEIPT:
qCritical() << " -> TICKET_VARIANT::START_RECEIPT";
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));
this->private_setupDynTicketData_START_RECEIPT(dynTicketData, printingData);
this->templateList << 21 << 22 << 23;
break;
case nsDeviceControllerInterface::TICKET_VARIANT::STOP_RECEIPT:
qCritical() << " -> TICKET_VARIANT::STOP_RECEIPT";
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));
this->private_setupDynTicketData_STOP_RECEIPT(dynTicketData, printingData);
this->templateList << 24 << 25 << 26;
break;
case nsDeviceControllerInterface::TICKET_VARIANT::RECEIPT:
@ -631,10 +585,16 @@ void ATBDeviceControllerPlugin::requestPrintTicket(nsDeviceControllerInterface::
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() << "ATBDeviceControllerPlugin::requestPrintTicket()";
for (int i =0; i < this->templateList.size(); ++i) {
qCritical() << " template: " << this->templateList.at(i);
}
@ -962,6 +922,87 @@ void ATBDeviceControllerPlugin::onPrintFinishedERR()
// private printer data setups
void ATBDeviceControllerPlugin::private_setupDynTicketData_START_RECEIPT(struct T_dynDat *dynTicketData, const QHash<QString, QVariant> & printingData)
{
QDateTime parkingEndDateTime = QDateTime::fromString(printingData["parkingEnd"].toString(), Qt::ISODate);
QDateTime currentDateTime = QDateTime::fromString(printingData["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());
memcpy((char*)dynTicketData->licensePlate, ba_licenseplate.data(), std::min(ba_licenseplate.size(),8));
QByteArray ba_amount = codec->fromUnicode(printingData["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
QByteArray ba_parkingEndTime = codec->fromUnicode(parkingEndDateTime.toString("hh:mm"));
memcpy((char*)dynTicketData->parkingEnd, ba_parkingEndTime.data(), std::min(ba_parkingEndTime.size(),8));
QByteArray ba_parkingEndDate = codec->fromUnicode(parkingEndDateString);
memcpy((char*)dynTicketData->currentTime, ba_parkingEndDate.data(), std::min(ba_parkingEndDate.size(),8));
// ! and yes... 'ParkingEndDate' is 'currentTime'
QByteArray ba_currentDate = codec->fromUnicode(currentDateString);
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());
qCritical() << " requestPrintTicket() STAN = " << stan;
QString stan1;
QString stan2;
if (stan.length() == 9) {
stan1 = " " + stan.mid(0,3);
stan2 = stan.mid(3,3) + " " + stan.mid(6,3);
}
else {
qCritical() << "ASSERT: ATBDeviceControllerPlugin::requestPrintTicket() invalid STAN: " << stan;
stan1 = " 000";
stan2 = "000 000";
}
QByteArray ba_stan1 = codec->fromUnicode(stan1);
QByteArray ba_stan2 = codec->fromUnicode(stan2);
// --------------------------------------------------------------------------------------
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<QString, QVariant> & printingData)
{
// same as START_RECEIPT
this->private_setupDynTicketData_START_RECEIPT(dynTicketData, printingData);
}
void ATBDeviceControllerPlugin::private_setupDynTicketData_FOOD_STAMP(struct T_dynDat *dynTicketData, const QHash<QString, QVariant> & printingData)
{
// set dynamic printer data:
QByteArray ba_licenseplate = codec->fromUnicode(printingData["employeeNr"].toString());
memcpy((char*)dynTicketData->licensePlate, ba_licenseplate.data(), std::min(ba_licenseplate.size(),8));
}
// 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;
}
/************************************************************************************************
* cash payment
*/

View File

@ -134,6 +134,10 @@ private:
// printer privates
TICKET_VARIANT currentTicketVariant;
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 private_setupDynTicketData_FOOD_STAMP(struct T_dynDat *dynTicketData, const QHash<QString, QVariant> & printingData);
void private_setupTemplateList_FOOD_STAMP(const QHash<QString, QVariant> & printingData);
private slots:
// printer