Ejemplo n.º 1
0
    def draw_plot(self):
        def limpiar_eur(x):
            if type(x) == float:
                return x
            else:
                return float(x.replace(',', '.'))

        query = sqls.select_fact
        ss = Services()
        data = ss.get_query(query)
        if not data.empty:
            data['fecha'] = pd.to_datetime(data['fecha'], format="%d/%m/%Y")
            data['mes'] = data['fecha'].apply(lambda x: x.month)
            data['anio'] = data['fecha'].apply(lambda x: x.year)
            data['eur'] = data['eur'].apply(lambda x: limpiar_eur(x))
            data.loc[data.tipo == 'Gasto', 'eur2'] = data['eur'] * -1
            data.loc[data.tipo != 'Gasto', 'eur2'] = data['eur']
            tablita = data[data['tipo'] != 'Traspaso'].pivot_table(
                'eur2', index=['anio', 'mes'], columns='tipo', aggfunc='sum')
            tablita.index = [
                pd.datetime(anio, mes, 1).date().strftime('%m/%y')
                for (anio, mes) in tablita.index
            ]
            df2 = pd.DataFrame(tablita.to_records())
            df2['ahorro_mensual'] = df2['Gasto'] + df2['Ingreso']
            df2['k'] = df2['ahorro_mensual'].cumsum()
            df2['index'] = pd.to_datetime(df2['index'], format="%m/%y")
            df2.index = [
                pd.to_datetime(i).date().strftime('%m/%y')
                for i in df2['index']
            ]
            df2[['Gasto', 'Ingreso']].plot.bar(color=['red', 'green'])
            self.subploti.plot(df2['index'], df2['Gasto'] * -1)
            self.subploti.plot(df2['index'], df2['Ingreso'])
            self.subploti.plot(df2['index'], df2['k'])
Ejemplo n.º 2
0
 def getLista(self):
     query = """SELECT cuenta FROM
               (SELECT  cuenta ,count(cuenta) as  freq
               FROM facts_table
               GROUP BY cuenta
               order by count(cuenta) desc) as T1"""
     elemntos = Services().run_query2(query)
     lista = [elemento[0] for elemento in elemntos]
     self.cuenta["values"] = lista
Ejemplo n.º 3
0
    def getMovimiento(self, tipo):
        # Limpia la tabla
        tipo = str(tipo)
        registrosAntiguos = self.tree.get_children()
        for registro in registrosAntiguos:
            self.tree.delete(registro)
        query = sqls.select_pruebas.format(tipo)

        movimientos = Services().run_query2(query)
        for movimiento in movimientos:
            self.tree.insert('', 0, text=movimiento[0], values=movimiento[0:])
Ejemplo n.º 4
0
 def editar_registro(self, id, newFecha, newCuenta, newCategoria,
                     newSubCategoria, newdescripcion, newEur, newtipo,
                     newNota, tipo):
     query = 'UPDATE pruebas SET Fecha =?, Cuenta =?,Categoria =?,Subcategoria =?,Descripcion =?,Total =?,' \
             'TipoMov =?,Notas =?  Where id=?'
     parameters = (newFecha, newCuenta, newCategoria, newSubCategoria,
                   newdescripcion, newEur, newtipo, newNota, id)
     Services().run_query2(query, parameters)
     self.edit_wind.destroy()
     self.message['text'] = 'El Registro nº{} se ha actualizado'.format(id)
     self.message.configure(foreground='red')
     self.getMovimiento(tipo)
Ejemplo n.º 5
0
    def g_borrar(self, tipo):
        self.message['text'] = ''  # Vaciamos el texto del mensaje
        try:
            self.tree.item(self.tree.selection())['values'][0]

        except IndexError:
            self.message['text'] = 'Selecciona un movimiento simpló!!'
            return
        self.message['text'] = ''
        id = self.tree.item(self.tree.selection())['text']
        query = 'DELETE FROM pruebas WHERE id=?'
        Services().run_query2(query, (id, ))
        self.message['text'] = 'yiaaass!!! La armaste'
        self.getMovimiento(tipo)
Ejemplo n.º 6
0
    def insertarMovimiento(self, tipo):
        if self.validacion():
            query = "INSERT INTO pruebas VALUES(NULL,?,?,?,?,?,?,?,?,?)"
            parameters = (self.fecha.get(), self.cuenta.get(),
                          self.categoria.get(), self.subcategoria.get(),
                          self.descripcion.get(), self.eur.get(),
                          self.tipo.get(), self.nota.get(), yet2)
            Services().run_query2(query, parameters)
            self.getMovimiento(tipo)
            self.eur.delete(0, 'end')
            self.message['text'] = 'Datos Salvados'
            self.message.configure(foreground='green')

        else:
            self.message['text'] = 'Algo hay mal, mira a ver!'
            self.message.configure(foreground='red')
Ejemplo n.º 7
0
 def getCategoria(self, tipo):
     query = 'SELECT distinct categoria from facts_table Where tipo="' + tipo + '"'
     elemntos = Services().run_query2(query)
     lista = [elemento[0] for elemento in elemntos]
     self.categoria["values"] = lista
Ejemplo n.º 8
0
 def getCuenta(self):
     query = sqls.lista_cuentas_ordenadas
     elemntos = Services().run_query2(query)
     lista = [elemento[0] for elemento in elemntos]
     self.cuenta["values"] = lista