diff --git a/core/data/numberseries.h b/core/data/numberseries.h index 0ef04ad..d97257e 100644 --- a/core/data/numberseries.h +++ b/core/data/numberseries.h @@ -7,9 +7,10 @@ #include #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) diff --git a/core/settings/globalsettings.h b/core/settings/globalsettings.h index 9c782a3..14e6933 100644 --- a/core/settings/globalsettings.h +++ b/core/settings/globalsettings.h @@ -80,4 +80,6 @@ signals: public slots: }; +typedef QSharedPointer GlobalSettingsPtr; + #endif // GLOBALSETTINGS_H diff --git a/shop/data/voucher.cpp b/shop/data/voucher.cpp index 55b330c..5ad6cf4 100644 --- a/shop/data/voucher.cpp +++ b/shop/data/voucher.cpp @@ -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; diff --git a/shop/data/voucher.h b/shop/data/voucher.h index c5c3782..c93a49e 100644 --- a/shop/data/voucher.h +++ b/shop/data/voucher.h @@ -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 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 m_contact; diff --git a/shop/icons/paied.svg b/shop/icons/paied.svg new file mode 100644 index 0000000..8f2b8d2 --- /dev/null +++ b/shop/icons/paied.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/shop/icons/pay.svg b/shop/icons/pay.svg new file mode 100644 index 0000000..305a6d0 --- /dev/null +++ b/shop/icons/pay.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/shop/icons/tempSave.svg b/shop/icons/tempSave.svg new file mode 100644 index 0000000..297aebd --- /dev/null +++ b/shop/icons/tempSave.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/shop/paydialog.cpp b/shop/paydialog.cpp new file mode 100644 index 0000000..e272503 --- /dev/null +++ b/shop/paydialog.cpp @@ -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)); + } +} diff --git a/shop/paydialog.h b/shop/paydialog.h new file mode 100644 index 0000000..55d81cb --- /dev/null +++ b/shop/paydialog.h @@ -0,0 +1,28 @@ +#ifndef PAYDIALOG_H +#define PAYDIALOG_H + +#include +#include + +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 diff --git a/shop/paydialog.ui b/shop/paydialog.ui new file mode 100644 index 0000000..fd9d4a2 --- /dev/null +++ b/shop/paydialog.ui @@ -0,0 +1,158 @@ + + + PayDialog + + + + 0 + 0 + 449 + 134 + + + + Recieve money + + + true + + + + + + + 12 + 75 + true + + + + Total: + + + + + + + + 12 + 75 + true + + + + 0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 12 + + + + Recieved + + + + + + + + 12 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + QAbstractSpinBox::NoButtons + + + 99999.990000000005239 + + + + + + + + 12 + + + + Return + + + + + + + + 12 + + + + 0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + false + + + Qt::Horizontal + + + QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + PayDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + PayDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/shop/paydvouchersdialog.cpp b/shop/paydvouchersdialog.cpp new file mode 100644 index 0000000..9bca5d7 --- /dev/null +++ b/shop/paydvouchersdialog.cpp @@ -0,0 +1,61 @@ +#include "paydvouchersdialog.h" +#include "ui_paydvouchersdialog.h" + +#include + +#include "receiptgenerator.h" +#include "shopservice.h" + +PaydVouchersDialog::PaydVouchersDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::PaydVouchersDialog) +{ + ui->setupUi(this); + + m_voucherModel = new AutoTableModel(this); + m_itemModel = new AutoTableModel(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 = 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 = 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 = m_voucherModel->itemFromIndex(ui->tableVouchers->currentIndex()); + + if (!fileToSave.isEmpty()) + { + ReceiptGenerator generator; + generator.setVoucher(voucher); + generator.setOutputFile(fileToSave); + generator.save(); + } +} diff --git a/shop/paydvouchersdialog.h b/shop/paydvouchersdialog.h new file mode 100644 index 0000000..973e3f0 --- /dev/null +++ b/shop/paydvouchersdialog.h @@ -0,0 +1,34 @@ +#ifndef PAYDVOUCHERSDIALOG_H +#define PAYDVOUCHERSDIALOG_H + +#include +#include "data/voucher.h" + +#include + +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 *m_voucherModel; + AutoTableModel *m_itemModel; +}; + +#endif // PAYDVOUCHERSDIALOG_H diff --git a/shop/paydvouchersdialog.ui b/shop/paydvouchersdialog.ui new file mode 100644 index 0000000..8512420 --- /dev/null +++ b/shop/paydvouchersdialog.ui @@ -0,0 +1,173 @@ + + + PaydVouchersDialog + + + + 0 + 0 + 798 + 514 + + + + Paied vouchers + + + true + + + + + + + + + false + + + Print receipt + + + + + + + :/icons/print.svg:/icons/print.svg + + + + 32 + 32 + + + + true + + + + + + + false + + + Save receipt + + + ... + + + + :/icons/save.svg:/icons/save.svg + + + + 32 + 32 + + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + + + + + Items + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 12 + + + + Total: + + + + + + + + 100 + 0 + + + + + 12 + 75 + true + + + + 0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + diff --git a/shop/receiptgenerator.cpp b/shop/receiptgenerator.cpp new file mode 100644 index 0000000..e9c9e6e --- /dev/null +++ b/shop/receiptgenerator.cpp @@ -0,0 +1,151 @@ +#include "receiptgenerator.h" +#include +#include + +#include +#include + +const QString ReceiptGenerator::DIACRITIC = "ÂâÁáÄäĂ㥹ĆćČčÇçĎďĐđÉéËëĚěĘęÍíÎîĹ弾ŁłŃńŇňÓóÖöÔôŐőŔŕŘřŚśŠšŞşŤťŢţÚúÜüŮůŰűÝýŹźŽžŻż"; +const QString ReceiptGenerator::NON_DIACRITIC = "AaAaAaAaAaCcCcCcDdDdEeEeEeEeIiIiLlLlLlNnNnOoOoOoOoRrRrSsSsSsTtTtUuUuUuUuYyZzZzZz"; + +ReceiptGenerator::ReceiptGenerator() +{ + +} + +void ReceiptGenerator::setVoucher(const QSharedPointer &voucher) +{ + m_voucher = voucher; +} + +void ReceiptGenerator::setSettings(const ShopSettingsPtr &settings) +{ + m_settings = settings; +} + +void ReceiptGenerator::save() +{ + SettingsService srvShopSettings("SHOP"); + ShopSettingsPtr shopSettings = srvShopSettings.loadSettings(); + + 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(); + GlobalSettingsPtr gs = srvGsSettings.loadSettings(); + + 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 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); +} diff --git a/shop/receiptgenerator.h b/shop/receiptgenerator.h new file mode 100644 index 0000000..ea7a47f --- /dev/null +++ b/shop/receiptgenerator.h @@ -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); + + 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 m_voucher; + ShopSettingsPtr m_settings; + + QString m_outputFile; + + QByteArray generate(); + QByteArray prepareString(const QString &str); +}; + +#endif // RECEIPTGENERATOR_H diff --git a/shop/settings/shopsettings.cpp b/shop/settings/shopsettings.cpp new file mode 100644 index 0000000..78064d3 --- /dev/null +++ b/shop/settings/shopsettings.cpp @@ -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; +} diff --git a/shop/settings/shopsettings.h b/shop/settings/shopsettings.h new file mode 100644 index 0000000..acfb626 --- /dev/null +++ b/shop/settings/shopsettings.h @@ -0,0 +1,43 @@ +#ifndef RECEIPTSETTINGS_H +#define RECEIPTSETTINGS_H + +#include + +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 ShopSettingsPtr; + +#endif // RECEIPTSETTINGS_H diff --git a/shop/settings/shopsettingsform.cpp b/shop/settings/shopsettingsform.cpp new file mode 100644 index 0000000..18c2b1d --- /dev/null +++ b/shop/settings/shopsettingsform.cpp @@ -0,0 +1,36 @@ +#include "shopsettingsform.h" +#include "ui_shopsettingsform.h" + +#include + +ShopSettingsForm::ShopSettingsForm(QWidget *parent) : + FormBinder(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(); + setEntity(settings); +} + +bool ShopSettingsForm::saveRecord() +{ + bindToData(); + SettingsService srv("SHOP"); + srv.saveSettings(entity()); + + return true; +} diff --git a/shop/settings/shopsettingsform.h b/shop/settings/shopsettingsform.h new file mode 100644 index 0000000..42bb46f --- /dev/null +++ b/shop/settings/shopsettingsform.h @@ -0,0 +1,31 @@ +#ifndef SHOPSETTINGSFORM_H +#define SHOPSETTINGSFORM_H + +#include +#include +#include "shopsettings.h" + +namespace Ui { +class ShopSettingsForm; +} + +class ShopSettingsForm : public FormBinder +{ + 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 diff --git a/shop/settings/shopsettingsform.ui b/shop/settings/shopsettingsform.ui new file mode 100644 index 0000000..405dd54 --- /dev/null +++ b/shop/settings/shopsettingsform.ui @@ -0,0 +1,60 @@ + + + ShopSettingsForm + + + + 0 + 0 + 608 + 450 + + + + Form + + + + + + Printer + + + + + + Output device + + + + + + + + + + Letters per line + + + + + + + + + + Footer text + + + + + + + + + + + + + + diff --git a/shop/shop.cpp b/shop/shop.cpp index 7d7e8cc..4f6ae67 100644 --- a/shop/shop.cpp +++ b/shop/shop.cpp @@ -2,6 +2,7 @@ #include #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() diff --git a/shop/shop.json b/shop/shop.json index 7f9c44e..9f54cc6 100644 --- a/shop/shop.json +++ b/shop/shop.json @@ -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, diff --git a/shop/shop.pro b/shop/shop.pro index d626e77..3bcd021 100644 --- a/shop/shop.pro +++ b/shop/shop.pro @@ -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 diff --git a/shop/shopform.cpp b/shop/shopform.cpp index a6c74bf..efcd1b0 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -5,6 +5,9 @@ #include "receiptsaveform.h" #include "receiptloadform.h" #include "shopservice.h" +#include "receiptgenerator.h" +#include "paydialog.h" +#include "paydvouchersdialog.h" #include #include #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(); +} diff --git a/shop/shopform.h b/shop/shopform.h index df37aa8..36cb250 100644 --- a/shop/shopform.h +++ b/shop/shopform.h @@ -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 m_voucher; @@ -42,6 +46,7 @@ private: void doTempSave(bool comboChanged); void changeReceipt(); void connectItemSignals(); + void createEmptyVoucher(); }; #endif // SHOPFORM_H diff --git a/shop/shopform.ui b/shop/shopform.ui index 40a0a21..56dceaf 100644 --- a/shop/shopform.ui +++ b/shop/shopform.ui @@ -269,30 +269,112 @@ + + + 10 + + Temporary Save + + + :/icons/tempSave.svg:/icons/tempSave.svg + + + + 32 + 32 + + + + + 10 + + Save + + + :/icons/save.svg:/icons/save.svg + + + + 32 + 32 + + + + + 10 + + Load + + + :/icons/edit.svg:/icons/edit.svg + + + + 32 + 32 + + + + + + + + + 10 + + + + Show paied + + + + :/icons/paied.svg:/icons/paied.svg + + + + 32 + 32 + + + + + 10 + + Pay + + + :/icons/pay.svg:/icons/pay.svg + + + + 32 + 32 + + @@ -305,6 +387,7 @@ + diff --git a/shop/shoprc.qrc b/shop/shoprc.qrc index 2961e1c..77a3ead 100644 --- a/shop/shoprc.qrc +++ b/shop/shoprc.qrc @@ -2,5 +2,8 @@ icons/shop.svg translations/shop_cs_CZ.qm + icons/tempSave.svg + icons/paied.svg + icons/pay.svg diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index 5bd7964..15e52a4 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -1,4 +1,5 @@ #include "shopservice.h" +#include "numberseriesservice.h" #include "shop-odb.hxx" ShopService::ShopService() @@ -76,6 +77,7 @@ void ShopService::calculateItem(QSharedPointer item) else { item->setPrice(item->unitPrice() * item->count()); + item->setPriceWitouthVat(item->price()); } } @@ -85,6 +87,39 @@ void ShopService::loadItems(QSharedPointer voucher) voucher->setItems(srv.all(QString("voucher = %1").arg(voucher->id()))); } +void ShopService::pay(QSharedPointer 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 > ShopService::savedVouchers() +{ + return all(QString("status = %1").arg(QString::number(Voucher::NOT_PAID))); +} + +QList > ShopService::tempVouchers() +{ + return all(QString("status = %1").arg(QString::number(Voucher::TEMPORARY))); +} + +QList > 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)); diff --git a/shop/shopservice.h b/shop/shopservice.h index 5b70012..0c626d1 100644 --- a/shop/shopservice.h +++ b/shop/shopservice.h @@ -18,6 +18,10 @@ public: void calculate(QSharedPointer voucher); void calculateItem(QSharedPointer item); void loadItems(QSharedPointer voucher); + void pay(QSharedPointer voucher); + QList > savedVouchers(); + QList > tempVouchers(); + QList > paiedVouchers(); private: QDecDouble includeVat(QDecDouble price, Enums::VatType vatType);