Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reportes #45

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions sec2/apps/reportes/templates/reporte_afiliados_por_estado.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{% extends 'reporte_appAfiliados.html' %}

{% block grafico %}

<div class="col">
<label>Seleccione al empleador:</label>
<div class="form-group">
<select name="enc_cuit" id="enc_cuit">
<option value="0"> --------------- </option>
{% for empleador in empleadores %}
<option value="{{ empleador.cuit_empleador }}">{{ empleador.cuit_empleador }} {{ empleador.razon_social }}</option>
{% endfor %}
</select>
</div>


</div>
<figure class="highcharts-figure">
<div id="container"></div>
<p class="highcharts-description">

</p>
</figure>
<div>
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<div id="container"></div>
</div>
</div>
</div>
</div>
<script>
var data_pendiene = {{ graph_afiliados.data_pendiente_list|safe }};
var data_activo = {{ graph_afiliados.data_activo_list|safe }};
var data_inactivo = {{ graph_afiliados.data_inactivo_list|safe }};
var data_baja = {{ graph_afiliados.data_baja_list|safe }};
var data_moroso = {{ graph_afiliados.data_moroso_list|safe }};
var titulo = {{ graph_afiliados.titulo }};
var categories = {{ graph_afiliados.categories|safe }};
var jq = $.noConflict();

jq(document).ready(function() {
jq('#enc_cuit').change(function() {
var cuit_empleador = $(this).val();
var url = 'afiliados_por_estado/';
jq.ajax({

url: url,
data: {'cuit_empleador': cuit_empleador},
dataType: 'json',
success: function(data) {
jq('#container').empty();
graficar(data);


}
});
});
});

function graficar(data){
Highcharts.chart('container', {
chart: {
type: 'pie'
},
title: {
text: "{{ graph_afiliados.titulo }}"
},
tooltip: {
valueSuffix: ''
},
plotOptions: {
series: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: [{
enabled: true,
distance: 20
}, {
enabled: true,
distance: -40,
format: '',
style: {
fontSize: '1.2em',
textOutline: 'none',
opacity: 0.7
},
filter: {
operator: '>',
property: 'cantidad',
value: 10
}
}]
}
},
series: [
{
name: 'Cantidad',
colorByPoint: true,
data: [
{
name: 'Pendientes',
y: data_pendiene
},
{
name: 'Activos',
sliced: true,
selected: true,
y: data_activo
},
{
name: 'Inactivos',
y: data_inactivo
},
{
name: 'Dados de baja',
y: data_baja
},
{
name: 'Morosos',
y: data_moroso
}
]
}
]
});
}

</script>









{% endblock %}
1 change: 1 addition & 0 deletions sec2/apps/reportes/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
56 changes: 55 additions & 1 deletion sec2/apps/reportes/views.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -57,4 +61,54 @@ def get_context_data(self, **kwargs):
'categories': categories,
'y_axis_title': 'Total de alquileres', # Y-axis title
}
return context
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