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


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title></title>
    <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 href="../css/framesearch_old.css" type="text/css" rel="stylesheet" />
    <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>
    <script src="../jscript/ajax.js"></script>
    <link href="../css/framesearch.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 type="text/javascript" src="../jscript/DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="../jscript/Cache.js"></script>

</head>
<body>
    <form id="frmForm" runat="server">
        <input type="hidden" id="downPDF" />
        <input id="RoomID" type="hidden" name="RoomID" runat="server" />
        <input id="CostIDs" type="hidden" name="CostIDs" runat="server" />
        <input id="CustID" type="hidden" name="CustID" runat="server" />
        <input id="BillData" name="BillData" value="" type="hidden" runat="server" />
        <input id="hiCommId" type="hidden" name="hiCommId" value="" runat="server" />
        <input id="CommIds" type="hidden" name="CommIds" value="" runat="server" />
        <input name="SearchType" type="hidden" id="SearchType" value="Red" />

        <input id="InvoiceID" type="hidden" name="InvoiceID" runat="server" />
        <input id="InvoiceType" type="hidden" name="InvoiceType" runat="server" />
        <input type="button" style="display: none" value="下载电票" id="btnDownImg" name="btnDownImg" onserverclick="btnDownImg_ServerClick" runat="server" />
        <div id="TableContainer" style="width: 100%;"></div>
        <div id="PushDlg" class="easyui-dialog" title="发票推送" style="width: 400px; height: 100px;" data-options="iconCls:'icon-search',closed: true,modal:true">
            <table class="SearchTable" style="margin: 5px auto">
                <tr>
                    <td class="TdTitle">推送类型</td>
                    <td class="TdContent">
                        <select id="BillPushType" name="BillPushType">
                            <option value="0">短信</option>
                            <option value="1" selected>邮箱</option>
                        </select>
                    </td>
                    <td colspan="2" style="padding-left: 20px;">
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="BillPush();">发票推送</a>
                    </td>
                </tr>
            </table>
        </div>
        <div id="fReasonDlg" class="easyui-dialog" title="红冲原因" style="width: 550px; height: 100px;" data-options="iconCls:'icon-search',closed: true,modal:true">
            <table class="SearchTable" style="margin: 10px auto">
                <tr>
                    <td class="TdTitle">申请原因</td>
                    <td class="TdContent">
                        <input type="text" id="FlushReason" name="FlushReason" runat="server" />
                    </td>
                    <td class="TdTitle">红字通知单编号</td>
                    <td class="TdContent">
                        <input type="text" placeholder="专票红冲必填" id="HZSQDBH" name="HZSQDBH" runat="server" />
                    </td>
                    <td class="TdTitle">
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="EinvoiceFlush();">红冲</a>
                    </td>
                </tr>

            </table>
        </div>
        <div id="dReasonDlg" class="easyui-dialog" title="作废原因" style="width: 500px; height: 100px;" data-options="iconCls:'icon-search',closed: true,modal:true">
            <table class="SearchTable" style="margin: 10px auto">
                <tr>
                    <td class="TdTitle">作废原因</td>
                    <td class="TdContent">
                        <input type="text" id="InvalidReason" name="InvalidReason" runat="server" />
                    </td>
                    <td class="TdTitle">
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="EinvoiceInvalid();">作废</a>
                    </td>
                </tr>
            </table>
        </div>
        <div id="SearchDlg" class="easyui-dialog" title="筛选条件" style="width: 860px; height: 310px;" data-options="iconCls:'icon-search',closed: true,modal:true">
            <table class="SearchTable" style="margin: 10px auto">
                <tr>
                    <td class="TdTitle">项目</td>
                    <td class="TdContentSearch" colspan="5">
                        <textarea name="CommNames" id="CommNames" style="width: 92%; height: 40px; border: 1px solid #cccccc; font-size: 12px; padding: 2px; resize: none;" runat="server"></textarea>
                    </td>
                </tr>
                <tr>
                    <td class="TdTitle">订单号</td>
                    <td class="TdContent">
                        <input id="OrderNo" name="OrderNo" />
                    </td>
                    <td class="TdTitle">发票号码</td>
                    <td class="TdContent">
                        <input id="InvoiceNo" name="InvoiceNo" /></td>
                    <td class="TdTitle">发票代码</td>
                    <td class="TdContent">
                        <input id="InvoiceCode" name="InvoiceCode" /></td>
                </tr>
                <tr>
                    <td class="TdTitle">开票(发起)时间从</td>
                    <td class="TdContentSearch">
                        <input id="BillStartDate" class="Wdate" onclick="WdatePicker()" name="BillStartDate" runat="server" /></td>
                    <td class="TdTitle">到</td>
                    <td class="TdContentSearch">
                        <input id="BillEndDate" class="Wdate" onclick="WdatePicker()" name="BillEndDate" runat="server" /></td>
                    <td class="TdTitle">开票人</td>
                    <td class="TdContent">
                        <input id="BillingUser" name="BillingUser" />
                    </td>
                </tr>
                <tr>

                    <td class="TdTitle">红冲(发起)时间从</td>
                    <td class="TdContentSearch">
                        <input id="FlushStartDate" class="Wdate" onclick="WdatePicker()" name="FlushStartDate" runat="server" /></td>
                    <td class="TdTitle">到</td>
                    <td class="TdContentSearch">
                        <input id="FlushEndDate" class="Wdate" onclick="WdatePicker()" name="FlushEndDate" runat="server" /></td>
                    <td class="TdTitle">是否红冲</td>
                    <td class="TdContent">
                        <select id="IsFlush" name="IsFlush">
                            <option value="0" selected="selected">否</option>
                            <option value="">全部</option>
                            <option value="1">是</option>
                        </select></td>
                </tr>
                <tr>
                    <td class="TdTitle">作废(发起)时间从</td>
                    <td class="TdContentSearch">
                        <input id="DestroyStartDate" class="Wdate" onclick="WdatePicker()" name="DestroyStartDate" runat="server" /></td>
                    <td class="TdTitle">到</td>
                    <td class="TdContentSearch">
                        <input id="DestroyEndDate" class="Wdate" onclick="WdatePicker()" name="DestroyEndDate" runat="server" /></td>
                    <td class="TdTitle">是否作废</td>
                    <td class="TdContent">
                        <select id="IsDestroy" name="IsDestroy">
                            <option value="0" selected="selected">否</option>
                            <option value="">全部</option>
                            <option value="1">是</option>
                        </select></td>
                </tr>
                <tr>
                    <td class="TdTitle">客户名称</td>
                    <td class="TdContentSearch">
                        <input id="CustName" searcher="SelCust" name="CustName" class="easyui-searchbox"
                            data-options="editable:false" runat="server" />
                    </td>
                    <td class="TdTitle">发票种类</td>
                    <td class="TdContent">
                        <select id="FPLXDM" name="FPLXDM">
                            <option value="0" selected="selected">全部</option>
                            <option value="026">增值税电子发票</option>
                            <option value="007">增值税普通发票</option>
                            <option value="004">增值税专用发票</option>
                            <option value="81">全电专票</option>
                            <option value="82">全电普票</option>
                        </select></td>
                </tr>
                <tr>
                    <td colspan="6" style="text-align: center; padding-top: 5px;">
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="LoadData();">查询</a>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>

<script type="text/javascript">

    var Base64 = {
        // 转码表
        table: [
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
            'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
            'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
            'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
            'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
            'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
            'w', 'x', 'y', 'z', '0', '1', '2', '3',
            '4', '5', '6', '7', '8', '9', '+', '/'
        ],
        UTF16ToUTF8: function (str) {
            var res = [], len = str.length;
            for (var i = 0; i < len; i++) {
                var code = str.charCodeAt(i);
                if (code > 0x0000 && code <= 0x007F) {
                    // 单字节，这里并不考虑0x0000，因为它是空字节
                    // U+00000000 – U+0000007F 	0xxxxxxx
                    res.push(str.charAt(i));
                } else if (code >= 0x0080 && code <= 0x07FF) {
                    // 双字节
                    // U+00000080 – U+000007FF 	110xxxxx 10xxxxxx
                    // 110xxxxx
                    var byte1 = 0xC0 | ((code >> 6) & 0x1F);
                    // 10xxxxxx
                    var byte2 = 0x80 | (code & 0x3F);
                    res.push(
                        String.fromCharCode(byte1),
                        String.fromCharCode(byte2)
                    );
                } else if (code >= 0x0800 && code <= 0xFFFF) {
                    // 三字节
                    // U+00000800 – U+0000FFFF 	1110xxxx 10xxxxxx 10xxxxxx
                    // 1110xxxx
                    var byte1 = 0xE0 | ((code >> 12) & 0x0F);
                    // 10xxxxxx
                    var byte2 = 0x80 | ((code >> 6) & 0x3F);
                    // 10xxxxxx
                    var byte3 = 0x80 | (code & 0x3F);
                    res.push(
                        String.fromCharCode(byte1),
                        String.fromCharCode(byte2),
                        String.fromCharCode(byte3)
                    );
                } else if (code >= 0x00010000 && code <= 0x001FFFFF) {
                    // 四字节
                    // U+00010000 – U+001FFFFF 	11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
                } else if (code >= 0x00200000 && code <= 0x03FFFFFF) {
                    // 五字节
                    // U+00200000 – U+03FFFFFF 	111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
                } else /** if (code >= 0x04000000 && code <= 0x7FFFFFFF)*/ {
                    // 六字节
                    // U+04000000 – U+7FFFFFFF 	1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
                }
            }

            return res.join('');
        },
        UTF8ToUTF16: function (str) {
            var res = [], len = str.length;
            var i = 0;
            for (var i = 0; i < len; i++) {
                var code = str.charCodeAt(i);
                // 对第一个字节进行判断
                if (((code >> 7) & 0xFF) == 0x0) {
                    // 单字节
                    // 0xxxxxxx
                    res.push(str.charAt(i));
                } else if (((code >> 5) & 0xFF) == 0x6) {
                    // 双字节
                    // 110xxxxx 10xxxxxx
                    var code2 = str.charCodeAt(++i);
                    var byte1 = (code & 0x1F) << 6;
                    var byte2 = code2 & 0x3F;
                    var utf16 = byte1 | byte2;
                    res.push(Sting.fromCharCode(utf16));
                } else if (((code >> 4) & 0xFF) == 0xE) {
                    // 三字节
                    // 1110xxxx 10xxxxxx 10xxxxxx
                    var code2 = str.charCodeAt(++i);
                    var code3 = str.charCodeAt(++i);
                    var byte1 = (code << 4) | ((code2 >> 2) & 0x0F);
                    var byte2 = ((code2 & 0x03) << 6) | (code3 & 0x3F);
                    var utf16 = ((byte1 & 0x00FF) << 8) | byte2
                    res.push(String.fromCharCode(utf16));
                } else if (((code >> 3) & 0xFF) == 0x1E) {
                    // 四字节
                    // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
                } else if (((code >> 2) & 0xFF) == 0x3E) {
                    // 五字节
                    // 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
                } else /** if (((code >> 1) & 0xFF) == 0x7E)*/ {
                    // 六字节
                    // 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
                }
            }

            return res.join('');
        },
        encode: function (str) {
            if (!str) {
                return '';
            }
            var utf8 = this.UTF16ToUTF8(str); // 转成UTF8
            var i = 0; // 遍历索引
            var len = utf8.length;
            var res = [];
            while (i < len) {
                var c1 = utf8.charCodeAt(i++) & 0xFF;
                res.push(this.table[c1 >> 2]);
                // 需要补2个=
                if (i == len) {
                    res.push(this.table[(c1 & 0x3) << 4]);
                    res.push('==');
                    break;
                }
                var c2 = utf8.charCodeAt(i++);
                // 需要补1个=
                if (i == len) {
                    res.push(this.table[((c1 & 0x3) << 4) | ((c2 >> 4) & 0x0F)]);
                    res.push(this.table[(c2 & 0x0F) << 2]);
                    res.push('=');
                    break;
                }
                var c3 = utf8.charCodeAt(i++);
                res.push(this.table[((c1 & 0x3) << 4) | ((c2 >> 4) & 0x0F)]);
                res.push(this.table[((c2 & 0x0F) << 2) | ((c3 & 0xC0) >> 6)]);
                res.push(this.table[c3 & 0x3F]);
            }

            return res.join('');
        },
        decode: function (str) {
            if (!str) {
                return '';
            }

            var len = str.length;
            var i = 0;
            var res = [];

            while (i < len) {
                code1 = this.table.indexOf(str.charAt(i++));
                code2 = this.table.indexOf(str.charAt(i++));
                code3 = this.table.indexOf(str.charAt(i++));
                code4 = this.table.indexOf(str.charAt(i++));

                c1 = (code1 << 2) | (code2 >> 4);
                c2 = ((code2 & 0xF) << 4) | (code3 >> 2);
                c3 = ((code3 & 0x3) << 6) | code4;

                res.push(String.fromCharCode(c1));

                if (code3 != 64) {
                    res.push(String.fromCharCode(c2));
                }
                if (code4 != 64) {
                    res.push(String.fromCharCode(c3));
                }

            }

            return this.UTF8ToUTF16(res.join(''));
        }
    };


</script>
<script type="text/javascript">
    var w = $(window).width();
    var h = $(window).height();
    function InitFunction() {
        var h = $(window).height();
        $("#TableContainer").css("height", h + "px");

        $("#CommNames").click(function () {
            if ($("#hiCommId").val() != '' && $("#hiCommId").val() != '0') {
                return;
            }
            HDialog.Open(700, 400, '../DialogNew/SelComm.aspx?IsCheck=1', "选择管理项目", false, function callback(_Data) {
                var arrRet = JSON.parse(_Data);
                $("#CommIds").val(arrRet.id);
                $("#CommNames").val(arrRet.name);
            });
        });
    }
    InitFunction();

    function SelCust() {

        $('#CustName').searchbox("setValue", '');
        $('#CustID').val('');

        var conent = "../DialogNew/CustDlg.aspx";

        HDialog.Open(w, h, conent, '客户选择', false, function callback(_Data) {
            var data = JSON.parse(_Data);
            $('#CustName').searchbox("setValue", data.CustName);
            $('#CustID').val(data.CustID);
        });
    }

    var strCustID = sessionStorage.getItem("OnlineCust");
    if (strCustID != "") {
        $("#CustID").val(strCustID);
    }
    var Headcolumn = [
        [
            { field: '', checkbox: true },
            { field: 'OrganName', title: '区域', align: 'center', sortable: true, width: 100 },
            { field: 'CommName', title: '项目', align: 'center', sortable: true, width: 100 },
            {
                field: 'CustName', title: '客户名称', align: 'center', sortable: true, width: 100,
                formatter: function (value, row, index) {
                    var str = "<a class=\"HrefStyle\" href='#' onclick=\"UpdateBillInfo(" + row.CustId + ",'" + row.InvoiceID + "');\">" + value + "</a>";
                    return str;
                }
            },
            { field: 'PurchaserTel', title: '联系电话', align: 'center', sortable: true, width: 100 },
            { field: 'Email', title: '联系邮箱', align: 'center', sortable: true, width: 100 },
            {
                field: 'InvoiceNo', title: '发票号码', align: 'center', sortable: true, width: 200, formatter: function (value, row, index) {
                    var urlarr = row.PdfUrl.split(",");
                    var noarr = value.split(",");
                    var strarr = new Array();
                    for (var i = 0; i < noarr.length; i++) {
                        if (row.InvoiceType == '026' || row.InvoiceType == '82' || row.InvoiceType == '81') {
                            var str = "<a class=\"HrefStyle\" target='_blank' href='" + urlarr[i] + "'>"
                                + noarr[i] + "</a>";
                            strarr.push(str);
                        } else {
                            var str = "<a class=\"HrefStyle\" href='#' onclick=\"ViewDetail('纸票发票详情'," + index + ");\">" + noarr[i] + "</a>";
                            strarr.push(str);
                        }
                    }
                    return strarr.join(",");
                }
            },
            { field: 'InvoiceCode', title: '发票代码', align: 'center', sortable: true, width: 100 },
            { field: 'BillAmount', title: '发票金额', align: 'center', sortable: true, width: 100 },
            {
                field: 'BillingTime', title: '开票发起时间', align: 'center', sortable: true, width: 100, formatter: function (value, row, index) {
                    var str = formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    return str;
                }
            },
            {
                field: 'InvoiceType', title: '发票种类', align: 'center', sortable: true, width: 100,
                formatter: function (value, row, index) {
                    var str = '';
                    if (row.InvoiceType == '026') {
                        str = '增值税电子发票';
                    }
                    if (row.InvoiceType == '004') {
                        str = '增值税专用发票';
                    }
                    if (row.InvoiceType == '007') {
                        str = '增值税普通发票';
                    }
                    if (row.InvoiceType == '81') {
                        str = '全电专票';
                    }
                    if (row.InvoiceType == '82') {
                        str = '全电普票';
                    }
                    return str;
                }
            },
            { field: 'BillingUser', title: '开票人', align: 'center', sortable: true, width: 100 },
            {
                field: 'CompleteTime', title: '开票完成时间', align: 'center', sortable: true, width: 100, formatter: function (value, row, index) {
                    var str = formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    return str;
                }
            },
            { field: 'OrderNo', title: '天问订单号', align: 'center', sortable: true, width: 300 },
            {
                field: 'BillingSource', title: '订单来源', align: 'center', sortable: true, width: 100,
                formatter: function (value, row, index) {
                    var str = "";
                    switch (row.BillingSource) {
                        case "1":
                            str = "天问收费系统";
                            break;
                        case "2":
                            str = "小程序";
                            break;
                        default:
                    }
                    return str;
                }
            },
            { field: 'Billingno', title: '关联订单号', align: 'center', sortable: true, width: 200 },
            {
                field: 'FlushState', title: '红冲状态', align: 'center', sortable: true, width: 100, formatter: function (value, row, index) {
                    var str = "";
                    switch (row.FlushState) {
                        case "1":
                            str = "已发送";
                            break;
                        case "2":
                            str = "已红冲";
                            break;
                        case "3":
                            str = "红冲失败";
                            break;
                        default:
                    }
                    return str;
                }
            },
            {
                field: 'FlushAmount', title: '红冲金额', align: 'center', sortable: true, width: 100, formatter: function (value, row, index) {
                    var str = "";
                    if (row.FlushState == "2") {
                        return "-" + row.BillAmount;
                    }
                    return str;
                }
            },

            {
                field: 'FlushTime', title: '红冲发起时间', align: 'center', sortable: true, width: 100, formatter: function (value, row, index) {
                    var str = formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    return str;
                }
            },
            { field: 'FlushUser', title: '红冲操作人', align: 'center', sortable: true, width: 100 },
            {
                field: 'FlushCompleteTime', title: '红冲完成时间', align: 'center', sortable: true, width: 100, formatter: function (value, row, index) {
                    var str = formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    return str;
                }
            },
            {
                field: 'FlushNo', title: '红冲发票号码', align: 'center', sortable: true, width: 200, formatter: function (value, row, index) {
                    var urlarr = row.FlushPdfUrl.split(",");
                    var noarr = value.split(",");
                    var strarr = new Array();
                    for (var i = 0; i < noarr.length; i++) {
                        if (row.InvoiceType == '026' || row.InvoiceType == '82' || row.InvoiceType == '81') {
                            var str = "<a class=\"HrefStyle\" target='_blank' href='" + urlarr[i] + "'>"
                                + noarr[i] + "</a>";
                            strarr.push(str);
                        } else {
                            var str = "<a class=\"HrefStyle\" href='#' onclick=\"ViewDetail('红冲发票详情'," + index + ");\">" + noarr[i] + "</a>";
                            strarr.push(str);
                        }
                    }
                    return strarr.join(",");
                }
            },
            { field: 'FlushCode', title: '红冲发票代码', align: 'center', sortable: true, width: 100 },

            { field: 'FlushErrMsg', title: '红冲备注', align: 'center', sortable: true, width: 100 },
            {
                field: 'DestroyState', title: '作废状态', align: 'center', sortable: true, width: 100, formatter: function (value, row, index) {
                    var str = "";
                    switch (row.DestroyState) {
                        case "1":
                            str = "已发送";
                            break;
                        case "2":
                            str = "已作废";
                            break;
                        case "3":
                            str = "作废失败";
                            break;
                        default:
                    }
                    return str;
                }
            },
            {
                field: 'DestroyTime', title: '作废发起时间', align: 'center', sortable: true, width: 100, formatter: function (value, row, index) {
                    var str = formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    return str;
                }
            },
            { field: 'DestroyUser', title: '作废操作人', align: 'center', sortable: true, width: 100 },
            {
                field: 'DestroyCompleteTime', title: '作废完成时间', align: 'center', sortable: true, width: 100, formatter: function (value, row, index) {
                    var str = formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    return str;
                }
            },
            {
                field: 'DestroyErrMsg', title: '作废备注', align: 'center', sortable: true, width: 160
            }
            //,
            //{
            //    field: 'PushCount', title: '推送成功次数', align: 'center', sortable: true, width: 90
            //},
            //{
            //    field: 'PushMsg', title: '推送备注', align: 'center', sortable: true, width: 120
            //}

        ]
    ];

    var toolbar = [
        {
            text: '筛选',
            iconCls: 'icon-filter',
            handler: function () {
                $('#SearchDlg').parent().appendTo($("form:first"));
                $('#SearchDlg').dialog('open');
            }
        }, '-',
        {
            text: '红冲发票',
            iconCls: 'icon-cancel',
            handler: function () {
                var ob = $("#TableContainer").datagrid('getSelections');
                if (ob != null && ob.length == 1) {
                    if (ob[0].InvoiceNo == "") {
                        HDialog.Info("票据开具未成功,无法红冲");
                        return;
                    }
                    if (ob[0].DestroyState == "1") {
                        HDialog.Info("票据已发起作废");
                        return;
                    }
                    if (ob[0].DestroyState == "2") {
                        HDialog.Info("票据已作废");
                        return;
                    }
                    if (ob[0].FlushState == "1") {
                        HDialog.Info("票据已发起红冲");
                        return;
                    }
                    if (ob[0].FlushState == "2") {
                        HDialog.Info("票据已红冲");
                        return;
                    }
                    var billDate = new Date(ob[0].CompleteTime);
                    var billYear = billDate.getFullYear();
                    var billMonth = billDate.getMonth() + 1;
                    var myDate = new Date();
                    var nowYear = myDate.getFullYear();
                    var nowMonth = myDate.getMonth() + 1;
                    if (billYear == nowYear && billMonth == nowMonth && (ob[0].InvoiceType == "004" || ob[0].InvoiceType == "007")) {
                        HDialog.Info("纸票次月才能红冲");
                        return;
                    }
                    $.messager.confirm('提示', '是否确认红冲?', function (r) {
                        if (r) {
                            $("#InvoiceID").val(ob[0].InvoiceID);
                            $("#InvoiceType").val(ob[0].InvoiceType);
                            $('#fReasonDlg').parent().appendTo($("form:first"));
                            $('#fReasonDlg').dialog('open');
                        }
                    });

                }
                else {
                    HDialog.Info("请选择一笔发票红冲");
                }

            }
        }, '-',
        //{
        //    text: '作废发票',
        //    iconCls: 'icon-cancel',
        //    handler: function () {
        //        var ob = $("#TableContainer").datagrid('getSelections');
        //        if (ob != null && ob.length == 1) {
        //            if (ob[0].InvoiceNo == "") {
        //                HDialog.Info("票据开具未成功,无法作废");
        //                return;
        //            }
        //            if (ob[0].DestroyState == "1") {
        //                HDialog.Info("票据已发起作废");
        //                return;
        //            }
        //            if (ob[0].DestroyState == "2") {
        //                HDialog.Info("票据已作废");
        //                return;
        //            }
        //            if (ob[0].FlushState == "1") {
        //                HDialog.Info("票据已发起红冲");
        //                return;
        //            }
        //            if (ob[0].FlushState == "2") {
        //                HDialog.Info("票据已红冲");
        //                return;
        //            }
        //            if (ob[0].InvoiceType == "026" || ob[0].InvoiceType == "82" || ob[0].InvoiceType == "81") {
        //                HDialog.Info("电票不能作废只能做红冲操作");
        //                return;
        //            }
        //            var billDate = new Date(ob[0].CompleteTime);
        //            var billYear = billDate.getFullYear();
        //            var billMonth = billDate.getMonth() + 1;
        //            var myDate = new Date();
        //            var nowYear = myDate.getFullYear();
        //            var nowMonth = myDate.getMonth() + 1;
        //            if (billYear != nowYear || billMonth != nowMonth) {
        //                HDialog.Info("纸票当月才能作废");
        //                return;
        //            }
        //            $.messager.confirm('提示', '是否确认作废?', function (r) {
        //                if (r) {
        //                    $("#InvoiceID").val(ob[0].InvoiceID);
        //                    $('#dReasonDlg').parent().appendTo($("form:first"));
        //                    $('#dReasonDlg').dialog('open');
        //                }
        //            });

        //        }
        //        else {
        //            HDialog.Info("请选择一笔发票作废");
        //        }
        //    }
        //}, '-',
        //{
        //    text: '查询红冲发票',
        //    iconCls: 'icon-print',
        //    handler: function () {
        //        var ob = $("#TableContainer").datagrid('getSelections');
        //        if (ob.length > 0) {
        //            if (ob[0].FlushTime == "" || ob[0].FlushTime == null) {
        //                HDialog.Info("票据未发起红冲");
        //                return;
        //            }
        //            $("#BillData").val(JSON.stringify(ob));
        //            //调用电票查询接口查询开票记录
        //            $.tool.DataPostNoLoading("EInvoiceManage", "UpdateEInvoice", $('#frmForm').serialize(),
        //                function Init() { },
        //                function callback(_Data) {
        //                    var data = JSON.parse(_Data);
        //                    if (data.state == "true") {
        //                        HDialog.Info(data.msg);
        //                    }
        //                    else {
        //                        HDialog.Info(data.msg);
        //                    }
        //                    LoadData();
        //                },
        //                function completeCallback() {
        //                },
        //                function errorCallback() {
        //                }
        //            );
        //        }
        //        else {
        //            HDialog.Info("请选择发票");
        //        }

        //    }
        //}
        //{
        //    text: '打印发票',
        //    iconCls: 'icon-print',
        //    handler: function () {
        //        var rows = $("#TableContainer").datagrid('getSelections');
        //        if (rows != null && rows.length == 1) {
        //            if (rows != null && rows[0].InvoiceType != '026') {
        //                $("#BillData").val(JSON.stringify(rows));
        //                //打印发票
        //                $.tool.DataPost("EInvoiceManage", "PrintInvoice", $('#frmForm').serialize(),
        //                    function Init() { },
        //                    function callback(_Data) {
        //                        var data = JSON.parse(_Data);
        //                        if (data.state == true) {
        //                            printex(data.msg);
        //                        }
        //                        else {
        //                            HDialog.Info(data.msg);
        //                        }

        //                    },
        //                    function completeCallback() {
        //                    },
        //                    function errorCallback() {
        //                    });
        //            }
        //            else {
        //                HDialog.Info("请选择纸质发票打印!");
        //            }
        //        } else {
        //            HDialog.Info("请选择一笔纸质发票打印");
        //        }
        //    }
        //}, '-',
        //{
        //    text: '电票下载',
        //    iconCls: 'icon-redo',
        //    handler: function () {
        //        var rows = $("#TableContainer").datagrid('getSelections');
        //        if (rows.length > 0) {
        //            var isDown = true;
        //            $("#BillData").val(JSON.stringify(rows));
        //            for (var i = 0; i < rows.length; i++) {
        //                if (rows[i].InvoiceType == "004" || rows[i].InvoiceType == "007") {
        //                    HDialog.Info("只能下载电子发票类型！");
        //                    isDown = false;
        //                    return;
        //                }
        //            }
        //            if (isDown == true) {
        //                $("#btnDownImg").click();
        //            }
        //        } else {
        //            HDialog.Info("请选择电子发票");
        //        }

        //    }
        //}
        //, '-',
        {
            text: 'Excel导出',
            iconCls: 'icon-page_white_excel',
            handler: function () {
                window.open("../ChargesNew/EInvoiceSearchExcel.aspx");
            }
        }, '-',
        {
            text: '<font color="red">备注:电子发票只有红冲没有作废,纸质发票为当月作废,跨月红冲。</font>',
            iconCls: 'icon-help'
        }
    ];


    //调用打印程序
    function printex(reqData) {
        $.ajax({
            url: "http://127.0.0.1:2999/print",
            type: "post",
            data: { data: reqData },
            dataType: "json", //指定服务器返回的数据类型 
            success: function (_Data) {
                var strXml = Base64.decode(_Data.Data);
                console.log(strXml);
                HDialog.Info(strXml);
            },
            error: function (e) {
                HDialog.Info("请开启客户端增值税打印服务程序,再刷新当前页面重试!");
            }
        });
    }

    function ViewDetail(title, index) {
        var row = $("#TableContainer").datagrid('getRows')[index];
        var param = JSON.stringify(row);
        Cache.SetData("InvoiceDetail", param);
        HDialog.Open(w, h, '../ChargesNew/EInvoiceDetailFrame.aspx', title, true, function callback(_Data) {

        });
    }

    //加载数据
    function LoadData() {
        $("#TableContainer").datagrid({
            //url: null,
            url: '/HM/M_Main/HC/DataPostControl.aspx',
            method: "post",
            nowrap: false,
            pageSize: 30,
            pageList: [30, 50, 80],
            columns: Headcolumn,
            fitColumns: false,
            singleSelect: false,
            pagination: true,
            remoteSort: false,
            rownumbers: true,
            toolbar: toolbar,
            border: false,
            sortOrder: "asc",
            onLoadSuccess: function (data) {
                $("#SearchDlg").dialog("close");
            },
            onBeforeLoad: function (param) {
                param = $.JQForm.GetParam("EInvoiceManage", "EinvoiceList", "TableContainer", param);
            },
            rowStyler: function (index, row) {
                return 'height:20px;';
            }
        });
    }

    //展示进度
    LoadData();

    //推送发票
    function BillPush() {
        var rows = $("#TableContainer").datagrid('getSelections');
        var BillPushType = $("#BillPushType").val();
        if (BillPushType == 1) {
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].Email == "" || rows[i].Email == null) {
                    HDialog.Info("推送邮箱不能为空！");
                    return;
                }
            }
        } else {
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].PurchaserTel == "" || rows[i].PurchaserTel == null) {
                    HDialog.Info("推送电话不能为空！");
                    return;
                }
            }
        }

        $("#BillData").val(JSON.stringify(rows));

        $.messager.confirm('提示', '是否确认推送?', function (r) {
            if (r) {
                $.tool.DataPost("EInvoiceManage", "BillPush", $('#frmForm').serialize(),
                    function Init() { },
                    function callback(_Data) {
                        var data = JSON.parse(_Data);
                        if (data.state == "true") {
                            HDialog.Info(data.msg);
                            LoadData();
                        }
                        else {
                            HDialog.Info(data.msg);
                        }
                    },
                    function completeCallback() {
                    },
                    function errorCallback() {
                    });
            }
        });

        $("#PushDlg").dialog("close");
    }

    //红冲
    function EinvoiceFlush() {
        if ($("#InvoiceType").val() == "004") {
            if ($("#FlushReason").val() == "") {
                HDialog.Info("专票红冲申请原因必填");
                return;
            }
            if ($("#HZSQDBH").val() == "") {
                HDialog.Info("专票红冲红字通知单编号必填");
                return;
            }
        }

        $('#fReasonDlg').dialog('close');
        $.tool.DataPost("EInvoiceManage", "EinvoiceFlush", $('#frmForm').serialize(),
            function Init() { },
            function callback(_Data) {
                var data = JSON.parse(_Data);
                if (data.state == "true") {
                    HDialog.Info(data.msg);
                }
                else {
                    HDialog.Info(data.msg);
                }
                LoadData();
            },
            function completeCallback() {
            },
            function errorCallback() {
            });
    }

    //作废
    function EinvoiceInvalid() {
        $('#dReasonDlg').dialog('close');
        $.tool.DataPost("EInvoiceManage", "EinvoiceInvalid", $('#frmForm').serialize(),
            function Init() { },
            function callback(_Data) {
                var data = JSON.parse(_Data);
                if (data.state == "true") {
                    HDialog.Info(data.msg);
                }
                else {
                    HDialog.Info(data.msg);
                }
                LoadData();
            },
            function completeCallback() {
            },
            function errorCallback() {
            });
    }
    //修改开票信息
    function UpdateBillInfo(strCustID, strInvoiceID) {
        if (strCustID != "") {
            HDialog.Open('850', '300', '../ChargesNew/ChargeCustBillInfo.aspx?CustID=' + strCustID + '&InvoiceID=' + strInvoiceID + '', '开票信息', false, function callback(_Data) {
                if (_Data != "") {
                    LoadData();
                }
            });
        }
    }

</script>

