UI for load and save receipts.

This commit is contained in:
2016-07-06 21:37:46 +02:00
parent a8f4ad4a04
commit 5e7549d8a6
8 changed files with 110 additions and 12 deletions
+31 -3
View File
@@ -12,9 +12,10 @@
#include <addressbookdata.h>
#include "data/voucher.h"
#include "shopservice.h"
#include "shop-odb.hxx"
ReceiptSaveForm::ReceiptSaveForm(QWidget *parent) :
ReceiptSaveForm::ReceiptSaveForm(QSharedPointer<Voucher> voucher, QWidget *parent) :
QDialog(parent),
ui(new Ui::ReceiptSaveForm)
{
@@ -22,7 +23,7 @@ ReceiptSaveForm::ReceiptSaveForm(QWidget *parent) :
m_voucherModel = new AutoTableModel<Voucher>(this);
Service<Voucher> srv;
m_voucherModel->setData(srv.all());
m_voucherModel->setData(srv.all(QString("status = %1").arg(QString::number(Voucher::NOT_PAID))));
m_voucherModel->setTranslations(Context::instance().plugin("SHOP")->translations());
ui->tabVouchers->setModel(m_voucherModel);
ui->tabVouchers->hideColumn(3);
@@ -50,8 +51,11 @@ ReceiptSaveForm::ReceiptSaveForm(QWidget *parent) :
comboData << ComboData(adb);
}
m_binder.setData(new Voucher);
m_voucher = voucher;
m_binder.setData(m_voucher.data());
m_binder.registerBinding(ui->contact, comboData);
m_binder.registerBinding(ui->name);
m_binder.registerBinding(ui->description);
m_binder.bindToUi();
ui->contact->completer()->setCompletionMode(QCompleter::PopupCompletion);
@@ -102,3 +106,27 @@ void ReceiptSaveForm::on_radioAdd_toggled(bool checked)
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!ui->name->text().isEmpty());
}
}
void ReceiptSaveForm::accept()
{
ShopService srv;
m_binder.bindToData();
if (m_saveAsNew)
{
m_voucher->setStatus(Voucher::NOT_PAID);
srv.updateVoucher(m_voucher);
}
else
{
QSharedPointer<Voucher> voucher = m_voucherModel->itemFromIndex(ui->tabVouchers->currentIndex());
foreach (QSharedPointer<VoucherItem> item, m_voucher->items()) {
voucher->addItem(item);
}
srv.calculate(voucher);
srv.updateVoucher(voucher);
srv.erase(m_voucher);
}
QDialog::accept();
}