Added pay voucher feature. Added dialog with paied vouchers. Added

support for printing receipts on POS printer.
print
Rokos Josef 9 years ago
parent a89b0381b1
commit e6dfc8ec21

@ -7,9 +7,10 @@
#include <odb/core.hxx>
#include "season.h"
#include "core_global.h"
#pragma db object
class NumberSeries : public QObject
class CORESHARED_EXPORT NumberSeries : public QObject
{
Q_OBJECT
Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)

@ -80,4 +80,6 @@ signals:
public slots:
};
typedef QSharedPointer<GlobalSettings> GlobalSettingsPtr;
#endif // GLOBALSETTINGS_H

@ -210,6 +210,26 @@ QDecDouble Voucher::VatAmountSecondLower()
return TO_DEC(m_totalPriceVatSecondLower) - TO_DEC(m_priceVatSecondLower);
}
QString Voucher::numSer() const
{
return m_numSer;
}
void Voucher::setNumSer(const QString &numSer)
{
m_numSer = numSer;
}
QDateTime Voucher::payDateTime() const
{
return m_payDateTime;
}
void Voucher::setPayDateTime(const QDateTime &payDateTime)
{
m_payDateTime = payDateTime;
}
int Voucher::id() const
{
return m_id;

@ -16,6 +16,8 @@ class Voucher : public QObject
{
Q_OBJECT
Q_PROPERTY(QString numSer READ numSer WRITE setNumSer)
Q_PROPERTY(QDateTime payDateTime READ payDateTime WRITE setPayDateTime)
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(QString description READ description WRITE setDescription)
Q_PROPERTY(QSharedPointer<QObject> contact READ contact WRITE setContact)
@ -102,10 +104,18 @@ public:
QDecDouble vatAmountFirstLower();
QDecDouble VatAmountSecondLower();
QString numSer() const;
void setNumSer(const QString &numSer);
QDateTime payDateTime() const;
void setPayDateTime(const QDateTime &payDateTime);
private:
friend class odb::access;
#pragma db id auto
int m_id;
QString m_numSer;
QDateTime m_payDateTime;
QString m_name;
QString m_description;
QSharedPointer<AddressbookData> m_contact;

@ -0,0 +1 @@
<?xml version="1.0" ?><svg clip-rule="evenodd" fill-rule="evenodd" image-rendering="optimizeQuality" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg"><defs><linearGradient gradientUnits="userSpaceOnUse" id="a" x1="249.999" x2="249.999" y1="112.399" y2="412.599"><stop offset="0" stop-color="#FCFCFD"/><stop offset="1" stop-color="#fff"/></linearGradient><linearGradient gradientUnits="userSpaceOnUse" id="b" x1="249.998" x2="249.998" y1="34.201" y2="85.799"><stop offset="0" stop-color="#008BFF"/><stop offset="1" stop-color="#0af"/></linearGradient></defs><g><path d="M95 65h310c8 0 15 7 15 15v365c0 8-7 15-15 15h-310c-8 0-15-7-15-15v-365c0-8 7-15 15-15z" fill="url(#a)" stroke="#434242" stroke-width="10"/><path d="M378 90h-256c-2 0-4-1-5-3 0-2 0-4 2-6l30-30c1-1 2-1 3-1h63c3 0 5-2 5-5v-10c0-3 2-5 5-5h50c3 0 5 2 5 5v10c0 3 2 5 5 5h63c1 0 2 0 3 1l30 30c2 2 2 4 2 6-1 2-3 3-5 3z" fill="url(#b)" stroke="#434242" stroke-width="10"/><path d="M120 140h40v40h-40v-40zm0 80h40v40h-40v-40zm0 80h40v40h-40v-40zm0 80h40v40h-40v-40zm55-210h165v10h-165v-10zm0 80h105v10h-105v-10zm0 80h165v10h-165v-10zm0 80h180v10h-180v-10zm0-265h205v10h-205v-10zm0 80h165v10h-165v-10zm0 80h130v10h-130v-10zm0 80h150v10h-150v-10z" fill="#434242"/></g></svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

@ -0,0 +1 @@
<?xml version="1.0" ?><svg clip-rule="evenodd" fill-rule="evenodd" image-rendering="optimizeQuality" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg"><defs><linearGradient gradientUnits="userSpaceOnUse" id="a" x1="249.997" x2="249.997" y1="82.801" y2="417.199"><stop offset="0" stop-color="#FCFCFD"/><stop offset="1" stop-color="#fff"/></linearGradient><linearGradient gradientUnits="userSpaceOnUse" id="b" x1="249.998" x2="249.998" y1="62.399" y2="137.599"><stop offset="0" stop-color="#008BFF"/><stop offset="1" stop-color="#0af"/></linearGradient></defs><g><path d="M100 30h300c11 0 20 9 20 20v400c0 11-9 20-20 20h-300c-11 0-20-9-20-20v-400c0-11 9-20 20-20z" fill="url(#a)" stroke="#434242" stroke-width="10"/><path d="M120 60h260c6 0 10 4 10 10v60c0 6-4 10-10 10h-260c-6 0-10-4-10-10v-60c0-6 4-10 10-10z" fill="url(#b)" stroke="#434242" stroke-width="10"/><polygon fill="#434242" points="190,175 235,175 235,220 190,220"/><polygon fill="#434242" points="265,175 310,175 310,220 265,220"/><polygon fill="#434242" points="335,175 380,175 380,220 335,220"/><polygon fill="#434242" points="115,175 160,175 160,220 115,220"/><polygon fill="#434242" points="190,245 235,245 235,290 190,290"/><polygon fill="#434242" points="265,245 310,245 310,290 265,290"/><polygon fill="#434242" points="335,245 380,245 380,290 335,290"/><polygon fill="#434242" points="115,245 160,245 160,290 115,290"/><polygon fill="#434242" points="190,320 235,320 235,365 190,365"/><polygon fill="#434242" points="265,320 310,320 310,365 265,365"/><polygon fill="#434242" points="115,320 160,320 160,365 115,365"/><polygon fill="#434242" points="190,395 235,395 235,440 190,440"/><polygon fill="#434242" points="265,395 310,395 310,440 265,440"/><polygon fill="#434242" points="335,320 380,320 380,440 335,440"/><polygon fill="#434242" points="115,395 160,395 160,440 115,440"/></g></svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

@ -0,0 +1 @@
<?xml version="1.0" ?><svg clip-rule="evenodd" fill-rule="evenodd" image-rendering="optimizeQuality" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg"><defs><linearGradient id="b" x1="1" x2="0" y1="1"><stop offset="0" stop-color="#008BFF"/><stop offset="1" stop-color="#0af"/></linearGradient><linearGradient id="a" x2="0" y1="1"><stop offset="0" stop-color="#FCFCFD"/><stop offset="1" stop-color="#DDDEDE"/></linearGradient></defs><g stroke="#434242" stroke-linejoin="round"><path d="M250 30h140c11 0 20 9 20 20v400c0 11-9 20-20 20h-280c-11 0-20-9-20-20v-260l160-160z" fill="url(#a)" stroke-linecap="round" stroke-width="15"/><path d="M220 190h-130l160-160v130c0 17-14 30-30 30z" fill="url(#b)" stroke-width="10"/></g></svg>

After

Width:  |  Height:  |  Size: 805 B

@ -0,0 +1,33 @@
#include "paydialog.h"
#include "ui_paydialog.h"
PayDialog::PayDialog(QDecDouble total, QWidget *parent) :
QDialog(parent),
ui(new Ui::PayDialog)
{
ui->setupUi(this);
m_total = total;
ui->labelTotal->setText(QString::number(total.toDouble(), 'f', 2));
ui->labelReturn->setText(QString::number(0, 'f', 2));
}
PayDialog::~PayDialog()
{
delete ui;
}
void PayDialog::on_recieved_valueChanged(double value)
{
if (value >= m_total.toDouble())
{
ui->buttonBox->setEnabled(true);
ui->labelReturn->setText(QString::number(value - m_total.toDouble(), 'f', 2));
}
else
{
ui->buttonBox->setEnabled(false);
ui->labelReturn->setText(QString::number(0, 'f', 2));
}
}

@ -0,0 +1,28 @@
#ifndef PAYDIALOG_H
#define PAYDIALOG_H
#include <QDialog>
#include <QDecDouble.hh>
namespace Ui {
class PayDialog;
}
class PayDialog : public QDialog
{
Q_OBJECT
public:
explicit PayDialog(QDecDouble total, QWidget *parent = 0);
~PayDialog();
private slots:
void on_recieved_valueChanged(double value);
private:
Ui::PayDialog *ui;
QDecDouble m_total;
};
#endif // PAYDIALOG_H

@ -0,0 +1,158 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PayDialog</class>
<widget class="QDialog" name="PayDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>449</width>
<height>134</height>
</rect>
</property>
<property name="windowTitle">
<string>Recieve money</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="font">
<font>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Total:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="labelTotal">
<property name="font">
<font>
<pointsize>12</pointsize>
<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="1" column="0">
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Recieved</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="recieved">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Return</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="labelReturn">
<property name="font">
<font>
<pointsize>12</pointsize>
</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="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>PayDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>PayDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

@ -0,0 +1,61 @@
#include "paydvouchersdialog.h"
#include "ui_paydvouchersdialog.h"
#include <QFileDialog>
#include "receiptgenerator.h"
#include "shopservice.h"
PaydVouchersDialog::PaydVouchersDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::PaydVouchersDialog)
{
ui->setupUi(this);
m_voucherModel = new AutoTableModel<Voucher>(this);
m_itemModel = new AutoTableModel<VoucherItem>(this);
ui->tableVouchers->setModel(m_voucherModel);
ui->tableItems->setModel(m_itemModel);
ShopService srv;
m_voucherModel->setData(srv.paiedVouchers());
connect(ui->tableVouchers->selectionModel(), &QItemSelectionModel::currentRowChanged, [this, &srv](const QModelIndex &current, const QModelIndex &) {
QSharedPointer<Voucher> voucher = m_voucherModel->itemFromIndex(current);
srv.loadItems(voucher);
m_itemModel->setData(voucher->items());
ui->total->setText(QString::number(voucher->totalPrice().toDouble(), 'f', 2));
ui->btnPrint->setEnabled(true);
ui->btnSave->setEnabled(true);
});
}
PaydVouchersDialog::~PaydVouchersDialog()
{
delete ui;
}
void PaydVouchersDialog::on_btnPrint_clicked()
{
QSharedPointer<Voucher> voucher = m_voucherModel->itemFromIndex(ui->tableVouchers->currentIndex());
ReceiptGenerator generator;
generator.setVoucher(voucher);
generator.print();
}
void PaydVouchersDialog::on_btnSave_clicked()
{
QString fileToSave = QFileDialog::getSaveFileName(this, tr("Save receipt"), "", tr("Text files (*.txt)"));
QSharedPointer<Voucher> voucher = m_voucherModel->itemFromIndex(ui->tableVouchers->currentIndex());
if (!fileToSave.isEmpty())
{
ReceiptGenerator generator;
generator.setVoucher(voucher);
generator.setOutputFile(fileToSave);
generator.save();
}
}

@ -0,0 +1,34 @@
#ifndef PAYDVOUCHERSDIALOG_H
#define PAYDVOUCHERSDIALOG_H
#include <autotablemodel.h>
#include "data/voucher.h"
#include <QDialog>
namespace Ui {
class PaydVouchersDialog;
}
class PaydVouchersDialog : public QDialog
{
Q_OBJECT
public:
explicit PaydVouchersDialog(QWidget *parent = 0);
~PaydVouchersDialog();
private slots:
void on_btnPrint_clicked();
void on_btnSave_clicked();
private:
Ui::PaydVouchersDialog *ui;
AutoTableModel<Voucher> *m_voucherModel;
AutoTableModel<VoucherItem> *m_itemModel;
};
#endif // PAYDVOUCHERSDIALOG_H

@ -0,0 +1,173 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PaydVouchersDialog</class>
<widget class="QDialog" name="PaydVouchersDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>798</width>
<height>514</height>
</rect>
</property>
<property name="windowTitle">
<string>Paied vouchers</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="btnPrint">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Print receipt</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../core/rc.qrc">
<normaloff>:/icons/print.svg</normaloff>:/icons/print.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnSave">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Save receipt</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../core/rc.qrc">
<normaloff>:/icons/save.svg</normaloff>:/icons/save.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTableView" name="tableVouchers">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Items</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTableView" name="tableItems"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Total:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="total">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
<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>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../core/rc.qrc"/>
</resources>
<connections/>
</ui>

@ -0,0 +1,151 @@
#include "receiptgenerator.h"
#include <settingsservice.h>
#include <settings/globalsettings.h>
#include <QTextCodec>
#include <QFile>
const QString ReceiptGenerator::DIACRITIC = "ÂâÁáÄäĂ㥹ĆćČčÇçĎďĐđÉéËëĚěĘęÍíÎîĹ弾ŁłŃńŇňÓóÖöÔôŐőŔŕŘřŚśŠšŞşŤťŢţÚúÜüŮůŰűÝýŹźŽžŻż";
const QString ReceiptGenerator::NON_DIACRITIC = "AaAaAaAaAaCcCcCcDdDdEeEeEeEeIiIiLlLlLlNnNnOoOoOoOoRrRrSsSsSsTtTtUuUuUuUuYyZzZzZz";
ReceiptGenerator::ReceiptGenerator()
{
}
void ReceiptGenerator::setVoucher(const QSharedPointer<Voucher> &voucher)
{
m_voucher = voucher;
}
void ReceiptGenerator::setSettings(const ShopSettingsPtr &settings)
{
m_settings = settings;
}
void ReceiptGenerator::save()
{
SettingsService srvShopSettings("SHOP");
ShopSettingsPtr shopSettings = srvShopSettings.loadSettings<ShopSettings>();
QString outFile = m_outputFile;
if (outFile.isEmpty())
{
outFile = shopSettings->output();
}
QFile file(outFile);
file.open(QIODevice::WriteOnly);
file.write(generate());
file.close();
}
void ReceiptGenerator::print()
{
save();
}
QString ReceiptGenerator::outputFile() const
{
return m_outputFile;
}
void ReceiptGenerator::setOutputFile(const QString &outputFile)
{
m_outputFile = outputFile;
}
QByteArray ReceiptGenerator::generate()
{
QByteArray out;
SettingsService srvGsSettings("CORE");
SettingsService srvShopSettings("SHOP");
ShopSettingsPtr shopSettings = srvShopSettings.loadSettings<ShopSettings>();
GlobalSettingsPtr gs = srvGsSettings.loadSettings<GlobalSettings>();
out.append("\x1b\x40\x1b\x61\x01");
out.append(prepareString(gs->firmName()));
out.append("\x0a");
out.append(prepareString(gs->street() + " " + gs->houseNumber()));
out.append("\x0a");
out.append(prepareString(gs->zipCode() + " " + gs->city()));
out.append("\x0a");
out.append(prepareString("IC: " + gs->ic()));
out.append("\x0a");
out.append("\x1b\x61\0");
for (int i = 0; i < shopSettings->lettersPerLine(); i++ )
{
out.append("_");
}
out.append("\x0a");
foreach (QSharedPointer<VoucherItem> item, m_voucher->items()) {
QString name = item->name();
QString price = QString::number(item->price().toDouble(), 'f', 2);
int numSpaces = 0;
if ((name.length() + price.length()) < shopSettings->lettersPerLine())
{
numSpaces = shopSettings->lettersPerLine() - (name.length() + price.length());
out.append(prepareString(name));
}
else
{
numSpaces = shopSettings->lettersPerLine() - (name.length() + price.length());
out.append(prepareString(name));
out.append("\x0a");
}
for (int i = 0; i < numSpaces; i++)
{
out.append(" ");
}
out.append(prepareString(price));
out.append("\x0a");
}
for (int i = 0; i < shopSettings->lettersPerLine(); i++ )
{
out.append("_");
}
out.append("\x0a");
char printMode = 8 | 16 ;
out.append("\x1b\x21");
out.append(printMode);
out.append("Celekem:");
QString totalPrice = QString::number(m_voucher->totalPrice().toDouble(), 'f', 2);
int numSpaces = shopSettings->lettersPerLine() - (8 * 2 + totalPrice.length() * 2);
for (int i = 0; i < numSpaces; i++)
{
out.append(" ");
}
out.append(prepareString(totalPrice));
out.append("\x1b\x21\0");
out.append("\x0a");
out.append("\x0a");
out.append("\x0a");
return out;
}
QByteArray ReceiptGenerator::prepareString(const QString &str)
{
QString strOut = str;
//ToDo - dát do nastavení
for (int i = 0; i < DIACRITIC.length(); i++)
{
strOut = strOut.replace(DIACRITIC.at(i), NON_DIACRITIC.at(i));
}
QTextCodec *codec = QTextCodec::codecForName("IBM850");
return codec->fromUnicode(strOut);
}

@ -0,0 +1,35 @@
#ifndef RECEIPTGENERATOR_H
#define RECEIPTGENERATOR_H
#include "data/voucher.h"
#include "settings/shopsettings.h"
class ReceiptGenerator
{
public:
ReceiptGenerator();
void setVoucher(const QSharedPointer<Voucher> &voucher);
void setSettings(const ShopSettingsPtr &settings);
void save();
void print();
QString outputFile() const;
void setOutputFile(const QString &outputFile);
private:
static const QString DIACRITIC;
static const QString NON_DIACRITIC;
QSharedPointer<Voucher> m_voucher;
ShopSettingsPtr m_settings;
QString m_outputFile;
QByteArray generate();
QByteArray prepareString(const QString &str);
};
#endif // RECEIPTGENERATOR_H

@ -0,0 +1,47 @@
#include "shopsettings.h"
ShopSettings::ShopSettings(QObject *parent) : QObject(parent)
{
m_codepage = ASCII;
m_lettersPerLine = 48;
}
QString ShopSettings::output() const
{
return m_output;
}
void ShopSettings::setOutput(const QString &output)
{
m_output = output;
}
ShopSettings::CODEPAGE ShopSettings::codepage() const
{
return m_codepage;
}
void ShopSettings::setCodepage(const CODEPAGE &codepage)
{
m_codepage = codepage;
}
int ShopSettings::lettersPerLine() const
{
return m_lettersPerLine;
}
void ShopSettings::setLettersPerLine(int lettersPerLine)
{
m_lettersPerLine = lettersPerLine;
}
QString ShopSettings::byMessage() const
{
return m_byMessage;
}
void ShopSettings::setByMessage(const QString &byMessage)
{
m_byMessage = byMessage;
}

@ -0,0 +1,43 @@
#ifndef RECEIPTSETTINGS_H
#define RECEIPTSETTINGS_H
#include <QObject>
class ShopSettings : public QObject
{
Q_PROPERTY(QString output READ output WRITE setOutput)
Q_PROPERTY(int lettersPerLine READ lettersPerLine WRITE setLettersPerLine)
Q_PROPERTY(QString byMessage READ byMessage WRITE setByMessage)
Q_OBJECT
public:
enum CODEPAGE
{
ASCII
};
explicit ShopSettings(QObject *parent = 0);
QString output() const;
void setOutput(const QString &output);
CODEPAGE codepage() const;
void setCodepage(const CODEPAGE &codepage);
int lettersPerLine() const;
void setLettersPerLine(int lettersPerLine);
QString byMessage() const;
void setByMessage(const QString &byMessage);
private:
QString m_output;
CODEPAGE m_codepage;
int m_lettersPerLine;
QString m_byMessage;
};
typedef QSharedPointer<ShopSettings> ShopSettingsPtr;
#endif // RECEIPTSETTINGS_H

@ -0,0 +1,36 @@
#include "shopsettingsform.h"
#include "ui_shopsettingsform.h"
#include <settingsservice.h>
ShopSettingsForm::ShopSettingsForm(QWidget *parent) :
FormBinder<ShopSettings>(parent),
ui(new Ui::ShopSettingsForm)
{
ui->setupUi(this);
registerBinding(ui->output);
registerBinding(ui->lettersPerLine);
registerBinding(ui->byMessage);
}
ShopSettingsForm::~ShopSettingsForm()
{
delete ui;
}
void ShopSettingsForm::loadEntity()
{
SettingsService srv("SHOP");
ShopSettingsPtr settings = srv.loadSettings<ShopSettings>();
setEntity(settings);
}
bool ShopSettingsForm::saveRecord()
{
bindToData();
SettingsService srv("SHOP");
srv.saveSettings(entity());
return true;
}

@ -0,0 +1,31 @@
#ifndef SHOPSETTINGSFORM_H
#define SHOPSETTINGSFORM_H
#include <QWidget>
#include <formbinder.h>
#include "shopsettings.h"
namespace Ui {
class ShopSettingsForm;
}
class ShopSettingsForm : public FormBinder<ShopSettings>
{
Q_OBJECT
public:
explicit ShopSettingsForm(QWidget *parent = 0);
~ShopSettingsForm();
private:
Ui::ShopSettingsForm *ui;
// IForm interface
public:
void loadEntity();
public slots:
bool saveRecord();
};
#endif // SHOPSETTINGSFORM_H

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ShopSettingsForm</class>
<widget class="QWidget" name="ShopSettingsForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>608</width>
<height>450</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Printer</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Output device</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="output"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Letters per line</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="lettersPerLine"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Footer text</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="byMessage"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

@ -2,6 +2,7 @@
#include <QIcon>
#include "shopform.h"
#include "shopservice.h"
#include "settings/shopsettingsform.h"
Shop::Shop()
@ -12,6 +13,7 @@ void Shop::initServiceUi()
{
m_ui = new ShopForm();
m_service = new ShopService();
m_settingsUi = new ShopSettingsForm();
}
QIcon Shop::pluginIcon()

@ -29,6 +29,8 @@
CREATE TABLE \"Voucher\" (
\"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
\"numSer\" TEXT NULL,
\"payDateTime\" TEXT NULL,
\"name\" TEXT NULL,
\"description\" TEXT NULL,
\"contact\" INTEGER NULL,

@ -21,7 +21,12 @@ SOURCES += shop.cpp \
receiptloadform.cpp \
data/voucheritem.cpp \
shopservice.cpp \
directsaleitem.cpp
directsaleitem.cpp \
receiptgenerator.cpp \
settings/shopsettings.cpp \
settings/shopsettingsform.cpp \
paydialog.cpp \
paydvouchersdialog.cpp
HEADERS += shop.h\
shop_global.h \
@ -36,7 +41,12 @@ HEADERS += shop.h\
data/shop-data.h \
isellableservice.h \
shopservice.h \
directsaleitem.h
directsaleitem.h \
receiptgenerator.h \
settings/shopsettings.h \
settings/shopsettingsform.h \
paydialog.h \
paydvouchersdialog.h
unix {
target.path = /usr/lib
@ -89,6 +99,9 @@ FORMS += \
directsaleform.ui \
temporaryreceiptsaveform.ui \
receiptsaveform.ui \
receiptloadform.ui
receiptloadform.ui \
settings/shopsettingsform.ui \
paydialog.ui \
paydvouchersdialog.ui
TRANSLATIONS = translations/shop_cs_CZ.ts

@ -5,6 +5,9 @@
#include "receiptsaveform.h"
#include "receiptloadform.h"
#include "shopservice.h"
#include "receiptgenerator.h"
#include "paydialog.h"
#include "paydvouchersdialog.h"
#include <QList>
#include <QSharedPointer>
#include "shop-odb.hxx"
@ -18,6 +21,7 @@ ShopForm::ShopForm(QWidget *parent) :
ui->temporarySaveButton->setEnabled(false);
ui->saveButton->setEnabled(false);
ui->payButton->setEnabled(false);
}
ShopForm::~ShopForm()
@ -48,6 +52,7 @@ void ShopForm::loadLast()
ui->total->setText(QString::number(m_voucher->totalPrice().toDouble(), 'f', 2));
ui->temporarySaveButton->setEnabled(true);
ui->saveButton->setEnabled(true);
ui->payButton->setEnabled(true);
}
}
@ -126,6 +131,7 @@ void ShopForm::onCountChanged()
ui->total->setText(QString::number(m_voucher->totalPrice().toDouble(), 'f', 2));
ui->temporarySaveButton->setEnabled(!m_voucher->items().isEmpty());
ui->saveButton->setEnabled(!m_voucher->items().isEmpty());
ui->payButton->setEnabled(!m_voucher->items().isEmpty());
if (m_voucher->status() == Voucher::NEW && m_voucher->id() == 0)
{
@ -163,10 +169,7 @@ void ShopForm::doTempSave(bool comboChanged)
}
else
{
m_voucher = srv.createVoucher();
ui->total->setText("0");
ui->temporarySaveButton->setEnabled(false);
ui->saveButton->setEnabled(false);
createEmptyVoucher();
}
fillRaceiptCombo();
@ -192,6 +195,7 @@ void ShopForm::changeReceipt()
ui->temporarySaveButton->setEnabled(true);
ui->saveButton->setEnabled(true);
ui->payButton->setEnabled(true);
fillRaceiptCombo();
}
@ -203,6 +207,16 @@ void ShopForm::connectItemSignals()
}
}
void ShopForm::createEmptyVoucher()
{
ShopService srv;
m_voucher = srv.createVoucher();
ui->total->setText("0");
ui->temporarySaveButton->setEnabled(false);
ui->saveButton->setEnabled(false);
ui->payButton->setEnabled(false);
}
void ShopForm::on_receiptCombo_currentIndexChanged(int)
{
if (!m_voucher.isNull() && m_voucher->items().isEmpty())
@ -223,3 +237,31 @@ void ShopForm::on_receiptCombo_currentIndexChanged(int)
doTempSave(true);
}
}
void ShopForm::on_payButton_clicked()
{
PayDialog *dialog = new PayDialog(m_voucher->totalPrice(), this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show();
connect(dialog, &QDialog::accepted, [this](){
ShopService srv;
srv.pay(m_voucher);
ReceiptGenerator generator;
generator.setVoucher(m_voucher);
generator.print();
createEmptyVoucher();
m_itemsModel->setData(m_voucher->items());
});
}
void ShopForm::on_showPaiedButton_clicked()
{
PaydVouchersDialog *dialog = new PaydVouchersDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show();
}

@ -33,6 +33,10 @@ private slots:
void on_receiptCombo_currentIndexChanged(int index);
void on_payButton_clicked();
void on_showPaiedButton_clicked();
private:
Ui::ShopForm *ui;
QSharedPointer<Voucher> m_voucher;
@ -42,6 +46,7 @@ private:
void doTempSave(bool comboChanged);
void changeReceipt();
void connectItemSignals();
void createEmptyVoucher();
};
#endif // SHOPFORM_H

@ -269,30 +269,112 @@
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="temporarySaveButton">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Temporary Save</string>
</property>
<property name="icon">
<iconset resource="shoprc.qrc">
<normaloff>:/icons/tempSave.svg</normaloff>:/icons/tempSave.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveButton">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Save</string>
</property>
<property name="icon">
<iconset resource="../core/rc.qrc">
<normaloff>:/icons/save.svg</normaloff>:/icons/save.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="loadButton">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Load</string>
</property>
<property name="icon">
<iconset resource="../core/rc.qrc">
<normaloff>:/icons/edit.svg</normaloff>:/icons/edit.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="showPaiedButton">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Show paied</string>
</property>
<property name="icon">
<iconset resource="shoprc.qrc">
<normaloff>:/icons/paied.svg</normaloff>:/icons/paied.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="payButton">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Pay</string>
</property>
<property name="icon">
<iconset resource="shoprc.qrc">
<normaloff>:/icons/pay.svg</normaloff>:/icons/pay.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
</layout>
@ -305,6 +387,7 @@
</widget>
<resources>
<include location="shoprc.qrc"/>
<include location="../core/rc.qrc"/>
</resources>
<connections/>
</ui>

@ -2,5 +2,8 @@
<qresource prefix="/">
<file>icons/shop.svg</file>
<file>translations/shop_cs_CZ.qm</file>
<file>icons/tempSave.svg</file>
<file>icons/paied.svg</file>
<file>icons/pay.svg</file>
</qresource>
</RCC>

@ -1,4 +1,5 @@
#include "shopservice.h"
#include "numberseriesservice.h"
#include "shop-odb.hxx"
ShopService::ShopService()
@ -76,6 +77,7 @@ void ShopService::calculateItem(QSharedPointer<VoucherItem> item)
else
{
item->setPrice(item->unitPrice() * item->count());
item->setPriceWitouthVat(item->price());
}
}
@ -85,6 +87,39 @@ void ShopService::loadItems(QSharedPointer<Voucher> voucher)
voucher->setItems(srv.all(QString("voucher = %1").arg(voucher->id())));
}
void ShopService::pay(QSharedPointer<Voucher> voucher)
{
Transaction tx;
NumberSeriesService srvNs;
NumberSeriesPtr numSer = srvNs.nextForPlugin("SHOP");
QString numSerStr;
numSerStr.sprintf("%s%05d", numSer->prefix().toStdString().c_str(), numSer->lastNumber());
voucher->setNumSer(numSerStr);
voucher->setStatus(Voucher::PAID);
voucher->setPayDateTime(QDateTime::currentDateTime());
this->update(voucher);
tx.commit();
}
QList<QSharedPointer<Voucher> > ShopService::savedVouchers()
{
return all(QString("status = %1").arg(QString::number(Voucher::NOT_PAID)));
}
QList<QSharedPointer<Voucher> > ShopService::tempVouchers()
{
return all(QString("status = %1").arg(QString::number(Voucher::TEMPORARY)));
}
QList<QSharedPointer<Voucher> > ShopService::paiedVouchers()
{
return all(QString("status = %1").arg(QString::number(Voucher::PAID)));
}
QDecDouble ShopService::includeVat(QDecDouble price, Enums::VatType vatType)
{
return price * ((vatRate(vatType) / 100) + QDecDouble(1));

@ -18,6 +18,10 @@ public:
void calculate(QSharedPointer<Voucher> voucher);
void calculateItem(QSharedPointer<VoucherItem> item);
void loadItems(QSharedPointer<Voucher> voucher);
void pay(QSharedPointer<Voucher> voucher);
QList<QSharedPointer<Voucher> > savedVouchers();
QList<QSharedPointer<Voucher> > tempVouchers();
QList<QSharedPointer<Voucher> > paiedVouchers();
private:
QDecDouble includeVat(QDecDouble price, Enums::VatType vatType);

Loading…
Cancel
Save