Added support for saving receipts.

This commit is contained in:
2016-05-29 18:31:46 +02:00
parent 9707ec7c66
commit facaf98cf0
14 changed files with 128 additions and 32 deletions
+39
View File
@@ -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();
}