Added load receipt functionality.

print
Josef Rokos 8 years ago
parent 707e2dbc0b
commit 9e9e1f6dba

@ -65,6 +65,10 @@ void Context::loadPlugins()
m_plugins.append(plugin);
}
}
else
{
qDebug() << pluginLoader.errorString();
}
}
QString dbPath = m_settings->value("db/path", "").toString();

@ -28,6 +28,7 @@ ReceiptLoadForm::ReceiptLoadForm(QWidget *parent) :
ui->tabVouchers->setColumnWidth(2, 200);
m_itemModel = new AutoTableModel<VoucherItem>(this);
m_itemModel->setCheckboxSelect(true);
ui->tabItems->setModel(m_itemModel);
connect(ui->tabVouchers->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](const QModelIndex &current, QModelIndex){
@ -43,6 +44,16 @@ ReceiptLoadForm::~ReceiptLoadForm()
delete ui;
}
QList<VoucherItemPtr> ReceiptLoadForm::selectedItems()
{
return m_itemModel->selectedItems();
}
VoucherPtr ReceiptLoadForm::selectedVoucher()
{
return m_voucherModel->itemFromIndex(ui->tabVouchers->currentIndex());
}
void ReceiptLoadForm::on_lineEdit_textChanged(const QString &text)
{
QSortFilterProxyModel proxy;

@ -16,6 +16,8 @@ class ReceiptLoadForm : public QDialog
public:
explicit ReceiptLoadForm(QWidget *parent = 0);
~ReceiptLoadForm();
QList<VoucherItemPtr> selectedItems();
VoucherPtr selectedVoucher();
private slots:
void on_lineEdit_textChanged(const QString &text);

@ -129,6 +129,23 @@ void ShopForm::on_loadButton_clicked()
{
ReceiptLoadForm *form = new ReceiptLoadForm(this);
form->setAttribute(Qt::WA_DeleteOnClose);
connect(form, &QDialog::accepted, [this, form](){
ShopService srv;
if (m_voucher.isNull())
{
m_voucher = srv.createVoucher();
}
srv.moveItems(form->selectedItems(), form->selectedVoucher(), this->m_voucher);
m_itemsModel->setData(m_voucher->items());
connectItemSignals();
onCountChanged();
});
form->show();
}

@ -106,6 +106,33 @@ void ShopService::pay(VoucherPtr voucher)
tx.commit();
}
void ShopService::moveItems(QList<VoucherItemPtr> items, VoucherPtr source, VoucherPtr target)
{
Transaction tx;
if (target->status() == Voucher::NEW && target->id() == 0)
{
this->saveVoucher(target);
}
odb::database *db = Context::instance().db();
foreach (VoucherItemPtr item, items) {
QString sql = QString("update VoucherItem set voucher = %1 where id = %2").arg(QString::number(target->id()), QString::number(item->id()));
db->execute(sql.toStdString());
}
loadItems(source);
loadItems(target);
if (source->items().isEmpty())
{
erase(source);
}
tx.commit();
}
QList<VoucherPtr> ShopService::savedVouchers()
{
return all(QString("status = %1").arg(QString::number(Voucher::NOT_PAID)));

@ -19,6 +19,7 @@ public:
void calculateItem(VoucherItemPtr item);
void loadItems(VoucherPtr voucher);
void pay(VoucherPtr voucher);
void moveItems(QList<VoucherItemPtr> items, VoucherPtr source, VoucherPtr target);
QList<VoucherPtr> savedVouchers();
QList<VoucherPtr> tempVouchers();
QList<VoucherPtr> paiedVouchers();

Loading…
Cancel
Save