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
+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();
}