diff --git a/shop/data/voucher.h b/shop/data/voucher.h index d4108ad..de0183b 100644 --- a/shop/data/voucher.h +++ b/shop/data/voucher.h @@ -12,8 +12,16 @@ #include "voucheritem.h" +#include + +#if defined(SHOP_LIBRARY) +# define SHOPSHARED_EXPORT Q_DECL_EXPORT +#else +# define SHOPSHARED_EXPORT Q_DECL_IMPORT +#endif + #pragma db object -class Voucher : public QObject +class SHOPSHARED_EXPORT Voucher : public QObject { Q_OBJECT diff --git a/shop/data/voucheritem.h b/shop/data/voucheritem.h index 4510fe1..e1b0508 100644 --- a/shop/data/voucheritem.h +++ b/shop/data/voucheritem.h @@ -10,10 +10,18 @@ #include +#include + +#if defined(SHOP_LIBRARY) +# define SHOPSHARED_EXPORT Q_DECL_EXPORT +#else +# define SHOPSHARED_EXPORT Q_DECL_IMPORT +#endif + class Voucher; #pragma db object -class VoucherItem : public QObject +class SHOPSHARED_EXPORT VoucherItem : public QObject { Q_OBJECT diff --git a/shop/paydialog.h b/shop/paydialog.h index fba7df2..9f72755 100644 --- a/shop/paydialog.h +++ b/shop/paydialog.h @@ -4,11 +4,13 @@ #include #include +#include "shop_global.h" + namespace Ui { class PayDialog; } -class PayDialog : public QDialog +class SHOPSHARED_EXPORT PayDialog : public QDialog { Q_OBJECT diff --git a/shop/shopform.cpp b/shop/shopform.cpp index ac7be7e..d8d65d3 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -4,9 +4,9 @@ #include "temporaryreceiptsaveform.h" #include "receiptsaveform.h" #include "receiptloadform.h" +#include "paydialog.h" #include "shopservice.h" #include "receiptgenerator.h" -#include "paydialog.h" #include "paydvouchersdialog.h" #include "isellableservice.h" #include @@ -18,6 +18,46 @@ #include "shop-odb.hxx" +void payVoucherFromUI(VoucherPtr voucher, PayDialog *dialog, ShopForm *form) +{ + ShopService srv; + srv.pay(voucher); + voucher->setEetStatus(dialog->sendToEet() ? Voucher::EET_FOR_SEND : Voucher::EET_NOT_ENTERING); + srv.update(voucher); + QString eetMsg; + + if (srv.isEetEnabled() && dialog->sendToEet()) + { + bool eetRet = srv.processEet(voucher, eetMsg); + + if (!eetRet) + { + QString errMsg = QObject::tr("EET communication error.\n"); + + if (!eetMsg.isEmpty()) + { + errMsg += QObject::tr("Message from portal: ") + eetMsg + "\n"; + } + + errMsg += QObject::tr("Switch to offline?"); + + if (srv.isEetOnline() && QMessageBox::question(NULL, QObject::tr("EET error"), errMsg) == QMessageBox::Yes) + { + srv.setEetOnline(false); + + if (form != NULL) + { + form->setEetStatusText(srv.isEetOnline() ? QObject::tr("Online") : QObject::tr("Offline")); + } + } + } + } + + ReceiptGenerator generator; + generator.setVoucher(voucher); + generator.print(); +} + ShopForm::ShopForm(QWidget *parent) : QWidget(parent), ui(new Ui::ShopForm) @@ -172,6 +212,11 @@ void ShopForm::fillRaceiptCombo() ui->receiptCombo->blockSignals(oldState); } +void ShopForm::setEetStatusText(const QString &statusText) +{ + ui->lblEetState->setText(statusText); +} + void ShopForm::on_directSale_clicked() { DirectSaleForm *form = new DirectSaleForm(this); @@ -429,38 +474,7 @@ void ShopForm::on_payButton_clicked() dialog->show(); connect(dialog, &QDialog::accepted, [this, dialog](){ - ShopService srv; - srv.pay(m_voucher); - m_voucher->setEetStatus(dialog->sendToEet() ? Voucher::EET_FOR_SEND : Voucher::EET_NOT_ENTERING); - srv.update(m_voucher); - QString eetMsg; - - if (srv.isEetEnabled() && dialog->sendToEet()) - { - bool eetRet = srv.processEet(m_voucher, eetMsg); - - if (!eetRet) - { - QString errMsg = tr("EET communication error.\n"); - - if (!eetMsg.isEmpty()) - { - errMsg += tr("Message from portal: ") + eetMsg + "\n"; - } - - errMsg += tr("Switch to offline?"); - - if (srv.isEetOnline() && QMessageBox::question(this, tr("EET error"), errMsg) == QMessageBox::Yes) - { - srv.setEetOnline(false); - ui->lblEetState->setText(srv.isEetOnline() ? tr("Online") : tr("Offline")); - } - } - } - - ReceiptGenerator generator; - generator.setVoucher(m_voucher); - generator.print(); + payVoucherFromUI(m_voucher, dialog, this); createEmptyVoucher(); m_itemsModel->setData(m_voucher->items()); diff --git a/shop/shopform.h b/shop/shopform.h index 9cf0cee..ef903d8 100644 --- a/shop/shopform.h +++ b/shop/shopform.h @@ -23,6 +23,7 @@ public: void loadLast(); void loadButtons(); void fillRaceiptCombo(); + void setEetStatusText(const QString &statusText); private slots: void on_directSale_clicked(); diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index 74dec20..08651f1 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -375,3 +375,14 @@ void ShopService::updateVoucher(VoucherPtr entity) tr.commit(); } + +void ShopService::eraseVoucher(VoucherPtr entity) +{ + Transaction tr; + odb::database *db = Context::instance().db(); + + db->execute(QString("DELETE FROM VoucherItem WHERE voucher = %1").arg(entity->id()).toStdString()); + db->erase(entity); + + tr.commit(); +} diff --git a/shop/shopservice.h b/shop/shopservice.h index 2a622bb..7db60d8 100644 --- a/shop/shopservice.h +++ b/shop/shopservice.h @@ -9,6 +9,11 @@ #include "data/shop-data.h" #include "shopitem.h" +class PayDialog; +class ShopForm; + +void payVoucherFromUI(VoucherPtr voucher, PayDialog *dialog, ShopForm *form = NULL); + class ShopService : public Service { public: @@ -41,6 +46,7 @@ private: public: void saveVoucher(VoucherPtr entity); void updateVoucher(VoucherPtr entity); + void eraseVoucher(VoucherPtr entity); }; #endif // SHOPSERVICE_H