/*--------------------------文档信息-------------------------------------------
///功能：      进项发票明细
///创建人：  王群
///创建时间：2011年05月31日
///修改人：  --------------
///修改时间：--------------
///详细说明：--------------
-----------------------------------------------------------------------------*/
//页面全局变量的定义
var strTableP041102 = "Tp041102";               //表格ID
var strPageP041102 = "divPageP041102";    //分页层的ID
var objSelRowP041102 = {};                          //选择行的数据
var intSelRowIDP041102 = 0;                        //选择行的ID
var objSelRowKpbh = "";                               //选择行的单据编号
var objPageParamP041102 = { sortfield: "", orderby: "", where: "", flag: 1 };     //分页控件使用

//窗口关闭按钮调用方法
function closeMyDlg(strDialog, strType, strTable) {
    //$("#" + strDialog).dialog("close");
    cihoDlgClose(strDialog);                //关闭弹出层
}
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**事件方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

//页面加载方法事件
function pageLoad_P041102() {
    try {
        //选择日期范围
        dateExtent_P041102();
        //供应商下拉信息的加载
        loadGysData_P041102()
        //药品下拉框信息的加载
        loadSpData_P041102();
        //获得表格的列属性
        objConfig = ParseData(window.external.DoOptions(strTableP041102, "GetTableConfig", "{}"));
        //格式化表中的数据
        setData_P041102(objConfig.colModel);
        //创建表格
        createGrid(strTableP041102, objConfig.colNames, objConfig.colModel, [], null, null, false, null);
        //添加事件
        addGridEvent_P041102();
        //调整表格的大小
        resizeGrid(strTableP041102, false, true);
        //创建分页
        createPage(strPageP041102, strTableP041102);
        //加载表格数据(触发查询按钮的点击事件)
        searchDataClick_P041102();
    } catch (e) { }
}

//查询按钮的事件
function searchDataClick_P041102() {
    try {
        if (!$("#cmbGysP041102").combobox("getValue")) {//"当前选择的供应商不存在，赋值为【全部供应商】！"
            $("#cmbGysP041102").combobox("setValue", "");
        }
        if (!$("#cmbSpP041102").combobox("getValue")) {//"当前选择的药品不存在，赋值为【全部药品】！"
            $("#cmbSpP041102").combobox("setValue", "");
        }
        //查询条件的取得
        objPageParamP041102.where = mySearchWhereJson();
        loadGridData_Page(objPageParamP041102);
    } catch (e) { }
}

//查看单据的事件
function viewReceipt_P041102() {
    if (intSelRowIDP041102 > 0) {
        if (objSelRowP041102.djbh.substr(0, 4) == "JXFP") {   //进项发票的查看单据
            showDialogP041102_jxfpd("divP041102_jxfpd", objSelRowP041102.djbh, objSelRowP041102.zt);
        }
        else if (objSelRowP041102.djbh.substr(0, 4) == "CGFH") {  //采购反货单的查看单据
            showDialogP011202_fhd("divP041102_cgfhd", objSelRowP041102.djbh);
        }
        else if (objSelRowP041102.djbh.substr(0, 4) == "CGTH") {//采购反货单的查看单据
            showDialogP011302_fhd("divP041102_cgthd", objSelRowP041102.djbh);
        }
        else if (objSelRowP041102.djbh.substr(0, 2) == "CG") {
            cgd(objSelRowP041102.djbh, "divP041102_cgd");
        }
    }
    else {
        //"请选择数据！"
        window.parent.cihoAlert(msg.other.selDataRow);
    }
}

//返回按钮的事件
function pageBack_P041102() {
    //改变标签的Name
    $(window.parent.document).find("#span_411").text("进项发票统计");
    //改变标签Iframe的Src
    $(window.parent.document).find("#idIframe-411").css("display", ""); //显示统计页面
    $(window.parent.document).find("#idIframe-41102").css("display", "none"); //隐藏明细页面
    $(window.parent.document).find("#idIframe-41102").attr("src", "");
}

//表格中的事件
function addGridEvent_P041102() {
    $("#" + strTableP041102).setGridParam({
        onSelectRow: function (rowid) {
            intSelRowIDP041102 = rowid;
            objSelRowP041102 = $(this).getRowData(rowid);
            objSelRowKpbh = objSelRowP041102.kpbh;
        },
        ondblClickRow: function () {
            viewReceipt_P041102();
        }
    });
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**事件方法 结束**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**自定义方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

//格式化表格中的数据
function setData_P041102(objP041102) {
    for (var i = 0; i < objP041102.length; i++) {
        if (objP041102[i].name == "ysje" || objP041102[i].name == "yisje") {    //【应收金额】【已收金额】的格式化
            objP041102[i].formatter = formatterP041102Money;
        }
        if (objP041102[i].name == "wsje") { //【余额】的格式化
            objP041102[i].formatter = formatterP041102WsMoney;
        }
    }
}

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

//选择日期范围方法
function dateExtent_P041102() {
    dateExtentCalculation("本月", "dateStartTimeP041102", "dateEndTimeP041102");
    $("#cmbDateExtentP041102").combobox({
        width: _iWidth100,
        listWidth: _iWidth100,
        valueField: "dm",
        textField: "mc",
        panelHeight: 102,
        editable: false,
        onSelect: function (option) {
            dateExtentCalculation(option.dm, "dateStartTimeP041102", "dateEndTimeP041102");
        },
        enterDown: function () {
            dateExtentCalculation($("#cmbDateExtentP041102").combobox("getValue"), "dateStartTimeP041102", "dateEndTimeP041102");
        }
    });
    //加载数据
    $("#cmbDateExtentP041102").combobox("loadData",
    [{ dm: "本月", mc: "本月", selected: true },
    { dm: "上一月", mc: "上一月" },
    { dm: "本周", mc: "本周" },
    { dm: "过去三个月", mc: "过去三个月" },
    { dm: "本年", mc: "本年"}]);
    var strDateItem = $(window.parent.document).find("#idIframe-41102").attr("dname");
    //设置默认日期为本月
    if (strDateItem != "") {
        $("#cmbDateExtentP021303").combobox("setValue", strDateItem);
        dateExtentCalculation(strDateItem, "dateStartTimeP041102", "dateEndTimeP041102");
    }
    else {
        var strStartTime = $(window.parent.document).find("#idIframe-41102").attr("sdate");
        var strEndTime = $(window.parent.document).find("#idIframe-41102").attr("edate");
        $("#cmbDateExtentP041102").combobox("setText", "自定义");
        $("#dateStartTimeP041102").val(strStartTime);
        $("#dateEndTimeP041102").val(strEndTime);
    }
    //释放内存
    strDateItem = null;
    strStartTime = null;
    strEndTime = null;
}

//供应商加载数据的方法
function loadGysData_P041102() {
    //添加变更事件
    $("#cmbGysP041102").combobox({
        width: _iWidth120,
        listWidth: _iWidth120,
        valueField: "dm",
        textField: "mc",
        onblur: function () {
            if ($("#cmbGysP041102").combobox("getText") == "") {
                $("#cmbGysP041102").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#cmbGysP041102").combobox("getText") == "全部供应商") {
                $("#cmbGysP041102").combobox("setText", "");
            }
        },
        enterDown: function () {

        }
    });
    //药品信息的取得
    var objDrug = getComboboxData("Tgysxx2");
    var strDrugID = $(window.parent.document).find("#idIframe-41102").attr("gysdm");
    var strDrugText = $(window.parent.document).find("#idIframe-41102").attr("gysmc");
    if (objDrug == "{}") {
        objDrug = [];
    }
    //加载数据
    objDrug.unshift({ "dm": "", "mc": "全部供应商", "selected": true });
    $("#cmbGysP041102").combobox("loadData", objDrug);
    //设定默认值
    $("#cmbGysP041102").combobox("setValue", strDrugID);
    $("#cmbGysP041102").combobox("setText", strDrugText);
    //释放内存
    objDrug = null;
    strDrugID = null;
}

//给药品加载数据
function loadSpData_P041102() {
    //添加变更事件
    $("#cmbSpP041102").combobox({
        width: _iWidth120,
        listWidth: _iWidth120,
        valueField: "dm",
        textField: "mc",
        onblur: function () {
            if ($("#cmbSpP041102").combobox("getText") == "") {
                $("#cmbSpP041102").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#cmbSpP041102").combobox("getText") == "全部药品") {
                $("#cmbSpP041102").combobox("setText", "");
            }
        },
        enterDown: function () {

        }
    });
    //药品信息的取得
    var objDrug = getComboboxData("Tspxx2");
    var strDrugID = $(window.parent.document).find("#idIframe-41102").attr("spdm");
    var strDrugText = $(window.parent.document).find("#idIframe-41102").attr("spmc");
    if (objDrug == "{}") {
        objDrug = [];
    }
    //加载数据
    objDrug.unshift({ "dm": "", "mc": "全部药品", "selected": true });
    $("#cmbSpP041102").combobox("loadData", objDrug);
    //设定默认值
    $("#cmbSpP041102").combobox("setValue", strDrugID);
    $("#cmbSpP041102").combobox("setText", strDrugText);
    //释放内存
    objDrug = null;
    strDrugID = null;
}

//应收金额和已收金额的格式化的方法
function formatterP041102Money(cellvalue, options, rowObject) {
    if (!cellvalue || cellvalue == "0") {
        return "&nbsp;";
    }
    else {
        return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
    }
}

//未收金额的格式化的方法
function formatterP041102WsMoney(cellvalue, options, rowObject) {
    if (isNaN(parseFloat(cellvalue))) {
        cellvalue = 0;
    }
    return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
}

//当基本资料数据有修改时 刷新相关的combobox的方法
function refreshMyCombobox() {
    var strModels = $("#idRefreshCombobox").val();
    var data = getComboboxData(strModels + "2");

    if (strModels == "Tspxx") {
        data.unshift({ dm: "", mc: "全部药品", "selected": true });
        reLoadCombobox("cmbSpP041102", data);
    }
    if (strModels == "Tgysxx") {
        data.unshift({ dm: "", mc: "全部供应商", "selected": true });
        reLoadCombobox("cmbGysP041102", data);
    }
}

//查询条件的取得
function mySearchWhereJson() {
    var strWhereJson = "";
    //查询条件的取得
    strWhereJson += "{\"sdate\":\"" + $("#dateStartTimeP041102").val() + "\",";
    strWhereJson += "\"edate\":\"" + $("#dateEndTimeP041102").val() + "\",";
    strWhereJson += "\"gysdm\":\"" + $("#cmbGysP041102").combobox("getValue") + "\",";
    strWhereJson += "\"spdm\":\"" + $("#cmbSpP041102").combobox("getValue") + "\"}";
    return strWhereJson.replace(/[{}]/g, "");
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**自定义方法 结束**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/



