diff --git a/camp/camp.json b/camp/camp.json index d4747c1..a2142d7 100644 --- a/camp/camp.json +++ b/camp/camp.json @@ -8,7 +8,7 @@ "default" : "", "CZ" : "" }, - "schemaVersion" : 7, + "schemaVersion" : 8, "sql" : [ "CREATE TABLE \"CampData\" ( \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, @@ -97,6 +97,12 @@ ALTER TABLE CampData ADD \"totalSale\" INTEGER NULL; "ALTER TABLE AddressItem ADD \"sale\" INTEGER NULL; ALTER TABLE AddressItem ADD \"totalPrice\" INTEGER NULL; +", + +"ALTER TABLE CampData ADD \"createdBy\" TEXT NULL; +ALTER TABLE CampData ADD \"created\" TEXT NULL; +ALTER TABLE CampData ADD \"updatedBy\" TEXT NULL; +ALTER TABLE CampData ADD \"updated\" TEXT NULL; " ], "dependencies" : [ "ADDRESSBOOK", "SHOP", "SERVICES" ], diff --git a/camp/campservice.cpp b/camp/campservice.cpp index 3c66315..f506422 100644 --- a/camp/campservice.cpp +++ b/camp/campservice.cpp @@ -105,6 +105,8 @@ void CampService::saveCamp(CampDataPtr data) NumberSeriesService numSrv; data->setNumSer(numSrv.nextStrForPlugin("CAMP")); + addDateAndUser(data, true); + db->persist(data); foreach (ServiceItemPtr item, data->services()) { @@ -153,6 +155,8 @@ void CampService::updateCamp(CampDataPtr data) db->persist(item); } + addDateAndUser(data, false); + db->update(data); tr.commit(); } diff --git a/camp/data/campdata.cpp b/camp/data/campdata.cpp index 61db83a..bb59a24 100644 --- a/camp/data/campdata.cpp +++ b/camp/data/campdata.cpp @@ -191,3 +191,43 @@ void CampData::setOnVoucher(bool onVoucher) { m_onVoucher = onVoucher; } + +QString CampData::createdBy() const +{ + return m_createdBy; +} + +void CampData::setCreatedBy(const QString &createdBy) +{ + m_createdBy = createdBy; +} + +QString CampData::updatedBy() const +{ + return m_updatedBy; +} + +void CampData::setUpdatedBy(const QString &updatedBy) +{ + m_updatedBy = updatedBy; +} + +QDateTime CampData::created() const +{ + return m_created; +} + +void CampData::setCreated(const QDateTime &created) +{ + m_created = created; +} + +QDateTime CampData::updated() const +{ + return m_updated; +} + +void CampData::setUpdated(const QDateTime &updated) +{ + m_updated = updated; +} diff --git a/camp/data/campdata.h b/camp/data/campdata.h index 7cb51cb..b7021e1 100644 --- a/camp/data/campdata.h +++ b/camp/data/campdata.h @@ -25,6 +25,10 @@ class CampData : public QObject Q_PROPERTY(bool fixedSale READ fixedSale WRITE setFixedSale) Q_PROPERTY(QDecDouble totalSale READ totalSale WRITE setTotalSale) Q_PROPERTY(bool onVoucher READ onVoucher WRITE setOnVoucher) + Q_PROPERTY(QString createdBy READ createdBy WRITE setCreatedBy) + Q_PROPERTY(QString updatedBy READ updatedBy WRITE setUpdatedBy) + Q_PROPERTY(QDateTime created READ created WRITE setCreated) + Q_PROPERTY(QDateTime updated READ updated WRITE setUpdated) public: explicit CampData(QObject *parent = 0); @@ -81,6 +85,18 @@ public: bool onVoucher() const; void setOnVoucher(bool onVoucher); + QString createdBy() const; + void setCreatedBy(const QString &createdBy); + + QString updatedBy() const; + void setUpdatedBy(const QString &updatedBy); + + QDateTime created() const; + void setCreated(const QDateTime &created); + + QDateTime updated() const; + void setUpdated(const QDateTime &updated); + private: friend class odb::access; #pragma db id auto @@ -102,6 +118,10 @@ private: bool m_fixedSale; SeasonPtr m_season; bool m_onVoucher; + QString m_createdBy; + QString m_updatedBy; + QDateTime m_created; + QDateTime m_updated; }; #endif // CAMPDATA_H diff --git a/core/data/system.cpp b/core/data/system.cpp index 9d81f03..b6aa926 100644 --- a/core/data/system.cpp +++ b/core/data/system.cpp @@ -5,6 +5,11 @@ System::System() } +System::~System() +{ + +} + int System::id() const { return m_id; diff --git a/core/data/system.h b/core/data/system.h index a8e8ef9..23e5507 100644 --- a/core/data/system.h +++ b/core/data/system.h @@ -11,6 +11,7 @@ class CORESHARED_EXPORT System { public: System(); + virtual ~System(); int id() const; void setId(int id); diff --git a/core/service.h b/core/service.h index 94c3760..7586464 100644 --- a/core/service.h +++ b/core/service.h @@ -82,6 +82,8 @@ public: Transaction tx; + addDateAndUser(entity, true); + try { db->persist(entity); @@ -108,6 +110,8 @@ public: Transaction tx; + addDateAndUser(entity, false); + try { db->update(entity); @@ -126,9 +130,9 @@ public: QSharedPointer loadById(int id) { QSharedPointer entity; - if (!checkPermission(PERM_READ)) { + /*if (!checkPermission(PERM_READ)) { return entity; - } + }*/ odb::database *db = Context::instance().db(); @@ -233,6 +237,28 @@ protected: return true; } + + void addDateAndUser(QSharedPointer entity, bool creating) { + + T *inner = entity.data(); + QObject *obj = dynamic_cast(inner); + + if (obj == NULL) + { + return; + } + + if (creating) + { + obj->setProperty("createdBy", Context::instance().currentUser()->login()); + obj->setProperty("created", QDateTime::currentDateTime()); + } + else + { + obj->setProperty("updatedBy", Context::instance().currentUser()->login()); + obj->setProperty("updated", QDateTime::currentDateTime()); + } + } }; #endif // SERVICE_H diff --git a/shop/data/voucher.cpp b/shop/data/voucher.cpp index e656ccd..d380649 100644 --- a/shop/data/voucher.cpp +++ b/shop/data/voucher.cpp @@ -301,6 +301,46 @@ void Voucher::setSeason(const SeasonPtr &season) m_season = season; } +QString Voucher::createdBy() const +{ + return m_createdBy; +} + +void Voucher::setCreatedBy(const QString &createdBy) +{ + m_createdBy = createdBy; +} + +QString Voucher::updatedBy() const +{ + return m_updatedBy; +} + +void Voucher::setUpdatedBy(const QString &updatedBy) +{ + m_updatedBy = updatedBy; +} + +QDateTime Voucher::created() const +{ + return m_created; +} + +void Voucher::setCreated(const QDateTime &created) +{ + m_created = created; +} + +QDateTime Voucher::updated() const +{ + return m_updated; +} + +void Voucher::setUpdated(const QDateTime &updated) +{ + m_updated = updated; +} + int Voucher::id() const { return m_id; diff --git a/shop/data/voucher.h b/shop/data/voucher.h index de0183b..f0de1b9 100644 --- a/shop/data/voucher.h +++ b/shop/data/voucher.h @@ -46,6 +46,10 @@ class SHOPSHARED_EXPORT Voucher : public QObject Q_ENUMS(VoucherStatus) Q_ENUMS(EetStatus) Q_PROPERTY(VoucherStatus status READ status WRITE setStatus) + Q_PROPERTY(QString createdBy READ createdBy WRITE setCreatedBy) + Q_PROPERTY(QString updatedBy READ updatedBy WRITE setUpdatedBy) + Q_PROPERTY(QDateTime created READ created WRITE setCreated) + Q_PROPERTY(QDateTime updated READ updated WRITE setUpdated) public: explicit Voucher(QObject *parent = 0); @@ -155,6 +159,18 @@ public: SeasonPtr season() const; void setSeason(const SeasonPtr &season); + QString createdBy() const; + void setCreatedBy(const QString &createdBy); + + QString updatedBy() const; + void setUpdatedBy(const QString &updatedBy); + + QDateTime created() const; + void setCreated(const QDateTime &created); + + QDateTime updated() const; + void setUpdated(const QDateTime &updated); + private: friend class odb::access; #pragma db id auto @@ -186,6 +202,10 @@ private: QOdbList > m_items; VoucherStatus m_status; SeasonPtr m_season; + QString m_createdBy; + QString m_updatedBy; + QDateTime m_created; + QDateTime m_updated; }; typedef QSharedPointer VoucherPtr; diff --git a/shop/shop.json b/shop/shop.json index 53b2d11..baad1ce 100644 --- a/shop/shop.json +++ b/shop/shop.json @@ -8,7 +8,7 @@ "default" : "", "CZ" : "" }, - "schemaVersion" : 6, + "schemaVersion" : 7, "sql" : [ "CREATE TABLE \"VoucherItem\" ( \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, @@ -76,6 +76,12 @@ CREATE TABLE \"Voucher\" ( "ALTER TABLE \"Voucher\" ADD \"season\" INTEGER NULL; UPDATE \"Voucher\" SET season = (SELECT id FROM \"Season\" WHERE active = 1); +", + +"ALTER TABLE Voucher ADD \"createdBy\" TEXT NULL; +ALTER TABLE Voucher ADD \"created\" TEXT NULL; +ALTER TABLE Voucher ADD \"updatedBy\" TEXT NULL; +ALTER TABLE Voucher ADD \"updated\" TEXT NULL; " ], "dependencies" : [ "ADDRESSBOOK" ], diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index 08651f1..68e675c 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -349,6 +349,8 @@ void ShopService::saveVoucher(VoucherPtr entity) Transaction tr; odb::database *db = Context::instance().db(); + addDateAndUser(entity, true); + db->persist(entity); foreach (QSharedPointer item, entity->items()) { @@ -371,6 +373,8 @@ void ShopService::updateVoucher(VoucherPtr entity) db->persist(item); } + addDateAndUser(entity, false); + db->update(entity); tr.commit();