This commit is contained in:
2016-08-03 18:32:48 +02:00
13 changed files with 120 additions and 21 deletions
+2 -1
View File
@@ -39,8 +39,9 @@ int VoucherItem::count() const
void VoucherItem::setCount(int count)
{
int oldCount = m_count;
m_count = count;
emit countChanged();
emit countChanged(oldCount);
}
QDecDouble VoucherItem::unitPrice() const
+1 -1
View File
@@ -63,7 +63,7 @@ public:
void setVoucher(const QWeakPointer<Voucher> &voucher);
signals:
void countChanged();
void countChanged(int oldCount);
private:
friend class odb::access;
+2 -2
View File
@@ -11,8 +11,8 @@ class SHOPSHARED_EXPORT ISellableService
public:
ISellableService();
virtual QList<ShopItemPtr> shopItems() = 0;
//virtual void addToReceipt()
virtual QList<QSharedPointer<ShopItem> > shopItems() = 0;
virtual void addedToVoucher(int itemId, int countAdded) = 0;
};
#endif // ISELLABLESERVICE_H
+34 -7
View File
@@ -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 &current, 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();
@@ -149,7 +150,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)
@@ -179,6 +180,12 @@ void ShopForm::onCountChanged()
{
srv.updateVoucher(m_voucher);
}
if (item != NULL)
{
int countAdded = item->count() - oldCount;
srv.updateRelatedItem(item, countAdded);
}
}
void ShopForm::createVoucher()
@@ -241,7 +248,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)));
}
}
@@ -255,6 +262,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())
@@ -303,3 +319,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());
}
+5 -1
View File
@@ -7,6 +7,7 @@
#include <autotablemodel.h>
class ShopItem;
class IShopItem;
namespace Ui {
class ShopForm;
@@ -31,7 +32,7 @@ private slots:
void on_loadButton_clicked();
void onCountChanged();
void onCountChanged(int oldCount);
void on_receiptCombo_currentIndexChanged(int index);
@@ -39,6 +40,8 @@ private slots:
void on_showPaiedButton_clicked();
void on_btnAddItem_clicked();
private:
Ui::ShopForm *ui;
QSharedPointer<Voucher> m_voucher;
@@ -50,6 +53,7 @@ private:
void changeReceipt();
void connectItemSignals();
void createEmptyVoucher();
void addItem(QSharedPointer<IShopItem> item, int count);
};
#endif // SHOPFORM_H
+21 -4
View File
@@ -55,7 +55,14 @@
<widget class="QLineEdit" name="commoditySearch"/>
</item>
<item>
<widget class="QTableView" name="commodityTable"/>
<widget class="QTableView" name="commodityTable">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_8" native="true">
@@ -68,7 +75,7 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox">
<widget class="QSpinBox" name="spnCount">
<property name="wrapping">
<bool>false</bool>
</property>
@@ -78,13 +85,23 @@
<property name="showGroupSeparator" stdset="0">
<bool>false</bool>
</property>
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="btnAddItem">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Add Item</string>
</property>
<property name="icon">
<iconset resource="../core/rc.qrc">
<normaloff>:/icons/new.svg</normaloff>:/icons/new.svg</iconset>
</property>
</widget>
</item>
</layout>
@@ -386,8 +403,8 @@
</layout>
</widget>
<resources>
<include location="shoprc.qrc"/>
<include location="../core/rc.qrc"/>
<include location="shoprc.qrc"/>
</resources>
<connections/>
</ui>
+2
View File
@@ -10,6 +10,7 @@ class SHOPSHARED_EXPORT ShopItem : public QObject, public IShopItem
{
Q_OBJECT
Q_PROPERTY(QString code READ code)
Q_PROPERTY(QString name READ name)
Q_PROPERTY(QDecDouble unitPrice READ unitPrice)
Q_PROPERTY(Enums::VatType vatType READ vatType)
@@ -24,6 +25,7 @@ public slots:
// IShopItem interface
public:
virtual int id() override { return 0; }
virtual QString code() { return ""; }
virtual QString name() override { return ""; }
virtual QDecDouble unitPrice() override { return QDecDouble(); }
virtual Enums::VatType vatType() override { return Enums::NONE; }
+13
View File
@@ -25,6 +25,8 @@ void ShopService::addShopItem(VoucherPtr voucher, QSharedPointer<IShopItem> item
vItem->setVatType(item->vatType());
voucher->addItem(vItem);
updateRelatedItem(vItem.data(), count);
}
void ShopService::calculate(VoucherPtr voucher)
@@ -106,6 +108,17 @@ void ShopService::pay(VoucherPtr voucher)
tx.commit();
}
void ShopService::updateRelatedItem(VoucherItem* item, int countAdded)
{
IPlugin *plugin = Context::instance().plugin(item->itemPlugin());
IService *srv = (plugin != NULL ? plugin->service<IService>() : NULL);
ISellableService *selSrv = dynamic_cast<ISellableService*>(srv);
if (selSrv != NULL)
{
selSrv->addedToVoucher(item->refId(), countAdded);
}
}
void ShopService::moveItems(QList<VoucherItemPtr> items, VoucherPtr source, VoucherPtr target)
{
Transaction tx;
+1
View File
@@ -20,6 +20,7 @@ public:
void loadItems(VoucherPtr voucher);
void pay(VoucherPtr voucher);
void moveItems(QList<VoucherItemPtr> items, VoucherPtr source, VoucherPtr target);
void updateRelatedItem(VoucherItem* item, int countAdded);
QList<VoucherPtr> savedVouchers();
QList<VoucherPtr> tempVouchers();
QList<VoucherPtr> paiedVouchers();