Added support for saving receipts.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "shopservice.h"
|
||||
#include "shop-odb.hxx"
|
||||
|
||||
ShopService::ShopService()
|
||||
{
|
||||
@@ -78,6 +79,12 @@ void ShopService::calculateItem(QSharedPointer<VoucherItem> item)
|
||||
}
|
||||
}
|
||||
|
||||
void ShopService::loadItems(QSharedPointer<Voucher> voucher)
|
||||
{
|
||||
Service<VoucherItem> srv;
|
||||
voucher->setItems(srv.all(QString("voucher = %1").arg(voucher->id())));
|
||||
}
|
||||
|
||||
QDecDouble ShopService::includeVat(QDecDouble price, Enums::VatType vatType)
|
||||
{
|
||||
return price * ((vatRate(vatType) / 100) + QDecDouble(1));
|
||||
@@ -116,3 +123,35 @@ QDecDouble ShopService::vatRate(Enums::VatType vatType)
|
||||
|
||||
return vatRate;
|
||||
}
|
||||
|
||||
void ShopService::save(QSharedPointer<Voucher> entity)
|
||||
{
|
||||
Transaction tr;
|
||||
odb::database *db = Context::instance().db();
|
||||
|
||||
db->persist(entity);
|
||||
|
||||
foreach (QSharedPointer<VoucherItem> item, entity->items()) {
|
||||
item->setVoucher(entity.toWeakRef());
|
||||
db->persist(item);
|
||||
}
|
||||
|
||||
tr.commit();
|
||||
}
|
||||
|
||||
void ShopService::update(QSharedPointer<Voucher> 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);
|
||||
}
|
||||
|
||||
db->update(entity);
|
||||
|
||||
tr.commit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user