/*--------------------------文档信息-------------------------------------------
///功能：      进项发票明细
///创建人：  王群
///创建时间：2011年05月31日
///修改人：  --------------
///修改时间：--------------
///详细说明：--------------
-----------------------------------------------------------------------------*/
//页面全局变量的定义
var strTableP041302 = "Tp041302";               //表格ID
var strPageP041302 = "divPageP041302";    //分页层的ID
var objSelRowP041302 = {};                          //选择行的数据
var intSelRowIDP041302 = 0;                        //选择行的ID
var objPageParamP041302 = { sortfield: "", orderby: "", where: "", flag: 1 };     //分页控件使用

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

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**事件方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

//页面加载事件
function pageLoad_P041302() {
    try {
        //选择日期范围
        dateExtent_P041302();
        //客户下拉信息的加载
        loadKhData_P041302()
        //药品下拉框信息的加载
        loadSpData_P041302();
        //获得表格的列属性
        objConfig = ParseData(window.external.DoOptions(strTableP041302, "GetTableConfig", "{}"));
        //格式化表中的数据
        setData_P041302(objConfig.colModel);
        //创建表格
        createGrid(strTableP041302, objConfig.colNames, objConfig.colModel, [], null, null, null, null);
        //添加事件
        addGridEvent_P041302();
        //调整表格的大小
        resizeGrid(strTableP041302, false, true);
        //创建分页
        createPage(strPageP041302, strTableP041302);
        //加载表格数据(触发查询按钮的点击事件)
        searchDataClick_P041302();
    } catch (e) { }
}

//查询按钮的事件
function searchDataClick_P041302() {
    try {
        if (!$("#cmbKhP041302").combobox("getValue")) {    //"当前选择的供应商不存在，赋值为【全部客户】！"
            $("#cmbKhP041302").combobox("setValue", "");
        }
        if (!$("#cmbSpP041302").combobox("getValue")) {//"当前选择的药品不存在，赋值为【全部药品】！"
            $("#cmbSpP041302").combobox("setValue", "");
        }

        //查询条件的取得
        objPageParamP041302.where = mySearchWhereJson();
        loadGridData_Page(objPageParamP041302);
    } catch (e) { }
}

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

//查看单据的事件
function viewReceipt_P041302() {
    if (intSelRowIDP041302 > 0) {
        if (objSelRowP041302.djbh.substr(0, 4) == "XXFP") {   //销项发票单据
            showDialogP041302_xxfpd("divP041302_xxfp", objSelRowP041302.djbh, objSelRowP041302.zt);
        }
        else if (objSelRowP041302.djbh.substr(0, 4) == "ZDXS" || objSelRowP041302.djbh.substr(0, 4) == "PSXS") {//终端和配送销售单
            showDialogP021103_xsd("divP041302_xsd", objSelRowP041302.djbh);
        }
        else if (objSelRowP041302.djbh.substr(0, 4) == "XSTH") { //终端和配送销售单
            showDialogP021103_thd("divP041302_thd", objSelRowP041302.djbh);
        }
    }
    else {
        //"请选择数据！"
        window.parent.cihoAlert(msg.other.selDataRow);
    }
}

//表格中的事件
function addGridEvent_P041302() {
    $("#" + strTableP041302).setGridParam({
        onSelectRow: function (rowid) {
            intSelRowIDP041302 = rowid;
            objSelRowP041302 = $(this).getRowData(rowid);
        },
        ondblClickRow: function () {
            viewReceipt_P041302();
        }
    });
}

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

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

//格式化一下表格中的数据
function setData_P041302(objP041302) {
    for (var i = 0; i < objP041302.length; i++) {
        if (objP041302[i].name == "ykje" || objP041302[i].name == "yikje") {        //money的格式化
            objP041302[i].formatter = formatterP041302Money;
        }
        if (objP041302[i].name == "ye") {       //余额的格式化
            objP041302[i].formatter = formatterP041302YeMoney;
        }
        if (objP041302[i].name == "xh") {       //隐藏序号列
            objP041302[i].hidden = true;
        }
    }
}

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


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

//给客户加载数据
function loadKhData_P041302() {
    //添加变更事件
    $("#cmbKhP041302").combobox({
        width: _iWidth120,
        listWidth: _iWidth120,
        valueField: "dm",
        textField: "mc",
        onblur: function () {
            if ($("#cmbKhP041302").combobox("getText") == "") {
                $("#cmbKhP041302").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#cmbKhP041302").combobox("getText") == "全部客户") {
                $("#cmbKhP041302").combobox("setText", "");
            }
        },
        afterChange: function (newValue, newText) {
            $(this).combobox("setText", newText.replace(/&nbsp;/g, ""));
        }
    });

    //客户信息的取得
    var objProvider = getComboboxData("Tkhxx2");
    var strProviderID = $(window.parent.document).find("#idIframe-41302").attr("khdm");
    var strProviderText = $(window.parent.document).find("#idIframe-41302").attr("khmc");
    if (objProvider == "{}") {
        objProvider = [];
    }
    //加载数据
    objProvider.unshift({ "dm": "", "mc": "全部客户", "selected": true });
    $("#cmbKhP041302").combobox("loadData", objProvider);
    //设定默认值
    $("#cmbKhP041302").combobox("setValue", strProviderID);
    $("#cmbKhP041302").combobox("setText", strProviderText);
    //释放内存
    objProvider = null;
    strProviderID = null;
    strProviderText = null;
}

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

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

//money的格式化方法
function formatterP041302Money(cellvalue, options, rowObject) {
    if (!cellvalue || cellvalue == "0") {
        return "&nbsp;";
    }
    else {
        return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
    }
}

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

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

    if (strModels == "Tspxx") {
        data.unshift({ dm: "", mc: "全部药品", "selected": true });
        reLoadCombobox("cmbSpP041302", data);
    }
    if (strModels == "Tkhxx") {
        data.unshift({ dm: "", mc: "全部客户", "selected": true });
        reLoadCombobox("cmbKhP041302", data);
    }
    //释放内存
    strModels = null;
    data = null;
}

//查询条件的取得
function mySearchWhereJson() {
    var strWhereJson = "";                  //存放查询条件的变量
    //查询条件的取得
    strWhereJson = "{\"sdate\":\"" + $("#dateStartTimeP041302").val() + "\",";
    strWhereJson += "\"edate\":\"" + $("#dateEndTimeP041302").val() + "\",";
    strWhereJson += "\"khdm\":\"" + $("#cmbKhP041302").combobox("getValue") + "\",";
    strWhereJson += "\"spdm\":\"" + $("#cmbSpP041302").combobox("getValue") + "\"}";
    return strWhereJson.replace(/[{}]/g, "");
}

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



