Build system changed to Cmake, ORM changed to QxORM, Qt6 compatibility.

This commit is contained in:
2023-04-28 22:25:29 +02:00
parent 30e6180c82
commit d699ce79f7
481 changed files with 2310 additions and 130206 deletions
+93
View File
@@ -0,0 +1,93 @@
cmake_minimum_required(VERSION 3.24)
project(shop)
include(../3rdparty/QxOrm/QxOrm.cmake)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ../plugins)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
find_package(Qt6 COMPONENTS
Core
Gui
Widgets
REQUIRED)
add_library(shop SHARED
directsaleform.cpp
directsaleform.h
directsaleform.ui
directsaleitem.cpp
directsaleitem.h
eetbatchdialog.cpp
eetbatchdialog.h
eetbatchdialog.ui
favbutton.h
isellableservice.cpp
isellableservice.h
iseller.cpp
iseller.h
ishopitem.h
paydialog.cpp
paydialog.h
paydialog.ui
paydvouchersdialog.cpp
paydvouchersdialog.h
paydvouchersdialog.ui
receiptgenerator.cpp
receiptgenerator.h
receiptloadform.cpp
receiptloadform.h
receiptloadform.ui
receiptsaveform.cpp
receiptsaveform.h
receiptsaveform.ui
shop.cpp
shop.h
shop_global.h
shopform.cpp
shopform.h
shopform.ui
shopitem.cpp
shopform.h
shopoverview.cpp
shopoverview.h
shopoverview.ui
shoprc.qrc
shopservice.cpp
shopservice.h
temporaryreceiptsaveform.cpp
temporaryreceiptsaveform.h
temporaryreceiptsaveform.ui
data/favoritgroup.cpp
data/favoritgroup.h
data/favorititem.cpp
data/favorititem.h
data/shop-data.h
data/voucher.cpp
data/voucher.h
data/voucheritem.cpp
data/voucheritem.h
settings/shopsettings.cpp
settings/shopsettings.h
settings/shopsettingsform.cpp
settings/shopsettingsform.h
settings/shopsettingsform.ui ishopitem.cpp)
target_compile_definitions(shop PRIVATE -DSHOP_LIBRARY)
include_directories(../core ../countryregister ../addressbook)
target_link_libraries(shop
Qt::Core
Qt::Gui
Qt::Widgets
qdecimal
decnumber
QxOrm
core
addressbook
)
+6
View File
@@ -0,0 +1,6 @@
#include "favoritgroup.h"
FavoritGroup::FavoritGroup()
{
}
+11
View File
@@ -0,0 +1,11 @@
#ifndef FAVORITGROUP_H
#define FAVORITGROUP_H
class FavoritGroup
{
public:
FavoritGroup();
};
#endif // FAVORITGROUP_H
+7 -10
View File
@@ -1,19 +1,16 @@
#include "favorititem.h"
#include <define.h>
FavoritItem::FavoritItem()
{
m_id = 0;
m_vatType = Enums::NONE;
m_unitPrice = 0;
}
QX_REGISTER_CPP_SHOP(FavoritItem)
int FavoritItem::id()
QX_REGISTER_ALL_QT_PROPERTIES(FavoritItem, "id")
long FavoritItem::id()
{
return m_id;
}
void FavoritItem::setId(int id)
void FavoritItem::setId(long id)
{
m_id = id;
}
@@ -78,12 +75,12 @@ void FavoritItem::setFavButtonName(const QString &favButtonName)
m_favButtonName = favButtonName;
}
int FavoritItem::refId() const
long FavoritItem::refId() const
{
return m_refId;
}
void FavoritItem::setRefId(int refId)
void FavoritItem::setRefId(long refId)
{
m_refId = refId;
}
+16 -16
View File
@@ -1,21 +1,21 @@
#ifndef FAVORITITEM_H
#define FAVORITITEM_H
#include "../ishopitem.h"
#include <QObject>
#include <QSharedPointer>
#include <QString>
#include <QDecDouble.hh>
//#include <QxOrm.h>
#include <enums.h>
#include <ishopitem.h>
#include <odb/core.hxx>
class IShopItem;
#pragma db object
class FavoritItem : public QObject, public IShopItem
class FavoritItem : public IShopItem
{
Q_OBJECT
QX_REGISTER_FRIEND_CLASS(FavoritItem)
Q_PROPERTY(int id READ id WRITE setId)
Q_PROPERTY(int refId READ refId WRITE setRefId)
Q_PROPERTY(QString name READ name WRITE setName)
@@ -26,12 +26,12 @@ class FavoritItem : public QObject, public IShopItem
Q_PROPERTY(QString favButtonName READ favButtonName WRITE setFavButtonName)
public:
FavoritItem();
FavoritItem() = default;
// IShopItem interface
public:
int id() override;
void setId(int id);
long id() override;
void setId(long id);
QString name() override;
void setName(const QString &name);
@@ -51,17 +51,15 @@ public:
QString favButtonName() const;
void setFavButtonName(const QString &favButtonName);
int refId() const;
void setRefId(int refId);
long refId() const;
void setRefId(long refId);
private:
friend class odb::access;
#pragma db id auto
int m_id;
int m_refId;
long m_id{0};
long m_refId{0};
QString m_name;
int m_unitPrice;
Enums::VatType m_vatType;
int m_unitPrice{0};
Enums::VatType m_vatType{Enums::NONE};
QString m_pluginId;
QString m_favButtonName;
QString m_shortName;
@@ -69,4 +67,6 @@ private:
typedef QSharedPointer<FavoritItem> FavoritItemPtr;
QX_REGISTER_HPP_SHOP(FavoritItem, QObject, 0)
#endif // FAVORITITEM_H
+58 -9
View File
@@ -1,6 +1,47 @@
#include <data/addressbookdata.h>
#include "voucher.h"
#include <define.h>
QX_REGISTER_CPP_SHOP(Voucher)
namespace qx {
template<> void register_class(QxClass<Voucher>& t) {
t.setName("Voucher");
t.id(&Voucher::m_id, "id");
t.data(&Voucher::m_numSer, "numSer");
t.data(&Voucher::m_payDateTime, "payDateTime");
t.data(&Voucher::m_name, "name");
t.data(&Voucher::m_description, "description");
t.data(&Voucher::m_vatRateHigh, "vatRateHigh");
t.data(&Voucher::m_vatRateFirstLower, "vatRateFirstLower");
t.data(&Voucher::m_vatRateSecondLower, "vatRateSecondLower");
t.data(&Voucher::m_priceNoVat, "priceNoVat");
t.data(&Voucher::m_priceVatHigh, "priceVatHigh");
t.data(&Voucher::m_priceVatFirstLower, "priceVatFirstLower");
t.data(&Voucher::m_priceVatSecondLower, "priceVatSecondLower");
t.data(&Voucher::m_priceWitouthVat, "priceWitouthVat");
t.data(&Voucher::m_totalPriceVatHigh, "totalPriceVatHigh");
t.data(&Voucher::m_totalPriceVatFirstLower, "totalPriceVatFirstLower");
t.data(&Voucher::m_totalPriceVatSecondLower, "totalPriceVatSecondLower");
t.data(&Voucher::m_totalPrice, "totalPrice");
t.data(&Voucher::m_status, "status");
t.data(&Voucher::m_eetStatus, "eetStatus");
t.data(&Voucher::m_eetSendDateTime, "eetSendDateTime");
t.data(&Voucher::m_eetPkp, "eetPkp");
t.data(&Voucher::m_eetBkp, "eetBkp");
t.data(&Voucher::m_eetFik, "eetFik");
t.data(&Voucher::m_saveDateTime, "saveDateTime");
t.data(&Voucher::m_createdBy, "createdBy");
t.data(&Voucher::m_created, "created");
t.data(&Voucher::m_updatedBy, "updatedBy");
t.data(&Voucher::m_updated, "updated");
t.relationOneToMany(&Voucher::m_items, "voucher", "voucher");
t.relationManyToOne(&Voucher::m_season, "season");
t.relationManyToOne(&Voucher::m_contact, "contact");
}
}
Voucher::Voucher(QObject *parent) : QObject(parent)
{
m_id = 0;
@@ -17,6 +58,7 @@ Voucher::Voucher(QObject *parent) : QObject(parent)
m_totalPriceVatSecondLower = 0;
m_totalPrice = 0;
m_eetStatus = EET_FOR_SEND;
m_status = NEW;
}
QString Voucher::name() const
@@ -341,20 +383,28 @@ void Voucher::setUpdated(const QDateTime &updated)
m_updated = updated;
}
int Voucher::id() const
long Voucher::id() const
{
return m_id;
}
void Voucher::setId(int id)
void Voucher::setId(long id)
{
m_id = id;
}
VoucherSum::VoucherSum()
{
m_totalPrice = 0;
m_count = 0;
QStringList Voucher::eagerLoad() {
return { "season", "contact" };
}
QX_REGISTER_CPP_SHOP(VoucherSum)
namespace qx {
template<> void register_class(QxClass<VoucherSum>& t) {
t.setName("VoucherSum");
t.data(&VoucherSum::m_count, "count");
t.data(&VoucherSum::m_totalPrice, "totalPrice");
}
}
QDecDouble VoucherSum::totalPrice() const
@@ -362,7 +412,6 @@ QDecDouble VoucherSum::totalPrice() const
return TO_DEC(m_totalPrice);
}
void VoucherSum::setTotalPrice(QDecDouble totalPrice)
{
m_totalPrice = FROM_DEC(totalPrice);
int VoucherSum::count() const {
return m_count;
}
+26 -33
View File
@@ -5,27 +5,19 @@
#include <QDecDouble.hh>
#include <QString>
#include <QSharedPointer>
#include <addressbookdata.h>
#include <season.h>
#include <odb/core.hxx>
#include <odb/qt/list.hxx>
#include <odb/section.hxx>
#include <data/addressbookdata.h>
#include <data/season.h>
#include "../shop_global.h"
#include "voucheritem.h"
#include <QtCore/qglobal.h>
#if defined(SHOP_LIBRARY)
# define SHOPSHARED_EXPORT Q_DECL_EXPORT
#else
# define SHOPSHARED_EXPORT Q_DECL_IMPORT
#endif
#pragma db object
class SHOPSHARED_EXPORT Voucher : public QObject
{
Q_OBJECT
QX_REGISTER_FRIEND_CLASS(Voucher)
Q_PROPERTY(QString numSer READ numSer WRITE setNumSer)
Q_PROPERTY(QDateTime payDateTime READ payDateTime WRITE setPayDateTime)
Q_PROPERTY(QDateTime saveDateTime READ saveDateTime WRITE setSaveDateTime)
@@ -44,8 +36,6 @@ class SHOPSHARED_EXPORT Voucher : public QObject
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)
Q_PROPERTY(QString createdBy READ createdBy WRITE setCreatedBy)
Q_PROPERTY(QString updatedBy READ updatedBy WRITE setUpdatedBy)
@@ -53,7 +43,7 @@ class SHOPSHARED_EXPORT Voucher : public QObject
Q_PROPERTY(QDateTime updated READ updated WRITE setUpdated)
public:
explicit Voucher(QObject *parent = 0);
explicit Voucher(QObject *parent = nullptr);
enum VoucherStatus
{
@@ -71,8 +61,11 @@ public:
EET_ERROR
};
int id() const;
void setId(int id);
Q_ENUM(VoucherStatus)
Q_ENUM(EetStatus)
long id() const;
void setId(long id);
QString name() const;
void setName(const QString &name);
@@ -172,13 +165,10 @@ public:
QDateTime updated() const;
void setUpdated(const QDateTime &updated);
#pragma db load(lazy)
odb::section m_itemsSection;
Q_INVOKABLE QStringList eagerLoad();
private:
friend class odb::access;
#pragma db id auto
int m_id;
long m_id;
QString m_numSer;
QDateTime m_payDateTime;
QDateTime m_saveDateTime;
@@ -202,8 +192,7 @@ private:
QString m_eetPkp;
QString m_eetBkp;
QString m_eetFik;
#pragma db value_not_null inverse(m_voucher) section(m_itemsSection)
QOdbList<QSharedPointer<VoucherItem> > m_items;
QList<QSharedPointer<VoucherItem>> m_items;
VoucherStatus m_status;
SeasonPtr m_season;
QString m_createdBy;
@@ -214,18 +203,22 @@ private:
typedef QSharedPointer<Voucher> VoucherPtr;
#pragma db view object(Voucher)
struct VoucherSum
QX_REGISTER_HPP_SHOP(Voucher, QObject, 0)
class VoucherSum
{
VoucherSum();
QX_REGISTER_FRIEND_CLASS(VoucherSum)
public:
VoucherSum() = default;
QDecDouble totalPrice() const;
void setTotalPrice(QDecDouble totalPrice);
#pragma db column("count(id)")
int m_count;
#pragma db column("sum(totalPrice)")
int m_totalPrice;
int count() const;
private:
int m_count{0};
int m_totalPrice{0};
};
QX_REGISTER_HPP_SHOP(VoucherSum, qx::trait::no_base_class_defined, 0)
#endif // VOUCHER_H
+27 -4
View File
@@ -1,8 +1,31 @@
#include "voucher.h"
#include "voucheritem.h"
#include <define.h>
QX_REGISTER_CPP_SHOP(VoucherItem)
namespace qx {
template<> void register_class(QxClass<VoucherItem> &t) {
t.setName("VoucherItem");
t.id(&VoucherItem::m_id, "id");
t.data(&VoucherItem::m_name, "name");
t.data(&VoucherItem::m_count, "count");
t.data(&VoucherItem::m_unitPrice, "unitPrice");
t.data(&VoucherItem::m_vatRate, "vatRate");
t.data(&VoucherItem::m_priceWitouthVat, "priceWitouthVat");
t.data(&VoucherItem::m_price, "price");
t.data(&VoucherItem::m_refId, "refId");
t.data(&VoucherItem::m_itemPlugin, "itemPlugin");
t.data(&VoucherItem::m_vatType, "vatType");
t.data(&VoucherItem::m_insertDate, "insertDate");
t.relationManyToOne(&VoucherItem::m_voucher, "voucher");
}
}
VoucherItem::VoucherItem(QObject *parent) : QObject(parent)
{
m_id = 0;
m_price = 0;
m_unitPrice = 0;
m_count = 0;
@@ -12,12 +35,12 @@ VoucherItem::VoucherItem(QObject *parent) : QObject(parent)
m_priceWitouthVat = 0;
}
int VoucherItem::id() const
long VoucherItem::id() const
{
return m_id;
}
void VoucherItem::setId(int id)
void VoucherItem::setId(long id)
{
m_id = id;
}
@@ -117,12 +140,12 @@ QDecDouble VoucherItem::vatAmount() const
return TO_DEC(m_price) - TO_DEC(m_priceWitouthVat);
}
QWeakPointer<Voucher> VoucherItem::voucher() const
QSharedPointer<Voucher> VoucherItem::voucher() const
{
return m_voucher;
}
void VoucherItem::setVoucher(const QWeakPointer<Voucher> &voucher)
void VoucherItem::setVoucher(const QSharedPointer<Voucher> &voucher)
{
m_voucher = voucher;
}
+11 -18
View File
@@ -4,27 +4,21 @@
#include <QObject>
#include <QString>
#include <QDecDouble.hh>
#include <odb/core.hxx>
#include <QSharedPointer>
#include <QDateTime>
#include <enums.h>
#include "../shop_global.h"
#include <QtCore/qglobal.h>
#if defined(SHOP_LIBRARY)
# define SHOPSHARED_EXPORT Q_DECL_EXPORT
#else
# define SHOPSHARED_EXPORT Q_DECL_IMPORT
#endif
class Voucher;
#pragma db object
class SHOPSHARED_EXPORT VoucherItem : public QObject
{
Q_OBJECT
QX_REGISTER_FRIEND_CLASS(VoucherItem)
Q_PROPERTY(QDateTime insertDate READ insertDate WRITE setInsertDate)
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged)
@@ -35,10 +29,10 @@ class SHOPSHARED_EXPORT VoucherItem : public QObject
Q_PROPERTY(QDecDouble price READ price WRITE setPrice)
public:
explicit VoucherItem(QObject *parent = 0);
explicit VoucherItem(QObject *parent = nullptr);
int id() const;
void setId(int id);
long id() const;
void setId(long id);
QString name() const;
void setName(const QString &name);
@@ -69,8 +63,8 @@ public:
QDecDouble vatAmount() const;
QWeakPointer<Voucher> voucher() const;
void setVoucher(const QWeakPointer<Voucher> &voucher);
QSharedPointer<Voucher> voucher() const;
void setVoucher(const QSharedPointer<Voucher> &voucher);
QDateTime insertDate() const;
void setInsertDate(const QDateTime &insertDate);
@@ -79,9 +73,7 @@ signals:
void countChanged(int oldCount);
private:
friend class odb::access;
#pragma db id auto
int m_id;
long m_id;
QString m_name;
int m_count;
int m_unitPrice;
@@ -92,10 +84,11 @@ private:
QDateTime m_insertDate;
QString m_itemPlugin;
Enums::VatType m_vatType;
#pragma db not_null
QWeakPointer<Voucher> m_voucher;
QSharedPointer<Voucher> m_voucher;
};
typedef QSharedPointer<VoucherItem> VoucherItemPtr;
QX_REGISTER_HPP_SHOP(VoucherItem, QObject, 0);
#endif // VOUCHERITEM_H
+2 -2
View File
@@ -1,12 +1,12 @@
#include "directsaleitem.h"
DirectSaleItem::DirectSaleItem(QObject *parent) : QObject(parent)
DirectSaleItem::DirectSaleItem(QObject *parent) : IShopItem(parent)
{
m_count = 1;
m_vat = Enums::NONE;
}
int DirectSaleItem::id()
long DirectSaleItem::id()
{
return 0;
}
+2 -2
View File
@@ -5,7 +5,7 @@
#include <QString>
#include "ishopitem.h"
class DirectSaleItem : public QObject, public IShopItem
class DirectSaleItem : public IShopItem
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
@@ -22,7 +22,7 @@ public slots:
// IShopItem interface
public:
int id() override;
long id() override;
QString name() override;
QString shortName() override;
QDecDouble unitPrice() override;
+2 -2
View File
@@ -12,8 +12,8 @@ class SHOPSHARED_EXPORT ISellableService
public:
ISellableService();
virtual QList<ShopItemPtr> shopItems() = 0;
virtual ShopItemPtr shopItem(int itemId) = 0;
virtual QList<IShopItemPtr> shopItems() = 0;
virtual IShopItemPtr shopItem(int itemId) = 0;
virtual void addedToVoucher(int itemId, int countAdded) = 0;
virtual ISeller *seller() = 0;
};
+14
View File
@@ -0,0 +1,14 @@
#include "ishopitem.h"
QX_REGISTER_CPP_SHOP(IShopItem)
namespace qx {
template<>
void register_class(QxClass<IShopItem> &) {
}
}
IShopItem::IShopItem(QObject *parent) : QObject(parent) {
}
+24 -7
View File
@@ -5,17 +5,34 @@
#include <QDecDouble.hh>
#include <QString>
#include <enums.h>
#include <QObject>
#include <QSharedPointer>
class SHOPSHARED_EXPORT IShopItem
class SHOPSHARED_EXPORT IShopItem : public QObject
{
Q_OBJECT
Q_PROPERTY(QString code READ code)
Q_PROPERTY(QString name READ name)
Q_PROPERTY(QString shortName READ shortName)
Q_PROPERTY(QDecDouble unitPrice READ unitPrice)
Q_PROPERTY(Enums::VatType vatType READ vatType)
public:
virtual int id() = 0;
virtual QString name() = 0;
virtual QString shortName() = 0;
virtual QDecDouble unitPrice() = 0;
virtual Enums::VatType vatType() = 0;
virtual QString pluginId() = 0;
explicit IShopItem(QObject* parent = nullptr);
~IShopItem() override = default;
virtual long id() { return {}; }
virtual QString name() { return {}; }
virtual QString code() { return {}; }
virtual QString shortName() { return {}; }
virtual QDecDouble unitPrice() { return {}; }
virtual Enums::VatType vatType() { return {}; }
virtual QString pluginId() { return {}; }
};
using IShopItemPtr = QSharedPointer<IShopItem>;
QX_REGISTER_HPP_SHOP(IShopItem, QObject, 0)
#endif // ISHOPITEM_H
-2
View File
@@ -2,8 +2,6 @@
#include "ui_paydialog.h"
#include "shopservice.h"
#include "shop-odb.hxx"
PayDialog::PayDialog(QDecDouble total, QWidget *parent) :
QDialog(parent),
ui(new Ui::PayDialog)
+4 -3
View File
@@ -11,8 +11,6 @@
#include <reporting/reportdialog.h>
#include <reporting/variablefiller.h>
#include "shop-odb.hxx"
PaydVouchersDialog::PaydVouchersDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::PaydVouchersDialog)
@@ -56,7 +54,10 @@ PaydVouchersDialog::PaydVouchersDialog(QWidget *parent) :
connect(ui->tableVouchers->selectionModel(), &QItemSelectionModel::currentRowChanged, [this, &srv](const QModelIndex &current, const QModelIndex &) {
QSharedPointer<Voucher> voucher = m_voucherModel->itemFromIndex(current);
srv.loadItems(voucher);
if (voucher->items().isEmpty()) {
srv.load(voucher);
}
m_itemModel->setData(voucher->items());
ui->total->setText(QString::number(voucher->totalPrice().toDouble(), 'f', 2));
+4 -3
View File
@@ -2,7 +2,7 @@
#include <settingsservice.h>
#include <settings/globalsettings.h>
#include <QTextCodec>
//#include <QTextCodec>
#include <QFile>
#ifdef _WIN32
@@ -349,6 +349,7 @@ QByteArray ReceiptGenerator::prepareString(const QString &str)
strOut = strOut.replace(DIACRITIC.at(i), NON_DIACRITIC.at(i));
}
QTextCodec *codec = QTextCodec::codecForName("IBM850");
return codec->fromUnicode(strOut);
//QTextCodec *codec = QTextCodec::codecForName("IBM850");
//return codec->fromUnicode(strOut);
return strOut.toLatin1();
}
+5 -3
View File
@@ -3,7 +3,6 @@
#include "receiptloadform.h"
#include "ui_receiptloadform.h"
#include "shopservice.h"
#include "shop-odb.hxx"
ReceiptLoadForm::ReceiptLoadForm(QWidget *parent) :
QDialog(parent),
@@ -13,7 +12,7 @@ ReceiptLoadForm::ReceiptLoadForm(QWidget *parent) :
m_voucherModel = new AutoTableModel<Voucher>(this);
ShopService srv;
m_voucherModel->setData(srv.all(QString("status = %1").arg(QString::number(Voucher::NOT_PAID))));
m_voucherModel->setData(srv.savedVouchers());
m_voucherModel->setTranslations(Context::instance().plugin("SHOP")->translations());
ui->tabVouchers->setModel(m_voucherModel);
ui->tabVouchers->setColumnHidden(0, true);
@@ -43,7 +42,10 @@ ReceiptLoadForm::ReceiptLoadForm(QWidget *parent) :
connect(ui->tabVouchers->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](const QModelIndex &current, QModelIndex){
ShopService srv;
VoucherPtr voucher = m_voucherModel->itemFromIndex(current);
srv.loadItems(voucher);
if (voucher->items().isEmpty()) {
srv.load(voucher);
}
m_itemModel->setData(voucher->items());
});
}
+2 -3
View File
@@ -9,11 +9,10 @@
#include <service.h>
#include <iplugin.h>
#include <addressbookservice.h>
#include <addressbookdata.h>
#include <data/addressbookdata.h>
#include "data/voucher.h"
#include "shopservice.h"
#include "shop-odb.hxx"
ReceiptSaveForm::ReceiptSaveForm(QSharedPointer<Voucher> voucher, QWidget *parent) :
QDialog(parent),
@@ -54,7 +53,7 @@ ReceiptSaveForm::ReceiptSaveForm(QSharedPointer<Voucher> voucher, QWidget *paren
m_binder.setData(voucher.data());
AddressBookService srvAdb;
m_binder.registerBinding(ui->contact, ComboData::createComboData(srvAdb.all("", "lastName, firstName")));
m_binder.registerBinding(ui->contact, ComboData::createComboData(srvAdb.all(""/*, "lastName, firstName"*/)));
m_binder.registerBinding(ui->name);
m_binder.registerBinding(ui->description);
m_binder.bindToUi();
+3 -5
View File
@@ -6,9 +6,7 @@
#include <QFileDialog>
#include <QDragEnterEvent>
#include <QDebug>
#include "shopservice.h"
#include "shop-odb.hxx"
#include "../shopservice.h"
ShopSettingsForm::ShopSettingsForm(QWidget *parent) :
FormBinder<ShopSettings>(parent),
@@ -58,7 +56,7 @@ ShopSettingsForm::ShopSettingsForm(QWidget *parent) :
<< ComboData(Enums::SECOND_LOWER, tr("Second lower"));
registerBinding(ui->defaultVat, listVatTypes);
m_itemModel = new AutoTableModel<ShopItem>();
m_itemModel = new AutoTableModel<IShopItem>(this);
}
ShopSettingsForm::~ShopSettingsForm()
@@ -99,7 +97,7 @@ void ShopSettingsForm::drawButtons()
});
connect(btn, &FavButton::itemDropped, [this, btn](){
ShopItemPtr item = m_itemModel->itemFromIndex(ui->tableItems->currentIndex());
IShopItemPtr item = m_itemModel->itemFromIndex(ui->tableItems->currentIndex());
FavoritItemPtr favItem = QSharedPointer<FavoritItem>(new FavoritItem);
favItem->setFavButtonName(btn->objectName());
favItem->setName(item->name());
+6 -6
View File
@@ -7,9 +7,9 @@
#include <QMap>
#include "shopsettings.h"
#include <core.h>
#include "shopitem.h"
#include "data/favorititem.h"
#include "favbutton.h"
#include "../shopitem.h"
#include "../data/favorititem.h"
#include "../favbutton.h"
namespace Ui {
class ShopSettingsForm;
@@ -25,10 +25,10 @@ public:
private:
Ui::ShopSettingsForm *ui;
AutoTableModel<ShopItem> *m_itemModel;
int m_favBtnRows;
AutoTableModel<IShopItem> *m_itemModel;
/*int m_favBtnRows;
int m_favBtnCols;
int m_favBtnSize;
int m_favBtnSize;*/
QMap<QString, FavoritItemPtr> m_btnMap;
void drawButtons();
+16 -1
View File
@@ -17,7 +17,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>3</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@@ -83,6 +83,9 @@
<item row="0" column="0" colspan="2">
<widget class="QWidget" name="widget_4" native="true">
<layout class="QFormLayout" name="formLayout_3">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
@@ -126,6 +129,9 @@
<string>Printer</string>
</attribute>
<layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
@@ -175,6 +181,9 @@
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
@@ -284,6 +293,9 @@
<string>Rounding</string>
</property>
<layout class="QFormLayout" name="formLayout_4">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
@@ -342,6 +354,9 @@
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout_5">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
+2 -3
View File
@@ -3,7 +3,6 @@
#include "shopform.h"
#include "shopservice.h"
#include "settings/shopsettingsform.h"
#include "shop-odb.hxx"
#include "shopoverview.h"
Shop::Shop()
@@ -27,9 +26,9 @@ QWidget *Shop::ui()
{
QWidget *uiWidget = IPlugin::ui();
if (uiWidget == NULL)
if (uiWidget == nullptr)
{
return NULL;
return nullptr;
}
qobject_cast<ShopForm*>(uiWidget)->setupForm();
+5 -5
View File
@@ -21,11 +21,11 @@ protected:
// IPlugin interface
public:
virtual QIcon pluginIcon();
virtual QWidget *ui() override;
QTranslator *translator();
bool hasNumberSeries();
QString numberSeriesPrefix();
QIcon pluginIcon() override;
QWidget *ui() override;
QTranslator *translator() override;
bool hasNumberSeries() override;
QString numberSeriesPrefix() override;
};
#endif // SHOP_H
-120
View File
@@ -1,120 +0,0 @@
#-------------------------------------------------
#
# Project created by QtCreator 2016-04-06T20:45:20
#
#-------------------------------------------------
QT += widgets sql
TARGET = shop
TEMPLATE = lib
CONFIG += eet
DEFINES += SHOP_LIBRARY
SOURCES += shop.cpp \
data/voucher.cpp \
shopform.cpp \
directsaleform.cpp \
temporaryreceiptsaveform.cpp \
receiptsaveform.cpp \
receiptloadform.cpp \
data/voucheritem.cpp \
shopservice.cpp \
directsaleitem.cpp \
receiptgenerator.cpp \
settings/shopsettings.cpp \
settings/shopsettingsform.cpp \
paydialog.cpp \
paydvouchersdialog.cpp \
shopitem.cpp \
isellableservice.cpp \
data/favorititem.cpp \
eetbatchdialog.cpp \
iseller.cpp \
shopoverview.cpp
HEADERS += shop.h\
shop_global.h \
data/voucher.h \
shopform.h \
directsaleform.h \
temporaryreceiptsaveform.h \
receiptsaveform.h \
receiptloadform.h \
ishopitem.h \
data/voucheritem.h \
data/shop-data.h \
isellableservice.h \
shopservice.h \
directsaleitem.h \
receiptgenerator.h \
settings/shopsettings.h \
settings/shopsettingsform.h \
paydialog.h \
paydvouchersdialog.h \
shopitem.h \
data/favorititem.h \
eetbatchdialog.h \
favbutton.h \
iseller.h \
shopoverview.h
include(../config_plugin.pri)
OTHER_FILES += shop.json
ODB_FILES = shop/data/shop-data.h
H_DIR = $$PWD/data/*.h
ODB_OTHER_INCLUDES = -I $$PWD/../addressbook/data -I $$PWD/../countryregister/data -I $$PWD/
include(../odb.pri)
RESOURCES += \
shoprc.qrc
FORMS += \
shopform.ui \
directsaleform.ui \
temporaryreceiptsaveform.ui \
receiptsaveform.ui \
receiptloadform.ui \
settings/shopsettingsform.ui \
paydialog.ui \
paydvouchersdialog.ui \
eetbatchdialog.ui \
shopoverview.ui
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
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lcountryregister
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lcountryregister
INCLUDEPATH += $$PWD/../addressbook/data
INCLUDEPATH += $$PWD/../addressbook
INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/../addressbook
INCLUDEPATH += $$PWD/../countryregister/data
INCLUDEPATH += $$PWD/../countryregister
TRANSLATIONS = translations/shop_cs_CZ.ts
win32 {
LIBS += -lwinspool
}
eet {
CONFIG(debug, debug|release) {
LIBS += -L$$PWD/../../EetCpp/bin/debug -lEetCpp
} else {
LIBS += -L$$PWD/../../EetCpp/bin/release -lEetCpp
}
DEFINES += EET
}
INCLUDEPATH += $$PWD/../../EetCpp/libEet
DEPENDPATH += $$PWD/../../EetCpp/libEet
+9
View File
@@ -2,6 +2,7 @@
#define SHOP_GLOBAL_H
#include <QtCore/qglobal.h>
#include <QxOrm.h>
#if defined(SHOP_LIBRARY)
# define SHOPSHARED_EXPORT Q_DECL_EXPORT
@@ -9,4 +10,12 @@
# define SHOPSHARED_EXPORT Q_DECL_IMPORT
#endif
#ifdef SHOP_LIBRARY
#define QX_REGISTER_HPP_SHOP QX_REGISTER_HPP_EXPORT_DLL
#define QX_REGISTER_CPP_SHOP QX_REGISTER_CPP_EXPORT_DLL
#else // SHOP_LIBRARY
#define QX_REGISTER_HPP_SHOP QX_REGISTER_HPP_IMPORT_DLL
#define QX_REGISTER_CPP_SHOP QX_REGISTER_CPP_IMPORT_DLL
#endif
#endif // SHOP_GLOBAL_H
+29 -28
View File
@@ -18,9 +18,7 @@
#include "data/favorititem.h"
#include "favbutton.h"
#include "shop-odb.hxx"
void payVoucherFromUI(VoucherPtr voucher, PayDialog *dialog, ShopForm *form)
void payVoucherFromUI(const VoucherPtr& voucher, PayDialog *dialog, ShopForm *form)
{
ShopService srv;
srv.pay(voucher);
@@ -43,11 +41,11 @@ void payVoucherFromUI(VoucherPtr voucher, PayDialog *dialog, ShopForm *form)
errMsg += QObject::tr("Switch to offline?");
if (srv.isEetOnline() && QMessageBox::question(NULL, QObject::tr("EET error"), errMsg) == QMessageBox::Yes)
if (srv.isEetOnline() && QMessageBox::question(nullptr, QObject::tr("EET error"), errMsg) == QMessageBox::Yes)
{
srv.setEetOnline(false);
if (form != NULL)
if (form != nullptr)
{
form->setEetStatusText(srv.isEetOnline() ? QObject::tr("<a href=\"#eet\">Online</a>") : QObject::tr("<a href=\"#eet\">Offline</a>"));
}
@@ -65,8 +63,8 @@ ShopForm::ShopForm(QWidget *parent) :
ui(new Ui::ShopForm)
{
ui->setupUi(this);
m_itemsModel = NULL;
m_commodityModel = NULL;
m_itemsModel = nullptr;
m_commodityModel = nullptr;
m_itemFound = false;
ui->temporarySaveButton->setEnabled(false);
@@ -89,7 +87,7 @@ ShopForm::~ShopForm()
void ShopForm::loadLast()
{
if (m_itemsModel == NULL)
if (m_itemsModel == nullptr)
{
m_itemsModel = new AutoTableModel<VoucherItem>(this);
m_itemsModel->setEditableCols(QList<int>() << 2);
@@ -118,7 +116,7 @@ void ShopForm::loadLast()
if (!receipt.isEmpty())
{
m_voucher = receipt[0];
srv.loadItems(m_voucher);
srv.load(m_voucher);
m_itemsModel->setData(m_voucher->items());
connectItemSignals();
@@ -133,9 +131,9 @@ void ShopForm::loadLast()
}
}
if (m_commodityModel == NULL)
if (m_commodityModel == nullptr)
{
m_commodityModel = new AutoTableModel<ShopItem>(this);
m_commodityModel = new AutoTableModel<IShopItem>(this);
m_commodityModel->setTranslations(Context::instance().plugin("SHOP")->translations());
ui->commodityTable->setModel(m_commodityModel);
@@ -218,7 +216,7 @@ void ShopForm::loadButtons(const ShopSettingsPtr& settings)
ui->commoditySearch->setFocus();
}
void ShopForm::fillRaceiptCombo()
void ShopForm::fillReceiptCombo()
{
bool oldState = ui->receiptCombo->blockSignals(true);
@@ -229,7 +227,7 @@ void ShopForm::fillRaceiptCombo()
ui->receiptCombo->addItem(tr("<< empty >>"));
foreach (QSharedPointer<Voucher> voucher, receipts) {
ui->receiptCombo->addItem(voucher->name(), voucher->id());
ui->receiptCombo->addItem(voucher->name(), (qlonglong)voucher->id());
}
ui->receiptCombo->blockSignals(oldState);
@@ -249,7 +247,7 @@ void ShopForm::setupForm()
ui->lblCount->setVisible(settings->showCount());
loadLast();
fillRaceiptCombo();
fillReceiptCombo();
loadButtons(settings);
}
@@ -285,7 +283,7 @@ void ShopForm::on_saveButton_clicked()
{
m_voucher->setStatus(Voucher::NOT_PAID);
m_voucher->setSaveDateTime(QDateTime::currentDateTime());
srv.updateVoucher(m_voucher);
srv.update(m_voucher);
createEmptyVoucher();
}
else
@@ -293,7 +291,7 @@ void ShopForm::on_saveButton_clicked()
VoucherPtr selVoucher = form->selectedVoucher();
srv.moveItems(m_voucher->items(), m_voucher, selVoucher);
srv.calculate(selVoucher);
srv.updateVoucher(selVoucher);
srv.update(selVoucher);
createEmptyVoucher();
}
@@ -365,13 +363,13 @@ void ShopForm::doTempSave(bool comboChanged)
TemporaryReceiptSaveForm *form = new TemporaryReceiptSaveForm(m_voucher, this);
form->setAttribute(Qt::WA_DeleteOnClose);
connect(form, &QDialog::accepted, [this, form, comboChanged](){
connect(form, &QDialog::accepted, [this, comboChanged](){
ShopService srv;
if (!m_voucher->items().isEmpty())
{
m_voucher->setStatus(Voucher::TEMPORARY);
srv.updateVoucher(m_voucher);
srv.update(m_voucher);
}
if (comboChanged && ui->receiptCombo->currentIndex() > 0)
@@ -383,7 +381,7 @@ void ShopForm::doTempSave(bool comboChanged)
createEmptyVoucher();
}
fillRaceiptCombo();
fillReceiptCombo();
m_itemsModel->setData(m_voucher->items());
});
@@ -396,10 +394,13 @@ void ShopForm::changeReceipt()
ShopService srv;
m_voucher = srv.loadById(ui->receiptCombo->currentData().toInt());
srv.loadItems(m_voucher);
if (m_voucher->items().isEmpty()) {
srv.load(m_voucher);
}
connectItemSignals();
m_voucher->setStatus(Voucher::NEW);
srv.updateVoucher(m_voucher);
srv.update(m_voucher);
m_itemsModel->setData(m_voucher->items());
//ui->total->setText(m_voucher->totalPrice().toString());
@@ -409,7 +410,7 @@ void ShopForm::changeReceipt()
ui->saveButton->setEnabled(true);
ui->payButton->setEnabled(true);
fillRaceiptCombo();
fillReceiptCombo();
}
void ShopForm::connectItemSignals()
@@ -430,7 +431,7 @@ void ShopForm::createEmptyVoucher()
ui->payButton->setEnabled(false);
}
void ShopForm::addItem(QSharedPointer<IShopItem> item, int count)
void ShopForm::addItem(const QSharedPointer<IShopItem>& item, int count)
{
if (m_voucher.isNull())
{
@@ -517,7 +518,7 @@ void ShopForm::recalculate()
}
else
{
srv.updateVoucher(m_voucher);
srv.update(m_voucher);
}
}
@@ -558,7 +559,7 @@ void ShopForm::on_payButton_clicked()
}
void ShopForm::on_showPaiedButton_clicked()
void ShopForm::on_showPaidButton_clicked()
{
PaydVouchersDialog *dialog = new PaydVouchersDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
@@ -567,7 +568,7 @@ void ShopForm::on_showPaiedButton_clicked()
void ShopForm::on_btnAddItem_clicked()
{
ShopItemPtr item = m_commodityModel->itemFromIndex(ui->commodityTable->currentIndex());
IShopItemPtr item = m_commodityModel->itemFromIndex(ui->commodityTable->currentIndex());
addItem(item, ui->spnCount->value());
}
@@ -631,7 +632,7 @@ void ShopForm::on_commoditySearch_returnPressed()
{
if (m_itemFound)
{
ShopItemPtr item = m_commodityModel->itemFromIndex(ui->commodityTable->currentIndex());
IShopItemPtr item = m_commodityModel->itemFromIndex(ui->commodityTable->currentIndex());
addItem(item, ui->spnCount->value());
}
ui->commoditySearch->clear();
@@ -639,7 +640,7 @@ void ShopForm::on_commoditySearch_returnPressed()
void ShopForm::on_actionDelete_items_triggered()
{
if (QMessageBox::question(this, tr("Delete items"), tr("Realy delete selected voucher items?")) == QMessageBox::Yes) {
if (QMessageBox::question(this, tr("Delete items"), tr("Really delete selected voucher items?")) == QMessageBox::Yes) {
QList<VoucherItemPtr> forDelete;
for (const auto& row : ui->actualReceipt->selectionModel()->selectedIndexes()) {
+4 -4
View File
@@ -42,7 +42,7 @@ private slots:
void on_payButton_clicked();
void on_showPaiedButton_clicked();
void on_showPaidButton_clicked();
void on_btnAddItem_clicked();
@@ -61,19 +61,19 @@ private:
Ui::ShopForm *ui;
QSharedPointer<Voucher> m_voucher;
AutoTableModel<VoucherItem> *m_itemsModel;
AutoTableModel<ShopItem> *m_commodityModel;
AutoTableModel<IShopItem> *m_commodityModel;
bool m_itemFound;
QScopedPointer<QMenu> m_itemCtxMenu;
void loadLast();
void loadButtons(const ShopSettingsPtr& settings);
void fillRaceiptCombo();
void fillReceiptCombo();
void createVoucher();
void doTempSave(bool comboChanged);
void changeReceipt();
void connectItemSignals();
void createEmptyVoucher();
void addItem(QSharedPointer<IShopItem> item, int count);
void addItem(const QSharedPointer<IShopItem>& item, int count);
void setTotalText();
void recalculate();
void updateItemCount(VoucherItem *item, int oldCount);
+3 -10
View File
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>990</width>
<width>1010</width>
<height>643</height>
</rect>
</property>
@@ -124,7 +124,7 @@
</font>
</property>
<property name="text">
<string>Direct Sale</string>
<string>Direct Sell</string>
</property>
<property name="icon">
<iconset resource="shoprc.qrc">
@@ -242,7 +242,6 @@
<widget class="QLabel" name="totalPriceSecondLower">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@@ -294,7 +293,6 @@
<widget class="QLabel" name="totalPriceFirstLower">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@@ -323,7 +321,6 @@
<widget class="QLabel" name="priceNoVat">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@@ -349,7 +346,6 @@
<widget class="QLabel" name="totalPriceVatHigh">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@@ -420,7 +416,6 @@
<widget class="QLabel" name="lblEetState">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@@ -453,7 +448,6 @@
<property name="font">
<font>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@@ -470,7 +464,6 @@
<property name="font">
<font>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
@@ -555,7 +548,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="showPaiedButton">
<widget class="QPushButton" name="showPaidButton">
<property name="font">
<font>
<pointsize>10</pointsize>
+1 -1
View File
@@ -1,6 +1,6 @@
#include "shopitem.h"
ShopItem::ShopItem(QObject *parent) : QObject(parent)
ShopItem::ShopItem(QObject *parent) : IShopItem(parent)
{
}
+9 -9
View File
@@ -6,7 +6,7 @@
#include "shop_global.h"
#include "ishopitem.h"
class SHOPSHARED_EXPORT ShopItem : public QObject, public IShopItem
class SHOPSHARED_EXPORT ShopItem : public IShopItem
{
Q_OBJECT
@@ -17,7 +17,7 @@ class SHOPSHARED_EXPORT ShopItem : public QObject, public IShopItem
Q_PROPERTY(Enums::VatType vatType READ vatType)
public:
explicit ShopItem(QObject *parent = 0);
explicit ShopItem(QObject *parent = nullptr);
signals:
@@ -25,13 +25,13 @@ public slots:
// IShopItem interface
public:
virtual int id() override { return 0; }
virtual QString code() { return ""; }
virtual QString name() override { return ""; }
virtual QString shortName() override { return ""; }
virtual QDecDouble unitPrice() override { return QDecDouble(); }
virtual Enums::VatType vatType() override { return Enums::NONE; }
virtual QString pluginId() override { return ""; }
long id() override { return 0; }
QString code() override { return ""; }
QString name() override { return ""; }
QString shortName() override { return ""; }
QDecDouble unitPrice() override { return {}; }
Enums::VatType vatType() override { return Enums::NONE; }
QString pluginId() override { return ""; }
};
typedef QSharedPointer<ShopItem> ShopItemPtr;
+2 -3
View File
@@ -1,6 +1,5 @@
#include "shopoverview.h"
#include "ui_shopoverview.h"
#include "shop-odb.hxx"
#include "shopservice.h"
ShopOverview::ShopOverview(QWidget *parent) :
@@ -22,7 +21,7 @@ void ShopOverview::refresh()
VoucherSum unpaid = srv.unpaidSummary();
VoucherSum unsend = srv.unsendEET();
ui->labelUnapiedCount->setText(QString::number(unpaid.m_count));
ui->labelUnapiedCount->setText(QString::number(unpaid.count()));
ui->labelUnpaiedAmount->setText(QString::number(unpaid.totalPrice().toDouble()));
ui->labelUnsendEET->setText(QString::number(unsend.m_count));
ui->labelUnsendEET->setText(QString::number(unsend.count()));
}
+40 -95
View File
@@ -1,23 +1,20 @@
#include "shopservice.h"
#include "numberseriesservice.h"
#include "isellableservice.h"
#include "shop-odb.hxx"
#include "settings/shopsettings.h"
#ifdef EET
#include <eetcpp.h>
#endif
#include <QEventLoop>
#include <seasonservice.h>
#include <math.h>
#include <cmath>
#ifdef _WIN32
inline double round(double value) { return value < 0 ? -std::floor(0.5 - value) : std::floor(0.5 + value); }
#endif
ShopService::ShopService()
{
}
VoucherPtr ShopService::createVoucher()
{
QSharedPointer<Voucher> voucher(new Voucher);
@@ -41,6 +38,7 @@ void ShopService::addShopItem(VoucherPtr voucher, QSharedPointer<IShopItem> item
vItem->setItemPlugin(item->pluginId());
vItem->setVatType(item->vatType());
vItem->setInsertDate(QDateTime::currentDateTime());
vItem->setVoucher(voucher);
voucher->addItem(vItem);
@@ -62,6 +60,10 @@ void ShopService::calculate(VoucherPtr voucher)
loadSettings();
if (voucher->items().isEmpty()) {
load(voucher);
}
foreach (QSharedPointer<VoucherItem> item, voucher->items()) {
if (item->refId() == ROUNDING_ITEM)
@@ -159,34 +161,27 @@ void ShopService::calculateItem(VoucherItemPtr item)
}
}
void ShopService::loadItems(VoucherPtr voucher)
{
Service<VoucherItem> srv;
voucher->setItems(srv.all(QString("voucher = %1").arg(voucher->id())));
}
void ShopService::pay(VoucherPtr voucher)
{
Transaction tx;
NumberSeriesService srvNs;
voucher->setNumSer(srvNs.nextStrForPlugin("SHOP"));
qx::QxSession session;
voucher->setNumSer(srvNs.nextStrForPlugin("SHOP", &session));
voucher->setStatus(Voucher::PAID);
voucher->setEetStatus(Voucher::EET_FOR_SEND);
voucher->setPayDateTime(QDateTime::currentDateTime());
this->update(voucher);
tx.commit();
this->update(voucher, &session);
}
void ShopService::updateRelatedItem(VoucherItem* item, int countAdded)
{
IPlugin *plugin = Context::instance().plugin(item->itemPlugin());
IService *srv = (plugin != NULL ? plugin->service<IService>() : NULL);
IService *srv = (plugin != nullptr ? plugin->service<IService>() : nullptr);
ISellableService *selSrv = dynamic_cast<ISellableService*>(srv);
if (selSrv != NULL)
if (selSrv != nullptr)
{
selSrv->addedToVoucher(item->refId(), countAdded);
}
@@ -359,39 +354,41 @@ VoucherItemPtr ShopService::roundingItem(VoucherPtr voucher)
}
}
return VoucherItemPtr();
return {};
}
void ShopService::moveItems(QList<VoucherItemPtr> items, VoucherPtr source, VoucherPtr target)
{
Transaction tx;
if (source->items().isEmpty()) {
load(source);
}
if (target->items().isEmpty()) {
load(target);
}
qx::QxSession session;
if (target->status() == Voucher::NEW && target->id() == 0)
{
this->saveVoucher(target);
this->saveVoucher(target, &session);
}
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());
for (const auto& it : items) {
target->addItem(it);
source->removeItem(it);
it->setVoucher(target);
}
loadItems(source);
loadItems(target);
if (source->items().isEmpty())
{
erase(source);
erase(source, &session);
}
else
{
calculate(source);
update(source);
update(source, &session);
}
tx.commit();
}
QList<VoucherPtr> ShopService::savedVouchers()
@@ -418,14 +415,14 @@ QList<VoucherPtr> ShopService::vouchersForEet()
.arg(QString::number(Voucher::PAID), QString::number(Voucher::EET_SENT), QString::number(Voucher::EET_NOT_ENTERING)));
}
QList<ShopItemPtr> ShopService::allSellableItems()
QList<IShopItemPtr> ShopService::allSellableItems()
{
QList<QSharedPointer<ShopItem> > items;
QList<QSharedPointer<IShopItem> > items;
foreach (IPlugin *plugin, Context::instance().plugins()) {
IService *srv = plugin->service<IService>();
ISellableService *selSrv = dynamic_cast<ISellableService*>(srv);
if (selSrv != NULL)
if (selSrv != nullptr)
{
items.append(selSrv->shopItems());
}
@@ -436,29 +433,17 @@ QList<ShopItemPtr> ShopService::allSellableItems()
VoucherSum ShopService::unpaidSummary()
{
Transaction tr;
VoucherSum sum; //= db->query_value<VoucherSum>("status = " + query::_ref((int)Voucher::NOT_PAID));
odb::database *db = Context::instance().db();
typedef odb::query<VoucherSum> query;
VoucherSum sum = db->query_value<VoucherSum>("status = " + query::_ref((int)Voucher::NOT_PAID));
tr.commit();
return sum;
}
VoucherSum ShopService::unsendEET()
{
Transaction tr;
VoucherSum sum; //= db->query_value<VoucherSum>("(eetStatus = " + query::_ref((int)Voucher::EET_FOR_SEND)
//+ " OR eetStatus = " + query::_ref((int)Voucher::EET_ERROR)
//+ ") AND status = " + query::_ref((int)Voucher::PAID));
odb::database *db = Context::instance().db();
typedef odb::query<VoucherSum> query;
VoucherSum sum = db->query_value<VoucherSum>("(eetStatus = " + query::_ref((int)Voucher::EET_FOR_SEND)
+ " OR eetStatus = " + query::_ref((int)Voucher::EET_ERROR)
+ ") AND status = " + query::_ref((int)Voucher::PAID));
tr.commit();
return sum;
}
@@ -506,53 +491,13 @@ QDecDouble ShopService::vatRate(Enums::VatType vatType)
return vatRate;
}
void ShopService::saveVoucher(VoucherPtr entity)
void ShopService::saveVoucher(VoucherPtr entity, qx::QxSession* pSession/* = nullptr*/)
{
SeasonService seasonSrv;
SeasonPtr season = seasonSrv.active();
entity->setSeason(season);
Transaction tr;
odb::database *db = Context::instance().db();
addDateAndUser(entity, true);
db->persist(entity);
foreach (QSharedPointer<VoucherItem> item, entity->items()) {
item->setVoucher(entity.toWeakRef());
db->persist(item);
}
tr.commit();
save(entity, pSession);
}
void ShopService::updateVoucher(VoucherPtr entity)
{
Transaction tr;
odb::database *db = Context::instance().db();
db->execute(QString("DELETE FROM VoucherItem WHERE voucher = %1").arg(entity->id()).toStdString());
foreach (QSharedPointer<VoucherItem> item, entity->items()) {
item->setVoucher(entity.toWeakRef());
db->persist(item);
}
addDateAndUser(entity, false);
db->update(entity);
tr.commit();
}
void ShopService::eraseVoucher(VoucherPtr entity)
{
Transaction tr;
odb::database *db = Context::instance().db();
db->execute(QString("DELETE FROM VoucherItem WHERE voucher = %1").arg(entity->id()).toStdString());
db->erase(entity);
tr.commit();
}
+4 -9
View File
@@ -16,18 +16,18 @@
class PayDialog;
class ShopForm;
void SHOPSHARED_EXPORT payVoucherFromUI(VoucherPtr voucher, PayDialog *dialog, ShopForm *form = NULL);
void SHOPSHARED_EXPORT payVoucherFromUI(const VoucherPtr& voucher, PayDialog *dialog, ShopForm *form = nullptr);
class SHOPSHARED_EXPORT ShopService : public Service<Voucher>
{
public:
ShopService();
ShopService() = default;
VoucherPtr createVoucher();
void addShopItem(VoucherPtr voucher, QSharedPointer<IShopItem> item, int count);
void calculate(VoucherPtr voucher);
void calculateItem(VoucherItemPtr item);
void loadItems(VoucherPtr voucher);
void pay(VoucherPtr voucher);
void saveVoucher(VoucherPtr entity, qx::QxSession* pSession = nullptr);
void moveItems(QList<VoucherItemPtr> items, VoucherPtr source, VoucherPtr target);
void updateRelatedItem(VoucherItem* item, int countAdded);
bool processEet(VoucherPtr voucher, QString &message);
@@ -40,7 +40,7 @@ public:
QList<VoucherPtr> tempVouchers();
QList<VoucherPtr> paiedVouchers();
QList<VoucherPtr> vouchersForEet();
QList<ShopItemPtr> allSellableItems();
QList<IShopItemPtr> allSellableItems();
VoucherSum unpaidSummary();
VoucherSum unsendEET();
@@ -51,11 +51,6 @@ private:
QSharedPointer<GlobalSettings> m_gs;
QDecDouble vatRate(Enums::VatType vatType);
public:
void saveVoucher(VoucherPtr entity);
void updateVoucher(VoucherPtr entity);
void eraseVoucher(VoucherPtr entity);
};
#endif // SHOPSERVICE_H