Exemple #1
0
class ControladorCerrarCampania:
    mdlCamp = ModeloCampanias()

    def __init__(self, parent, camp):
        self.parent = parent
        self.camp = camp

    def run(self):
        self.frame = FrameCerrarCampania(self.parent)
        self.frame.btn_cancelar.SetFocus()
        self.cargarDatos()
        rta = self.frame.ShowModal()

        if rta == wx.ID_OK:
            self.CerrarCampania()

        self.frame.Destroy()

    def cargarDatos(self):
        texto = str(self.camp['numero']) + '-' + str(self.camp['anio'])
        self.frame.st_campania.SetLabel(texto)
        self.frame.tc_inicio.SetValue(str(self.camp['inicio']))
        self.frame.tc_cierre.SetValue(time.strftime("%d-%m-%Y"))

    def CerrarCampania(self):
        self.mdlCamp.anio = self.camp['anio']
        self.mdlCamp.num = self.camp['numero']
        self.mdlCamp.fin = time.strftime("%Y-%m-%d")
        self.mdlCamp.close()
Exemple #2
0
class ControladorCrearCampania:
    mdlCamp = ModeloCampanias()

    def __init__(self, parent, usuario):
        self.usuario = usuario
        self.parent = parent

    def run(self):
        self.frame = FrameCrearCampania(self.parent)
        self.frame.tc_comentario.SetFocus()
        self.cargarDatos()
        self.cargarValidadores()
        resp = self.frame.ShowModal()
        if resp == wx.ID_OK:
            self.AgregarCampania()

    def cargarValidadores(self):
        self.mdlCamp.anio = int(time.strftime("%Y"))
        self.frame.tc_numero.SetValidator(Validar())
        self.frame.tc_diferencia.SetValidator(ValidarFlotante())
        self.frame.tc_base.SetValidator(ValidarFlotante())
        self.frame.tc_parametro.SetValidator(ValidarFlotante())

    def cargarDatos(self):
        self.mdlCamp.anio = int(time.strftime("%Y"))
        n = self.mdlCamp.get_next_number_campaign()
        self.frame.tc_numero.SetValue(str(n))
        self.frame.tc_fecha_inicio.SetValue(time.strftime("%d-%m-%Y"))
        self.frame.tc_usuario.SetValue(self.usuario)

    def AgregarCampania(self):
        self.mdlCamp.anio = int(time.strftime("%Y"))
        self.mdlCamp.num = int(self.frame.tc_numero.GetValue())
        if not self.mdlCamp.exist_campaign():
            self.mdlCamp.inicio = time.strftime("%Y-%m-%d")
            self.mdlCamp.ini_repato = self.frame.tc_ini_reparto.GetValue()
            self.mdlCamp.diferencia = float(
                self.frame.tc_diferencia.GetValue())
            self.mdlCamp.parametro = float(self.frame.tc_parametro.GetValue())
            self.mdlCamp.base = float(self.frame.tc_base.GetValue())
            self.mdlCamp.comentario = self.frame.tc_comentario.GetValue()
            self.mdlCamp.usuario = self.usuario
            self.mdlCamp.create()
        else:
            wx.MessageBox(u"La campana que desea crear ya existe.", "Ups!")
class ControladorModificarCampania:
    mdlCamp = ModeloCampanias()

    def __init__(self, parent, camp):
        self.parent = parent
        self.aCamp = camp

    def run(self):
        self.frame = FrameModificarCampania(self.parent)
        self.cargarDatos()
        self.cargarValidadores()
        self.frame.btn_cancelar.SetFocus()
        rpta = self.frame.ShowModal()
        if rpta == wx.ID_OK:
            self.Modificar()
        self.frame.Destroy()

    def cargarValidadores(self):
        self.frame.tc_diferencia.SetValidator(ValidarFlotante())
        self.frame.tc_base.SetValidator(ValidarFlotante())
        self.frame.tc_parametro.SetValidator(ValidarFlotante())

    def cargarDatos(self):
        self.frame.tc_fecha_inicio.SetValue(str(self.aCamp['inicio']))
        self.frame.tc_numero.SetValue(str(self.aCamp['numero']))
        self.frame.tc_ini_reparto.SetValue(self.aCamp['ini_reparto'])
        self.frame.tc_fin_reparto.SetValue(self.aCamp['fin_reparto'])
        self.frame.tc_diferencia.SetValue(str(self.aCamp['diferencia']))
        self.frame.tc_parametro.SetValue(str(self.aCamp['parametro']))
        self.frame.tc_base.SetValue(str(self.aCamp['base']))
        self.frame.tc_comentarios.SetValue(str(self.aCamp['comentarios']))

    def Modificar(self):
        self.mdlCamp.anio = self.aCamp['anio']
        self.mdlCamp.num = self.aCamp['numero']
        self.mdlCamp.ini_reparto = self.frame.tc_ini_reparto.GetValue()
        self.mdlCamp.fin_reparto = self.frame.tc_fin_reparto.GetValue()
        self.mdlCamp.diferencia = float(self.frame.tc_diferencia.GetValue())
        self.mdlCamp.parametro = float(self.frame.tc_parametro.GetValue())
        self.mdlCamp.base = float(self.frame.tc_base.GetValue())
        self.mdlCamp.comentario = self.frame.tc_comentarios.GetValue()
        self.mdlCamp.update()
Exemple #4
0
class ControladorVerCampania:
    mdlCampania = ModeloCampanias()

    def __init__(self, parent, Seleccionado):
        self.parent = parent
        self.mdlCampania.num = Seleccionado[1]
        self.mdlCampania.inicio = Seleccionado[0]

    def run(self):
        self.frame = FrameVerCampania(self.parent)
        self.cargarDatos()
        self.frame.ShowModal()

    def capturarEventos(self):
        pass

    def cargarDatos(self):
        datos = self.mdlCampania.read()
        camp = str(datos[0][1]) + "-" + str(datos[0][2]).split("-")[0]
        self.frame.tc_campania.SetValue(camp)
        self.frame.tc_inicio.SetValue(str(datos[0][2]))
        self.frame.tc_fin.SetValue(str(datos[0][3]))
        self.frame.tc_comentarios.SetValue(str(datos[0][4]))
        self.frame.tc_usuario.SetValue(str(datos[0][5]))
Exemple #5
0
    def generar_reporte(self):
        """Crear libro y hoja xls"""
        wb = xlwt.Workbook(encoding='latin-1')
        mdlArt = ModeloArticulos()
        mdlCamp = ModeloCampanias()
        mdlLis = ModeloListados()

        mdlArt.cam_anio = self.camp['anio']
        mdlArt.cam_num = self.camp['numero']

        progresoMax = len(self.contenido)
        dialog = wx.ProgressDialog("Progreso",
                                   "Generando ruta...",
                                   progresoMax,
                                   style=wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME
                                   | wx.PD_REMAINING_TIME)
        band = True
        incremento = 0
        for nombre in self.contenido:
            ws = wb.add_sheet(nombre)

            estilo = xlwt.easyxf(
                'font: bold on; align: vert centre, horiz left')

            ws.write(0, 0, u"REPARTO DIA: %s" % self.dia, estilo)

            ws.write(2, 0, u"ord", estilo)
            ws.col(0).width = len('ord__') * 256

            ws.write(2, 1, u"codigo", estilo)
            ws.write(2, 2, u"sec", estilo)
            ws.write(2, 3, u"apellido y nombre", estilo)
            ws.col(3).width = len('__apellido y nombre__') * 256

            ws.write(2, 4, u"deuda", estilo)
            ws.write(2, 5, u"localidad", estilo)
            ws.write(2, 6, u"domicilio", estilo)
            ws.write(2, 7, u"telefono", estilo)
            ws.write(2, 8, u"barrio", estilo)
            ws.write(2, 9, u"rec", estilo)
            ws.write(2, 10, u"estado", estilo)

            for fila, dato in enumerate(self.contenido[nombre]):
                ws.write(fila + 3, 0, dato[0])
                ws.write(fila + 3, 1, dato[1])
                if dato[2].strip().isdigit():
                    ws.write(fila + 3, 2, int(dato[2]))
                else:
                    ws.write(fila + 3, 2, dato[2])
                ws.write(fila + 3, 3, dato[3])
                ws.write(fila + 3, 4, dato[4])
                ws.write(fila + 3, 5, dato[5])
                ws.write(fila + 3, 6, dato[6])

                if dato[7].strip().isdigit():
                    ws.write(fila + 3, 7, int(dato[7]))
                else:
                    ws.write(fila + 3, 7, dato[7])

                ws.write(fila + 3, 8, dato[8])

                mdlArt.cli_codigo = dato[1]

                hist = mdlArt.historial(12).split(',')[1:]
                cont = hist.count('A') + hist.count('S/B')
                ws.write(fila + 3, 9, cont)

                if mdlArt.exist():
                    if mdlArt.articulo_pagado() != 0:
                        if str(mdlArt.articulo_entregado()) == "None":
                            ws.write(fila + 3, 10, u"Pagado")
                        else:
                            ws.write(fila + 3, 10, u"E")
                    elif dato[9] == 0:
                        ws.write(fila + 3, 10, u"")
                    elif dato[9] == 1:
                        ws.write(fila + 3, 10, u"R/D")
                    elif dato[9] == 2:
                        ws.write(fila + 3, 10, u"N/S")
                    elif dato[9] == 3:
                        ws.write(fila + 3, 10, u"Lider")

                    mdlLis.cam_anio = self.camp['anio']
                    mdlLis.cam_num = self.camp['numero']
                    mdlLis.numero = dato[11]
                    lis = mdlLis.read()
                    if lis:
                        ws.write(fila + 3, 11, lis['comentario'])
                else:
                    ws.write(fila + 3, 10, u"x")

            if band and incremento < progresoMax:
                incremento += 1
                band = dialog.Update(incremento)
        dialog.Destroy()
        wb.save(self.dir)
Exemple #6
0
class ModeloReporte:
    """Esta clase contiene los modulos para la creacion de archivos de extencion .xls
		para la generacion de reporte de campañas."""
    mdlCli = ModeloClientes()
    mdlArt = ModeloArticulos()
    mdlCamp = ModeloCampanias()
    mdlEnv = ModeloEnvios()
    mdlGvar = ModeloGastosVarios()

    def __init__(self, dir, camp):
        self.dir = dir
        self.mdlCamp.anio = camp['anio']
        self.mdlCamp.num = camp['numero']
        self.camp = self.mdlCamp.read()
        locale.setlocale(
            locale.LC_ALL,
            'spanish_spain')  # Para que la fecha este es catelano.

    def generar_libro(self):
        """Crear libro y hoja xls"""
        wb = xlwt.Workbook(encoding='latin-1')
        ws = wb.add_sheet("Hoja1")

        #Cargando encabezado
        ws.write(0, 0, "ZONA")
        ws.write(0, 1, u"CÓDIGO")
        ws.write(0, 2, "LOCALIDAD")
        ws.write(0, 3, "CAMP")
        ws.write(0, 4, "DEUDA")
        ws.write(0, 5, "NO ENTR")
        ws.write(0, 6, "BOLETA")

        #Cargando cuerpo de listado
        self.mdlArt.cam_anio = self.camp['anio']
        self.mdlArt.cam_num = self.camp['num']
        tabla = self.mdlArt.obtenerContenidoCampania()

        for i, fila in enumerate(tabla):
            ws.write(i + 1, 0, int(fila[0]))  # Zona
            ws.write(i + 1, 1, str(fila[1]))  # Codigo
            ws.write(i + 1, 2, str(fila[2]))  # Localidad
            ws.write(i + 1, 3, int(fila[3]))  # Camp
            ws.write(i + 1, 4, float(fila[4]))  # Deuda

            if str(fila[5]) == "None":  # No Entr
                ws.write(i + 1, 5, "x")
            else:
                ws.write(i + 1, 5, "")

            if fila[6] == 2:  # Boleta
                ws.write(i + 1, 6, "x")
            else:
                ws.write(i + 1, 6, "")

        # Cargando pie de reporte (formulas)
        cantFilas = len(tabla)

        ws.write(cantFilas + 5, 1, "Total en $")

        valArticulosCampania = 'SUM(E1:E%s)' % (cantFilas + 1)
        ws.write(cantFilas + 5, 3, xlwt.Formula(valArticulosCampania))

        valArticulosNoEntregados = 'SUMIF(F1:F%s;"x";E1:E%s)' % (cantFilas + 1,
                                                                 cantFilas + 1)
        ws.write(cantFilas + 5, 4, xlwt.Formula(valArticulosNoEntregados))

        valArticulosBoletas = 'SUMIF(G1:G%s;"x";E1:E%s)' % (cantFilas + 1,
                                                            cantFilas + 1)
        ws.write(cantFilas + 5, 5, xlwt.Formula(valArticulosBoletas))

        ws.write(cantFilas + 7, 1, u"Total en códigos")

        cantArticulosCampania = 'COUNT(E1:E%s)' % (cantFilas + 1)
        ws.write(cantFilas + 7, 3, xlwt.Formula(cantArticulosCampania))

        cantArticulosNoEntregados = 'COUNTIF(F1:F%s;"x")' % (cantFilas + 1)
        ws.write(cantFilas + 7, 4, xlwt.Formula(cantArticulosNoEntregados))

        cantArticulosBoletas = 'COUNTIF(G1:G%s;"x")' % (cantFilas + 1)
        ws.write(cantFilas + 7, 5, xlwt.Formula(cantArticulosBoletas))

        ws.write(cantFilas + 9, 0, "FECHA DE INICIO DE REPARTO")
        ws.write(cantFilas + 9, 3, self.camp['ini_reparto'])
        ws.write(cantFilas + 10, 0, "FECHA DE FIN DE REPARTO")
        ws.write(cantFilas + 10, 3, self.camp['fin_reparto'])

        ws.write(cantFilas + 12, 0, "A RENDIR")
        exp1 = "D%s" % (cantFilas + 6)
        ws.write(cantFilas + 12, 3, xlwt.Formula(exp1))

        ws.write(cantFilas + 14, 0, "NO ENTREGADOS")
        exp1 = "E%s" % (cantFilas + 6)
        ws.write(cantFilas + 14, 3, xlwt.Formula(exp1))

        ws.write(cantFilas + 15, 0, "BOLETAS INDIVIDUALES")
        exp1 = "F%s" % (cantFilas + 6)
        ws.write(cantFilas + 15, 3, xlwt.Formula(exp1))

        #Listado de depositos bancarios

        self.mdlEnv.ecam_anio = self.camp['anio']
        self.mdlEnv.ecam_num = self.camp['num']
        listadoEnv = self.mdlEnv.read_all()
        cantFilas2 = cantFilas + 16
        for i, dato in enumerate(listadoEnv):
            label = "%s° ENVIO" % (i + 1)
            ws.write(cantFilas2, 0, label)
            ws.write(cantFilas2, 3, dato[4])
            ws.write(cantFilas2, 4, dato[3])
            cantFilas2 += 1

        ws.write(cantFilas2 + 1, 0, u"DISTRIBUCIÓN")
        ws.write(cantFilas2 + 2, 0, "OTROS")

        # Cargando Otros Gastos
        self.mdlGvar.icam_anio = self.camp['anio']
        self.mdlGvar.icam_num = self.camp['num']
        listadoGvar = self.mdlGvar.read_all()
        cantFilas3 = cantFilas2 + 3
        for dato in listadoGvar:
            ws.write(cantFilas3, 0, dato[5])
            ws.write(cantFilas3, 3, dato[4])
            cantFilas3 += 1

        ws.write(cantFilas3 + 3, 0, "DIFERENCIA ANTERIOR")
        ws.write(cantFilas3 + 3, 3, self.camp['diferencia'])

        ws.write(cantFilas3 + 5, 0, "SALDO")

        ws.write(cantFilas3 + 10, 0, "GASTOS DE DISTRIBUCION")
        ws.write(cantFilas3 + 11, 0, "A entregar")
        exp1 = "D%s" % (cantFilas + 8)
        ws.write(cantFilas3 + 11, 3, xlwt.Formula(exp1))

        ws.write(cantFilas3 + 12, 0, "No entregados")
        exp1 = "E%s" % (cantFilas + 8)
        ws.write(cantFilas3 + 12, 3, xlwt.Formula(exp1))

        ws.write(cantFilas3 + 13, 0, "Pedidos a cobrar")
        exp1 = "D%s - D%s" % (cantFilas3 + 12, cantFilas3 + 13)
        ws.write(cantFilas3 + 13, 3, xlwt.Formula(exp1))

        #DISTRIBUCION
        exp1 = "D%s * %s+ %s" % (cantFilas3 + 14, self.camp['parametro'],
                                 self.camp['base'])
        ws.write(cantFilas2 + 1, 3, xlwt.Formula(exp1))

        #SALDO
        exp1 = 'SUM(D%s: D%s)- D%s' % (cantFilas + 15, cantFilas3 + 5,
                                       cantFilas + 13)
        ws.write(cantFilas3 + 5, 3, xlwt.Formula(exp1))

        wb.save(self.dir)
class ControladorCampanias:
    mdlCampanias = ModeloCampanias()

    def __init__(self, parent, usuario):
        self.parent = parent
        self.usuario = usuario
        self.listadoCampanias = self.mdlCampanias.read_all()
        self.Seleccionado = {}

    def run(self):
        self.frame = FrameCampanias(self.parent)

        loc = wx.IconLocation(r'icono.ico')
        self.frame.SetIcon(wx.IconFromLocation(loc))

        self.capturarEventos()
        self.configurarGrilla(len(self.listadoCampanias))
        self.cargarGrilla(self.listadoCampanias)
        self.deshabilitaBTNS()
        self.frame.Show()

    def capturarEventos(self):
        self.frame.btn_ver.Bind(wx.EVT_BUTTON, self.Ver)
        self.frame.btn_buscar.Bind(wx.EVT_BUTTON, self.Buscar)
        self.frame.btn_volver.Bind(wx.EVT_BUTTON, self.Volver)
        self.frame.grilla.Bind(wx.grid.EVT_GRID_SELECT_CELL,
                               self.f_seleccion_fila)

    def configurarGrilla(self, tam):
        self.frame.grilla.SetSelectionMode(wx.grid.Grid.SelectRows)
        self.frame.grilla.AppendRows(tam)
        presentador = wx.grid.GridCellAutoWrapStringRenderer
        for i in range(tam):
            self.frame.grilla.SetRowSize(i, 25)
            self.frame.grilla.SetCellRenderer(i, 1, presentador())

    def cargarGrilla(self, listado):
        for i in range(len(listado)):
            self.frame.grilla.SetCellValue(i, 0, str(listado[i][0]))
            self.frame.grilla.SetCellValue(i, 1, str(listado[i][1]))
            self.frame.grilla.SetCellValue(i, 2, str(listado[i][2]))
            self.frame.grilla.SetCellValue(i, 3, str(listado[i][4]))

    def limpiarGrilla(self):
        for i in range(self.frame.grilla.GetNumberRows()):
            self.frame.grilla.DeleteRows(0, 1)

    def refrescar_grilla(self, listado):
        self.limpiarGrilla()
        self.configurarGrilla(len(listado))
        self.cargarGrilla(listado)

    '''Eventos de Botones'''

    def Buscar(self, event):
        if self.isint(self.frame.tc_anio.GetValue()):
            if self.isint(self.frame.tc_numero.GetValue()):
                self.mdlCampanias.anio = int(self.frame.tc_anio.GetValue())
                self.mdlCampanias.num = int(self.frame.tc_numero.GetValue())
                self.listadoCampanias = self.mdlCampanias.read_x_anio_num()
                self.refrescar_grilla(self.listadoCampanias)
            else:
                self.mdlCampanias.anio = int(self.frame.tc_anio.GetValue())
                self.listadoCampanias = self.mdlCampanias.read_x_anio()
                self.refrescar_grilla(self.listadoCampanias)

    def Volver(self, event):
        self.frame.Destroy()

    def Ver(self, event):
        verCamp = ControladorResultadoCampania(self.frame, self.Seleccionado)
        verCamp.run()

    '''Habilitar/Deshabilitar Botones'''

    def deshabilitaBTNS(self):
        self.frame.btn_ver.Enable(False)

    def habilitarBTNS(self):
        self.frame.btn_ver.Enable(True)

    '''Eventos de Grilla'''

    def f_seleccion_fila(self, event):
        fila = event.GetRow()
        try:
            self.Seleccionado['anio'] = int(
                self.frame.grilla.GetCellValue(fila, 0))
            self.Seleccionado['numero'] = int(
                self.frame.grilla.GetCellValue(fila, 1))
            self.habilitarBTNS()
        except:
            pass
        event.Skip()

    def isint(self, n):
        try:
            int(n)
            return True
        except:
            return False
Exemple #8
0
class ControladorResultadoCampania:
    mdlArt = ModeloArticulos()
    mdlCamp = ModeloCampanias()

    def __init__(self, parent, camp):
        self.parent = parent
        self.camp = camp

    def run(self):
        self.frame = FrameResultadoCampania(self.parent)

        loc = wx.IconLocation(r'icono.ico')
        self.frame.SetIcon(wx.IconFromLocation(loc))

        self.frame.btn_volver.SetFocus()
        self.configurarGrilla()
        self.cargarGrilla()
        self.cargarDatos()
        self.capturarEventos()
        self.frame.Show()

    def capturarEventos(self):
        self.frame.btn_volver.Bind(wx.EVT_BUTTON, self.Volver)
        self.frame.btn_generar.Bind(wx.EVT_BUTTON, self.Generar)

        self.frame.grilla.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.Detalle)

    def configurarGrilla(self):
        self.frame.grilla.SetCellSize(0, 0, 3, 1)
        self.frame.grilla.SetCellSize(0, 1, 1, 6)
        self.frame.grilla.SetCellSize(1, 1, 1, 2)
        self.frame.grilla.SetCellSize(1, 3, 1, 2)
        self.frame.grilla.SetCellSize(1, 5, 1, 2)
        self.frame.grilla.SetCellSize(0, 7, 2, 2)

        self.frame.grilla.SetCellBackgroundColour(1, 1, '#81de1e')
        self.frame.grilla.SetCellBackgroundColour(1, 3, '#81de1e')
        self.frame.grilla.SetCellBackgroundColour(1, 5, '#81de1e')
        self.frame.grilla.SetCellBackgroundColour(3, 7, '#81de1e')
        self.frame.grilla.SetCellBackgroundColour(4, 1, '#81de1e')
        self.frame.grilla.SetCellBackgroundColour(4, 7, '#81de1e')

    def configurarGrilla2(self):
        pass

    def cargarGrilla(self):
        self.frame.grilla.SetCellValue(3, 0, "ENTREGADOS")
        self.frame.grilla.SetCellValue(4, 0, "NO ENTREGADOS")
        self.frame.grilla.SetCellValue(5, 0, "SUBTOTALES")

        self.frame.grilla.SetCellValue(0, 1, "COBRADOS")
        self.frame.grilla.SetCellValue(1, 1, "EFECTIVO")
        self.frame.grilla.SetCellValue(1, 3, "BOLETAS")
        self.frame.grilla.SetCellValue(1, 5, "RECIBO OFICINA")
        self.frame.grilla.SetCellValue(0, 7, "NO COBRADOS")

        self.frame.grilla.SetCellValue(2, 1, u"códigos")
        self.frame.grilla.SetCellValue(2, 2, "$")
        self.frame.grilla.SetCellValue(2, 3, u"códigos")
        self.frame.grilla.SetCellValue(2, 4, "$")
        self.frame.grilla.SetCellValue(2, 5, u"códigos")
        self.frame.grilla.SetCellValue(2, 6, "$")
        self.frame.grilla.SetCellValue(2, 7, u"códigos")
        self.frame.grilla.SetCellValue(2, 8, "$")

        self.mdlArt.cam_anio = self.camp['anio']
        self.mdlArt.cam_num = self.camp['numero']

        resultados = self.mdlArt.result_campaign()

        # cantidades Articulos
        self.frame.grilla.SetCellValue(3, 1,
                                       str(resultados['entregadosEfectivo']))
        self.frame.grilla.SetCellValue(4, 1,
                                       str(resultados['noEntregadosEfectivo']))
        self.frame.grilla.SetCellValue(5, 1,
                                       str(resultados['cobradosEfectivo']))

        self.frame.grilla.SetCellValue(3, 3,
                                       str(resultados['entregadosBoleta']))
        self.frame.grilla.SetCellValue(4, 3,
                                       str(resultados['noEntregadosBoleta']))
        self.frame.grilla.SetCellValue(5, 3, str(resultados['cobradosBoleta']))

        self.frame.grilla.SetCellValue(3, 5,
                                       str(resultados['entregadosOficina']))
        self.frame.grilla.SetCellValue(4, 5,
                                       str(resultados['noEntregadosOficina']))
        self.frame.grilla.SetCellValue(5, 5,
                                       str(resultados['cobradosOficina']))

        self.frame.grilla.SetCellValue(3, 7,
                                       str(resultados['entregadosNoCobrados']))
        self.frame.grilla.SetCellValue(
            4, 7, str(resultados['noEntregadosNoCobrados']))
        self.frame.grilla.SetCellValue(5, 7, str(resultados['noCobrados']))

        # valores Articulos

        self.frame.grilla.SetCellValue(
            3, 2, str(resultados['valEntregadosEfectivo']))
        self.frame.grilla.SetCellValue(
            4, 2, str(resultados['valNoEntregadosEfectivo']))
        self.frame.grilla.SetCellValue(5, 2, str(resultados['valEfectivo']))

        self.frame.grilla.SetCellValue(3, 4,
                                       str(resultados['valEntregadosBoleta']))
        self.frame.grilla.SetCellValue(
            4, 4, str(resultados['valNoEntregadosBoleta']))
        self.frame.grilla.SetCellValue(5, 4, str(resultados['valBoleta']))

        self.frame.grilla.SetCellValue(3, 6,
                                       str(resultados['valEntregadosOficina']))
        self.frame.grilla.SetCellValue(
            4, 6, str(resultados['valNoEntregadosOficina']))
        self.frame.grilla.SetCellValue(5, 6, str(resultados['valOficina']))

        self.frame.grilla.SetCellValue(
            3, 8, str(resultados['valEntregadosNoCobrados']))
        self.frame.grilla.SetCellValue(
            4, 8, str(resultados['valNoEntregadosNoCobrados']))
        self.frame.grilla.SetCellValue(5, 8, str(resultados['valNoCobrados']))

        # cargando grilla 2
        self.frame.grilla2.SetCellValue(1, 0, u"Total en $")
        self.frame.grilla2.SetCellValue(2, 0, u"Total en códigos")
        self.frame.grilla2.SetCellValue(0, 1, "DEUDA")
        self.frame.grilla2.SetCellValue(0, 2, "NO ENTR")
        self.frame.grilla2.SetCellValue(0, 3, "BOLETA")

        self.frame.grilla2.SetCellValue(
            1, 1, str(resultados['valArticulosCampania']))
        self.frame.grilla2.SetCellValue(
            1, 2, str(resultados['valArticulosNoEntregados']))
        self.frame.grilla2.SetCellValue(1, 3,
                                        str(resultados['valArticulosBoletas']))

        self.frame.grilla2.SetCellValue(
            2, 1, str(resultados['cantArticulosCampania']))
        self.frame.grilla2.SetCellValue(
            2, 2, str(resultados['cantArticulosNoEntregados']))
        self.frame.grilla2.SetCellValue(
            2, 3, str(resultados['cantArticulosBoletas']))

    def cargarDatos(self):
        self.mdlCamp.anio = self.camp['anio']
        self.mdlCamp.num = self.camp['numero']
        self.dCamp = self.mdlCamp.read()
        self.titulo = str(self.camp['numero']) + "-" + str(self.camp['anio'])
        self.frame.tc_campania.SetValue(self.titulo)
        self.frame.tc_inicio.SetValue(self.dCamp['inicio'])

    "Evento de ventana"

    def Volver(self, event):
        self.frame.Destroy()

    def Generar(self, event):
        nombreArchivo = "/Camp %s__%s .xls" % (self.titulo,
                                               time.strftime("%d-%m-%Y"))
        dialog = wx.DirDialog(self.frame,
                              "SELECCIONAR CARPETA DE DESTINO:",
                              style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
        rta = dialog.ShowModal()
        if rta == wx.ID_OK:
            dir = dialog.GetPath()

            dir = dir + nombreArchivo
            mdlRep = ModeloReporte(dir, self.camp)
            try:
                mdlRep.generar_libro()
            except:
                wx.MessageBox("Ha ocurrido un error al generar reporte.",
                              "Ups!")
            else:
                wx.MessageBox("El reporte ha sido generado con exito.",
                              "Enhorabuena!")

        dialog.Destroy()

    def Detalle(self, event):
        celda = (event.GetRow(), event.GetCol())
        if celda == (1, 1):  # Cobradas en efectivo
            cobEfCamp = ControladorCobradosEfectivoCampania(
                self.frame, self.camp)
            cobEfCamp.run()
        elif celda == (1, 3):  # Cobradas por boleta unica
            cobBoCamp = ControladorCobradosBoletaCampania(
                self.frame, self.camp)
            cobBoCamp.run()
        elif celda == (1, 5):  # Cobrados por recibo oficina
            cobReCamp = ControladorCobradosReciboCampania(
                self.frame, self.camp)
            cobReCamp.run()
        elif celda == (3, 7):  # No cobrados entregados
            noCoEntr = ControladorNoCobradosEntregadosCampania(
                self.frame, self.camp)
            noCoEntr.run()
        elif celda == (4, 1):  # Cobrados en efectivo no entregados
            cobEfNoEntrCamp = ControladorCobradosEfectivoNoEntregadosCampania(
                self.frame, self.camp)
            cobEfNoEntrCamp.run()
        elif celda == (4, 7):  # Desmantelado
            desCamp = ControladorDesmanteladoCampania(self.frame, self.camp)
            desCamp.run()
class ControladorHistorial:
    mdlArt = ModeloArticulos()
    mdlCamp = ModeloCampanias()
    mdlCli = ModeloClientes()

    def __init__(self, parent):
        self.parent = parent

    def run(self):
        self.frame = FrameHistorialClientes(self.parent)

        loc = wx.IconLocation(r'icono.ico')
        self.frame.SetIcon(wx.IconFromLocation(loc))

        self.capturarEventos()
        self.cargarValidadores()
        self.frame.Show()

    def capturarEventos(self):
        self.frame.btn_buscar.Bind(wx.EVT_BUTTON, self.Buscar)
        self.frame.tc_codigo.Bind(wx.EVT_TEXT_ENTER, self.Buscar)
        self.frame.tc_codigo.Bind(wx.EVT_TEXT, self.AutoCompletar)
        self.frame.btn_salir.Bind(wx.EVT_BUTTON, self.Salir)

    def cargarValidadores(self):
        self.frame.tc_rango.SetValidator(ValidarEntero())

    def Buscar(self, event):
        self.limpiar_grilla()
        self.mdlCli.codigo = self.frame.tc_codigo.GetValue()
        if self.mdlCli.exist():
            self.frame.tc_codigo.SetBackgroundColour(
                wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
            self.frame.tc_codigo.SetFocus()
            self.frame.tc_codigo.Refresh()

            datosCli = self.mdlCli.read()
            rng = int(self.frame.tc_rango.GetValue())
            camps = self.mdlCamp.campaign_in_range(rng)
            hist = self.mdlArt.historialCliente(camps, datosCli['codigo'])

            self.frame.grilla.AppendRows(1)
            self.frame.grilla.SetCellValue(0, 0, datosCli['codigo'])
            self.frame.grilla.SetCellValue(0, 1, datosCli['nombre'])
            self.frame.grilla.SetCellValue(0, 2, datosCli['seccion'])
            self.frame.grilla.SetCellValue(0, 3, datosCli['domicilio'])
            self.frame.grilla.SetCellValue(0, 4, datosCli['barrio'])

            col = 5
            for camp in camps:
                etiq = str(camp[1]) + "-" + str(camp[0])
                self.frame.grilla.SetColLabelValue(col, etiq)
                col += 1
            col = 5
            for h in hist:
                self.frame.grilla.SetCellValue(0, col, h)
                col += 1
        else:
            self.frame.tc_codigo.SetBackgroundColour("pink")
            self.frame.tc_codigo.SetFocus()
            self.frame.tc_codigo.Refresh()

    def AutoCompletar(self, event):
        prefijo = self.frame.tc_codigo.GetValue()
        if len(prefijo) == 4:
            sufijo = prefijo[-1]
            if sufijo != "/":
                prefijo = prefijo[:3] + "/"
                prefijo += sufijo
                self.frame.tc_codigo.SetValue(prefijo)
        self.frame.tc_codigo.SetInsertionPoint(len(prefijo))
        event.Skip()

    def limpiar_grilla(self):
        for i in range(self.frame.grilla.GetNumberRows()):
            self.frame.grilla.DeleteRows(0, 1)

    def Salir(self, event):
        self.frame.Destroy()
class ControladorClientes:
    mdlCamp = ModeloCampanias()
    mdlArt = ModeloArticulos()

    def __init__(self, parent, datosCaja):
        self.parent = parent
        self.datosCaja = datosCaja

    def run(self):
        self.frame = FrameClientes(self.parent.frame)

        loc = wx.IconLocation(r'icono.ico')
        self.frame.SetIcon(wx.IconFromLocation(loc))

        self.frame.tc_dato_busqueda.SetFocus()
        self.capturarEventos()
        self.frame.Show()

    def capturarEventos(self):
        self.frame.btn_buscar.Bind(wx.EVT_BUTTON, self.Buscar)
        self.frame.tc_dato_busqueda.Bind(wx.EVT_TEXT_ENTER, self.Buscar)
        self.frame.tc_dato_busqueda.Bind(wx.EVT_TEXT, self.AutoCompletar)
        self.frame.btn_continuar.Bind(wx.EVT_BUTTON, self.Continuar)
        self.frame.grilla.Bind(wx.grid.EVT_GRID_SELECT_CELL,
                               self.f_seleccion_fila)
        self.frame.grilla.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK,
                               self.Continuar)
        self.frame.btn_volver.Bind(wx.EVT_BUTTON, self.Volver)

    "Eventos"

    def Volver(self, event):
        self.frame.Destroy()

    def Buscar(self, event):
        # Primero verificamos que existe una campaña activa.
        campania = self.mdlCamp.get_active_campaign()
        if campania != {}:
            # Verificamos que el tipo de busqueda es por codigo.
            if self.frame.rb_codigo.GetValue() == True:
                # Tipo de busqueda por codigo.
                self.mdlArt.cam_anio = campania['anio']
                self.mdlArt.cam_num = campania['numero']
                self.mdlArt.cli_codigo = self.frame.tc_dato_busqueda.GetValue()
                self.datosCli = self.mdlArt.read()
                # Verificamos si existe un articulo para ese codigo.
                if self.datosCli != {}:
                    # Si existe mostramos los datos en la proxima pantalla.
                    self.Continuar()
                    self.frame.tc_dato_busqueda.SetBackgroundColour(
                        wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
                    self.frame.tc_dato_busqueda.Refresh()
                else:
                    # Si no existe.
                    self.frame.tc_dato_busqueda.SetBackgroundColour("pink")
                    self.frame.tc_dato_busqueda.SetFocus()
                    self.frame.tc_dato_busqueda.Refresh()
            else:
                # Tipo de busqueda es por apellido y nombre.
                self.mdlArt.cam_anio = campania['anio']
                self.mdlArt.cam_num = campania['numero']
                self.mdlArt.cli_apenom = self.frame.tc_dato_busqueda.GetValue()
                self.refrescar_grilla()
                self.frame.btn_continuar.Enable(False)
        else:
            wx.MessageBox(
                u"No se ha encontrado una campaña activa.\nPor favor compruebe que exista una campaña \nabierta.",
                "No existe campaña activa!")

    def AutoCompletar(self, event):
        if self.frame.rb_codigo.GetValue():
            prefijo = self.frame.tc_dato_busqueda.GetValue()
            if len(prefijo) == 4:
                sufijo = prefijo[-1]
                if sufijo != "/":
                    prefijo = prefijo[:3] + "/"
                    prefijo += sufijo
                    self.frame.tc_dato_busqueda.SetValue(prefijo)
            self.frame.tc_dato_busqueda.SetInsertionPoint(len(prefijo))
            event.Skip()

    def Continuar(self, event=None):
        campania = self.mdlCamp.get_active_campaign()
        if campania != {}:
            infoCli = ControladorInfoCliente(self.frame, self.datosCaja,
                                             self.datosCli)
            infoCli.run()
            self.frame.tc_dato_busqueda.SelectAll()
            self.parent.refrescar_grilla_uno()
            self.parent.refrescar_resultados()
            self.parent.panelUno.btn_modificar.Enable(False)
        else:
            wx.MessageBox(
                u"No se ha encontrado una campaña activa.\nPor favor compruebe que exista una campaña \nabierta.",
                "No existe campaña activa!")

    def configurar_grilla(self, tam):
        self.frame.grilla.SetSelectionMode(wx.grid.Grid.SelectRows)
        self.frame.grilla.AppendRows(tam)
        presentador = wx.grid.GridCellAutoWrapStringRenderer
        for i in range(tam):
            self.frame.grilla.SetRowSize(i, 25)
            self.frame.grilla.SetCellRenderer(i, 2, presentador())

    def cargarGrilla(self, listado):
        self.configurar_grilla(len(listado))
        for i in range(len(listado)):
            self.frame.grilla.SetCellValue(i, 0, str(listado[i]['codigo']))
            self.frame.grilla.SetCellValue(i, 1, str(listado[i]['nombre']))
            self.frame.grilla.SetCellValue(i, 2, str(listado[i]['domicilio']))

    def limpiar_grilla(self):
        for i in range(self.frame.grilla.GetNumberRows()):
            self.frame.grilla.DeleteRows(0, 1)

    def refrescar_grilla(self):
        self.limpiar_grilla()
        self.listadoCampanias = self.mdlArt.read_for_name()
        if self.listadoCampanias != ():
            self.frame.tc_dato_busqueda.SetBackgroundColour(
                wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
            self.frame.tc_dato_busqueda.SetFocus()
            self.frame.tc_dato_busqueda.Refresh()
            self.cargarGrilla(self.listadoCampanias)
        else:
            self.frame.tc_dato_busqueda.SetBackgroundColour("pink")
            self.frame.tc_dato_busqueda.SetFocus()
            self.frame.tc_dato_busqueda.Refresh()
            self.frame.btn_conrinuar.Enable(False)

    def f_seleccion_fila(self, event):
        fila = event.GetRow()
        try:
            self.mdlArt.cli_codigo = self.frame.grilla.GetCellValue(fila, 0)
            self.datosCli = self.mdlArt.read()
            self.frame.btn_continuar.Enable(True)
        except:
            pass
        event.Skip()
Exemple #11
0
class ControladorPrincipal:
    mdlCamp = ModeloCampanias()
    mdlArt = ModeloArticulos()

    def __init__(self, usuario):
        self.usuario = usuario

    def run(self):
        self.frame = FramePrincipal(None)

        loc = wx.IconLocation(r'icono.ico')
        self.frame.SetIcon(wx.IconFromLocation(loc))

        self.panelUno = PanelUno(self.frame.notebook)
        self.panelDos = PanelDos(self.frame.notebook)

        self.capturarEventos()

        self.frame.notebook.AddPage(self.panelUno, u"Campaña actual", False)
        self.frame.notebook.AddPage(self.panelDos, u"Menú", False)

        self.cargarDatos()

        self.frame.Show()

    def capturarEventos(self):
        """Eventos de Frame"""
        self.frame.btn_salir.Bind(wx.EVT_BUTTON, self.Salir)
        """Eventos de Panel Uno"""
        self.panelUno.btn_buscar.Bind(wx.EVT_BUTTON, self.Buscar)
        self.panelUno.btn_crear_campania.Bind(wx.EVT_BUTTON,
                                              self.CrearCampania)
        self.panelUno.btn_cerrar_campania.Bind(wx.EVT_BUTTON,
                                               self.CerrarCampania)
        self.panelUno.btn_modificar_campania.Bind(wx.EVT_BUTTON,
                                                  self.ModificarCampania)
        self.panelUno.btn_listados.Bind(wx.EVT_BUTTON, self.Listados)
        self.panelUno.btn_repartos.Bind(wx.EVT_BUTTON, self.Repartos)
        self.panelUno.btn_gastos.Bind(wx.EVT_BUTTON, self.Gastos)
        self.panelUno.btn_depositos.Bind(wx.EVT_BUTTON, self.Envios)
        self.panelUno.tc_codigo.Bind(wx.EVT_TEXT_ENTER, self.Buscar)
        self.panelUno.tc_codigo.Bind(wx.EVT_TEXT, self.AutoCompletar)
        self.panelUno.btn_resultados_campania.Bind(wx.EVT_BUTTON,
                                                   self.ResultCampania)
        """Eventos de Panel Dos"""
        self.panelDos.btn_campanias.Bind(wx.EVT_BUTTON, self.Campanias)
        self.panelDos.btn_usuarios.Bind(wx.EVT_BUTTON, self.Usuarios)
        self.panelDos.btn_clientes.Bind(wx.EVT_BUTTON, self.Clientes)
        self.panelDos.btn_historial.Bind(wx.EVT_BUTTON, self.Historial)
        self.panelDos.btn_rutas.Bind(wx.EVT_BUTTON, self.Rutas)

    """Eventos de Frame"""

    def Salir(self, event):
        self.frame.Destroy()

    """Eventos de Panel Uno"""

    def Buscar(self, event):
        self.mdlArt.cam_anio = self.aCamp['anio']
        self.mdlArt.cam_num = self.aCamp['numero']
        cod = self.panelUno.tc_codigo.GetValue()
        self.mdlArt.cli_codigo = cod
        if self.mdlArt.exist():
            self.panelUno.tc_codigo.SetBackgroundColour(
                wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
            self.panelUno.tc_codigo.SetFocus()
            self.panelUno.tc_codigo.Refresh()
            info = ControladorInformacion(self.frame, self.aCamp, cod)
            info.run()
            self.panelUno.tc_codigo.SelectAll()
        else:
            self.panelUno.tc_codigo.SetBackgroundColour("pink")
            self.panelUno.tc_codigo.SetFocus()
            self.panelUno.tc_codigo.Refresh()
        event.Skip()

    def AutoCompletar(self, event):
        prefijo = self.panelUno.tc_codigo.GetValue()
        if len(prefijo) == 4:
            sufijo = prefijo[-1]
            if sufijo != "/":
                prefijo = prefijo[:3] + "/"
                prefijo += sufijo
                self.panelUno.tc_codigo.SetValue(prefijo)
        self.panelUno.tc_codigo.SetInsertionPoint(len(prefijo))
        event.Skip()

    def CrearCampania(self, event):
        crearCamp = ControladorCrearCampania(self.frame, self.usuario)
        crearCamp.run()
        self.cargarDatos()

    def ModificarCampania(self, event):
        modifCampania = ControladorModificarCampania(self.frame, self.aCamp)
        modifCampania.run()
        self.cargarDatos()

    def CerrarCampania(self, event):
        cerrarCamp = ControladorCerrarCampania(self.frame, self.aCamp)
        cerrarCamp.run()
        self.cargarDatos()

    def Listados(self, event):
        listados = ControladorListados(self.frame, self.aCamp)
        listados.run()

    def Repartos(self, event):
        repartos = ControladorRepartos(self.frame, self.aCamp)
        repartos.run()

    def Gastos(self, event):
        gastos = ControladorGastosVarios(self.frame, self.aCamp)
        gastos.run()

    def Envios(self, event):
        envios = ControladorDepositos(self.frame, self.aCamp)
        envios.run()

    def ResultCampania(self, event):
        resCamp = ControladorResultadoCampania(self.frame, self.aCamp)
        resCamp.run()

    def cargarDatos(self):
        if self.mdlCamp.get_active_campaign() != {}:

            self.panelUno.btn_crear_campania.Enable(False)
            self.panelUno.tc_codigo.SetFocus()

            self.aCamp = self.mdlCamp.get_active_campaign()
            texto = str(self.aCamp['numero']) + '-' + str(self.aCamp['anio'])
            self.panelUno.st_campania.SetLabel(texto)

            self.panelUno.tc_codigo.Enable(True)
            self.panelUno.btn_listados.Enable(True)
            self.panelUno.btn_modificar_campania.Enable(True)
            self.panelUno.btn_cerrar_campania.Enable(True)
            self.panelUno.btn_buscar.Enable(True)
            self.panelUno.btn_resultados_campania.Enable(True)
            self.panelUno.btn_depositos.Enable(True)
            self.panelUno.btn_gastos.Enable(True)
            self.panelUno.btn_repartos.Enable(True)
        else:
            self.panelUno.tc_codigo.Clear()
            self.panelUno.tc_codigo.SetBackgroundColour(
                wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
            self.panelUno.tc_codigo.Enable(False)
            self.panelUno.btn_crear_campania.Enable(True)
            self.panelUno.btn_crear_campania.SetFocus()
            self.panelUno.st_campania.SetLabel(u'No hay campañas abiertas')
            self.panelUno.btn_listados.Enable(False)
            self.panelUno.btn_modificar_campania.Enable(False)
            self.panelUno.btn_cerrar_campania.Enable(False)
            self.panelUno.btn_buscar.Enable(False)
            self.panelUno.btn_resultados_campania.Enable(False)
            self.panelUno.btn_depositos.Enable(False)
            self.panelUno.btn_gastos.Enable(False)
            self.panelUno.btn_repartos.Enable(False)

    """Eventos de Panel Dos"""

    def Clientes(self, event):
        clientes = ControladorClientes(self.frame)
        clientes.run()

    def Campanias(self, event):
        campanias = ControladorCampanias(self.frame, self.usuario)
        campanias.run()

    def Usuarios(self, event):
        usuarios = ControladorUsuarios(self.frame)
        usuarios.run()

    def Historial(self, event):
        hist = ControladorHistorial(self.frame)
        hist.run()

    def Rutas(self, event):
        ruts = ControladorRutas(self.frame)
        ruts.run()
class ControladorPrincipal:
	mdlCaj = ModeloCajas()
	mdlMov = ModeloMovimientos()
	mdlMovCli = ModeloMovimientoClientes()
	mdlCamp = ModeloCampanias()
	
	def __init__(self):
		self.parent = None
		self.selec = {}

	def run(self):
		self.frame = FramePrincipal(self.parent)

		loc = wx.IconLocation(r'icono.ico')
		self.frame.SetIcon(wx.IconFromLocation(loc))
		
		log = ControladorLogin(self.frame, False)
		self.usuario = log.run()
		if self.usuario != {}:
			self.panelUno = PanelUno(self.frame.notebook)
			self.panelDos = PanelDos(self.frame.notebook)

			self.frame.notebook.AddPage(self.panelUno, u"Clientes atendidos", False)
			self.frame.notebook.AddPage(self.panelDos, u"Ingresos/Egresos Varios", False)

			self.capturarEventos()
			self.cargarDatos()
			self.frame.Show()

	def capturarEventos(self):
		self.frame.btn_iniciar.Bind(wx.EVT_BUTTON, self.Iniciar)
		self.frame.btn_cerrar.Bind(wx.EVT_BUTTON, self.Cerrar)
		self.frame.btn_salir.Bind(wx.EVT_BUTTON, self.Salir)

		# Eventos panel uno
		self.panelUno.btn_clientes.Bind(wx.EVT_BUTTON, self.Clientes)
		self.panelUno.btn_modificar.Bind(wx.EVT_BUTTON, self.Modificar)
		self.panelUno.grilla_uno.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.f_seleccion_fila)

		# Eventos panel dos
		self.panelDos.btn_ingresos.Bind(wx.EVT_BUTTON, self.IngresosVarios)
		self.panelDos.btn_egresos.Bind(wx.EVT_BUTTON, self.EgresosVarios)

	def cargarDatos(self):
		self.datosCamp = self.mdlCamp.get_active_campaign()
		if self.datosCamp != {}:
			camp = str(self.datosCamp['numero']) + '-' + str(self.datosCamp['anio'])
			self.frame.st_campania.SetLabel(camp)
		self.datosCaja = self.mdlCaj.get_box_active()
	
		if self.datosCaja != {}:
			self.frame.btn_iniciar.Enable(False)
			camp = str(self.datosCaja['campNum']) + "-" + str(self.datosCaja['campAnio'])
			self.frame.st_campania.SetLabel(camp)
			self.frame.btn_cerrar.Enable(True)
			self.frame.tc_monto_inicial.SetValue(str(self.datosCaja['monto']))
			self.frame.tc_monto_inicial.Enable(True)

			self.mdlMovCli.mcam_anio = self.datosCaja['campAnio']
			self.mdlMovCli.mcam_num = self.datosCaja['campNum']
			self.mdlMovCli.mcaj_numero = self.datosCaja['numero']
			ListadoMovCli = self.mdlMovCli.read_all()
			self.cargar_grilla_uno(ListadoMovCli)

			self.mdlMov.mcam_anio = self.datosCaja['campAnio']
			self.mdlMov.mcam_num = self.datosCaja['campNum']
			self.mdlMov.mcaj_numero = self.datosCaja['numero']

			self.ListadoMov = self.mdlMov.read_all()
			self.cargar_grilla_dos(self.ListadoMov)

			self.panelUno.btn_clientes.Enable(True)
			self.panelDos.btn_ingresos.Enable(True)
			self.panelDos.btn_egresos.Enable(True)
			
			self.refrescar_resultados()

		else:
			self.frame.tc_monto_inicial.Clear()
			self.frame.btn_iniciar.Enable(True)
			self.frame.btn_cerrar.Enable(False)
			self.frame.tc_monto_inicial.Enable(False)
			self.panelUno.btn_clientes.Enable(False)
			self.panelDos.btn_ingresos.Enable(False)
			self.panelDos.btn_egresos.Enable(False)
			self.limpiar_grilla_uno()
			self.limpiar_grilla_dos()
			self.frame.tc_total_ing.Clear()
			self.frame.tc_total_egr.Clear()
			self.frame.tc_totales.Clear()
			
		self.panelUno.btn_modificar.Enable(False)
		


	def configurar_grilla_uno(self, tam):
		self.panelUno.grilla_uno.SetSelectionMode(wx.grid.Grid.SelectRows)
		self.panelUno.grilla_uno.AppendRows(tam)

	def cargar_grilla_uno(self, listado):
		self.configurar_grilla_uno(len(listado))
		for i in range(len(listado)):
			self.panelUno.grilla_uno.SetCellValue(i, 0, str(listado[i][0]))
			self.panelUno.grilla_uno.SetCellValue(i, 1, str(listado[i][1]))
			self.panelUno.grilla_uno.SetCellValue(i, 2, str(listado[i][2]))

			if listado[i][3] == 0:
				self.panelUno.grilla_uno.SetCellValue(i, 3, "No")
			elif listado[i][3] == 1:
				self.panelUno.grilla_uno.SetCellValue(i, 3, "Si")

			if listado[i][4] == 2:
				self.panelUno.grilla_uno.SetCellValue(i, 4, str(listado[i][5]))
			elif listado[i][4] == 3:
				self.panelUno.grilla_uno.SetCellValue(i, 5, str(listado[i][5]))

	def limpiar_grilla_uno(self):
		for i in range(self.panelUno.grilla_uno.GetNumberRows()):
			self.panelUno.grilla_uno.DeleteRows(0, 1)

	def refrescar_grilla_uno(self):
		self.limpiar_grilla_uno()
		self.ListadoMovCli = self.mdlMovCli.read_all()
		self.cargar_grilla_uno(self.ListadoMovCli)

	def configurar_grilla_dos(self, tam):
		self.panelDos.grilla_dos.SetSelectionMode(wx.grid.Grid.SelectRows)
		self.panelDos.grilla_dos.AppendRows(tam)
		presentador = wx.grid.GridCellAutoWrapStringRenderer
		for i in range(tam):
			self.panelDos.grilla_dos.SetRowSize(i, 25)
			self.panelDos.grilla_dos.SetCellRenderer(i, 2, presentador())

	def cargar_grilla_dos(self, listado):
		self.configurar_grilla_dos(len(listado))
		for i in range(len(listado)):
			self.panelDos.grilla_dos.SetCellValue(i, 0, listado[i]['tipo'])
			self.panelDos.grilla_dos.SetCellValue(i, 1, listado[i]['monto'])
			self.panelDos.grilla_dos.SetCellValue(i, 2, listado[i]['comentario'])

	def limpiar_grilla_dos(self):
		for i in range(self.panelDos.grilla_dos.GetNumberRows()):
			self.panelDos.grilla_dos.DeleteRows(0, 1)

	def refrescar_grilla_dos(self):
		self.limpiar_grilla_dos()
		self.cargar_grilla_dos(self.ListadoMov)

	def refrescar_resultados(self):
		ingr = self.mdlMov.totalIngresos() + self.mdlMovCli.totalIngresosClientes()
		egre = self.mdlMov.totalEgresos()
		ttal = ingr - egre
		self.frame.tc_total_ing.SetValue(str(ingr))
		self.frame.tc_total_egr.SetValue(str(egre))
		self.frame.tc_totales.SetValue(str(ttal))


	def Iniciar(self, event):
		if self.datosCamp != {}:
			iniCaja = ControladorIniciarCaja(self.frame, self.datosCamp)
			iniCaja.run()
			self.cargarDatos()
		else:
			wx.MessageBox(u"Para iniciar la caja primero debe existir una campaña activa.", u"No hay campaña activa!")


	def Cerrar(self, event):
		cerCaja = ControladorCerrarCaja(self.frame, self.datosCaja)
		cerCaja.run()
		self.cargarDatos()

	def Clientes(self, event):
		cli = ControladorClientes(self, self.datosCaja)
		cli.run()
		self.panelUno.btn_modificar.Enable(False)

	def Modificar(self, event):
		log = ControladorLogin(self.frame, True)
		usu = log.run()
		if usu != {}:
			modMov = ControladorModificarMovimiento(self.frame, self.selec)
			modMov.run()
			self.panelUno.btn_modificar.Enable(False)
			self.selec = {}
			self.refrescar_resultados()
			self.refrescar_grilla_uno()
			self.panelUno.btn_modificar.Enable(False)
		

	def f_seleccion_fila(self, event):
		fila = event.GetRow()
		try:
			self.selec['anio'] = self.datosCaja['campAnio']
			self.selec['num'] = self.datosCaja['campNum']
			self.selec['cnum'] = self.datosCaja['numero']
			self.selec['codigo'] = self.panelUno.grilla_uno.GetCellValue(fila, 0)
			self.panelUno.btn_modificar.Enable(True) 
		except:
			pass
		event.Skip()

	def IngresosVarios(self, event):
		ingVar = ControladorCajaIngresosVarios(self.frame, self.datosCaja)
		ingVar.run()
		self.ListadoMov = self.mdlMov.read_all()
		self.refrescar_grilla_dos()
		self.refrescar_resultados()

	def EgresosVarios(self, event):
		egrVar = ControladorCajaEgresosVarios(self.frame, self.datosCaja)
		egrVar.run()
		self.ListadoMov = self.mdlMov.read_all()
		self.refrescar_grilla_dos()
		self.refrescar_resultados()

	def Salir(self, event):
		self.frame.Destroy()
Exemple #13
0
class ControladorAgregarListado:
    mdlXLCod = ModeloXLCodigos()
    mdlList = ModeloListados()
    mdlArt = ModeloArticulos()
    mdlCli = ModeloClientes()
    mdlCam = ModeloCampanias()

    def __init__(self, parent, aCamp):
        self.parent = parent
        self.aCamp = aCamp

    def run(self):
        self.frame = FrameAgregarListado(self.parent)
        self.cargarDatos()
        self.capturarEventos()
        self.cargarValidadores()
        resp = self.frame.ShowModal()
        if resp == wx.ID_OK:
            self.Agregar()
            #wx.MessageBox("El listado a sido cargado con exito", "Enhorabuena")
        self.frame.Destroy()

    def capturarEventos(self):
        self.frame.btn_buscar.Bind(wx.EVT_BUTTON, self.Buscar)

    def cargarDatos(self):
        t = str(self.aCamp['anio']) + '-' + str(self.aCamp['numero'])
        self.frame.tc_campania.SetValue(t)
        self.frame.tc_fecha.SetValue(time.strftime("%d-%m-%Y"))
        self.mdlList.cam_anio = self.aCamp['anio']
        self.mdlList.cam_num = self.aCamp['numero']
        self.frame.tc_num_listado.SetValue(str(self.mdlList.count_list() + 1))

    def cargarValidadores(self):
        self.frame.tc_archivo.SetValidator(ValidarList())

    def Buscar(self, event):
        wildcard = "Archivos de Excel (*.xls)|*.xls"

        dialog = wx.FileDialog(self.frame, "Elegir archivo",
                               "C:\Users\leonel\desktop", "", wildcard,
                               wx.OPEN)
        if dialog.ShowModal() == wx.ID_OK:
            self.mdlXLCod.dir = dialog.GetPath()
            self.frame.tc_archivo.SetValue(dialog.GetFilename())

            if self.mdlXLCod.traerLibro():
                self.listadoCodigos = self.mdlXLCod.obtenerCodigos()
                self.frame.tc_archivo.SetBackgroundColour(
                    wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
                self.frame.tc_archivo.Refresh()
            else:
                wx.MessageBox(
                    "Se produgo un error al intentar leer el archivo Excel!",
                    "Ups!")
                self.frame.tc_archivo.SetBackgroundColour("pink")
                self.frame.tc_archivo.SetFocus()

    def Agregar(self):

        self.mdlList.fecha = time.strftime("%Y-%m-%d")
        self.mdlList.numero = self.frame.tc_num_listado.GetValue()
        self.mdlList.comentario = self.frame.tc_comentarios.GetValue()
        self.mdlList.create()  # Agregar un nuevo listado.

        progresoMax = len(self.listadoCodigos)
        dialog = wx.ProgressDialog("Progreso de Carga",
                                   "Cargando listado",
                                   progresoMax,
                                   style=wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME
                                   | wx.PD_REMAINING_TIME)
        band = True
        cont = 0
        nuevosCodigos = 0
        self.mdlArt.cam_anio = self.aCamp['anio']
        self.mdlArt.cam_num = self.aCamp['numero']
        self.mdlArt.lis_numero = self.mdlList.numero

        for datos in self.listadoCodigos:
            self.mdlArt.cli_codigo = datos['codigo']
            if not self.mdlArt.exist():  # el codigo existe en la campania?
                self.mdlCli.codigo = datos['codigo']
                if not self.mdlCli.exist():  # el codigo de cliente existe?
                    nuevosCodigos += 1
                    self.mdlCli.create_short()

                # Actualizamos la localidad del cliente
                self.mdlCli.localidad = datos['localidad']
                self.mdlCli.new_update()

                self.mdlArt.cli_codigo = datos['codigo']
                self.mdlArt.deuda = float(datos['deuda'])
                self.mdlArt.camp = datos['campania']
                self.mdlArt.create()  # agregamos un articulo nuevo
            if band and cont < progresoMax:
                cont += 1
                band = dialog.Update(cont)
        dialog.Destroy()