Added possibility for creating vouchers from other module.
This commit is contained in:
+9
-1
@@ -12,8 +12,16 @@
|
||||
|
||||
#include "voucheritem.h"
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#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
|
||||
|
||||
|
||||
@@ -10,10 +10,18 @@
|
||||
|
||||
#include <enums.h>
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#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
|
||||
|
||||
|
||||
+3
-1
@@ -4,11 +4,13 @@
|
||||
#include <QDialog>
|
||||
#include <QDecDouble.hh>
|
||||
|
||||
#include "shop_global.h"
|
||||
|
||||
namespace Ui {
|
||||
class PayDialog;
|
||||
}
|
||||
|
||||
class PayDialog : public QDialog
|
||||
class SHOPSHARED_EXPORT PayDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
+47
-33
@@ -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 <QList>
|
||||
@@ -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("<a href=\"#eet\">Online</a>") : QObject::tr("<a href=\"#eet\">Offline</a>"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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("<a href=\"#eet\">Online</a>") : tr("<a href=\"#eet\">Offline</a>"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReceiptGenerator generator;
|
||||
generator.setVoucher(m_voucher);
|
||||
generator.print();
|
||||
payVoucherFromUI(m_voucher, dialog, this);
|
||||
|
||||
createEmptyVoucher();
|
||||
m_itemsModel->setData(m_voucher->items());
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
void loadLast();
|
||||
void loadButtons();
|
||||
void fillRaceiptCombo();
|
||||
void setEetStatusText(const QString &statusText);
|
||||
|
||||
private slots:
|
||||
void on_directSale_clicked();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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<Voucher>
|
||||
{
|
||||
public:
|
||||
@@ -41,6 +46,7 @@ private:
|
||||
public:
|
||||
void saveVoucher(VoucherPtr entity);
|
||||
void updateVoucher(VoucherPtr entity);
|
||||
void eraseVoucher(VoucherPtr entity);
|
||||
};
|
||||
|
||||
#endif // SHOPSERVICE_H
|
||||
|
||||
Reference in New Issue
Block a user