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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>增值税税率审核</title>
    <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" />
    <link href="../css/framesearch.css" type="text/css" rel="stylesheet" />
    <link href="../css/button.css" rel="stylesheet" />

    <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>
    <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 type="text/javascript" src="../Jscript-Ui/JQForm/JQForm.js"></script>
    <script src="../jscript/Dialog.js" type="text/javascript"></script>
    <script src="../jscript/DateFormat.js" type="text/javascript"></script>
    <script type="text/javascript" src="../jscript/DatePicker/WdatePicker.js"></script>
    <script src="../jscript/format.js" type="text/javascript"></script>
    <script type="text/javascript" src="../jscript/Cache.js"></script>
    <style>
        #CommName {
            width: 91.7%;
            height: 50px;
            border: 1px solid #cccccc;
            font-size: 12px;
            padding: 2px;
            resize: none;
        }

        #CostName {
            width: 91.7%;
            height: 50px;
            border: 1px solid #cccccc;
            font-size: 12px;
            padding: 2px;
            resize: none;
        }
    </style>
</head>
<body>
    <form id="frmForm" runat="server">
        <input type="hidden" id="InPopedom" runat="server" />
        <div id="TableContainer"></div>
        <div id="SearchDlg" class="easyui-dialog" title="筛选条件" data-options="iconCls:'icon-search',closed: true,modal:true"
            style="width: 700px; height: 240px; padding: 10px; overflow: hidden;">
            <table class="SearchTable">
                <tr>
                    <td class="TdTitle">管理项目</td>
                    <td colspan="3" class="TdContent">
                        <textarea id="CommName" name="CommName" onclick="SelCommInfo();"></textarea>
                    </td>
                </tr>
                <tr>
                    <td class="TdTitle">费用科目</td>
                    <td colspan="3" class="TdContent">
                        <textarea id="CostName" name="CostName" runat="server" onclick="SelCost();"></textarea>
                        <input id="CorpCostID" name="CorpCostID" value="" type="hidden" /></td>
                </tr>
                <tr>
                    <td class="TdTitle">审核状态</td>
                    <td colspan="3" class="TdContent">
                        <select id="AuditStatus" style="width: 120px; border: 1px solid #cccccc;">
                            <option value=""></option>
                            <option value="0">待审核</option>
                            <option value="1">已审核</option>
                            <option value="2">退回</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: center; padding-top: 5px;" colspan="4">
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="LoadList();">查询</a>
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="Clear();">清空</a>
                    </td>
                </tr>
            </table>
        </div>
        <script type="text/javascript">
            function InitTableHeight() {
                var h = $(window).height();
                $("#TableContainer").css("height", h + "px");
                $("#AuditStatus").get(0).selectedIndex = 1;
                $("#AuditStatus option[text='待审核']").attr("selected", true);
            }
            InitTableHeight();

            //选择费用科目
            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 SelCommInfo() {
               var w = $(window).width() * 0.7;
                    HDialog.Open(w, 500, '../DialogNew/SelComm.aspx?IsCheck=1', "选择管理项目", false, function callback(_Data) {
                    var arrRet = JSON.parse(_Data);
                    $("#InPopedom").val(arrRet.id);
                    $("#CommName").val(arrRet.name);
                });
            }

            //**清空
            function Clear() {
                $('#CommName').val("");
                $('#InPopedom').val("");
                $('#CostName').val("");
                $('#CorpCostID').val("");
                $("#AuditStatus").get(0).selectedIndex = 1;
                $("#AuditStatus option[text='待审核']").attr("selected", true);
            }

            //浮点数乘法运算
            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 toolbar = [
                {
                    text: '筛选',
                    iconCls: 'icon-search',
                    handler: function () {
                        $('#SearchDlg').parent().appendTo($("form:first"))
                        $('#SearchDlg').dialog('open');
                    }
                }, '-',
                {
                    text: '批量审核通过',
                    iconCls: 'icon-add',
                    handler: function () {
                        OperationDetail('0');
                    }
                }, '-',
                {
                    text: '批量退回',
                    iconCls: 'icon-edit',
                    handler: function () {
                        OperationDetail('1');
                    }
                }, '-',
                {
                    text: 'Excel导出',
                    iconCls: 'icon-page_white_excel',
                    handler: function () {
                        window.location.href = "../ChargesNew/TaxRateSettingCreExcel.aspx";
                    }
                }
                
            ];



            //列表列
            var column = [[
                { field: 'ck', checkbox: true },
                { field: 'OrganName', title: '区域名称', width: 100, align: 'center', sortable: true },
                { field: 'CommID', title: '项目编号', width: 100, align: 'center', sortable: true },
				{ field: 'CommName', title: '项目名称', width: 100, align: 'center', sortable: true },
				{ field: 'TaxpayerScale', title: '纳税人规模', width: 100, align: 'center', sortable: true },
                { field: 'CostName', title: '费用科目', width: 120, align: 'center', sortable: true },
                {
                    field: 'TaxRate', title: '税率', width: 100, align: 'center', 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: 90, align: 'center', sortable: true, fixed: true,
                    formatter: function (value, row, index) {
                        var str = formatDate(row.StartDate, "yyyy-MM-dd");
                        return str;
                    }
                },
                {
                    field: 'EndDate', title: '结束时间', width: 90, align: 'center', sortable: true, fixed: true,
                    formatter: function (value, row, index) {
                        var str = formatDate(row.EndDate, "yyyy-MM-dd");
                        return str;
                    }
                },
                {
                    field: 'AuditStatusName', title: '审核状态', width: 70, align: 'center', sortable: true, formatter: function (value, row, index) {
                        var str = '';
                        if (row.AuditStatus == 1) {
                            str = '已审核';
                        } else if (row.AuditStatus == 0) {
                            str = '待审核';
                        } else if (row.AuditStatus == 2) {
                            str = '退回';
                        }
                        return str;
                    }
                },
                {
                    field: 'IsRealEstateRecord', title: '是否需要不动产备案', width: 120, align: 'center', sortable: true, formatter: function (value, row, index) {
                        var str = '';
                        if (row.IsRealEstateRecord == 1) {
                            str = '是';
                        } else {
                            str = '否';
                        }
                        return str;
                    }
                },

                {
                    field: 'RecordedTaxRate', title: '已备案税率', width: 90, align: 'left', sortable: true, formatter: function (value, row, index) {
                        if (value) { value = FloatMul(value, 100) + "%"; }
                        return value;
                    }
                },
                {
                    field: 'UnrecordedTaxRate', title: '未备案税率', width: 90, align: 'left', sortable: true, formatter: function (value, row, index) {
                        if (value) { value = FloatMul(value, 100) + "%"; }
                        return value;
                    }
                },
                {
                    field: 'IsContractPenalty', title: '是否需要合同违约金税率', width: 145, align: 'center', 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: 70, align: 'center', sortable: true },
                { field: 'OperationDate', title: '操作时间', width: 140, align: 'center', sortable: true }
            ]];

            //显示详细
            function OperationDetail(OpType) {//TaxRateAudit
                //获取勾选的数据
                var CheckedRow = $('#TableContainer').datagrid("getChecked");
                if (CheckedRow.length == 0) {
                    if (OpType == "0") {
                        HDialog.Info('请选择需要审核通过的增值税税率');
                        return;
                    } else if (OpType == "1") {
                        HDialog.Info('请选择需要退回的增值税税率');
                        return;
                    } else if (OpType == "2") {
                        HDialog.Info('请选择需要删除的增值税税率');
                        return;
                    }
                } else {
                    if (OpType == "0") {
                        for (var i = 0; i < CheckedRow.length; i++) {
                            if (CheckedRow[i].AuditStatus == "1") {
                                HDialog.Info("已审核数据不能继续审核！");
                                return;
                            }
                        }
                    } else if (OpType == "1") {
                        for (var i = 0; i < CheckedRow.length; i++) {
                            if (CheckedRow[i].AuditStatus == "1") {
                                HDialog.Info("已审核数据不能退回！");
                                return;
                            }
                        }
                    } else if (OpType == "2") {
                        for (var i = 0; i < CheckedRow.length; i++) {
                            if (CheckedRow[i].AuditStatus == "1") {
                                HDialog.Info("已审核数据不能删除！");
                                return;
                            }
                        }
                    }
                }

                if (OpType == "2") {
                    $.messager.confirm('确定', '确定删除选中的增值税税率？', function (r) {
                        if (r) {
                            var IdList = "";
                            for (var i = 0; i < CheckedRow.length; i++) {
                                IdList += CheckedRow[i].TaxRateSettingID + ",";
                            }
                            if (IdList.length > 0) {
                                IdList = IdList.substring(0, IdList.length - 1);
                            }
                            SaveData(OpType, IdList);
                        } else {
                            return;
                        }
                    });
                } else {
                    var IdList = "";
                    for (var i = 0; i < CheckedRow.length; i++) {
                        IdList += CheckedRow[i].TaxRateSettingID + ",";
                    }
                    if (IdList.length > 0) {
                        IdList = IdList.substring(0, IdList.length - 1);
                    }
                    SaveData(OpType, IdList);
                }
            }

            //增值税税率审核保存
            function SaveData(OpType, IdList) {
                $.tool.DataPostAsync('TaxRateSetting', 'TaxRateAudit', "Flag=" + OpType + "&IdList=" + IdList + "&" + $("#frmForm").serialize(),
                    function Init() {
                    },
                    function callback(_Data) {
                        if (_Data == "Lock") {
                            HDialog.Info("有效期内已产生应收，不允许删除税率");
                        } else {
                            LoadList();
                        }
                    });
            }

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



                $("#SearchDlg").dialog("close");
            }
            LoadList();

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