Merge branch 'master' of https://git.bukova.info/repos/git/prodejna
						commit
						e733901286
					
				@ -0,0 +1,75 @@
 | 
			
		||||
#include "numberseries.h"
 | 
			
		||||
#include "../context.h"
 | 
			
		||||
#include "../iplugin.h"
 | 
			
		||||
 | 
			
		||||
NumberSeries::NumberSeries(QObject *parent) : QObject(parent)
 | 
			
		||||
{
 | 
			
		||||
    m_id = 0;
 | 
			
		||||
    m_lastNumber = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int NumberSeries::id() const
 | 
			
		||||
{
 | 
			
		||||
    return m_id;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void NumberSeries::setId(int id)
 | 
			
		||||
{
 | 
			
		||||
    m_id = id;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString NumberSeries::prefix() const
 | 
			
		||||
{
 | 
			
		||||
    return m_prefix;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void NumberSeries::setPrefix(const QString &prefix)
 | 
			
		||||
{
 | 
			
		||||
    m_prefix = prefix;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int NumberSeries::lastNumber() const
 | 
			
		||||
{
 | 
			
		||||
    return m_lastNumber;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void NumberSeries::setLastNumber(int lastNumber)
 | 
			
		||||
{
 | 
			
		||||
    m_lastNumber = lastNumber;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString NumberSeries::pluginId() const
 | 
			
		||||
{
 | 
			
		||||
    return m_pluginId;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void NumberSeries::setPluginId(const QString &pluginId)
 | 
			
		||||
{
 | 
			
		||||
    m_pluginId = pluginId;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QSharedPointer<Season> NumberSeries::season() const
 | 
			
		||||
{
 | 
			
		||||
    return m_season;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void NumberSeries::setSeason(const QSharedPointer<Season> &season)
 | 
			
		||||
{
 | 
			
		||||
    m_season = season;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString NumberSeries::seasonName() const
 | 
			
		||||
{
 | 
			
		||||
    if (!m_season.isNull())
 | 
			
		||||
    {
 | 
			
		||||
        return m_season->name();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return "";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString NumberSeries::pluginName() const
 | 
			
		||||
{
 | 
			
		||||
    IPlugin *plugin = Context::instance().plugin(m_pluginId);
 | 
			
		||||
    return plugin != NULL ? plugin->pluginName() : "";
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,55 @@
 | 
			
		||||
#ifndef NUMBERSERIES_H
 | 
			
		||||
#define NUMBERSERIES_H
 | 
			
		||||
 | 
			
		||||
#include <QObject>
 | 
			
		||||
#include <QSharedPointer>
 | 
			
		||||
 | 
			
		||||
#include <odb/core.hxx>
 | 
			
		||||
 | 
			
		||||
#include "season.h"
 | 
			
		||||
#include "core_global.h"
 | 
			
		||||
 | 
			
		||||
#pragma db object
 | 
			
		||||
class CORESHARED_EXPORT NumberSeries : public QObject
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
    Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
 | 
			
		||||
    Q_PROPERTY(int lastNumber READ lastNumber WRITE setLastNumber)
 | 
			
		||||
    Q_PROPERTY(QString pluginName READ pluginName)
 | 
			
		||||
    Q_PROPERTY(QString seasonName READ seasonName)
 | 
			
		||||
public:
 | 
			
		||||
    explicit NumberSeries(QObject *parent = 0);
 | 
			
		||||
 | 
			
		||||
    int id() const;
 | 
			
		||||
    void setId(int id);
 | 
			
		||||
 | 
			
		||||
    QString prefix() const;
 | 
			
		||||
    void setPrefix(const QString &prefix);
 | 
			
		||||
 | 
			
		||||
    int lastNumber() const;
 | 
			
		||||
    void setLastNumber(int lastNumber);
 | 
			
		||||
 | 
			
		||||
    QString pluginId() const;
 | 
			
		||||
    void setPluginId(const QString &pluginId);
 | 
			
		||||
 | 
			
		||||
    QSharedPointer<Season> season() const;
 | 
			
		||||
    void setSeason(const QSharedPointer<Season> &season);
 | 
			
		||||
 | 
			
		||||
    QString seasonName() const;
 | 
			
		||||
 | 
			
		||||
    QString pluginName() const;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    friend class odb::access;
 | 
			
		||||
 | 
			
		||||
#pragma db id auto
 | 
			
		||||
    int m_id;
 | 
			
		||||
    QString m_prefix;
 | 
			
		||||
    int m_lastNumber;
 | 
			
		||||
    QString m_pluginId;
 | 
			
		||||
    QSharedPointer<Season> m_season;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef QSharedPointer<NumberSeries> NumberSeriesPtr;
 | 
			
		||||
 | 
			
		||||
#endif // NUMBERSERIES_H
 | 
			
		||||
@ -0,0 +1,58 @@
 | 
			
		||||
#include "season.h"
 | 
			
		||||
 | 
			
		||||
Season::Season(QObject *parent)
 | 
			
		||||
    :QObject(parent)
 | 
			
		||||
{
 | 
			
		||||
    m_id = 0;
 | 
			
		||||
    m_active = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString Season::name() const
 | 
			
		||||
{
 | 
			
		||||
    return m_name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Season::setName(const QString &name)
 | 
			
		||||
{
 | 
			
		||||
    m_name = name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QDate Season::validFrom() const
 | 
			
		||||
{
 | 
			
		||||
    return m_validFrom;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Season::setValidFrom(const QDate &validFrom)
 | 
			
		||||
{
 | 
			
		||||
    m_validFrom = validFrom;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QDate Season::validTo() const
 | 
			
		||||
{
 | 
			
		||||
    return m_validTo;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Season::setValidTo(const QDate &validTo)
 | 
			
		||||
{
 | 
			
		||||
    m_validTo = validTo;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Season::active() const
 | 
			
		||||
{
 | 
			
		||||
    return m_active;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Season::setActive(bool active)
 | 
			
		||||
{
 | 
			
		||||
    m_active = active;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Season::id() const
 | 
			
		||||
{
 | 
			
		||||
    return m_id;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Season::setId(int id)
 | 
			
		||||
{
 | 
			
		||||
    m_id = id;
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,51 @@
 | 
			
		||||
#ifndef SEASON_H
 | 
			
		||||
#define SEASON_H
 | 
			
		||||
 | 
			
		||||
#include "core_global.h"
 | 
			
		||||
 | 
			
		||||
#include <QObject>
 | 
			
		||||
#include <QString>
 | 
			
		||||
#include <QDate>
 | 
			
		||||
 | 
			
		||||
#include <odb/core.hxx>
 | 
			
		||||
 | 
			
		||||
#pragma db object
 | 
			
		||||
class CORESHARED_EXPORT Season : public QObject
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
    Q_PROPERTY(QString name READ name WRITE setName)
 | 
			
		||||
    Q_PROPERTY(QDate validFrom READ validFrom WRITE setValidFrom)
 | 
			
		||||
    Q_PROPERTY(QDate validTo READ validTo WRITE setValidTo)
 | 
			
		||||
    Q_PROPERTY(bool active READ active WRITE setActive)
 | 
			
		||||
public:
 | 
			
		||||
    explicit Season(QObject *parent = 0);
 | 
			
		||||
 | 
			
		||||
    QString name() const;
 | 
			
		||||
    void setName(const QString &name);
 | 
			
		||||
 | 
			
		||||
    QDate validFrom() const;
 | 
			
		||||
    void setValidFrom(const QDate &validFrom);
 | 
			
		||||
 | 
			
		||||
    QDate validTo() const;
 | 
			
		||||
    void setValidTo(const QDate &validTo);
 | 
			
		||||
 | 
			
		||||
    bool active() const;
 | 
			
		||||
    void setActive(bool active);
 | 
			
		||||
 | 
			
		||||
    int id() const;
 | 
			
		||||
    void setId(int id);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    friend class odb::access;
 | 
			
		||||
 | 
			
		||||
#pragma db id auto
 | 
			
		||||
    int m_id;
 | 
			
		||||
    QString m_name;
 | 
			
		||||
    QDate m_validFrom;
 | 
			
		||||
    QDate m_validTo;
 | 
			
		||||
    bool m_active;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef QSharedPointer<Season> SeasonPtr;
 | 
			
		||||
 | 
			
		||||
#endif // SEASON_H
 | 
			
		||||
@ -0,0 +1,53 @@
 | 
			
		||||
#include "numberseriesservice.h"
 | 
			
		||||
#include "seasonservice.h"
 | 
			
		||||
#include "core-odb.hxx"
 | 
			
		||||
 | 
			
		||||
NumberSeriesService::NumberSeriesService()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QSharedPointer<NumberSeries> NumberSeriesService::forPluginAndSeason(QString pluginId, QSharedPointer<Season> season)
 | 
			
		||||
{
 | 
			
		||||
    QList<QSharedPointer<NumberSeries> > series = all(QString("pluginId = '%1' AND season = %2").arg(pluginId, QString::number(season->id())));
 | 
			
		||||
 | 
			
		||||
    if (!series.isEmpty())
 | 
			
		||||
    {
 | 
			
		||||
        return series[0];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return QSharedPointer<NumberSeries>();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QSharedPointer<NumberSeries> NumberSeriesService::forPlugin(QString pluginId)
 | 
			
		||||
{
 | 
			
		||||
    SeasonService sesSrv;
 | 
			
		||||
    QSharedPointer<Season> currentSeason = sesSrv.active();
 | 
			
		||||
 | 
			
		||||
    if (!currentSeason.isNull())
 | 
			
		||||
    {
 | 
			
		||||
        return forPluginAndSeason(pluginId, currentSeason);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return QSharedPointer<NumberSeries>();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QSharedPointer<NumberSeries> NumberSeriesService::nextForPlugin(QString pluginId)
 | 
			
		||||
{
 | 
			
		||||
    QSharedPointer<NumberSeries> numSer = forPlugin(pluginId);
 | 
			
		||||
 | 
			
		||||
    if (numSer.isNull())
 | 
			
		||||
    {
 | 
			
		||||
        return QSharedPointer<NumberSeries>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    numSer->setLastNumber(numSer->lastNumber() + 1);
 | 
			
		||||
    update(numSer);
 | 
			
		||||
 | 
			
		||||
    return numSer;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QList<QSharedPointer<NumberSeries> > NumberSeriesService::allForSeason(QSharedPointer<Season> season)
 | 
			
		||||
{
 | 
			
		||||
    return all(QString("season = %1").arg(QString::number(season->id())));
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,20 @@
 | 
			
		||||
#ifndef NUMBERSERIESSERVICE_H
 | 
			
		||||
#define NUMBERSERIESSERVICE_H
 | 
			
		||||
 | 
			
		||||
#include "data/numberseries.h"
 | 
			
		||||
#include "data/season.h"
 | 
			
		||||
#include "service.h"
 | 
			
		||||
#include "core_global.h"
 | 
			
		||||
 | 
			
		||||
class CORESHARED_EXPORT NumberSeriesService : public Service<NumberSeries>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    NumberSeriesService();
 | 
			
		||||
 | 
			
		||||
    QSharedPointer<NumberSeries> forPluginAndSeason(QString pluginId, QSharedPointer<Season> season);
 | 
			
		||||
    QSharedPointer<NumberSeries> forPlugin(QString pluginId);
 | 
			
		||||
    QSharedPointer<NumberSeries> nextForPlugin(QString pluginId);
 | 
			
		||||
    QList<QSharedPointer<NumberSeries> > allForSeason(QSharedPointer<Season> season);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // NUMBERSERIESSERVICE_H
 | 
			
		||||
@ -0,0 +1,34 @@
 | 
			
		||||
#include "seasonservice.h"
 | 
			
		||||
 | 
			
		||||
#include "core-odb.hxx"
 | 
			
		||||
 | 
			
		||||
SeasonService::SeasonService()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QSharedPointer<Season> SeasonService::active()
 | 
			
		||||
{
 | 
			
		||||
    QList<QSharedPointer<Season> > seasons = all("active = 1");
 | 
			
		||||
    if (seasons.count() > 0)
 | 
			
		||||
    {
 | 
			
		||||
        return seasons[0];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return QSharedPointer<Season>();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SeasonService::activate(QSharedPointer<Season> season)
 | 
			
		||||
{
 | 
			
		||||
    Transaction tx;
 | 
			
		||||
 | 
			
		||||
    foreach (QSharedPointer<Season> ses, all()) {
 | 
			
		||||
        ses->setActive(false);
 | 
			
		||||
        update(ses);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    season->setActive(true);
 | 
			
		||||
    update(season);
 | 
			
		||||
 | 
			
		||||
    tx.commit();
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,18 @@
 | 
			
		||||
#ifndef SEASONSERVICE_H
 | 
			
		||||
#define SEASONSERVICE_H
 | 
			
		||||
 | 
			
		||||
#include <QSharedPointer>
 | 
			
		||||
 | 
			
		||||
#include "data/season.h"
 | 
			
		||||
#include "service.h"
 | 
			
		||||
#include "core_global.h"
 | 
			
		||||
 | 
			
		||||
class CORESHARED_EXPORT SeasonService : public Service<Season>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    SeasonService();
 | 
			
		||||
    QSharedPointer<Season> active();
 | 
			
		||||
    void activate(QSharedPointer<Season> season);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // SEASONSERVICE_H
 | 
			
		||||
@ -0,0 +1,24 @@
 | 
			
		||||
#include "seasonnamedialog.h"
 | 
			
		||||
#include "ui_seasonnamedialog.h"
 | 
			
		||||
 | 
			
		||||
SeasonNameDialog::SeasonNameDialog(SeasonPtr season, QWidget *parent) :
 | 
			
		||||
    QDialog(parent),
 | 
			
		||||
    ui(new Ui::SeasonNameDialog)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
 | 
			
		||||
    m_binder.registerBinding(ui->name);
 | 
			
		||||
    m_binder.setData(season.data());
 | 
			
		||||
    m_binder.bindToUi();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SeasonNameDialog::~SeasonNameDialog()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SeasonNameDialog::accept()
 | 
			
		||||
{
 | 
			
		||||
    m_binder.bindToData();
 | 
			
		||||
    QDialog::accept();
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,30 @@
 | 
			
		||||
#ifndef SEASONNAMEDIALOG_H
 | 
			
		||||
#define SEASONNAMEDIALOG_H
 | 
			
		||||
 | 
			
		||||
#include <QDialog>
 | 
			
		||||
 | 
			
		||||
#include "../data/season.h"
 | 
			
		||||
#include "../objectbinder.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
class SeasonNameDialog;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class SeasonNameDialog : public QDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit SeasonNameDialog(SeasonPtr season, QWidget *parent = 0);
 | 
			
		||||
    ~SeasonNameDialog();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::SeasonNameDialog *ui;
 | 
			
		||||
    ObjectBinder m_binder;
 | 
			
		||||
 | 
			
		||||
    // QDialog interface
 | 
			
		||||
public slots:
 | 
			
		||||
    void accept();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // SEASONNAMEDIALOG_H
 | 
			
		||||
@ -0,0 +1,77 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<ui version="4.0">
 | 
			
		||||
 <class>SeasonNameDialog</class>
 | 
			
		||||
 <widget class="QDialog" name="SeasonNameDialog">
 | 
			
		||||
  <property name="geometry">
 | 
			
		||||
   <rect>
 | 
			
		||||
    <x>0</x>
 | 
			
		||||
    <y>0</y>
 | 
			
		||||
    <width>406</width>
 | 
			
		||||
    <height>82</height>
 | 
			
		||||
   </rect>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="windowTitle">
 | 
			
		||||
   <string>Season</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="text">
 | 
			
		||||
      <string>Season name</string>
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item row="0" column="1">
 | 
			
		||||
    <widget class="QLineEdit" name="name"/>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item row="1" column="0" colspan="2">
 | 
			
		||||
    <widget class="QDialogButtonBox" name="buttonBox">
 | 
			
		||||
     <property name="orientation">
 | 
			
		||||
      <enum>Qt::Horizontal</enum>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="standardButtons">
 | 
			
		||||
      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
  </layout>
 | 
			
		||||
 </widget>
 | 
			
		||||
 <resources/>
 | 
			
		||||
 <connections>
 | 
			
		||||
  <connection>
 | 
			
		||||
   <sender>buttonBox</sender>
 | 
			
		||||
   <signal>accepted()</signal>
 | 
			
		||||
   <receiver>SeasonNameDialog</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>SeasonNameDialog</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 @@
 | 
			
		||||
<?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