Esempio n. 1
0
	def showAddDrugForm(self, row, col):
		if row == self.ui.tableWidget.rowCount() - 1:
			self.add_drug_form = AddDrugForm(self)
			self.add_drug_form.setWindowModality(2)
			QObject.connect(self.add_drug_form.count_form, SIGNAL("drugAdded()"), self.drawTable)
			self.add_drug_form.show()
Esempio n. 2
0
class SaleWindow(QFrame):
	def initForm(self):
		QFrame.__init__(self)
		self.ui = Ui_sale_form()
		self.ui.setupUi(self)
		self.s = Session()
		QObject.connect(self.ui.tableWidget, SIGNAL("cellDoubleClicked(int, int)"), self.showAddDrugForm)
		QObject.connect(self.ui.reciever_btn, SIGNAL("clicked()"), self.setReciever)
		QObject.connect(self.ui.reciever_combo, SIGNAL("currentIndexChanged(int)"), self.changeReciever)
		QObject.connect(self.ui.save_close_btn, SIGNAL("clicked()"), self.acceptSale)
		QObject.connect(self.ui.save_btn, SIGNAL("clicked()"), self.saveSale)
		QObject.connect(self.ui.financing_combo, SIGNAL("currentIndexChanged(int)"), self.setFinancing)
		QObject.connect(self.ui.close_btn, SIGNAL("clicked()"), self.closeme)
		
		self.setWindowTitle(QString.fromUtf8('Создание расходной накладной'))
		self.drawFinancingCombo()
		
		self.ui.m_org_combo = QComboBox(self)
		self.ui.gridLayout.addWidget(self.ui.m_org_combo, 4, 2, 1, 1)
		self.ui.m_org_combo.setVisible(False)
		
		QObject.connect(self.ui.m_org_combo, SIGNAL("currentIndexChanged(int)"), self.newMedorg)
	def initNewSale(self):
		self.sale = Sale()
#financing
		self.sale.financing = self.financing
		self.sale.create_date = date.today()
		
	def __init__(self,sale = None):
		self.initForm()
		if sale == None:
			self.initNewSale()
		else:
			self.sale = sale
		self.drawTable()
		self.drawControls()
			
	
	def drawControls(self):
		self.ui.financing_combo.setCurrentIndex(self.ui.financing_combo.findText(self.sale.financing.name))
		self.ui.reciever_label.setText(QString.fromUtf8(repr(self.sale.getReciever())))
		if self.sale.m_organisation == None:
			self.ui.reciever_btn.setVisible(True)
			self.ui.m_org_combo.setVisible(False)
		else:
			self.ui.reciever_btn.setVisible(False)
			self.ui.m_org_combo.setVisible(True)
			self.ui.m_org_combo.setCurrentIndex(2)
			self.drawMedorgCombo()
			self.ui.m_org_combo.setCurrentIndex(self.ui.m_org_combo.findText(self.sale.m_organisation.name))

		self.ui.bill_number_date.setText(QString.fromUtf8(repr(self.sale)))
		self.ui.financing_combo.setDisabled(self.sale.accepted)
		self.ui.reciever_btn.setDisabled(self.sale.accepted)
		self.ui.m_org_combo.setDisabled(self.sale.accepted)
		self.ui.reciever_combo.setDisabled(self.sale.accepted)
		self.ui.save_close_btn.setDisabled(self.sale.accepted)
		self.ui.save_btn.setDisabled(self.sale.accepted)
		
	def drawTable(self):
		self.ui.tableWidget.clear()
		self.ui.tableWidget.setColumnCount(7)
		self.ui.tableWidget.setRowCount(1)
		self.ui.tableWidget.setHorizontalHeaderLabels([QString.fromUtf8('ИД'), QString.fromUtf8('Название препарата'), QString.fromUtf8('Производитель'), QString.fromUtf8('Серийный номер'), QString.fromUtf8('Годен до'), QString.fromUtf8('Цена'),QString.fromUtf8('Количество')])
		self.summ = 0
		for m in self.sale.maps:
			data = []
			data.append(str(m.drug.id))
			data.append(QString.fromUtf8(m.drug.name()))
			data.append(QString.fromUtf8(m.drug.manufacter.name))
			data.append(str(m.drug.serial))
			data.append(m.drug.best_before.strftime("%d.%m.%Y"))
			data.append(str(m.drug.price))
			data.append(str(m.count))
		
			self.summ = self.summ + m.count*m.drug.price
			for i in range(0,7):	
				tableitem = QTableWidgetItem()
				tableitem.setText(data[i])
				tableitem.font = QFont("Arial", 10)
				tableitem.font.setBold(True)
				tableitem.textcolor = QColor("black")
				tableitem.setBackgroundColor(QColor('White'))
				self.ui.tableWidget.setItem(self.ui.tableWidget.rowCount() - 1,i,tableitem)
			self.ui.tableWidget.setRowCount(self.ui.tableWidget.rowCount()+1)
		self.ui.label_3.setText(QString.fromUtf8("Всего лс на сумму " + str(self.summ) + "р."))
		self.ui.tableWidget.resizeColumnsToContents()
		
	def drawFinancingCombo(self):
		fin = query_session.query(Financing).all()
		self.ui.financing_combo.clear()
		
		for item in fin:
			self.ui.financing_combo.addItem(item.name)
		self.setFinancing(0)
		
	def setFinancing(self,num):
		financing = query_session.query(Financing).filter_by(name=unicode(self.ui.financing_combo.itemText(num))).one()
		self.financing = financing
		print self.financing

	def changeReciever(self, res):
		if (res == 0):
			self.ui.reciever_btn.setText(QString.fromUtf8('Рецепт'))
			self.ui.reciever_btn.setVisible(True)
			self.ui.m_org_combo.setVisible(False)
		elif (res == 1):
			#self.ui.reciever_btn.setText(QString.fromUtf8('Мед. организация'))
			self.ui.m_org_combo.setVisible(True)
			self.ui.reciever_btn.setVisible(False)
			self.drawMedorgCombo()

	def showNewRecipeForm(self):
		self.new_recipe_form = NewRecipeForm(self)
		self.new_recipe_form.setWindowModality(2)
		self.new_recipe_form.show()
		self.ui.reciever_combo.setDisabled(True)

	def showAddDrugForm(self, row, col):
		if row == self.ui.tableWidget.rowCount() - 1:
			self.add_drug_form = AddDrugForm(self)
			self.add_drug_form.setWindowModality(2)
			QObject.connect(self.add_drug_form.count_form, SIGNAL("drugAdded()"), self.drawTable)
			self.add_drug_form.show()
			
			
	def acceptSale(self):
		self.sale.accepted = True
		self.saveSale()
	
	def saveSale(self):
		self.s.add(self.sale)
		self.s.commit()
		self.s.close()
		self.closeme()
		
	def closeme(self):
		self.parent().close()
		
	def setReciever(self):
		if self.ui.reciever_combo.currentIndex() == 0:
			self.showNewRecipeForm()
	
	
	def drawMedorgCombo(self):
		combo = self.ui.m_org_combo
		items = query_session.query(M_organisation).all()
		combo.clear()		
		for item in items:
			combo.addItem(QString.fromUtf8(repr(item)))
		
		combo.addItem(QString.fromUtf8('Добавить'))
		combo.setCurrentIndex(0)
		
	def newMedorg(self,num):
		if (num >= self.ui.m_org_combo.count() - 1) and (self.ui.m_org_combo.count() > 1):
			self.new_medorg_form = NewMedorgForm()
			self.new_medorg_form.setWindowModality(2)
			QObject.connect(self.new_medorg_form, SIGNAL("medorgAdded()"), self.drawMedorgCombo)
			self.new_medorg_form.show()
		else:
			self.sale.m_organisation = query_session.query(M_organisation).filter_by(name=str(self.ui.m_org_combo.currentText().toUtf8())).one()
Esempio n. 3
0
class DeliverWindow(QFrame):
	
	def initForm(self):
		QFrame.__init__(self)
		self.ui = Ui_deliver_form()
		self.ui.setupUi(self)
		
		self.ui.distributor_combo.setEditable(False)
		self.drawDistributorCombo()
		self.drawFinancingCombo()
		QObject.connect(self.ui.tableWidget, SIGNAL("cellDoubleClicked(int, int)"), self.showAddDrugForm)
		QObject.connect(self.ui.save_close_btn, SIGNAL("clicked()"), self.saveAcceptDeliver)
		QObject.connect(self.ui.save_btn, SIGNAL("clicked()"), self.saveDeliver)
		QObject.connect(self.ui.print_bill_btn, SIGNAL("clicked()"), self.createReport)
		QObject.connect(self.ui.close_btn, SIGNAL("clicked()"), self.closeme)
	
	def initNewDeliver(self):
		self.deliver = Deliver()
		self.deliver.create_date = date.today()
		self.ui.bill_number_date.setText(QString.fromUtf8(repr(self.deliver)))
		self.ui.deliver_date.setText(QString.fromUtf8(self.deliver.create_date.strftime("%d.%m.%Y")))
		self.drawTable()
		
		
	def __init__(self,deliver=None):
		self.initForm()
		if deliver == None:
			self.initNewDeliver()
		else:
			self.deliver = deliver
			self.ui.bill_number_date.setText(QString.fromUtf8(repr(self.deliver)))
			self.ui.deliver_date.setText(self.deliver.deliver_date.strftime("%d.%m.%Y"))
			self.ui.distributor_combo.setCurrentIndex(self.ui.distributor_combo.findText(self.deliver.distributor.name))
			self.ui.financing_combo.setCurrentIndex(self.ui.financing_combo.findText(self.deliver.financing.name))
			self.drawTable()
			
			if self.deliver.accepted:
				self.ui.save_btn.setDisabled(True)
				self.ui.save_close_btn.setDisabled(True)
				self.ui.distributor_combo.setDisabled(True)
				self.ui.financing_combo.setDisabled(True)
				self.ui.deliver_date.setDisabled(True)
	def drawTable(self):
		self.ui.tableWidget.clear()
		self.ui.tableWidget.setRowCount(1)
		self.ui.tableWidget.setColumnCount(7)
		self.ui.tableWidget.setHorizontalHeaderLabels([QString.fromUtf8('ИД'), QString.fromUtf8('Название препарата'), QString.fromUtf8('Производитель'), QString.fromUtf8('Серийный номер'), QString.fromUtf8('Годен до'), QString.fromUtf8('Цена'),QString.fromUtf8('Количество')])
		self.summ = 0
		for m in self.deliver.maps:
			if not m.count == 0:
				data = []
				data.append(str(m.drug.id))
				data.append(QString.fromUtf8(m.drug.name()))
				data.append(m.drug.manufacter.name)
				data.append(str(m.drug.serial))
				data.append(m.drug.best_before.strftime("%d.%m.%Y"))
				data.append(str(m.drug.price))
				data.append(str(m.count))
			
				self.summ = self.summ + m.count*m.drug.price
				for i in range(0,7):	
					tableitem = QTableWidgetItem()
					tableitem.setText(data[i])
					tableitem.font = QFont("Arial", 10)
					tableitem.font.setBold(True)
					tableitem.textcolor = QColor("black")
					tableitem.setBackgroundColor(QColor('White'))
					self.ui.tableWidget.setItem(self.ui.tableWidget.rowCount() - 1,i,tableitem)
				self.ui.tableWidget.setRowCount(self.ui.tableWidget.rowCount()+1)
			else:
				self.deliver.maps.remove(m)
		self.ui.label_3.setText(QString.fromUtf8("Всего лс на сумму " + str(self.summ) + "р."))
		self.ui.tableWidget.resizeColumnsToContents()		

	def drawDistributorCombo(self):
		distributors = query_session.query(Distributor).all()
		self.ui.distributor_combo.clear()		
		for item in distributors:
			self.ui.distributor_combo.addItem(item.name)
		
		self.ui.distributor_combo.addItem(QString.fromUtf8('Новый поставщик'))
		QObject.connect(self.ui.distributor_combo, SIGNAL("currentIndexChanged(int)"), self.setDistributor)
		self.setDistributor(0)
		
	def drawFinancingCombo(self):
		fin = query_session.query(Financing).all()
		self.ui.financing_combo.clear()
		
		for item in fin:
			self.ui.financing_combo.addItem(item.name)
		
		self.ui.financing_combo.addItem(QString.fromUtf8('Новый источник финансирования'))
		QObject.connect(self.ui.financing_combo, SIGNAL("currentIndexChanged(int)"), self.setFinancing)
		self.setFinancing(0)


	def showAddDrugForm(self, row, col):
		if row == self.ui.tableWidget.rowCount() - 1:
			self.add_drug_form = AddDrugForm(self)
			self.add_drug_form.setWindowModality(2)
			QObject.connect(self.add_drug_form.count_form, SIGNAL("drugAdded()"), self.drawTable)
			self.add_drug_form.showMaximized()
			

	def saveAcceptDeliver(self):
		self.deliver.accepted = True
		self.saveDeliver()
		
	def saveDeliver(self):
		self.deliver.deliver_date = _date_from_str(self.ui.deliver_date.text())
		self.deliver.distributor = self.distributor
		self.deliver.financing = self.financing
		s = Session()
		s.add(self.deliver)
		s.commit()
		s.close()
		
		self.parent().close()
	
	
	def setDistributor(self,num):
		if (num < self.ui.distributor_combo.count() - 1):
			distributor = query_session.query(Distributor).filter_by(name=unicode(self.ui.distributor_combo.itemText(num))).one()
			self.distributor = distributor
		else:
			self.new_distributor_form = NewDistributorForm(self)
			self.new_distributor_form.setWindowModality(2)
			QObject.connect(self.new_distributor_form, SIGNAL("distributorAdded()"), self.drawTable)
			QObject.connect(self.new_distributor_form, SIGNAL("distributorAdded()"), self.drawDistributorCombo)	
			self.new_distributor_form.show()
	
	def setFinancing(self,num):
		if (num < self.ui.financing_combo.count() - 1):
			financing = query_session.query(Financing).filter_by(name=unicode(self.ui.financing_combo.itemText(num))).one()
			self.financing = financing
		else:
			self.new_financing_form = NewFinancingForm(self)
			self.new_financing_form.setWindowModality(2)
			QObject.connect(self.new_financing_form, SIGNAL("financingAdded()"), self.drawTable)
			QObject.connect(self.new_financing_form, SIGNAL("financingAdded()"), self.drawFinancingCombo)	
			self.new_financing_form.show()
			
	
	def createReport(self):
		fileName = '%sdeliver%d.pdf' % ('reports/', self.deliver.id)
		if path.exists(fileName):
			os.popen('evince %s' % fileName)
		else:
			opts = {'deliver': self.deliver}
			renderer = Renderer('appy/templates/deliver.odt', opts, fileName)
			renderer.run()
			
		os.popen('evince %s' % fileName)
		
	def closeme(self):
		self.parent().close()