|
|
@ -5,6 +5,7 @@ from django.http import JsonResponse |
|
|
# Create your views here. |
|
|
# Create your views here. |
|
|
from .models import Cuenta, Apunte, Tipo |
|
|
from .models import Cuenta, Apunte, Tipo |
|
|
from .forms import CuentaForm, ApunteForm |
|
|
from .forms import CuentaForm, ApunteForm |
|
|
|
|
|
import json |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required |
|
|
@login_required |
|
|
@ -130,23 +131,43 @@ def eliminar_apunte(request, apunte_id): |
|
|
return redirect('lista_apuntes') |
|
|
return redirect('lista_apuntes') |
|
|
|
|
|
|
|
|
@login_required |
|
|
@login_required |
|
|
def datos_grafico_bancos(request): |
|
|
|
|
|
datos = Cuenta.objects.filter(tipo=Tipo.objects.get(tipo="Banco")) | Cuenta.objects.filter(tipo=Tipo.objects.get(tipo="Ahorro")) |
|
|
|
|
|
|
|
|
def datos_por_tipo_cuenta(request): |
|
|
|
|
|
debancos = Cuenta.objects.filter(tipo=Tipo.objects.get(tipo="Banco")) |
|
|
|
|
|
|
|
|
etiquetas = [item.nombre for item in datos] |
|
|
|
|
|
valores = [item.saldo_actual for item in datos] |
|
|
|
|
|
|
|
|
etiquetas = [] |
|
|
|
|
|
bancos = [] |
|
|
|
|
|
ahorro = [] |
|
|
|
|
|
|
|
|
print(etiquetas) |
|
|
|
|
|
|
|
|
for cuenta in debancos: |
|
|
|
|
|
etiqueta = f"{cuenta.nombre}" |
|
|
|
|
|
if etiqueta not in etiquetas: |
|
|
|
|
|
etiquetas.append(etiqueta) |
|
|
|
|
|
|
|
|
datos_grafico_bancos = { |
|
|
|
|
|
'label': 'Bancos', |
|
|
|
|
|
'labels': etiquetas, |
|
|
|
|
|
'values': valores, |
|
|
|
|
|
|
|
|
bancos.append(float(cuenta.saldo_actual)) |
|
|
|
|
|
ahorro.append(0) |
|
|
|
|
|
|
|
|
'chart_type': 'bar' # any chart type line, bar, ects |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
print("Etiqueta: ", etiquetas, " --- ", bancos) |
|
|
|
|
|
|
|
|
return JsonResponse(datos_grafico_bancos) |
|
|
|
|
|
|
|
|
|
|
|
def grafico_bancos_view(request): |
|
|
|
|
|
return render(request, 'apuntes/grafico_bancos.html') |
|
|
|
|
|
|
|
|
deahorro = Cuenta.objects.filter(tipo=Tipo.objects.get(tipo="Ahorro")) |
|
|
|
|
|
|
|
|
|
|
|
for cuenta in deahorro: |
|
|
|
|
|
etiqueta = f"{cuenta.nombre}" |
|
|
|
|
|
if etiqueta not in etiquetas: |
|
|
|
|
|
etiquetas.append(etiqueta) |
|
|
|
|
|
|
|
|
|
|
|
ahorro.append(float(cuenta.saldo_actual)) |
|
|
|
|
|
bancos.append(0) |
|
|
|
|
|
|
|
|
|
|
|
print("Etiqueta: ", etiquetas, " --- ", ahorro) |
|
|
|
|
|
|
|
|
|
|
|
context = { |
|
|
|
|
|
'bancos': bancos, |
|
|
|
|
|
'etiquetas_json': json.dumps(etiquetas), |
|
|
|
|
|
'bancos_datos_json': json.dumps(bancos), |
|
|
|
|
|
'ahorro_datos_json': json.dumps(ahorro), |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
print("Context: ", context['etiquetas_json']) |
|
|
|
|
|
|
|
|
|
|
|
return render(request, 'apuntes/nuevo_grafico.html', context) |