diff --git a/shop/directsaleform.cpp b/shop/directsaleform.cpp index 5a59da6..c5edab2 100644 --- a/shop/directsaleform.cpp +++ b/shop/directsaleform.cpp @@ -1,12 +1,13 @@ #include "directsaleform.h" #include "ui_directsaleform.h" -DirectSaleForm::DirectSaleForm(QWidget *parent) : +DirectSaleForm::DirectSaleForm(QWidget *parent, Enums::VatType defaultVat) : QDialog(parent), ui(new Ui::DirectSaleForm) { ui->setupUi(this); m_shopItem = QSharedPointer(new DirectSaleItem); + m_shopItem->setVatType(defaultVat); m_binder.setData(m_shopItem.data()); m_binder.registerBinding(ui->name); diff --git a/shop/directsaleform.h b/shop/directsaleform.h index 4c797ef..9d32ce3 100644 --- a/shop/directsaleform.h +++ b/shop/directsaleform.h @@ -18,7 +18,7 @@ class DirectSaleForm : public QDialog Q_OBJECT public: - explicit DirectSaleForm(QWidget *parent = 0); + explicit DirectSaleForm(QWidget *parent = nullptr, Enums::VatType defaultVat = Enums::NONE); ~DirectSaleForm(); QSharedPointer shopItem() const; diff --git a/shop/settings/shopsettings.cpp b/shop/settings/shopsettings.cpp index ba42f1b..33ff15f 100644 --- a/shop/settings/shopsettings.cpp +++ b/shop/settings/shopsettings.cpp @@ -17,6 +17,8 @@ ShopSettings::ShopSettings(QObject *parent) : QObject(parent) m_rounding = Enums::R_NONE; m_decimalPlaces = 0; + m_defaultVat = Enums::NONE; + m_doublePrint = false; } @@ -219,3 +221,13 @@ void ShopSettings::setDoublePrintItem(const QString &doublePrintItem) { m_doublePrintItem = doublePrintItem; } + +Enums::VatType ShopSettings::defaultVat() const +{ + return m_defaultVat; +} + +void ShopSettings::setDefaultVat(const Enums::VatType &defaultVat) +{ + m_defaultVat = defaultVat; +} diff --git a/shop/settings/shopsettings.h b/shop/settings/shopsettings.h index b7b8b11..f0dfc70 100644 --- a/shop/settings/shopsettings.h +++ b/shop/settings/shopsettings.h @@ -30,6 +30,8 @@ class ShopSettings : public QObject Q_PROPERTY(int decimalPlaces READ decimalPlaces WRITE setDecimalPlaces) Q_PROPERTY(QString roundingItem READ roundingItem WRITE setRoundingItem) + Q_PROPERTY(Enums::VatType defaultVat READ defaultVat WRITE setDefaultVat) + Q_OBJECT public: @@ -100,6 +102,9 @@ public: QString doublePrintItem() const; void setDoublePrintItem(const QString &doublePrintItem); + Enums::VatType defaultVat() const; + void setDefaultVat(const Enums::VatType &defaultVat); + private: QString m_output; CODEPAGE m_codepage; @@ -125,6 +130,8 @@ private: Enums::Rounding m_rounding; int m_decimalPlaces; QString m_roundingItem; + + Enums::VatType m_defaultVat; }; typedef QSharedPointer ShopSettingsPtr; diff --git a/shop/settings/shopsettingsform.cpp b/shop/settings/shopsettingsform.cpp index 21b3d2f..9198727 100644 --- a/shop/settings/shopsettingsform.cpp +++ b/shop/settings/shopsettingsform.cpp @@ -48,6 +48,14 @@ ShopSettingsForm::ShopSettingsForm(QWidget *parent) : registerBinding(ui->doublePrint); registerBinding(ui->doublePrintItem); + QList listVatTypes; + listVatTypes + << 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->defaultVat, listVatTypes); + m_itemModel = new AutoTableModel(); } @@ -70,7 +78,7 @@ void ShopSettingsForm::drawButtons() btn->setObjectName(QString::number(i) + "_" + QString::number(j)); btn->setAcceptDrops(true); - if (m_btnMap[btn->objectName()] != NULL) + if (m_btnMap[btn->objectName()] != nullptr) { btn->setText(m_btnMap[btn->objectName()]->shortName()); } diff --git a/shop/settings/shopsettingsform.ui b/shop/settings/shopsettingsform.ui index fde28d8..0a7d9b3 100644 --- a/shop/settings/shopsettingsform.ui +++ b/shop/settings/shopsettingsform.ui @@ -317,6 +317,16 @@ + + + + Default VAT type + + + + + + diff --git a/shop/shopform.cpp b/shop/shopform.cpp index 5479131..9d7b06c 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -190,17 +190,17 @@ void ShopForm::loadButtons() btn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); ((QGridLayout*)ui->favorites->layout())->addWidget(btn, i + 1, j); - if (btnMap[btnName] != NULL) + if (btnMap[btnName] != nullptr) { btn->setText(btnMap[btnName]->shortName()); connect(btn, &FavButton::clicked, [this, btnMap, btn](bool){ FavoritItemPtr item = btnMap[btn->objectName()]; IPlugin *plugin = Context::instance().plugin(item->pluginId()); - IService *service = (plugin != NULL ? plugin->service() : NULL); + IService *service = (plugin != nullptr ? plugin->service() : nullptr); ISellableService *selSrv = dynamic_cast(service); - if (selSrv != NULL) + if (selSrv != nullptr) { addItem(selSrv->shopItem(item->refId()), 1); } @@ -236,7 +236,10 @@ void ShopForm::setEetStatusText(const QString &statusText) void ShopForm::on_directSale_clicked() { - DirectSaleForm *form = new DirectSaleForm(this); + SettingsService srv("SHOP"); + ShopSettingsPtr settings = srv.loadSettings(); + + DirectSaleForm *form = new DirectSaleForm(this, settings->defaultVat()); form->setAttribute(Qt::WA_DeleteOnClose); connect(form, &QDialog::accepted, [this, form](){ @@ -316,7 +319,7 @@ void ShopForm::on_loadButton_clicked() void ShopForm::onCountChanged(int oldCount/* = 0*/) { VoucherItem *item = qobject_cast(sender()); - if (item != NULL && item->count() == 0) + if (item != nullptr && item->count() == 0) { for (int i = 0; i < m_voucher->items().count(); i++) { @@ -346,7 +349,7 @@ void ShopForm::onCountChanged(int oldCount/* = 0*/) srv.updateVoucher(m_voucher); } - if (item != NULL) + if (item != nullptr) { int countAdded = item->count() - oldCount; srv.updateRelatedItem(item, countAdded); @@ -437,7 +440,7 @@ void ShopForm::addItem(QSharedPointer item, int count) } IPlugin *plugin = Context::instance().plugin(item->pluginId()); - IService *service = (plugin != NULL ? plugin->service() : NULL); + IService *service = (plugin != nullptr ? plugin->service() : nullptr); ISellableService *selSrv = dynamic_cast(service); auto addFunc = [this](QSharedPointer shopItem, int itemCount){ @@ -448,7 +451,7 @@ void ShopForm::addItem(QSharedPointer item, int count) onCountChanged(); }; - if (selSrv != NULL && selSrv->seller() != NULL) + if (selSrv != nullptr && selSrv->seller() != nullptr) { ISeller *seller = selSrv->seller();