/*-------------------------------文档信息-----------------------------------
///功能：应收税金对账
///创建人: 翟新乐
///创建时间：2011-07-01
///修改人：------------------------
///修改时间：-----------------------
///修改原因：-----------------------
///详细说明：-----------------------
---------------------------------------------------------------------*/
//页面全局变量的定义
var strTableP041401 = "Tp041401";   //表格ID
var objSelRowP041401 = {};          //选择行的数据
var intSelRowIDP041401 = 0;         //选择行的ID
var strPageP041401 = "divPageP041401";
var objPageParamP041401 = { sortfield: "", orderby: "", where: "", flag: 0 };  //分页控件使用

//窗口关闭按钮调用方法
function closeMyDlg(strDialog, strType, strTable) {
    //$("#" + strDialog).dialog("close");
    cihoDlgClose(strDialog);
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**事件方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
//页面加载方法
function pageLoad_P041401() {
    //选择日期范围
    dateExtent_P041401();
    //KP下拉框信息的加载
    loadKpdwData_P041401();
    var objConfig = ParseData(window.external.DoOptions(strTableP041401, "GetTableConfig", "{}"));
    //添加列格式化方法
    for (var i = 0; i < objConfig.colModel.length; i++) {
        if (objConfig.colModel[i].name == "fpje" || objConfig.colModel[i].name == "xxsj" || objConfig.colModel[i].name == "jxdk"
            || objConfig.colModel[i].name == "sjtz" || objConfig.colModel[i].name == "yjsj") {
            objConfig.colModel[i].formatter = formatterP041401Money;
        }
        if (objConfig.colModel[i].name == "wjsj") {
            objConfig.colModel[i].formatter = formatterWjsjMoney;
        }
        if (objConfig.colModel[i].name == "xh") {
            objConfig.colModel[i].hidden = true;
        }
    }
    //创建表格
    createGrid(strTableP041401, objConfig.colNames, objConfig.colModel, [], null, null, true);
    //表格事件的添加
    addGridEvent_P041401();
    resizeGrid(strTableP041401, true, true);
    //创建分页
    createPage(strPageP041401, strTableP041401);
    //加载表格数据(触发查询按钮的点击事件)
    searchDataClick_P041401();
    //resizeGrid(strTableP041401);
    objConfig = {};
}

//查询按钮事件
function searchDataClick_P041401() {
    try {
        objPageParamP041401.sortfield = ""; //排序字段
        objPageParamP041401.orderby = "";     //排序顺序
        objPageParamP041401.flag = 1;             //表示点击查询按钮
        loadGridDataP041401();                     //加载数据
        objPageParamP041401.flag = 0;              //使用完后，设置为零
        //resizeGrid(strTableP041401);
    } catch (e) { }
}

//加载数据,合计
function loadGridDataP041401() {
    var objResult = [];
    objPageParamP041401.where = getSelJson_P041401();
    objResult = loadGridData_Page(objPageParamP041401);
    //后台返回的合计
    if (objResult) {
        if (objResult.Records.length > 0) {
            $("#" + strTableP041401).footerData("set", { rn: "合计",
                fpje: objResult.fpje.toFixed(window.parent.strMoneyPlace),
                xxsj: objResult.xxsj.toFixed(window.parent.strMoneyPlace),
                jxdk: objResult.jxdk.toFixed(window.parent.strMoneyPlace),
                sjtz: objResult.sjtz.toFixed(window.parent.strMoneyPlace),
                yjsj: objResult.yjsj.toFixed(window.parent.strMoneyPlace)
            }, false);
        }
        else {
            $("#" + strTableP041401).footerData("set", { rn: "合计", fpje: "&nbsp;", xxsj: "&nbsp;", jxdk: "&nbsp;", sjtz: "&nbsp;", yjsj: "&nbsp;" }, false);
        }
    }
    objResult = {};
    intSelRowIDP041401 = "";
    objSelRowP041401 = {};
}

//取得查询条件
function getSelJson_P041401() {
    if (!$("#cmbKpdwP041401").combobox("getValue")) {
        $("#cmbKpdwP041401").combobox("setValue", "");
    }
    //查询条件的取得
    var strWhereJson = "";
    strWhereJson = "\"sdate\":\"" + $("#dateStartTimeP041401").val() + "\",";
    strWhereJson += "\"edate\":\"" + $("#dateEndTimeP041401").val() + "\",";
    strWhereJson += "\"kpdwdm\":\"" + $("#cmbKpdwP041401").combobox("getValue") + "\"";
    return strWhereJson;
}

//查看单据按钮的方法
function viewReceipt_P041401() {
    try {
        if (intSelRowIDP041401) {
            if (objSelRowP041401.djname == "销项发票" || objSelRowP041401.djname == "销项退票") {
                //销项发票
                showDialogP041302_xxfpd("divP041401", objSelRowP041401.djbh);
            }
            else if (objSelRowP041401.djname == "进项抵扣") {
                //进项抵扣
                showDialogP041201_jxfpdkd("divP041401", objSelRowP041401.djbh);
            }
            else if (objSelRowP041401.djname == "进项发票") {
                //进项发票
                showDialogP041102_jxfpd("divP041401", objSelRowP041401.djbh);
            }
            else if (objSelRowP041401.djname == "税金支付") {
                //税金支付
                showDialogP040301_zfd("divP041401", objSelRowP041401.djbh);
            }
            else if (objSelRowP041401.djname == "税金增加" || objSelRowP041401.djname == "税金减少") {
                //税金调整
                showDialogP040401_tzd("divP041401", objSelRowP041401.djbh);
            }
        }
        else {
            window.parent.cihoAlert(msg.other.selDataRow);
        }
    } catch (e) { }
}

//返回按钮的方法
function pageBack_P041401() {
    //改变标签的Name
    $(window.parent.document).find("#span_414").text("往来税金核算");
    //改变标签Iframe的Src
    $(window.parent.document).find("#idIframe-414").css("display", ""); //显示统计页面
    $(window.parent.document).find("#idIframe-41401").css("display", "none"); //隐藏明细页面
    $(window.parent.document).find("#idIframe-41401").attr("src", "");
}

//日期范围修改方法
function dateTimeChange_P041401() {
    if ($("#cmbDateExtentP041401").combobox("getText") != "自定义") {
        $("#cmbDateExtentP041401").combobox("setValue", "");
        $("#cmbDateExtentP041401").combobox("setText", "自定义");
    }
}

/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑**事件方法 结束**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**自定义方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

//选择日期范围
function dateExtent_P041401() {
    $("#cmbDateExtentP041401").combobox({
        valueField: "dm",
        textField: "mc",
        editable: false,
        panelHeight: 82,
        onSelect: function (option) {
            dateExtentCalculation(option.dm, "dateStartTimeP041401", "dateEndTimeP041401");
        },
        enterDown: function () {
            dateExtentCalculation($(this).combobox("getValue"), "dateStartTimeP041401", "dateEndTimeP041401");
            //searchDataClick_P041401();
        }
    });
    //加载数据
    $("#cmbDateExtentP041401").combobox("loadData", [{ dm: "本月", mc: "本月", selected: true }, { dm: "上一月", mc: "上一月" }, { dm: "过去三个月", mc: "过去三个月" }, { dm: "本年", mc: "本年"}]);

    $("#cmbDateExtentP041401").combobox("setValue", $(window.parent.document).find("#idIframe-41401").attr("dname"));
    $("#cmbDateExtentP041401").combobox("setText", $(window.parent.document).find("#idIframe-41401").attr("dname"));
    $("#dateStartTimeP041401").val($(window.parent.document).find("#idIframe-41401").attr("sdate"));
    $("#dateEndTimeP041401").val($(window.parent.document).find("#idIframe-41401").attr("edate"));
}

//开票单位下拉框信息的加载
function loadKpdwData_P041401() {
    $("#cmbKpdwP041401").combobox({
        valueField: "dm",
        textField: "mc",
        onblur: function () {
            if ($("#cmbKpdwP041401").combobox("getText") == "") {
                $("#cmbKpdwP041401").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#cmbKpdwP041401").combobox("getText") == "全部开票单位") {
                $("#cmbKpdwP041401").combobox("setText", "");
            }
        }
    });

    //药品信息的取得
    var objDrug = getComboboxData('Tkpdwxx2');
    if (objDrug == "{}") {
        objDrug = [];
    }
    //加载数据
    objDrug.unshift({ "dm": "", "mc": "全部开票单位" });
    $("#cmbKpdwP041401").combobox("loadData", objDrug);    
    //设定默认值
    $("#cmbKpdwP041401").combobox("setValue",  $(window.parent.document).find("#idIframe-41401").attr("kpdwdm"));
    $("#cmbKpdwP041401").combobox("setText", $(window.parent.document).find("#idIframe-41401").attr("kpdwmc"));
    objDrug = {};
}

//表格事件的添加
function addGridEvent_P041401() {
    $("#" + strTableP041401).setGridParam({        
        onSelectRow: function (rowId) { //当前选择行数据取得
            intSelRowIDP041401 = rowId;
            objSelRowP041401 = $(this).getRowData(rowId);
        },
        ondblClickRow: function (rowId) {   //双击事件
            viewReceipt_P041401();
        }
    });
}

//dj,je格式化money
function formatterP041401Money(cellvalue, options, rowObject) {
    if ((parseFloat(cellvalue)) != "0") {
        return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
    }
    else {
        return "&nbsp;";
    }
}

//格式化未收金额
function formatterWjsjMoney(cellvalue, options, rowObject) {
    if (!isNaN(parseFloat(cellvalue))) {
        return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
    }
    else {
        return "&nbsp;";
    }
}
/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑**自定义方法 结束**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/