Exemple #1
0
def report(request):
    parent_templates = Template.get_parents()
    data = []
    totals = []
    years = []
    grand_total = 0

    if request.GET:
        form = ReportForm(request.GET)
    else:
        form = ReportForm()

    if form.is_valid():
        data = form.cleaned_data
        report_type = data['report_type']
        status = data['status']
        year = data['year']

        if report_type == "monthly":
            data, totals = reportutils.get_total_by_month(
                parent_templates, status, year)
            grand_total = sum(totals)
        elif report_type == "yearly":
            data, totals = reportutils.get_total_by_year(
                parent_templates, status)
            grand_total = sum(totals)
            years = reportutils.get_years()

    else:
        report_type = ''

    return render(
        request, "documents/report.html", {
            'form': form,
            'report_type': report_type,
            'parents': parent_templates,
            'data': data,
            'years': years,
            'totals': totals,
            'grand_total': grand_total
        })