function initializeDebtStructures() {
    var columns = [
        {
            data: "SubjectId",
            name: "SubjectId",
            filtertype: "text",
            render: function (data) {
                if (data === null || data === "") {
                    return "";
                } else {
                    return '<a href="Subjects/Edit/?id=' + data + '">' + data + '</a>';
                }
            }
        },
        { data: "Due", name: "Due", filtertype: "number", render: $.fn.dataTable.render.number('.', ',', $("#DefaultDecimalPlacesQuantity").val()), className: 'dt-body-right' },
        { data: "Period1Amt", name: "Period1Amt", filtertype: "number", render: $.fn.dataTable.render.number('.', ',', $("#DefaultDecimalPlacesQuantity").val()), className: 'dt-body-right' },
        { data: "Period2Amt", name: "Period2Amt", filtertype: "number", render: $.fn.dataTable.render.number('.', ',', $("#DefaultDecimalPlacesQuantity").val()), className: 'dt-body-right' },
        { data: "Period3Amt", name: "Period3Amt", filtertype: "number", render: $.fn.dataTable.render.number('.', ',', $("#DefaultDecimalPlacesQuantity").val()), className: 'dt-body-right' },
        { data: "Period4Amt", name: "Period4Amt", filtertype: "number", render: $.fn.dataTable.render.number('.', ',', $("#DefaultDecimalPlacesQuantity").val()), className: 'dt-body-right' },
        { data: "Period5Amt", name: "Period5Amt", filtertype: "number", render: $.fn.dataTable.render.number('.', ',', $("#DefaultDecimalPlacesQuantity").val()), className: 'dt-body-right' },
        { data: "PeriodSumAmt", name: "PeriodSumAmt", filtertype: "number", render: $.fn.dataTable.render.number('.', ',', $("#DefaultDecimalPlacesQuantity").val()), className: 'dt-body-right' }
    ];

    initializeDataTables('debtStructures', 'Keywords', columns);

    $("#printButton").prop("disabled", false);
    $("#printButton + button").prop("disabled", false);
}

$('#DetailedByBill').on('select2:select', function () {
    var value = $("#DetailedByBill").val();
    var table = $('#outstandingitems').DataTable();
    if (value === '32Q') {
        table.columns('.08P').visible(false);
    }
    else {
        table.columns('.08P').visible(true);
    }
});

$('#Type').on('select2:select', function (e) {
    if (e.params.data.id == 0) {
        $("#SubjSupplier").first().css("display", "none");
        $("#SubjBuyer").first().css("display", "block");
    }
    else {
        $("#SubjBuyer").first().css("display", "none");
        $("#SubjSupplier").first().css("display", "block");
    }
});

function changeColumnName(notYetOverdue, overdue) {
    var id = $("#OpenItem").val();
    var openItem = $("#DebtStatus").val();

    if (id === openItem) {
        $("#th-open-or-due").text(notYetOverdue);
    }
    else {
        $("#th-open-or-due").text(overdue);
    }
}

let printWindow;
function printDebtStructures(reportCode) {
    var url = $("#DebtStucturesPrintUrl").val() + "?Date=" + reformatDate($("#DateFrom").val());

    var subject = $("#SubjectId").val();
    // TODO: Add filters when available

    if (subject)
        url = url + "&Subject=" + subject;
    if (reportCode)
        url = url + "&ReportType=" + reportCode;

    url = url + "&filterColumn=" + $("#filterColumn").val()
        + "&filterCriteria=" + $("#filterCriteria").val()
        + "&filterValue=" + $("#filterValue").val()
        + "&filterValue2=" + $("#filterValue2").val();

    printWindow = window.open();
    printWindow.document.write(generatePrintingPage());
    printPAAS("", false, false, url, false);
}