diff --git a/config_plugin.pri b/config_plugin.pri index 2552b0c..c9f90d2 100644 --- a/config_plugin.pri +++ b/config_plugin.pri @@ -17,6 +17,7 @@ else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../core/debug/ -lco else:unix: LIBS += -L$$OUT_PWD/../core/ -lcore INCLUDEPATH += $$PWD/core +INCLUDEPATH += $$PWD/core/data DEPENDPATH += $$PWD/core win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber diff --git a/core/numberseriesservice.cpp b/core/numberseriesservice.cpp index ecd121c..0d7204a 100644 --- a/core/numberseriesservice.cpp +++ b/core/numberseriesservice.cpp @@ -51,3 +51,12 @@ QList > NumberSeriesService::allForSeason(QSharedPo { return all(QString("season = %1").arg(QString::number(season->id()))); } + +QString NumberSeriesService::nextStrForPlugin(QString pluginId) +{ + NumberSeriesPtr numSer = nextForPlugin(pluginId); + QString numSerStr; + numSerStr.sprintf("%s%05d", numSer->prefix().toStdString().c_str(), numSer->lastNumber()); + + return numSerStr; +} diff --git a/core/numberseriesservice.h b/core/numberseriesservice.h index d2e1ed0..e97e477 100644 --- a/core/numberseriesservice.h +++ b/core/numberseriesservice.h @@ -15,6 +15,7 @@ public: QSharedPointer forPlugin(QString pluginId); QSharedPointer nextForPlugin(QString pluginId); QList > allForSeason(QSharedPointer season); + QString nextStrForPlugin(QString pluginId); }; #endif // NUMBERSERIESSERVICE_H diff --git a/odb.pri b/odb.pri index 44fb68f..c778674 100644 --- a/odb.pri +++ b/odb.pri @@ -45,6 +45,7 @@ DEFINES += DATABASE_SQLITE ODB_FLAGS += -I $$[QT_INSTALL_HEADERS] ODB_FLAGS += -I $$[QT_INSTALL_HEADERS]/QtCore ODB_FLAGS += -I $$PWD/core +ODB_FLAGS += -I $$PWD/core/data ODB_FLAGS += -I $$PWD/qdecimal/src ODB_FLAGS += -I $$PWD/qdecimal/decnumber ODB_FLAGS += $$ODB_OTHER_INCLUDES diff --git a/shop/data/voucher.cpp b/shop/data/voucher.cpp index 4a8f5be..e656ccd 100644 --- a/shop/data/voucher.cpp +++ b/shop/data/voucher.cpp @@ -291,6 +291,16 @@ void Voucher::setSaveDateTime(const QDateTime &saveDateTime) m_saveDateTime = saveDateTime; } +SeasonPtr Voucher::season() const +{ + return m_season; +} + +void Voucher::setSeason(const SeasonPtr &season) +{ + m_season = season; +} + int Voucher::id() const { return m_id; diff --git a/shop/data/voucher.h b/shop/data/voucher.h index 70ee1a0..d4108ad 100644 --- a/shop/data/voucher.h +++ b/shop/data/voucher.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -143,6 +144,9 @@ public: QDateTime saveDateTime() const; void setSaveDateTime(const QDateTime &saveDateTime); + SeasonPtr season() const; + void setSeason(const SeasonPtr &season); + private: friend class odb::access; #pragma db id auto @@ -173,6 +177,7 @@ private: #pragma db value_not_null inverse(m_voucher) QOdbList > m_items; VoucherStatus m_status; + SeasonPtr m_season; }; typedef QSharedPointer VoucherPtr; diff --git a/shop/shop.json b/shop/shop.json index f0087a2..63efeee 100644 --- a/shop/shop.json +++ b/shop/shop.json @@ -8,7 +8,7 @@ "default" : "", "CZ" : "" }, - "schemaVersion" : 5, + "schemaVersion" : 6, "sql" : [ "CREATE TABLE \"VoucherItem\" ( \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, @@ -72,6 +72,10 @@ CREATE TABLE \"Voucher\" ( \"favButtonName\" TEXT NULL); ", "ALTER TABLE \"FavoritItem\" ADD \"shortName\" TEXT NULL; +", + +"ALTER TABLE \"Voucher\" ADD \"season\" INTEGER NULL; +UPDATE \"Voucher\" SET season = (SELECT id FROM \"Season\" WHERE active = 1); " ], "dependencies" : [ "ADDRESSBOOK" ], diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index b528ae4..74dec20 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -7,6 +7,7 @@ #include #include +#include ShopService::ShopService() { @@ -101,11 +102,7 @@ void ShopService::pay(VoucherPtr voucher) Transaction tx; NumberSeriesService srvNs; - NumberSeriesPtr numSer = srvNs.nextForPlugin("SHOP"); - QString numSerStr; - numSerStr.sprintf("%s%05d", numSer->prefix().toStdString().c_str(), numSer->lastNumber()); - - voucher->setNumSer(numSerStr); + voucher->setNumSer(srvNs.nextStrForPlugin("SHOP")); voucher->setStatus(Voucher::PAID); voucher->setEetStatus(Voucher::EET_FOR_SEND); voucher->setPayDateTime(QDateTime::currentDateTime()); @@ -345,6 +342,10 @@ QDecDouble ShopService::vatRate(Enums::VatType vatType) void ShopService::saveVoucher(VoucherPtr entity) { + SeasonService seasonSrv; + SeasonPtr season = seasonSrv.active(); + entity->setSeason(season); + Transaction tr; odb::database *db = Context::instance().db();