diff --git a/core/define.h b/core/define.h index 850b245..74647ff 100644 --- a/core/define.h +++ b/core/define.h @@ -10,6 +10,8 @@ #define PERM_DELETE "DELETE" #define DEC_MULTIPLE 100 +#define TO_DEC(num) QDecDouble((double)num / DEC_MULTIPLE) +#define FROM_DEC(num) num.toDouble() * DEC_MULTIPLE #endif // DEFINE_H diff --git a/odb.pri b/odb.pri index 146fac5..5459420 100644 --- a/odb.pri +++ b/odb.pri @@ -18,7 +18,7 @@ unix { LIBS += -lodb -lodb-sqlite -lodb-qt } -ODB_FLAGS = --database sqlite --profile qt --generate-schema --generate-query --generate-session --at-once --input-name $$TARGET --schema-format sql +ODB_FLAGS += --database sqlite --profile qt --generate-schema --generate-query --generate-session --at-once --input-name $$TARGET --schema-format sql win32 { ODB_PATH = d:\prac\odb\odb-2.4.0-i686-windows\bin\odb @@ -45,6 +45,7 @@ ODB_FLAGS += -I $$[QT_INSTALL_HEADERS]/QtCore 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__ win32 { diff --git a/shop/data/shop-data.h b/shop/data/shop-data.h new file mode 100644 index 0000000..856c470 --- /dev/null +++ b/shop/data/shop-data.h @@ -0,0 +1,7 @@ +#ifndef SHOPDATA_H +#define SHOPDATA_H + +#include "voucher.h" +#include "voucheritem.h" + +#endif // SHOPDATA_H diff --git a/shop/data/voucher.cpp b/shop/data/voucher.cpp index 9742720..83f64b0 100644 --- a/shop/data/voucher.cpp +++ b/shop/data/voucher.cpp @@ -1,6 +1,90 @@ #include "voucher.h" +#include Voucher::Voucher(QObject *parent) : QObject(parent) { } + +QString Voucher::name() const +{ + return m_name; +} + +void Voucher::setName(const QString &name) +{ + m_name = name; +} + +QString Voucher::description() const +{ + return m_description; +} + +void Voucher::setDescription(const QString &description) +{ + m_description = description; +} + +QSharedPointer Voucher::contact() const +{ + return m_contact; +} + +void Voucher::setContact(const QSharedPointer &contact) +{ + if (qobject_cast(contact.data()) != NULL) + { + m_contact = qSharedPointerDynamicCast(contact); + } +} + +Voucher::VoucherStatus Voucher::status() const +{ + return m_status; +} + +void Voucher::setStatus(const Voucher::VoucherStatus &status) +{ + m_status = status; +} + +QDecDouble Voucher::totalPrice() const +{ + return TO_DEC(m_totalPrice); +} + +void Voucher::setTotalPrice(QDecDouble totalPrice) +{ + m_totalPrice = FROM_DEC(totalPrice); +} + +QList > Voucher::items() const +{ + return m_items; +} + +void Voucher::setItems(const QList > &items) +{ + m_items = items; +} + +void Voucher::addItem(QSharedPointer item) +{ + m_items.append(item); +} + +void Voucher::clearItems() +{ + m_items.clear(); +} + +int Voucher::id() const +{ + return m_id; +} + +void Voucher::setId(int id) +{ + m_id = id; +} diff --git a/shop/data/voucher.h b/shop/data/voucher.h index 83feb23..db4e380 100644 --- a/shop/data/voucher.h +++ b/shop/data/voucher.h @@ -2,16 +2,72 @@ #define VOUCHER_H #include +#include +#include +#include +#include +#include +#include +#include "voucheritem.h" + +#pragma db object class Voucher : public QObject { Q_OBJECT + + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString description READ description WRITE setDescription) + Q_PROPERTY(QSharedPointer contact READ contact WRITE setContact) + Q_PROPERTY(QDecDouble totalPrice READ totalPrice WRITE setTotalPrice) + Q_ENUMS(VoucherStatus) + Q_PROPERTY(VoucherStatus status READ status WRITE setStatus) + public: explicit Voucher(QObject *parent = 0); -signals: + enum VoucherStatus + { + NEW, + TEMPORARY, + NOT_PAID, + PAID + }; + + int id() const; + void setId(int id); + + QString name() const; + void setName(const QString &name); + + QString description() const; + void setDescription(const QString &description); + + QSharedPointer contact() const; + void setContact(const QSharedPointer &contact); + + VoucherStatus status() const; + void setStatus(const VoucherStatus &status); + + QDecDouble totalPrice() const; + void setTotalPrice(QDecDouble totalPrice); + + QList > items() const; + void setItems(const QList > &items); + + void addItem(QSharedPointer item); + void clearItems(); -public slots: +private: + friend class odb::access; +#pragma db id auto + int m_id; + QString m_name; + QString m_description; + QSharedPointer m_contact; + int m_totalPrice; + QOdbList > m_items; + VoucherStatus m_status; }; -#endif // VOUCHER_H \ No newline at end of file +#endif // VOUCHER_H diff --git a/shop/data/voucheritem.cpp b/shop/data/voucheritem.cpp new file mode 100644 index 0000000..353f255 --- /dev/null +++ b/shop/data/voucheritem.cpp @@ -0,0 +1,87 @@ +#include "voucheritem.h" +#include + +VoucherItem::VoucherItem(QObject *parent) : QObject(parent) +{ + +} + +int VoucherItem::id() const +{ + return m_id; +} + +void VoucherItem::setId(int id) +{ + m_id = id; +} + +QString VoucherItem::name() const +{ + return m_name; +} + +void VoucherItem::setName(const QString &name) +{ + m_name = name; +} + +int VoucherItem::count() const +{ + return m_count; +} + +void VoucherItem::setCount(int count) +{ + m_count = count; +} + +QDecDouble VoucherItem::unitPrice() const +{ + return TO_DEC(m_unitPrice); +} + +void VoucherItem::setUnitPrice(QDecDouble unitPrice) +{ + m_unitPrice = FROM_DEC(unitPrice); +} + +QDecDouble VoucherItem::price() const +{ + return TO_DEC(m_price); +} + +void VoucherItem::setPrice(QDecDouble price) +{ + m_price = FROM_DEC(price); +} + +int VoucherItem::refId() const +{ + return m_refId; +} + +void VoucherItem::setRefId(int refId) +{ + m_refId = refId; +} + +QString VoucherItem::itemPlugin() const +{ + return m_itemPlugin; +} + +void VoucherItem::setItemPlugin(const QString &itemPlugin) +{ + m_itemPlugin = itemPlugin; +} + +Enums::VatType VoucherItem::vatType() const +{ + return m_vatType; +} + +void VoucherItem::setVatType(const Enums::VatType &vatType) +{ + m_vatType = vatType; +} diff --git a/shop/data/voucheritem.h b/shop/data/voucheritem.h new file mode 100644 index 0000000..31b1b08 --- /dev/null +++ b/shop/data/voucheritem.h @@ -0,0 +1,64 @@ +#ifndef VOUCHERITEM_H +#define VOUCHERITEM_H + +#include +#include +#include +#include + +#include + +#pragma db object +class VoucherItem : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(int count READ count WRITE setCount) + Q_PROPERTY(QDecDouble unitPrice READ unitPrice WRITE setUnitPrice) + Q_PROPERTY(QDecDouble price READ price WRITE setPrice) + Q_PROPERTY(int refId READ refId WRITE setRefId) + Q_PROPERTY(QString itemPlugin READ itemPlugin WRITE setItemPlugin) + Q_PROPERTY(Enums::VatType vatType READ vatType WRITE setVatType) + +public: + explicit VoucherItem(QObject *parent = 0); + + int id() const; + void setId(int id); + + QString name() const; + void setName(const QString &name); + + int count() const; + void setCount(int count); + + QDecDouble unitPrice() const; + void setUnitPrice(QDecDouble unitPrice); + + QDecDouble price() const; + void setPrice(QDecDouble price); + + int refId() const; + void setRefId(int refId); + + QString itemPlugin() const; + void setItemPlugin(const QString &itemPlugin); + + Enums::VatType vatType() const; + void setVatType(const Enums::VatType &vatType); + +private: + friend class odb::access; +#pragma db id auto + int m_id; + QString m_name; + int m_count; + int m_unitPrice; + int m_price; + int m_refId; + QString m_itemPlugin; + Enums::VatType m_vatType; +}; + +#endif // VOUCHERITEM_H diff --git a/shop/isellableservice.h b/shop/isellableservice.h new file mode 100644 index 0000000..717164e --- /dev/null +++ b/shop/isellableservice.h @@ -0,0 +1,15 @@ +#ifndef ISELLABLESERVICE_H +#define ISELLABLESERVICE_H + +#include "shop_global.h" +#include "ishopitem.h" +#include +#include + +class SHOPSHARED_EXPORT ISellableService +{ +public: + QList > shopItems() = 0; +}; + +#endif // ISELLABLESERVICE_H diff --git a/shop/ishopitem.h b/shop/ishopitem.h new file mode 100644 index 0000000..d13cfe8 --- /dev/null +++ b/shop/ishopitem.h @@ -0,0 +1,16 @@ +#ifndef ISHOPITEM_H +#define ISHOPITEM_H + +#include "shop_global.h" +#include +#include + +class SHOPSHARED_EXPORT IShopItem +{ + +public: + QString name() = 0; + QDecDouble unitPrice() = 0; +}; + +#endif // ISHOPITEM_H diff --git a/shop/shop.json b/shop/shop.json index 6411e0d..b13f950 100644 --- a/shop/shop.json +++ b/shop/shop.json @@ -10,8 +10,46 @@ }, "schemaVersion" : 1, "sql" : [ + "CREATE TABLE \"VoucherItem\" ( + \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + \"name\" TEXT NULL, + \"count\" INTEGER NOT NULL, + \"unitPrice\" INTEGER NOT NULL, + \"price\" INTEGER NOT NULL, + \"refId\" INTEGER NOT NULL, + \"itemPlugin\" TEXT NULL, + \"vatType\" INTEGER NOT NULL); + CREATE TABLE \"Voucher\" ( + \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + \"name\" TEXT NULL, + \"description\" TEXT NULL, + \"contact\" INTEGER NULL, + \"totalPrice\" INTEGER NOT NULL, + \"status\" INTEGER NOT NULL, + CONSTRAINT \"contact_fk\" + FOREIGN KEY (\"contact\") + REFERENCES \"AddressbookData\" (\"id\") + DEFERRABLE INITIALLY DEFERRED); + CREATE TABLE \"Voucher_items\" ( + \"object_id\" INTEGER NOT NULL, + \"index\" INTEGER NOT NULL, + \"value\" INTEGER NULL, + CONSTRAINT \"object_id_fk\" + FOREIGN KEY (\"object_id\") + REFERENCES \"Voucher\" (\"id\") + ON DELETE CASCADE, + CONSTRAINT \"value_fk\" + FOREIGN KEY (\"value\") + REFERENCES \"VoucherItem\" (\"id\") + DEFERRABLE INITIALLY DEFERRED); + + CREATE INDEX \"Voucher_items_object_id_i\" + ON \"Voucher_items\" (\"object_id\"); + + CREATE INDEX \"Voucher_items_index_i\" + ON \"Voucher_items\" (\"index\");" ], - "dependencies" : [] + "dependencies" : [ "ADDRESSBOOK" ] } diff --git a/shop/shop.pro b/shop/shop.pro index 976c591..75a5de8 100644 --- a/shop/shop.pro +++ b/shop/shop.pro @@ -13,11 +13,16 @@ DEFINES += SHOP_LIBRARY\ _GLIBCXX_USE_CXX11_ABI=1 SOURCES += shop.cpp \ - data/voucher.cpp + data/voucher.cpp \ + data/voucheritem.cpp HEADERS += shop.h\ shop_global.h \ - data/voucher.h + data/voucher.h \ + ishopitem.h \ + data/voucheritem.h \ + data/shop-data.h \ + isellableservice.h unix { target.path = /usr/lib @@ -37,12 +42,20 @@ else:unix: LIBS += -L$$OUT_PWD/../core/ -lcore INCLUDEPATH += $$PWD/../core DEPENDPATH += $$PWD/../core +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -laddressbook +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -laddressbook +else:unix: LIBS += -L$$OUT_PWD/../plugins/ -laddressbook + +INCLUDEPATH += $$PWD/../addressbook/data +DEPENDPATH += $$PWD/../addressbook + DESTDIR = ../plugins OTHER_FILES += shop.json -#ODB_FILES = shop/data/....h +ODB_FILES = shop/data/shop-data.h H_DIR = $$PWD/data/*.h +ODB_OTHER_INCLUDES = -I $$PWD/../addressbook/data include(../odb.pri) win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber