Added support for Value Added Tax.

master
Josef Rokos 7 years ago
parent 8e7137f3bb
commit b8ed333c3a

@ -7,6 +7,8 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
m_vatHigh = 0;
m_vatFirstLower = 0;
m_vatSecondLower = 0;
m_vatPayer = false;
m_pricesWithVAT = true;
}
QString GlobalSettings::firmName() const
@ -156,5 +158,15 @@ void GlobalSettings::setPhone(const QString &phone)
m_phone = phone;
}
bool GlobalSettings::pricesWithVAT() const
{
return m_pricesWithVAT;
}
void GlobalSettings::setPricesWithVAT(bool pricesWithVAT)
{
m_pricesWithVAT = pricesWithVAT;
}

@ -18,6 +18,7 @@ class CORESHARED_EXPORT GlobalSettings : public QObject
Q_PROPERTY(int ic READ ic WRITE setIc)
Q_PROPERTY(QString dic READ dic WRITE setDic)
Q_PROPERTY(bool vatPayer READ vatPayer WRITE setVatPayer)
Q_PROPERTY(bool pricesWithVAT READ pricesWithVAT WRITE setPricesWithVAT)
Q_PROPERTY(QString logoPath READ logoPath WRITE setLogoPath)
Q_PROPERTY(QDecDouble vatHigh READ vatHigh WRITE setVatHigh)
Q_PROPERTY(QDecDouble vatFirstLower READ vatFirstLower WRITE setVatFirstLower)
@ -74,6 +75,9 @@ public:
QString phone() const;
void setPhone(const QString &phone);
bool pricesWithVAT() const;
void setPricesWithVAT(bool pricesWithVAT);
private:
QString m_firmName;
QString m_street;
@ -83,6 +87,7 @@ private:
int m_ic;
QString m_dic;
bool m_vatPayer;
bool m_pricesWithVAT;
QString m_logoPath;
int m_vatHigh;
int m_vatFirstLower;

@ -24,6 +24,7 @@ GlobalSettingsForm::GlobalSettingsForm(QWidget *parent) :
registerBinding(ui->city);
registerBinding(ui->ic);
registerBinding(ui->vatPayer);
registerBinding(ui->pricesWithVAT);
registerBinding(ui->dic);
registerBinding(ui->vatHigh);
registerBinding(ui->vatFirstLower);
@ -110,6 +111,7 @@ void GlobalSettingsForm::loadEntity()
QSharedPointer<GlobalSettings> settings = srv.loadSettings<GlobalSettings>();
setEntity(settings);
ui->grpVat->setEnabled(settings->vatPayer());
ui->pricesWithVAT->setEnabled(settings->vatPayer());
if (!settings->logoPath().isEmpty())
{
@ -123,6 +125,7 @@ void GlobalSettingsForm::loadEntity()
void GlobalSettingsForm::on_vatPayer_toggled(bool checked)
{
ui->grpVat->setEnabled(checked);
ui->pricesWithVAT->setEnabled(checked);
}
void GlobalSettingsForm::on_season_currentIndexChanged(int)

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>759</width>
<height>557</height>
<height>630</height>
</rect>
</property>
<property name="windowTitle">
@ -253,6 +253,13 @@
</layout>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="pricesWithVAT">
<property name="text">
<string>Prices with VAT</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

@ -148,9 +148,16 @@ QByteArray ReceiptGenerator::generate()
QString price = QString::number(item->price().toDouble(), 'f', 2);
int numSpaces = 0;
name = count + "x " + name;
if (gs->vatPayer())
{
out.append(prepareString("DPH " + QString::number(item->vatRate().toDouble(), 'f', 0)) + "%");
out.append("\x0a");
}
if ((name.length() + price.length()) < shopSettings->lettersPerLine())
{
name = count + "x " + name;
numSpaces = shopSettings->lettersPerLine() - (name.length() + price.length());
out.append(prepareString(name));
}
@ -179,6 +186,100 @@ QByteArray ReceiptGenerator::generate()
out.append((char)0);
out.append("\x0a");
if (gs->vatPayer())
{
QString zaklad = "Zaklad DPH ";
QString dph = "DPH ";
QString output;
QDecDouble zero(0);
if (m_voucher->vatAmountHigh() > zero)
{
output = zaklad + QString::number(m_voucher->vatRateHigh().toDouble()) + "%";
out.append(prepareString(output));
QString amount = QString::number(m_voucher->priceVatHigh().toDouble(), 'f', 2);
int numSpaces = shopSettings->lettersPerLine() - (output.length() + amount.length());
for (int i = 0; i < numSpaces; i++)
{
out.append(" ");
}
out.append(prepareString(amount));
out.append("\x0a");
output = dph + QString::number(m_voucher->vatRateHigh().toDouble()) + "%";
out.append(prepareString(output));
amount = QString::number(m_voucher->vatAmountHigh().toDouble(), 'f', 2);
numSpaces = shopSettings->lettersPerLine() - (output.length() + amount.length());
for (int i = 0; i < numSpaces; i++)
{
out.append(" ");
}
out.append(prepareString(amount));
out.append("\x0a");
}
if (m_voucher->vatAmountFirstLower() > zero)
{
output = zaklad + QString::number(m_voucher->vatRateFirstLower().toDouble()) + "%";
out.append(prepareString(output));
QString amount = QString::number(m_voucher->priceVatFirstLower().toDouble(), 'f', 2);
int numSpaces = shopSettings->lettersPerLine() - (output.length() + amount.length());
for (int i = 0; i < numSpaces; i++)
{
out.append(" ");
}
out.append(prepareString(amount));
out.append("\x0a");
output = dph + QString::number(m_voucher->vatRateFirstLower().toDouble()) + "%";
out.append(prepareString(output));
amount = QString::number(m_voucher->vatAmountFirstLower().toDouble(), 'f', 2);
numSpaces = shopSettings->lettersPerLine() - (output.length() + amount.length());
for (int i = 0; i < numSpaces; i++)
{
out.append(" ");
}
out.append(prepareString(amount));
out.append("\x0a");
}
if (m_voucher->VatAmountSecondLower() > zero)
{
output = zaklad + QString::number(m_voucher->vatRateSecondLower().toDouble()) + "%";
out.append(prepareString(output));
QString amount = QString::number(m_voucher->priceVatSecondLower().toDouble(), 'f', 2);
int numSpaces = shopSettings->lettersPerLine() - (output.length() + amount.length());
for (int i = 0; i < numSpaces; i++)
{
out.append(" ");
}
out.append(prepareString(amount));
out.append("\x0a");
output = dph + QString::number(m_voucher->vatRateSecondLower().toDouble()) + "%";
out.append(prepareString(output));
amount = QString::number(m_voucher->VatAmountSecondLower().toDouble(), 'f', 2);
numSpaces = shopSettings->lettersPerLine() - (output.length() + amount.length());
for (int i = 0; i < numSpaces; i++)
{
out.append(" ");
}
out.append(prepareString(amount));
out.append("\x0a");
}
out.append("\x1b\x21");
out.append(printMode);
for (int i = 0; i < shopSettings->lettersPerLine(); i++ )
{
out.append("-");
}
out.append("\x1b\x21");
out.append((char)0);
out.append("\x0a");
}
out.append("\x1b\x21");
out.append(printMode);
out.append("Celkem:");

@ -13,6 +13,9 @@ ShopSettings::ShopSettings(QObject *parent) : QObject(parent)
m_favBtnCols = 0;
m_favBtnRows = 0;
m_favBtnSize = 0;
m_rounding = Enums::R_NONE;
m_decimalPlaces = 0;
}
QString ShopSettings::output() const
@ -164,3 +167,33 @@ void ShopSettings::setFavBtnSize(int favBtnSize)
{
m_favBtnSize = favBtnSize;
}
Enums::Rounding ShopSettings::rounding() const
{
return m_rounding;
}
void ShopSettings::setRounding(const Enums::Rounding &rounding)
{
m_rounding = rounding;
}
int ShopSettings::decimalPlaces() const
{
return m_decimalPlaces;
}
void ShopSettings::setDecimalPlaces(int decimalPlaces)
{
m_decimalPlaces = decimalPlaces;
}
QString ShopSettings::roundingItem() const
{
return m_roundingItem;
}
void ShopSettings::setRoundingItem(const QString &roundingItem)
{
m_roundingItem = roundingItem;
}

@ -2,6 +2,7 @@
#define RECEIPTSETTINGS_H
#include <QObject>
#include <enums.h>
class ShopSettings : public QObject
{
@ -22,6 +23,10 @@ class ShopSettings : public QObject
Q_PROPERTY(int favBtnRows READ favBtnRows WRITE setFavBtnRows)
Q_PROPERTY(int favBtnSize READ favBtnSize WRITE setFavBtnSize)
Q_PROPERTY(Enums::Rounding rounding READ rounding WRITE setRounding)
Q_PROPERTY(int decimalPlaces READ decimalPlaces WRITE setDecimalPlaces)
Q_PROPERTY(QString roundingItem READ roundingItem WRITE setRoundingItem)
Q_OBJECT
public:
@ -77,6 +82,15 @@ public:
int favBtnSize() const;
void setFavBtnSize(int favBtnSize);
Enums::Rounding rounding() const;
void setRounding(const Enums::Rounding &rounding);
int decimalPlaces() const;
void setDecimalPlaces(int decimalPlaces);
QString roundingItem() const;
void setRoundingItem(const QString &roundingItem);
private:
QString m_output;
CODEPAGE m_codepage;
@ -95,6 +109,10 @@ private:
int m_favBtnCols;
int m_favBtnRows;
int m_favBtnSize;
Enums::Rounding m_rounding;
int m_decimalPlaces;
QString m_roundingItem;
};
typedef QSharedPointer<ShopSettings> ShopSettingsPtr;

@ -35,6 +35,16 @@ ShopSettingsForm::ShopSettingsForm(QWidget *parent) :
registerBinding(ui->favBtnRows);
registerBinding(ui->favBtnSize);
QList<ComboData> listRounding;
listRounding
<< ComboData(Enums::R_NONE, tr("None"))
<< ComboData(Enums::R_UP, tr("Up"))
<< ComboData(Enums::R_DOWN, tr("Down"))
<< ComboData(Enums::R_MATH, tr("Mathematic"));
registerBinding(ui->rounding, listRounding);
registerBinding(ui->decimalPlaces);
registerBinding(ui->roundingItem);
m_itemModel = new AutoTableModel<ShopItem>();
}

@ -273,6 +273,55 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_4">
<attribute name="title">
<string>Other</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Rounding</string>
</property>
<layout class="QFormLayout" name="formLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Direction</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="rounding"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Decimal places</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="decimalPlaces"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Rounding item text</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="roundingItem"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>

@ -89,8 +89,18 @@ void ShopForm::loadLast()
ui->actualReceipt->setColumnHidden(0, true);
ui->actualReceipt->setColumnHidden(3, true);
ui->actualReceipt->setColumnHidden(4, true);
ui->actualReceipt->setColumnHidden(5, true);
SettingsService srv("CORE");
GlobalSettingsPtr settings = srv.loadSettings<GlobalSettings>();
if (!settings->vatPayer())
{
ui->actualReceipt->setColumnHidden(5, true);
ui->widgetVAT->setVisible(false);
}
ui->actualReceipt->setColumnHidden(6, true);
ui->actualReceipt->setColumnWidth(2, 50);
ui->actualReceipt->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
}
@ -103,7 +113,8 @@ void ShopForm::loadLast()
m_itemsModel->setData(m_voucher->items());
connectItemSignals();
ui->total->setText(QString::number(m_voucher->totalPrice().toDouble(), 'f', 2));
//ui->total->setText(QString::number(m_voucher->totalPrice().toDouble(), 'f', 2));
setTotalText();
if (!m_voucher->items().isEmpty())
{
@ -319,7 +330,9 @@ void ShopForm::onCountChanged(int oldCount/* = 0*/)
ShopService srv;
srv.calculate(m_voucher);
ui->total->setText(QString::number(m_voucher->totalPrice().toDouble(), 'f', 2));
this->m_itemsModel->setData(m_voucher->items());
setTotalText();
ui->temporarySaveButton->setEnabled(!m_voucher->items().isEmpty());
ui->saveButton->setEnabled(!m_voucher->items().isEmpty());
ui->payButton->setEnabled(!m_voucher->items().isEmpty());
@ -388,7 +401,8 @@ void ShopForm::changeReceipt()
srv.updateVoucher(m_voucher);
m_itemsModel->setData(m_voucher->items());
ui->total->setText(m_voucher->totalPrice().toString());
//ui->total->setText(m_voucher->totalPrice().toString());
setTotalText();
ui->temporarySaveButton->setEnabled(true);
ui->saveButton->setEnabled(true);
@ -408,7 +422,8 @@ void ShopForm::createEmptyVoucher()
{
ShopService srv;
m_voucher = srv.createVoucher();
ui->total->setText("0");
//ui->total->setText("0");
setTotalText();
ui->temporarySaveButton->setEnabled(false);
ui->saveButton->setEnabled(false);
ui->payButton->setEnabled(false);
@ -428,7 +443,7 @@ void ShopForm::addItem(QSharedPointer<IShopItem> item, int count)
auto addFunc = [this](QSharedPointer<IShopItem> shopItem, int itemCount){
ShopService srv;
srv.addShopItem(m_voucher, shopItem, itemCount);
this->m_itemsModel->addRow(m_voucher->items()[m_voucher->items().count() - 1]);
//this->m_itemsModel->addRow(m_voucher->items()[m_voucher->items().count() - 1]);
connect(m_voucher->items()[m_voucher->items().count() - 1].data(), SIGNAL(countChanged(int)), this, SLOT(onCountChanged(int)));
onCountChanged();
};
@ -452,6 +467,28 @@ void ShopForm::addItem(QSharedPointer<IShopItem> item, int count)
ui->commoditySearch->setText("");
}
void ShopForm::setTotalText()
{
ui->total->setText(QString::number(m_voucher->totalPrice().toDouble(), 'f', 2));
ui->vatRateHigh->setText(QString::number(m_voucher->vatRateHigh().toDouble(), 'f', 0) + "%");
ui->vatRateFirstLow->setText(QString::number(m_voucher->vatRateFirstLower().toDouble(), 'f', 0) + "%");
ui->vatRateSecondLow->setText(QString::number(m_voucher->vatRateSecondLower().toDouble(), 'f', 0) + "%");
ui->priceVatHigh->setText(QString::number(m_voucher->priceVatHigh().toDouble(), 'f', 2));
ui->priceVatFirstLower->setText(QString::number(m_voucher->priceVatFirstLower().toDouble(), 'f', 2));
ui->priceVatSecondLower->setText(QString::number(m_voucher->priceVatSecondLower().toDouble(), 'f', 2));
ui->vatHigh->setText(QString::number((m_voucher->totalPriceVatHigh() - m_voucher->priceVatHigh()).toDouble(), 'f', 2));
ui->vatFirstLower->setText(QString::number((m_voucher->totalPriceVatFirstLower() - m_voucher->priceVatFirstLower()).toDouble(), 'f', 2));
ui->vatSecondLower->setText(QString::number((m_voucher->totalPriceVatSecondLower() - m_voucher->priceVatSecondLower()).toDouble(), 'f', 2));
ui->totalPriceVatHigh->setText(QString::number(m_voucher->totalPriceVatHigh().toDouble(), 'f', 2));
ui->totalPriceFirstLower->setText(QString::number(m_voucher->totalPriceVatFirstLower().toDouble(), 'f', 2));
ui->totalPriceSecondLower->setText(QString::number(m_voucher->totalPriceVatSecondLower().toDouble(), 'f', 2));
ui->priceNoVat->setText(QString::number(m_voucher->priceNoVat().toDouble(), 'f', 2));
}
void ShopForm::on_receiptCombo_currentIndexChanged(int)
{
if (!m_voucher.isNull() && m_voucher->items().isEmpty())

@ -63,6 +63,7 @@ private:
void connectItemSignals();
void createEmptyVoucher();
void addItem(QSharedPointer<IShopItem> item, int count);
void setTotalText();
};
#endif // SHOPFORM_H

@ -167,7 +167,226 @@
<widget class="QComboBox" name="receiptCombo"/>
</item>
<item>
<widget class="QTableView" name="actualReceipt"/>
<widget class="QTableView" name="actualReceipt">
<property name="minimumSize">
<size>
<width>400</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widgetVAT" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="2">
<widget class="QLabel" name="vatHigh">
<property name="text">
<string>0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="vatRateSecondLow">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>10%</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="priceVatFirstLower">
<property name="text">
<string>0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="priceVatSecondLower">
<property name="text">
<string>0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="vatFirstLower">
<property name="text">
<string>0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QLabel" name="totalPriceSecondLower">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="vatRateZero">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>0%</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="vatRateHigh">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>21%</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="priceVatHigh">
<property name="text">
<string>0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLabel" name="totalPriceFirstLower">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="vatRateFirstLow">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>15%</string>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="QLabel" name="priceNoVat">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLabel" name="vatSecondLower">
<property name="text">
<string>0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="totalPriceVatHigh">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_17">
<property name="text">
<string>Witouth VAT</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_18">
<property name="text">
<string>VAT</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Total</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
@ -382,8 +601,8 @@
</layout>
</widget>
<resources>
<include location="shoprc.qrc"/>
<include location="../core/rc.qrc"/>
<include location="shoprc.qrc"/>
</resources>
<connections/>
</ui>

@ -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())

@ -11,6 +11,8 @@
#include "shop_global.h"
#define ROUNDING_ITEM -9999
class PayDialog;
class ShopForm;
@ -32,6 +34,8 @@ public:
void setEetOnline(bool online);
bool isEetOnline();
bool isEetEnabled();
void roundVoucher(VoucherPtr voucher);
VoucherItemPtr roundingItem(VoucherPtr voucher);
QList<VoucherPtr> savedVouchers();
QList<VoucherPtr> tempVouchers();
QList<VoucherPtr> paiedVouchers();
@ -40,6 +44,7 @@ public:
private:
QDecDouble includeVat(QDecDouble price, Enums::VatType vatType);
QDecDouble excludeVat(QDecDouble price, Enums::VatType vatType);
void loadSettings();
QSharedPointer<GlobalSettings> m_gs;

Loading…
Cancel
Save