<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TaxRateSetting.aspx.cs" Inherits="M_Main.ChargesNew.TaxRateSetting" %>

<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript" src="../Jscript-Ui/jquery-easyui-1.4.4/jquery.min.js"></script>
    <script src="../jscript/jquery.tool.js" type="text/javascript"></script>
    <script src="../jscript/JSClient.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>
    <script src="../jscript/Dialog.js" type="text/javascript"></script>
    <link href="../css/button.css" type="text/css" rel="stylesheet" />

    <script type="text/javascript" src="../Jscript-Ui/JQForm/JQForm.js"></script>
    <script type="text/javascript" src="../Jscript-Ui/hplus/js/plugins/layer/layer.min.js"></script>

    <link href="../css/framesearch.css" type="text/css" rel="stylesheet" />

    <script type="text/javascript" src="../jscript/jquery.ztree.core-3.5.js"></script>
    <link href="../css/style.css" type="text/css" rel="stylesheet" />
    <link href="../css/zTreeStyle/zTreeStyle.css" type="text/css" rel="stylesheet" />
    <link href="../css/workflow.css" type="text/css" rel="stylesheet" />
    <script src="../jscript/DateFormat.js" type="text/javascript"></script>
    <script src="../jscript/CloseAjaxCache.js" type="text/javascript"></script>
    <style type="text/css">
        body {
            margin: 0px;
            margin-top: 0px;
            overflow: hidden;
            font-family: 微软雅黑;
            background-color: #ffffff;
        }

        .Container {
            width: 100%;
            height: auto;
            font-size: 12px;
            font-family: 微软雅黑;
        }

        .ContainerLeft {
            float: left;
            width: 25%;
            padding-right: 5px;
            overflow-y: auto;
            border-right: 1px solid #cccccc;
        }

        .ContainerRight {
            float: left;
            width: 73.5%;
        }

        textarea {
            height: 22px;
            resize: none;
            border: 1px solid #cccccc;
            width: 200px;
        }
    </style>
</head>
<body>
    <form id="frmForm" runat="server">

        <div id="SearchDlg" class="easyui-dialog" title="筛选条件" data-options="iconCls:'icon-search',closed: true,modal:true" style="width: 500px; height: 140px; padding: 10px;">
            <table style="width: 100%; font-size: 12px; font-family: 微软雅黑;">
                <tr>
                    <td class="TdTitle">所属项目</td>
                    <td class="TdContent">
                        <textarea id="CostName" name="CostName" class="easyui-validatebox" onclick="SelCost();"></textarea>
                        <input id="CorpCostID" name="CorpCostID" value="" type="hidden" />
                    </td>
                </tr>
                <tr style="height: 10px;">
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td colspan="8" align="center"><a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="LoadList();">确定筛选</a>
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" onclick="btnClear();">清空</a>
                    </td>
                </tr>
            </table>
        </div>

        <div class="Container">
            <div id="ContainerLeft" class="ContainerLeft" style="height: 500px;">
                <div id="TableContainerTree">
                </div>
            </div>
            <div id="ContainerRight" class="ContainerRight">
                <div style="background-color: #cccccc;" id="TableContainer">
                </div>
            </div>
        </div>

         <div id="DlgMemo" class="easyui-dialog" title="备注" data-options="iconCls:'icon-search',closed: true,modal:true" style="width: 500px; height: 120px; padding: 10px;">
            <table cellpadding="0" cellspacing="0" border="0" width="100%" style='color: Red'>
                <tr>
                    <td rowspan="4" width="40px" valign="top" >备注：</td>
                    <td>1.第一次设置某项目收费科目税率时，请点新增；
                    </td>
                </tr>
                <tr><td style='line-height: 20px'>2.以后变更时，请点变更； </td>
                </tr>
                <tr><td style='line-height: 20px'>3.未审核和已退回记录可删除。 </td>
                </tr>
            </table>
        </div>

        <input id="hidID" type="hidden" size="2" name="hidID" runat="server" />
        <input id="OrganCode" type="hidden" size="2" name="OrganCode" runat="server" />
        <input id="OrganName" type="hidden" size="2" name="OrganName" runat="server" />
        <input id="InPopedom" type="hidden" name="InPopedom" runat="server" />
        <input id="TaxRateSettingID" type="hidden" name="TaxRateSettingID" runat="server" />
        <script type="text/javascript">
            //选择费用科目
            function SelCost() {
                HDialog.Open('700', '450', "../dialogNew/MultiCorpCostDlg.aspx" + "?Ram=" + Math.random(), '收费项目选择', false, function (_data) {
                    var varReturn = _data;
                    if (varReturn != "") {//**获得返回 刷新
                        var varObjects = varReturn.split("\t");
                        $("#CorpCostID").val(varObjects[0]);
                        $("#CostName").val(varObjects[1]);
                    }
                });
            }

            function btnClear() {
                $("#CorpCostID").val('');
                $("#CostName").val('');
            }

            var column;
            column = [[
                {
                    field: 'text', title: '项目列表', align: 'left', sortable: true, formatter: function (value, row, index) {
                        var str = "<a class=\"HrefStyle\" href=\"#\">" + row.text + "</a>";
                        return str;
                    }
                },
                {
                    field: 'InPopedom', title: '小区ID', align: 'left', formatter: function (value, row, index) {
                        var str = row.attributes.InPopedom;
                        if (str == 0) str = '';
                        return str;
                    }
                }
            ]];

            var IsCollapseAll = false;
            var toolbar = [
                {
                    text: '展开/折叠',
                    iconCls: 'icon-redo',
                    handler: function () {
                        if (IsCollapseAll == true) {
                            $('#TableContainerTree').treegrid('expandAll');
                            IsCollapseAll = false;
                        }
                        else {
                            $('#TableContainerTree').treegrid('collapseAll');
                            IsCollapseAll = true;
                        }
                    }
                }
            ];

            function LoadListTree() {
                $("#TableContainerTree").treegrid({
                    url: '/HM/M_Main/HC/DataGetControl.aspx?Method=DataGet&Class=Organ&Command=GetOrganTreeGridList&' + $('#frmForm').serialize(),
                    treeField: 'text',
                    idField: 'id',
                    method: "get",
                    nowrap: false,
                    pageSize: top.ListPageSize,
                    pageList: top.ListPageList,
                    columns: column,
                    fitColumns: true,
                    singleSelect: true,
                    remoteSort: false,
                    pagination: false,
                    rownumbers: true,
                    IsCustomHead: false,
                    cascadeCheck: false,
                    width: "100%",
                    toolbar: toolbar,
                    border: false,
                    sortOrder: "asc",
                    onClickRow: function (node) {
                        //$("#OrganCode").val(node.attributes.OrganCode);
                        if (parseInt(node.attributes.InPopedom) > 0) {
                            $("#InPopedom").val(node.attributes.InPopedom);
                            $("#OrganName").val(node.text);
                        } else {
                            $("#InPopedom").val('');
                            $("#OrganName").val('');
                        }
                        LoadList();
                    }
                });
            }
            LoadListTree();

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

            var toolbar = [
                {
                    text: '新增',
                    iconCls: 'icon-add',
                    handler: function () {
                        if ($("#InPopedom").val() == "" || $("#InPopedom").val() == null || $("#InPopedom").val() == undefined || $("#InPopedom").val() == 0) {
                            HDialog.Info("请选择要设置税率的项目");
                        } else {
                            HDialog.Open('700', '500', '../ChargesNew/TaxRateSettingAdd.aspx?OpType=insert&CommID=' + $("#InPopedom").val() + '&CommName=' + encodeURI($("#OrganName").val()), '新增增值税税率', true, function callback(_Data) {
                                LoadList();
                            });
                        }
                    }
                }, '-',
                {
                    text: '变更',
                    iconCls: 'icon-add',
                    handler: function () {
                        if ($("#InPopedom").val() == "" || $("#InPopedom").val() == null || $("#InPopedom").val() == undefined || $("#InPopedom").val() == 0) {
                            HDialog.Info("请选择要设置税率的项目");
                        } else {
                            HDialog.Open('700', '500', '../ChargesNew/TaxRateSettingChange.aspx?OpType=insert&CommID=' + $("#InPopedom").val() + '&CommName=' + encodeURI($("#OrganName").val()), '变更增值税税率', true, function callback(_Data) {
                                LoadList();
                            });
                        }
                    }
                }, '-',
                {
                    text: '删除',
                    iconCls: 'icon-cancel',
                    handler: function () {
                        var row = $("#TableContainer").datagrid("getSelected");
                        if (row != null && row != undefined && row != "") {
                            if (row.AuditStatus == "1") {
                                HDialog.Info("已审核数据不能删除！");
                                return;
                            }
                            DelRecord(GetDateGridCheckId());
                        } else {
                            HDialog.Info("请选择一行数据进行删除！");
                        }
                    }
                }
                , '-',
                {
                    text: '修改',
                    iconCls: 'icon-edit',
                    handler: function () {
                        var row = $("#TableContainer").datagrid("getSelected");
                        if (row != "" && row != null && row != undefined) {
                            if (row.AuditStatus == "1") {
                                HDialog.Info("已审核数据不能修改！");
                                return;
                            }
                            HDialog.Open('700', '500', '../ChargesNew/TaxRateSettingAdd.aspx?OpType=edit&TaxRateSettingID=' + row.TaxRateSettingID, '修改增值税税率', true, function callback(_Data) {
                                LoadList();
                            });
                        }
                        else {
                            HDialog.Info("请选择一行数据进行修改！");
                        }
                    }
                }, '-',
                {
                    text: 'Excel导出',
                    iconCls: 'icon-page_white_excel',
                    handler: function () {
                        window.location.href = "../ChargesNew/TaxRateSettingCreExcel.aspx";
                    }
                }
                , '-',
                {
                    text: '查看备注',
                    iconCls: 'icon-help',
                    handler: function () {
                        SearchDlg2();
                    }
                }
               
            ];

            function DelRecord(TaxRateSettingID) {
                $.messager.confirm('确定', '是否删除该项', function (r) {
                    if (r) {
                        $.tool.DataGet('TaxRateSetting', 'Delete', 'TaxRateSettingID=' + TaxRateSettingID,
                            function Init() {
                            },
                            function callback(_Data) {
                                if (_Data == "false") {
                                    HDialog.Info("请有效期内已产生应收，不允许删除税率");
                                } else {
                                    LoadList();
                                }
                            },
                            function completeCallback() {
                            },
                            function errorCallback() {
                            });
                    }
                });
            }

            //浮点数乘法运算
            function FloatMul(arg1, arg2) {
                var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
                try { m += s1.split(".")[1].length } catch (e) { }
                try { m += s2.split(".")[1].length } catch (e) { }
                return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
            }

            var column = [[
                { field: 'ck', checkbox: true },
                { field: 'TaxRateSettingID', title: 'TaxRateSettingID', width: 25, align: 'left', sortable: true, hidden: true },
                { field: 'CorpCostID', title: 'CorpCostID', width: 25, align: 'left', sortable: true, hidden: true },
                { field: 'OrganName', title: '区域名称', width: 150, align: 'left', sortable: true },
               
                { field: 'CommName', title: '项目名称', width: 150, align: 'left', sortable: true },
                { field: 'TaxpayerScale', title: '纳税人规模', width: 150, align: 'left', sortable: true },
                //{
                //    field: 'CostName', title: '费用科目', width: 150, align: 'left', sortable: true, formatter: function (value, row, index) {
                //        var str = "<a style=\"color:blue;\" href=\"TaxRateSettingAdd.aspx?OpType=edit&TaxRateSettingID=" + row.TaxRateSettingID + "\">" + row.CostName + "</a>";
                //        return str;
                //    }
                //},
                { field: 'CostName', title: '费用科目', width: 150, align: 'left', sortable: true },
                {
                    field: 'TaxRate', title: '税率', width: 80, align: 'left', sortable: true, formatter: function (value, row, index) {
                        if (value) { value = FloatMul(value, 100) + "%"; }
                        return value;
                    }
                },
                {
                    field: 'IsSimpleExpropriation', title: '是否简易征税', width: 120, align: 'left', sortable: true, formatter: function (value, row, index) {
                        var str = '';
                        if (row.IsSimpleExpropriation == 1) {
                            str = '是';
                        } else {
                            str = '否';
                        }
                        return str;
                    }
                },
                {
                    field: 'StartDate', title: '开始时间', width: 130, align: 'left', sortable: true, fixed: true,
                    formatter: function (value, row, index) {
                        var str = formatDate(row.StartDate, "yyyy-MM-dd");
                        return str;
                    }
                },
                {
                    field: 'EndDate', title: '结束时间', width: 130, align: 'left', sortable: true, fixed: true,
                    formatter: function (value, row, index) {
                        var str = formatDate(row.EndDate, "yyyy-MM-dd");
                        return str;
                    }
                },
                {
                    field: 'AuditStatus', title: '审核状态', width: 80, align: 'left', sortable: true, formatter: function (value, row, index) {
                        var str = '';
                        if (row.AuditStatus == parseInt("1")) {
                            str = '已审核';
                        } else if (row.AuditStatus == parseInt("2")) {
                            str = '退回';
                        } else {
                            str = '待审核';
                        }
                        return str;
                    }
                },
                {
                    field: 'IsRealEstateRecord', title: '是否需要不动产备案', width: 150, align: 'left', sortable: true, formatter: function (value, row, index) {
                        var str = '';
                        if (row.IsRealEstateRecord == 1) {
                            str = '是';
                        } else {
                            str = '否';
                        }
                        return str;
                    }
                },

                {
                    field: 'RecordedTaxRate', title: '已备案税率', width: 100, align: 'left', sortable: true, formatter: function (value, row, index) {
                        if (value) { value = FloatMul(value, 100) + "%"; }
                        return value;
                    }
                },
                {
                    field: 'UnrecordedTaxRate', title: '未备案税率', width: 100, align: 'left', sortable: true, formatter: function (value, row, index) {
                        if (value) { value = FloatMul(value, 100) + "%"; }
                        return value;
                    }
                },
                {
                    field: 'IsContractPenalty', title: '是否需要合同违约金税率', width: 170, align: 'left', sortable: true, formatter: function (value, row, index) {
                        var str = '';
                        if (row.IsContractPenalty == 1) {
                            str = '是';
                        } else {
                            str = '否';
                        }
                        return str;
                    }
                },
                {
                    field: 'ContractPenaltyRate', title: '合同违约金税率', width: 100, align: 'left', sortable: true, formatter: function (value, row, index) {
                        if (value) { value = FloatMul(value, 100) + "%"; }
                        return value;
                    }
                },
                { field: 'OperationUserName', title: '操作人', width: 100, align: 'left', sortable: true },
                {
                    field: 'OperationDate', title: '操作时间', width: 130, align: 'left', sortable: true, fixed: true,
                    formatter: function (value, row, index) {
                        var str = formatDate(row.OperationDate, "yyyy-MM-dd");
                        return str;
                    }
                }
            ]];

            //获取单选或者批量的ID
            function GetDateGridCheckId() {
                var str = "";
                var row = $("#TableContainer").datagrid("getChecked");
                if (row.length > 0) {
                    for (var i = 0; i < row.length; i++) {
                        str += "," + row[i].TaxRateSettingID;
                    }
                    if (str.length > 0)
                        str = str.substr(1, str.length - 1);
                }
                else {
                    var rows = $("#TableContainer").datagrid("getSelected");
                    str = rows.TaxRateSettingID;
                }
                return str;
            }

            function LoadList() {
                $("#TableContainer").datagrid({
                    url: '/HM/M_Main/HC/DataGetControl.aspx?Method=DataGet&Class=TaxRateSetting&Command=List&' + $('#frmForm').serialize(),
                    method: "get",
                    nowrap: false,
                    pageSize: top.ListPageSize,
                    pageList: top.ListPageList,
                    columns: column,
                    remoteSort: false,
                    fitColumns: false,
                    rownumbers: true,
                    singleSelect: true,
                    selectOnCheck: false,
                    checkOnSelect: false,
                    pagination: true,
                    width: "100%",
                    border: false,
                    toolbar: toolbar,
                    border: false,
                    sortOrder: "asc"
                    //onCheck: function (rowIndex, rowData) {
                    //    document.getElementById("TaxRateSettingID").value = document.getElementById("TaxRateSettingID").value + "|" + rowData.TaxRateSettingID;
                    //},
                    //onUncheck: function (rowIndex, rowData) {
                    //    var ss = document.getElementById("TaxRateSettingID").value.split('|');
                    //    for (var i = 0; i < ss.length; i++) {
                    //        if (ss[i].indexOf(rowData.TaxRateSettingID) >= 0) {
                    //            ss.splice(i, 1);
                    //        }
                    //    }
                    //    valu = "";
                    //    for (var i = 0; i < ss.length; i++) {
                    //        valu += "|" + ss[i];
                    //    }
                    //    document.getElementById("TaxRateSettingID").value = valu.substr(1, valu.length);
                    //},
                    //onCheckAll: function (rows) {
                    //    document.getElementById("TaxRateSettingID").value = "";
                    //    for (var i = 0; i < rows.length; i++) {
                    //        document.getElementById("TaxRateSettingID").value = document.getElementById("TaxRateSettingID").value + "|" + rows[i].TaxRateSettingID;
                    //    }
                    //},
                    //onUncheckAll: function (rows) {
                    //    document.getElementById("TaxRateSettingID").value = "";
                    //}
                });
                $("#SearchDlg").dialog("close");
            }
            LoadList();

             function SearchDlg2() {
                $('#DlgMemo').parent().appendTo($("form:first"))
                $('#DlgMemo').dialog('open');
            }

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

