Added recalculating receipt on item count changed. Some UI changes.
This commit is contained in:
@@ -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
|
||||
|
||||
+10
-2
@@ -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;
|
||||
|
||||
+178
-71
@@ -7,57 +7,186 @@
|
||||
<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">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<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="QLabel" name="commodity">
|
||||
<property name="text">
|
||||
<string>Commodity</string>
|
||||
<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">
|
||||
<property name="text">
|
||||
<string>Commodity</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="commoditySearch"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableView" name="commodityTable"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_8" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Count</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox">
|
||||
<property name="wrapping">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="buttonSymbols">
|
||||
<enum>QAbstractSpinBox::UpDownArrows</enum>
|
||||
</property>
|
||||
<property name="showGroupSeparator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Add Item</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="commoditySearch"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableView" name="commodityTable"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_8" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<widget class="QWidget" name="widgetButtons" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Count</string>
|
||||
</property>
|
||||
<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="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>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox">
|
||||
<property name="wrapping">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="buttonSymbols">
|
||||
<enum>QAbstractSpinBox::UpDownArrows</enum>
|
||||
</property>
|
||||
<property name="showGroupSeparator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<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>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Add Item</string>
|
||||
</property>
|
||||
<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>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@@ -67,44 +196,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_2" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="favorites1" native="true">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="directSale">
|
||||
<property name="text">
|
||||
<string>Direct Sale</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_5" native="true">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="favorites2"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_6" native="true">
|
||||
<layout class="QGridLayout" name="gridLayout_5">
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="favorites3"/>
|
||||
</item>
|
||||
</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
|
||||
|
||||
Reference in New Issue
Block a user