diff --git a/shop/receiptsaveform.cpp b/shop/receiptsaveform.cpp index 8106eb4..a2dc864 100644 --- a/shop/receiptsaveform.cpp +++ b/shop/receiptsaveform.cpp @@ -45,7 +45,7 @@ ReceiptSaveForm::ReceiptSaveForm(QSharedPointer voucher, QWidget *paren ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty()); }); - m_binder.setData(new Voucher); + m_binder.setData(voucher.data()); AddressBookService srvAdb; m_binder.registerBinding(ui->contact, ComboData::createComboData(srvAdb.all())); m_binder.registerBinding(ui->name); @@ -66,6 +66,21 @@ ReceiptSaveForm::~ReceiptSaveForm() 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) { QSortFilterProxyModel proxy; diff --git a/shop/receiptsaveform.h b/shop/receiptsaveform.h index 663f3c4..09e6175 100644 --- a/shop/receiptsaveform.h +++ b/shop/receiptsaveform.h @@ -18,6 +18,9 @@ public: explicit ReceiptSaveForm(QSharedPointer voucher, QWidget *parent = 0); ~ReceiptSaveForm(); + VoucherPtr selectedVoucher(); + bool saveAsNew(); + private slots: void on_lineEdit_textChanged(const QString &text); @@ -28,7 +31,7 @@ private: ObjectBinder m_binder; AutoTableModel *m_voucherModel; bool m_saveAsNew; - QSharedPointer m_voucher; + VoucherPtr m_voucher; // QDialog interface public slots: diff --git a/shop/shopform.cpp b/shop/shopform.cpp index 9e5674c..1ed3c1f 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -54,9 +54,13 @@ void ShopForm::loadLast() connectItemSignals(); ui->total->setText(QString::number(m_voucher->totalPrice().toDouble(), 'f', 2)); - ui->temporarySaveButton->setEnabled(true); - ui->saveButton->setEnabled(true); - ui->payButton->setEnabled(true); + + if (!m_voucher->items().isEmpty()) + { + ui->temporarySaveButton->setEnabled(true); + ui->saveButton->setEnabled(true); + ui->payButton->setEnabled(true); + } } if (m_commodityModel == NULL) @@ -119,13 +123,25 @@ void ShopForm::on_saveButton_clicked() ReceiptSaveForm *form = new ReceiptSaveForm(m_voucher, this); form->setAttribute(Qt::WA_DeleteOnClose); - connect(form, &QDialog::accepted, [this]() { + connect(form, &QDialog::accepted, [this, form]() { ShopService srv; - m_voucher->setStatus(Voucher::NOT_PAID); - srv.saveVoucher(m_voucher); - m_voucher = srv.createVoucher(); + + if (form->saveAsNew()) + { + m_voucher->setStatus(Voucher::NOT_PAID); + srv.saveVoucher(m_voucher); + 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()); - ui->total->setText("0"); }); form->show(); @@ -306,7 +322,13 @@ void ShopForm::on_payButton_clicked() connect(dialog, &QDialog::accepted, [this](){ ShopService srv; srv.pay(m_voucher); - srv.processEet(m_voucher); + QString eetMsg; + bool eetRet = srv.processEet(m_voucher, eetMsg); + + if (!eetRet) + { + + } ReceiptGenerator generator; generator.setVoucher(m_voucher); diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index 8d719e0..5055c4d 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -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) { - return; + return true; } SettingsService srvSettings("SHOP"); @@ -157,11 +157,12 @@ void ShopService::processEet(VoucherPtr voucher) connect(sender, &EetSender::sendFinished, [this, voucher, sender, &loop](){ Transaction tx; + voucher->setEetBkp(sender->resut()->bkp()); + voucher->setEetPkp(sender->resut()->pkp()); + voucher->setEetFik(sender->resut()->fik()); + 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); } @@ -179,6 +180,30 @@ void ShopService::processEet(VoucherPtr voucher) sender->sendRequest(&request); 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 items, VoucherPtr source, VoucherPtr target) diff --git a/shop/shopservice.h b/shop/shopservice.h index 55e6189..29e58c7 100644 --- a/shop/shopservice.h +++ b/shop/shopservice.h @@ -21,7 +21,8 @@ public: void pay(VoucherPtr voucher); void moveItems(QList items, VoucherPtr source, VoucherPtr target); void updateRelatedItem(VoucherItem* item, int countAdded); - void processEet(VoucherPtr voucher); + bool processEet(VoucherPtr voucher, QString message); + void setEetOnline(bool online); QList savedVouchers(); QList tempVouchers(); QList paiedVouchers();