Added sell commodity feature.
This commit is contained in:
+34
-7
@@ -8,6 +8,7 @@
|
||||
#include "receiptgenerator.h"
|
||||
#include "paydialog.h"
|
||||
#include "paydvouchersdialog.h"
|
||||
#include "isellableservice.h"
|
||||
#include <QList>
|
||||
#include <QSharedPointer>
|
||||
#include "shop-odb.hxx"
|
||||
@@ -60,6 +61,10 @@ void ShopForm::loadLast()
|
||||
{
|
||||
m_commodityModel = new AutoTableModel<ShopItem>(this);
|
||||
ui->commodityTable->setModel(m_commodityModel);
|
||||
|
||||
connect(ui->commodityTable->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](const QModelIndex ¤t, const QModelIndex &){
|
||||
ui->btnAddItem->setEnabled(current.isValid());
|
||||
});
|
||||
}
|
||||
|
||||
m_commodityModel->setData(srv.allSellableItems());
|
||||
@@ -93,11 +98,7 @@ void ShopForm::on_directSale_clicked()
|
||||
form->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
connect(form, &QDialog::accepted, [this, form](){
|
||||
ShopService srv;
|
||||
srv.addShopItem(m_voucher, form->shopItem(), ((DirectSaleItem*)form->shopItem().data())->count());
|
||||
this->m_itemsModel->addRow(m_voucher->items()[m_voucher->items().count() - 1]);
|
||||
connect(m_voucher->items()[m_voucher->items().count() - 1].data(), SIGNAL(countChanged()), this, SLOT(onCountChanged()));
|
||||
onCountChanged();
|
||||
addItem(form->shopItem(), ((DirectSaleItem*)form->shopItem().data())->count());
|
||||
});
|
||||
|
||||
form->show();
|
||||
@@ -132,7 +133,7 @@ void ShopForm::on_loadButton_clicked()
|
||||
form->show();
|
||||
}
|
||||
|
||||
void ShopForm::onCountChanged()
|
||||
void ShopForm::onCountChanged(int oldCount)
|
||||
{
|
||||
VoucherItem *item = qobject_cast<VoucherItem*>(sender());
|
||||
if (item != NULL && item->count() == 0)
|
||||
@@ -162,6 +163,12 @@ void ShopForm::onCountChanged()
|
||||
{
|
||||
srv.updateVoucher(m_voucher);
|
||||
}
|
||||
|
||||
if (item != NULL)
|
||||
{
|
||||
int countAdded = item->count() - oldCount;
|
||||
srv.updateRelatedItem(item, countAdded);
|
||||
}
|
||||
}
|
||||
|
||||
void ShopForm::createVoucher()
|
||||
@@ -224,7 +231,7 @@ void ShopForm::changeReceipt()
|
||||
void ShopForm::connectItemSignals()
|
||||
{
|
||||
foreach (QSharedPointer<VoucherItem> item, m_voucher->items()) {
|
||||
connect(item.data(), SIGNAL(countChanged()), this, SLOT(onCountChanged()));
|
||||
connect(item.data(), SIGNAL(countChanged(int)), this, SLOT(onCountChanged(int)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,6 +245,15 @@ void ShopForm::createEmptyVoucher()
|
||||
ui->payButton->setEnabled(false);
|
||||
}
|
||||
|
||||
void ShopForm::addItem(QSharedPointer<IShopItem> item, int count)
|
||||
{
|
||||
ShopService srv;
|
||||
srv.addShopItem(m_voucher, item, count);
|
||||
this->m_itemsModel->addRow(m_voucher->items()[m_voucher->items().count() - 1]);
|
||||
connect(m_voucher->items()[m_voucher->items().count() - 1].data(), SIGNAL(countChanged(int)), this, SLOT(onCountChanged(int)));
|
||||
onCountChanged(0);
|
||||
}
|
||||
|
||||
void ShopForm::on_receiptCombo_currentIndexChanged(int)
|
||||
{
|
||||
if (!m_voucher.isNull() && m_voucher->items().isEmpty())
|
||||
@@ -286,3 +302,14 @@ void ShopForm::on_showPaiedButton_clicked()
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dialog->show();
|
||||
}
|
||||
|
||||
void ShopForm::on_btnAddItem_clicked()
|
||||
{
|
||||
if (m_voucher.isNull())
|
||||
{
|
||||
createVoucher();
|
||||
}
|
||||
|
||||
ShopItemPtr item = m_commodityModel->itemFromIndex(ui->commodityTable->currentIndex());
|
||||
addItem(item, ui->spnCount->value());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user