Fixed voucher saving.

closes #274
print
Josef Rokos 8 years ago
parent 9e8d69827f
commit ec16d90fa4

@ -45,7 +45,7 @@ ReceiptSaveForm::ReceiptSaveForm(QSharedPointer<Voucher> voucher, QWidget *paren
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty()); ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty());
}); });
m_binder.setData(new Voucher); m_binder.setData(voucher.data());
AddressBookService srvAdb; AddressBookService srvAdb;
m_binder.registerBinding(ui->contact, ComboData::createComboData(srvAdb.all())); m_binder.registerBinding(ui->contact, ComboData::createComboData(srvAdb.all()));
m_binder.registerBinding(ui->name); m_binder.registerBinding(ui->name);
@ -66,6 +66,21 @@ ReceiptSaveForm::~ReceiptSaveForm()
delete ui; delete ui;
} }
VoucherPtr ReceiptSaveForm::selectedVoucher()
{
if (ui->tabVouchers->currentIndex().isValid())
{
return m_voucherModel->itemFromIndex(ui->tabVouchers->currentIndex());
}
return VoucherPtr();
}
bool ReceiptSaveForm::saveAsNew()
{
return m_saveAsNew;
}
void ReceiptSaveForm::on_lineEdit_textChanged(const QString &text) void ReceiptSaveForm::on_lineEdit_textChanged(const QString &text)
{ {
QSortFilterProxyModel proxy; QSortFilterProxyModel proxy;

@ -18,6 +18,9 @@ public:
explicit ReceiptSaveForm(QSharedPointer<Voucher> voucher, QWidget *parent = 0); explicit ReceiptSaveForm(QSharedPointer<Voucher> voucher, QWidget *parent = 0);
~ReceiptSaveForm(); ~ReceiptSaveForm();
VoucherPtr selectedVoucher();
bool saveAsNew();
private slots: private slots:
void on_lineEdit_textChanged(const QString &text); void on_lineEdit_textChanged(const QString &text);
@ -28,7 +31,7 @@ private:
ObjectBinder m_binder; ObjectBinder m_binder;
AutoTableModel<Voucher> *m_voucherModel; AutoTableModel<Voucher> *m_voucherModel;
bool m_saveAsNew; bool m_saveAsNew;
QSharedPointer<Voucher> m_voucher; VoucherPtr m_voucher;
// QDialog interface // QDialog interface
public slots: public slots:

@ -54,10 +54,14 @@ void ShopForm::loadLast()
connectItemSignals(); connectItemSignals();
ui->total->setText(QString::number(m_voucher->totalPrice().toDouble(), 'f', 2)); ui->total->setText(QString::number(m_voucher->totalPrice().toDouble(), 'f', 2));
if (!m_voucher->items().isEmpty())
{
ui->temporarySaveButton->setEnabled(true); ui->temporarySaveButton->setEnabled(true);
ui->saveButton->setEnabled(true); ui->saveButton->setEnabled(true);
ui->payButton->setEnabled(true); ui->payButton->setEnabled(true);
} }
}
if (m_commodityModel == NULL) if (m_commodityModel == NULL)
{ {
@ -119,13 +123,25 @@ void ShopForm::on_saveButton_clicked()
ReceiptSaveForm *form = new ReceiptSaveForm(m_voucher, this); ReceiptSaveForm *form = new ReceiptSaveForm(m_voucher, this);
form->setAttribute(Qt::WA_DeleteOnClose); form->setAttribute(Qt::WA_DeleteOnClose);
connect(form, &QDialog::accepted, [this]() { connect(form, &QDialog::accepted, [this, form]() {
ShopService srv; ShopService srv;
if (form->saveAsNew())
{
m_voucher->setStatus(Voucher::NOT_PAID); m_voucher->setStatus(Voucher::NOT_PAID);
srv.saveVoucher(m_voucher); srv.saveVoucher(m_voucher);
m_voucher = srv.createVoucher(); createEmptyVoucher();
}
else
{
VoucherPtr selVoucher = form->selectedVoucher();
srv.moveItems(m_voucher->items(), m_voucher, selVoucher);
srv.calculate(selVoucher);
srv.updateVoucher(selVoucher);
createEmptyVoucher();
}
m_itemsModel->setData(m_voucher->items()); m_itemsModel->setData(m_voucher->items());
ui->total->setText("0");
}); });
form->show(); form->show();
@ -306,7 +322,13 @@ void ShopForm::on_payButton_clicked()
connect(dialog, &QDialog::accepted, [this](){ connect(dialog, &QDialog::accepted, [this](){
ShopService srv; ShopService srv;
srv.pay(m_voucher); srv.pay(m_voucher);
srv.processEet(m_voucher); QString eetMsg;
bool eetRet = srv.processEet(m_voucher, eetMsg);
if (!eetRet)
{
}
ReceiptGenerator generator; ReceiptGenerator generator;
generator.setVoucher(m_voucher); generator.setVoucher(m_voucher);

@ -126,11 +126,11 @@ void ShopService::updateRelatedItem(VoucherItem* item, int countAdded)
} }
} }
void ShopService::processEet(VoucherPtr voucher) bool ShopService::processEet(VoucherPtr voucher, QString message)
{ {
if (voucher->eetStatus() == Voucher::EET_NOT_ENTERING) if (voucher->eetStatus() == Voucher::EET_NOT_ENTERING)
{ {
return; return true;
} }
SettingsService srvSettings("SHOP"); SettingsService srvSettings("SHOP");
@ -157,11 +157,12 @@ void ShopService::processEet(VoucherPtr voucher)
connect(sender, &EetSender::sendFinished, [this, voucher, sender, &loop](){ connect(sender, &EetSender::sendFinished, [this, voucher, sender, &loop](){
Transaction tx; Transaction tx;
if (sender->resut()->status() == EetResult::RESPONSE_OK)
{
voucher->setEetBkp(sender->resut()->bkp()); voucher->setEetBkp(sender->resut()->bkp());
voucher->setEetPkp(sender->resut()->pkp()); voucher->setEetPkp(sender->resut()->pkp());
voucher->setEetFik(sender->resut()->fik()); voucher->setEetFik(sender->resut()->fik());
if (sender->resut()->status() == EetResult::RESPONSE_OK)
{
voucher->setEetSendDateTime(QDateTime::currentDateTime()); voucher->setEetSendDateTime(QDateTime::currentDateTime());
voucher->setEetStatus(Voucher::EET_SENT); voucher->setEetStatus(Voucher::EET_SENT);
} }
@ -179,6 +180,30 @@ void ShopService::processEet(VoucherPtr voucher)
sender->sendRequest(&request); sender->sendRequest(&request);
loop.exec(); loop.exec();
auto addMessage = [&message](EetMessage *msg, const QString &label){
if (message.isEmpty())
{
message = label + "\n";
}
message += QString::number(msg->code()) + ": " + msg->message();
};
foreach (EetMessage *msg, sender->resut()->errors()) {
addMessage(msg, "Errors:");
}
foreach (EetMessage *msg, sender->resut()->warnings()) {
addMessage(msg, "Warnings:");
}
return voucher->eetStatus() == Voucher::EET_SENT;
}
void ShopService::setEetOnline(bool online)
{
EetSender::m_online = online;
} }
void ShopService::moveItems(QList<VoucherItemPtr> items, VoucherPtr source, VoucherPtr target) void ShopService::moveItems(QList<VoucherItemPtr> items, VoucherPtr source, VoucherPtr target)

@ -21,7 +21,8 @@ public:
void pay(VoucherPtr voucher); void pay(VoucherPtr voucher);
void moveItems(QList<VoucherItemPtr> items, VoucherPtr source, VoucherPtr target); void moveItems(QList<VoucherItemPtr> items, VoucherPtr source, VoucherPtr target);
void updateRelatedItem(VoucherItem* item, int countAdded); void updateRelatedItem(VoucherItem* item, int countAdded);
void processEet(VoucherPtr voucher); bool processEet(VoucherPtr voucher, QString message);
void setEetOnline(bool online);
QList<VoucherPtr> savedVouchers(); QList<VoucherPtr> savedVouchers();
QList<VoucherPtr> tempVouchers(); QList<VoucherPtr> tempVouchers();
QList<VoucherPtr> paiedVouchers(); QList<VoucherPtr> paiedVouchers();

Loading…
Cancel
Save