Josef Rokos 9 years ago
commit cf7831c368

@ -17,3 +17,15 @@ QList<QSharedPointer<ShopItem> > CommodityService::shopItems()
return ret;
}
void CommodityService::addedToVoucher(int itemId, int countAdded)
{
QSharedPointer<CommodityData> commodity = loadById(itemId);
if (!commodity.isNull())
{
commodity->setCount(commodity->count() - countAdded);
}
update(commodity);
}

@ -13,6 +13,7 @@ public:
// ISellableService interface
public:
QList<QSharedPointer<ShopItem> > shopItems() override;
void addedToVoucher(int itemId, int countAdded) override;
};
#endif // COMMODITYSERVICE_H

@ -8,7 +8,7 @@ CommodityData::CommodityData(QObject *parent)
m_price = 0;
m_vat = Enums::NONE;
}
int CommodityData::id() const
int CommodityData::id()
{
return m_id;
}
@ -17,7 +17,7 @@ void CommodityData::setId(int id)
{
m_id = id;
}
QString CommodityData::name() const
QString CommodityData::name()
{
return m_name;
}
@ -83,6 +83,21 @@ void CommodityData::setCount(int count)
m_count = count;
}
QDecDouble CommodityData::unitPrice()
{
return price();
}
Enums::VatType CommodityData::vatType()
{
return vat();
}
QString CommodityData::pluginId()
{
return "COMMODITY";
}

@ -14,9 +14,9 @@
class CommodityData : public ShopItem
{
Q_OBJECT
Q_PROPERTY(QString code READ code WRITE setCode)
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(QString shortName READ shortName WRITE setShortName)
Q_PROPERTY(QString code READ code WRITE setCode)
Q_PROPERTY(QSharedPointer<QObject> type READ type WRITE setType)
Q_PROPERTY(QDecDouble price READ price WRITE setPrice)
Q_PROPERTY(Enums::VatType vat READ vat WRITE setVat)
@ -25,10 +25,10 @@ class CommodityData : public ShopItem
public:
CommodityData(QObject *parent = 0);
int id() const;
int id() override;
void setId(int id);
QString name() const;
QString name() override;
void setName(const QString &name);
QString shortName() const;
@ -60,6 +60,12 @@ private:
int m_price;
Enums::VatType m_vat;
int m_count;
// IShopItem interface
public:
QDecDouble unitPrice() override;
Enums::VatType vatType() override;
QString pluginId() override;
};
#endif // COMMODITYDATA_H

@ -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

@ -63,7 +63,7 @@ public:
void setVoucher(const QWeakPointer<Voucher> &voucher);
signals:
void countChanged();
void countChanged(int oldCount);
private:
friend class odb::access;

@ -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

@ -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());
}

@ -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

@ -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>

@ -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; }

@ -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;

@ -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();

Loading…
Cancel
Save