Example #1
0
    def autentificar(self):
        if self.changeConection(self.cbServidores.currentIndex()):
            usuario = str(self.leUsuario.text())
            clave = str(self.leClave.text())
            m = md5.new(clave)
            clave = m.hexdigest()

            if len(usuario) > 0:
                self.curser.execute("SELECT * from usuarios where usuario='{0}' and clave='{1}'".format(usuario, clave))
                user = self.curser.fetchone()
                if user != None:
                    user = dicursor(self.curser, user)
                    if user != None:
                        if user["nivel"] >= self.nivel:
                            self.lbInfo.setText("<h2>Bienvenido %s </h2>" % user["nombre"])
                            print "Bienvenido %s " % user["nombre"]
                            self.usuario = user
                            self.done(int(user["id_usuario"]))
                        else:
                            self.notify("Su nivel de acceso es menor al necesario, consulte con su superior.")
                    else:
                        if self.count < 2:
                            self.notify(
                                "El usuario/clave son incorrectos\nIntentelo nuevamente (Intentos {0}).".format(
                                    self.count
                                )
                            )
                            self.count += 1
                        else:
                            self.done(-1)
Example #2
0
    def checkAllPromos(self,ref):
	  promos=[]
	  self.curser.execute("SELECT `ref`,`precio`, familia, departamento  FROM productos,familias where ref=%s AND familia=familias.id   AND familia=familias.id limit 1"%ref)
	  prod = self.curser.fetchone()
	  if prod!=None:
	    prod=dicursor(self.curser,prod)
	    self.cursor.execute("SELECT nombre,minimo, descuento, %s-(%s*descuento*0.01) FROM ofertas as O,promociones as P WHERE ((tipo=0 and conjunto=%s) OR (tipo=1 and conjunto=%s) OR (tipo=2 and conjunto=%s)) AND O.promocion=P.id AND CURDATE() BETWEEN P.inicio AND P.fin  order by P.descuento desc "%(prod['precio'],prod['precio'],prod['ref'],prod['familia'],prod['departamento']))
	    oferta=self.cursor.fetchall()
	    if oferta !=None:
	      oferta=list(oferta)
	      promos.extend(oferta)
	    return promos
Example #3
0
    def editar(self,y,x):
	#head=['id','nombre']
	key=self.ui.twUsuarios.item(y,0).text()
	self.ide=key
	self.curser.execute("SELECT * FROM usuarios where id_usuario=%s"%key)
	usuario=self.curser.fetchone()
	if usuario!=None:
	  usuario=dicursor(self.curser,usuario)
	  self.ui.leNombre.setText(str(usuario['nombre']))
	  self.ui.leUsuario.setText(str(usuario['usuario']))
	  self.ui.leClave.setEnabled(False)
	  self.ui.cbNivel.setCurrentIndex(self.ui.cbNivel.findData(QVariant(usuario['nivel'])))
Example #4
0
    def iniciar(self): #iniciar para edicion
      self.extraTool.addWidget(self.CP)  
      self.tools.setVisible(False)
      if self.ide!=-1:
	self.curser.execute("""SELECT * FROM promociones where id=%s """%self.ide)
	row=self.curser.fetchone()
	if row!=None:
	  row=dicursor(self.curser,row)
	  self.leNombre.setText(row['nombre'])
	  self.dsDescuento.setValue(row['descuento'])
	  self.sbMinimo.setValue(row['minimo'])
	  self.sbMaximo.setValue(row['maximo'])
	  self.deInicio.setDate(QDate().fromString(str(row['inicio']), "yyyy-MM-dd"))
	  self.deFin.setDate(QDate().fromString(str(row['fin']), "yyyy-MM-dd"))
	  self.cargarLista()
Example #5
0
    def checar(self):
	line=str(self.codigo.text())
	if len(line)>0:
	  self.curser.execute('SELECT ref,`descripcion`, `precio`, nombre as unidad from productos,unidades as u where unidad=u.id and codigo='+line+' or ref='+line+' limit 1;')
	  prod=None
	  prod=self.curser.fetchone()
	  cad=''
	  if prod!=None:
	    prod=dicursor(self.curser,prod)
	    promos=self.checkAllPromos(prod['ref'])#Devuelve una lista [(nombre, minimo,descuento,precio-descuento)]
	    if len(promos)>0:
	      for promo in promos:
		cad+="A partir de %s %s : <b>$%s</b><br/>"%(promo[1],prod['unidad'],promo[3])
	      cad="<p style=\"font-size:17px\">%s</p>"%cad
	  else:
	    prod={"descripcion":"Lo sentimos, pero este producto no fue encontrado, verifique nuevamente o pregunte en cajas.",'precio':''}
	  self.lblInfo.setText(prod['descripcion'])
	  self.stack.setCurrentIndex(1)  
	  self.lblPrecio.setText("<h2>Precio: $%s</h2>%s"%(prod['precio'],cad))
	  self.codigo.clear()
	  self.codigo.setFocus(True)
Example #6
0
    def iniciar(self):
      if self.cargarPlantilla():
	iva=0
	subtotal=0
	total=0
	alto=int(self.cfg.get("documento", "alto"))
	ancho=int(self.cfg.get("documento", "ancho"))
	cfont=QFont("Droid Sans", int(self.cfg.get("cliente", "fuente")), int(self.cfg.get("cliente", "peso") ))
	pfont=QFont("Droid Sans", int(self.cfg.get("productos", "fuente")), int(self.cfg.get("productos", "peso") ))
	ffont=QFont("Droid Sans", int(self.cfg.get("fecha", "fuente")), int(self.cfg.get("fecha", "peso") ))
	tfont=QFont("Droid Sans", int(self.cfg.get("totales", "fuente")), int(self.cfg.get("totales", "peso") ))
	self.escena.setSceneRect(-int(self.cfg.get("documento", "x")),-int(self.cfg.get("documento", "y")),ancho,alto)
	fuente=QFont("Droid Sans", int(self.cfg.get("documento", "fuente")), int(self.cfg.get("documento", "peso") ))
	smallDroid=QFont("Droid Sans", 9)
	sql="""SELECT * FROM clientes as C, notas WHERE notas.id=%s and notas.cliente=C.id;"""%self.num
	self.curser.execute(sql)
	cliente=self.curser.fetchone()
	if cliente!=None:
	  cliente=dicursor(self.curser,cliente)
	datos=self.escena.addText("",cfont)
	datos.setHtml("<p><b>Nombre:</b> %s<br><b>Direccion:</b>  %s, C.P %s %s, %s.<br><b>RFC:</b>  %s</p>"%(cliente['nombre'],cliente['direccion'],cliente['correo'],cliente['poblacion'],cliente['estado'],cliente['rfc']))
	datos.setPos(int(self.cfg.get("cliente", "x")) ,int(self.cfg.get("cliente", "y")))
	datos.setTextWidth(int(self.cfg.get("cliente", "ancho")))
	self.curser.execute("SELECT cantidad, `descripcion`,total/cantidad as precio,total,porcentaje as imp,unidades.nombre as unidad, ' ' as espacio  from productos,vendidos, impuestos , unidades where ref=producto and venta="+str(self.num)+" and impuestos.id=impuesto and unidades.id=unidad group by ref")
	fecha=self.escena.addText("",ffont)
	if isinstance(cliente['fecha'],datetime.datetime):
	  fecha.setHtml(cliente['fecha'].strftime(self.cfg.get("fecha", "formato")))
	else:
	  fecha.setHtml(datetime.datetime.strptime(cliente['fecha'],'%Y-%m-%d %H:%M:%S').strftime(self.cfg.get("fecha", "formato")))
	fecha.setPos(int(self.cfg.get("fecha", "x")),int(self.cfg.get("fecha", "y")))
	fecha.setTextWidth(int(self.cfg.get("fecha", "ancho")))
	#print "SELECT cantidad, `descripcion`,precio,total from productos,vendidos where ref=producto and venta="+str(self.num)+" group by ref"
	arts=self.curser.fetchall()
	if arts!=None:
	  arts=dicursor(self.curser,arts)
	  col=[[],[],[],[],[]]
	  #dict(arts)
	  for item in arts:
	    imp=0;porc=0
	    imp=item['total']/float("1.%d"%item['imp'])
	    porc=imp*(int(item['imp'])*.01)
	    #imp=round(imp,2)
	    #porc=round(porc,2)
	    #porc+=item['total']-(imp+porc)
	    total+=item['total']
	    item['precio']=round(imp/item['cantidad'],2)
	    item['total']=round(imp,2) 
	    iva+=porc
	    subtotal+=imp
	  subtotal=round(subtotal,2)
	  iva=round(iva,2)
	  filas=[]
	  campos=self.cfg.get("productos", "campos").replace(" ","").split(",")
	  heads="{%s}"%"},{".join(campos)
	  anchos=self.cfg.get("productos", "anchos").replace(" ","").split(",")
	  #cabezas=heads.replace("{","").replace("}","").split(",")
	  for item in arts:
	      row=heads.format(**item)
	      filas.append(row.split(','))

	  heads=heads.replace("{","").replace("}","") 
	  tabla=self.escena.addText("",pfont)
	  tabla.setHtml(listaHtml(filas,cabezas=campos,color='#fff',fondo="#FFF", tfuente=11,opc="101",css="th{color:#FFF} .celda{margin:10px;padding:5px;}",anchos=anchos))
	  tabla.setPos(int(self.cfg.get("productos", "x")),int(self.cfg.get("productos", "y")))
	  tabla.setTextWidth(int(self.cfg.get("productos", "ancho")))

	cantidad=self.escena.addText("",pfont)
	cantidad.setHtml("<center>%s</center>"%nletra(total))
	cantidad.setPos(int(self.cfg.get("nletra", "x")),int(self.cfg.get("nletra", "y")))
	cantidad.setTextWidth(int(self.cfg.get("nletra", "ancho")))
	totales=self.escena.addText("",tfont)
	totales.setHtml("<p ALIGN=right>%.2f</p><p ALIGN=right>%.2f</p><p ALIGN=right>%.2f</p>"%(float(subtotal),float(iva),float(total)))
	totales.setPos(int(self.cfg.get("totales", "x")),int(self.cfg.get("totales", "y")))
	totales.setTextWidth(int(self.cfg.get("totales", "ancho")))
	#self.curser.execute("SELECT cantidad, `descripcion`,precio,total from productos,vendidos where ref=producto and venta="+str(self.num)+" group by ref")
	
	self.gvDocumento.setScene(self.escena)
      else:
	print "Error al cargar plantilla"
Example #7
0
    def iniciar(self):
      if self.cargarPlantilla():
	iva=0
	subtotal=0
	total=0
	alto=int(self.cfg.get("documento", "alto"))
	ancho=int(self.cfg.get("documento", "ancho"))
	cfont=QtGui.QFont("Droid Sans", int(self.cfg.get("cliente", "fuente")), int(self.cfg.get("cliente", "peso") ))
	pfont=QtGui.QFont("Droid Sans", int(self.cfg.get("productos", "fuente")), int(self.cfg.get("productos", "peso") ))
	ffont=QtGui.QFont("Droid Sans", int(self.cfg.get("fecha", "fuente")), int(self.cfg.get("fecha", "peso") ))
	tfont=QtGui.QFont("Droid Sans", int(self.cfg.get("totales", "fuente")), int(self.cfg.get("totales", "peso") ))
	self.escena.setSceneRect(-int(self.cfg.get("documento", "x")),-int(self.cfg.get("documento", "y")),ancho,alto)
	fuente=QtGui.QFont("Droid Sans", int(self.cfg.get("documento", "fuente")), int(self.cfg.get("documento", "peso") ))
	smallDroid=QtGui.QFont("Droid Sans", 9)
	self.curser.execute("""SELECT * FROM clientes as C, notas WHERE notas.id=%s and notas.cliente=C.id;"""%self.num)
	cliente=self.curser.fetchone()
	if cliente!=None:
	  cliente=dicursor(self.curser,cliente)
	datos=self.escena.addText("",cfont)
	datos.setHtml("<p><b>Nombre:</b> %s<br><b>Direccion:</b>  %s, C.P %s %s, %s.<br><b>RFC:</b>  %s</p>"%(cliente['nombre'],cliente['direccion'],cliente['correo'],cliente['poblacion'],cliente['estado'],cliente['rfc']))
	datos.setPos(int(self.cfg.get("cliente", "x")) ,int(self.cfg.get("cliente", "y")))
	datos.setTextWidth(int(self.cfg.get("cliente", "ancho")))
	self.curser.execute("SELECT cantidad, `descripcion`,precio,total,porcentaje as imp from productos,vendidos, impuestos where ref=producto and venta="+str(self.num)+" and impuestos.id=impuesto group by ref")
	fecha=self.escena.addText("",ffont)
	fecha.setHtml(datetime.datetime.strptime(cliente['fecha'],'%Y-%m-%d').strftime(self.cfg.get("fecha", "formato")))
	fecha.setPos(int(self.cfg.get("fecha", "x")),int(self.cfg.get("fecha", "y")))
	fecha.setTextWidth(int(self.cfg.get("fecha", "ancho")))
	#print "SELECT cantidad, `descripcion`,precio,total from productos,vendidos where ref=producto and venta="+str(self.num)+" group by ref"
	arts=self.curser.fetchall()
	col=[[],[],[],[]]
	#dict(arts)
	for item in arts:
	  imp=0;porc=0
	  imp=item['total']/float("1.%d"%item['imp'])
	  porc=imp*(int(item['imp'])*.01)
	  #imp=round(imp,2)
	  #porc=round(porc,2)
	  #porc+=item['total']-(imp+porc)
	  total+=item['total']
	  item['precio']=round(imp/item['cantidad'],2)
	  item['total']=round(imp,2) 
	  iva+=porc
	  subtotal+=imp
	subtotal=round(subtotal,2)
	iva=round(iva,2)
	for item in arts:
	    col[0].append("%.2f"%float(item['cantidad']))
	    col[1].append(str(item['descripcion']))
	    col[2].append("%.2f"%float(item['precio']))
	    col[3].append("%.2f"%float(item['total']))
	#tbl="<table width='%s%%' border='0' cellpadding=3 cellspacing=1 align='center'>"%self.cfg.get("productos", "ancho")
	#tbl+="<tr bgcolor=\"#ddd\" valign='middle' width='100%%' > <TH>1</TH><TH>2</TH><TH>3</TH><TH>4</TH></TR>"

	#for item in arts:
	  #tbl+="<tr bgcolor=\"#ddd\" valign='middle' width='100%%' >"
	  #tbl+="<td width='%s%%' align=\"right\"><span> %3.2f </span></td>"%(self.cfg.get("cantidad", "ancho"),float(item['cantidad']))
	  #tbl+="<td width='%s%%' align=\"center\"> <span> %s </span> </td>"%(self.cfg.get("desc", "ancho"),item['descripcion'])
	  #tbl+="<td width='%s%%' align=\"right\"><span> %3.2f </span> </td>"%(self.cfg.get("precio", "ancho"),float(item['precio']))
	  #tbl+="<td width='%s%%' align=\"right\"> <span> %3.2f </span></td>"%(self.cfg.get("total", "ancho"),float(item['total']))
	  #tbl+="</tr>"	  
	#tbl+="</table>"
	#print tbl
	#tabla=self.escena.addText("",pfont)  
	#tabla.setHtml(tbl)
	#tabla.setPos(int(self.cfg.get("productos", "x")),int(self.cfg.get("productos", "y")))   
	#cnt=
	cant=self.escena.addText("",pfont)
	cant.setHtml("<p ALIGN=right>%s</p>"%('<br>'.join(col[0])))
	cant.setPos(int(self.cfg.get("cantidad", "x")),int(self.cfg.get("productos", "y")))
	cant.setTextWidth(int(self.cfg.get("cantidad", "ancho")))

	desc=self.escena.addText('\n'.join(col[1]),pfont)
	desc.setPos(int(self.cfg.get("desc", "x")),int(self.cfg.get("productos", "y")))
	#desc.setTextWidth(int(self.cfg.get("desc", "ancho")))

	precio=self.escena.addText("",pfont)
	precio.setHtml("<p ALIGN=right>%s</p>"%('<br>'.join(col[2])))
	precio.setPos(int(self.cfg.get("precio", "x")),int(self.cfg.get("productos", "y")))
	precio.setTextWidth(int(self.cfg.get("precio", "ancho")))
	
	imp=self.escena.addText("",pfont)
	imp.setHtml("<p ALIGN=right>%s</p>"%('<br>'.join(col[3])))
	imp.setPos(int(self.cfg.get("total", "x")),int(self.cfg.get("productos", "y")))
	imp.setTextWidth(int(self.cfg.get("total", "ancho")))
	
	#col[1]=self.escena.addText('\n'.join(col[1]),pfont)
	#col[1].setPos(int(self.cfg.get("desc", "x")),int(self.cfg.get("productos", "y")))
	#col[2]=self.escena.addText('\n'.join(col[2]),pfont)
	#col[2].setPos(int(self.cfg.get("precio", "x")),int(self.cfg.get("productos", "y")))
	#col[3]=self.escena.addText('\n'.join(col[3]),pfont)
	#col[3].setPos(int(self.cfg.get("total", "x")),int(self.cfg.get("productos", "y")))
	cantidad=self.escena.addText("",pfont)
	cantidad.setHtml("<center>%s</center>"%nletra(total))
	cantidad.setPos(int(self.cfg.get("nletra", "x")),int(self.cfg.get("nletra", "y")))
	cantidad.setTextWidth(int(self.cfg.get("nletra", "ancho")))
	totales=self.escena.addText("",tfont)
	totales.setHtml("<p ALIGN=right>%.2f</p><p ALIGN=right>%.2f</p><p ALIGN=right>%.2f</p>"%(float(subtotal),float(iva),float(total)))
	totales.setPos(int(self.cfg.get("totales", "x")),int(self.cfg.get("totales", "y")))
	totales.setTextWidth(int(self.cfg.get("totales", "ancho")))
	#self.curser.execute("SELECT cantidad, `descripcion`,precio,total from productos,vendidos where ref=producto and venta="+str(self.num)+" group by ref")
	
	self.gvDocumento.setScene(self.escena)
      else:
	print "Error al cargar plantilla"