Added pay voucher feature. Added dialog with paied vouchers. Added
support for printing receipts on POS printer.print
parent
a89b0381b1
commit
e6dfc8ec21
@ -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 ¤t, 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>
|
Loading…
Reference in New Issue