|  |  |  | @ -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); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | } | 
		
	
	
		
			
				
					|  |  |  | 
 |