Exemplo n.º 1
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['title'] = 'Reporte de Services'
     context['entity'] = 'Services'
     context['list_url'] = reverse_lazy('service_report')
     context['form'] = ReportForm()
     return context
Exemplo n.º 2
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['title'] = 'Reporte de Comisiones'
     context['entity'] = 'Reportes'
     context['list_url'] = reverse_lazy('commission_report')
     context['form'] = ReportForm()
     return context
Exemplo n.º 3
0
def results_report(request):
    data = get_module_options(request)
    if request.method == 'GET':
        data['title'] = 'Reporte de Ganancias y Perdidas'
        data['form'] = ReportForm()
        return render(request, 'results_report/result_report_rp.html', data)
    elif request.method == 'POST':
        filter = request.POST['filter']
        month = request.POST['month']
        start_date = request.POST['start_date']
        end_date = request.POST['end_date']
        year = request.POST['year']
        if month == "" and filter == '3':
            filter = '2'
        try:
            data = []
            purchase = Ingress.objects.filter()
            sales = Sales.objects.filter(type=1)
            pedids = Sales.objects.filter(type=2)
            expenses = Expenses.objects.filter()
            salary = Salary.objects.filter()
            if filter == '1':
                purchase = purchase.filter(date_joined__range=[start_date, end_date])
                sales = sales.filter(date_joined__range=[start_date, end_date])
                pedids = pedids.filter(date_joined__range=[start_date, end_date])
                expenses = expenses.filter(date_joined__range=[start_date, end_date])
                salary = salary.filter(date_joined__range=[start_date, end_date])
            elif filter == '2':
                purchase = purchase.filter(date_joined__year=year)
                sales = sales.filter(date_joined__year=year)
                pedids = pedids.filter(date_joined__year=year)
                expenses = expenses.filter(date_joined__year=year)
                salary = salary.filter(year=year)
            elif filter == '3':
                purchase = purchase.filter(date_joined__year=year, date_joined__month=month)
                sales = sales.filter(date_joined__year=year, date_joined__month=month)
                pedids = pedids.filter(date_joined__year=year, date_joined__month=month)
                expenses = expenses.filter(date_joined__year=year, date_joined__month=month)
                salary = salary.filter(year=year, month=month)
            purchase = purchase.aggregate(resp=Coalesce(Sum('total'), 0.00))['resp']
            sales = sales.aggregate(resp=Coalesce(Sum('total'), 0.00))['resp']
            pedids = pedids.aggregate(resp=Coalesce(Sum('total'), 0.00))['resp']
            expenses = expenses.aggregate(resp=Coalesce(Sum('cost'), 0.00))['resp']
            salary = salary.aggregate(resp=Coalesce(Sum('total'), 0.00))['resp']
            utility = sales - expenses - purchase - salary + pedids
            status = 2
            if utility > 0:
                status = 1
            elif utility < 0:
                status = 3
            data.append([format(purchase, '.2f'), format(expenses, '.2f'), format(salary, '.2f'), format(sales, '.2f'),
                         format(pedids, '.2f'), format(utility, '.2f'), status])
        except Exception as e:
            data = {}
            data['error'] = str(e)
            data['resp'] = False
        return HttpResponse(json.dumps(data), content_type='application/json')
    else:
        return HttpResponseRedirect(HOME)
Exemplo n.º 4
0
def cli_prod_report(request):
    data = get_module_options(request)
    if request.method == 'GET':
        data['title'] = 'Reporte de Materiales'
        data['form'] = ReportForm(request.user.bodega_id)
        return render(request, 'cli_prod_report/cli_prod_report_rp.html', data)
    elif request.method == 'POST':
        filter = request.POST['filter']
        month = request.POST['month']
        start_date = request.POST['start_date']
        end_date = request.POST['end_date']
        year = request.POST['year']
        cli = request.POST['cli']
        prod = request.POST['prod']
        data = []
        if month == "" and filter == '3':
            filter = '2'
        try:
            items = Sales.objects.filter(
                type=1, usuario_id__bodega_id=request.user.bodega_id)
            productos = SalesProducts.objects.all()
            if len(prod):
                productos = productos.filter(prod=prod)
            if len(cli):
                items = items.filter(cli_id=cli)
            if filter == '1':
                items = items.filter(date_joined__range=[start_date, end_date])
            elif filter == '2':
                items = items.filter(date_joined__year=year)
            elif filter == '3':
                items = items.filter(date_joined__year=year,
                                     date_joined__month=month)
            sum = 0
            cant = 0
            for i in items:
                for j in productos.filter(sales=i.id):
                    sum += float(j.subtotal_format()) * int(j.cant)
                    cant += j.cant
                    data.append([
                        i.id,
                        i.get_nro(),
                        i.date_joined_format(), i.cli.name, j.prod.name,
                        format(
                            float(j.subtotal_format()) * int(j.cant), '.2f'),
                        j.cant
                    ])
            data.append([
                '-------', '-------', '-------', '-------', '-------',
                format(sum, '.2f'), cant
            ])
        except Exception as e:
            data = {}
            data['error'] = str(e)
            data['resp'] = False
        return HttpResponse(json.dumps(data), content_type='application/json')
    else:
        return HttpResponseRedirect(HOME)
Exemplo n.º 5
0
def sales_report(request):
    data = get_module_options(request)
    if request.method == 'GET':
        data['title'] = 'Reporte de Egresos'
        data['form'] = ReportForm(request.user.bodega_id)
        return render(request, 'sales_report/sales_report_rp.html', data)
    elif request.method == 'POST':
        filter = request.POST['filter']
        month = request.POST['month']
        start_date = request.POST['start_date']
        end_date = request.POST['end_date']
        year = request.POST['year']
        cli = request.POST['cli']
        if month == "" and filter == '3':
            filter = '2'
        try:
            items = Sales.objects.filter(
                type=1, usuario_id__bodega_id=request.user.bodega_id)
            if len(cli):
                items = items.filter(cli_id=cli)
            if filter == '1':
                items = items.filter(date_joined__range=[start_date, end_date])
            elif filter == '2':
                items = items.filter(date_joined__year=year)
            elif filter == '3':
                items = items.filter(date_joined__year=year,
                                     date_joined__month=month)
            subtotal = items.aggregate(
                resp=Coalesce(Sum('subtotal'), 0.00))['resp']
            iva = items.aggregate(resp=Coalesce(Sum('iva'), 0.00))['resp']
            total = items.aggregate(resp=Coalesce(Sum('total'), 0.00))['resp']
            data = [[
                i.id,
                i.get_nro(), i.cli.name,
                i.date_joined_format(),
                i.subtotal_format(),
                i.iva_format(),
                i.total_format()
            ] for i in items]
            data.append([
                '-------', '-------', '-------', '-------',
                format(subtotal, '.2f'),
                format(iva, '.2f'),
                format(total, '.2f')
            ])
        except Exception as e:
            data = {}
            data['error'] = str(e)
            data['resp'] = False
        return HttpResponse(json.dumps(data), content_type='application/json')
    else:
        return HttpResponseRedirect(HOME)
Exemplo n.º 6
0
def salary_report(request):
    data = get_module_options(request)
    if request.method == 'GET':
        data['title'] = 'Reporte de Empleados y Salarios'
        data['form'] = ReportForm(request.user.bodega_id)
        return render(request, 'salary_report/salary_report_rp.html', data)
    elif request.method == 'POST':
        year = request.POST['year']
        month = request.POST['month']
        cont = request.POST['cont']
        data = []
        try:
            items = Salary.objects.filter()
            if month is None or month == "":
                month = "0"
            if len(cont):
                items = items.filter(cont_id=cont)
            if len(year):
                items = items.filter(year=year)
            if len(month) and month != "0":
                items = items.filter(month=month)
            total = items.aggregate(resp=Coalesce(Sum('total'), 0.00))['resp']
            for i in items:
                data.append([
                    i.cont_id, i.cont.pers.names, i.year,
                    i.get_month_display(),
                    i.cont.rmu_format(),
                    format(i.cont.get_day_salary(), '.2f'), i.falts,
                    i.dscto_format(),
                    i.total_format()
                ])
            data.append([
                '-------', '-------', '-------', '-------', '-------',
                '-------', '-------', '-------',
                format(total, '.2f')
            ])
        except Exception as e:
            data = {}
            data['error'] = str(e)
            data['resp'] = False
        return HttpResponse(json.dumps(data), content_type='application/json')
    else:
        return HttpResponseRedirect(HOME)
Exemplo n.º 7
0
def expenses_report(request):
    data = get_module_options(request)
    if request.method == 'GET':
        data['title'] = 'Reporte de Gastos'
        data['form'] = ReportForm()
        return render(request, 'expenses_report/expenses_report_rp.html', data)
    elif request.method == 'POST':
        filter = request.POST['filter']
        month = request.POST['month']
        start_date = request.POST['start_date']
        end_date = request.POST['end_date']
        year = request.POST['year']
        type_expenses = request.POST['type_expenses']
        if month == "" and filter == '3':
            filter = '2'
        try:
            items = Expenses.objects.filter()
            if len(type_expenses):
                items = items.filter(type_id=type_expenses)
            if filter == '1':
                items = items.filter(date_joined__range=[start_date, end_date])
            elif filter == '2':
                items = items.filter(date_joined__year=year)
            elif filter == '3':
                items = items.filter(date_joined__year=year,
                                     date_joined__month=month)
            total = items.aggregate(resp=Coalesce(Sum('cost'), 0.00))['resp']
            data = [[
                i.id, i.type.name, i.details,
                i.date_joined_format(),
                i.cost_format()
            ] for i in items]
            data.append([
                '-------', '-------', '-------', '-------',
                format(total, '.2f')
            ])
        except Exception as e:
            data = {}
            data['error'] = str(e)
            data['resp'] = False
        return HttpResponse(json.dumps(data), content_type='application/json')
    else:
        return HttpResponseRedirect(HOME)
Exemplo n.º 8
0
def orders_report(request):
    data = get_module_options(request)
    if request.method == 'GET':
        data['title'] = 'Reporte de Pedidos'
        data['form'] = ReportForm()
        return render(request, 'orders_report/orders_report_rp.html', data)
    elif request.method == 'POST':
        filter = request.POST['filter']
        month = request.POST['month']
        start_date = request.POST['start_date']
        end_date = request.POST['end_date']
        year = request.POST['year']
        cli = request.POST['cli']
        if month == "" and filter == '3':
            filter = '2'
        try:
            items = Sales.objects.filter(type=2)
            if len(cli):
                items = items.filter(cli_id=cli)
            if filter == '1':
                items = items.filter(date_joined__range=[start_date, end_date])
            elif filter == '2':
                items = items.filter(date_joined__year=year)
            elif filter == '3':
                items = items.filter(date_joined__year=year,
                                     date_joined__month=month)
            data = [[
                i.id,
                i.get_nro(), i.cli.name,
                i.date_joined_format(),
                i.count_products(),
                i.count_ent_products(),
                i.count_prods_rest()
            ] for i in items]
        except Exception as e:
            data = {}
            data['error'] = str(e)
            data['resp'] = False
        return HttpResponse(json.dumps(data), content_type='application/json')
    else:
        return HttpResponseRedirect(HOME)
Exemplo n.º 9
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['title'] = 'Reporte de requeremientos'
     context["form"] = ReportForm()
     return context
Exemplo n.º 10
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['form'] = ReportForm()
     context['title'] = 'Reporte de Citas Médicas'
     return context
Exemplo n.º 11
0
def med_report(request):
    data = get_module_options(request)
    if request.method == 'GET':
        data['title'] = 'Reporte de Medidores & Sellos'
        data['form'] = ReportForm(request.user.bodega_id)
        return render(request, 'med_report/med_report_rp.html', data)
    elif request.method == 'POST':
        filter = request.POST['filter']
        month = request.POST['month']
        start_date = request.POST['start_date']
        end_date = request.POST['end_date']
        year = request.POST['year']
        cli = request.POST['cli']
        type = request.POST['type']
        bod = request.POST['bod']
        data = []
        if month == "" and filter == '3':
            filter = '2'
        try:
            items = InventoryMedidor.objects.filter(
                usuario_id__bodega_id=request.user.bodega_id)
            items1 = InventorySello.objects.filter(
                usuario_id__bodega_id=request.user.bodega_id)
            if len(cli):
                print(cli)
                items = items.filter(cli_id=cli)
                items1 = items1.filter(cli_id=cli)
                print(items)
            if len(bod):
                if bod == '1':
                    items = items.filter(distribuido=True)
                    items1 = items1.filter(distribuido=True)
                elif bod == '2':
                    items = items.filter(distribuido=False)
                    items1 = items1.filter(distribuido=False)
            if filter == '1':
                items = items.filter(date_joined__range=[start_date, end_date])
                items1 = items1.filter(
                    date_joined__range=[start_date, end_date])
            elif filter == '2':
                items = items.filter(date_joined__year=year)
                items1 = items1.filter(date_joined__year=year)
            elif filter == '3':
                items = items.filter(date_joined__year=year,
                                     date_joined__month=month)
                items1 = items1.filter(date_joined__year=year,
                                       date_joined__month=month)
            if not len(type):
                for i in items:
                    data.append([
                        i.id,
                        i.date_joined_format(),
                        '---' if i.cli_id is None else i.cli.name,
                        i.numeracion, i.medtype.name,
                        'ProEnergy' if i.distribuido is True else 'Wagner'
                    ])
                for i in items1:
                    data.append([
                        i.id,
                        i.date_joined_format(),
                        '---' if i.cli_id is None else i.cli.name,
                        i.numeracion, '------',
                        'ProEnergy' if i.distribuido is True else 'Wagner'
                    ])
            elif type == '1':
                for i in items:
                    data.append([
                        i.id,
                        i.date_joined_format(),
                        '---' if i.cli_id is None else i.cli.name,
                        i.numeracion, i.medtype.name,
                        'ProEnergy' if i.distribuido is True else 'Wagner'
                    ])
            elif type == '2':
                for i in items1:
                    data.append([
                        i.id,
                        i.date_joined_format(),
                        '---' if i.cli_id is None else i.cli.name,
                        i.numeracion, '------',
                        'ProEnergy' if i.distribuido is True else 'Wagner'
                    ])
        except Exception as e:

            print('se sale')
            data = {}
            data['error'] = str(e)
            data['resp'] = False
        return HttpResponse(json.dumps(data), content_type='application/json')
    else:
        return HttpResponseRedirect(HOME)
Exemplo n.º 12
0
def ingress_report(request):
    data = get_module_options(request)
    if request.method == 'GET':
        data['title'] = 'Reporte de Ingresos'
        data['form'] = ReportForm(request.user.bodega_id)
        return render(request, 'ingress_report/ingress_report_rp.html', data)
    elif request.method == 'POST':
        filtro = request.POST['filter']
        month = request.POST['month']
        start_date = request.POST['start_date']
        end_date = request.POST['end_date']
        year = request.POST['year']
        provs = request.POST['provs']
        prod = request.POST.getlist("prod[]")
        data = []
        if month == "" and filtro == '3':
            filtro = '2'
        try:
            items = Product.objects.filter(bodega=request.user.bodega_id)
            # items = Ingress.objects.filter(usuario_id__bodega_id=request.user.bodega_id)
            if len(prod):
                for y in prod:
                    items = Product.objects.filter(
                        bodega=request.user.bodega_id)
                    items = items.filter(id=y)
                    if filtro == '1':
                        for i in items:
                            inv = Inventory.objects.filter(
                                prod__id=i.id,
                                ing__date_joined__range=[start_date, end_date])
                            if len(provs):
                                inv = inv.filter(ing__prov_id=provs)
                            cantidad = 0
                            total = 0
                            material = ""
                            for x in inv:
                                cantidad += int(x.cant - x.diferencia)
                                total += float(x.subtotal_format())
                                material = x.prod.name
                                data.append([
                                    x.id, x.ing.prov.name, x.prod.name,
                                    x.ing.date_joined_format(),
                                    x.cant - x.diferencia,
                                    x.subtotal_format(),
                                    i.get_sales()
                                ])
                            if len(inv) > 1:
                                data.append([
                                    '-------', '-------', material, '-------',
                                    cantidad,
                                    format(total, '.2f')
                                ])

                    elif filtro == '2':
                        for i in items:
                            inv = Inventory.objects.filter(
                                prod__id=i.id, ing__date_joined__year=year)
                            if len(provs):
                                inv = inv.filter(ing__prov_id=provs)
                            cantidad = 0
                            total = 0
                            material = ""
                            for x in inv:
                                cantidad += int(x.cant - x.diferencia)
                                total += float(x.subtotal_format())
                                material = x.prod.name
                                data.append([
                                    x.id, x.ing.prov.name, x.prod.name,
                                    x.ing.date_joined_format(),
                                    x.cant - x.diferencia,
                                    x.subtotal_format(),
                                    i.get_sales()
                                ])
                            if len(inv) > 1:
                                data.append([
                                    '-------', '-------', material, '-------',
                                    cantidad,
                                    format(total, '.2f')
                                ])

                    elif filtro == '3':
                        for i in items:
                            inv = Inventory.objects.filter(
                                prod__id=i.id,
                                ing__date_joined__year=year,
                                ing__date_joined__month=month)
                            if len(provs):
                                inv = inv.filter(ing__prov_id=provs)
                            cantidad = 0
                            total = 0
                            material = ""
                            for x in inv:
                                cantidad += int(x.cant - x.diferencia)
                                total += float(x.subtotal_format())
                                material = x.prod.name
                                data.append([
                                    x.id, x.ing.prov.name, x.prod.name,
                                    x.ing.date_joined_format(),
                                    x.cant - x.diferencia,
                                    x.subtotal_format(),
                                    i.get_sales()
                                ])
                            if len(inv) > 1:
                                data.append([
                                    '-------', '-------', material, '-------',
                                    cantidad,
                                    format(total, '.2f')
                                ])

                    else:
                        for i in items:
                            inv = Inventory.objects.filter(prod__id=i.id)
                            if len(provs):
                                inv = inv.filter(ing__prov_id=provs)
                            cantidad = 0
                            total = 0
                            material = ""
                            for x in inv:
                                cantidad += int(x.cant - x.diferencia)
                                total += float(x.subtotal_format())
                                material = x.prod.name
                                data.append([
                                    x.id, x.ing.prov.name, x.prod.name,
                                    x.ing.date_joined_format(),
                                    x.cant - x.diferencia,
                                    x.subtotal_format(),
                                    i.get_sales()
                                ])
                            if len(inv) > 1:
                                data.append([
                                    '-------', '-------', material, '-------',
                                    cantidad,
                                    format(total, '.2f')
                                ])

            else:
                if filtro == '1':
                    for i in items:
                        inv = Inventory.objects.filter(
                            prod__id=i.id,
                            ing__date_joined__range=[start_date, end_date])
                        if len(provs):
                            inv = inv.filter(ing__prov_id=provs)
                        cantidad = 0
                        total = 0
                        material = ""
                        for x in inv:
                            cantidad += int(x.cant - x.diferencia)
                            total += float(x.subtotal_format())
                            material = x.prod.name
                            data.append([
                                x.id, x.ing.prov.name, x.prod.name,
                                x.ing.date_joined_format(),
                                x.cant - x.diferencia,
                                x.subtotal_format(),
                                i.get_sales()
                            ])
                        if len(inv) > 1:
                            data.append([
                                '-------', '-------', material, '-------',
                                cantidad,
                                format(total, '.2f')
                            ])

                elif filtro == '2':
                    for i in items:
                        inv = Inventory.objects.filter(
                            prod__id=i.id, ing__date_joined__year=year)
                        if len(provs):
                            inv = inv.filter(ing__prov_id=provs)
                        cantidad = 0
                        total = 0
                        material = ""
                        for x in inv:
                            cantidad += int(x.cant - x.diferencia)
                            total += float(x.subtotal_format())
                            material = x.prod.name
                            data.append([
                                x.id, x.ing.prov.name, x.prod.name,
                                x.ing.date_joined_format(),
                                x.cant - x.diferencia,
                                x.subtotal_format(),
                                i.get_sales()
                            ])
                        if len(inv) > 1:
                            data.append([
                                '-------', '-------', material, '-------',
                                cantidad,
                                format(total, '.2f')
                            ])

                elif filtro == '3':
                    for i in items:
                        inv = Inventory.objects.filter(
                            prod__id=i.id,
                            ing__date_joined__year=year,
                            ing__date_joined__month=month)
                        if len(provs):
                            inv = inv.filter(ing__prov_id=provs)
                        cantidad = 0
                        total = 0
                        material = ""
                        for x in inv:
                            cantidad += int(x.cant - x.diferencia)
                            total += float(x.subtotal_format())
                            material = x.prod.name
                            data.append([
                                x.id, x.ing.prov.name, x.prod.name,
                                x.ing.date_joined_format(),
                                x.cant - x.diferencia,
                                x.subtotal_format(),
                                i.get_sales()
                            ])
                        if len(inv) > 1:
                            data.append([
                                '-------', '-------', material, '-------',
                                cantidad,
                                format(total, '.2f')
                            ])

                else:
                    for i in items:
                        inv = Inventory.objects.filter(prod__id=i.id)
                        if len(provs):
                            inv = inv.filter(ing__prov_id=provs)
                        cantidad = 0
                        total = 0
                        material = ""
                        for x in inv:
                            cantidad += int(x.cant - x.diferencia)
                            total += float(x.subtotal_format())
                            material = x.prod.name
                            data.append([
                                x.id, x.ing.prov.name, x.prod.name,
                                x.ing.date_joined_format(),
                                x.cant - x.diferencia,
                                x.subtotal_format(),
                                i.get_sales()
                            ])
                        if len(inv) > 1:
                            data.append([
                                '-------', '-------', material, '-------',
                                cantidad,
                                format(total, '.2f')
                            ])
            '''
            if len(provs):
                items = items.filter(prov_id=provs)
            if filter == '1':
                items = items.filter(date_joined__range=[start_date, end_date])
            elif filter == '2':
                items = items.filter(date_joined__year=year)
            elif filter == '3':
                items = items.filter(date_joined__year=year, date_joined__month=month)



            subtotal = items.aggregate(resp=Coalesce(Sum('subtotal'), 0.00))['resp']
            dscto = items.aggregate(resp=Coalesce(Sum('dscto'), 0.00))['resp']
            iva = items.aggregate(resp=Coalesce(Sum('iva'), 0.00))['resp']
            total = items.aggregate(resp=Coalesce(Sum('total'), 0.00))['resp']
            data = [[i.id, i.prov.name, '-----------', i.date_joined_format(), i.subtotal_format(), i.total_format()]
                    for i in items]
            data.append(['-------', '-------', '-------', '-------', format(subtotal, '.2f'), format(total, '.2f')])
            '''
        except Exception as e:
            data = {}
            data['error'] = str(e)
            data['resp'] = False
        return HttpResponse(json.dumps(data), content_type='application/json')
    else:
        return HttpResponseRedirect(HOME)
Exemplo n.º 13
0
def inventory_report(request):
    data = get_module_options(request)
    if request.method == 'GET':
        data['title'] = 'Reporte de Inventarios'
        data['form'] = ReportForm(request.user.bodega_id)
        return render(request, 'inventory_report/inventory_report_rp.html',
                      data)
    elif request.method == 'POST':
        filtro = request.POST['filter']
        month = request.POST['month']
        start_date = request.POST['start_date']
        end_date = request.POST['end_date']
        year = request.POST['year']
        prod = request.POST.getlist("prod[]")
        data = []
        if month == "" and filtro == '3':
            filtro = '2'
        try:
            print(filtro)
            items = Product.objects.filter(bodega=request.user.bodega_id)
            if len(prod):
                for x in prod:
                    items = Product.objects.filter(
                        bodega=request.user.bodega_id)
                    items = items.filter(id=x)
                    if filtro == '1':
                        for i in items:
                            data.append([
                                i.id, i.name,
                                i.cost_format(), i.stock,
                                i.get_ingress_range(start_date, end_date),
                                i.get_sales_range(start_date, end_date),
                                i.get_pedids_range(start_date, end_date)
                            ])

                    elif filtro == '2':
                        for i in items:
                            data.append([
                                i.id, i.name,
                                i.cost_format(), i.stock,
                                i.get_ingress_year(year),
                                i.get_sales_year(year),
                                i.get_pedids_year(year)
                            ])

                    elif filtro == '3':
                        print(year, month)
                        for i in items:
                            data.append([
                                i.id, i.name,
                                i.cost_format(), i.stock,
                                i.get_ingress_year_month(year, month),
                                i.get_sales_year_month(year, month),
                                i.get_pedids_year_month(year, month)
                            ])

                    else:
                        for i in items:
                            data.append([
                                i.id, i.name,
                                i.cost_format(), i.stock,
                                i.get_ingress(),
                                i.get_sales(),
                                i.get_pedids()
                            ])

            else:
                if filtro == '1':
                    for i in items:
                        data.append([
                            i.id, i.name,
                            i.cost_format(), i.stock,
                            i.get_ingress_range(start_date, end_date),
                            i.get_sales_range(start_date, end_date),
                            i.get_pedids_range(start_date, end_date)
                        ])

                elif filtro == '2':
                    for i in items:
                        data.append([
                            i.id, i.name,
                            i.cost_format(), i.stock,
                            i.get_ingress_year(year),
                            i.get_sales_year(year),
                            i.get_pedids_year(year)
                        ])

                elif filtro == '3':
                    print(year, month)
                    for i in items:
                        data.append([
                            i.id, i.name,
                            i.cost_format(), i.stock,
                            i.get_ingress_year_month(year, month),
                            i.get_sales_year_month(year, month),
                            i.get_pedids_year_month(year, month)
                        ])

                else:
                    for i in items:
                        data.append([
                            i.id, i.name,
                            i.cost_format(), i.stock,
                            i.get_ingress(),
                            i.get_sales(),
                            i.get_pedids()
                        ])

        except Exception as e:
            data = {'error': str(e), 'resp': False}
        return HttpResponse(json.dumps(data), content_type='application/json')
    else:
        return HttpResponseRedirect(HOME)