<%@ Page Language="c#" CodeBehind="InputFeesBatchManage.aspx.cs" AutoEventWireup="false" Inherits="M_Main.ChargesNew.InputFeesBatchManage" %>

<%@ Register TagPrefix="dslbc" Namespace="DualSelectListBoxControl" Assembly="DualSelectListBoxControl" %>
<%@ Register TagPrefix="webdiyer" Namespace="Wuqi.Webdiyer" Assembly="AspNetPager" %>
<!DOCTYPE HTML >
<html>
<head>
    <title></title>
    <script type="text/javascript" src="../jscript/DateControl.js"></script>
    <script type="text/javascript" src="../jscript/JSClient.js"></script>
    <script type="text/javascript" src="../jscript/ajax.js"></script>
    <script type="text/javascript" src="../jscript/Keydown.js" event="onkeydown" for="document"></script>

    <script type="text/javascript" src="../Jscript-Ui/jquery-easyui-1.4.4/jquery.min.js"></script>
    <script src="../jscript/JSClient.js" type="text/javascript"></script>
    <script src="../jscript/jquery.tool.new.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="../Jscript-Ui/jquery-easyui-1.4.4/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../Jscript-Ui/jquery-easyui-1.4.4/themes/icon.css" />
    <script type="text/javascript" src="../Jscript-Ui/jquery-easyui-1.4.4/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../Jscript-Ui/jquery-easyui-1.4.4/locale/easyui-lang-zh_CN.js"></script>
    <link href="../css/framesearch.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="../Jscript-Ui/JQForm/JQForm.js"></script>
    <script src="../jscript/Dialog.js" type="text/javascript"></script>

    <link href="../css/framesearch_old.css" type="text/css" rel="stylesheet" />
    <link href="../css/button.css" rel="stylesheet" />
    <script src="../jscript/DateFormat.js" type="text/javascript"></script>
    <script src="../jscript/format.js" type="text/javascript"></script>
    <script language="javascript">
		<!--

    function btnSelCost_OnClick() {
        var tmpCostGeneType = InputFeesBatchManage.CostGeneType.value;
        var varReturn;

        varReturn = showModalDlg("../dialog/CorpCommCostDlg.aspx?CostGeneType=" + tmpCostGeneType + "&Ram=" + Math.random(), "", 500, 400);


        //alert("["+varReturn+"]");
        if (varReturn != "") {//**获得返回 刷新
            var varObjects = varReturn.split("\t");

            InputFeesBatchManage.CostID.value = varObjects[0];
            InputFeesBatchManage.CostName.value = varObjects[2];
            InputFeesBatchManage.hiCostName.value = varObjects[2];

            return true;
        }

        return false;
    }

    function btnOK_Onclick() {
        if (InputFeesBatchManage.CostID.value == "") {
            HDialog.Info("请选择费用名称!");
            InputFeesBatchManage.btnSelCost.focus();
            return false;
        }

        if (InputFeesBatchManage.RbFeesDate2.checked) {
            if (InputFeesBatchManage.FeesStateDate.value == "") {
                HDialog.Info("请输入开始时间!");
                InputFeesBatchManage.FeesStateDate.focus();
                return false;
            }
        }

        if (InputFeesBatchManage.FeesEndDate.value == "") {
            HDialog.Info("请输入结束时间!");
            InputFeesBatchManage.FeesEndDate.focus();
            return false;
        }
        if (InputFeesBatchManage.FeesDueDate.value == "") {
            HDialog.Info("请输入费用时间!");
            InputFeesBatchManage.FeesDueDate.focus();
            return false;
        }

        if (InputFeesBatchManage.RbAccDate2.checked) {
            if (InputFeesBatchManage.AccountsDueDate.value == "") {
                HDialog.Info("请输入应交时间!");
                InputFeesBatchManage.AccountsDueDate.focus();
                return false;
            }
        }

        return true;

    }

    function FeesDate_OnClick() {

        if (InputFeesBatchManage.RbFeesDate1.checked) {
            $('#IsFeesDate').val('1');
            InputFeesBatchManage.FeesStateDate.disabled = true
        }
        else {
            $('#IsFeesDate').val('0');
            InputFeesBatchManage.FeesStateDate.disabled = false;
        }

    }

    function AccDate_OnClick() {
        if (InputFeesBatchManage.RbAccDate1.checked) {
            $('#IsAccDate').val('1');
            InputFeesBatchManage.AccountsDueDate.disabled = true
        }
        else {
            $('#IsAccDate').val('0');
            InputFeesBatchManage.AccountsDueDate.disabled = false;
        }
    }

    //-->
    </script>
    <script language="javascript" type="text/javascript" src="../jscript/DatePicker/WdatePicker.js"></script>

</head>
<body>

    <form id="InputFeesBatchManage" method="post" runat="server">
        <input style="z-index: 0; width: 16px;" id="CostGeneType" size="1" type="hidden"
            name="CostGeneType" runat="server" />
        <input id="IsFeesDate" name="IsFeesDate" type="hidden" value="0" runat="server" />
        <input id="IsAccDate" name="IsAccDate" type="hidden" value="0" runat="server" />
        <input id="RoomSQLEx" name="RoomSQLEx" type="hidden" runat="server" />
        <input id="IsSplit" name="IsSplit" type="hidden" runat="server" />
         <input id="IsShow" name="IsShow" type="hidden" runat="server" />
         <input id="FeesBatchCalc" name="FeesBatchCalc" type="hidden" runat="server" />
        
        <div id="SearchDlg" class="easyui-dialog" title="费用试算" data-options="iconCls:'icon-search',closed: true,modal:true"
            style="width: 800px; height: 400px; overflow-y: auto">
            <table class="DialogTable" style="width: 100%">
                <tr>
                    <td align="center" style="background-color: #e6e6e6"><span style="font-size: 16px">第一步：选择费项</span></td>
                </tr>
                <tr>
                    <td valign="top">
                        <table class="DialogTable">
                            <tr>
                                <td class="TdTitle">收费项目</td>
                                <td class="TdContentSearch">
                                    <input id="CostName"
                                        name="CostName" class="easyui-searchbox" searcher="SelCost" data-options="editable:false" runat="server"><input id="hiCostName" style="width: 8px; height: 22px" type="hidden"
                                            size="1" name="hiCostName" runat="server"><input id="CostID" style="width: 8px; height: 22px" type="hidden"
                                                size="1" name="CostID" runat="server"></td>
                                <td class="TdTitle">收费标准</td>
                                <td class="TdContentSearch">按照每个客户绑定的收费标准</td>
                            </tr>
                        </table>
                    </td>
                </tr>

                <tr>
                    <td align="center" style="background-color: #e6e6e6"><span style="font-size: 16px">第二步：选择时间</span></td>
                </tr>

                <tr>
                    <td valign="top">
                        <table class="DialogTable">
                            <tr>
                                <td class="TdTitle">开始时间</td>
                                <td class="TdContentSearch">
                                    <input id="RbFeesDate1" checked type="radio" name="RbFeesDate" runat="server" onclick="FeesDate_OnClick();">自动提取<input id="RbFeesDate2" type="radio" name="RbFeesDate" runat="server" onclick="    FeesDate_OnClick();">自定义<input style="z-index: 0; width: 150px;" id="FeesStateDate" class="Wdate"
                                        onkeypress="CheckSmallDate();" onclick="WdatePicker()" maxlength="50" size="26" name="FeesStateDate" runat="server" disabled></td>
                                <td class="TdTitle">结束时间</td>
                                <td class="TdContentSearch">
                                    <input style="z-index: 0; width: 150px;" id="FeesEndDate" class="Wdate"
                                        onkeypress="CheckSmallDate();" onclick="WdatePicker()" maxlength="50" size="26" name="FeesEndDate"
                                        runat="server"></td>
                            </tr>
                            <tr>
                                <td class="TdTitle">费用时间</td>
                                <td class="TdContentSearch">
                                    <input style="z-index: 0; width: 150px;" id="FeesDueDate" class="Wdate"
                                        onclick="javascript: WdatePicker()" maxlength="50" size="26" name="FeesDueDate"
                                        runat="server"></td>
                                <td class="TdTitle">应交时间</td>
                                <td class="TdContentSearch">
                                    <input id="RbAccDate1" value="on" checked type="radio" name="RbAccDate" runat="server" 
                                        onclick="AccDate_OnClick();">以开始时间为准<input id="RbAccDate2" type="radio" name="RbAccDate" runat="server" onclick="AccDate_OnClick();">自定义<input style="z-index: 0; width: 150px;" id="AccountsDueDate" class="Wdate"
                                            onclick="javascript: WdatePicker()" maxlength="50" size="26" name="AccountsDueDate" runat="server" disabled></td>
                            </tr>
                        </table>
                    </td>
                </tr>

                <tr>
                    <td align="center" style="background-color: #e6e6e6"><span style="font-size: 16px">第三步：选择房号</span></td>
                </tr>
                <tr>
                    <td valign="top" align="center">
                        <table class="DialogTable">
                            <tr>
                                <td class="TdTitle">请选择房号范围</td>
                                <td class="TdContentSearch" colspan="3">
                                    <table class="DialogTable">
                                        <tr>
                                            <td width="30%"></td>
                                            <td>
                                                <asp:DropDownList ID="DListRange" runat="server" AutoPostBack="True">
                                                    <asp:ListItem Value="1">按楼宇</asp:ListItem>
                                                    <asp:ListItem Value="2">按单元</asp:ListItem>
                                                    <asp:ListItem Value="3">按楼层</asp:ListItem>
                                                </asp:DropDownList></td>
                                            <td width="30%"></td>
                                        </tr>
                                    </table>
                                    <dslbc:DualSelectListBox ID="DualListField" runat="server">
                                        <RightListStyle Width="200px" Height="250px"></RightListStyle>
                                        <LeftListStyle Width="200px" Height="250px"></LeftListStyle>
                                    </dslbc:DualSelectListBox>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td align="center" style="background-color: #e6e6e6"><span style="font-size: 16px">第四步：选择客户</span></td>
                </tr>

                <tr>
                    <td valign="top">
                        <table class="DialogTable">
                            <tr>
                                <td class="TdTitle">客户类别</td>
                                <td class="TdContentSearch">
                                    <select style="z-index: 0" id="CustTypeID" name="CustTypeID" runat="server">
                                        <option selected></option>
                                    </select></td>
                                <td class="TdTitle"></td>
                                <td class="TdContentSearch"></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td align="center" style="background-color: #e6e6e6"><span style="font-size: 16px">第五步：费用试算</span></td>
                </tr>
                <tr>
                    <td valign="top" align="center">
                        <table class="DialogTable">
                            <tr>
                                <td align="center">
                                     <a href="#" id="search" class="easyui-linkbutton" data-options="iconCls:'icon-edit'" onclick="FeesBatchCalc();">试算</a>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                </table>
              </div>
              <div id="SearchDlg2" class="easyui-dialog" title="费用新增" data-options="iconCls:'icon-search',closed: true,modal:true"
                style="width: 600px; height: 100px; overflow-y: auto">
                <table class="DialogTable" style="width: 100%">              
                <tr>
                    <td valign="top">
                        <table class="DialogTable">
                            <tr>
                                <td align="center">
                                    <input  ID="CkIsSplit" runat="server"  type="checkbox"></input>按自然月分解&nbsp;
                                      <a href="#" id="bsave" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="FeesIns();">确定新增</a>
                                 
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
                 
        </div>
        <div class="SearchContainer" id="TableContainer">
        </div>
        <script type="text/javascript">

            function InitFunction() {
                var h = $(window).height();
                $("#TableContainer").css("height", h + "px");

            }
            InitFunction();

            function SelCost() {
            
                var conent = "../dialogNew/CorpCommCostDlg.aspx";

                HDialog.Open('700', '400', conent, '收费项目选择', false, function callback(_Data) {


                    if (_Data != "") {//**获得返回 刷新
                        //var varObjects = _Data.split("\t");

                        var data = JSON.parse(_Data);
                        var data = JSON.parse(_Data);

                        if (data.SysCostSign == "H0000") {
                            HDialog.Info('批量新增费用不能选择合同类费用');
                        }
                        else {
                            $('#CostName').searchbox("setValue", data.CostName);
                            $('#CostID').val(data.CostID);
                            $('#hiCostName').val(data.CostName);
                        }

                    }
                });

            }
            var frozenColumns = [[
            { field: 'CustName', title: '客户名称', width: 100, align: 'left', sortable: true },
            { field: 'RoomSign', title: '房屋编号', width: 180, align: 'left', sortable: true },
            { field: 'RoomName', title: '房屋名称', width: 180, align: 'left', sortable: true },
            ]];
            var column = [[
            { field: 'CostName', title: '费用名称', width: 100, align: 'left', sortable: true },
            { field: 'StanName', title: '标准名称', width: 100, align: 'left', sortable: true },
            {
                field: 'FeeDueYearMonth', title: '费用日期', width: 100, align: 'left', sortable: true
            },
            {
                field: 'AccountsDueDate', title: '应收日期', width: 100, align: 'left', sortable: true, formatter: function (value, row, index) {

                    var str = formatDate(row.AccountsDueDate, "yyyy-MM-dd");
                    return str;
                }
            },
            {
                field: 'FeesStateDate', title: '开始日期', width: 100, align: 'left', sortable: true, formatter: function (value, row, index) {

                    var str = formatDate(row.FeesStateDate, "yyyy-MM-dd");
                    return str;
                }
            },
            {
                field: 'FeesEndDate', title: '结束日期', width: 100, align: 'left', sortable: true, formatter: function (value, row, index) {

                    var str = formatDate(row.FeesEndDate, "yyyy-MM-dd");
                    return str;
                }
            },
            { field: 'DueAmount', title: '应收金额', width: 100, align: 'left', sortable: true },
             { field: 'ErrorMsg', title: '返回信息', width: 200, align: 'left', sortable: true }
            ]]


            var toolbar = [
                {
                    text: '费用试算',
                    iconCls: 'icon-edit',
                    handler: function () {

                        $('#IsShow').val("1");
                        $('#FeesBatchCalc').val('0');
                        $('#SearchDlg').parent().appendTo($("form:first"));
                        $('#SearchDlg').dialog('open');
                        

                    }
                }, '-',
                   {
                       text: '导出试算结果',
                       iconCls: 'icon-page_white_excel',
                       handler: function () {
                           var rows = $('#TableContainer').datagrid('getRows');
                           if (rows.length>0) {
                               window.location.href = 'ExcelFeesBatchCre.aspx';
                           }
                           else {                              
                               HDialog.Info('请先试算费用!');
                           }

                       }
                   }, '-',
                   {
                       text: '确定导入',
                       iconCls: 'icon-save',
                       handler: function () {
                           var rows = $('#TableContainer').datagrid('getRows');
                           if (rows.length > 0) {
                               $('#SearchDlg2').parent().appendTo($("form:first"))
                               $('#SearchDlg2').dialog('open');
                           }
                           else {

                               HDialog.Info('请先试算费用!');
                           }                                                   
                       }
                   }
            ];

            function LoadList() {
                
                $("#TableContainer").datagrid({
                    url: '/HM/M_Main/HC/DataPostControl.aspx',
                    method: "post",
                    nowrap: false,
                    pageSize: top.ListPageSize,
                    pageList: top.ListPageList,
                    columns: column,
                    frozenColumns: frozenColumns,
                    fitColumns: true,
                    remoteSort: false,
                    singleSelect: true,
                    pagination: true,
                    width: "100%",
                    toolbar: toolbar,
                    sortOrder: "asc",
                    singleSelect: true,
                    selectOnCheck: false,
                    checkOnSelect: false,
                    rownumbers: true,
                    border: false,
                    toolbar: toolbar,
                    sortOrder: "asc",
                    onBeforeLoad: function (param) {
                        param = $.JQForm.GetParam("Fees", "FeesBatchCalc", "TableContainer", param);
                    },
                    onLoadSuccess: function (data) {

                        if ($('#IsShow').val() == "1") {
                            $('#SearchDlg').parent().appendTo($("form:first"));
                            $('#SearchDlg').dialog('open');
                            
                        }

                    }
                });
                
                              
            }
            
            LoadList();

            function FeesBatchCalc()
            {

                if (InputFeesBatchManage.CostID.value == "") {
                    HDialog.Info("请选择费用名称!");
                    InputFeesBatchManage.btnSelCost.focus();
                    return false;
                }

                if (InputFeesBatchManage.RbFeesDate2.checked) {
                    if (InputFeesBatchManage.FeesStateDate.value == "") {
                        HDialog.Info("请输入开始时间!");
                        InputFeesBatchManage.FeesStateDate.focus();
                        return false;
                    }
                }

                if (InputFeesBatchManage.FeesEndDate.value == "") {
                    HDialog.Info("请输入结束时间!");
                    InputFeesBatchManage.FeesEndDate.focus();
                    return false;
                }
                if (InputFeesBatchManage.FeesDueDate.value == "") {
                    HDialog.Info("请输入费用时间!");
                    InputFeesBatchManage.FeesDueDate.focus();
                    return false;
                }

                if (InputFeesBatchManage.RbAccDate2.checked) {
                    if (InputFeesBatchManage.AccountsDueDate.value == "") {
                        HDialog.Info("请输入应交时间!");
                        InputFeesBatchManage.AccountsDueDate.focus();
                        return false;
                    }
                }

                var SelAll = document.getElementById("DualListField_RightBox").length;
                var tmpSQL1 = "";

                for (var i = 0; i < SelAll; i++) {
                    var strval = document.getElementById("DualListField_RightBox").options[i].value//参数值


                    if (strval != "") {
                        var arrval = strval.split(',');

                        iBuildSNum = arrval[0];
                        iUnitSNum = arrval[1];
                        iFloorSNum = arrval[2];

                        if (i == 0) {
                            //按楼宇						
                            tmpSQL1 = tmpSQL1 + " and  (BuildSNum = " + iBuildSNum + "";

                            //**按单元
                            if (iUnitSNum != 0) {
                                tmpSQL1 = tmpSQL1 + " and UnitSNum = " + iUnitSNum + "";
                            }
                            //**按楼层
                            if (iFloorSNum != 0) {
                                tmpSQL1 = tmpSQL1 + " and FloorSNum = " + iFloorSNum + "";
                            }

                            tmpSQL1 = tmpSQL1 + ")";
                        } else {
                            //按楼宇						
                            tmpSQL1 = tmpSQL1 + " or  (BuildSNum = " + iBuildSNum + "";

                            //**按单元
                            if (iUnitSNum != 0) {
                                tmpSQL1 = tmpSQL1 + " and UnitSNum = " + iUnitSNum + "";
                            }
                            //**按楼层
                            if (iFloorSNum != 0) {
                                tmpSQL1 = tmpSQL1 + " and FloorSNum = " + iFloorSNum + "";
                            }

                            tmpSQL1 = tmpSQL1 + ")";
                        }
                        
                    }
                }

                $('#IsShow').val("0");
                $('#SearchDlg').dialog('close');

                $('#FeesBatchCalc').val('1');
                $('#RoomSQLEx').val(tmpSQL1);

                
                LoadList();
            }

            function FeesIns()
            {
                if ($("#CkIsSplit").is(':checked'))
                {
                    $('#IsSplit').val('1');
                }


                //保存到隐藏文本框;
                $.tool.DataPost('Fees', "FeesIns", $('#InputFeesBatchManage').serialize(),
                function Init() {
                  
                },
                function callback(_Data) {
                    var data = _Data.split('|');
                    if (data[0] == "true")
                    {
                       HDialog.Info("导入成功");
                        LoadList();
                    }

                },
                function completeCallback() {
                   
                },
                function errorCallback() {

                });
            }

            
        </script>
    </form>
</body>
</html>
