diff --git a/shop/data/voucher.cpp b/shop/data/voucher.cpp index 5ad6cf4..99cf029 100644 --- a/shop/data/voucher.cpp +++ b/shop/data/voucher.cpp @@ -16,6 +16,7 @@ Voucher::Voucher(QObject *parent) : QObject(parent) m_totalPriceVatFirstLower = 0; m_totalPriceVatSecondLower = 0; m_totalPrice = 0; + m_eetStatus = EET_FOR_SEND; } QString Voucher::name() const @@ -230,6 +231,56 @@ void Voucher::setPayDateTime(const QDateTime &payDateTime) m_payDateTime = payDateTime; } +Voucher::EetStatus Voucher::eetStatus() const +{ + return m_eetStatus; +} + +void Voucher::setEetStatus(const Voucher::EetStatus &eetStatus) +{ + m_eetStatus = eetStatus; +} + +QDateTime Voucher::eetSendDateTime() const +{ + return m_eetSendDateTime; +} + +void Voucher::setEetSendDateTime(const QDateTime &eetSendDateTime) +{ + m_eetSendDateTime = eetSendDateTime; +} + +QString Voucher::eetPkp() const +{ + return m_eetPkp; +} + +void Voucher::setEetPkp(const QString &eetPkp) +{ + m_eetPkp = eetPkp; +} + +QString Voucher::eetBkp() const +{ + return m_eetBkp; +} + +void Voucher::setEetBkp(const QString &eetBkp) +{ + m_eetBkp = eetBkp; +} + +QString Voucher::eetFik() const +{ + return m_eetFik; +} + +void Voucher::setEetFik(const QString &eetFik) +{ + m_eetFik = eetFik; +} + int Voucher::id() const { return m_id; diff --git a/shop/data/voucher.h b/shop/data/voucher.h index 36063d1..3ad0385 100644 --- a/shop/data/voucher.h +++ b/shop/data/voucher.h @@ -28,7 +28,13 @@ class Voucher : public QObject Q_PROPERTY(QDecDouble priceVatFirstLower READ priceVatFirstLower WRITE setPriceVatFirstLower) Q_PROPERTY(QDecDouble priceVatSecondLower READ priceVatSecondLower WRITE setPriceVatSecondLower) Q_PROPERTY(QDecDouble totalPrice READ totalPrice WRITE setTotalPrice) + Q_PROPERTY(EetStatus eetStatus READ eetStatus WRITE setEetStatus) + Q_PROPERTY(QDateTime eetSendDateTime READ eetSendDateTime WRITE setEetSendDateTime) + Q_PROPERTY(QString eetBkp READ eetBkp WRITE setEetBkp) + Q_PROPERTY(QString eetPkp READ eetPkp WRITE setEetPkp) + Q_PROPERTY(QString eetFik READ eetFik WRITE setEetFik) Q_ENUMS(VoucherStatus) + Q_ENUMS(EetStatus) Q_PROPERTY(VoucherStatus status READ status WRITE setStatus) public: @@ -42,6 +48,14 @@ public: PAID }; + enum EetStatus + { + EET_FOR_SEND, + EET_NOT_ENTERING, + EET_SENT, + EET_ERROR + }; + int id() const; void setId(int id); @@ -110,6 +124,21 @@ public: QDateTime payDateTime() const; void setPayDateTime(const QDateTime &payDateTime); + EetStatus eetStatus() const; + void setEetStatus(const EetStatus &eetStatus); + + QDateTime eetSendDateTime() const; + void setEetSendDateTime(const QDateTime &eetSendDateTime); + + QString eetPkp() const; + void setEetPkp(const QString &eetPkp); + + QString eetBkp() const; + void setEetBkp(const QString &eetBkp); + + QString eetFik() const; + void setEetFik(const QString &eetFik); + private: friend class odb::access; #pragma db id auto @@ -131,6 +160,11 @@ private: int m_totalPriceVatFirstLower; int m_totalPriceVatSecondLower; int m_totalPrice; + EetStatus m_eetStatus; + QDateTime m_eetSendDateTime; + QString m_eetPkp; + QString m_eetBkp; + QString m_eetFik; #pragma db value_not_null inverse(m_voucher) QOdbList > m_items; VoucherStatus m_status; diff --git a/shop/receiptgenerator.cpp b/shop/receiptgenerator.cpp index 4f513e1..daeafa4 100644 --- a/shop/receiptgenerator.cpp +++ b/shop/receiptgenerator.cpp @@ -138,7 +138,13 @@ QByteArray ReceiptGenerator::generate() out.append("\x1b\x21"); out.append((char)0); out.append("\x0a"); + out.append("BKP:"); out.append("\x0a"); + out.append(prepareString(m_voucher->eetBkp())); + out.append("\x0a"); + out.append("FIK:"); + out.append("\x0a"); + out.append(prepareString(m_voucher->eetFik())); out.append("\x0a"); out.append("\x0a"); out.append("\x0a"); diff --git a/shop/settings/shopsettings.cpp b/shop/settings/shopsettings.cpp index 78064d3..38e6ad5 100644 --- a/shop/settings/shopsettings.cpp +++ b/shop/settings/shopsettings.cpp @@ -4,6 +4,11 @@ ShopSettings::ShopSettings(QObject *parent) : QObject(parent) { m_codepage = ASCII; m_lettersPerLine = 48; + + m_eetActive = false; + m_eetMode = 1; + m_eetTest = 0; + m_eetPlayground = 0; } QString ShopSettings::output() const @@ -45,3 +50,83 @@ void ShopSettings::setByMessage(const QString &byMessage) { m_byMessage = byMessage; } + +bool ShopSettings::eetActive() const +{ + return m_eetActive; +} + +void ShopSettings::setEetActive(bool eetActive) +{ + m_eetActive = eetActive; +} + +QString ShopSettings::eetShopId() const +{ + return m_eetShopId; +} + +void ShopSettings::setEetShopId(const QString &eetShopId) +{ + m_eetShopId = eetShopId; +} + +QString ShopSettings::eetRegisterId() const +{ + return m_eetRegisterId; +} + +void ShopSettings::setEetRegisterId(const QString &eetRegisterId) +{ + m_eetRegisterId = eetRegisterId; +} + +int ShopSettings::eetMode() const +{ + return m_eetMode; +} + +void ShopSettings::setEetMode(int eetMode) +{ + m_eetMode = eetMode; +} + +QString ShopSettings::eetCertificate() const +{ + return m_eetCertificate; +} + +void ShopSettings::setEetCertificate(const QString &eetCertificate) +{ + m_eetCertificate = eetCertificate; +} + +QString ShopSettings::eetKeyPassword() const +{ + return m_eetKeyPassword; +} + +void ShopSettings::setEetKeyPassword(const QString &eetKeyPassword) +{ + m_eetKeyPassword = eetKeyPassword; +} + +bool ShopSettings::eetTest() const +{ + return m_eetTest; +} + +void ShopSettings::setEetTest(bool eetTest) +{ + m_eetTest = eetTest; +} + +bool ShopSettings::eetPlayground() const +{ + return m_eetPlayground; +} + +void ShopSettings::setEetPlayground(bool eetPlayground) +{ + m_eetPlayground = eetPlayground; +} diff --git a/shop/settings/shopsettings.h b/shop/settings/shopsettings.h index acfb626..d57f892 100644 --- a/shop/settings/shopsettings.h +++ b/shop/settings/shopsettings.h @@ -9,6 +9,15 @@ class ShopSettings : public QObject Q_PROPERTY(int lettersPerLine READ lettersPerLine WRITE setLettersPerLine) Q_PROPERTY(QString byMessage READ byMessage WRITE setByMessage) + Q_PROPERTY(bool eetActive READ eetActive WRITE setEetActive) + Q_PROPERTY(QString eetShopId READ eetShopId WRITE setEetShopId) + Q_PROPERTY(QString eetRegisterId READ eetRegisterId WRITE setEetRegisterId) + Q_PROPERTY(int eetMode READ eetMode WRITE setEetMode) + Q_PROPERTY(QString eetCertificate READ eetCertificate WRITE setEetCertificate) + Q_PROPERTY(QString eetKeyPassword READ eetKeyPassword WRITE setEetKeyPassword) + Q_PROPERTY(bool eetTest READ eetTest WRITE setEetTest) + Q_PROPERTY(bool eetPlayground READ eetPlayground WRITE setEetPlayground) + Q_OBJECT public: @@ -31,11 +40,44 @@ public: QString byMessage() const; void setByMessage(const QString &byMessage); + bool eetActive() const; + void setEetActive(bool eetActive); + + QString eetShopId() const; + void setEetShopId(const QString &eetShopId); + + QString eetRegisterId() const; + void setEetRegisterId(const QString &eetRegisterId); + + int eetMode() const; + void setEetMode(int eetMode); + + QString eetCertificate() const; + void setEetCertificate(const QString &eetCertificate); + + QString eetKeyPassword() const; + void setEetKeyPassword(const QString &eetKeyPassword); + + bool eetTest() const; + void setEetTest(bool eetTest); + + bool eetPlayground() const; + void setEetPlayground(bool eetPlayground); + private: QString m_output; CODEPAGE m_codepage; int m_lettersPerLine; QString m_byMessage; + + bool m_eetActive; + QString m_eetShopId; + QString m_eetRegisterId; + int m_eetMode; + QString m_eetCertificate; + QString m_eetKeyPassword; + bool m_eetTest; + bool m_eetPlayground; }; typedef QSharedPointer ShopSettingsPtr; diff --git a/shop/settings/shopsettingsform.cpp b/shop/settings/shopsettingsform.cpp index b7280bf..b919ee9 100644 --- a/shop/settings/shopsettingsform.cpp +++ b/shop/settings/shopsettingsform.cpp @@ -2,6 +2,8 @@ #include "ui_shopsettingsform.h" #include +#include +#include #include "shopservice.h" ShopSettingsForm::ShopSettingsForm(QWidget *parent) : @@ -14,6 +16,17 @@ ShopSettingsForm::ShopSettingsForm(QWidget *parent) : registerBinding(ui->lettersPerLine); registerBinding(ui->byMessage); + registerBinding(ui->eetActive); + registerBinding(ui->eetShopId); + registerBinding(ui->eetRegisterId); + QList listModes; + listModes << ComboData(0, tr("Simplifyed")) << ComboData(1, tr("Standard")); + registerBinding(ui->eetMode, listModes); + registerBinding(ui->eetCertificate); + registerBinding(ui->eetKeyPassword); + registerBinding(ui->eetTest); + registerBinding(ui->eetPlayground); + m_itemModel = new AutoTableModel(); } @@ -41,3 +54,13 @@ bool ShopSettingsForm::saveRecord() return true; } + +void ShopSettingsForm::on_btnCertBrowse_clicked() +{ + QString certFile = QFileDialog::getOpenFileName(this, "Certificate file", "", "P12 Files (*.p12)"); + + if (!certFile.isEmpty()) + { + ui->eetCertificate->setText(certFile); + } +} diff --git a/shop/settings/shopsettingsform.h b/shop/settings/shopsettingsform.h index f46f875..ecefb41 100644 --- a/shop/settings/shopsettingsform.h +++ b/shop/settings/shopsettingsform.h @@ -29,6 +29,8 @@ public: public slots: bool saveRecord(); +private slots: + void on_btnCertBrowse_clicked(); }; #endif // SHOPSETTINGSFORM_H diff --git a/shop/settings/shopsettingsform.ui b/shop/settings/shopsettingsform.ui index 7e5b2e6..267bd7d 100644 --- a/shop/settings/shopsettingsform.ui +++ b/shop/settings/shopsettingsform.ui @@ -17,7 +17,7 @@ - 0 + 2 @@ -234,6 +234,121 @@ + + + EET + + + + + + Activate EET + + + true + + + false + + + + + + Shop ID + + + + + + + + + + Cash register ID + + + + + + + + + + EET mode + + + + + + + + + + Certificate file + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + ... + + + + + + + + + + Private key password + + + + + + + QLineEdit::Password + + + + + + + Test mode + + + + + + + Communication with playground + + + + + + + + diff --git a/shop/shop.json b/shop/shop.json index ccd3cab..62277d8 100644 --- a/shop/shop.json +++ b/shop/shop.json @@ -47,6 +47,11 @@ CREATE TABLE \"Voucher\" ( \"totalPriceVatSecondLower\" INTEGER NOT NULL, \"totalPrice\" INTEGER NOT NULL, \"status\" INTEGER NOT NULL, + \"eetStatus\" INTEGER NOT NULL, + \"eetSendDateTime\" TEXT NULL, + \"eetPkp\" TEXT, + \"eetBkp\" TEXT, + \"eetFik\" TEXT, CONSTRAINT \"contact_fk\" FOREIGN KEY (\"contact\") REFERENCES \"AddressbookData\" (\"id\") diff --git a/shop/shop.pro b/shop/shop.pro index 665cec6..9507421 100644 --- a/shop/shop.pro +++ b/shop/shop.pro @@ -113,3 +113,8 @@ FORMS += \ paydvouchersdialog.ui TRANSLATIONS = translations/shop_cs_CZ.ts + +unix|win32: LIBS += -L$$PWD/../../build-EetCpp-Desktop-Debug/libEet -lEetCpp + +INCLUDEPATH += $$PWD/../../EetCpp/libEet +DEPENDPATH += $$PWD/../../EetCpp/libEet diff --git a/shop/shopform.cpp b/shop/shopform.cpp index 4d29d80..9e5674c 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -306,6 +306,7 @@ void ShopForm::on_payButton_clicked() connect(dialog, &QDialog::accepted, [this](){ ShopService srv; srv.pay(m_voucher); + srv.processEet(m_voucher); ReceiptGenerator generator; generator.setVoucher(m_voucher); diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index 9aa6895..8d719e0 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -3,6 +3,11 @@ #include "isellableservice.h" #include "shop-odb.hxx" +#include "settings/shopsettings.h" + +#include +#include + ShopService::ShopService() { } @@ -101,6 +106,7 @@ void ShopService::pay(VoucherPtr voucher) voucher->setNumSer(numSerStr); voucher->setStatus(Voucher::PAID); + voucher->setEetStatus(Voucher::EET_FOR_SEND); voucher->setPayDateTime(QDateTime::currentDateTime()); this->update(voucher); @@ -119,6 +125,62 @@ void ShopService::updateRelatedItem(VoucherItem* item, int countAdded) selSrv->addedToVoucher(item->refId(), countAdded); } } + +void ShopService::processEet(VoucherPtr voucher) +{ + if (voucher->eetStatus() == Voucher::EET_NOT_ENTERING) + { + return; + } + + SettingsService srvSettings("SHOP"); + ShopSettingsPtr settings = srvSettings.loadSettings(); + + loadSettings(); + EetRequest request; + request.setCelkTrzba(voucher->totalPrice().toDouble()); + request.setDatTrzby(voucher->payDateTime()); + request.setIdPokl(settings->eetRegisterId()); + request.setIdProvoz(settings->eetShopId()); + request.setPrvniZaslani(voucher->eetStatus() == Voucher::EET_FOR_SEND); + request.setDicPopl(m_gs->dic()); + request.setPoradCis(voucher->numSer()); + request.setDatOdesl(QDateTime::currentDateTime()); + request.setRezim((EetRequest::EetRezim)settings->eetMode()); + + EetSender *sender = new EetSender(this); + sender->setupSigner(settings->eetCertificate(), settings->eetKeyPassword()); + sender->setPlayground(settings->eetPlayground()); + + QEventLoop loop; + + connect(sender, &EetSender::sendFinished, [this, voucher, sender, &loop](){ + Transaction tx; + + if (sender->resut()->status() == EetResult::RESPONSE_OK) + { + voucher->setEetBkp(sender->resut()->bkp()); + voucher->setEetPkp(sender->resut()->pkp()); + voucher->setEetFik(sender->resut()->fik()); + voucher->setEetSendDateTime(QDateTime::currentDateTime()); + voucher->setEetStatus(Voucher::EET_SENT); + } + else + { + voucher->setEetStatus(Voucher::EET_ERROR); + } + + this->update(voucher); + tx.commit(); + sender->deleteLater(); + + loop.quit(); + }); + + sender->sendRequest(&request); + loop.exec(); +} + void ShopService::moveItems(QList items, VoucherPtr source, VoucherPtr target) { Transaction tx; diff --git a/shop/shopservice.h b/shop/shopservice.h index e4b5bf6..55e6189 100644 --- a/shop/shopservice.h +++ b/shop/shopservice.h @@ -21,6 +21,7 @@ public: void pay(VoucherPtr voucher); void moveItems(QList items, VoucherPtr source, VoucherPtr target); void updateRelatedItem(VoucherItem* item, int countAdded); + void processEet(VoucherPtr voucher); QList savedVouchers(); QList tempVouchers(); QList paiedVouchers();