#include "shopform.h" #include "ui_shopform.h" #include "directsaleform.h" #include "temporaryreceiptsaveform.h" #include "receiptsaveform.h" #include "receiptloadform.h" #include "shopservice.h" #include #include #include "shop-odb.hxx" ShopForm::ShopForm(QWidget *parent) : QWidget(parent), ui(new Ui::ShopForm) { ui->setupUi(this); } ShopForm::~ShopForm() { delete ui; } void ShopForm::loadLast() { m_itemsModel = new AutoTableModel(this); m_itemsModel->setEditableCols(QList() << 1); ui->actualReceipt->setModel(m_itemsModel); ui->actualReceipt->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); ShopService srv; QList > receipt = srv.all(QString("status = %1").arg(QString::number(Voucher::NEW))); if (!receipt.isEmpty()) { m_voucher = receipt[0]; srv.loadItems(m_voucher); m_itemsModel->setData(m_voucher->items()); foreach (QSharedPointer 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::on_directSale_clicked() { if (m_voucher.isNull()) { createVoucher(); } DirectSaleForm *form = new DirectSaleForm(this); connect(form, &QDialog::accepted, [this, form](){ ShopService srv; srv.addShopItem(m_voucher, form->shopItem(), ((DirectSaleItem*)form->shopItem().data())->count()); this->m_itemsModel->addRow(m_voucher->items()[m_voucher->items().count() - 1]); connect(m_voucher->items()[m_voucher->items().count() - 1].data(), SIGNAL(countChanged()), this, SLOT(onCountChanged())); onCountChanged(); }); form->show(); } void ShopForm::on_temporarySaveButton_clicked() { TemporaryReceiptSaveForm *form = new TemporaryReceiptSaveForm(this); form->show(); } void ShopForm::on_saveButton_clicked() { ReceiptSaveForm *form = new ReceiptSaveForm; form->show(); } void ShopForm::on_loadButton_clicked() { ReceiptLoadForm *form = new ReceiptLoadForm; form->show(); } void ShopForm::onCountChanged() { VoucherItem *item = qobject_cast(sender()); if (item != NULL && item->count() == 0) { for (int i = 0; i < m_voucher->items().count(); i++) { if (m_voucher->items()[i].data() == item) { m_voucher->removeItem(m_voucher->items()[i]); m_itemsModel->setData(m_voucher->items()); } } } ShopService srv; srv.calculate(m_voucher); ui->total->setText(QString::number(m_voucher->totalPrice().toDouble(), 'f', 2)); if (m_voucher->status() == Voucher::NEW && m_voucher->id() == 0) { srv.save(m_voucher); } else { srv.update(m_voucher); } } void ShopForm::createVoucher() { ShopService srv; m_voucher = srv.createVoucher(); }