|
|
|
@ -8,6 +8,7 @@
|
|
|
|
|
#include <eetcpp.h>
|
|
|
|
|
#include <QEventLoop>
|
|
|
|
|
#include <seasonservice.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
ShopService::ShopService()
|
|
|
|
|
{
|
|
|
|
@ -16,6 +17,12 @@ ShopService::ShopService()
|
|
|
|
|
VoucherPtr ShopService::createVoucher()
|
|
|
|
|
{
|
|
|
|
|
QSharedPointer<Voucher> voucher(new Voucher);
|
|
|
|
|
|
|
|
|
|
loadSettings();
|
|
|
|
|
voucher->setVatRateHigh(m_gs->vatHigh());
|
|
|
|
|
voucher->setVatRateFirstLower(m_gs->vatFirstLower());
|
|
|
|
|
voucher->setVatRateSecondLower(m_gs->vatSecondLower());
|
|
|
|
|
|
|
|
|
|
voucher->setStatus(Voucher::NEW);
|
|
|
|
|
return voucher;
|
|
|
|
|
}
|
|
|
|
@ -40,39 +47,87 @@ void ShopService::calculate(VoucherPtr voucher)
|
|
|
|
|
{
|
|
|
|
|
QDecDouble total;
|
|
|
|
|
|
|
|
|
|
voucher->setPriceNoVat(0);
|
|
|
|
|
voucher->setPriceVatHigh(0);
|
|
|
|
|
voucher->setPriceVatFirstLower(0);
|
|
|
|
|
voucher->setPriceVatSecondLower(0);
|
|
|
|
|
|
|
|
|
|
voucher->setTotalPriceVatHigh(0);
|
|
|
|
|
voucher->setTotalPriceVatFirstLower(0);
|
|
|
|
|
voucher->setTotalPriceVatSecondLower(0);
|
|
|
|
|
|
|
|
|
|
loadSettings();
|
|
|
|
|
voucher->setVatRateHigh(m_gs->vatHigh());
|
|
|
|
|
voucher->setVatRateFirstLower(m_gs->vatFirstLower());
|
|
|
|
|
voucher->setVatRateSecondLower(m_gs->vatSecondLower());
|
|
|
|
|
|
|
|
|
|
foreach (QSharedPointer<VoucherItem> item, voucher->items()) {
|
|
|
|
|
|
|
|
|
|
if (item->refId() == ROUNDING_ITEM)
|
|
|
|
|
{
|
|
|
|
|
voucher->removeItem(item);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
calculateItem(item);
|
|
|
|
|
|
|
|
|
|
QDecDouble priceWitouthWat = item->priceWitouthVat();
|
|
|
|
|
switch (item->vatType()) {
|
|
|
|
|
case Enums::NONE:
|
|
|
|
|
voucher->setPriceNoVat(voucher->priceNoVat() + priceWitouthWat);
|
|
|
|
|
break;
|
|
|
|
|
case Enums::HIGH:
|
|
|
|
|
voucher->setPriceVatHigh(voucher->priceVatHigh() + priceWitouthWat);
|
|
|
|
|
break;
|
|
|
|
|
case Enums::FIRST_LOWER:
|
|
|
|
|
voucher->setPriceVatFirstLower(voucher->priceVatFirstLower() + priceWitouthWat);
|
|
|
|
|
break;
|
|
|
|
|
case Enums::SECOND_LOWER:
|
|
|
|
|
voucher->setPriceVatSecondLower(voucher->priceVatSecondLower() + priceWitouthWat);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
QDecDouble itemPrice;
|
|
|
|
|
|
|
|
|
|
if (item->vatType() == Enums::NONE)
|
|
|
|
|
{
|
|
|
|
|
voucher->setPriceNoVat(voucher->priceNoVat() + item->priceWitouthVat());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_gs->pricesWithVAT())
|
|
|
|
|
{
|
|
|
|
|
itemPrice = item->price();
|
|
|
|
|
switch (item->vatType()) {
|
|
|
|
|
case Enums::HIGH:
|
|
|
|
|
voucher->setTotalPriceVatHigh(voucher->totalPriceVatHigh() + itemPrice);
|
|
|
|
|
break;
|
|
|
|
|
case Enums::FIRST_LOWER:
|
|
|
|
|
voucher->setTotalPriceVatFirstLower(voucher->totalPriceVatFirstLower() + itemPrice);
|
|
|
|
|
break;
|
|
|
|
|
case Enums::SECOND_LOWER:
|
|
|
|
|
voucher->setTotalPriceVatSecondLower(voucher->totalPriceVatSecondLower() + itemPrice);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
itemPrice = item->priceWitouthVat();
|
|
|
|
|
switch (item->vatType()) {
|
|
|
|
|
case Enums::HIGH:
|
|
|
|
|
voucher->setPriceVatHigh(voucher->priceVatHigh() + itemPrice);
|
|
|
|
|
break;
|
|
|
|
|
case Enums::FIRST_LOWER:
|
|
|
|
|
voucher->setPriceVatFirstLower(voucher->priceVatFirstLower() + itemPrice);
|
|
|
|
|
break;
|
|
|
|
|
case Enums::SECOND_LOWER:
|
|
|
|
|
voucher->setPriceVatSecondLower(voucher->priceVatSecondLower() + itemPrice);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
total += item->price();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
voucher->setTotalPriceVatHigh(includeVat(voucher->priceVatHigh(), Enums::HIGH));
|
|
|
|
|
voucher->setTotalPriceVatFirstLower(includeVat(voucher->priceVatFirstLower(), Enums::FIRST_LOWER));
|
|
|
|
|
voucher->setTotalPriceVatSecondLower(includeVat(voucher->priceVatSecondLower(), Enums::SECOND_LOWER));
|
|
|
|
|
if (m_gs->pricesWithVAT())
|
|
|
|
|
{
|
|
|
|
|
voucher->setPriceVatHigh(excludeVat(voucher->totalPriceVatHigh(), Enums::HIGH));
|
|
|
|
|
voucher->setPriceVatFirstLower(excludeVat(voucher->totalPriceVatFirstLower(), Enums::FIRST_LOWER));
|
|
|
|
|
voucher->setPriceVatSecondLower(excludeVat(voucher->totalPriceVatSecondLower(), Enums::SECOND_LOWER));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
voucher->setTotalPriceVatHigh(includeVat(voucher->priceVatHigh(), Enums::HIGH));
|
|
|
|
|
voucher->setTotalPriceVatFirstLower(includeVat(voucher->priceVatFirstLower(), Enums::FIRST_LOWER));
|
|
|
|
|
voucher->setTotalPriceVatSecondLower(includeVat(voucher->priceVatSecondLower(), Enums::SECOND_LOWER));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
voucher->setTotalPrice(total);
|
|
|
|
|
roundVoucher(voucher);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShopService::calculateItem(VoucherItemPtr item)
|
|
|
|
@ -81,8 +136,17 @@ void ShopService::calculateItem(VoucherItemPtr item)
|
|
|
|
|
if (m_gs->vatPayer())
|
|
|
|
|
{
|
|
|
|
|
item->setVatRate(vatRate(item->vatType()));
|
|
|
|
|
item->setPriceWitouthVat(item->unitPrice() * item->count());
|
|
|
|
|
item->setPrice(includeVat(item->priceWitouthVat(), item->vatType()));
|
|
|
|
|
|
|
|
|
|
if (m_gs->pricesWithVAT())
|
|
|
|
|
{
|
|
|
|
|
item->setPrice(item->unitPrice() * item->count());
|
|
|
|
|
item->setPriceWitouthVat(excludeVat(item->price(), item->vatType()));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
item->setPriceWitouthVat(item->unitPrice() * item->count());
|
|
|
|
|
item->setPrice(includeVat(item->priceWitouthVat(), item->vatType()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -147,6 +211,18 @@ bool ShopService::processEet(VoucherPtr voucher, QString &message)
|
|
|
|
|
request.setDatOdesl(QDateTime::currentDateTime());
|
|
|
|
|
request.setRezim((EetRequest::EetRezim)settings->eetMode());
|
|
|
|
|
|
|
|
|
|
if (m_gs->vatPayer())
|
|
|
|
|
{
|
|
|
|
|
request.setDan1(voucher->vatAmountHigh().toDouble());
|
|
|
|
|
request.setDan2(voucher->vatAmountFirstLower().toDouble());
|
|
|
|
|
request.setDan3(voucher->VatAmountSecondLower().toDouble());
|
|
|
|
|
|
|
|
|
|
request.setZaklDan1(voucher->priceVatHigh().toDouble());
|
|
|
|
|
request.setZaklDan2(voucher->priceVatFirstLower().toDouble());
|
|
|
|
|
request.setZaklDan3(voucher->priceVatSecondLower().toDouble());
|
|
|
|
|
request.setZaklNepodlDph(voucher->priceNoVat().toDouble());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EetSender *sender = new EetSender(this);
|
|
|
|
|
sender->setupSigner(settings->eetCertificate(), settings->eetKeyPassword());
|
|
|
|
|
sender->setPlayground(settings->eetPlayground());
|
|
|
|
@ -232,6 +308,56 @@ bool ShopService::isEetEnabled()
|
|
|
|
|
return settings->eetActive();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShopService::roundVoucher(VoucherPtr voucher)
|
|
|
|
|
{
|
|
|
|
|
SettingsService setSrv("SHOP");
|
|
|
|
|
ShopSettingsPtr settings = setSrv.loadSettings<ShopSettings>();
|
|
|
|
|
QDecDouble totalPrice(voucher->totalPrice());
|
|
|
|
|
|
|
|
|
|
switch (settings->rounding()) {
|
|
|
|
|
case Enums::R_UP:
|
|
|
|
|
totalPrice = QDecDouble(ceil(voucher->totalPrice().toDouble() * pow(10, settings->decimalPlaces())) / pow(10, settings->decimalPlaces()));
|
|
|
|
|
break;
|
|
|
|
|
case Enums::R_DOWN:
|
|
|
|
|
totalPrice = QDecDouble(floor(voucher->totalPrice().toDouble() * pow(10, settings->decimalPlaces())) / pow(10, settings->decimalPlaces()));
|
|
|
|
|
break;
|
|
|
|
|
case Enums::R_MATH:
|
|
|
|
|
totalPrice = QDecDouble(round(voucher->totalPrice().toDouble() * pow(10, settings->decimalPlaces())) / pow(10, settings->decimalPlaces()));
|
|
|
|
|
break;
|
|
|
|
|
case Enums::R_NONE:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VoucherItemPtr roundingItem(new VoucherItem);
|
|
|
|
|
roundingItem->setCount(1);
|
|
|
|
|
roundingItem->setUnitPrice(totalPrice - voucher->totalPrice());
|
|
|
|
|
roundingItem->setVatType(Enums::NONE);
|
|
|
|
|
roundingItem->setName(settings->roundingItem());
|
|
|
|
|
roundingItem->setRefId(ROUNDING_ITEM);
|
|
|
|
|
roundingItem->setVoucher(voucher);
|
|
|
|
|
|
|
|
|
|
calculateItem(roundingItem);
|
|
|
|
|
|
|
|
|
|
if (roundingItem->price() != QDecDouble(0))
|
|
|
|
|
{
|
|
|
|
|
voucher->addItem(roundingItem);
|
|
|
|
|
voucher->setPriceNoVat(voucher->priceNoVat() + roundingItem->price());
|
|
|
|
|
voucher->setTotalPrice(totalPrice);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VoucherItemPtr ShopService::roundingItem(VoucherPtr voucher)
|
|
|
|
|
{
|
|
|
|
|
foreach (VoucherItemPtr item, voucher->items()) {
|
|
|
|
|
if (item->refId() == ROUNDING_ITEM)
|
|
|
|
|
{
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return VoucherItemPtr();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShopService::moveItems(QList<VoucherItemPtr> items, VoucherPtr source, VoucherPtr target)
|
|
|
|
|
{
|
|
|
|
|
Transaction tx;
|
|
|
|
@ -306,6 +432,11 @@ QDecDouble ShopService::includeVat(QDecDouble price, Enums::VatType vatType)
|
|
|
|
|
return price * ((vatRate(vatType) / 100) + QDecDouble(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QDecDouble ShopService::excludeVat(QDecDouble price, Enums::VatType vatType)
|
|
|
|
|
{
|
|
|
|
|
return price / ((vatRate(vatType) / 100) + QDecDouble(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShopService::loadSettings()
|
|
|
|
|
{
|
|
|
|
|
if (m_gs.isNull())
|
|
|
|
|