You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.0 KiB
C++
44 lines
1.0 KiB
C++
#include "shopservice.h"
|
|
|
|
ShopService::ShopService()
|
|
{
|
|
|
|
}
|
|
|
|
QSharedPointer<Voucher> ShopService::createVoucher()
|
|
{
|
|
QSharedPointer<Voucher> voucher(new Voucher);
|
|
voucher->setStatus(Voucher::NEW);
|
|
return voucher;
|
|
}
|
|
|
|
void ShopService::addShopItem(QSharedPointer<Voucher> voucher, QSharedPointer<IShopItem> item, int count)
|
|
{
|
|
QSharedPointer<VoucherItem> vItem(new VoucherItem);
|
|
vItem->setName(item->name());
|
|
vItem->setUnitPrice(item->unitPrice());
|
|
vItem->setCount(count);
|
|
vItem->setRefId(item->id());
|
|
vItem->setItemPlugin(item->pluginId());
|
|
vItem->setVatType(item->vatType());
|
|
|
|
voucher->addItem(vItem);
|
|
}
|
|
|
|
void ShopService::calculate(QSharedPointer<Voucher> voucher)
|
|
{
|
|
QDecDouble total;
|
|
|
|
foreach (QSharedPointer<VoucherItem> item, voucher->items()) {
|
|
calculateItem(item);
|
|
total += item->price();
|
|
}
|
|
|
|
voucher->setTotalPrice(total);
|
|
}
|
|
|
|
void ShopService::calculateItem(QSharedPointer<VoucherItem> item)
|
|
{
|
|
item->setPrice(item->unitPrice() * item->count());
|
|
}
|