
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function () {
            oldonload();
            func();
        }
    }
}

var k = 0;
var l = 0;
//给选项卡加上切换功能和点击事件
function switchPage() {
    if (!document.getElementsByTagName || !document.getElementById)
        return false;
    var ulChilds = document.getElementsByTagName("ul")[0].childNodes;
    if (!ulChilds) return;
    for (var i = 0; i < ulChilds.length; i++) {
        if (ulChilds[i].nodeType == 1) {
            ulChilds[i].onclick = function () {
                var baseInfo = document.getElementById("invoice_li").style.display = "none";
                document.getElementById("acr_invoice_li").style.display = "none";
                document.getElementById("receipt_li").style.display = "none";
                document.getElementById("acp_invoice_li").style.display = "none";
                document.getElementById(this.title).style.display = "block";

                if (this.title == "acr_invoice_li" && k == 0) {
                    k++;
                    invoice_query();
                }

                for (var j = 0; j < ulChilds.length; j++) {
                    if (ulChilds[j].nodeType == 1) {
                        ulChilds[j].style.color = "#999999";
                        ulChilds[j].setAttribute("class", "nav-no-boxShadow-fontColor");
                    }
                }
                this.style.color = "black";
                this.setAttribute("class", "nav-boxShadow-fontColor");

            }
        }
    }
    ulChilds[1].style.color = "black";
    ulChilds[1].setAttribute("class", "nav-boxShadow-fontColor");
}

//待开票清单
function initInvoiceListInfo() {
    $.ajax({
        type: "GET",
        data: {},
        url: contextPath + '/vat/VAT000H/vat000hQuerybillingAmountRadio',
        contentType: "application/json; charset=utf-8",
        success: function (datas) {
            if (datas.rows[0]) {
                var radio = (datas.rows[0].radio * 100).toFixed(2);
                if (radio != null || radio != undefined) {
                    $("#task-percent-span").append(radio + '%');
                } else {
                    $("#task-percent-span").append( '--');
                }
                $('#row-task-left-circle-canvas').attr("data-percent", radio);
                InitiateEasyPieChart.init('row-task-left-circle-canvas');
            }
        }
    });
}


var InitiateEasyPieChart1 = function () {
    return {
        init: function (id) {
            var easypiecharts = $('#' + id);
            $.each(easypiecharts, function () {
                var barColor = getcolor($(this).data('barcolor')) || themeprimary,
                    trackColor = getcolor($(this).data('trackcolor')) || false,
                    scaleColor = getcolor($(this).data('scalecolor')) || false,
                    lineCap = $(this).data('linecap') || "round",
                    lineWidth = $(this).data('linewidth') || 3,
                    size = $(this).data('size') || 110,
                    animate = $(this).data('animate') || false;

                $(this).easyPieChart({
                    barColor: barColor,
                    trackColor: trackColor,
                    scaleColor: scaleColor,
                    lineCap: lineCap,
                    lineWidth: lineWidth,
                    size: size,
                    animate: animate
                });
            });
        }
    };
}();

//进项发票
function initAcpInvoiceInfo() {
    $.ajax({
        type: "GET",
        data: {},
        url: contextPath + '/vat/acp/detail/scale/query',
        contentType: "application/json; charset=utf-8",
        success: function (datas) {

            if (datas.rows[0]) {
                var totalNum = datas.rows[0].specialNum + datas.rows[0].normalNum;
                if (totalNum && !isNaN(+totalNum)) {

                    var radio = ((datas.rows[0].specialNum / totalNum) * 100).toFixed(2);
                    if (radio) {
                        $("#task-percent-span1").append(radio + '%');
                    } else {
                        $("#task-percent-span1").append('--');
                    }
                    $('#row-task-left-circle-canvas1').attr("data-percent", radio);
                    InitiateEasyPieChart1.init('row-task-left-circle-canvas1');
                }else{
                    $("#task-percent-span1").append( '0%');
                }
            }
        }
    });
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//查询框按钮点击
function optionSelected(id) {
    $("#" + id).attr("type", "selected");
    $("#" + id).css("background", "#00b3b3");
    $("#" + id).css("color", "white");
}

function optionUnSelected(id) {
    $("#" + id).attr("type", "unSelected");
    $("#" + id).css("background", "#ffffff");
    $("#" + id).css("color", "black");
}


function reset() {
    $("#tOneWeekTime").css("background", "#ffffff");
    $("#tOneWeekTime").css("color", "black");
    $("#tOneWeekTime").attr("type", "unSelected");
    $("#tOneMonthTime").css("background", "#ffffff");
    $("#tOneMonthTime").css("color", "black");
    $("#tOneMonthTime").attr("type", "unSelected");
    $("#tThreeMonthTime").css("background", "#ffffff");
    $("#tThreeMonthTime").css("color", "black");
    $("#tThreeMonthTime").attr("type", "unSelected");
    $("#tTimeInfinite").css("background", "#ffffff");
    $("#tTimeInfinite").css("color", "black");
    $("#tTimeInfinite").attr("type", "unSelected");
}


function reset2() {
    optionUnSelected("IOneWeekTime");
    optionUnSelected("IOneMonthTime");
    optionUnSelected("IThreeMonthTime");

}

function reset3() {
    optionUnSelected("ROneWeekTime");
    optionUnSelected("ROneMonthTime");
    optionUnSelected("RThreeMonthTime");
}

function reset4() {
    optionUnSelected("POneWeekTime");
    optionUnSelected("POneMonthTime");
    optionUnSelected("PThreeMonthTime");
    optionUnSelected("PTimeInfinite");
}
//查询
function selectFunciton() {

    $("#tOneWeekTime").click(function () {
        if ($("#tOneWeekTime").attr("type") == "unSelected") {
            optionSelected("tOneWeekTime");
            optionUnSelected("tOneMonthTime");
            optionUnSelected("tThreeMonthTime");
            optionUnSelected("tTimeInfinite");

        } else {
            reset()
        }
    });

    $("#tOneMonthTime").click(function () {
        if ($("#tOneMonthTime").attr("type") == "unSelected") {
            optionUnSelected("tOneWeekTime");
            optionSelected("tOneMonthTime");
            optionUnSelected("tThreeMonthTime");
            optionUnSelected("tTimeInfinite");

        } else {
            reset()
        }
    });

    $("#tThreeMonthTime").click(function () {
        if ($("#tThreeMonthTime").attr("type") == "unSelected") {
            optionUnSelected("tOneWeekTime");
            optionUnSelected("tOneMonthTime");
            optionSelected("tThreeMonthTime");
            optionUnSelected("tTimeInfinite");

        } else {
            reset()
        }
    });

    $("#tTimeInfinite").click(function () {

        if ($("#tTimeInfinite").attr("type") == "unSelected") {
            optionUnSelected("tOneWeekTime");
            optionUnSelected("tOneMonthTime");
            optionUnSelected("tThreeMonthTime");
            optionSelected("tTimeInfinite");

        } else {
            reset()
        }
    });

    $("#tRental").click(function () {
        if ($("#tRental").attr("type") == "unSelected") {
            optionSelected("tRental");
            /* optionUnSelected("tInterest");
             optionUnSelected("tDownPayment");
             optionUnSelected("tCharge");
             optionUnSelected("tResidualValue");
             optionUnSelected("tDelayedPerformance");*/
            optionUnSelected("tItemInfinite");

        } else {
            /*reset2()*/
            optionUnSelected("tRental");
        }
    });


    $("#tDownPayment").click(function () {
        if ($("#tDownPayment").attr("type") == "unSelected") {
            /*  optionUnSelected("tRental");*/
            optionSelected("tDownPayment");
            /*   optionUnSelected("tCharge");
             optionUnSelected("tResidualValue");
             optionUnSelected("tDelayedPerformance");*/
            optionUnSelected("tItemInfinite");

        } else {
            /*reset2()*/
            optionUnSelected("tDownPayment");
        }
    });

    $("#tCharge").click(function () {
        if ($("#tCharge").attr("type") == "unSelected") {
            /* optionUnSelected("tRental");
             optionUnSelected("tDownPayment");*/
            optionSelected("tCharge");
            /* optionUnSelected("tResidualValue");
             optionUnSelected("tDelayedPerformance");*/
            optionUnSelected("tItemInfinite");

        } else {
            /*reset2()*/
            optionUnSelected("tCharge");
        }
    });

    $("#tResidualValue").click(function () {
        if ($("#tResidualValue").attr("type") == "unSelected") {
            /*optionUnSelected("tRental");
             optionUnSelected("tDownPayment");
             optionUnSelected("tCharge");*/
            optionSelected("tResidualValue");
            /*  optionUnSelected("tDelayedPerformance");*/
            optionUnSelected("tItemInfinite");

        } else {
            /*reset2()*/
            optionUnSelected("tResidualValue");
        }
    });

    $("#tDelayedPerformance").click(function () {
        if ($("#tDelayedPerformance").attr("type") == "unSelected") {
            /* optionUnSelected("tRental");
             optionUnSelected("tDownPayment");
             optionUnSelected("tCharge");
             optionUnSelected("tResidualValue");*/
            optionSelected("tDelayedPerformance");
            optionUnSelected("tItemInfinite");

        } else {
            /*reset2()*/
            optionUnSelected("tDelayedPerformance");
        }
    });

    $("#tItemInfinite").click(function () {
        if ($("#tItemInfinite").attr("type") == "unSelected") {
            optionUnSelected("tRental");
            optionUnSelected("tDownPayment");
            optionUnSelected("tCharge");
            optionUnSelected("tResidualValue");
            optionUnSelected("tDelayedPerformance");
            optionSelected("tItemInfinite");

        } else {
            /* reset2()*/
            optionUnSelected("tItemInfinite");
        }
    });

//Tab 2

    $("#IOneWeekTime").click(function () {
        if ($("#IOneWeekTime").attr("type") == "unSelected") {
            optionSelected("IOneWeekTime");
            optionUnSelected("IOneMonthTime");
            optionUnSelected("IThreeMonthTime");
        } else {
            reset2()
        }
    });

    $("#IOneMonthTime").click(function () {
        if ($("#IOneMonthTime").attr("type") == "unSelected") {
            optionUnSelected("IOneWeekTime");
            optionSelected("IOneMonthTime");
            optionUnSelected("IThreeMonthTime");


        } else {
            reset2()
        }
    });

    $("#IThreeMonthTime").click(function () {
        if ($("#IThreeMonthTime").attr("type") == "unSelected") {
            optionUnSelected("IOneWeekTime");
            optionUnSelected("IOneMonthTime");
            optionSelected("IThreeMonthTime");
        } else {
            reset2()
        }
    });


    $("#InvoiceTypespecial").click(function () {
        if ($("#InvoiceTypespecial").attr("type") == "unSelected") {
            optionSelected("InvoiceTypespecial");
            optionUnSelected("InvoideTypeNormal");
        } else {
            optionUnSelected("InvoiceTypespecial");
        }
    });

    $("#InvoideTypeNormal").click(function () {
        if ($("#InvoideTypeNormal").attr("type") == "unSelected") {
            optionSelected("InvoideTypeNormal");
            optionUnSelected("InvoiceTypespecial");
        } else {
            optionUnSelected("InvoideTypeNormal");
        }
    });

    $("#InvoiceTaxRate17").click(function () {
        if ($("#InvoiceTaxRate17").attr("type") == "unSelected") {
            optionSelected("InvoiceTaxRate17");
        } else {
            optionUnSelected("InvoiceTaxRate17");
        }
    });
    $("#InvoiceTaxRate11").click(function () {
        if ($("#InvoiceTaxRate11").attr("type") == "unSelected") {
            optionSelected("InvoiceTaxRate11");
        } else {
            optionUnSelected("InvoiceTaxRate11");
        }
    });
    $("#InvoiceTaxRate6").click(function () {
        if ($("#InvoiceTaxRate6").attr("type") == "unSelected") {
            optionSelected("InvoiceTaxRate6");
        } else {
            optionUnSelected("InvoiceTaxRate6");
        }
    });
    $("#InvoiceTaxRate5").click(function () {
        if ($("#InvoiceTaxRate5").attr("type") == "unSelected") {
            optionSelected("InvoiceTaxRate5");
        } else {
            optionUnSelected("InvoiceTaxRate5");
        }
    });


    //Tab 3

    $("#ROneWeekTime").click(function () {
        if ($("#ROneWeekTime").attr("type") == "unSelected") {
            optionSelected("ROneWeekTime");
            optionUnSelected("ROneMonthTime");
            optionUnSelected("RThreeMonthTime");
        } else {
            reset3()
        }
    });

    $("#ROneMonthTime").click(function () {
        if ($("#ROneMonthTime").attr("type") == "unSelected") {
            optionUnSelected("ROneWeekTime");
            optionSelected("ROneMonthTime");
            optionUnSelected("RThreeMonthTime");


        } else {
            reset3()
        }
    });

    $("#RThreeMonthTime").click(function () {
        if ($("#RThreeMonthTime").attr("type") == "unSelected") {
            optionUnSelected("ROneWeekTime");
            optionUnSelected("ROneMonthTime");
            optionSelected("RThreeMonthTime");
        } else {
            reset3()
        }
    });


    $("#receiptPrincipal").click(function () {
        if ($("#receiptPrincipal").attr("type") == "unSelected") {
            optionSelected("receiptPrincipal");
            optionUnSelected("receiptOther");
        } else {

            optionUnSelected("receiptPrincipal");
        }
    });

    $("#receiptOther").click(function () {
        if ($("#receiptOther").attr("type") == "unSelected") {
            optionSelected("receiptOther");
            optionUnSelected("receiptPrincipal");
        } else {

            optionUnSelected("receiptOther");
        }
    });
    //Tab4
    $("#POneWeekTime").click(function () {
        if ($("#POneWeekTime").attr("type") == "unSelected") {
            optionSelected("POneWeekTime");
            optionUnSelected("POneMonthTime");
            optionUnSelected("PThreeMonthTime");
            optionUnSelected("PTimeInfinite");
        } else {
            reset4()
        }
    });

    $("#POneMonthTime").click(function () {
        if ($("#POneMonthTime").attr("type") == "unSelected") {
            optionUnSelected("POneWeekTime");
            optionSelected("POneMonthTime");
            optionUnSelected("PThreeMonthTime");
            optionUnSelected("PTimeInfinite");

        } else {
            reset4()
        }
    });

    $("#PThreeMonthTime").click(function () {
        if ($("#PThreeMonthTime").attr("type") == "unSelected") {
            optionUnSelected("POneWeekTime");
            optionUnSelected("POneMonthTime");
            optionSelected("PThreeMonthTime");
            optionUnSelected("PTimeInfinite");
        } else {
            reset4()
        }
    });
    $("#PTimeInfinite").click(function () {
        if ($("#PTimeInfinite").attr("type") == "unSelected") {
            optionUnSelected("POneWeekTime");
            optionUnSelected("POneMonthTime");
            optionUnSelected("PThreeMonthTime");
            optionSelected("PTimeInfinite");
        } else {
            reset4()
        }
    });

    $("#PY").click(function () {
        if ($("#PY").attr("type") == "unSelected") {
            optionSelected("PY");
            optionUnSelected("PN");
            optionUnSelected("PYN");
        } else {
            optionUnSelected("PY");
            optionUnSelected("PN");
            optionUnSelected("PYN");
        }
    });

    $("#PN").click(function () {
        if ($("#PN").attr("type") == "unSelected") {
            optionUnSelected("PY");
            optionSelected("PN");
            optionUnSelected("PYN");
        } else {
            optionUnSelected("PY");
            optionUnSelected("PN");
            optionUnSelected("PYN");
        }
    });

    $("#PYN").click(function () {
        if ($("#PYN").attr("type") == "unSelected") {
            optionUnSelected("PY");
            optionUnSelected("PN");
            optionSelected("PYN");
        } else {
            optionUnSelected("PY");
            optionUnSelected("PN");
            optionUnSelected("PYN");
        }
    });


    $("#PLeaseItemAmount").click(function () {
        if ($("#PLeaseItemAmount").attr("type") == "unSelected") {
            optionSelected("PLeaseItemAmount");
            optionUnSelected("POthers");
        } else {
            optionUnSelected("PLeaseItemAmount");
        }
    });

    $("#PInsurance").click(function () {
        if ($("#PInsurance").attr("type") == "unSelected") {
            optionSelected("PInsurance");
            optionUnSelected("POthers");
        } else {
            optionUnSelected("PInsurance");
        }
    });

    $("#POthers").click(function () {
        if ($("#POthers").attr("type") == "unSelected") {
            optionSelected("POthers");
            optionUnSelected("PLeaseItemAmount");
            optionUnSelected("PInsurance");
        } else {
            optionUnSelected("POthers");
        }
    });
}


//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


function invoiceExcelImport(){
    var dialog = $("#acpInvoiceExcel").kendoWindow({
        width: 	400,
        height: 250,
        modal: true,
        visible: false,
        iframe: true,
        content: contextPath + '/vat/VAT000H/invoice_excel_import.html',
        close:function(){

        }
    }).data("kendoWindow");
    dialog.title('进项发票Excel导入');
    //hlsWindow(dialog,'HALF', contextPath + '/vat/VAT000H/invoice_excel_import.html');
    dialog.center().open();
}

function button_click() {
    $("#invoiceAdd").click(function () {
    	var flag = false;
    	var str = [];
        var randomStr = (Math.random()*10000);

    	var oInputs = document.querySelectorAll("#table input[type='checkbox']");

    	for(var i = 1; i < oInputs.length; i++)
    	{
    		if(oInputs[i].checked)
    		{
                var cashflow = {};
                cashflow.queryCond = oInputs[i].title;
                cashflow.totalAmount = Number($(oInputs[i]).closest("tr").find("input")[1].value.replace(/,/g,''));
                str.push(cashflow);
                flag = true;
    		}
    	}
    	// str = str.substring(0,str.length-1);
    	if(flag)
    	{
            top.openTab('VAT210A', '销项发票创建', 'vat/VAT210A/acr_invoice_create_new.html?cashflowList='+encodeURIComponent(JSON.stringify(str)), false, '', false,randomStr, false);
             top.openFunctionArray.pop();
            // top.openTab('VAT210A','销项发票创建','vat/VAT210A/acr_invoice_create_new.html?cashflowList='+encodeURIComponent(JSON.stringify(str)),false,'',null,str);
    	}
    	else
    	{
    		  kendo.ui.showInfoDialog({
                  title:'提示',
                  message:'请至少选择一条记录'	
               });
    	}
    });
    $("#acrInvoiceAdd").click(function(){
    	top.openTab('VAT200A','销项发票创建','vat/VAT200A/vat_invoice_list.view',false,'',null);
    })
    $("#receiptAdd").click(function(){
    	top.openTab('VAT300A','收据创建','vat/VAT300A/acr_receipt_new.view',false,'',null);
    })
    $("#invoiceImport").click(function(){
        invoiceExcelImport();

    });
    $("#stayPaymentQuery").click(function(){
    	top.openTab('VAT200A','销项发票创建','vat/VAT200A/vat_invoice_list.view',false,'',null);
    })

    /*$("#invoice_checkbox_1").click(function () {
     if ($("#invoice_checkbox_1").attr("type") == "unSelected") {
     $("#invoice_checkbox_1").css("background-position", "0px 0");
     $("#invoice_checkbox_1").attr("type", "selected");
     } else {
     $("#invoice_checkbox_1").css("background-position", "-24px 0");
     $("#invoice_checkbox_1").attr("type", "unSelected");
     }

     });*/

    /*
     $("#spreadWin").click(function () {
     if ($("#spreadWin").attr("type") == "unSelected") {
     $("#spreadWin").css("transform", "rotate(90deg)");
     $("#spreadWin").attr("type", "selected");
     $("#invoice_spread_1").css("display", "block");
     $("#invoice_spread_2").css("display", "block");
     $("#invoice_spread_3").css("display", "block");
     } else {
     $("#spreadWin").css("transform", "rotate(0deg)");
     $("#spreadWin").attr("type", "unSelected");
     $("#invoice_spread_1").css("display", "none");
     $("#invoice_spread_2").css("display", "none");
     $("#invoice_spread_3").css("display", "none");
     }
     });

     $("#spreadWin7").click(function () {
     if ($("#spreadWin7").attr("type") == "unSelected") {
     $("#spreadWin7").css("transform", "rotate(90deg)");
     $("#spreadWin7").attr("type", "selected");
     $("#invoice_spread_5").css("display", "block");
     $("#invoice_spread_6").css("display", "block");
     $("#invoice_spread_7").css("display", "block");
     } else {
     $("#spreadWin7").css("transform", "rotate(0deg)");
     $("#spreadWin7").attr("type", "unSelected");
     $("#invoice_spread_5").css("display", "none");
     $("#invoice_spread_6").css("display", "none");
     $("#invoice_spread_7").css("display", "none");
     }
     });*/
}

//------------------------------------------------------------------------------------------------------------------------------------------------
//柱状图
themeprimary = getThemeColorFromCss('themeprimary');
themesecondary = getThemeColorFromCss('themesecondary');
themethirdcolor = getThemeColorFromCss('themethirdcolor');
themefourthcolor = getThemeColorFromCss('themefourthcolor');
themefifthcolor = getThemeColorFromCss('themefifthcolor');

var InitiateBarChart = function () {
    return {
        init: function (data) {
            (function clear() {
                var fundContain_pie_body = document.getElementById("bailManagementContainChartTabContainChartFirst");
                var childNodes = fundContain_pie_body.childNodes;
                for (var i = childNodes.length - 1; i >= 0; i--) {
                    fundContain_pie_body.removeChild(childNodes[i]);
                }
            })();
            Morris.Bar({
                element: 'bailManagementContainChartTabContainChartFirst',
                data: data,
                xkey: 'x',
                ykeys: ['a', 'b'],
                labels: ['合同保证金', '保证金池'],
                hideHover: 'auto',
                barColors: [themethirdcolor, themeprimary],
                barSizeRatio: 0.4
            });
        }
    };
}();

var d2 = new Array();
/* 已开发票统计 */
function invoice_query() {
    //模糊查询
    var url = contextPath + '/vat/acp/invoiced/group/query';
    $.ajax({
        type: 'GET',
        url: url,
        async: false, //设为同步
        contentType: "application/json; charset=utf-8",
        success: function (datas) {

            for (var i = 0; i < datas.rows.length; i++) {
                d2[i] = new Object();
                d2[i].type = datas.rows[i].description;
                d2[i].totalAmount = datas.rows[i].totalAmount;

               // d2[i].totalAmount = 10000;

               /* if(datas.rows[i].cfItem == '-99'){
                    d2[i].type ='其它';
                    d2[i].count = datas.rows[i].totalAmount;
                }
                if(datas.rows[i].cfItem == '1'){
                    d2[i].type ='租金';
                    d2[i].count = datas.rows[i].totalAmount;
                }
                if(datas.rows[i].cfItem == '2'){
                    d2[i].type ='首付款';
                    d2[i].count = datas.rows[i].totalAmount;
                }
                if(datas.rows[i].cfItem == '3'){
                    d2[i].type ='手续费';
                    d2[i].count = datas.rows[i].totalAmount;
                }
                if(datas.rows[i].cfItem == '8'){
                    d2[i].type ='留购价';
                    d2[i].count = datas.rows[i].totalAmount;
                }
                if(datas.rows[i].cfItem == '9'){
                    d2[i].type ='延迟履行金';
                    d2[i].count = datas.rows[i].totalAmount;
                }*/

            }
            var InitiateBarChart = function () {
                return {
                    init: function (d2) {
                        var d1 = [];
                        d1[0] = new Object();
                        d1[0].type = '租金';
                        d1[0].totalAmount = '0';
                        d1[1] = new Object();
                        d1[1].type = '首付款';
                        d1[1].totalAmount = '0';
                        d1[2] = new Object();
                        d1[2].type = '手续费';
                        d1[2].totalAmount = '0';
                        d1[3] = new Object();
                        d1[3].type = '留购金';
                        d1[3].totalAmount = '0';
                        d1[4] = new Object();
                        d1[4].type = '延迟履行金';
                        d1[4].totalAmount = '0';
                        d1[5] = new Object();
                        d1[5].type = '其它';
                        d1[5].totalAmount = '0';
                        for (var i = 0; i < d1.length; i++) {
                            for (var j = 0; j < d2.length; j++) {
                                if (d1[i].type == d2[j].type) {
                                    d1[i].totalAmount = d2[j].totalAmount;
                                }
                            }
                        }
                        Morris.Bar({
                            element: 'arc_invoice_query',
                            data: d1,
                            xkey: 'type',
                            ykeys: ['totalAmount'],
                            labels: ['开票金额'],
                            hideHover: 'auto',
                            barColors: [themeprimary],
                            barSizeRatio: 0.2
                        });
                    }
                };
            }();
            InitiateBarChart.init(d2);

            homeCount(contextPath)
        }
    });


}


function homeCount(contextPath) {
    var url = contextPath + '/vat/acp/invoiced/totle/query';
    $.ajax({
        type: 'GET',
        url: url,
        async: false, //设为同步
        contentType: "application/json; charset=utf-8",
        success: function (datas) {
            $('#sumCount').html(formatCurrency(datas.rows[0].specialNum));
            $('#addCount').html(formatCurrency(datas.rows[0].normalNum));
        }
    });
}


function queryCashFlowDetail(cashflowId) {
    var datas;
    $.ajax({
        url: contextPath + "/csh/vat/detail/query?reversedFlag='N'&cashflowId=" + cashflowId,
        type: "POST",
        dataType: "json",
        async: false,
        contentType: "application/json",
        success: function (args) {
            datas = args;
        },
        error: function () {
        }
    });
    return datas;
}

function add(id, rowIndex) {
    var tr = document.createElement("tr");
    var td = document.createElement("td");
    td.colSpan = "9";
    var divAll = document.createElement("div");
    divAll.style.background = "rgb(245,245,245)";
    divAll.style.width = "1090px";
    divAll.style.marginLeft = "30px";
    //	div.innerHTML = "<span>测试</span>";
    tr.appendChild(td);
    td.appendChild(divAll);

    if (!page.addTr(rowIndex, tr)) {
        $("#spreadWin_" + (id +　rowIndex)).css("transform", "rotate(0deg)");
        page.deleteTr(rowIndex);
    }
    else {
        $("#spreadWin_" + (id + rowIndex)).css("transform", "rotate(90deg)");
        var datas = queryCashFlowDetail(id);
        if (datas) {
            for (var i = 0; i < datas.rows.length; i++) {
                var divOuter = document.createElement("div") , divInner = document.createElement("div");
                divOuter.className = "table-list-pull-down";
                divInner.style.width = "710px";
                divInner.style.float = "right";
                divOuter.appendChild(divInner);

                var p = new Array();
                for (var j = 0; j < 5; j++) {
                    p[j] = document.createElement("span");
                    p[j].className = "spanInfo";
                    divInner.appendChild(p[j]);
                }
                var id = datas.rows[i].writeOffId;

                p[0].style.width= "158px";
                p[4].style.width= "58px";
                p[4].style.marginLeft = "50px";
                p[0].innerHTML = '核销日期:&nbsp;'+ formatDate(datas.rows[i].writeOffDate) || '--';
                p[1].innerHTML = '金额:<span class="number-format">' + (datas.rows[i].writeOffDueAmountFormat) || 0 + '</span>';
                p[2].innerHTML = '本金:<span class="number-format">' + (datas.rows[i].writeOffPrincipalFormat) || 0 + '</span>';
                p[3].innerHTML = '利息:<span class="number-format">' + (datas.rows[i].writeOffInterestFormat) || 0 + '</span>';
                p[4].innerHTML = "<a style='cursor:pointer' onclick=writeOffDetail(" + id + ");>更多..</a>";
                divAll.appendChild(divOuter);
            }

        }
    }
}

function writeOffDetail(writeOffId) {
  /*  url = contextPath + '/csh/CSH502B/csh_write_off_detail.html?writeOffId=' + writeOffId;
    var editWin = $("#writeoffwin").kendoWindow({
        actions: ["Close"],
        width: 1000,
        height: 450,
        title: '核销明细',
        iframe: true,
        visible: false,
        modal: true,
        content: url,
        close: function () {
            hlsWindowClose(this);
        }
    }).data("kendoWindow");
    hlsWindow(editWin, 'HALF', url, 610);*/
    Hls.openBox(
        {
            functionCode: "CSH502B",
            winId: "writeoffwin",
            params: {
                writeOffId:writeOffId
            }
        }
    );



}

var datas = {
    'contractInfo': '',
    //  'tenantInfo': '',
    'count': '',
    'timesFrom': '',
    'timesTo': '',
    'cashflowItems': '',
    'status': ''
};
//------------------------------------------------------------------------------------------------------------------------------------------------
//tab 1 的查询按钮
function invoiceSearchBtn() {

    //到期日
    datas.count = "";
    if ($("#tOneWeekTime").attr("type") == "selected") {
        datas.count = 7;
    }
    if ($("#tOneMonthTime").attr("type") == "selected") {
        datas.count = 1;
    }
    if ($("#tThreeMonthTime").attr("type") == "selected") {
        datas.count = 3;
    }
    if ($("#tTimeInfinite").attr("type") == "selected") {
        datas.count = null;
    }
    //应收项目


    var items = document.getElementsByClassName("t_cf_item");
    datas.cashflowItems = "";
    for (var i = 0; i < items.length; i++) {
        if ($("#" + items[i].id).attr("type") == 'selected' && $("#" + items[i].id).attr("name") != 99) {
            datas.cashflowItems = datas.cashflowItems + $("#" + items[i].id).attr("name") + "、";
        }
        if ($("#" + items[i].id).attr("type") == 'selected' && $("#" + items[i].id).attr("name") == 99) {
            datas.cashflowItems = "1、2、3、8、9、";
        }
    }
    datas.cashflowItems = datas.cashflowItems.substring(0, datas.cashflowItems.length - 1);

    datas.contractInfo = $("#contractInfo").val();

    datas.timesFrom = $("#timesFromInfo").val();

    datas.timesTo = $("#timesToInfo").val();


    $.ajax({
        url: contextPath + '/con/contract/vat/List/query',
        type: "POST",
        dataType: "json",
        data: kendo.stringify(datas),
        contentType: "application/json",
        success: function (datas) {
            debugger
            for(var i=0;i<datas.rows.length;i++){
                if(datas.rows[i].due_amount==datas.rows[i].billing_amount){
                    datas.rows.splice(i,1);
                }
            }
            var divObject = document.getElementById("table");
            page = new paging();
            page.setDataSourse(datas.rows);
            page.setPageSize(10);
            page.setParentDiv(divObject);
            page.setFeilds(["", "contract_name", "times", "cf_item_desc", "due_date", "due_amount", "billing_amount", "invoiceAmount",""]);
            page.setFeildsName(['', '合同编号/合同名称', '期数', '应收项目', '到期日', '应收金额', '已开票金额', '本次开票金额','展开']);
            page.init();
            var last = document.getElementById("last");
            var next = document.getElementById("next");
            if(page.maxSize == 1 || page.maxSize == 0) {
				next.src = contextPath + "/resources/images/CSH/nextNot.png";
			} else {
				next.src = contextPath + "/resources/images/CSH/next.png";
			}
           
            last.onclick = function(){
				page.lastPage();
				if(page.page == 0){
					last.src = contextPath + "/resources/images/CSH/last.png";
					if(page.maxSize !=1){
						next.src = contextPath + "/resources/images/CSH/next.png";
					}
				} else {
					next.src = contextPath + "/resources/images/CSH/next.png";
					last.src = contextPath + "/resources/images/CSH/lastCan.png";
				}
				setCheck();
			}
			next.onclick = function(){
				page.nextPage();
				if(page.page == page.maxSize-1){
					next.src = contextPath + "/resources/images/CSH/nextNot.png";
					if(page.maxSize !=1){
						last.src = contextPath + "/resources/images/CSH/lastCan.png";
					}
				} else {
					last.src = contextPath + "/resources/images/CSH/lastCan.png";
					next.src = contextPath + "/resources/images/CSH/next.png";
				}
				 setCheck();
			}

            $("#table tr:first td:first span").html('<input type="checkbox" id="check" class="selfCheckBox"  title="checked" /><label for="check"></label>');
            document.getElementById("check").onclick = function (){
                var $oInput = $("#table input[type='checkbox']");
                if(!this.checked){
                    $.each($oInput,function(){
                        console.log("1");
                        this.checked = false;
                    });
                }else{
                    $.each($oInput,function(){
                        console.log("2");
                        this.checked = true;
                    });
                }
            }

            function firstFeild(rowdata, rowIndex) {
                var num = parseInt(rowdata.cashflow_id) + "-" + rowdata.bsCfItem ;
                page.modifyField(0,'<input type="checkbox" id="check'+rowIndex+'" class="selfCheckBox" title = "'+num+'" /><label for="check'+rowIndex+'"></label>','template',rowIndex);
            }

            page.modifyEvent(0, "template", firstFeild);

            function twoField(rowdata, rowIndex) {
                page.modifyField(1, "<p style='text-align:left;padding-left:20px;'>" + rowdata.contract_number + "</p><p style='text-align:left;padding-left:20px;'>" + rowdata.contract_name + "</p>", "template", rowIndex);
            }

            page.modifyEvent(1, "template", twoField);
            
            function fiveField(rowdata, rowIndex) {
                page.modifyField(5, "<p style='text-align:right; '>" + formatCurrency(rowdata.due_amount) + "</p>", "template", rowIndex);
            }

            page.modifyEvent(5, "template", fiveField);
            
            // function sixField(rowdata, rowIndex) {
            //     page.modifyField(6, "<p style='text-align:right;'>" + formatCurrency(rowdata.principal) + "</p>", "template", rowIndex);
            // }
            //
            // page.modifyEvent(6, "template", sixField);
            //
            // function sevenField(rowdata, rowIndex) {
            //     page.modifyField(7, "<p style='text-align:right;'>" + formatCurrency(rowdata.interest) + "</p>", "template", rowIndex);
            // }

            // page.modifyEvent(7, "template", sevenField);
            
            function eightField(rowdata, rowIndex) {
                page.modifyField(6, "<p style='text-align:right;'>" + formatCurrency(rowdata.billing_amount) + "</p>", "template", rowIndex);
            }

            page.modifyEvent(6, "template", eightField);
            
            // function nineField(rowdata, rowIndex) {
            //     page.modifyField(9, "<p style='text-align:right;'>" + formatCurrency(rowdata.billing_principal) + "</p>", "template", rowIndex);
            // }
            //
            // page.modifyEvent(9, "template", nineField);
            //
            // function tenField(rowdata, rowIndex) {
            //     page.modifyField(10,"<p style='text-align:right;'>" + formatCurrency(rowdata.billing_interest) + "</p>", "template", rowIndex);
            // }
            //
            // page.modifyEvent(10, "template", tenField);
            function invoiceAmountFormat(rowdata, rowIndex){
                var invoiceAmount = minus(rowdata.due_amount,rowdata.billing_amount);
                var inputId = "invoiceAmount"+Number(rowIndex+1);
                page.modifyField(7, '<p style="text-align:right;" onclick="renderNumberComponent(this,'+inputId+','+invoiceAmount+')" >'+formatCurrency(invoiceAmount)+'<input type="text" style="color:#000;" hidden id="invoiceAmount'+(rowIndex+1)+'" name="invoiceInput" value="'+(rowdata.due_amount - rowdata.billing_amount)+'"/></p>', "template", rowIndex);

            // <input type="text" style="color:#000;" id="invoiceAmount'+(rowIndex+1)+'" value="'+(rowdata.due_amount - rowdata.billing_amount)+'"/>
            //     renderNumberComponent("invoiceAmount"+(rowIndex+1) ,(rowdata.due_amount - rowdata.billing_amount) );
            }
            page.modifyEvent(7, "template", invoiceAmountFormat);

            function addAndDel(rowdata, rowIndex) {
                var id = parseInt(rowdata.cashflow_id) +　rowIndex;
                page.modifyField(8, '<p style="cursor:pointer;" onclick="add(' + rowdata.cashflow_id + ',' + rowIndex + ')"><img id="spreadWin_' + id + '" style="cursor: pointer;width: 24px;height: 24px;margin-top: 0px;" src="' + contextPath + '/resources/images/VAT/u87.png" type="unSelected"/></p>', "template", rowIndex);
            }

            page.modifyEvent(8, "template", addAndDel);
            dataId = new Array();
            var dataIndex = 0;
            function setCheck() {
            }
            setCheck();
        },
        error: function () {
        }
    });
}
function renderNumberComponent(that,id,amount){
    id = (typeof id === 'object') ? id.id : id;
    $(that).off();
    $(that).replaceWith('<input id="'+id+'" value="'+amount+'"  style="color:#000"/>');
    $("#"+id).kendoNumericTextBox({
        min: 0,
        change: function(e){
        }
    });

}

var datas2 = {
    'count': '',
    'invoiceTypes': '',
    'invoiceTaxRate': ''
};
function acrInvoiceSearchBtn() {
    //开票日期
    datas2.count = "";
    if ($("#IOneWeekTime").attr("type") == "selected") {
        datas2.count = 7;
    }
    if ($("#IOneMonthTime").attr("type") == "selected") {
        datas2.count = 1;
    }
    if ($("#IThreeMonthTime").attr("type") == "selected") {
        datas2.count = 3;
    }

    //开票种类
    datas2.invoiceKind = "";
    if ($("#InvoiceTypespecial").attr("type") == "selected") {
        datas2.invoiceKind = '0';
    }
    if ($("#InvoideTypeNormal").attr("type") == "selected") {
        datas2.invoiceKind = '2';
    }

    //税率
    datas2.invoiceTypesRate = "";
    var rateList = document.getElementsByClassName("i_rate_list");
    for (var i = 0; i < rateList.length; i++) {
        if ($("#" + rateList[i].id).attr("type") == 'selected') {
            datas2.invoiceTypesRate = datas2.invoiceTypesRate + $("#" + rateList[i].id).attr("name") + '、';
        }
    }
    if (datas2.invoiceTypesRate) {
        datas2.invoiceTypesRate = datas2.invoiceTypesRate.substring(0, datas2.invoiceTypesRate.length - 1);
    }

    $.ajax({
        url: contextPath + '/vat/acr/invoicehd/detail/query',
        type: "POST",
        dataType: "json",
        data: kendo.stringify(datas2),
        contentType: "application/json",
        success: function (datas) {
            var divObject = document.getElementById("acr_table");
            page2 = new paging();
            page2.setDataSourse(datas.rows);
            page2.setPageSize(6);
            page2.setParentDiv(divObject);

            page2.setFeilds(["invoiceDate", "invoiceKindDesc", "bpName", "bpAddressPhoneNum", "bpBankAccount", "totalAmount",""]);
            page2.setFeildsName(['开票日期', '发票种类', '购货单位/纳税人识别号', '地址、电话', '开户行及账号', '价税合计/金额/税额','明细']);
            page2.init();
           
            
            var last = document.getElementById("last2");
            var next = document.getElementById("next2");
            if(page2.maxSize == 1 || page2.maxSize == 0) {
				next.src = contextPath + "/resources/images/CSH/nextNot.png";
			} else {
				next.src = contextPath + "/resources/images/CSH/next.png";
			}
           
            last.onclick = function(){
				page2.lastPage();
				if(page2.page == 0){
					last.src = contextPath + "/resources/images/CSH/last.png";
					if(page2.maxSize !=1){
						next.src = contextPath + "/resources/images/CSH/next.png";
					}
				} else {
					next.src = contextPath + "/resources/images/CSH/next.png";
					last.src = contextPath + "/resources/images/CSH/lastCan.png";
				}
				
			}
			next.onclick = function(){
				page2.nextPage();
				if(page2.page == page2.maxSize-1){
					next.src = contextPath + "/resources/images/CSH/nextNot.png";
					if(page2.maxSize !=1){
						last.src = contextPath + "/resources/images/CSH/lastCan.png";
					}
				} else {
					last.src = contextPath + "/resources/images/CSH/lastCan.png";
					next.src = contextPath + "/resources/images/CSH/next.png";
				}
				 
			}

            function firstField(rowdata, rowIndex) {
                if(rowdata.invoiceDate == undefined)
                    rowdata.invoiceDate = "--";
                else
                    rowdata.invoiceDate = formatDate(rowdata.invoiceDate);
                page2.modifyField(0,rowdata.invoiceDate, "template", rowIndex);
            }
            page2.modifyEvent(0, "template", firstField);

            function thirdField(rowdata, rowIndex) {
                page2.modifyField(2, "<p style='text-align:left;padding-left:40px;'>" + rowdata.bpName + "</p><p style='text-align:left;padding-left:40px;'>" + rowdata.bpTaxRegistryNum + "</p>", "template", rowIndex);
            }
            page2.modifyEvent(2, "template", thirdField);

            function sixField(rowdata, rowIndex) {
                page2.modifyField(5, "<p style='text-align:right;padding-right:40px;'>" + formatCurrency(rowdata.totalAmount) + "</p><p style='text-align:right;padding-right:40px;'>" + formatCurrency(rowdata.netAmount) + "|" + formatCurrency(rowdata.taxAmount) + "</p>", "template", rowIndex);
            }

            page2.modifyEvent(5, "template", sixField);

            function throwDetail2(rowdata, rowIndex) {
                //进入到销项发票明细
                /*if (rowdata.payment_req_ln_id)
                 addFunction(rowdata.payment_req_ln_id);*/
                if(rowdata.invoiceKind == 1 || rowdata.invoiceKind == 2)
                {
                    page2.modifyField(6, "<img onclick='addFunctionCheck1("+rowdata.invoiceHdId+","+1+")'  src=" + contextPath + "/resources/images/CONT/detail.png style='cursor:pointer;display:inline-block;margin-right:5px;height:15px;width:15px;'/>", "template", rowIndex);
                }
                else
                {
                    page2.modifyField(6, "<img onclick='addFunctionCheck1("+rowdata.invoiceHdId+","+2+")'  src=" + contextPath + "/resources/images/CONT/detail.png style='cursor:pointer;display:inline-block;margin-right:5px;height:15px;width:15px;'/>", "template", rowIndex);
                }
                /*page2.modifyField(6, "<img onclick='addFunctionCheck1("+rowdata.invoiceHdId+"," + rowIndex + ")'  src=" + contextPath + "/resources/images/CONT/detail.png style='cursor:pointer;display:inline-block;margin-right:5px;height:15px;width:15px;padding-right:40px;'/>", "template", rowIndex);

*/
            }
            page2.modifyEvent(6, "template", throwDetail2);

        },
        error: function () {
        }
    });
}
//销项发票明细弹框
function addFunctionCheck1(id){
    addFunction1(contextPath + '/vat/VAT230A/vat_sales_invoice_detail.html?invoiceHdId='+id);
}
function addFunction1(url) {
    var dialogs = $("#popDiv").kendoWindow({
        actions: ["Close"],
        width: 1000,
        height: 500,
        resizable: false,
        // title: false,
        visible: false,
        iframe: true,
        modal: false,
        content: url
    }).data("kendoWindow");
    dialogs.center().open();
}



//投放明细弹框
function addFunctionCheck(sourceId,sourceType){
    if(sourceType == "CASHFLOW_PRINCIPAL"){
        Hls.openBox(
            {
                functionCode: "CSH503B",
                winId: "throwDetailDialog",
                width:610,
                params: {
                    cashflowId:sourceId
                }
            }
        );
    }else if(sourceType == "CSH_RECEIPT"){
        Hls.openBox(
            {
                functionCode: "CSH504B",
                winId: "throwDetailDialog",
                params: {
                    transaction_id:sourceId
                }
            }
        );
    }else{
        Hls.showErrorMessage("该收据来源类型未知!");
    }
}
function addFunction(url) {
	
    var dialog = $("#throwDetailDialog").kendoWindow({
        // actions: ["Maximize", "Minimize", "Close"],
        width: 600,
        height: 400,
        modal: true,
        visible: false,
        iframe: true,
        close: function () {
            hlsWindowClose(this);
        }
    }).data("kendoWindow");
    dialog.title("投放明细");
    hlsWindow(dialog, 'FULL', url, "610");
}


//-----------------------------------------------------------------------------------------------------------------------
//tab3 查询
var data3 = {
    'count': '',
    'contractInfo': '',
    'totalAmountFrom': '',
    'totalAmountTo': '',
    'cfItem': ''
};
function recInvoiceSearchBtn() {
    //时间跨度

    data3.count = "";
    if ($("#ROneWeekTime").attr("type") == "selected") {
        data3.count = 7;
    }
    if ($("#ROneMonthTime").attr("type") == "selected") {
        data3.count = 1;
    }
    if ($("#RThreeMonthTime").attr("type") == "selected") {
        data3.count = 3;
    }

    //交款单位
    data3.contractInfo = $("#receiptInfo").val();

    //金额
    data3.totalAmountFrom = $("#receiptAmountFrom").val();
    data3.totalAmountTo = $("#receiptAmountTo").val();
    //款项内容
    if ($("#receiptPrincipal").attr("type") == "selected") {
        data3.cfItem = 1;
    }
    if ($("#receiptOther").attr("type") == "selected") {
        data3.cfItem = -99;
    }

    $.ajax({
        url: contextPath + '/vat/acr/invoicehd/receipt/query',
        type: "POST",
        dataType: "json",
        data: kendo.stringify(data3),
        contentType: "application/json",
        success: function (datas) {
            var divObject = document.getElementById("rec_table");
            page3 = new paging();
            page3.setDataSourse(datas.rows);
            page3.setPageSize(6);
            page3.setParentDiv(divObject);

            page3.setFeilds(["documentNumber","sourceTypeDesc","bpName", "receiptDate", "totalAmount", "companyName", "a"]);
            page3.setFeildsName(['编号', '收据类型','交款单位', '日期', '金额', '收款单位', '明细']);
            page3.init();
          
            
            var last = document.getElementById("last3");
            var next = document.getElementById("next3");
            if(page3.maxSize == 1 || page3.maxSize == 0)
			{
				next.src = contextPath + "/resources/images/CSH/nextNot.png";
			}
			else
			{
				next.src = contextPath + "/resources/images/CSH/next.png";
			}
           
            last.onclick = function(){
				page3.lastPage();
				if(page3.page == 0){
					last.src = contextPath + "/resources/images/CSH/last.png";
					if(page3.maxSize !=1){
						next.src = contextPath + "/resources/images/CSH/next.png";
					}
				}
				else
				{
					next.src = contextPath + "/resources/images/CSH/next.png";
					last.src = contextPath + "/resources/images/CSH/lastCan.png";
				}
				
			}
			next.onclick = function(){
				page3.nextPage();
				if(page3.page == page3.maxSize-1){
					next.src = contextPath + "/resources/images/CSH/nextNot.png";
					if(page3.maxSize !=1){
						last.src = contextPath + "/resources/images/CSH/lastCan.png";
					}
				}
				else
				{
					last.src = contextPath + "/resources/images/CSH/lastCan.png";
					next.src = contextPath + "/resources/images/CSH/next.png";
				}
				 
			}

            function oneField(rowdata, rowIndex) {
                var sourceType = {
                    CASHFLOW_PRINCIPAL:"回租本金",
                    CSH_RECEIPT:"收款"


                };


                page3.modifyField(1, "<p style='text-align:left;padding-left:20px;width:80px;'>" + sourceType[rowdata.sourceType] + "</p>", "template", rowIndex);
            }
            page3.modifyEvent(1, "template", oneField);

            function twoField(rowdata, rowIndex) {
                page3.modifyField(2, "<p style='text-align:left;padding-left:20px;width:160px;'>" + rowdata.bpName + "</p>", "template", rowIndex);
            }
            page3.modifyEvent(2, "template", twoField);
            
            function thirdField(rowdata, rowIndex) {
                page3.modifyField(3, "<p>" + formatDate(rowdata.receiptDate) + "</p>", "template", rowIndex);
            }

            page3.modifyEvent(3, "template", thirdField);

            function fiveField(rowdata, rowIndex) {
                page3.modifyField(4, "<p style='text-align:right;padding-right:10px;'>" + formatCurrency(rowdata.totalAmount) + "</p>", "template", rowIndex);
            }

            page3.modifyEvent(4, "template", fiveField);

            function throwDetail1(rowdata, rowIndex) {
                //进入到合同明细
            	page3.modifyField(6, '<img onclick="addFunctionCheck('+rowdata.sourceId+',\''+rowdata.sourceType+'\')"  src="'+contextPath+'/resources/images/CONT/detail.png" style="cursor:pointer;display:inline-block;margin-right:5px;height:15px;width:15px;"/>', "template", rowIndex);
            }
            page3.modifyEvent(6, "template", throwDetail1);
            

        },
        error: function () {
        }
    });
}


//-----------------------------------------------------------------------------------------------------------------------

function queryAcpLnDetail(cashflowId) {
    var datas;
    $.ajax({
        url: contextPath + "/vat/acp/detail/ln/query?cashflowId=" + cashflowId,
        type: "POST",
        dataType: "json",
        async: false,
        contentType: "application/json",
        success: function (args) {
            datas = args;
        },
        error: function () {
        }
    });
    return datas;
}


function spread_win(id, rowIndex) {
    var tr = document.createElement("tr");
    var td = document.createElement("td");
    td.colSpan = "9";
    var divAll = document.createElement("div");
    divAll.style.background = "rgb(245,245,245)";
    divAll.style.width = "1100px";
    // divAll.style.marginLeft = "20px";
    //	div.innerHTML = "<span>测试</span>";
    tr.appendChild(td);
    td.appendChild(divAll);
    if (!page4.addTr(rowIndex, tr)) {
        $("#spreadWin_" + id).css("transform", "rotate(0deg)");
        page4.deleteTr(rowIndex);
    }
    else {
        $("#spreadWin_" + id).css("transform", "rotate(90deg)");
        var datas = queryAcpLnDetail(id);
        if (datas) {
            for (var i = 0; i < datas.rows.length; i++) {
                var div = document.createElement("div");
                var p = new Array();
                for (var j = 0; j < 7; j++) {
                    p[j] = document.createElement("span");
                    p[j].className = "spanInfo1";
                    div.appendChild(p[j]);
                }
                p[0].innerHTML = "发票号:" + datas.rows[i].invoiceNumber;
                p[1].innerHTML = "记账日期:" + formatDate(datas.rows[i].invoiceDate) || '--';
                p[2].innerHTML = "发票备注:" + datas.rows[i].description;
                p[3].innerHTML = "发票种类:" + datas.rows[i].invoiceKindDesc;
                p[4].innerHTML = "价税合计:" + formatCurrencyUnsigned(datas.rows[i].totalAmount);
                p[5].innerHTML = "税率:" + datas.rows[i].taxTypeRate * 100 + "%";
                p[6].innerHTML = "税额:" + datas.rows[i].taxAmount;
                divAll.appendChild(div);
            }
        }
    }
}


//tab4 查询
var data4 = {
    'count': '',
    'diff': '',
    'cashflowItems': '',
    'amountFrom': '',
    'amountTo': '',
    'contractInfo': '',
    'timesFrom': '',
    'timesTo': '',
    'flag': ''

};


function acpInvoiceSearchBtn() {
    //记账日期
    data4.count = "";
    if ($("#POneWeekTime").attr("type") == "selected") {
        data4.count = 7;
    }
    if ($("#POneMonthTime").attr("type") == "selected") {
        data4.count = 1;
    }
    if ($("#PThreeMonthTime").attr("type") == "selected") {
        data4.count = 3;
    }

    //差异
    data4.diff = ""

    if ($("#PY").attr("type") == "selected") {
        data4.diff = 'Y';
    }
    if ($("#PN").attr("type") == "selected") {
        data4.diff = 'N';
    }

    var items = document.getElementsByClassName("p_cf_item");
    data4.cashflowItems = "";
    data4.flag = "";
    for (var i = 0; i < items.length; i++) {
        if ($("#" + items[i].id).attr("type") == 'selected' && $("#" + items[i].id).attr("name") != -99) {
            data4.cashflowItems = data4.cashflowItems + $("#" + items[i].id).attr("name") + "、";
            data4.flag = 'Y';
        }
        if ($("#" + items[i].id).attr("type") == 'selected' && $("#" + items[i].id).attr("name") == -99) {
            data4.cashflowItems = "-99、";
            data4.flag = 'N';
        }
    }
    data4.cashflowItems = data4.cashflowItems.substring(0, data4.cashflowItems.length - 1);


    //开票金额
    data4.amountFrom = $("#amountFrom").val();
    data4.amountTo = $("#amountTo").val();
    //合同信息
    data4.contractInfo = $("#pContractInfo").val();
    data4.timesFrom = $("#pTimesFromInfo").val();
    data4.timesTo = $("#pTimesToInfo").val();

    $.ajax({
        url: contextPath + '/vat/acp/detail/query',
        type: "POST",
        dataType: "json",
        data: kendo.stringify(data4),
        contentType: "application/json",
        success: function (datas) {

            var divObject = document.getElementById("acp_table");

            page4 = new paging();
            page4.setDataSourse(datas.rows);
            page4.setPageSize(6);
            page4.setParentDiv(divObject);

            page4.setFeilds(["", "contractNumber", "contractName", "cfItemDesc", "times", "companyFullName", "billingAmount", "diffAmount", ""]);
            page4.setFeildsName(['', '合同号', '合同名称', '应付项目', '应付期数', '销方对象', '本次开票金额', '差异', '展开']);
            page4.init();
            var last = document.getElementById("last4");
            var next = document.getElementById("next4");
            if(page4.maxSize == 1 || page4.maxSize == 0)
			{
				next.src = contextPath + "/resources/images/CSH/nextNot.png";
			}
			else
			{
				next.src = contextPath + "/resources/images/CSH/next.png";
			}
           
            last.onclick = function(){
				page4.lastPage();
				if(page4.page == 0){
					last.src = contextPath + "/resources/images/CSH/last.png";
					if(page4.maxSize !=1){
						next.src = contextPath + "/resources/images/CSH/next.png";
					}
				}
				else
				{
					next.src = contextPath + "/resources/images/CSH/next.png";
					last.src = contextPath + "/resources/images/CSH/lastCan.png";
				}
				
			}
			next.onclick = function(){
				page4.nextPage();
				if(page4.page == page4.maxSize-1){
					next.src = contextPath + "/resources/images/CSH/nextNot.png";
					if(page4.maxSize !=1){
						last.src = contextPath + "/resources/images/CSH/lastCan.png";
					}
				}
				else
				{
					last.src = contextPath + "/resources/images/CSH/lastCan.png";
					next.src = contextPath + "/resources/images/CSH/next.png";
				}
				 
			}

            function firstField(rowdata, rowIndex) {
                if(rowdata.diffAmount != 0){
                    page4.modifyField(0, "<img  src=" + contextPath + "/resources/images/VAT/u164.png style='cursor:pointer;display:inline-block;margin-right:5px;height:15px;width:15px;'/>", true);
                }else{
                    page4.modifyField(0, "<p style='width:15px;height: 15px;'></p>", true);
                }
            }

            page4.modifyEvent(0, "template", firstField);

            
            function twoField(rowdata, rowIndex) {
                page4.modifyField(2, '<p style="text-align:left;">'+rowdata.contractName+'</p>', "template", rowIndex);
            }

            page4.modifyEvent(2, "template", twoField);
            
            function sixField(rowdata, rowIndex) {
                page4.modifyField(6, '<p style="text-align:right; width:120px;">'+formatCurrency(rowdata.billingAmount)+'</p>', "template", rowIndex);
            }

            page4.modifyEvent(6, "template", sixField);

            function nineField(rowdata, rowIndex) {
                page4.modifyField(8, '<p style="cursor:pointer;" onclick="spread_win(' + rowdata.cashflowId + ',' + rowIndex + ')"><img id="spreadWin_' + rowdata.cashflowId + '" style="cursor: pointer;width: 24px;height: 24px;margin-top: 0px;" src="' + contextPath + '/resources/images/VAT/u87.png" type="unSelected"/></p>', "template", rowIndex);
            }

            page4.modifyEvent(8, "template", nineField);


        },
        error: function () {
        }
    });
}

