Implemented temporary save.

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

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

@ -14,6 +14,7 @@ ShopForm::ShopForm(QWidget *parent) :
ui(new Ui::ShopForm)
{
ui->setupUi(this);
m_itemsModel = NULL;
}
ShopForm::~ShopForm()
@ -23,10 +24,14 @@ ShopForm::~ShopForm()
void ShopForm::loadLast()
{
m_itemsModel = new AutoTableModel<VoucherItem>(this);
m_itemsModel->setEditableCols(QList<int>() << 1);
ui->actualReceipt->setModel(m_itemsModel);
ui->actualReceipt->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
if (m_itemsModel == NULL)
{
m_itemsModel = new AutoTableModel<VoucherItem>(this);
m_itemsModel->setEditableCols(QList<int>() << 1);
m_itemsModel->setTranslations(Context::instance().plugin("SHOP")->translations());
ui->actualReceipt->setModel(m_itemsModel);
ui->actualReceipt->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
}
ShopService srv;
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];
srv.loadItems(m_voucher);
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));
}
}
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()
{
if (m_voucher.isNull())
@ -51,6 +71,7 @@ void ShopForm::on_directSale_clicked()
}
DirectSaleForm *form = new DirectSaleForm(this);
form->setAttribute(Qt::WA_DeleteOnClose);
connect(form, &QDialog::accepted, [this, form](){
ShopService srv;
@ -65,8 +86,7 @@ void ShopForm::on_directSale_clicked()
void ShopForm::on_temporarySaveButton_clicked()
{
TemporaryReceiptSaveForm *form = new TemporaryReceiptSaveForm(this);
form->show();
doTempSave(false);
}
void ShopForm::on_saveButton_clicked()
@ -115,3 +135,79 @@ void ShopForm::createVoucher()
ShopService srv;
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);
~ShopForm();
void loadLast();
void fillRaceiptCombo();
private slots:
void on_directSale_clicked();
@ -30,12 +31,17 @@ private slots:
void onCountChanged();
void on_receiptCombo_currentIndexChanged(int index);
private:
Ui::ShopForm *ui;
QSharedPointer<Voucher> m_voucher;
AutoTableModel<VoucherItem> *m_itemsModel;
void createVoucher();
void doTempSave(bool comboChanged);
void changeReceipt();
void connectItemSignals();
};
#endif // SHOPFORM_H

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

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

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

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

Loading…
Cancel
Save