function selectAllUnconfirmed(cb) {
    selectAll(cb, $("#GetAllIdsUrl").val(), getSearchData());
}

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

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

    $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.PartnerId = $("#Filter_PartnerId").val();
                d.DocType = $("#Filter_DocType").val();
                d.Author = $("#Filter_Author").val();
                d.IssuedBillsFilter = $("#itemsDisplayFilterTypeCustomDate").val();
            }
        },
        order: [[2, 'desc']],
        columns: [
            { data: "AcKey", orderable: false, render: $.fn.dataTable.render.checkbox("invoiceSelectionChanged"), className: 'dt-body-center' },
            {
                data: "AcKeyDisplay", name: "AcKey", filtertype: "text", render: $.fn.dataTable.render.link("AcKey", false, $("#Filter_Author").val() === $("#AuthorTypePOS").val() ? 0 :
                    ($("#Filter_Author").val() === $("#AuthorTypeWS").val() ? 1 : 2))
            },
            { data: "FiscTypeDesc", name: "FiscTypeDesc", filtertype: "text" },
            { data: "PriceWithVat", name: "ForPay", filtertype: "number", render: $.fn.dataTable.render.number('.', ',', $("#DefaultDecimalPlacesPrice").val()), className: 'dt-body-right' },
            { data: "WorkPlace", name: "WorkPlace", filtertype: "text" },
            { data: "FiscalDevice", name: "FiscalDevice", filtertype: "text" },
            { data: "FiscalNum", name: "FiscalNum", filtertype: "number" },
            { data: "FiscalDate", name: "DateTimePrint", filtertype: "dateTime" },
            { data: "ErrorDescription", name: "Error", filtertype: "text" }
        ]
    }).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);
            $('.grid-data-selected-items-count').html(0);
        }
    }).on('draw', function (e, settings, json, xhr) {
        displayCheckboxes();

        var ackey = $("#Filter_AcKey").val();
        if (ackey) {
            $("#cb" + ackey).prop("checked", true);
            invoiceSelectionChanged(document.getElementById("cb" + ackey));
        }
    });

    $("#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();
    });
}