Implemented temporary save.

print
Josef Rokos 9 years ago
parent 8ed2e4d78a
commit 5eb73fb877

@ -23,6 +23,7 @@ QWidget *Shop::ui()
{ {
QWidget *uiWidget = IPlugin::ui(); QWidget *uiWidget = IPlugin::ui();
qobject_cast<ShopForm*>(uiWidget)->loadLast(); qobject_cast<ShopForm*>(uiWidget)->loadLast();
qobject_cast<ShopForm*>(uiWidget)->fillRaceiptCombo();
return uiWidget; return uiWidget;
} }

@ -14,6 +14,7 @@ ShopForm::ShopForm(QWidget *parent) :
ui(new Ui::ShopForm) ui(new Ui::ShopForm)
{ {
ui->setupUi(this); ui->setupUi(this);
m_itemsModel = NULL;
} }
ShopForm::~ShopForm() ShopForm::~ShopForm()
@ -23,10 +24,14 @@ ShopForm::~ShopForm()
void ShopForm::loadLast() void ShopForm::loadLast()
{ {
if (m_itemsModel == NULL)
{
m_itemsModel = new AutoTableModel<VoucherItem>(this); m_itemsModel = new AutoTableModel<VoucherItem>(this);
m_itemsModel->setEditableCols(QList<int>() << 1); m_itemsModel->setEditableCols(QList<int>() << 1);
m_itemsModel->setTranslations(Context::instance().plugin("SHOP")->translations());
ui->actualReceipt->setModel(m_itemsModel); ui->actualReceipt->setModel(m_itemsModel);
ui->actualReceipt->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); ui->actualReceipt->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
}
ShopService srv; ShopService srv;
QList<QSharedPointer<Voucher> > receipt = srv.all(QString("status = %1").arg(QString::number(Voucher::NEW))); QList<QSharedPointer<Voucher> > receipt = srv.all(QString("status = %1").arg(QString::number(Voucher::NEW)));
@ -35,14 +40,29 @@ void ShopForm::loadLast()
m_voucher = receipt[0]; m_voucher = receipt[0];
srv.loadItems(m_voucher); srv.loadItems(m_voucher);
m_itemsModel->setData(m_voucher->items()); m_itemsModel->setData(m_voucher->items());
connectItemSignals();
foreach (QSharedPointer<VoucherItem> item, m_voucher->items()) {
connect(item.data(), SIGNAL(countChanged()), this, SLOT(onCountChanged()));
}
ui->total->setText(QString::number(m_voucher->totalPrice().toDouble(), 'f', 2)); ui->total->setText(QString::number(m_voucher->totalPrice().toDouble(), 'f', 2));
} }
} }
void ShopForm::fillRaceiptCombo()
{
bool oldState = ui->receiptCombo->blockSignals(true);
ShopService srv;
QList<QSharedPointer<Voucher> > receipts = srv.all(QString("status = %1").arg(QString::number(Voucher::TEMPORARY)));
ui->receiptCombo->clear();
ui->receiptCombo->addItem(tr("<< empty >>"));
foreach (QSharedPointer<Voucher> voucher, receipts) {
ui->receiptCombo->addItem(voucher->name(), voucher->id());
}
ui->receiptCombo->blockSignals(oldState);
}
void ShopForm::on_directSale_clicked() void ShopForm::on_directSale_clicked()
{ {
if (m_voucher.isNull()) if (m_voucher.isNull())
@ -51,6 +71,7 @@ void ShopForm::on_directSale_clicked()
} }
DirectSaleForm *form = new DirectSaleForm(this); DirectSaleForm *form = new DirectSaleForm(this);
form->setAttribute(Qt::WA_DeleteOnClose);
connect(form, &QDialog::accepted, [this, form](){ connect(form, &QDialog::accepted, [this, form](){
ShopService srv; ShopService srv;
@ -65,8 +86,7 @@ void ShopForm::on_directSale_clicked()
void ShopForm::on_temporarySaveButton_clicked() void ShopForm::on_temporarySaveButton_clicked()
{ {
TemporaryReceiptSaveForm *form = new TemporaryReceiptSaveForm(this); doTempSave(false);
form->show();
} }
void ShopForm::on_saveButton_clicked() void ShopForm::on_saveButton_clicked()
@ -115,3 +135,79 @@ void ShopForm::createVoucher()
ShopService srv; ShopService srv;
m_voucher = srv.createVoucher(); m_voucher = srv.createVoucher();
} }
void ShopForm::doTempSave(bool comboChanged)
{
TemporaryReceiptSaveForm *form = new TemporaryReceiptSaveForm(m_voucher, this);
form->setAttribute(Qt::WA_DeleteOnClose);
connect(form, &QDialog::accepted, [this, form, comboChanged](){
ShopService srv;
if (!m_voucher->items().isEmpty())
{
m_voucher->setStatus(Voucher::TEMPORARY);
srv.update(m_voucher);
}
if (comboChanged && ui->receiptCombo->currentIndex() > 0)
{
changeReceipt();
}
else
{
m_voucher = srv.createVoucher();
ui->total->setText("0");
}
fillRaceiptCombo();
m_itemsModel->setData(m_voucher->items());
});
form->show();
}
void ShopForm::changeReceipt()
{
ShopService srv;
m_voucher = srv.loadById(ui->receiptCombo->currentData().toInt());
srv.loadItems(m_voucher);
connectItemSignals();
m_voucher->setStatus(Voucher::NEW);
srv.update(m_voucher);
m_itemsModel->setData(m_voucher->items());
ui->total->setText(m_voucher->totalPrice().toString());
fillRaceiptCombo();
}
void ShopForm::connectItemSignals()
{
foreach (QSharedPointer<VoucherItem> item, m_voucher->items()) {
connect(item.data(), SIGNAL(countChanged()), this, SLOT(onCountChanged()));
}
}
void ShopForm::on_receiptCombo_currentIndexChanged(int)
{
if (!m_voucher.isNull() && m_voucher->items().isEmpty())
{
ShopService srv;
srv.erase(m_voucher);
changeReceipt();
return;
}
if (m_voucher.isNull())
{
changeReceipt();
}
else
{
doTempSave(true);
}
}

@ -18,6 +18,7 @@ public:
explicit ShopForm(QWidget *parent = 0); explicit ShopForm(QWidget *parent = 0);
~ShopForm(); ~ShopForm();
void loadLast(); void loadLast();
void fillRaceiptCombo();
private slots: private slots:
void on_directSale_clicked(); void on_directSale_clicked();
@ -30,12 +31,17 @@ private slots:
void onCountChanged(); void onCountChanged();
void on_receiptCombo_currentIndexChanged(int index);
private: private:
Ui::ShopForm *ui; Ui::ShopForm *ui;
QSharedPointer<Voucher> m_voucher; QSharedPointer<Voucher> m_voucher;
AutoTableModel<VoucherItem> *m_itemsModel; AutoTableModel<VoucherItem> *m_itemsModel;
void createVoucher(); void createVoucher();
void doTempSave(bool comboChanged);
void changeReceipt();
void connectItemSignals();
}; };
#endif // SHOPFORM_H #endif // SHOPFORM_H

@ -206,7 +206,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="ReceiptCombo"/> <widget class="QComboBox" name="receiptCombo"/>
</item> </item>
<item> <item>
<widget class="QTableView" name="actualReceipt"/> <widget class="QTableView" name="actualReceipt"/>

@ -1,14 +1,23 @@
#include "temporaryreceiptsaveform.h" #include "temporaryreceiptsaveform.h"
#include "ui_temporaryreceiptsaveform.h" #include "ui_temporaryreceiptsaveform.h"
TemporaryReceiptSaveForm::TemporaryReceiptSaveForm(QWidget *parent) : TemporaryReceiptSaveForm::TemporaryReceiptSaveForm(QSharedPointer<Voucher> voucher, QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::TemporaryReceiptSaveForm) ui(new Ui::TemporaryReceiptSaveForm)
{ {
ui->setupUi(this); ui->setupUi(this);
m_voucher = voucher;
m_binder.registerBinding(ui->name);
m_binder.setData(m_voucher.data());
} }
TemporaryReceiptSaveForm::~TemporaryReceiptSaveForm() TemporaryReceiptSaveForm::~TemporaryReceiptSaveForm()
{ {
delete ui; delete ui;
} }
void TemporaryReceiptSaveForm::accept()
{
m_binder.bindToData();
QDialog::accept();
}

@ -2,6 +2,10 @@
#define TEMPORARYRECEIPTSAVEFORM_H #define TEMPORARYRECEIPTSAVEFORM_H
#include <QDialog> #include <QDialog>
#include <QSharedPointer>
#include <objectbinder.h>
#include "data/voucher.h"
namespace Ui { namespace Ui {
class TemporaryReceiptSaveForm; class TemporaryReceiptSaveForm;
@ -12,11 +16,17 @@ class TemporaryReceiptSaveForm : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit TemporaryReceiptSaveForm(QWidget *parent = 0); explicit TemporaryReceiptSaveForm(QSharedPointer<Voucher> voucher, QWidget *parent = 0);
~TemporaryReceiptSaveForm(); ~TemporaryReceiptSaveForm();
private: private:
Ui::TemporaryReceiptSaveForm *ui; Ui::TemporaryReceiptSaveForm *ui;
QSharedPointer<Voucher> m_voucher;
ObjectBinder m_binder;
// QDialog interface
public slots:
virtual void accept() override;
}; };
#endif // TEMPORARYRECEIPTSAVEFORM_H #endif // TEMPORARYRECEIPTSAVEFORM_H

@ -22,7 +22,7 @@
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLineEdit" name="temporaryReceiptName"/> <widget class="QLineEdit" name="name"/>
</item> </item>
<item row="1" column="0" colspan="2"> <item row="1" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">

Loading…
Cancel
Save