From fb6b4fe027478ecc0b8f7556b7d4325f60388e72 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Wed, 13 Jul 2016 15:15:18 +0200 Subject: [PATCH 01/14] Implemented base functionality for commodity grid on shop form. --- commodity/commodity.cpp | 3 ++- commodity/commodity.pro | 14 ++++++++++++-- commodity/commodityservice.cpp | 19 ++++++++++++++++++ commodity/commodityservice.h | 18 +++++++++++++++++ commodity/data/commoditydata.cpp | 2 +- commodity/data/commoditydata.h | 3 ++- shop/isellableservice.cpp | 5 +++++ shop/isellableservice.h | 6 ++++-- shop/shop.pro | 7 +++++-- shop/shopform.cpp | 9 +++++++++ shop/shopform.h | 3 +++ shop/shopitem.cpp | 6 ++++++ shop/shopitem.h | 33 ++++++++++++++++++++++++++++++++ shop/shopservice.cpp | 17 ++++++++++++++++ shop/shopservice.h | 3 ++- 15 files changed, 138 insertions(+), 10 deletions(-) create mode 100644 commodity/commodityservice.cpp create mode 100644 commodity/commodityservice.h create mode 100644 shop/isellableservice.cpp create mode 100644 shop/shopitem.cpp create mode 100644 shop/shopitem.h diff --git a/commodity/commodity.cpp b/commodity/commodity.cpp index cd0622f..68db393 100644 --- a/commodity/commodity.cpp +++ b/commodity/commodity.cpp @@ -3,6 +3,7 @@ #include "commodityform.h" #include "commoditygrid.h" #include "commoditysettingsform.h" +#include "commodityservice.h" Commodity::Commodity() { @@ -13,7 +14,7 @@ void Commodity::initServiceUi() CommodityGrid *grid = new CommodityGrid(); CommodityForm *form = new CommodityForm(); - m_service = new Service; + m_service = new CommodityService(); m_ui = grid; ((CommodityGrid *) m_ui)->setForm(form); m_settingsUi = new CommoditySettingsForm(); diff --git a/commodity/commodity.pro b/commodity/commodity.pro index 0ca4f0b..5fc1b92 100644 --- a/commodity/commodity.pro +++ b/commodity/commodity.pro @@ -20,7 +20,8 @@ SOURCES += commodity.cpp \ commoditytablemodel.cpp \ commodityform.cpp \ commoditygrid.cpp \ - commoditysettingsform.cpp + commoditysettingsform.cpp \ + commodityservice.cpp HEADERS += commodity.h\ commodity_global.h \ @@ -30,7 +31,8 @@ HEADERS += commodity.h\ commoditytablemodel.h \ commodityform.h \ commoditygrid.h \ - commoditysettingsform.h + commoditysettingsform.h \ + commodityservice.h unix { target.path = /usr/lib @@ -53,6 +55,7 @@ DESTDIR = ../plugins ODB_FILES = commodity/data/commodity-data.h H_DIR = $$PWD/data/*.h +ODB_OTHER_INCLUDES = -I $$PWD/../shop include(../odb.pri) win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber @@ -73,3 +76,10 @@ FORMS += \ RESOURCES += \ commodityrc.qrc TRANSLATIONS = translations/commodity_cs_CZ.ts + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lshop +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lshop +else:unix: LIBS += -L$$OUT_PWD/../plugins/ -lshop + +INCLUDEPATH += $$PWD/../shop +DEPENDPATH += $$PWD/../shop diff --git a/commodity/commodityservice.cpp b/commodity/commodityservice.cpp new file mode 100644 index 0000000..adbfb82 --- /dev/null +++ b/commodity/commodityservice.cpp @@ -0,0 +1,19 @@ +#include "commodityservice.h" + +#include "commodity-odb.hxx" + +CommodityService::CommodityService() +{ + +} + +QList > CommodityService::shopItems() +{ + QList > ret; + + foreach (QSharedPointer data, all()) { + ret.append(qSharedPointerDynamicCast(data)); + } + + return ret; +} diff --git a/commodity/commodityservice.h b/commodity/commodityservice.h new file mode 100644 index 0000000..8527aef --- /dev/null +++ b/commodity/commodityservice.h @@ -0,0 +1,18 @@ +#ifndef COMMODITYSERVICE_H +#define COMMODITYSERVICE_H + +#include +#include +#include "data/commodity-data.h" + +class CommodityService : public Service, public ISellableService +{ +public: + CommodityService(); + + // ISellableService interface +public: + QList > shopItems() override; +}; + +#endif // COMMODITYSERVICE_H diff --git a/commodity/data/commoditydata.cpp b/commodity/data/commoditydata.cpp index b0b9769..5a12089 100644 --- a/commodity/data/commoditydata.cpp +++ b/commodity/data/commoditydata.cpp @@ -2,7 +2,7 @@ #include CommodityData::CommodityData(QObject *parent) - :QObject(parent) + :ShopItem(parent) { m_count = 0; m_price = 0; diff --git a/commodity/data/commoditydata.h b/commodity/data/commoditydata.h index 7ac5e48..3fb5c42 100644 --- a/commodity/data/commoditydata.h +++ b/commodity/data/commoditydata.h @@ -5,12 +5,13 @@ #include #include #include "commoditytypedata.h" +#include #include #include #include #pragma db object -class CommodityData : public QObject +class CommodityData : public ShopItem { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) diff --git a/shop/isellableservice.cpp b/shop/isellableservice.cpp new file mode 100644 index 0000000..f8dad60 --- /dev/null +++ b/shop/isellableservice.cpp @@ -0,0 +1,5 @@ +#include "isellableservice.h" + +ISellableService::ISellableService() +{ +} diff --git a/shop/isellableservice.h b/shop/isellableservice.h index 717164e..8ce1372 100644 --- a/shop/isellableservice.h +++ b/shop/isellableservice.h @@ -2,14 +2,16 @@ #define ISELLABLESERVICE_H #include "shop_global.h" -#include "ishopitem.h" +#include "shopitem.h" #include #include class SHOPSHARED_EXPORT ISellableService { public: - QList > shopItems() = 0; + ISellableService(); + + virtual QList > shopItems() = 0; }; #endif // ISELLABLESERVICE_H diff --git a/shop/shop.pro b/shop/shop.pro index 3bcd021..8991736 100644 --- a/shop/shop.pro +++ b/shop/shop.pro @@ -26,7 +26,9 @@ SOURCES += shop.cpp \ settings/shopsettings.cpp \ settings/shopsettingsform.cpp \ paydialog.cpp \ - paydvouchersdialog.cpp + paydvouchersdialog.cpp \ + shopitem.cpp \ + isellableservice.cpp HEADERS += shop.h\ shop_global.h \ @@ -46,7 +48,8 @@ HEADERS += shop.h\ settings/shopsettings.h \ settings/shopsettingsform.h \ paydialog.h \ - paydvouchersdialog.h + paydvouchersdialog.h \ + shopitem.h unix { target.path = /usr/lib diff --git a/shop/shopform.cpp b/shop/shopform.cpp index 0819eee..3b1cfc5 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -18,6 +18,7 @@ ShopForm::ShopForm(QWidget *parent) : { ui->setupUi(this); m_itemsModel = NULL; + m_commodityModel = NULL; ui->temporarySaveButton->setEnabled(false); ui->saveButton->setEnabled(false); @@ -54,6 +55,14 @@ void ShopForm::loadLast() ui->saveButton->setEnabled(true); ui->payButton->setEnabled(true); } + + if (m_commodityModel == NULL) + { + m_commodityModel = new AutoTableModel(this); + ui->commodityTable->setModel(m_commodityModel); + } + + m_commodityModel->setData(srv.allSellableItems()); } void ShopForm::fillRaceiptCombo() diff --git a/shop/shopform.h b/shop/shopform.h index 36cb250..bb26645 100644 --- a/shop/shopform.h +++ b/shop/shopform.h @@ -6,6 +6,8 @@ #include "data/shop-data.h" #include +class ShopItem; + namespace Ui { class ShopForm; } @@ -41,6 +43,7 @@ private: Ui::ShopForm *ui; QSharedPointer m_voucher; AutoTableModel *m_itemsModel; + AutoTableModel *m_commodityModel; void createVoucher(); void doTempSave(bool comboChanged); diff --git a/shop/shopitem.cpp b/shop/shopitem.cpp new file mode 100644 index 0000000..541aaac --- /dev/null +++ b/shop/shopitem.cpp @@ -0,0 +1,6 @@ +#include "shopitem.h" + +ShopItem::ShopItem(QObject *parent) : QObject(parent) +{ + +} diff --git a/shop/shopitem.h b/shop/shopitem.h new file mode 100644 index 0000000..d23eac1 --- /dev/null +++ b/shop/shopitem.h @@ -0,0 +1,33 @@ +#ifndef SHOPITEM_H +#define SHOPITEM_H + +#include + +#include "shop_global.h" +#include "ishopitem.h" + +class SHOPSHARED_EXPORT ShopItem : public QObject, public IShopItem +{ + Q_OBJECT + + Q_PROPERTY(QString name READ name) + Q_PROPERTY(QDecDouble unitPrice READ unitPrice) + Q_PROPERTY(Enums::VatType vatType READ vatType) + +public: + explicit ShopItem(QObject *parent = 0); + +signals: + +public slots: + + // IShopItem interface +public: + virtual int id() override { return 0; } + virtual QString name() override { return ""; } + virtual QDecDouble unitPrice() override { return QDecDouble(); } + virtual Enums::VatType vatType() override { return Enums::NONE; } + virtual QString pluginId() override { return ""; } +}; + +#endif // SHOPITEM_H diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index 15e52a4..6220085 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -1,5 +1,6 @@ #include "shopservice.h" #include "numberseriesservice.h" +#include "isellableservice.h" #include "shop-odb.hxx" ShopService::ShopService() @@ -120,6 +121,22 @@ QList > ShopService::paiedVouchers() return all(QString("status = %1").arg(QString::number(Voucher::PAID))); } +QList > ShopService::allSellableItems() +{ + QList > items; + foreach (IPlugin *plugin, Context::instance().plugins()) { + IService *srv = plugin->service(); + ISellableService *selSrv = dynamic_cast(srv); + + if (selSrv != NULL) + { + items.append(selSrv->shopItems()); + } + } + + return items; +} + QDecDouble ShopService::includeVat(QDecDouble price, Enums::VatType vatType) { return price * ((vatRate(vatType) / 100) + QDecDouble(1)); diff --git a/shop/shopservice.h b/shop/shopservice.h index 0c626d1..87eae88 100644 --- a/shop/shopservice.h +++ b/shop/shopservice.h @@ -7,7 +7,7 @@ #include #include "data/shop-data.h" -#include "ishopitem.h" +#include "shopitem.h" class ShopService : public Service { @@ -22,6 +22,7 @@ public: QList > savedVouchers(); QList > tempVouchers(); QList > paiedVouchers(); + QList > allSellableItems(); private: QDecDouble includeVat(QDecDouble price, Enums::VatType vatType); From 44c74a5cfe1bf73a7b8e96842a0a097eb3893ea3 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Thu, 21 Jul 2016 16:24:07 +0200 Subject: [PATCH 02/14] Added sell commodity feature. --- commodity/commodityservice.cpp | 12 ++++++++++ commodity/commodityservice.h | 1 + commodity/data/commoditydata.cpp | 19 +++++++++++++-- commodity/data/commoditydata.h | 12 +++++++--- shop/data/voucheritem.cpp | 3 ++- shop/data/voucheritem.h | 2 +- shop/isellableservice.h | 1 + shop/shopform.cpp | 41 ++++++++++++++++++++++++++------ shop/shopform.h | 6 ++++- shop/shopform.ui | 25 +++++++++++++++---- shop/shopitem.h | 4 ++++ shop/shopservice.cpp | 14 +++++++++++ shop/shopservice.h | 1 + 13 files changed, 122 insertions(+), 19 deletions(-) diff --git a/commodity/commodityservice.cpp b/commodity/commodityservice.cpp index adbfb82..ecb1d3f 100644 --- a/commodity/commodityservice.cpp +++ b/commodity/commodityservice.cpp @@ -17,3 +17,15 @@ QList > CommodityService::shopItems() return ret; } + +void CommodityService::addedToVoucher(int itemId, int countAdded) +{ + QSharedPointer commodity = loadById(itemId); + + if (!commodity.isNull()) + { + commodity->setCount(commodity->count() - countAdded); + } + + update(commodity); +} diff --git a/commodity/commodityservice.h b/commodity/commodityservice.h index 8527aef..4f67690 100644 --- a/commodity/commodityservice.h +++ b/commodity/commodityservice.h @@ -13,6 +13,7 @@ public: // ISellableService interface public: QList > shopItems() override; + void addedToVoucher(int itemId, int countAdded) override; }; #endif // COMMODITYSERVICE_H diff --git a/commodity/data/commoditydata.cpp b/commodity/data/commoditydata.cpp index 5a12089..2463564 100644 --- a/commodity/data/commoditydata.cpp +++ b/commodity/data/commoditydata.cpp @@ -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"; +} + diff --git a/commodity/data/commoditydata.h b/commodity/data/commoditydata.h index 3fb5c42..462b4f1 100644 --- a/commodity/data/commoditydata.h +++ b/commodity/data/commoditydata.h @@ -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 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 diff --git a/shop/data/voucheritem.cpp b/shop/data/voucheritem.cpp index 3d25f3f..cd7132f 100644 --- a/shop/data/voucheritem.cpp +++ b/shop/data/voucheritem.cpp @@ -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 diff --git a/shop/data/voucheritem.h b/shop/data/voucheritem.h index 02ee8de..d41e77f 100644 --- a/shop/data/voucheritem.h +++ b/shop/data/voucheritem.h @@ -63,7 +63,7 @@ public: void setVoucher(const QWeakPointer &voucher); signals: - void countChanged(); + void countChanged(int oldCount); private: friend class odb::access; diff --git a/shop/isellableservice.h b/shop/isellableservice.h index 8ce1372..dc778c0 100644 --- a/shop/isellableservice.h +++ b/shop/isellableservice.h @@ -12,6 +12,7 @@ public: ISellableService(); virtual QList > shopItems() = 0; + virtual void addedToVoucher(int itemId, int countAdded) = 0; }; #endif // ISELLABLESERVICE_H diff --git a/shop/shopform.cpp b/shop/shopform.cpp index 3b1cfc5..f78c431 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -8,6 +8,7 @@ #include "receiptgenerator.h" #include "paydialog.h" #include "paydvouchersdialog.h" +#include "isellableservice.h" #include #include #include "shop-odb.hxx" @@ -60,6 +61,10 @@ void ShopForm::loadLast() { m_commodityModel = new AutoTableModel(this); ui->commodityTable->setModel(m_commodityModel); + + connect(ui->commodityTable->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](const QModelIndex ¤t, 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(); @@ -132,7 +133,7 @@ void ShopForm::on_loadButton_clicked() form->show(); } -void ShopForm::onCountChanged() +void ShopForm::onCountChanged(int oldCount) { VoucherItem *item = qobject_cast(sender()); if (item != NULL && item->count() == 0) @@ -162,6 +163,12 @@ void ShopForm::onCountChanged() { srv.updateVoucher(m_voucher); } + + if (item != NULL) + { + int countAdded = item->count() - oldCount; + srv.updateRelatedItem(item, countAdded); + } } void ShopForm::createVoucher() @@ -224,7 +231,7 @@ void ShopForm::changeReceipt() void ShopForm::connectItemSignals() { foreach (QSharedPointer item, m_voucher->items()) { - connect(item.data(), SIGNAL(countChanged()), this, SLOT(onCountChanged())); + connect(item.data(), SIGNAL(countChanged(int)), this, SLOT(onCountChanged(int))); } } @@ -238,6 +245,15 @@ void ShopForm::createEmptyVoucher() ui->payButton->setEnabled(false); } +void ShopForm::addItem(QSharedPointer 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()) @@ -286,3 +302,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()); +} diff --git a/shop/shopform.h b/shop/shopform.h index bb26645..301823b 100644 --- a/shop/shopform.h +++ b/shop/shopform.h @@ -7,6 +7,7 @@ #include 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 m_voucher; @@ -50,6 +53,7 @@ private: void changeReceipt(); void connectItemSignals(); void createEmptyVoucher(); + void addItem(QSharedPointer item, int count); }; #endif // SHOPFORM_H diff --git a/shop/shopform.ui b/shop/shopform.ui index 56dceaf..93f4c36 100644 --- a/shop/shopform.ui +++ b/shop/shopform.ui @@ -55,7 +55,14 @@ - + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + @@ -68,7 +75,7 @@ - + false @@ -78,13 +85,23 @@ false + + 1 + - + + + false + Add Item + + + :/icons/new.svg:/icons/new.svg + @@ -386,8 +403,8 @@ - + diff --git a/shop/shopitem.h b/shop/shopitem.h index d23eac1..0f03f44 100644 --- a/shop/shopitem.h +++ b/shop/shopitem.h @@ -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,10 +25,13 @@ 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; } virtual QString pluginId() override { return ""; } }; +typedef QSharedPointer ShopItemPtr; + #endif // SHOPITEM_H diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index 6220085..5692915 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -25,6 +25,8 @@ void ShopService::addShopItem(QSharedPointer voucher, QSharedPointersetVatType(item->vatType()); voucher->addItem(vItem); + + updateRelatedItem(vItem.data(), count); } void ShopService::calculate(QSharedPointer voucher) @@ -106,6 +108,18 @@ void ShopService::pay(QSharedPointer voucher) tx.commit(); } +void ShopService::updateRelatedItem(VoucherItem* item, int countAdded) +{ + IPlugin *plugin = Context::instance().plugin(item->itemPlugin()); + IService *srv = (plugin != NULL ? plugin->service() : NULL); + ISellableService *selSrv = dynamic_cast(srv); + + if (selSrv != NULL) + { + selSrv->addedToVoucher(item->refId(), countAdded); + } +} + QList > ShopService::savedVouchers() { return all(QString("status = %1").arg(QString::number(Voucher::NOT_PAID))); diff --git a/shop/shopservice.h b/shop/shopservice.h index 87eae88..f941ca3 100644 --- a/shop/shopservice.h +++ b/shop/shopservice.h @@ -19,6 +19,7 @@ public: void calculateItem(QSharedPointer item); void loadItems(QSharedPointer voucher); void pay(QSharedPointer voucher); + void updateRelatedItem(VoucherItem* item, int countAdded); QList > savedVouchers(); QList > tempVouchers(); QList > paiedVouchers(); From f15a361b507dbcf3d0e61fdad245034eba0ac861 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Fri, 22 Jul 2016 13:18:31 +0200 Subject: [PATCH 03/14] Added support for checkbox select in AutoTableModel. --- core/autotablemodel.h | 46 +++++++++++++++++++++++++++++++++++++++++-- core/itablemodel.cpp | 15 ++++++++++++++ core/itablemodel.h | 4 ++++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/core/autotablemodel.h b/core/autotablemodel.h index 6f45b0f..2b12a38 100644 --- a/core/autotablemodel.h +++ b/core/autotablemodel.h @@ -24,6 +24,7 @@ public: :ITableModel(parent) { filtered = false; + m_checkboxSelect = false; } virtual ~AutoTableModel() {} @@ -50,6 +51,21 @@ public: QVariant data(const QModelIndex &index, int role) const { + if (index.column() == 0 && m_checkboxSelect) + { + if (role == Qt::CheckStateRole) + { + if (m_selectedRows.contains(index.row())) + { + return Qt::Checked; + } + else + { + return Qt::Unchecked; + } + } + } + QSharedPointer entity = m_list.at(index.row()); QObject *rawEntity = (QObject*)entity.data(); @@ -189,6 +205,21 @@ public: m_translations = translations; } + QList selectedRows() const + { + return m_selectedRows; + } + + QList > selectedItems() + { + QList > ret; + foreach (int row, m_selectedRows) { + ret.append(m_list[row]); + } + + return ret; + } + protected: void handleFilter(const QString &filter) override { @@ -220,10 +251,10 @@ protected: private: QList > m_list; QList > m_fullList; + QList m_selectedRows; QMap m_translations; bool filtered; - // QAbstractItemModel interface public: virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override @@ -236,10 +267,21 @@ public: rawEntity->setProperty(rawEntity->metaObject()->property(index.column() + 1).name(), value); } + if (role == Qt::CheckStateRole) + { + if (m_selectedRows.contains(index.row())) + { + m_selectedRows.removeOne(index.row()); + } + else + { + m_selectedRows.append(index.row()); + } + } + emit editCompleted(); return true; } }; #endif // ODBTABLEMODEL_H - diff --git a/core/itablemodel.cpp b/core/itablemodel.cpp index dfde394..7933a8c 100644 --- a/core/itablemodel.cpp +++ b/core/itablemodel.cpp @@ -3,7 +3,17 @@ ITableModel::ITableModel(QObject *parent) :QAbstractTableModel(parent) { + m_checkboxSelect = false; +} + +bool ITableModel::checkboxSelect() const +{ + return m_checkboxSelect; +} +void ITableModel::setCheckboxSelect(bool checkboxSelect) +{ + m_checkboxSelect = checkboxSelect; } void ITableModel::filter(const QString &filter) @@ -18,6 +28,11 @@ void ITableModel::restore() Qt::ItemFlags ITableModel::flags(const QModelIndex &index) const { + if (index.column() == 0 && m_checkboxSelect) + { + return Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled; + } + if (m_editableCols.contains(index.column())) { return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; diff --git a/core/itablemodel.h b/core/itablemodel.h index e30780f..b337c16 100644 --- a/core/itablemodel.h +++ b/core/itablemodel.h @@ -16,6 +16,7 @@ public: protected: virtual void handleFilter(const QString &filter) = 0; virtual void handleRestore() = 0; + bool m_checkboxSelect; public slots: void filter(const QString &filter); @@ -29,6 +30,9 @@ public: virtual Qt::ItemFlags flags(const QModelIndex &index) const override; void setEditableCols(const QList cols); + bool checkboxSelect() const; + void setCheckboxSelect(bool checkboxSelect); + private: QList m_editableCols; }; From 0f397c430803886d0c39b265d01823bc6bcae961 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Fri, 22 Jul 2016 13:21:39 +0200 Subject: [PATCH 04/14] Transation fix. --- application/translations/prodejna_cs_CZ.qm | Bin 560 -> 558 bytes application/translations/prodejna_cz.ts | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/application/translations/prodejna_cs_CZ.qm b/application/translations/prodejna_cs_CZ.qm index ff3af12a1711b42ac8ffc3bef8e6739b11f5ffc3..f569e5d5e8489a9b868d359be2df9e341a614048 100644 GIT binary patch delta 47 zcmdnMvW{hf51%#9ZpLB;2F3}QK;q=aC^kkx0fqpEB8Gg16oyoWEQUOW#L2~sdjT6< B3$*|M delta 35 qcmZ3-vVmoS51%d1ZpLB;2F6L5K;rbqC^p8)?-+#`Gba}^?gap}MG9j8 diff --git a/application/translations/prodejna_cz.ts b/application/translations/prodejna_cz.ts index cc1072e..8d1a56b 100644 --- a/application/translations/prodejna_cz.ts +++ b/application/translations/prodejna_cz.ts @@ -20,7 +20,7 @@ MainWindow - Nastaveni + Prodejna From 707e2dbc0b47d7685913755e35b4b77280c1f4c5 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Fri, 22 Jul 2016 13:22:51 +0200 Subject: [PATCH 05/14] Added typedefs for QSharedPointer types --- shop/isellableservice.h | 3 ++- shop/shopitem.h | 2 ++ shop/shopservice.cpp | 24 ++++++++++++------------ shop/shopservice.h | 24 ++++++++++++------------ 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/shop/isellableservice.h b/shop/isellableservice.h index 8ce1372..41ba709 100644 --- a/shop/isellableservice.h +++ b/shop/isellableservice.h @@ -11,7 +11,8 @@ class SHOPSHARED_EXPORT ISellableService public: ISellableService(); - virtual QList > shopItems() = 0; + virtual QList shopItems() = 0; + //virtual void addToReceipt() }; #endif // ISELLABLESERVICE_H diff --git a/shop/shopitem.h b/shop/shopitem.h index d23eac1..e9c9f26 100644 --- a/shop/shopitem.h +++ b/shop/shopitem.h @@ -30,4 +30,6 @@ public: virtual QString pluginId() override { return ""; } }; +typedef QSharedPointer ShopItemPtr; + #endif // SHOPITEM_H diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index 6220085..23833d7 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -7,14 +7,14 @@ ShopService::ShopService() { } -QSharedPointer ShopService::createVoucher() +VoucherPtr ShopService::createVoucher() { QSharedPointer voucher(new Voucher); voucher->setStatus(Voucher::NEW); return voucher; } -void ShopService::addShopItem(QSharedPointer voucher, QSharedPointer item, int count) +void ShopService::addShopItem(VoucherPtr voucher, QSharedPointer item, int count) { QSharedPointer vItem(new VoucherItem); vItem->setName(item->name()); @@ -27,7 +27,7 @@ void ShopService::addShopItem(QSharedPointer voucher, QSharedPointeraddItem(vItem); } -void ShopService::calculate(QSharedPointer voucher) +void ShopService::calculate(VoucherPtr voucher) { QDecDouble total; @@ -66,7 +66,7 @@ void ShopService::calculate(QSharedPointer voucher) voucher->setTotalPrice(total); } -void ShopService::calculateItem(QSharedPointer item) +void ShopService::calculateItem(VoucherItemPtr item) { loadSettings(); if (m_gs->vatPayer()) @@ -82,13 +82,13 @@ void ShopService::calculateItem(QSharedPointer item) } } -void ShopService::loadItems(QSharedPointer voucher) +void ShopService::loadItems(VoucherPtr voucher) { Service srv; voucher->setItems(srv.all(QString("voucher = %1").arg(voucher->id()))); } -void ShopService::pay(QSharedPointer voucher) +void ShopService::pay(VoucherPtr voucher) { Transaction tx; NumberSeriesService srvNs; @@ -106,22 +106,22 @@ void ShopService::pay(QSharedPointer voucher) tx.commit(); } -QList > ShopService::savedVouchers() +QList ShopService::savedVouchers() { return all(QString("status = %1").arg(QString::number(Voucher::NOT_PAID))); } -QList > ShopService::tempVouchers() +QList ShopService::tempVouchers() { return all(QString("status = %1").arg(QString::number(Voucher::TEMPORARY))); } -QList > ShopService::paiedVouchers() +QList ShopService::paiedVouchers() { return all(QString("status = %1").arg(QString::number(Voucher::PAID))); } -QList > ShopService::allSellableItems() +QList ShopService::allSellableItems() { QList > items; foreach (IPlugin *plugin, Context::instance().plugins()) { @@ -176,7 +176,7 @@ QDecDouble ShopService::vatRate(Enums::VatType vatType) return vatRate; } -void ShopService::saveVoucher(QSharedPointer entity) +void ShopService::saveVoucher(VoucherPtr entity) { Transaction tr; odb::database *db = Context::instance().db(); @@ -191,7 +191,7 @@ void ShopService::saveVoucher(QSharedPointer entity) tr.commit(); } -void ShopService::updateVoucher(QSharedPointer entity) +void ShopService::updateVoucher(VoucherPtr entity) { Transaction tr; odb::database *db = Context::instance().db(); diff --git a/shop/shopservice.h b/shop/shopservice.h index 87eae88..2b1ef82 100644 --- a/shop/shopservice.h +++ b/shop/shopservice.h @@ -13,16 +13,16 @@ class ShopService : public Service { public: ShopService(); - QSharedPointer createVoucher(); - void addShopItem(QSharedPointer voucher, QSharedPointer item, int count); - void calculate(QSharedPointer voucher); - void calculateItem(QSharedPointer item); - void loadItems(QSharedPointer voucher); - void pay(QSharedPointer voucher); - QList > savedVouchers(); - QList > tempVouchers(); - QList > paiedVouchers(); - QList > allSellableItems(); + VoucherPtr createVoucher(); + void addShopItem(VoucherPtr voucher, QSharedPointer item, int count); + void calculate(VoucherPtr voucher); + void calculateItem(VoucherItemPtr item); + void loadItems(VoucherPtr voucher); + void pay(VoucherPtr voucher); + QList savedVouchers(); + QList tempVouchers(); + QList paiedVouchers(); + QList allSellableItems(); private: QDecDouble includeVat(QDecDouble price, Enums::VatType vatType); @@ -32,8 +32,8 @@ private: QDecDouble vatRate(Enums::VatType vatType); public: - void saveVoucher(QSharedPointer entity); - void updateVoucher(QSharedPointer entity); + void saveVoucher(VoucherPtr entity); + void updateVoucher(VoucherPtr entity); }; #endif // SHOPSERVICE_H From 9e9e1f6dba93bf3e18b66f5c0ab18295d540ce75 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Wed, 3 Aug 2016 18:24:15 +0200 Subject: [PATCH 06/14] Added load receipt functionality. --- core/context.cpp | 4 ++++ shop/receiptloadform.cpp | 11 +++++++++++ shop/receiptloadform.h | 2 ++ shop/shopform.cpp | 17 +++++++++++++++++ shop/shopservice.cpp | 27 +++++++++++++++++++++++++++ shop/shopservice.h | 1 + 6 files changed, 62 insertions(+) diff --git a/core/context.cpp b/core/context.cpp index c658df6..7b92ef3 100644 --- a/core/context.cpp +++ b/core/context.cpp @@ -65,6 +65,10 @@ void Context::loadPlugins() m_plugins.append(plugin); } } + else + { + qDebug() << pluginLoader.errorString(); + } } QString dbPath = m_settings->value("db/path", "").toString(); diff --git a/shop/receiptloadform.cpp b/shop/receiptloadform.cpp index 9622c27..1eff0a6 100644 --- a/shop/receiptloadform.cpp +++ b/shop/receiptloadform.cpp @@ -28,6 +28,7 @@ ReceiptLoadForm::ReceiptLoadForm(QWidget *parent) : ui->tabVouchers->setColumnWidth(2, 200); m_itemModel = new AutoTableModel(this); + m_itemModel->setCheckboxSelect(true); ui->tabItems->setModel(m_itemModel); connect(ui->tabVouchers->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](const QModelIndex ¤t, QModelIndex){ @@ -43,6 +44,16 @@ ReceiptLoadForm::~ReceiptLoadForm() delete ui; } +QList ReceiptLoadForm::selectedItems() +{ + return m_itemModel->selectedItems(); +} + +VoucherPtr ReceiptLoadForm::selectedVoucher() +{ + return m_voucherModel->itemFromIndex(ui->tabVouchers->currentIndex()); +} + void ReceiptLoadForm::on_lineEdit_textChanged(const QString &text) { QSortFilterProxyModel proxy; diff --git a/shop/receiptloadform.h b/shop/receiptloadform.h index ec022d3..f49954d 100644 --- a/shop/receiptloadform.h +++ b/shop/receiptloadform.h @@ -16,6 +16,8 @@ class ReceiptLoadForm : public QDialog public: explicit ReceiptLoadForm(QWidget *parent = 0); ~ReceiptLoadForm(); + QList selectedItems(); + VoucherPtr selectedVoucher(); private slots: void on_lineEdit_textChanged(const QString &text); diff --git a/shop/shopform.cpp b/shop/shopform.cpp index 3b1cfc5..8995846 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -129,6 +129,23 @@ void ShopForm::on_loadButton_clicked() { ReceiptLoadForm *form = new ReceiptLoadForm(this); form->setAttribute(Qt::WA_DeleteOnClose); + + connect(form, &QDialog::accepted, [this, form](){ + ShopService srv; + + if (m_voucher.isNull()) + { + m_voucher = srv.createVoucher(); + } + + srv.moveItems(form->selectedItems(), form->selectedVoucher(), this->m_voucher); + + m_itemsModel->setData(m_voucher->items()); + + connectItemSignals(); + onCountChanged(); + }); + form->show(); } diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index 23833d7..242dd4a 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -106,6 +106,33 @@ void ShopService::pay(VoucherPtr voucher) tx.commit(); } +void ShopService::moveItems(QList items, VoucherPtr source, VoucherPtr target) +{ + Transaction tx; + + if (target->status() == Voucher::NEW && target->id() == 0) + { + this->saveVoucher(target); + } + + odb::database *db = Context::instance().db(); + + foreach (VoucherItemPtr item, items) { + QString sql = QString("update VoucherItem set voucher = %1 where id = %2").arg(QString::number(target->id()), QString::number(item->id())); + db->execute(sql.toStdString()); + } + + loadItems(source); + loadItems(target); + + if (source->items().isEmpty()) + { + erase(source); + } + + tx.commit(); +} + QList ShopService::savedVouchers() { return all(QString("status = %1").arg(QString::number(Voucher::NOT_PAID))); diff --git a/shop/shopservice.h b/shop/shopservice.h index 2b1ef82..4646e55 100644 --- a/shop/shopservice.h +++ b/shop/shopservice.h @@ -19,6 +19,7 @@ public: void calculateItem(VoucherItemPtr item); void loadItems(VoucherPtr voucher); void pay(VoucherPtr voucher); + void moveItems(QList items, VoucherPtr source, VoucherPtr target); QList savedVouchers(); QList tempVouchers(); QList paiedVouchers(); From a82a0be8836c4143493ca22f872a22954f78aa73 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Thu, 4 Aug 2016 22:19:16 +0200 Subject: [PATCH 07/14] Fixed API change. --- shop/shopform.cpp | 4 ++-- shop/shopform.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/shop/shopform.cpp b/shop/shopform.cpp index fd3a9eb..d62030e 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -150,7 +150,7 @@ void ShopForm::on_loadButton_clicked() form->show(); } -void ShopForm::onCountChanged(int oldCount) +void ShopForm::onCountChanged(int oldCount/* = 0*/) { VoucherItem *item = qobject_cast(sender()); if (item != NULL && item->count() == 0) @@ -268,7 +268,7 @@ void ShopForm::addItem(QSharedPointer item, int count) 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); + onCountChanged(); } void ShopForm::on_receiptCombo_currentIndexChanged(int) diff --git a/shop/shopform.h b/shop/shopform.h index 301823b..1542b59 100644 --- a/shop/shopform.h +++ b/shop/shopform.h @@ -32,7 +32,7 @@ private slots: void on_loadButton_clicked(); - void onCountChanged(int oldCount); + void onCountChanged(int oldCount = 0); void on_receiptCombo_currentIndexChanged(int index); From 0af4db2641c0c3bcb5e133f2ffeb1e6071092d24 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Sat, 7 Jan 2017 15:19:40 +0100 Subject: [PATCH 08/14] Minor UI changes. Added gcc switches to odb compiler. --- odb.pri | 2 +- shop/shop.json | 1 + shop/shopform.cpp | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/odb.pri b/odb.pri index 5459420..ab3dc7b 100644 --- a/odb.pri +++ b/odb.pri @@ -46,7 +46,7 @@ ODB_FLAGS += -I $$PWD/core ODB_FLAGS += -I $$PWD/qdecimal/src ODB_FLAGS += -I $$PWD/qdecimal/decnumber ODB_FLAGS += $$ODB_OTHER_INCLUDES -ODB_FLAGS += -D __PIC__ +ODB_FLAGS += -x -std=c++11 -x -fPIC win32 { ODB_FLAGS += -I d:/prac/odb/libodb-2.4.0 diff --git a/shop/shop.json b/shop/shop.json index 9f54cc6..ccd3cab 100644 --- a/shop/shop.json +++ b/shop/shop.json @@ -57,6 +57,7 @@ CREATE TABLE \"Voucher\" ( "translations" : { "CZ" : { "name" : "Název", + "code" : "Kod", "count" : "Počet", "unitPrice" : "Jednotková cena", "vatRate" : "Procento DPH", diff --git a/shop/shopform.cpp b/shop/shopform.cpp index d62030e..3df7c76 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -60,6 +60,7 @@ void ShopForm::loadLast() if (m_commodityModel == NULL) { m_commodityModel = new AutoTableModel(this); + m_commodityModel->setTranslations(Context::instance().plugin("SHOP")->translations()); ui->commodityTable->setModel(m_commodityModel); connect(ui->commodityTable->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](const QModelIndex ¤t, const QModelIndex &){ @@ -68,6 +69,8 @@ void ShopForm::loadLast() } m_commodityModel->setData(srv.allSellableItems()); + ui->commodityTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); + ui->commodityTable->setColumnHidden(3, true); } void ShopForm::fillRaceiptCombo() From c2544d812f78752e52570b7cd22f3fc995ee6530 Mon Sep 17 00:00:00 2001 From: Zdenek Jonak Date: Tue, 10 Jan 2017 20:56:04 +0100 Subject: [PATCH 09/14] translation source files --- addressbook/translations/addressbook_cs_CZ.ts | 62 ++++ commodity/translations/commodity_cs_CZ.ts | 85 +++++ core/translations/core_cs_CZ.ts | 93 ++++- services/translations/services_cs_CZ.ts | 82 +++++ shop/translations/shop_cs_CZ.ts | 319 ++++++++++++++++++ 5 files changed, 624 insertions(+), 17 deletions(-) create mode 100644 addressbook/translations/addressbook_cs_CZ.ts create mode 100644 commodity/translations/commodity_cs_CZ.ts create mode 100644 services/translations/services_cs_CZ.ts create mode 100644 shop/translations/shop_cs_CZ.ts diff --git a/addressbook/translations/addressbook_cs_CZ.ts b/addressbook/translations/addressbook_cs_CZ.ts new file mode 100644 index 0000000..64d466c --- /dev/null +++ b/addressbook/translations/addressbook_cs_CZ.ts @@ -0,0 +1,62 @@ + + + + + AddressbookForm + + + Form + + + + + Title + Titul + + + + First Name + Křestní jméno + + + + Last Name + Příjmení + + + + Day of Birth + Datum narození + + + + ID Card Number + Číslo dokladu totožnosti + + + + City + Město + + + + ZTP + ZTP + + + + Street + Ulice + + + + House Number + Číslo popisné + + + + ZIP + PSČ + + + diff --git a/commodity/translations/commodity_cs_CZ.ts b/commodity/translations/commodity_cs_CZ.ts new file mode 100644 index 0000000..db5539e --- /dev/null +++ b/commodity/translations/commodity_cs_CZ.ts @@ -0,0 +1,85 @@ + + + + + CommodityForm + + + Form + Zboží + + + + Name + Název + + + + Short Name + Zobrazit na účtence + + + + Code + Kód + + + + Type + Druh + + + + Price + Cena + + + + Vat + DPH + + + + Count + Počet + + + + None + Žádná + + + + High + Vysoká + + + + First Lower + První snížená + + + + Second Lower + Druhá snížená + + + + CommoditySettingsForm + + + Form + + + + + + + + + + + + - + - + + + diff --git a/core/translations/core_cs_CZ.ts b/core/translations/core_cs_CZ.ts index e23a684..6fd7131 100644 --- a/core/translations/core_cs_CZ.ts +++ b/core/translations/core_cs_CZ.ts @@ -126,86 +126,132 @@ - + + Base settings + + + + Company info Informace o společnosti - + IC IČO - + VAT number DIČ - + VAT payer Plátce DPH - + VAT rates Sazby DPH - + High Vysoká - + First lower První snížená - + Second lower Druhá snížená - + + + Number series + + + + + Edit name + + + + + Season + + + + + Create new + + + + Contact Kontaktní údaje - + Firm Name Název společnosti - + Street Ulice - + House Number Číslo popisné - + City Město - + ZIP code PSČ - - + + Logo Logo - + Select file Vyber soubor + + + Switch season + + + + + Realy switch active season? + + + + + New season + + + + + Realy create new season and switch to it? + + GridForm @@ -314,6 +360,19 @@ Název filtru + + SeasonNameDialog + + + Season + + + + + Season name + + + SettingsForm diff --git a/services/translations/services_cs_CZ.ts b/services/translations/services_cs_CZ.ts new file mode 100644 index 0000000..a065c7e --- /dev/null +++ b/services/translations/services_cs_CZ.ts @@ -0,0 +1,82 @@ + + + + + AccServiceForm + + + Form + Služba + + + + Service Name + Název + + + + Price + Cena + + + + Service Type + Druh + + + + Sale Possible + Umožnit slevu + + + + Active + Aktivní + + + + ServiceCode + Kód + + + + Vat Type + Sazba DPH + + + + Car + Vozidlo + + + + Tent + Stan + + + + OTHER + Ostatní + + + + None + Žádná + + + + High + Vysoká + + + + First Lower + První snížená + + + + Second Lower + Druhá snížená + + + diff --git a/shop/translations/shop_cs_CZ.ts b/shop/translations/shop_cs_CZ.ts new file mode 100644 index 0000000..c92efdf --- /dev/null +++ b/shop/translations/shop_cs_CZ.ts @@ -0,0 +1,319 @@ + + + + + DirectSaleForm + + + Form + Zboží + + + + Commodity Name + Název + + + + Price + Cena + + + + Count + Počet + + + + VAT rate + Sazba DPH + + + + None + Žádná + + + + High + Vysoká + + + + First Lower + První snížená + + + + Second Lower + Druhá snížená + + + + PayDialog + + + Recieve money + + + + + Total: + Celkem: + + + + + 0 + + + + + Recieved + + + + + Return + + + + + PaydVouchersDialog + + + Paied vouchers + + + + + Print receipt + + + + + + Save receipt + + + + + ... + + + + + Items + Položky + + + + Total: + Celkem: + + + + 0 + + + + + Text files (*.txt) + + + + + ReceiptLoadForm + + + Dialog + + + + + Receipts + Účtenky + + + + Search + Hledat + + + + Items + Položky + + + + ReceiptSaveForm + + + Existing Receipts + Přidat k již uložené + + + + Search + Hledat + + + GroupBox + Uložit novou + + + + Save receipt + + + + + Add to existing + + + + + Save as new + + + + + New receipt + + + + + Name + Název + + + + Description + Popis + + + + Search Contacts + Vyhledat kontakt + + + + ShopForm + + + Form + + + + + Commodity + Zboží + + + + Count + Počet + + + + Add Item + Přidat položku + + + + Direct Sale + Přímý prodej + + + + Ctrl+D + + + + + Receipt + Účtenka + + + + Total: + Celkem: + + + + 0 + + + + + Temporary Save + Dočasné uložení + + + + Save + Uložení + + + + Load + Načíst + + + + Show paied + + + + + Pay + Zaplatit + + + + << empty >> + + + + + ShopSettingsForm + + + Form + Zboží + + + + Printer + + + + + Output device + + + + + Letters per line + + + + + Footer text + + + + + TemporaryReceiptSaveForm + + + Dialog + Dočasné uložení + + + + Temporary Receipt Name + Název dočasně uložené účtenky + + + From 2eb1039f6faf8b919474f8267e2674f47ed69c6d Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Fri, 17 Feb 2017 15:15:45 +0100 Subject: [PATCH 10/14] Implemented search in shop items on ShopForm. Prepare for favorite buttons. --- core/itablemodel.cpp | 2 +- shop/data/favorititem.cpp | 69 ++++++++ shop/data/favorititem.h | 62 +++++++ shop/data/shop-data.h | 1 + shop/settings/favoriteservice.cpp | 6 + shop/settings/favoriteservice.h | 13 ++ shop/settings/shopsettingsform.cpp | 7 + shop/settings/shopsettingsform.h | 3 + shop/settings/shopsettingsform.ui | 257 ++++++++++++++++++++++++----- shop/shop.pro | 11 +- shop/shopform.cpp | 30 ++++ shop/shopform.h | 2 + shop/shopform.ui | 174 ++++++++++++++++++- 13 files changed, 593 insertions(+), 44 deletions(-) create mode 100644 shop/data/favorititem.cpp create mode 100644 shop/data/favorititem.h create mode 100644 shop/settings/favoriteservice.cpp create mode 100644 shop/settings/favoriteservice.h diff --git a/core/itablemodel.cpp b/core/itablemodel.cpp index dfde394..50f689b 100644 --- a/core/itablemodel.cpp +++ b/core/itablemodel.cpp @@ -23,7 +23,7 @@ Qt::ItemFlags ITableModel::flags(const QModelIndex &index) const return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; } - return QAbstractTableModel::flags(index); + return QAbstractTableModel::flags(index) | Qt::ItemIsDragEnabled; } void ITableModel::setEditableCols(const QList cols) diff --git a/shop/data/favorititem.cpp b/shop/data/favorititem.cpp new file mode 100644 index 0000000..3d7e5e3 --- /dev/null +++ b/shop/data/favorititem.cpp @@ -0,0 +1,69 @@ +#include "favorititem.h" +#include + +FavoritItem::FavoritItem() +{ + m_id = 0; + m_vatType = Enums::NONE; + m_unitPrice = 0; +} + +int FavoritItem::id() +{ + return m_id; +} + +void FavoritItem::setId(int id) +{ + m_id = id; +} + +QString FavoritItem::name() +{ + return m_name; +} + +void FavoritItem::setName(const QString &name) +{ + m_name = name; +} + +QDecDouble FavoritItem::unitPrice() +{ + return TO_DEC(m_unitPrice); +} + +void FavoritItem::setUnitPrice(QDecDouble unitPrice) +{ + m_unitPrice = FROM_DEC(unitPrice); +} + +Enums::VatType FavoritItem::vatType() +{ + return m_vatType; +} + +void FavoritItem::setVatType(const Enums::VatType &vatType) +{ + m_vatType = vatType; +} + +QString FavoritItem::pluginId() +{ + return m_pluginId; +} + +void FavoritItem::setPluginId(const QString &pluginId) +{ + m_pluginId = pluginId; +} + +QString FavoritItem::favButtonName() const +{ + return m_favButtonName; +} + +void FavoritItem::setFavButtonName(const QString &favButtonName) +{ + m_favButtonName = favButtonName; +} diff --git a/shop/data/favorititem.h b/shop/data/favorititem.h new file mode 100644 index 0000000..c569838 --- /dev/null +++ b/shop/data/favorititem.h @@ -0,0 +1,62 @@ +#ifndef FAVORITITEM_H +#define FAVORITITEM_H + +#include +#include +#include +#include +#include +#include +#include + +class IShopItem; + +#pragma db object +class FavoritItem : public QObject, public IShopItem +{ + Q_OBJECT + + Q_PROPERTY(int id READ id WRITE setId) + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QDecDouble unitPrice READ unitPrice WRITE setUnitPrice) + Q_PROPERTY(Enums::VatType vatType READ vatType WRITE setVatType) + Q_PROPERTY(QString pluginId READ pluginId WRITE setPluginId) + Q_PROPERTY(QString favButtonName READ favButtonName WRITE setFavButtonName) + +public: + FavoritItem(); + + // IShopItem interface +public: + int id() override; + void setId(int id); + + QString name() override; + void setName(const QString &name); + + QDecDouble unitPrice() override; + void setUnitPrice(QDecDouble unitPrice); + + Enums::VatType vatType() override; + void setVatType(const Enums::VatType &vatType); + + QString pluginId() override; + void setPluginId(const QString &pluginId); + + QString favButtonName() const; + void setFavButtonName(const QString &favButtonName); + +private: + friend class odb::access; +#pragma db id auto + int m_id; + QString m_name; + int m_unitPrice; + Enums::VatType m_vatType; + QString m_pluginId; + QString m_favButtonName; +}; + +typedef QSharedPointer FavoritItemPtr; + +#endif // FAVORITITEM_H diff --git a/shop/data/shop-data.h b/shop/data/shop-data.h index 856c470..43c0f25 100644 --- a/shop/data/shop-data.h +++ b/shop/data/shop-data.h @@ -3,5 +3,6 @@ #include "voucher.h" #include "voucheritem.h" +#include "favorititem.h" #endif // SHOPDATA_H diff --git a/shop/settings/favoriteservice.cpp b/shop/settings/favoriteservice.cpp new file mode 100644 index 0000000..b90ace2 --- /dev/null +++ b/shop/settings/favoriteservice.cpp @@ -0,0 +1,6 @@ +#include "favoriteservice.h" + +FavoriteService::FavoriteService() +{ + +} diff --git a/shop/settings/favoriteservice.h b/shop/settings/favoriteservice.h new file mode 100644 index 0000000..d99648e --- /dev/null +++ b/shop/settings/favoriteservice.h @@ -0,0 +1,13 @@ +#ifndef FAVORITESERVICE_H +#define FAVORITESERVICE_H + +#include +#include "data/favorititem.h" + +class FavoriteService : public Service +{ +public: + FavoriteService(); +}; + +#endif // FAVORITESERVICE_H diff --git a/shop/settings/shopsettingsform.cpp b/shop/settings/shopsettingsform.cpp index 18c2b1d..b7280bf 100644 --- a/shop/settings/shopsettingsform.cpp +++ b/shop/settings/shopsettingsform.cpp @@ -2,6 +2,7 @@ #include "ui_shopsettingsform.h" #include +#include "shopservice.h" ShopSettingsForm::ShopSettingsForm(QWidget *parent) : FormBinder(parent), @@ -12,6 +13,8 @@ ShopSettingsForm::ShopSettingsForm(QWidget *parent) : registerBinding(ui->output); registerBinding(ui->lettersPerLine); registerBinding(ui->byMessage); + + m_itemModel = new AutoTableModel(); } ShopSettingsForm::~ShopSettingsForm() @@ -24,6 +27,10 @@ void ShopSettingsForm::loadEntity() SettingsService srv("SHOP"); ShopSettingsPtr settings = srv.loadSettings(); setEntity(settings); + + ShopService srvShop; + m_itemModel->setData(srvShop.allSellableItems()); + ui->tableItems->setModel(m_itemModel); } bool ShopSettingsForm::saveRecord() diff --git a/shop/settings/shopsettingsform.h b/shop/settings/shopsettingsform.h index 42bb46f..f46f875 100644 --- a/shop/settings/shopsettingsform.h +++ b/shop/settings/shopsettingsform.h @@ -4,6 +4,8 @@ #include #include #include "shopsettings.h" +#include +#include "shopitem.h" namespace Ui { class ShopSettingsForm; @@ -19,6 +21,7 @@ public: private: Ui::ShopSettingsForm *ui; + AutoTableModel *m_itemModel; // IForm interface public: diff --git a/shop/settings/shopsettingsform.ui b/shop/settings/shopsettingsform.ui index 405dd54..7e5b2e6 100644 --- a/shop/settings/shopsettingsform.ui +++ b/shop/settings/shopsettingsform.ui @@ -6,8 +6,8 @@ 0 0 - 608 - 450 + 645 + 463 @@ -15,42 +15,225 @@ - - - Printer + + + 0 - - - - - Output device - - - - - - - - - - Letters per line - - - - - - - - - - Footer text - - - - - - - + + + Favorite buttons + + + + + + QAbstractItemView::NoEditTriggers + + + true + + + QAbstractItemView::DragDrop + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + true + + + + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Printer + + + + + + Output device + + + + + + + + + + Letters per line + + + + + + + + + + Footer text + + + + + + + + diff --git a/shop/shop.pro b/shop/shop.pro index 8991736..665cec6 100644 --- a/shop/shop.pro +++ b/shop/shop.pro @@ -28,7 +28,9 @@ SOURCES += shop.cpp \ paydialog.cpp \ paydvouchersdialog.cpp \ shopitem.cpp \ - isellableservice.cpp + isellableservice.cpp \ + data/favorititem.cpp \ + settings/favoriteservice.cpp HEADERS += shop.h\ shop_global.h \ @@ -49,7 +51,9 @@ HEADERS += shop.h\ settings/shopsettingsform.h \ paydialog.h \ paydvouchersdialog.h \ - shopitem.h + shopitem.h \ + data/favorititem.h \ + settings/favoriteservice.h unix { target.path = /usr/lib @@ -75,6 +79,7 @@ else:unix: LIBS += -L$$OUT_PWD/../plugins/ -laddressbook INCLUDEPATH += $$PWD/../addressbook/data INCLUDEPATH += $$PWD/../addressbook +INCLUDEPATH += $$PWD/ DEPENDPATH += $$PWD/../addressbook DESTDIR = ../plugins @@ -83,7 +88,7 @@ OTHER_FILES += shop.json ODB_FILES = shop/data/shop-data.h H_DIR = $$PWD/data/*.h -ODB_OTHER_INCLUDES = -I $$PWD/../addressbook/data +ODB_OTHER_INCLUDES = -I $$PWD/../addressbook/data -I $$PWD/ include(../odb.pri) win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber diff --git a/shop/shopform.cpp b/shop/shopform.cpp index f78c431..985bca5 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -11,6 +11,8 @@ #include "isellableservice.h" #include #include +#include + #include "shop-odb.hxx" ShopForm::ShopForm(QWidget *parent) : @@ -313,3 +315,31 @@ void ShopForm::on_btnAddItem_clicked() ShopItemPtr item = m_commodityModel->itemFromIndex(ui->commodityTable->currentIndex()); addItem(item, ui->spnCount->value()); } + +void ShopForm::on_commoditySearch_textChanged(const QString &text) +{ + QSortFilterProxyModel proxy; + proxy.setSourceModel(m_commodityModel); + proxy.setFilterKeyColumn(0); + proxy.setFilterFixedString(text); + + auto moveToIndex = [this](const QModelIndex &matchingIndex) { + ui->commodityTable->scrollTo(matchingIndex,QAbstractItemView::EnsureVisible); + ui->commodityTable->setCurrentIndex(matchingIndex); + }; + + QModelIndex matchingIndex = proxy.mapToSource(proxy.index(0,0)); + if(matchingIndex.isValid()) { + moveToIndex(matchingIndex); + } + else + { + proxy.setFilterKeyColumn(1); + matchingIndex = proxy.mapToSource(proxy.index(0,0)); + + if (matchingIndex.isValid()) + { + moveToIndex(matchingIndex); + } + } +} diff --git a/shop/shopform.h b/shop/shopform.h index 301823b..d2eecd6 100644 --- a/shop/shopform.h +++ b/shop/shopform.h @@ -42,6 +42,8 @@ private slots: void on_btnAddItem_clicked(); + void on_commoditySearch_textChanged(const QString &text); + private: Ui::ShopForm *ui; QSharedPointer m_voucher; diff --git a/shop/shopform.ui b/shop/shopform.ui index 93f4c36..270547c 100644 --- a/shop/shopform.ui +++ b/shop/shopform.ui @@ -7,7 +7,7 @@ 0 0 959 - 582 + 643 @@ -131,6 +131,11 @@ + + + 10 + + Direct Sale @@ -177,7 +182,82 @@ 0 - + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + @@ -200,8 +280,96 @@ 0 + + + + + 75 + 75 + + + + ... + + + - + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + From 9e8d69827f7c723ffe6ac65fddb094a6521188c4 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Fri, 17 Feb 2017 23:13:59 +0100 Subject: [PATCH 11/14] Implemented communication with EET portal. --- shop/data/voucher.cpp | 51 +++++++++++++ shop/data/voucher.h | 34 +++++++++ shop/receiptgenerator.cpp | 6 ++ shop/settings/shopsettings.cpp | 85 +++++++++++++++++++++ shop/settings/shopsettings.h | 42 +++++++++++ shop/settings/shopsettingsform.cpp | 23 ++++++ shop/settings/shopsettingsform.h | 2 + shop/settings/shopsettingsform.ui | 117 ++++++++++++++++++++++++++++- shop/shop.json | 5 ++ shop/shop.pro | 5 ++ shop/shopform.cpp | 1 + shop/shopservice.cpp | 62 +++++++++++++++ shop/shopservice.h | 1 + 13 files changed, 433 insertions(+), 1 deletion(-) diff --git a/shop/data/voucher.cpp b/shop/data/voucher.cpp index 5ad6cf4..99cf029 100644 --- a/shop/data/voucher.cpp +++ b/shop/data/voucher.cpp @@ -16,6 +16,7 @@ Voucher::Voucher(QObject *parent) : QObject(parent) m_totalPriceVatFirstLower = 0; m_totalPriceVatSecondLower = 0; m_totalPrice = 0; + m_eetStatus = EET_FOR_SEND; } QString Voucher::name() const @@ -230,6 +231,56 @@ void Voucher::setPayDateTime(const QDateTime &payDateTime) m_payDateTime = payDateTime; } +Voucher::EetStatus Voucher::eetStatus() const +{ + return m_eetStatus; +} + +void Voucher::setEetStatus(const Voucher::EetStatus &eetStatus) +{ + m_eetStatus = eetStatus; +} + +QDateTime Voucher::eetSendDateTime() const +{ + return m_eetSendDateTime; +} + +void Voucher::setEetSendDateTime(const QDateTime &eetSendDateTime) +{ + m_eetSendDateTime = eetSendDateTime; +} + +QString Voucher::eetPkp() const +{ + return m_eetPkp; +} + +void Voucher::setEetPkp(const QString &eetPkp) +{ + m_eetPkp = eetPkp; +} + +QString Voucher::eetBkp() const +{ + return m_eetBkp; +} + +void Voucher::setEetBkp(const QString &eetBkp) +{ + m_eetBkp = eetBkp; +} + +QString Voucher::eetFik() const +{ + return m_eetFik; +} + +void Voucher::setEetFik(const QString &eetFik) +{ + m_eetFik = eetFik; +} + int Voucher::id() const { return m_id; diff --git a/shop/data/voucher.h b/shop/data/voucher.h index 36063d1..3ad0385 100644 --- a/shop/data/voucher.h +++ b/shop/data/voucher.h @@ -28,7 +28,13 @@ class Voucher : public QObject 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_PROPERTY(EetStatus eetStatus READ eetStatus WRITE setEetStatus) + Q_PROPERTY(QDateTime eetSendDateTime READ eetSendDateTime WRITE setEetSendDateTime) + Q_PROPERTY(QString eetBkp READ eetBkp WRITE setEetBkp) + Q_PROPERTY(QString eetPkp READ eetPkp WRITE setEetPkp) + Q_PROPERTY(QString eetFik READ eetFik WRITE setEetFik) Q_ENUMS(VoucherStatus) + Q_ENUMS(EetStatus) Q_PROPERTY(VoucherStatus status READ status WRITE setStatus) public: @@ -42,6 +48,14 @@ public: PAID }; + enum EetStatus + { + EET_FOR_SEND, + EET_NOT_ENTERING, + EET_SENT, + EET_ERROR + }; + int id() const; void setId(int id); @@ -110,6 +124,21 @@ public: QDateTime payDateTime() const; void setPayDateTime(const QDateTime &payDateTime); + EetStatus eetStatus() const; + void setEetStatus(const EetStatus &eetStatus); + + QDateTime eetSendDateTime() const; + void setEetSendDateTime(const QDateTime &eetSendDateTime); + + QString eetPkp() const; + void setEetPkp(const QString &eetPkp); + + QString eetBkp() const; + void setEetBkp(const QString &eetBkp); + + QString eetFik() const; + void setEetFik(const QString &eetFik); + private: friend class odb::access; #pragma db id auto @@ -131,6 +160,11 @@ private: int m_totalPriceVatFirstLower; int m_totalPriceVatSecondLower; int m_totalPrice; + EetStatus m_eetStatus; + QDateTime m_eetSendDateTime; + QString m_eetPkp; + QString m_eetBkp; + QString m_eetFik; #pragma db value_not_null inverse(m_voucher) QOdbList > m_items; VoucherStatus m_status; diff --git a/shop/receiptgenerator.cpp b/shop/receiptgenerator.cpp index 4f513e1..daeafa4 100644 --- a/shop/receiptgenerator.cpp +++ b/shop/receiptgenerator.cpp @@ -138,7 +138,13 @@ QByteArray ReceiptGenerator::generate() out.append("\x1b\x21"); out.append((char)0); out.append("\x0a"); + out.append("BKP:"); out.append("\x0a"); + out.append(prepareString(m_voucher->eetBkp())); + out.append("\x0a"); + out.append("FIK:"); + out.append("\x0a"); + out.append(prepareString(m_voucher->eetFik())); out.append("\x0a"); out.append("\x0a"); out.append("\x0a"); diff --git a/shop/settings/shopsettings.cpp b/shop/settings/shopsettings.cpp index 78064d3..38e6ad5 100644 --- a/shop/settings/shopsettings.cpp +++ b/shop/settings/shopsettings.cpp @@ -4,6 +4,11 @@ ShopSettings::ShopSettings(QObject *parent) : QObject(parent) { m_codepage = ASCII; m_lettersPerLine = 48; + + m_eetActive = false; + m_eetMode = 1; + m_eetTest = 0; + m_eetPlayground = 0; } QString ShopSettings::output() const @@ -45,3 +50,83 @@ void ShopSettings::setByMessage(const QString &byMessage) { m_byMessage = byMessage; } + +bool ShopSettings::eetActive() const +{ + return m_eetActive; +} + +void ShopSettings::setEetActive(bool eetActive) +{ + m_eetActive = eetActive; +} + +QString ShopSettings::eetShopId() const +{ + return m_eetShopId; +} + +void ShopSettings::setEetShopId(const QString &eetShopId) +{ + m_eetShopId = eetShopId; +} + +QString ShopSettings::eetRegisterId() const +{ + return m_eetRegisterId; +} + +void ShopSettings::setEetRegisterId(const QString &eetRegisterId) +{ + m_eetRegisterId = eetRegisterId; +} + +int ShopSettings::eetMode() const +{ + return m_eetMode; +} + +void ShopSettings::setEetMode(int eetMode) +{ + m_eetMode = eetMode; +} + +QString ShopSettings::eetCertificate() const +{ + return m_eetCertificate; +} + +void ShopSettings::setEetCertificate(const QString &eetCertificate) +{ + m_eetCertificate = eetCertificate; +} + +QString ShopSettings::eetKeyPassword() const +{ + return m_eetKeyPassword; +} + +void ShopSettings::setEetKeyPassword(const QString &eetKeyPassword) +{ + m_eetKeyPassword = eetKeyPassword; +} + +bool ShopSettings::eetTest() const +{ + return m_eetTest; +} + +void ShopSettings::setEetTest(bool eetTest) +{ + m_eetTest = eetTest; +} + +bool ShopSettings::eetPlayground() const +{ + return m_eetPlayground; +} + +void ShopSettings::setEetPlayground(bool eetPlayground) +{ + m_eetPlayground = eetPlayground; +} diff --git a/shop/settings/shopsettings.h b/shop/settings/shopsettings.h index acfb626..d57f892 100644 --- a/shop/settings/shopsettings.h +++ b/shop/settings/shopsettings.h @@ -9,6 +9,15 @@ class ShopSettings : public QObject Q_PROPERTY(int lettersPerLine READ lettersPerLine WRITE setLettersPerLine) Q_PROPERTY(QString byMessage READ byMessage WRITE setByMessage) + Q_PROPERTY(bool eetActive READ eetActive WRITE setEetActive) + Q_PROPERTY(QString eetShopId READ eetShopId WRITE setEetShopId) + Q_PROPERTY(QString eetRegisterId READ eetRegisterId WRITE setEetRegisterId) + Q_PROPERTY(int eetMode READ eetMode WRITE setEetMode) + Q_PROPERTY(QString eetCertificate READ eetCertificate WRITE setEetCertificate) + Q_PROPERTY(QString eetKeyPassword READ eetKeyPassword WRITE setEetKeyPassword) + Q_PROPERTY(bool eetTest READ eetTest WRITE setEetTest) + Q_PROPERTY(bool eetPlayground READ eetPlayground WRITE setEetPlayground) + Q_OBJECT public: @@ -31,11 +40,44 @@ public: QString byMessage() const; void setByMessage(const QString &byMessage); + bool eetActive() const; + void setEetActive(bool eetActive); + + QString eetShopId() const; + void setEetShopId(const QString &eetShopId); + + QString eetRegisterId() const; + void setEetRegisterId(const QString &eetRegisterId); + + int eetMode() const; + void setEetMode(int eetMode); + + QString eetCertificate() const; + void setEetCertificate(const QString &eetCertificate); + + QString eetKeyPassword() const; + void setEetKeyPassword(const QString &eetKeyPassword); + + bool eetTest() const; + void setEetTest(bool eetTest); + + bool eetPlayground() const; + void setEetPlayground(bool eetPlayground); + private: QString m_output; CODEPAGE m_codepage; int m_lettersPerLine; QString m_byMessage; + + bool m_eetActive; + QString m_eetShopId; + QString m_eetRegisterId; + int m_eetMode; + QString m_eetCertificate; + QString m_eetKeyPassword; + bool m_eetTest; + bool m_eetPlayground; }; typedef QSharedPointer ShopSettingsPtr; diff --git a/shop/settings/shopsettingsform.cpp b/shop/settings/shopsettingsform.cpp index b7280bf..b919ee9 100644 --- a/shop/settings/shopsettingsform.cpp +++ b/shop/settings/shopsettingsform.cpp @@ -2,6 +2,8 @@ #include "ui_shopsettingsform.h" #include +#include +#include #include "shopservice.h" ShopSettingsForm::ShopSettingsForm(QWidget *parent) : @@ -14,6 +16,17 @@ ShopSettingsForm::ShopSettingsForm(QWidget *parent) : registerBinding(ui->lettersPerLine); registerBinding(ui->byMessage); + registerBinding(ui->eetActive); + registerBinding(ui->eetShopId); + registerBinding(ui->eetRegisterId); + QList listModes; + listModes << ComboData(0, tr("Simplifyed")) << ComboData(1, tr("Standard")); + registerBinding(ui->eetMode, listModes); + registerBinding(ui->eetCertificate); + registerBinding(ui->eetKeyPassword); + registerBinding(ui->eetTest); + registerBinding(ui->eetPlayground); + m_itemModel = new AutoTableModel(); } @@ -41,3 +54,13 @@ bool ShopSettingsForm::saveRecord() return true; } + +void ShopSettingsForm::on_btnCertBrowse_clicked() +{ + QString certFile = QFileDialog::getOpenFileName(this, "Certificate file", "", "P12 Files (*.p12)"); + + if (!certFile.isEmpty()) + { + ui->eetCertificate->setText(certFile); + } +} diff --git a/shop/settings/shopsettingsform.h b/shop/settings/shopsettingsform.h index f46f875..ecefb41 100644 --- a/shop/settings/shopsettingsform.h +++ b/shop/settings/shopsettingsform.h @@ -29,6 +29,8 @@ public: public slots: bool saveRecord(); +private slots: + void on_btnCertBrowse_clicked(); }; #endif // SHOPSETTINGSFORM_H diff --git a/shop/settings/shopsettingsform.ui b/shop/settings/shopsettingsform.ui index 7e5b2e6..267bd7d 100644 --- a/shop/settings/shopsettingsform.ui +++ b/shop/settings/shopsettingsform.ui @@ -17,7 +17,7 @@ - 0 + 2 @@ -234,6 +234,121 @@ + + + EET + + + + + + Activate EET + + + true + + + false + + + + + + Shop ID + + + + + + + + + + Cash register ID + + + + + + + + + + EET mode + + + + + + + + + + Certificate file + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + ... + + + + + + + + + + Private key password + + + + + + + QLineEdit::Password + + + + + + + Test mode + + + + + + + Communication with playground + + + + + + + + diff --git a/shop/shop.json b/shop/shop.json index ccd3cab..62277d8 100644 --- a/shop/shop.json +++ b/shop/shop.json @@ -47,6 +47,11 @@ CREATE TABLE \"Voucher\" ( \"totalPriceVatSecondLower\" INTEGER NOT NULL, \"totalPrice\" INTEGER NOT NULL, \"status\" INTEGER NOT NULL, + \"eetStatus\" INTEGER NOT NULL, + \"eetSendDateTime\" TEXT NULL, + \"eetPkp\" TEXT, + \"eetBkp\" TEXT, + \"eetFik\" TEXT, CONSTRAINT \"contact_fk\" FOREIGN KEY (\"contact\") REFERENCES \"AddressbookData\" (\"id\") diff --git a/shop/shop.pro b/shop/shop.pro index 665cec6..9507421 100644 --- a/shop/shop.pro +++ b/shop/shop.pro @@ -113,3 +113,8 @@ FORMS += \ paydvouchersdialog.ui TRANSLATIONS = translations/shop_cs_CZ.ts + +unix|win32: LIBS += -L$$PWD/../../build-EetCpp-Desktop-Debug/libEet -lEetCpp + +INCLUDEPATH += $$PWD/../../EetCpp/libEet +DEPENDPATH += $$PWD/../../EetCpp/libEet diff --git a/shop/shopform.cpp b/shop/shopform.cpp index 4d29d80..9e5674c 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -306,6 +306,7 @@ void ShopForm::on_payButton_clicked() connect(dialog, &QDialog::accepted, [this](){ ShopService srv; srv.pay(m_voucher); + srv.processEet(m_voucher); ReceiptGenerator generator; generator.setVoucher(m_voucher); diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index 9aa6895..8d719e0 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -3,6 +3,11 @@ #include "isellableservice.h" #include "shop-odb.hxx" +#include "settings/shopsettings.h" + +#include +#include + ShopService::ShopService() { } @@ -101,6 +106,7 @@ void ShopService::pay(VoucherPtr voucher) voucher->setNumSer(numSerStr); voucher->setStatus(Voucher::PAID); + voucher->setEetStatus(Voucher::EET_FOR_SEND); voucher->setPayDateTime(QDateTime::currentDateTime()); this->update(voucher); @@ -119,6 +125,62 @@ void ShopService::updateRelatedItem(VoucherItem* item, int countAdded) selSrv->addedToVoucher(item->refId(), countAdded); } } + +void ShopService::processEet(VoucherPtr voucher) +{ + if (voucher->eetStatus() == Voucher::EET_NOT_ENTERING) + { + return; + } + + SettingsService srvSettings("SHOP"); + ShopSettingsPtr settings = srvSettings.loadSettings(); + + loadSettings(); + EetRequest request; + request.setCelkTrzba(voucher->totalPrice().toDouble()); + request.setDatTrzby(voucher->payDateTime()); + request.setIdPokl(settings->eetRegisterId()); + request.setIdProvoz(settings->eetShopId()); + request.setPrvniZaslani(voucher->eetStatus() == Voucher::EET_FOR_SEND); + request.setDicPopl(m_gs->dic()); + request.setPoradCis(voucher->numSer()); + request.setDatOdesl(QDateTime::currentDateTime()); + request.setRezim((EetRequest::EetRezim)settings->eetMode()); + + EetSender *sender = new EetSender(this); + sender->setupSigner(settings->eetCertificate(), settings->eetKeyPassword()); + sender->setPlayground(settings->eetPlayground()); + + QEventLoop loop; + + connect(sender, &EetSender::sendFinished, [this, voucher, sender, &loop](){ + Transaction tx; + + if (sender->resut()->status() == EetResult::RESPONSE_OK) + { + voucher->setEetBkp(sender->resut()->bkp()); + voucher->setEetPkp(sender->resut()->pkp()); + voucher->setEetFik(sender->resut()->fik()); + voucher->setEetSendDateTime(QDateTime::currentDateTime()); + voucher->setEetStatus(Voucher::EET_SENT); + } + else + { + voucher->setEetStatus(Voucher::EET_ERROR); + } + + this->update(voucher); + tx.commit(); + sender->deleteLater(); + + loop.quit(); + }); + + sender->sendRequest(&request); + loop.exec(); +} + void ShopService::moveItems(QList items, VoucherPtr source, VoucherPtr target) { Transaction tx; diff --git a/shop/shopservice.h b/shop/shopservice.h index e4b5bf6..55e6189 100644 --- a/shop/shopservice.h +++ b/shop/shopservice.h @@ -21,6 +21,7 @@ public: void pay(VoucherPtr voucher); void moveItems(QList items, VoucherPtr source, VoucherPtr target); void updateRelatedItem(VoucherItem* item, int countAdded); + void processEet(VoucherPtr voucher); QList savedVouchers(); QList tempVouchers(); QList paiedVouchers(); From ec16d90fa4f851a2f8ec75b4108b90fb9bc86659 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Tue, 21 Feb 2017 20:37:38 +0100 Subject: [PATCH 12/14] Fixed voucher saving. closes #274 --- shop/receiptsaveform.cpp | 17 ++++++++++++++++- shop/receiptsaveform.h | 5 ++++- shop/shopform.cpp | 40 +++++++++++++++++++++++++++++++--------- shop/shopservice.cpp | 35 ++++++++++++++++++++++++++++++----- shop/shopservice.h | 3 ++- 5 files changed, 83 insertions(+), 17 deletions(-) diff --git a/shop/receiptsaveform.cpp b/shop/receiptsaveform.cpp index 8106eb4..a2dc864 100644 --- a/shop/receiptsaveform.cpp +++ b/shop/receiptsaveform.cpp @@ -45,7 +45,7 @@ ReceiptSaveForm::ReceiptSaveForm(QSharedPointer voucher, QWidget *paren ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty()); }); - m_binder.setData(new Voucher); + m_binder.setData(voucher.data()); AddressBookService srvAdb; m_binder.registerBinding(ui->contact, ComboData::createComboData(srvAdb.all())); m_binder.registerBinding(ui->name); @@ -66,6 +66,21 @@ ReceiptSaveForm::~ReceiptSaveForm() delete ui; } +VoucherPtr ReceiptSaveForm::selectedVoucher() +{ + if (ui->tabVouchers->currentIndex().isValid()) + { + return m_voucherModel->itemFromIndex(ui->tabVouchers->currentIndex()); + } + + return VoucherPtr(); +} + +bool ReceiptSaveForm::saveAsNew() +{ + return m_saveAsNew; +} + void ReceiptSaveForm::on_lineEdit_textChanged(const QString &text) { QSortFilterProxyModel proxy; diff --git a/shop/receiptsaveform.h b/shop/receiptsaveform.h index 663f3c4..09e6175 100644 --- a/shop/receiptsaveform.h +++ b/shop/receiptsaveform.h @@ -18,6 +18,9 @@ public: explicit ReceiptSaveForm(QSharedPointer voucher, QWidget *parent = 0); ~ReceiptSaveForm(); + VoucherPtr selectedVoucher(); + bool saveAsNew(); + private slots: void on_lineEdit_textChanged(const QString &text); @@ -28,7 +31,7 @@ private: ObjectBinder m_binder; AutoTableModel *m_voucherModel; bool m_saveAsNew; - QSharedPointer m_voucher; + VoucherPtr m_voucher; // QDialog interface public slots: diff --git a/shop/shopform.cpp b/shop/shopform.cpp index 9e5674c..1ed3c1f 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -54,9 +54,13 @@ void ShopForm::loadLast() connectItemSignals(); ui->total->setText(QString::number(m_voucher->totalPrice().toDouble(), 'f', 2)); - ui->temporarySaveButton->setEnabled(true); - ui->saveButton->setEnabled(true); - ui->payButton->setEnabled(true); + + if (!m_voucher->items().isEmpty()) + { + ui->temporarySaveButton->setEnabled(true); + ui->saveButton->setEnabled(true); + ui->payButton->setEnabled(true); + } } if (m_commodityModel == NULL) @@ -119,13 +123,25 @@ void ShopForm::on_saveButton_clicked() ReceiptSaveForm *form = new ReceiptSaveForm(m_voucher, this); form->setAttribute(Qt::WA_DeleteOnClose); - connect(form, &QDialog::accepted, [this]() { + connect(form, &QDialog::accepted, [this, form]() { ShopService srv; - m_voucher->setStatus(Voucher::NOT_PAID); - srv.saveVoucher(m_voucher); - m_voucher = srv.createVoucher(); + + if (form->saveAsNew()) + { + m_voucher->setStatus(Voucher::NOT_PAID); + srv.saveVoucher(m_voucher); + createEmptyVoucher(); + } + else + { + VoucherPtr selVoucher = form->selectedVoucher(); + srv.moveItems(m_voucher->items(), m_voucher, selVoucher); + srv.calculate(selVoucher); + srv.updateVoucher(selVoucher); + createEmptyVoucher(); + } + m_itemsModel->setData(m_voucher->items()); - ui->total->setText("0"); }); form->show(); @@ -306,7 +322,13 @@ void ShopForm::on_payButton_clicked() connect(dialog, &QDialog::accepted, [this](){ ShopService srv; srv.pay(m_voucher); - srv.processEet(m_voucher); + QString eetMsg; + bool eetRet = srv.processEet(m_voucher, eetMsg); + + if (!eetRet) + { + + } ReceiptGenerator generator; generator.setVoucher(m_voucher); diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index 8d719e0..5055c4d 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -126,11 +126,11 @@ void ShopService::updateRelatedItem(VoucherItem* item, int countAdded) } } -void ShopService::processEet(VoucherPtr voucher) +bool ShopService::processEet(VoucherPtr voucher, QString message) { if (voucher->eetStatus() == Voucher::EET_NOT_ENTERING) { - return; + return true; } SettingsService srvSettings("SHOP"); @@ -157,11 +157,12 @@ void ShopService::processEet(VoucherPtr voucher) connect(sender, &EetSender::sendFinished, [this, voucher, sender, &loop](){ Transaction tx; + voucher->setEetBkp(sender->resut()->bkp()); + voucher->setEetPkp(sender->resut()->pkp()); + voucher->setEetFik(sender->resut()->fik()); + if (sender->resut()->status() == EetResult::RESPONSE_OK) { - voucher->setEetBkp(sender->resut()->bkp()); - voucher->setEetPkp(sender->resut()->pkp()); - voucher->setEetFik(sender->resut()->fik()); voucher->setEetSendDateTime(QDateTime::currentDateTime()); voucher->setEetStatus(Voucher::EET_SENT); } @@ -179,6 +180,30 @@ void ShopService::processEet(VoucherPtr voucher) sender->sendRequest(&request); loop.exec(); + + auto addMessage = [&message](EetMessage *msg, const QString &label){ + if (message.isEmpty()) + { + message = label + "\n"; + } + + message += QString::number(msg->code()) + ": " + msg->message(); + }; + + foreach (EetMessage *msg, sender->resut()->errors()) { + addMessage(msg, "Errors:"); + } + + foreach (EetMessage *msg, sender->resut()->warnings()) { + addMessage(msg, "Warnings:"); + } + + return voucher->eetStatus() == Voucher::EET_SENT; +} + +void ShopService::setEetOnline(bool online) +{ + EetSender::m_online = online; } void ShopService::moveItems(QList items, VoucherPtr source, VoucherPtr target) diff --git a/shop/shopservice.h b/shop/shopservice.h index 55e6189..29e58c7 100644 --- a/shop/shopservice.h +++ b/shop/shopservice.h @@ -21,7 +21,8 @@ public: void pay(VoucherPtr voucher); void moveItems(QList items, VoucherPtr source, VoucherPtr target); void updateRelatedItem(VoucherItem* item, int countAdded); - void processEet(VoucherPtr voucher); + bool processEet(VoucherPtr voucher, QString message); + void setEetOnline(bool online); QList savedVouchers(); QList tempVouchers(); QList paiedVouchers(); From 954f6553630bce8365fd2c9a16aa8874b5f6474d Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Tue, 21 Feb 2017 22:15:43 +0100 Subject: [PATCH 13/14] Implemented "EET switch to offline" feature. --- shop/shopform.cpp | 13 +++++++++++++ shop/shopservice.cpp | 17 ++++++++++++++--- shop/shopservice.h | 3 ++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/shop/shopform.cpp b/shop/shopform.cpp index 1ed3c1f..cd02c6d 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include "shop-odb.hxx" @@ -327,7 +328,19 @@ void ShopForm::on_payButton_clicked() if (!eetRet) { + QString errMsg = tr("EET communication error.\n"); + if (!eetMsg.isEmpty()) + { + errMsg += tr("Message from portal: ") + eetMsg + "\n"; + } + + errMsg += tr("Switch to offline?"); + + if (srv.isEetOnline() && QMessageBox::question(this, tr("EET error"), errMsg) == QMessageBox::Yes) + { + srv.setEetOnline(false); + } } ReceiptGenerator generator; diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index 5055c4d..2b515be 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -126,7 +126,7 @@ void ShopService::updateRelatedItem(VoucherItem* item, int countAdded) } } -bool ShopService::processEet(VoucherPtr voucher, QString message) +bool ShopService::processEet(VoucherPtr voucher, QString &message) { if (voucher->eetStatus() == Voucher::EET_NOT_ENTERING) { @@ -153,8 +153,9 @@ bool ShopService::processEet(VoucherPtr voucher, QString message) sender->setPlayground(settings->eetPlayground()); QEventLoop loop; + bool replyFinished = false; - connect(sender, &EetSender::sendFinished, [this, voucher, sender, &loop](){ + connect(sender, &EetSender::sendFinished, [this, voucher, sender, &loop, &replyFinished](){ Transaction tx; voucher->setEetBkp(sender->resut()->bkp()); @@ -176,10 +177,15 @@ bool ShopService::processEet(VoucherPtr voucher, QString message) sender->deleteLater(); loop.quit(); + replyFinished = true; }); sender->sendRequest(&request); - loop.exec(); + + if (!replyFinished) + { + loop.exec(); + } auto addMessage = [&message](EetMessage *msg, const QString &label){ if (message.isEmpty()) @@ -206,6 +212,11 @@ void ShopService::setEetOnline(bool online) EetSender::m_online = online; } +bool ShopService::isEetOnline() +{ + return EetSender::m_online; +} + void ShopService::moveItems(QList items, VoucherPtr source, VoucherPtr target) { Transaction tx; diff --git a/shop/shopservice.h b/shop/shopservice.h index 29e58c7..b3bb095 100644 --- a/shop/shopservice.h +++ b/shop/shopservice.h @@ -21,8 +21,9 @@ public: void pay(VoucherPtr voucher); void moveItems(QList items, VoucherPtr source, VoucherPtr target); void updateRelatedItem(VoucherItem* item, int countAdded); - bool processEet(VoucherPtr voucher, QString message); + bool processEet(VoucherPtr voucher, QString &message); void setEetOnline(bool online); + bool isEetOnline(); QList savedVouchers(); QList tempVouchers(); QList paiedVouchers(); From 402535c40c60ea8f3c50b80c9aebdd032f014ac4 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Thu, 23 Feb 2017 22:50:01 +0100 Subject: [PATCH 14/14] Implemented EET batch send. closes #275 --- shop/eetbatchdialog.cpp | 19 ++++++++ shop/eetbatchdialog.h | 23 ++++++++++ shop/eetbatchdialog.ui | 74 +++++++++++++++++++++++++++++++ shop/icons/sendEet.svg | 8 ++++ shop/paydvouchersdialog.cpp | 71 ++++++++++++++++++++++++++++++ shop/paydvouchersdialog.h | 4 ++ shop/paydvouchersdialog.ui | 87 ++++++++++++++++++++++++++++++++++++- shop/shop.json | 5 ++- shop/shop.pro | 9 ++-- shop/shopform.cpp | 24 +++++----- shop/shoprc.qrc | 1 + shop/shopservice.cpp | 13 ++++++ shop/shopservice.h | 2 + 13 files changed, 324 insertions(+), 16 deletions(-) create mode 100644 shop/eetbatchdialog.cpp create mode 100644 shop/eetbatchdialog.h create mode 100644 shop/eetbatchdialog.ui create mode 100644 shop/icons/sendEet.svg diff --git a/shop/eetbatchdialog.cpp b/shop/eetbatchdialog.cpp new file mode 100644 index 0000000..59232e4 --- /dev/null +++ b/shop/eetbatchdialog.cpp @@ -0,0 +1,19 @@ +#include "eetbatchdialog.h" +#include "ui_eetbatchdialog.h" + +EetBatchDialog::EetBatchDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::EetBatchDialog) +{ + ui->setupUi(this); +} + +EetBatchDialog::~EetBatchDialog() +{ + delete ui; +} + +void EetBatchDialog::addLog(const QString &log) +{ + ui->logView->setPlainText(ui->logView->toPlainText() + log); +} diff --git a/shop/eetbatchdialog.h b/shop/eetbatchdialog.h new file mode 100644 index 0000000..9c15fba --- /dev/null +++ b/shop/eetbatchdialog.h @@ -0,0 +1,23 @@ +#ifndef EETBATCHDIALOG_H +#define EETBATCHDIALOG_H + +#include + +namespace Ui { +class EetBatchDialog; +} + +class EetBatchDialog : public QDialog +{ + Q_OBJECT + +public: + explicit EetBatchDialog(QWidget *parent = 0); + ~EetBatchDialog(); + void addLog(const QString &log); + +private: + Ui::EetBatchDialog *ui; +}; + +#endif // EETBATCHDIALOG_H diff --git a/shop/eetbatchdialog.ui b/shop/eetbatchdialog.ui new file mode 100644 index 0000000..2a6bd2e --- /dev/null +++ b/shop/eetbatchdialog.ui @@ -0,0 +1,74 @@ + + + EetBatchDialog + + + + 0 + 0 + 324 + 272 + + + + EET batch send + + + true + + + + + + true + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + + buttonBox + accepted() + EetBatchDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + EetBatchDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/shop/icons/sendEet.svg b/shop/icons/sendEet.svg new file mode 100644 index 0000000..ce6a617 --- /dev/null +++ b/shop/icons/sendEet.svg @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/shop/paydvouchersdialog.cpp b/shop/paydvouchersdialog.cpp index 9bca5d7..b4ee136 100644 --- a/shop/paydvouchersdialog.cpp +++ b/shop/paydvouchersdialog.cpp @@ -5,6 +5,7 @@ #include "receiptgenerator.h" #include "shopservice.h" +#include "eetbatchdialog.h" PaydVouchersDialog::PaydVouchersDialog(QWidget *parent) : QDialog(parent), @@ -14,10 +15,30 @@ PaydVouchersDialog::PaydVouchersDialog(QWidget *parent) : m_voucherModel = new AutoTableModel(this); m_itemModel = new AutoTableModel(this); + m_voucherModel->setTranslations(Context::instance().plugin("SHOP")->translations()); + m_itemModel->setTranslations(Context::instance().plugin("SHOP")->translations()); ui->tableVouchers->setModel(m_voucherModel); ui->tableItems->setModel(m_itemModel); + ui->tableVouchers->setColumnHidden(5, true); + ui->tableVouchers->setColumnHidden(6, true); + ui->tableVouchers->setColumnHidden(7, true); + ui->tableVouchers->setColumnHidden(8, true); + ui->tableVouchers->setColumnHidden(9, true); + ui->tableVouchers->setColumnHidden(10, true); + ui->tableVouchers->setColumnHidden(12, true); + ui->tableVouchers->setColumnHidden(13, true); + ui->tableVouchers->setColumnHidden(14, true); + ui->tableVouchers->setColumnHidden(15, true); + ui->tableVouchers->setColumnHidden(16, true); + ui->tableVouchers->setColumnHidden(17, true); + ui->tableVouchers->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); + ui->tableVouchers->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Stretch); + ui->tableVouchers->horizontalHeader()->setSectionResizeMode(4, QHeaderView::Stretch); + + ui->tableItems->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); + ShopService srv; m_voucherModel->setData(srv.paiedVouchers()); @@ -27,6 +48,23 @@ PaydVouchersDialog::PaydVouchersDialog(QWidget *parent) : m_itemModel->setData(voucher->items()); ui->total->setText(QString::number(voucher->totalPrice().toDouble(), 'f', 2)); + switch (voucher->eetStatus()) { + case Voucher::EET_NOT_ENTERING: + ui->lblEetStatus->setText(tr("not entering")); + break; + case Voucher::EET_FOR_SEND: + ui->lblEetStatus->setText(tr("for send")); + break; + case Voucher::EET_ERROR: + ui->lblEetStatus->setText(tr("error")); + break; + case Voucher::EET_SENT: + ui->lblEetStatus->setText(tr("sent")); + break; + default: + break; + } + ui->btnPrint->setEnabled(true); ui->btnSave->setEnabled(true); }); @@ -59,3 +97,36 @@ void PaydVouchersDialog::on_btnSave_clicked() generator.save(); } } + +void PaydVouchersDialog::on_btnEetNotSen_clicked(bool checked) +{ + ShopService srv; + + if (checked) + { + m_voucherModel->setData(srv.vouchersForEet()); + } + else + { + m_voucherModel->setData(srv.paiedVouchers()); + } + + m_itemModel->setData(QList()); +} + +void PaydVouchersDialog::on_btnSendEet_clicked() +{ + ShopService srv; + QList vouchers = srv.vouchersForEet(); + EetBatchDialog *dialog = new EetBatchDialog(this); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); + + foreach (VoucherPtr vch, vouchers) { + QString msg; + bool sent = srv.processEet(vch, msg); + dialog->addLog(vch->numSer() + ": "); + dialog->addLog(sent ? "OK\n" : tr("Error")); + dialog->addLog((msg.isEmpty() && !sent) ? "\n" : ": " + msg); + } +} diff --git a/shop/paydvouchersdialog.h b/shop/paydvouchersdialog.h index 973e3f0..9c8f5bf 100644 --- a/shop/paydvouchersdialog.h +++ b/shop/paydvouchersdialog.h @@ -24,6 +24,10 @@ private slots: void on_btnSave_clicked(); + void on_btnEetNotSen_clicked(bool checked); + + void on_btnSendEet_clicked(); + private: Ui::PaydVouchersDialog *ui; diff --git a/shop/paydvouchersdialog.ui b/shop/paydvouchersdialog.ui index 8512420..feeb4dd 100644 --- a/shop/paydvouchersdialog.ui +++ b/shop/paydvouchersdialog.ui @@ -6,8 +6,8 @@ 0 0 - 798 - 514 + 900 + 650 @@ -72,6 +72,49 @@ + + + + ... + + + + :/icons/filter.svg:/icons/filter.svg + + + + 32 + 32 + + + + true + + + true + + + + + + + ... + + + + :/icons/sendEet.svg:/icons/sendEet.svg + + + + 32 + 32 + + + + true + + + @@ -90,6 +133,12 @@ + + + 0 + 300 + + QAbstractItemView::SingleSelection @@ -110,6 +159,39 @@ + + + + + + + EET: + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + @@ -167,6 +249,7 @@ + diff --git a/shop/shop.json b/shop/shop.json index 62277d8..8b9be10 100644 --- a/shop/shop.json +++ b/shop/shop.json @@ -74,6 +74,7 @@ CREATE TABLE \"Voucher\" ( "vatRateHigh" : "Vysoká sazba", "vatRateFirstLower" : "První snížená sazba", "vatRateSecondLower" : "Druhá snížená sazba", + "vatAmount" : "Dan", "priceNoVat" : "Cena zboží s nulovou DPH", "priceVatHigh" : "Cena zboží s vysokou sazbou DPH", "priceVatFirstLower" : "Cena zboží s první sníženou sazbou DPH", @@ -83,7 +84,9 @@ CREATE TABLE \"Voucher\" ( "totalPriceVatFirstLower" : "Celková cena zboží s první sníženou sazbou DPH", "totalPriceVatSecondLower" : "Celková cena zboží s druhou sníženou sazbou DPH", "totalPrice" : "Celková cena", - "status" : "Stav" + "status" : "Stav", + "numSer" : "Číslo", + "payDateTime" : "Datum" } } } diff --git a/shop/shop.pro b/shop/shop.pro index 9507421..5ec558b 100644 --- a/shop/shop.pro +++ b/shop/shop.pro @@ -30,7 +30,8 @@ SOURCES += shop.cpp \ shopitem.cpp \ isellableservice.cpp \ data/favorititem.cpp \ - settings/favoriteservice.cpp + settings/favoriteservice.cpp \ + eetbatchdialog.cpp HEADERS += shop.h\ shop_global.h \ @@ -53,7 +54,8 @@ HEADERS += shop.h\ paydvouchersdialog.h \ shopitem.h \ data/favorititem.h \ - settings/favoriteservice.h + settings/favoriteservice.h \ + eetbatchdialog.h unix { target.path = /usr/lib @@ -110,7 +112,8 @@ FORMS += \ receiptloadform.ui \ settings/shopsettingsform.ui \ paydialog.ui \ - paydvouchersdialog.ui + paydvouchersdialog.ui \ + eetbatchdialog.ui TRANSLATIONS = translations/shop_cs_CZ.ts diff --git a/shop/shopform.cpp b/shop/shopform.cpp index cd02c6d..5a2b756 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -324,22 +324,26 @@ void ShopForm::on_payButton_clicked() ShopService srv; srv.pay(m_voucher); QString eetMsg; - bool eetRet = srv.processEet(m_voucher, eetMsg); - if (!eetRet) + if (srv.isEetEnabled()) { - QString errMsg = tr("EET communication error.\n"); + bool eetRet = srv.processEet(m_voucher, eetMsg); - if (!eetMsg.isEmpty()) + if (!eetRet) { - errMsg += tr("Message from portal: ") + eetMsg + "\n"; - } + QString errMsg = tr("EET communication error.\n"); - errMsg += tr("Switch to offline?"); + if (!eetMsg.isEmpty()) + { + errMsg += tr("Message from portal: ") + eetMsg + "\n"; + } - if (srv.isEetOnline() && QMessageBox::question(this, tr("EET error"), errMsg) == QMessageBox::Yes) - { - srv.setEetOnline(false); + errMsg += tr("Switch to offline?"); + + if (srv.isEetOnline() && QMessageBox::question(this, tr("EET error"), errMsg) == QMessageBox::Yes) + { + srv.setEetOnline(false); + } } } diff --git a/shop/shoprc.qrc b/shop/shoprc.qrc index 77a3ead..6a447f7 100644 --- a/shop/shoprc.qrc +++ b/shop/shoprc.qrc @@ -5,5 +5,6 @@ icons/tempSave.svg icons/paied.svg icons/pay.svg + icons/sendEet.svg diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index 2b515be..8af8217 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -217,6 +217,13 @@ bool ShopService::isEetOnline() return EetSender::m_online; } +bool ShopService::isEetEnabled() +{ + SettingsService srvSettings("SHOP"); + ShopSettingsPtr settings = srvSettings.loadSettings(); + return settings->eetActive(); +} + void ShopService::moveItems(QList items, VoucherPtr source, VoucherPtr target) { Transaction tx; @@ -259,6 +266,12 @@ QList ShopService::paiedVouchers() return all(QString("status = %1").arg(QString::number(Voucher::PAID))); } +QList ShopService::vouchersForEet() +{ + return all(QString("status = %1 AND eetStatus <> %2 AND eetStatus <> %3") + .arg(QString::number(Voucher::PAID), QString::number(Voucher::EET_SENT), QString::number(Voucher::EET_NOT_ENTERING))); +} + QList ShopService::allSellableItems() { QList > items; diff --git a/shop/shopservice.h b/shop/shopservice.h index b3bb095..2a622bb 100644 --- a/shop/shopservice.h +++ b/shop/shopservice.h @@ -24,9 +24,11 @@ public: bool processEet(VoucherPtr voucher, QString &message); void setEetOnline(bool online); bool isEetOnline(); + bool isEetEnabled(); QList savedVouchers(); QList tempVouchers(); QList paiedVouchers(); + QList vouchersForEet(); QList allSellableItems(); private: