diff --git a/sec2/apps/reportes/templates/reporte_afiliados_por_estado.html b/sec2/apps/reportes/templates/reporte_afiliados_por_estado.html
new file mode 100644
index 00000000..a4b71fcd
--- /dev/null
+++ b/sec2/apps/reportes/templates/reporte_afiliados_por_estado.html
@@ -0,0 +1,140 @@
+{% extends 'reporte_appAfiliados.html' %}
+
+{% block grafico %}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/sec2/apps/reportes/urls.py b/sec2/apps/reportes/urls.py
index dca545ef..f8748181 100644
--- a/sec2/apps/reportes/urls.py
+++ b/sec2/apps/reportes/urls.py
@@ -7,4 +7,5 @@
urlpatterns = [
path('reportes/alquileres_por_mes',reportesView.as_view(), name="alquileres_por_mes"),
+ path('reportes/afiliados_por_estado',ReporteAfiliadoViews.as_view(), name="afiliados_por_estado"),
]
diff --git a/sec2/apps/reportes/views.py b/sec2/apps/reportes/views.py
index bc3bf844..98c598fd 100644
--- a/sec2/apps/reportes/views.py
+++ b/sec2/apps/reportes/views.py
@@ -1,10 +1,14 @@
from django.shortcuts import render
from apps.alquileres.models import Alquiler
+from apps.afiliados.models import Afiliado
+
from django.views.generic import TemplateView
from datetime import datetime
from collections import Counter
from django.db.models import Count
+from django.http import JsonResponse
+
class reportesView(TemplateView):
template_name = 'reporte_alquileres_por_mes.html'
@@ -57,4 +61,54 @@ def get_context_data(self, **kwargs):
'categories': categories,
'y_axis_title': 'Total de alquileres', # Y-axis title
}
- return context
\ No newline at end of file
+ return context
+
+
+class ReporteAfiliadoViews(TemplateView):
+ template_name = 'reporte_afiliados_por_estado.html'
+
+ def get_graph_afiliados(self):
+
+ data_activo = Counter()
+ data_inactivo = Counter()
+ data_pendiente = Counter()
+ data_baja = Counter()
+ data_moroso = Counter()
+
+ afiliados_por_estado = Afiliado.objects.all()
+
+ for afiliado in afiliados_por_estado:
+ estado = afiliado.estado
+ if afiliado.estado == 1: # Pendiente
+ data_pendiente[estado] += 1
+ elif afiliado.estado == 2: # Activo
+ data_activo[estado] += 1
+ elif afiliado.estado == 3: # Inactivo
+ data_inactivo[estado] += 1
+ elif afiliado.estado == 4: # Dado de baja
+ data_baja[estado] += 1
+ elif afiliado.estado == 5: # Moroso
+ data_moroso[estado] += 1
+
+ categories = ['Pendiente','Activo','Inactivo','Dado de baja','Moroso']
+
+ return data_pendiente, data_activo, data_inactivo, data_baja, data_moroso, categories
+
+ def get_context_data(self, **kwargs):
+ context = super().get_context_data(**kwargs)
+ context['titulo'] = 'Reportes de afiliados'
+
+ data_activo_list, data_inactivo_list, data_pendiente_list, data_baja_list, data_moroso_list, categories = self.get_graph_afiliados()
+
+ context['graph_afiliados'] = {
+ 'data_activo_list': data_activo_list,
+ 'data_inactivo_list': data_inactivo_list,
+ 'data_pendiente_list': data_pendiente_list,
+ 'data_baja_list': data_baja_list,
+ 'data_moroso_list': data_moroso_list,
+ 'categories': categories,
+ 'titulo': 'Afiliados por estado',
+ }
+
+ return context
+
\ No newline at end of file