function initializeReportsIssuedBillsByCategories() {
    $("#downloadIssuedBills").show();
    $("#confirmBillsDropdown").addClass('hidden');
    $('.dateFilter').addClass('hide');

    var getSearchData = function () {
        var returnParameters = {
            DateFrom: reformatDate($("#Filter_DateFrom").val()),
            DateTo: reformatDate($("#Filter_DateTo").val()),
            DocType: $("#Filter_DocType").val(),
            CategoryId: $("#Filter_CategoryId").val(),
            IsWholesale: $("#Filter_IsWholesale").val(),
            Author: $("#Filter_Author").val()
        };

        return returnParameters;
    };

    var select2Categories = $("#Filter_CategoryId").select2({
        ajax: {
            url: $("#Filter_CategoryId").data("url"),
            dataType: 'json',
            type: "POST",
            delay: 250,
            data: function (params) {
                return {
                    filter: params.term, // search term
                    page: params.page
                };
            },
            id: function (data) {
                return data.Value;
            },
            processResults: function (data, params) {
                // parse the results into the format expected by Select2
                // since we are using custom formatting functions we do not need to
                // alter the remote JSON data, except to indicate that infinite
                // scrolling can be used
                params.page = params.page || 1;

                var select2Data = $.map(data.Items, function (obj) {
                    obj.id = obj.Value,
                        obj.text = obj.Text;

                    return obj;
                });

                return {
                    results: select2Data,
                    pagination: {
                        more: (params.page * 10) < data.TotalItems
                    }
                };
            },
            cache: true
        },
        allowClear: true,
        placeholder: $('#categoryPlaceholder').val(),
        theme: "bootstrap",
        escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
        minimumInputLength: 1,
        templateResult: format, // omitted for brevity, see the source of this page
        templateSelection: function (item) { return item.name || item.text; }, // omitted for brevity, see the source of this page
        language: $('#i18n').val()
    }).on('change', function () {
        $.fn.dataTable.reload($dataTable);
    }).on("select2:unselecting", function (e) {
        $(this).select2("val", "");
        e.preventDefault();
    });

    $dataTable = $('#grid-data');
    $dataTable.DataTable({
        ajax: {
            url: $dataTable.attr('data-url'),
            data: function (d) {
                d.Keywords = encodeURIComponent($("#Keywords").val());
                d.DateFrom = reformatDate($("#Filter_DateFrom").val());
                d.DateTo = reformatDate($("#Filter_DateTo").val());
                d.DocType = $("#Filter_DocType").val();
                d.CategoryId = $("#Filter_CategoryId").val();
                d.Author = $("#Filter_Author").val();
            }
        },
        columns: [
            { data: "Category", name: "Category", filtertype: "text" },
            { data: "CategoryName", name: "Name", filtertype: "text" },
            {
                data: "Type", name: "Type", filtertype: "text", render: function (data, type) {
                    switch (data) {
                        case "P":
                            return data + " - " + $("#primaryClassifText").val();
                        case "S":
                            return data + " - " + $("#secondaryClassifText").val();
                        case "O":
                            return data + " - " + $("#bothClassifText").val();
                    }

                    return data;
                }
            },
            { data: "Quantity", name: "Quantity", filtertype: "number", render: $.fn.dataTable.render.number('.', ',', $("#DefaultDecimalPlacesQuantity").val()), className: 'dt-body-right' },
            { data: "ValueWithoutTax", name: "TotalPrice", filtertype: "number", render: $.fn.dataTable.render.number('.', ',', $("#DefaultDecimalPlacesPrice").val()), className: 'dt-body-right' },
            { data: "TotalVAT", name: "TotalVAT", filtertype: "number", render: $.fn.dataTable.render.number('.', ',', $("#DefaultDecimalPlacesPrice").val()), className: 'dt-body-right' },
            { data: "ValueWithTax", name: "TotalPriceWithVAT", filtertype: "number", render: $.fn.dataTable.render.number('.', ',', $("#DefaultDecimalPlacesPrice").val()), className: 'dt-body-right' }
        ]
    }).on('xhr.dt', function (e, settings, json, xhr) {
        if (json && json.prop) {
            $('#grid-data-total-sum').html($.fn.dataTable.render.number('.', ',', $("#DefaultDecimalPlacesPrice").val()).display(json.prop.SumAmount));
            $('#grid-data-vat-sum').html($.fn.dataTable.render.number('.', ',', $("#DefaultDecimalPlacesPrice").val()).display(json.prop.SumVat));
            $('#grid-data-vat-total-sum').html($.fn.dataTable.render.number('.', ',', $("#DefaultDecimalPlacesPrice").val()).display(json.prop.SumAmountWithVat));
            $('.grid-data-start-items').html(json.recordsTotal === 0 ? '0' : '1');
            $('.grid-data-total-items').html(json.recordsTotal);
        }
    });

    $("#downloadIssuedBills").off("click");
    $("#downloadIssuedBills").on("click", function () {
        var params = getSearchData();

        var form = $('<form id="exportForm" method="POST" style="display:none;"></form>');
        form.attr("action", $("#ExportUrl").val());
        var form_data = new FormData();

        for (var key in params) {
            var input = $("<input>")
                .attr("name", key).val(params[key]);
            form.append(input);
        }

        $("body").append(form);
        form.submit();
        $("#exportForm").remove();
    });
}