diff --git a/sigi/apps/convenios/reports.py b/sigi/apps/convenios/reports.py index 40cb180..b2625a1 100644 --- a/sigi/apps/convenios/reports.py +++ b/sigi/apps/convenios/reports.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from geraldo import Report, ReportBand, ObjectValue, DetailBand, Label +from geraldo import Report, ReportBand, ObjectValue, DetailBand, Label, FIELD_ACTION_SUM, FIELD_ACTION_COUNT from reportlab.lib.units import cm class CasasAderidasReport(object): pass @@ -40,3 +40,47 @@ class ConvenioReport(Report): ObjectValue(attribute_name='data_adesao', left=10*cm) ] border = {'bottom': True} + +class ConvenioReportRegiao(Report): + title = u'Relatório dos Convênios por Região' + author = u'Interlegis' + class band_page_header(ReportBand): + elements = [ + Label( + text="Região", left=0*cm + ), + Label( + text="Quantidade Casas", left=3*cm, + ), + Label( + text="Quantidade Casas Conveniadas", left=6*cm + ), + Label( + text="Porcentagem Casas Conveniadas", left=15*cm + ), + ] + class band_detail(DetailBand): + height = 0.5*cm + elements=[ + ObjectValue(attribute_name='regiao', left=0*cm, ), + ObjectValue(attribute_name='casas', left=3*cm,), + ObjectValue(attribute_name='casas_conveniadas', left=6*cm), + ObjectValue(attribute_name='porc_casas_conveniadas', left=15*cm), + ] + border = {'bottom': True} + class band_summary(ReportBand): + elements = [ + Label(text="Total", top=0.1*cm, left=0), + ObjectValue(attribute_name='casas', action=FIELD_ACTION_SUM, left=3*cm, top=0.1*cm), + ObjectValue(attribute_name='casas_conveniadas', left=6*cm, action=FIELD_ACTION_SUM), + ] + borders = {'top':True} + child_bands = [ + ReportBand( + height = 0.6*cm, + elements = [ + Label(text="Total",), + ObjectValue(attribute_name='casas', action=FIELD_ACTION_COUNT,) + ] + ), + ] diff --git a/sigi/apps/convenios/views.py b/sigi/apps/convenios/views.py index 352315b..42c936e 100644 --- a/sigi/apps/convenios/views.py +++ b/sigi/apps/convenios/views.py @@ -1,7 +1,9 @@ from django.http import HttpResponse, HttpResponseRedirect from geraldo.generators import PDFGenerator from sigi.apps.convenios.models import Convenio -from sigi.apps.convenios.reports import ConvenioReport +from sigi.apps.convenios.reports import ConvenioReport, ConvenioReportRegiao +from sigi.apps.casas.models import CasaLegislativa + def report(request, id=None): qs = Convenio.objects.all() @@ -25,3 +27,35 @@ def report(request, id=None): report = ConvenioReport(queryset=qs) report.generate_by(PDFGenerator, filename=response) return response + +class Relatorios(object): + def __init__(self, regiao, casas, casas_conveniadas): + self.regiao = regiao + self.casas = casas + self.casas_conveniadas = casas_conveniadas + if(casas_conveniadas!=0): + self.porc_casas_conveniadas = float(casas_conveniadas)/float(casas)*100 + else: + self.porc_casas_conveniadas = 0 + +def reportRegiao(request): + REGIAO_CHOICES = ( + ('SL', 'Sul'), + ('SD', 'Sudeste'), + ('CO', 'Centro-Oeste'), + ('NE', 'Nordeste'), + ('NO', 'Norte'), + ) + relatorio = [] + for casa in REGIAO_CHOICES: + casasSD = CasaLegislativa.objects.filter(municipio__uf__regiao=casa[0]) + casasConvSD = CasaLegislativa.objects.filter(convenio__casa_legislativa__municipio__uf__regiao=casa[0]).distinct() + + relatorio.append(Relatorios(casa[1], casasSD.count(), + casasConvSD.count())) + + response = HttpResponse(mimetype='application/pdf') + relatorio = ConvenioReportRegiao(queryset=relatorio) + relatorio.generate_by(PDFGenerator, filename=response) + return response +