Added load receipt functionality.
This commit is contained in:
@@ -65,6 +65,10 @@ void Context::loadPlugins()
|
|||||||
m_plugins.append(plugin);
|
m_plugins.append(plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug() << pluginLoader.errorString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString dbPath = m_settings->value("db/path", "").toString();
|
QString dbPath = m_settings->value("db/path", "").toString();
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ ReceiptLoadForm::ReceiptLoadForm(QWidget *parent) :
|
|||||||
ui->tabVouchers->setColumnWidth(2, 200);
|
ui->tabVouchers->setColumnWidth(2, 200);
|
||||||
|
|
||||||
m_itemModel = new AutoTableModel<VoucherItem>(this);
|
m_itemModel = new AutoTableModel<VoucherItem>(this);
|
||||||
|
m_itemModel->setCheckboxSelect(true);
|
||||||
ui->tabItems->setModel(m_itemModel);
|
ui->tabItems->setModel(m_itemModel);
|
||||||
|
|
||||||
connect(ui->tabVouchers->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](const QModelIndex ¤t, QModelIndex){
|
connect(ui->tabVouchers->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](const QModelIndex ¤t, QModelIndex){
|
||||||
@@ -43,6 +44,16 @@ ReceiptLoadForm::~ReceiptLoadForm()
|
|||||||
delete ui;
|
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)
|
void ReceiptLoadForm::on_lineEdit_textChanged(const QString &text)
|
||||||
{
|
{
|
||||||
QSortFilterProxyModel proxy;
|
QSortFilterProxyModel proxy;
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ class ReceiptLoadForm : public QDialog
|
|||||||
public:
|
public:
|
||||||
explicit ReceiptLoadForm(QWidget *parent = 0);
|
explicit ReceiptLoadForm(QWidget *parent = 0);
|
||||||
~ReceiptLoadForm();
|
~ReceiptLoadForm();
|
||||||
|
QList<VoucherItemPtr> selectedItems();
|
||||||
|
VoucherPtr selectedVoucher();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_lineEdit_textChanged(const QString &text);
|
void on_lineEdit_textChanged(const QString &text);
|
||||||
|
|||||||
@@ -129,6 +129,23 @@ void ShopForm::on_loadButton_clicked()
|
|||||||
{
|
{
|
||||||
ReceiptLoadForm *form = new ReceiptLoadForm(this);
|
ReceiptLoadForm *form = new ReceiptLoadForm(this);
|
||||||
form->setAttribute(Qt::WA_DeleteOnClose);
|
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();
|
form->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,33 @@ void ShopService::pay(VoucherPtr voucher)
|
|||||||
tx.commit();
|
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()
|
QList<VoucherPtr> ShopService::savedVouchers()
|
||||||
{
|
{
|
||||||
return all(QString("status = %1").arg(QString::number(Voucher::NOT_PAID)));
|
return all(QString("status = %1").arg(QString::number(Voucher::NOT_PAID)));
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public:
|
|||||||
void calculateItem(VoucherItemPtr item);
|
void calculateItem(VoucherItemPtr item);
|
||||||
void loadItems(VoucherPtr voucher);
|
void loadItems(VoucherPtr voucher);
|
||||||
void pay(VoucherPtr voucher);
|
void pay(VoucherPtr voucher);
|
||||||
|
void moveItems(QList<VoucherItemPtr> items, VoucherPtr source, VoucherPtr target);
|
||||||
QList<VoucherPtr> savedVouchers();
|
QList<VoucherPtr> savedVouchers();
|
||||||
QList<VoucherPtr> tempVouchers();
|
QList<VoucherPtr> tempVouchers();
|
||||||
QList<VoucherPtr> paiedVouchers();
|
QList<VoucherPtr> paiedVouchers();
|
||||||
|
|||||||
Reference in New Issue
Block a user