Added recalculating receipt on item count changed. Some UI changes.

print
Josef Rokos 9 years ago
parent 726da24de9
commit 9fbf216bba

@ -5,9 +5,16 @@
#include <QString>
#include <QDate>
#include <odb/core.hxx>
#include <QtCore/qglobal.h>
#if defined(ADDRESSBOOK_LIBRARY)
# define ADDRESSBOOKSHARED_EXPORT Q_DECL_EXPORT
#else
# define ADDRESSBOOKSHARED_EXPORT Q_DECL_IMPORT
#endif
#pragma db object
class AddressbookData : public QObject
class ADDRESSBOOKSHARED_EXPORT AddressbookData : public QObject
{
Q_OBJECT
Q_PROPERTY(QString title READ title WRITE setTitle)

@ -44,6 +44,8 @@ bool CommoditySettingsForm::saveRecord()
commodityService.erase(item);
}
return true;
}
void CommoditySettingsForm::on_addCommodityType_clicked()

@ -74,6 +74,11 @@ void Voucher::addItem(QSharedPointer<VoucherItem> item)
m_items.append(item);
}
void Voucher::removeItem(QSharedPointer<VoucherItem> item)
{
m_items.removeOne(item);
}
void Voucher::clearItems()
{
m_items.clear();

@ -56,6 +56,7 @@ public:
void setItems(const QList<QSharedPointer<VoucherItem> > &items);
void addItem(QSharedPointer<VoucherItem> item);
void removeItem(QSharedPointer<VoucherItem> item);
void clearItems();
private:

@ -7,6 +7,7 @@ VoucherItem::VoucherItem(QObject *parent) : QObject(parent)
m_unitPrice = 0;
m_count = 0;
m_refId = 0;
m_vatType = Enums::HIGH;
}
int VoucherItem::id() const
@ -37,6 +38,7 @@ int VoucherItem::count() const
void VoucherItem::setCount(int count)
{
m_count = count;
emit countChanged();
}
QDecDouble VoucherItem::unitPrice() const

@ -14,7 +14,7 @@ class VoucherItem : public QObject
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(int count READ count WRITE setCount)
Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged)
Q_PROPERTY(QDecDouble unitPrice READ unitPrice WRITE setUnitPrice)
Q_PROPERTY(QDecDouble price READ price WRITE setPrice)
Q_PROPERTY(Enums::VatType vatType READ vatType WRITE setVatType)
@ -46,6 +46,9 @@ public:
Enums::VatType vatType() const;
void setVatType(const Enums::VatType &vatType);
signals:
void countChanged();
private:
friend class odb::access;
#pragma db id auto

@ -32,7 +32,11 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="unitPrice"/>
<widget class="QDoubleSpinBox" name="unitPrice">
<property name="maximum">
<double>9999999999.989999771118164</double>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="countLabel">
@ -42,7 +46,11 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="count"/>
<widget class="QSpinBox" name="count">
<property name="maximum">
<number>999999</number>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QDialogButtonBox" name="buttonBox">

@ -16,6 +16,7 @@ ShopForm::ShopForm(QWidget *parent) :
m_itemsModel = new AutoTableModel<VoucherItem>(this);
m_itemsModel->setEditableCols(QList<int>() << 1);
ui->actualReceipt->setModel(m_itemsModel);
ui->actualReceipt->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
}
ShopForm::~ShopForm()
@ -31,6 +32,8 @@ void ShopForm::on_directSale_clicked()
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();
});
form->show();
@ -53,3 +56,25 @@ void ShopForm::on_loadButton_clicked()
ReceiptLoadForm *form = new ReceiptLoadForm;
form->show();
}
void ShopForm::onCountChanged()
{
VoucherItem *item = qobject_cast<VoucherItem*>(sender());
if (item != NULL && item->count() == 0)
{
for (int i = 0; i < m_voucher->items().count(); i++)
{
if (m_voucher->items()[i].data() == item)
{
m_voucher->removeItem(m_voucher->items()[i]);
m_itemsModel->setData(m_voucher->items());
}
}
}
ShopService srv;
srv.calculate(m_voucher);
ui->total->setText(m_voucher->totalPrice().toString());
//if (m_voucher->status())
}

@ -27,6 +27,8 @@ private slots:
void on_loadButton_clicked();
void onCountChanged();
private:
Ui::ShopForm *ui;
QSharedPointer<Voucher> m_voucher;

@ -7,15 +7,42 @@
<x>0</x>
<y>0</y>
<width>959</width>
<height>531</height>
<height>582</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QWidget" name="widget" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QWidget" name="widgetComodity" native="true">
<property name="maximumSize">
<size>
<width>500</width>
<height>16777215</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="commodity">
@ -67,16 +94,48 @@
</widget>
</item>
<item>
<widget class="QWidget" name="widget_2" native="true">
<widget class="QWidget" name="widgetButtons" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="favorites1" native="true">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="directSale">
<widget class="QToolButton" name="directSale">
<property name="text">
<string>Direct Sale</string>
</property>
<property name="icon">
<iconset resource="shoprc.qrc">
<normaloff>:/icons/shop.svg</normaloff>:/icons/shop.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>45</width>
<height>45</height>
</size>
</property>
<property name="shortcut">
<string>Ctrl+D</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
@ -85,6 +144,21 @@
<item>
<widget class="QWidget" name="widget_5" native="true">
<layout class="QGridLayout" name="gridLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<layout class="QGridLayout" name="favorites2"/>
</item>
@ -94,6 +168,21 @@
<item>
<widget class="QWidget" name="widget_6" native="true">
<layout class="QGridLayout" name="gridLayout_5">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<layout class="QGridLayout" name="favorites3"/>
</item>
@ -103,8 +192,11 @@
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_3" native="true">
<widget class="QWidget" name="widgetReceipt" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="receipt">
@ -122,6 +214,19 @@
<item>
<widget class="QWidget" name="widget_7" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="font">
@ -196,6 +301,8 @@
</item>
</layout>
</widget>
<resources/>
<resources>
<include location="shoprc.qrc"/>
</resources>
<connections/>
</ui>

@ -29,9 +29,14 @@ void ShopService::calculate(QSharedPointer<Voucher> voucher)
QDecDouble total;
foreach (QSharedPointer<VoucherItem> item, voucher->items()) {
QDecDouble itemPrice = item->unitPrice() * item->count();
total += itemPrice;
calculateItem(item);
total += item->price();
}
voucher->setTotalPrice(total);
}
void ShopService::calculateItem(QSharedPointer<VoucherItem> item)
{
item->setPrice(item->unitPrice() * item->count());
}

@ -15,6 +15,7 @@ public:
QSharedPointer<Voucher> createVoucher();
void addShopItem(QSharedPointer<Voucher> voucher, QSharedPointer<IShopItem> item, int count);
void calculate(QSharedPointer<Voucher> voucher);
void calculateItem(QSharedPointer<VoucherItem> item);
};
#endif // SHOPSERVICE_H

Loading…
Cancel
Save