From 9fbf216bba551234b76a836d5a00cda7fdc87b03 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Thu, 26 May 2016 15:11:55 +0200 Subject: [PATCH 1/3] Added recalculating receipt on item count changed. Some UI changes. --- addressbook/data/addressbookdata.h | 9 +- commodity/commoditysettingsform.cpp | 2 + shop/data/voucher.cpp | 5 + shop/data/voucher.h | 1 + shop/data/voucheritem.cpp | 2 + shop/data/voucheritem.h | 5 +- shop/directsaleform.ui | 12 +- shop/shopform.cpp | 25 +++ shop/shopform.h | 2 + shop/shopform.ui | 237 ++++++++++++++++++++-------- shop/shopservice.cpp | 9 +- shop/shopservice.h | 1 + 12 files changed, 239 insertions(+), 71 deletions(-) diff --git a/addressbook/data/addressbookdata.h b/addressbook/data/addressbookdata.h index cc0f2b8..bcfc735 100644 --- a/addressbook/data/addressbookdata.h +++ b/addressbook/data/addressbookdata.h @@ -5,9 +5,16 @@ #include #include #include +#include + +#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) diff --git a/commodity/commoditysettingsform.cpp b/commodity/commoditysettingsform.cpp index a17e072..ea25466 100644 --- a/commodity/commoditysettingsform.cpp +++ b/commodity/commoditysettingsform.cpp @@ -44,6 +44,8 @@ bool CommoditySettingsForm::saveRecord() commodityService.erase(item); } + + return true; } void CommoditySettingsForm::on_addCommodityType_clicked() diff --git a/shop/data/voucher.cpp b/shop/data/voucher.cpp index 83f64b0..113a592 100644 --- a/shop/data/voucher.cpp +++ b/shop/data/voucher.cpp @@ -74,6 +74,11 @@ void Voucher::addItem(QSharedPointer item) m_items.append(item); } +void Voucher::removeItem(QSharedPointer item) +{ + m_items.removeOne(item); +} + void Voucher::clearItems() { m_items.clear(); diff --git a/shop/data/voucher.h b/shop/data/voucher.h index db4e380..b6b13b1 100644 --- a/shop/data/voucher.h +++ b/shop/data/voucher.h @@ -56,6 +56,7 @@ public: void setItems(const QList > &items); void addItem(QSharedPointer item); + void removeItem(QSharedPointer item); void clearItems(); private: diff --git a/shop/data/voucheritem.cpp b/shop/data/voucheritem.cpp index 3129b58..d0615e8 100644 --- a/shop/data/voucheritem.cpp +++ b/shop/data/voucheritem.cpp @@ -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 diff --git a/shop/data/voucheritem.h b/shop/data/voucheritem.h index 0457c57..29a5684 100644 --- a/shop/data/voucheritem.h +++ b/shop/data/voucheritem.h @@ -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 diff --git a/shop/directsaleform.ui b/shop/directsaleform.ui index 952f906..77cf8eb 100644 --- a/shop/directsaleform.ui +++ b/shop/directsaleform.ui @@ -32,7 +32,11 @@ - + + + 9999999999.989999771118164 + + @@ -42,7 +46,11 @@ - + + + 999999 + + diff --git a/shop/shopform.cpp b/shop/shopform.cpp index 5072dfb..497391f 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -16,6 +16,7 @@ ShopForm::ShopForm(QWidget *parent) : m_itemsModel = new AutoTableModel(this); m_itemsModel->setEditableCols(QList() << 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(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()) +} diff --git a/shop/shopform.h b/shop/shopform.h index e62453b..4e94ffa 100644 --- a/shop/shopform.h +++ b/shop/shopform.h @@ -27,6 +27,8 @@ private slots: void on_loadButton_clicked(); + void onCountChanged(); + private: Ui::ShopForm *ui; QSharedPointer m_voucher; diff --git a/shop/shopform.ui b/shop/shopform.ui index f02cb6d..2a2ebd2 100644 --- a/shop/shopform.ui +++ b/shop/shopform.ui @@ -7,95 +7,187 @@ 0 0 959 - 531 + 582 Form - + - + + + 0 + 100 + + + + + 0 + + + 0 + + + 0 + + + 0 + - - - Commodity + + + + 500 + 16777215 + - - - - - - - - - - - + - + - Count + Commodity - - - false - - - QAbstractSpinBox::UpDownArrows - - - false - - + - - - Add Item - + + + + + + + + + Count + + + + + + + false + + + QAbstractSpinBox::UpDownArrows + + + false + + + + + + + Add Item + + + + - - - - - - - - - - - - Direct Sale - + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Direct Sale + + + + :/icons/shop.svg:/icons/shop.svg + + + + 45 + 45 + + + + Ctrl+D + + + Qt::ToolButtonTextUnderIcon + + + true + + + + - - - - - - - - + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + - - - - - - - - + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + @@ -104,7 +196,7 @@ - + @@ -122,6 +214,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -196,6 +301,8 @@ - + + + diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index 3441ef3..57e618f 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -29,9 +29,14 @@ void ShopService::calculate(QSharedPointer voucher) QDecDouble total; foreach (QSharedPointer item, voucher->items()) { - QDecDouble itemPrice = item->unitPrice() * item->count(); - total += itemPrice; + calculateItem(item); + total += item->price(); } voucher->setTotalPrice(total); } + +void ShopService::calculateItem(QSharedPointer item) +{ + item->setPrice(item->unitPrice() * item->count()); +} diff --git a/shop/shopservice.h b/shop/shopservice.h index 77212f7..6bcb841 100644 --- a/shop/shopservice.h +++ b/shop/shopservice.h @@ -15,6 +15,7 @@ public: QSharedPointer createVoucher(); void addShopItem(QSharedPointer voucher, QSharedPointer item, int count); void calculate(QSharedPointer voucher); + void calculateItem(QSharedPointer item); }; #endif // SHOPSERVICE_H From 7b9bc06c52de3de5f57399d568ae25e491371308 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Thu, 26 May 2016 16:30:45 +0200 Subject: [PATCH 2/3] Data structures prepared for VAT. --- commodity/data/commoditydata.cpp | 1 + core/enums.h | 8 +++++++- core/settings/globalsettings.cpp | 34 ++++++++++++++++++++++++++++++++ core/settings/globalsettings.h | 16 +++++++++++++++ shop/data/voucheritem.cpp | 2 +- shop/directsaleitem.cpp | 11 +++++++++++ shop/directsaleitem.h | 4 ++++ shop/ishopitem.h | 2 ++ shop/shopservice.cpp | 1 + 9 files changed, 77 insertions(+), 2 deletions(-) diff --git a/commodity/data/commoditydata.cpp b/commodity/data/commoditydata.cpp index 09ce104..b0b9769 100644 --- a/commodity/data/commoditydata.cpp +++ b/commodity/data/commoditydata.cpp @@ -6,6 +6,7 @@ CommodityData::CommodityData(QObject *parent) { m_count = 0; m_price = 0; + m_vat = Enums::NONE; } int CommodityData::id() const { diff --git a/core/enums.h b/core/enums.h index e41e5de..65adf26 100644 --- a/core/enums.h +++ b/core/enums.h @@ -11,7 +11,13 @@ class CORESHARED_EXPORT Enums : public QObject Q_ENUMS(VatType) public: - enum VatType { HIGH,FIRST_LOWER,SECOND_LOWER }; + enum VatType + { + NONE, + HIGH, + FIRST_LOWER, + SECOND_LOWER + }; Enums() { diff --git a/core/settings/globalsettings.cpp b/core/settings/globalsettings.cpp index c2cf97d..9256782 100644 --- a/core/settings/globalsettings.cpp +++ b/core/settings/globalsettings.cpp @@ -1,8 +1,12 @@ #include "globalsettings.h" +#include GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent) { m_ic = 0; + m_vatHigh = 0; + m_vatFirstLower = 0; + m_vatSecondLower = 0; } QString GlobalSettings::firmName() const @@ -94,3 +98,33 @@ void GlobalSettings::setLogoPath(const QString &logoPath) { m_logoPath = logoPath; } +QDecDouble GlobalSettings::vatHigh() const +{ + return TO_DEC(m_vatHigh); +} + +void GlobalSettings::setVatHigh(QDecDouble vatHigh) +{ + m_vatHigh = FROM_DEC(vatHigh); +} +QDecDouble GlobalSettings::vatFirstLower() const +{ + return TO_DEC(m_vatFirstLower); +} + +void GlobalSettings::setVatFirstLower(QDecDouble vatFirstLower) +{ + m_vatFirstLower = FROM_DEC(vatFirstLower); +} +QDecDouble GlobalSettings::vatSecondLower() const +{ + return TO_DEC(m_vatSecondLower); +} + +void GlobalSettings::setVatSecondLower(QDecDouble vatSecondLower) +{ + m_vatSecondLower = FROM_DEC(vatSecondLower); +} + + + diff --git a/core/settings/globalsettings.h b/core/settings/globalsettings.h index 2a6425e..e4a2051 100644 --- a/core/settings/globalsettings.h +++ b/core/settings/globalsettings.h @@ -3,6 +3,7 @@ #include #include +#include class GlobalSettings : public QObject { @@ -17,6 +18,9 @@ class GlobalSettings : public QObject Q_PROPERTY(QString dic READ dic WRITE setDic) Q_PROPERTY(bool vatPayer READ vatPayer WRITE setVatPayer) Q_PROPERTY(QString logoPath READ logoPath WRITE setLogoPath) + Q_PROPERTY(QDecDouble vatHigh READ vatHigh WRITE setVatHigh) + Q_PROPERTY(QDecDouble vatFirstLower READ vatFirstLower WRITE setVatFirstLower) + Q_PROPERTY(QDecDouble vatSecondLower READ vatSecondLower WRITE setVatSecondLower) public: explicit GlobalSettings(QObject *parent = 0); @@ -47,6 +51,15 @@ public: QString logoPath() const; void setLogoPath(const QString &logoPath); + QDecDouble vatHigh() const; + void setVatHigh(QDecDouble vatHigh); + + QDecDouble vatFirstLower() const; + void setVatFirstLower(QDecDouble vatFirstLower); + + QDecDouble vatSecondLower() const; + void setVatSecondLower(QDecDouble vatSecondLower); + private: QString m_firmName; QString m_street; @@ -57,6 +70,9 @@ private: QString m_dic; bool m_vatPayer; QString m_logoPath; + int m_vatHigh; + int m_vatFirstLower; + int m_vatSecondLower; signals: diff --git a/shop/data/voucheritem.cpp b/shop/data/voucheritem.cpp index d0615e8..bc92ac5 100644 --- a/shop/data/voucheritem.cpp +++ b/shop/data/voucheritem.cpp @@ -7,7 +7,7 @@ VoucherItem::VoucherItem(QObject *parent) : QObject(parent) m_unitPrice = 0; m_count = 0; m_refId = 0; - m_vatType = Enums::HIGH; + m_vatType = Enums::NONE; } int VoucherItem::id() const diff --git a/shop/directsaleitem.cpp b/shop/directsaleitem.cpp index f08bdde..615d6c1 100644 --- a/shop/directsaleitem.cpp +++ b/shop/directsaleitem.cpp @@ -3,6 +3,7 @@ DirectSaleItem::DirectSaleItem(QObject *parent) : QObject(parent) { m_count = 1; + m_vat = Enums::NONE; } int DirectSaleItem::id() @@ -25,6 +26,11 @@ QString DirectSaleItem::pluginId() return ""; } +Enums::VatType DirectSaleItem::vatType() +{ + return m_vat; +} + int DirectSaleItem::count() const { return m_count; @@ -44,3 +50,8 @@ void DirectSaleItem::setUnitPrice(const QDecDouble &unitPrice) { m_unitPrice = unitPrice; } + +void DirectSaleItem::setVatType(Enums::VatType vat) +{ + m_vat = vat; +} diff --git a/shop/directsaleitem.h b/shop/directsaleitem.h index 243ec5d..25aac87 100644 --- a/shop/directsaleitem.h +++ b/shop/directsaleitem.h @@ -25,6 +25,7 @@ public: QString name() override; QDecDouble unitPrice() override; QString pluginId() override; + Enums::VatType vatType() override; int count() const; void setCount(int count); @@ -33,10 +34,13 @@ public: void setUnitPrice(const QDecDouble &unitPrice); + void setVatType(Enums::VatType vatType); + private: QString m_name; QDecDouble m_unitPrice; int m_count; + Enums::VatType m_vat; }; #endif // DIRECTSALEITEM_H diff --git a/shop/ishopitem.h b/shop/ishopitem.h index 5a9c799..81c753f 100644 --- a/shop/ishopitem.h +++ b/shop/ishopitem.h @@ -4,6 +4,7 @@ #include "shop_global.h" #include #include +#include class SHOPSHARED_EXPORT IShopItem { @@ -12,6 +13,7 @@ public: virtual int id() = 0; virtual QString name() = 0; virtual QDecDouble unitPrice() = 0; + virtual Enums::VatType vatType() = 0; virtual QString pluginId() = 0; }; diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index 57e618f..ac9f4de 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -20,6 +20,7 @@ void ShopService::addShopItem(QSharedPointer voucher, QSharedPointersetCount(count); vItem->setRefId(item->id()); vItem->setItemPlugin(item->pluginId()); + vItem->setVatType(item->vatType()); voucher->addItem(vItem); } From 4ebfae307a0375da55164bfc3fe5fef0686ca414 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Fri, 27 May 2016 16:47:40 +0200 Subject: [PATCH 3/3] Added support for VAT calculations. --- commodity/commodityform.cpp | 9 +- core/context.cpp | 4 +- core/data/system.h | 3 +- core/settings/globalsettings.h | 3 +- core/settings/globalsettingsform.cpp | 9 ++ core/settings/globalsettingsform.h | 2 + core/settings/globalsettingsform.ui | 64 +++++++++++++- core/settingsservice.h | 17 +++- services/accserviceform.cpp | 7 +- shop/data/voucher.cpp | 127 ++++++++++++++++++++++++++- shop/data/voucher.h | 54 ++++++++++++ shop/data/voucheritem.cpp | 27 ++++++ shop/data/voucheritem.h | 14 ++- shop/directsaleform.cpp | 8 ++ shop/directsaleform.ui | 12 ++- shop/directsaleitem.h | 1 + shop/shop.json | 84 ++++++++++-------- shop/shopform.cpp | 21 +++-- shop/shopform.h | 2 + shop/shopform.ui | 4 +- shop/shopservice.cpp | 79 ++++++++++++++++- shop/shopservice.h | 8 ++ 22 files changed, 500 insertions(+), 59 deletions(-) diff --git a/commodity/commodityform.cpp b/commodity/commodityform.cpp index eac189c..7daacdd 100644 --- a/commodity/commodityform.cpp +++ b/commodity/commodityform.cpp @@ -14,9 +14,12 @@ CommodityForm::CommodityForm(QWidget *parent) : registerBinding(ui->shortName); registerBinding(ui->code); registerBinding(ui->price); - QList vt ; - vt << ComboData(Enums::HIGH,tr("High")) << ComboData(Enums::FIRST_LOWER,tr("First Lower")) << ComboData(Enums::SECOND_LOWER,tr("Second Lower")); - registerBinding(ui->vat,vt); + QList vt; + vt << ComboData(Enums::NONE,tr("None")) + << ComboData(Enums::HIGH,tr("High")) + << ComboData(Enums::FIRST_LOWER,tr("First Lower")) + << ComboData(Enums::SECOND_LOWER,tr("Second Lower")); + registerBinding(ui->vat, vt); registerBinding(ui->count); } diff --git a/core/context.cpp b/core/context.cpp index be5c917..961933b 100644 --- a/core/context.cpp +++ b/core/context.cpp @@ -50,7 +50,7 @@ void Context::loadPlugins() m_plugins.append(new Users); m_plugins.append(new Roles); - QDir pluginsDir(qApp->applicationDirPath() + "/../plugins"); + QDir pluginsDir(qApp->applicationDirPath() + "/../../plugins"); foreach (QString fileName, pluginsDir.entryList(QStringList() << "*.so" << "*.dll")) { QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName)); @@ -144,7 +144,7 @@ void Context::checkDb(const QString &path) db.open(); QSqlQuery q(db); QString verSql = "SELECT pluginId, schemaVersion FROM system"; - QString createSysSql = "CREATE TABLE \"system\" (\"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, \"pluginId\" TEXT NULL, \"schemaVersion\" TEXT NULL)"; + QString createSysSql = "CREATE TABLE \"system\" (\"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, \"pluginId\" TEXT NULL, \"schemaVersion\" TEXT NULL, \"settings\" TEXT NULL)"; if (q.exec(verSql)) { diff --git a/core/data/system.h b/core/data/system.h index 20ce5b5..a8e8ef9 100644 --- a/core/data/system.h +++ b/core/data/system.h @@ -1,12 +1,13 @@ #ifndef SYSTEM_H #define SYSTEM_H +#include "core_global.h" #include #include #pragma db object -class System +class CORESHARED_EXPORT System { public: System(); diff --git a/core/settings/globalsettings.h b/core/settings/globalsettings.h index e4a2051..9c782a3 100644 --- a/core/settings/globalsettings.h +++ b/core/settings/globalsettings.h @@ -4,8 +4,9 @@ #include #include #include +#include "../core_global.h" -class GlobalSettings : public QObject +class CORESHARED_EXPORT GlobalSettings : public QObject { Q_OBJECT diff --git a/core/settings/globalsettingsform.cpp b/core/settings/globalsettingsform.cpp index 70e7cc3..3aab7c6 100644 --- a/core/settings/globalsettingsform.cpp +++ b/core/settings/globalsettingsform.cpp @@ -18,6 +18,9 @@ GlobalSettingsForm::GlobalSettingsForm(QWidget *parent) : registerBinding(ui->ic); registerBinding(ui->vatPayer); registerBinding(ui->dic); + registerBinding(ui->vatHigh); + registerBinding(ui->vatFirstLower); + registerBinding(ui->vatSecondLower); } GlobalSettingsForm::~GlobalSettingsForm() @@ -39,4 +42,10 @@ void GlobalSettingsForm::loadEntity() SettingsService srv("CORE"); QSharedPointer settings = srv.loadSettings(); setEntity(settings); + ui->grpVat->setEnabled(settings->vatPayer()); +} + +void GlobalSettingsForm::on_vatPayer_toggled(bool checked) +{ + ui->grpVat->setEnabled(checked); } diff --git a/core/settings/globalsettingsform.h b/core/settings/globalsettingsform.h index 472d240..e355b3f 100644 --- a/core/settings/globalsettingsform.h +++ b/core/settings/globalsettingsform.h @@ -27,6 +27,8 @@ public slots: // IForm interface public: void loadEntity() override; +private slots: + void on_vatPayer_toggled(bool checked); }; #endif // GLOBALSETTINGSFORM_H diff --git a/core/settings/globalsettingsform.ui b/core/settings/globalsettingsform.ui index 859592e..5a87665 100644 --- a/core/settings/globalsettingsform.ui +++ b/core/settings/globalsettingsform.ui @@ -6,8 +6,8 @@ 0 0 - 422 - 323 + 586 + 419 @@ -20,6 +20,9 @@ Company info + + QFormLayout::AllNonFixedFieldsGrow + @@ -47,6 +50,63 @@ + + + + + 0 + 0 + + + + VAT rates + + + + + + High + + + + + + + QAbstractSpinBox::NoButtons + + + + + + + First lower + + + + + + + QAbstractSpinBox::NoButtons + + + + + + + Second lower + + + + + + + QAbstractSpinBox::NoButtons + + + + + + diff --git a/core/settingsservice.h b/core/settingsservice.h index 3f137e9..15aa258 100644 --- a/core/settingsservice.h +++ b/core/settingsservice.h @@ -7,6 +7,8 @@ #include #include +#include + #include "data/system.h" #include "service.h" #include "core_global.h" @@ -43,6 +45,12 @@ public: const char *propName = objSettings->metaObject()->property(i).name(); QJsonValue v = val.toObject()[propName]; QVariant varVal = v.toVariant(); + + if (objSettings->property(propName).canConvert()) + { + QDecDouble dec(TO_DEC(varVal.toInt())); + varVal = QVariant::fromValue(dec); + } objSettings->setProperty(propName, varVal); } @@ -59,7 +67,14 @@ public: for (int i = 0; i < objSettingsQo->metaObject()->propertyCount(); i++) { const char *propName = objSettings->metaObject()->property(i).name(); - jsonObj[propName] = QJsonValue::fromVariant(objSettingsQo->property(propName)); + QVariant val = objSettingsQo->property(propName); + if (val.canConvert()) + { + int vat = FROM_DEC(val.value()); + val = QVariant::fromValue(vat); + } + + jsonObj[propName] = QJsonValue::fromVariant(val); } QJsonObject jsonSettings; diff --git a/services/accserviceform.cpp b/services/accserviceform.cpp index 65f8bc3..cc9ab39 100644 --- a/services/accserviceform.cpp +++ b/services/accserviceform.cpp @@ -18,8 +18,11 @@ AccServiceForm::AccServiceForm(QWidget *parent) : cd << ComboData(AccService::CAR,tr("Car")) << ComboData(AccService::TENT,tr("Tent")) << ComboData(AccService::OTHER,tr("OTHER")); registerBinding(ui->serviceType,cd); QList vt ; - vt << ComboData(Enums::HIGH,tr("High")) << ComboData(Enums::FIRST_LOWER,tr("First Lower")) << ComboData(Enums::SECOND_LOWER,tr("Second Lower")); - registerBinding(ui->vatType,vt); + vt << ComboData(Enums::NONE,tr("None")) + << ComboData(Enums::HIGH,tr("High")) + << ComboData(Enums::FIRST_LOWER,tr("First Lower")) + << ComboData(Enums::SECOND_LOWER,tr("Second Lower")); + registerBinding(ui->vatType, vt); } diff --git a/shop/data/voucher.cpp b/shop/data/voucher.cpp index 113a592..0b8bb27 100644 --- a/shop/data/voucher.cpp +++ b/shop/data/voucher.cpp @@ -3,7 +3,18 @@ Voucher::Voucher(QObject *parent) : QObject(parent) { - + m_vatRateHigh = 0; + m_vatRateFirstLower = 0; + m_vatRateSecondLower = 0; + m_priceNoVat = 0; + m_priceVatHigh = 0; + m_priceVatFirstLower = 0; + m_priceVatSecondLower = 0; + m_priceWitouthVat = 0; + m_totalPriceVatHigh = 0; + m_totalPriceVatFirstLower = 0; + m_totalPriceVatSecondLower = 0; + m_totalPrice = 0; } QString Voucher::name() const @@ -83,6 +94,120 @@ void Voucher::clearItems() { m_items.clear(); } +QDecDouble Voucher::vatRateHigh() const +{ + return TO_DEC(m_vatRateHigh); +} + +void Voucher::setVatRateHigh(QDecDouble vatRateHigh) +{ + m_vatRateHigh = FROM_DEC(vatRateHigh); +} +QDecDouble Voucher::vatRateFirstLower() const +{ + return TO_DEC(m_vatRateFirstLower); +} + +void Voucher::setVatRateFirstLower(QDecDouble vatRateFirstLower) +{ + m_vatRateFirstLower = FROM_DEC(vatRateFirstLower); +} +QDecDouble Voucher::vatRateSecondLower() const +{ + return TO_DEC(m_vatRateSecondLower); +} + +void Voucher::setVatRateSecondLower(QDecDouble vatRateSecondLower) +{ + m_vatRateSecondLower = FROM_DEC(vatRateSecondLower); +} +QDecDouble Voucher::priceVatHigh() const +{ + return TO_DEC(m_priceVatHigh); +} + +void Voucher::setPriceVatHigh(QDecDouble priceVatHigh) +{ + m_priceVatHigh = FROM_DEC(priceVatHigh); +} +QDecDouble Voucher::priceVatFirstLower() const +{ + return TO_DEC(m_priceVatFirstLower); +} + +void Voucher::setPriceVatFirstLower(QDecDouble priceVatFirstLower) +{ + m_priceVatFirstLower = FROM_DEC(priceVatFirstLower); +} +QDecDouble Voucher::priceVatSecondLower() const +{ + return TO_DEC(m_priceVatSecondLower); +} + +void Voucher::setPriceVatSecondLower(QDecDouble priceVatSecondLower) +{ + m_priceVatSecondLower = FROM_DEC(priceVatSecondLower); +} +QDecDouble Voucher::priceNoVat() const +{ + return TO_DEC(m_priceNoVat); +} + +void Voucher::setPriceNoVat(QDecDouble priceNoVat) +{ + m_priceNoVat = FROM_DEC(priceNoVat); +} +QDecDouble Voucher::priceWitouthVat() const +{ + return TO_DEC(m_priceWitouthVat); +} + +void Voucher::setPriceWitouthVat(QDecDouble priceWitouthVat) +{ + m_priceWitouthVat = FROM_DEC(priceWitouthVat); +} +QDecDouble Voucher::totalPriceVatHigh() const +{ + return TO_DEC(m_totalPriceVatHigh); +} + +void Voucher::setTotalPriceVatHigh(QDecDouble totalPriceVatHigh) +{ + m_totalPriceVatHigh = FROM_DEC(totalPriceVatHigh); +} +QDecDouble Voucher::totalPriceVatFirstLower() const +{ + return TO_DEC(m_totalPriceVatFirstLower); +} + +void Voucher::setTotalPriceVatFirstLower(QDecDouble totalPriceVatFirstLower) +{ + m_totalPriceVatFirstLower = FROM_DEC(totalPriceVatFirstLower); +} +QDecDouble Voucher::totalPriceVatSecondLower() const +{ + return TO_DEC(m_totalPriceVatSecondLower); +} + +void Voucher::setTotalPriceVatSecondLower(QDecDouble totalPriceVatSecondLower) +{ + m_totalPriceVatSecondLower = FROM_DEC(totalPriceVatSecondLower); +} + +QDecDouble Voucher::vatAmountHigh() +{ + return m_totalPriceVatHigh - m_priceVatHigh; +} + +QDecDouble Voucher::vatAmountFirstLower() +{ + return m_totalPriceVatFirstLower - m_priceVatFirstLower; +} + +QDecDouble Voucher::VatAmountSecondLower() +{ + return m_totalPriceVatSecondLower - m_priceVatSecondLower; +} int Voucher::id() const { diff --git a/shop/data/voucher.h b/shop/data/voucher.h index b6b13b1..d549ff9 100644 --- a/shop/data/voucher.h +++ b/shop/data/voucher.h @@ -19,6 +19,12 @@ class Voucher : public QObject Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QString description READ description WRITE setDescription) Q_PROPERTY(QSharedPointer contact READ contact WRITE setContact) + Q_PROPERTY(QDecDouble vatRateHigh READ vatRateHigh WRITE setVatRateHigh) + Q_PROPERTY(QDecDouble vatRateFirstLower READ vatRateFirstLower WRITE setVatRateFirstLower) + Q_PROPERTY(QDecDouble vatRateSecondLower READ vatRateSecondLower WRITE setVatRateSecondLower) + Q_PROPERTY(QDecDouble priceVatHigh READ priceVatHigh WRITE setPriceVatHigh) + Q_PROPERTY(QDecDouble priceVatFirstLower READ priceVatFirstLower WRITE setPriceVatFirstLower) + Q_PROPERTY(QDecDouble priceVatSecondLower READ priceVatSecondLower WRITE setPriceVatSecondLower) Q_PROPERTY(QDecDouble totalPrice READ totalPrice WRITE setTotalPrice) Q_ENUMS(VoucherStatus) Q_PROPERTY(VoucherStatus status READ status WRITE setStatus) @@ -59,6 +65,43 @@ public: void removeItem(QSharedPointer item); void clearItems(); + QDecDouble vatRateHigh() const; + void setVatRateHigh(QDecDouble vatRateHigh); + + QDecDouble vatRateFirstLower() const; + void setVatRateFirstLower(QDecDouble vatRateFirstLower); + + QDecDouble vatRateSecondLower() const; + void setVatRateSecondLower(QDecDouble vatRateSecondLower); + + QDecDouble priceVatHigh() const; + void setPriceVatHigh(QDecDouble priceVatHigh); + + QDecDouble priceVatFirstLower() const; + void setPriceVatFirstLower(QDecDouble priceVatFirstLower); + + QDecDouble priceVatSecondLower() const; + void setPriceVatSecondLower(QDecDouble priceVatSecondLower); + + QDecDouble priceNoVat() const; + void setPriceNoVat(QDecDouble priceNoVat); + + QDecDouble priceWitouthVat() const; + void setPriceWitouthVat(QDecDouble priceWitouthVat); + + QDecDouble totalPriceVatHigh() const; + void setTotalPriceVatHigh(QDecDouble totalPriceVatHigh); + + QDecDouble totalPriceVatFirstLower() const; + void setTotalPriceVatFirstLower(QDecDouble totalPriceVatFirstLower); + + QDecDouble totalPriceVatSecondLower() const; + void setTotalPriceVatSecondLower(QDecDouble totalPriceVatSecondLower); + + QDecDouble vatAmountHigh(); + QDecDouble vatAmountFirstLower(); + QDecDouble VatAmountSecondLower(); + private: friend class odb::access; #pragma db id auto @@ -66,6 +109,17 @@ private: QString m_name; QString m_description; QSharedPointer m_contact; + int m_vatRateHigh; + int m_vatRateFirstLower; + int m_vatRateSecondLower; + int m_priceNoVat; + int m_priceVatHigh; + int m_priceVatFirstLower; + int m_priceVatSecondLower; + int m_priceWitouthVat; + int m_totalPriceVatHigh; + int m_totalPriceVatFirstLower; + int m_totalPriceVatSecondLower; int m_totalPrice; QOdbList > m_items; VoucherStatus m_status; diff --git a/shop/data/voucheritem.cpp b/shop/data/voucheritem.cpp index bc92ac5..133d96e 100644 --- a/shop/data/voucheritem.cpp +++ b/shop/data/voucheritem.cpp @@ -8,6 +8,8 @@ VoucherItem::VoucherItem(QObject *parent) : QObject(parent) m_count = 0; m_refId = 0; m_vatType = Enums::NONE; + m_vatRate = 0; + m_priceWitouthVat = 0; } int VoucherItem::id() const @@ -90,3 +92,28 @@ void VoucherItem::setVatType(const Enums::VatType &vatType) { m_vatType = vatType; } +QDecDouble VoucherItem::vatRate() const +{ + return TO_DEC(m_vatRate); +} + +void VoucherItem::setVatRate(QDecDouble vatRate) +{ + m_vatRate = FROM_DEC(vatRate); +} +QDecDouble VoucherItem::priceWitouthVat() const +{ + return TO_DEC(m_priceWitouthVat); +} + +void VoucherItem::setPriceWitouthVat(QDecDouble priceWitouthVat) +{ + m_priceWitouthVat = FROM_DEC(priceWitouthVat); +} + +QDecDouble VoucherItem::vatAmount() const +{ + return m_price - m_priceWitouthVat; +} + + diff --git a/shop/data/voucheritem.h b/shop/data/voucheritem.h index 29a5684..a99cb56 100644 --- a/shop/data/voucheritem.h +++ b/shop/data/voucheritem.h @@ -16,8 +16,10 @@ class VoucherItem : public QObject Q_PROPERTY(QString name READ name WRITE setName) 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) + Q_PROPERTY(QDecDouble vatRate READ vatRate WRITE setVatRate) + Q_PROPERTY(QDecDouble vatAmount READ vatAmount) + Q_PROPERTY(QDecDouble price READ price WRITE setPrice) public: explicit VoucherItem(QObject *parent = 0); @@ -46,6 +48,14 @@ public: Enums::VatType vatType() const; void setVatType(const Enums::VatType &vatType); + QDecDouble vatRate() const; + void setVatRate(QDecDouble vatRate); + + QDecDouble priceWitouthVat() const; + void setPriceWitouthVat(QDecDouble priceWitouthVat); + + QDecDouble vatAmount() const; + signals: void countChanged(); @@ -56,6 +66,8 @@ private: QString m_name; int m_count; int m_unitPrice; + int m_vatRate; + int m_priceWitouthVat; int m_price; int m_refId; QString m_itemPlugin; diff --git a/shop/directsaleform.cpp b/shop/directsaleform.cpp index 8db5c48..5a59da6 100644 --- a/shop/directsaleform.cpp +++ b/shop/directsaleform.cpp @@ -12,6 +12,14 @@ DirectSaleForm::DirectSaleForm(QWidget *parent) : m_binder.registerBinding(ui->name); m_binder.registerBinding(ui->unitPrice); m_binder.registerBinding(ui->count); + + QList vt; + vt << ComboData(Enums::NONE,tr("None")) + << ComboData(Enums::HIGH,tr("High")) + << ComboData(Enums::FIRST_LOWER,tr("First Lower")) + << ComboData(Enums::SECOND_LOWER,tr("Second Lower")); + + m_binder.registerBinding(ui->vatType, vt); m_binder.bindToUi(); } diff --git a/shop/directsaleform.ui b/shop/directsaleform.ui index 77cf8eb..96a2a1a 100644 --- a/shop/directsaleform.ui +++ b/shop/directsaleform.ui @@ -7,7 +7,7 @@ 0 0 400 - 136 + 150 @@ -52,7 +52,17 @@ + + + + VAT rate + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok diff --git a/shop/directsaleitem.h b/shop/directsaleitem.h index 25aac87..f497e28 100644 --- a/shop/directsaleitem.h +++ b/shop/directsaleitem.h @@ -11,6 +11,7 @@ class DirectSaleItem : public QObject, public IShopItem Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QDecDouble unitPrice READ unitPrice WRITE setUnitPrice) Q_PROPERTY(int count READ count WRITE setCount) + Q_PROPERTY(Enums::VatType vatType READ vatType WRITE setVatType) public: explicit DirectSaleItem(QObject *parent = 0); diff --git a/shop/shop.json b/shop/shop.json index b13f950..6bab111 100644 --- a/shop/shop.json +++ b/shop/shop.json @@ -11,45 +11,59 @@ "schemaVersion" : 1, "sql" : [ "CREATE TABLE \"VoucherItem\" ( - \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - \"name\" TEXT NULL, - \"count\" INTEGER NOT NULL, - \"unitPrice\" INTEGER NOT NULL, - \"price\" INTEGER NOT NULL, - \"refId\" INTEGER NOT NULL, - \"itemPlugin\" TEXT NULL, - \"vatType\" INTEGER NOT NULL); + \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + \"name\" TEXT NULL, + \"count\" INTEGER NOT NULL, + \"unitPrice\" INTEGER NOT NULL, + \"vatRate\" INTEGER NOT NULL, + \"priceWitouthVat\" INTEGER NOT NULL, + \"price\" INTEGER NOT NULL, + \"refId\" INTEGER NOT NULL, + \"itemPlugin\" TEXT NULL, + \"vatType\" INTEGER NOT NULL); - CREATE TABLE \"Voucher\" ( - \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - \"name\" TEXT NULL, - \"description\" TEXT NULL, - \"contact\" INTEGER NULL, - \"totalPrice\" INTEGER NOT NULL, - \"status\" INTEGER NOT NULL, - CONSTRAINT \"contact_fk\" - FOREIGN KEY (\"contact\") - REFERENCES \"AddressbookData\" (\"id\") - DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE \"Voucher\" ( + \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + \"name\" TEXT NULL, + \"description\" TEXT NULL, + \"contact\" INTEGER NULL, + \"vatRateHigh\" INTEGER NOT NULL, + \"vatRateFirstLower\" INTEGER NOT NULL, + \"vatRateSecondLower\" INTEGER NOT NULL, + \"priceNoVat\" INTEGER NOT NULL, + \"priceVatHigh\" INTEGER NOT NULL, + \"priceVatFirstLower\" INTEGER NOT NULL, + \"priceVatSecondLower\" INTEGER NOT NULL, + \"priceWitouthVat\" INTEGER NOT NULL, + \"totalPriceVatHigh\" INTEGER NOT NULL, + \"totalPriceVatFirstLower\" INTEGER NOT NULL, + \"totalPriceVatSecondLower\" INTEGER NOT NULL, + \"totalPrice\" INTEGER NOT NULL, + \"status\" INTEGER NOT NULL, + CONSTRAINT \"contact_fk\" + FOREIGN KEY (\"contact\") + REFERENCES \"AddressbookData\" (\"id\") + DEFERRABLE INITIALLY DEFERRED); - CREATE TABLE \"Voucher_items\" ( - \"object_id\" INTEGER NOT NULL, - \"index\" INTEGER NOT NULL, - \"value\" INTEGER NULL, - CONSTRAINT \"object_id_fk\" - FOREIGN KEY (\"object_id\") - REFERENCES \"Voucher\" (\"id\") - ON DELETE CASCADE, - CONSTRAINT \"value_fk\" - FOREIGN KEY (\"value\") - REFERENCES \"VoucherItem\" (\"id\") - DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE \"Voucher_items\" ( + \"object_id\" INTEGER NOT NULL, + \"index\" INTEGER NOT NULL, + \"value\" INTEGER NULL, + CONSTRAINT \"object_id_fk\" + FOREIGN KEY (\"object_id\") + REFERENCES \"Voucher\" (\"id\") + ON DELETE CASCADE, + CONSTRAINT \"value_fk\" + FOREIGN KEY (\"value\") + REFERENCES \"VoucherItem\" (\"id\") + DEFERRABLE INITIALLY DEFERRED); - CREATE INDEX \"Voucher_items_object_id_i\" - ON \"Voucher_items\" (\"object_id\"); +CREATE INDEX \"Voucher_items_object_id_i\" + ON \"Voucher_items\" (\"object_id\"); - CREATE INDEX \"Voucher_items_index_i\" - ON \"Voucher_items\" (\"index\");" +CREATE INDEX \"Voucher_items_index_i\" + ON \"Voucher_items\" (\"index\"); +" ], "dependencies" : [ "ADDRESSBOOK" ] } diff --git a/shop/shopform.cpp b/shop/shopform.cpp index 497391f..7628149 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -11,12 +11,6 @@ ShopForm::ShopForm(QWidget *parent) : ui(new Ui::ShopForm) { ui->setupUi(this); - ShopService srv; - m_voucher = srv.createVoucher(); - m_itemsModel = new AutoTableModel(this); - m_itemsModel->setEditableCols(QList() << 1); - ui->actualReceipt->setModel(m_itemsModel); - ui->actualReceipt->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); } ShopForm::~ShopForm() @@ -26,6 +20,11 @@ ShopForm::~ShopForm() void ShopForm::on_directSale_clicked() { + if (m_voucher.isNull()) + { + createVoucher(); + } + DirectSaleForm *form = new DirectSaleForm(this); connect(form, &QDialog::accepted, [this, form](){ @@ -78,3 +77,13 @@ void ShopForm::onCountChanged() //if (m_voucher->status()) } + +void ShopForm::createVoucher() +{ + ShopService srv; + m_voucher = srv.createVoucher(); + m_itemsModel = new AutoTableModel(this); + m_itemsModel->setEditableCols(QList() << 1); + ui->actualReceipt->setModel(m_itemsModel); + ui->actualReceipt->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); +} diff --git a/shop/shopform.h b/shop/shopform.h index 4e94ffa..4fd013d 100644 --- a/shop/shopform.h +++ b/shop/shopform.h @@ -33,6 +33,8 @@ private: Ui::ShopForm *ui; QSharedPointer m_voucher; AutoTableModel *m_itemsModel; + + void createVoucher(); }; #endif // SHOPFORM_H diff --git a/shop/shopform.ui b/shop/shopform.ui index 2a2ebd2..c6010b3 100644 --- a/shop/shopform.ui +++ b/shop/shopform.ui @@ -231,12 +231,13 @@ + 12 75 true - Total + Total: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -247,6 +248,7 @@ + 12 75 true diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index ac9f4de..4c7a42a 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -2,7 +2,6 @@ ShopService::ShopService() { - } QSharedPointer ShopService::createVoucher() @@ -29,15 +28,91 @@ void ShopService::calculate(QSharedPointer voucher) { QDecDouble total; + loadSettings(); + voucher->setVatRateHigh(m_gs->vatHigh()); + voucher->setVatRateFirstLower(m_gs->vatFirstLower()); + voucher->setVatRateSecondLower(m_gs->vatSecondLower()); + foreach (QSharedPointer item, voucher->items()) { calculateItem(item); + + QDecDouble priceWitouthWat = item->priceWitouthVat(); + switch (item->vatType()) { + case Enums::NONE: + voucher->setPriceNoVat(voucher->priceNoVat() + priceWitouthWat); + break; + case Enums::HIGH: + voucher->setPriceVatHigh(voucher->priceVatHigh() + priceWitouthWat); + break; + case Enums::FIRST_LOWER: + voucher->setPriceVatFirstLower(voucher->priceVatFirstLower() + priceWitouthWat); + break; + case Enums::SECOND_LOWER: + voucher->setPriceVatSecondLower(voucher->priceVatSecondLower() + priceWitouthWat); + break; + default: + break; + } + total += item->price(); } + voucher->setTotalPriceVatHigh(includeVat(voucher->priceVatHigh(), Enums::HIGH)); + voucher->setTotalPriceVatFirstLower(includeVat(voucher->priceVatFirstLower(), Enums::FIRST_LOWER)); + voucher->setTotalPriceVatSecondLower(includeVat(voucher->priceVatSecondLower(), Enums::SECOND_LOWER)); voucher->setTotalPrice(total); } void ShopService::calculateItem(QSharedPointer item) { - item->setPrice(item->unitPrice() * item->count()); + loadSettings(); + if (m_gs->vatPayer()) + { + item->setVatRate(vatRate(item->vatType())); + item->setPriceWitouthVat(item->unitPrice() * item->count()); + item->setPrice(includeVat(item->priceWitouthVat(), item->vatType())); + } + else + { + item->setPrice(item->unitPrice() * item->count()); + } +} + +QDecDouble ShopService::includeVat(QDecDouble price, Enums::VatType vatType) +{ + return price * ((vatRate(vatType) / 100) + QDecDouble(1)); +} + +void ShopService::loadSettings() +{ + if (m_gs.isNull()) + { + SettingsService settings("CORE"); + m_gs = settings.loadSettings(); + } +} + +QDecDouble ShopService::vatRate(Enums::VatType vatType) +{ + QDecDouble vatRate; + + loadSettings(); + switch (vatType) { + case Enums::NONE: + vatRate = 0; + break; + case Enums::HIGH: + vatRate = m_gs->vatHigh(); + break; + case Enums::FIRST_LOWER: + vatRate = m_gs->vatFirstLower(); + break; + case Enums::SECOND_LOWER: + vatRate = m_gs->vatSecondLower(); + break; + default: + break; + } + + return vatRate; } diff --git a/shop/shopservice.h b/shop/shopservice.h index 6bcb841..1360fca 100644 --- a/shop/shopservice.h +++ b/shop/shopservice.h @@ -4,6 +4,7 @@ #include #include +#include #include "data/shop-data.h" #include "ishopitem.h" @@ -16,6 +17,13 @@ public: void addShopItem(QSharedPointer voucher, QSharedPointer item, int count); void calculate(QSharedPointer voucher); void calculateItem(QSharedPointer item); + +private: + QDecDouble includeVat(QDecDouble price, Enums::VatType vatType); + void loadSettings(); + + QSharedPointer m_gs; + QDecDouble vatRate(Enums::VatType vatType); }; #endif // SHOPSERVICE_H