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

<!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>
    <style type="text/css">
        .button {
            line-height: 28px;
            height: 28px;
            width: 60px;
            color: #ffffff;
            background-color: #3e73ca;
            font-size: 12px;
            font-weight: normal;
            font-family: 微软雅黑;
            border: 0px solid #dcdcdc;
            -webkit-border-top-left-radius: 3px;
            -moz-border-radius-topleft: 3px;
            border-top-left-radius: 3px;
            -webkit-border-top-right-radius: 3px;
            -moz-border-radius-topright: 3px;
            border-top-right-radius: 3px;
            -webkit-border-bottom-left-radius: 3px;
            -moz-border-radius-bottomleft: 3px;
            border-bottom-left-radius: 3px;
            -webkit-border-bottom-right-radius: 3px;
            -moz-border-radius-bottomright: 3px;
            border-bottom-right-radius: 3px;
            -moz-box-shadow: inset 0px 0px 0px 0px #ffffff;
            -webkit-box-shadow: inset 0px 0px 0px 0px #ffffff;
            box-shadow: inset 0px 0px 0px 0px #ffffff;
            text-align: center;
            display: inline-block;
            text-decoration: none;
        }

            .button:hover {
                background-color: #2b58a0;
            }
    </style>
</head>
<body>
    <form id="frmForm">
        <input id="BillData" name="BillData" value="" type="hidden" />
        <input id="RoomID" type="hidden" size="1" name="RoomID" runat="server" />
        <input id="CostIDs" type="hidden" name="CostIDs" runat="server" />
        <input id="CustID" type="hidden" name="CustID" runat="server" />
        <input name="SearchType" type="hidden" id="SearchType" value="Blue" />

        <input name="IsCreate" type="hidden" id="IsCreate" />

        <div id="TableContainer" style="width: 100%;"></div>
        <div id="SearchDlg" class="easyui-dialog" title="筛选条件" style="width: 700px; height: 230px;" data-options="iconCls:'icon-search',closed: true,modal:true">
            <table class="SearchTable" style="margin: 10px auto">
                <tr>
                    <td class="DialogTdTitle">业务类型</td>
                    <td class="DialogTdContent">
                        <select id="FType" name="FType" runat="server">
                            <option value="0" selected="selected">全部</option>
                            <option value="1">实收</option>
                            <%--  <option value="2">预收</option>--%>
                            <option value="3">单项预存</option>
                            <%--<option value="4">滞纳金</option>
                            <option value="5">预存冲抵</option>--%>
                            <option value="6">人工托收</option>
                            <option value="7">减免</option>
                        </select></td>
                    <td class="DialogTdTitle">费用时间从</td>
                    <td class="DialogTdContent">
                        <input id="FeesStartDate" class="Wdate" onclick="WdatePicker()" name="FeesStartDate" runat="server" /></td>
                    <td class="DialogTdTitle">到</td>
                    <td class="DialogTdContent">
                        <input id="FeesEndDate" class="Wdate" onclick="WdatePicker()" name="FeesEndDate" runat="server" /></td>

                </tr>
                <tr>
                    <td class="DialogTdTitle">客户名称</td>
                    <td class="DialogTdContent">
                        <input id="CustName" searcher="SelCust"
                            name="CustName" class="easyui-searchbox" data-options="editable:false" runat="server" />
                    </td>
                    <td class="DialogTdTitle">收款时间从</td>
                    <td class="DialogTdContent">
                        <input id="ChargeStartDate" class="Wdate" onclick="WdatePicker()" name="ChargeStartDate" runat="server" /></td>
                    <td class="DialogTdTitle">到</td>
                    <td class="DialogTdContent">
                        <input id="ChargeEndDate" class="Wdate" onclick="WdatePicker()" name="ChargeEndDate" runat="server" /></td>
                </tr>
                <tr>
                    <td class="DialogTdTitle">房屋编号</td>
                    <td class="DialogTdContent">
                        <input id="RoomSign" searcher="SelRoom" name="RoomSign" class="easyui-searchbox" data-options="editable:false" runat="server" /></td>
                    <td class="DialogTdTitle">费用名称</td>
                    <td class="DialogTdContent">
                        <input id="CostNames" class="easyui-searchbox" data-options="editable:false" searcher="SelCost"
                            name="CostNames" runat="server" /></td>
                    <td class="DialogTdTitle">开票状态</td>
                    <td class="DialogTdContent">
                        <select id="BillingState" name="BillingState">
                            <option value="">全部</option>
                            <option value="1">已发送</option>
                            <option value="2">开票成功</option>
                            <option value="3">开票失败</option>
                            <option value="4" selected="selected">未开票</option>
                        </select></td>
                </tr>
                <tr>
                    <td class="DialogTdTitle">发票号码</td>
                    <td class="DialogTdContent">
                        <input id="InvoiceNo" name="InvoiceNo" /></td>
                    <td class="DialogTdTitle">发票代码</td>
                    <td class="DialogTdContent">
                        <input id="InvoiceCode" name="InvoiceCode" /></td>
                    <td class="DialogTdTitle">收据号码</td>
                    <td class="DialogTdContent">
                        <input id="BillsSign" name="BillsSign" /></td>
                </tr>
                <tr>
                    <td class="DialogTdTitle">业务单号</td>
                    <td class="DialogTdContent">
                        <input id="OrderNo" name="OrderNo" />
                    </td>
                    <td class="DialogTdTitle">车位编号</td>
                    <td class="DialogTdContent">
                        <input id="ParkName" name="ParkName" />

                    </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(1);">生成并查询</a>
                        &nbsp;
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="LoadData(0);">查询</a>

                    </td>
                </tr>
            </table>
        </div>
        <script src="../jscript/CloseAjaxCache.js" type="text/javascript"></script>
        <script type="text/javascript">
            function SelCost() {

                var w = 700;
                var h = 400;

                HDialog.Open('700', '400', "../dialogNew/MultiCorpCommCostDlg.aspx", '收费项目选择', false, function callback(_Data) {

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

                        $('#CostIDs').val(varObjects[0]);
                        $('#CostNames').searchbox('setValue', varObjects[1]);
                    }
                });
            }
            function SelCust() {

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

                var w = $(window).width();
                var h = $(window).height();

                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);
                });
            }

            function SelRoom() {
                $('#RoomSign').searchbox("setValue", '');
                $('#RoomID').val('');

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

                var w = $(window).width();
                var h = $(window).height();

                HDialog.Open(w, h, conent, '房屋选择', false, function callback(_Data) {
                    var data = JSON.parse(_Data);
                    $('#RoomSign').searchbox("setValue", data.RoomSign);
                    $('#RoomID').val(data.RoomID);

                });
            }



            function InitFunction() {
                var h = $(window).height();
                $("#TableContainer").css("height", h + "px");
                $("#FType").on('change', function () {
                    if ($("#FType").val() == "3") {
                        $("#FeesStartDate").val("");
                        $("#FeesEndDate").val("");
                    }
                })
            }
            InitFunction();


            var Headcolumn = [
                [
                    { field: '', checkbox: true },
                    { field: 'CustName', title: '客户名称', align: 'center', sortable: true, width: 100 },
                    {
                        field: 'FType', title: '业务类型', align: 'center', sortable: true, width: 80, formatter: function (value, row, index) {
                            if (row.FType == "1") {
                                return "实收";
                            }
                            //if (row.FType == "2") {
                            //    return "预收";
                            //}
                            if (row.FType == "3") {
                                return "单项预存";
                            }
                            //if (row.FType == "4") {
                            //    return "滞纳金";
                            //}
                            //if (row.FType == "5") {
                            //    return "预存冲抵";
                            //}
                            if (row.FType == "6") {
                                return "人工托收";
                            }
                            if (row.FType == "7") {
                                return "减免";
                            }
                        }
                    },
                    { field: 'ParkName', title: '车位编号', align: 'center', sortable: true, width: 120 },
                    { field: 'RoomSign', title: '房屋编号', align: 'center', sortable: true, width: 120 },
                    { field: 'RoomName', title: '房屋名称', align: 'center', sortable: true, width: 120 },
                    { field: 'CostName', title: '费用名称', align: 'center', sortable: true, width: 100 },
                    {
                        field: 'FeesDueDate', title: '费用日期', align: 'center', sortable: true, width: 100, formatter: function (value, row, index) {
                            var str = formatDate(value, "yyyy-MM-dd");
                            return str;
                        }
                    },
                    {
                        field: 'FeesStateDate', title: '应收开始时间', align: 'center', sortable: true, width: 100, formatter: function (value, row, index) {
                            var str = formatDate(value, "yyyy-MM-dd");
                            return str;
                        }
                    },

                    {
                        field: 'FeesEndDate', title: '应收结束日期', align: 'center', sortable: true, width: 100, formatter: function (value, row, index) {

                            var str = formatDate(value, "yyyy-MM-dd");
                            return str;
                        }
                    },
                    { field: 'BillsSign', title: '收据号码', align: 'center', sortable: true, width: 100 },
                    //{ field: 'DueAmount', title: '应收金额', align: 'center', sortable: true, width: 100 },
                    { field: 'PaidAmount', title: '实收金额', align: 'center', sortable: true, width: 100 },
                    { field: 'OffsetAmount', title: '冲抵金额', align: 'center', sortable: true, width: 100 },
                    { field: 'WaivAmount', title: '减免金额', align: 'center', sortable: true, width: 100 },
                    //{ field: 'PrecAmount', title: '预收金额', align: 'center', sortable: true, width: 100 },
                    {
                        field: 'ChargeDate', title: '收款日期', align: 'center', sortable: true, width: 100, formatter: function (value, row, index) {

                            var str = formatDate(value, "yyyy-MM-dd");
                            return str;
                        }
                    },
                    {
                        field: 'State', title: '开票状态', align: 'center', sortable: true, width: 100, formatter: function (value, row, index) {
                            var str = "";
                            switch (row.State) {
                                //case "0":
                                //    str = "待发送";
                                //    break;
                                case "1":
                                    str = "已发送";
                                    break;
                                case "2":
                                    str = "开票成功";
                                    break;
                                case "3":
                                    str = "开票失败";
                                    break;
                                //case "5":
                                //    str = "扫码开票中";
                                //    break;
                                default:
                            }
                            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: 'BillingTime', title: '开票发起时间', align: 'center', sortable: true, width: 150, 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: '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: '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 == '81' || row.InvoiceType == '82') {
                                    var str = "<a class=\"HrefStyle\" target='_blank' href='" + urlarr[i] + "'>"
                                        + noarr[i] + "</a>";
                                    strarr.push(str);
                                } else {
                                    strarr.push(noarr[i]);
                                }
                            }

                            return strarr.join(",");
                        }
                    },
                    { field: 'InvoiceCode', title: '发票代码', align: 'center', sortable: true, width: 100 },
                    { field: 'ErrMsg', title: '备注', align: 'center', sortable: true, width: 150 }

                ]
            ];

            var toolbar = [
                {
                    text: '筛选',
                    iconCls: 'icon-filter',
                    handler: function () {
                        $('#SearchDlg').parent().appendTo($("form:first"));
                        $('#SearchDlg').dialog('open');
                    }
                }, '-',
                {
                    text: '开具发票',
                    iconCls: 'icon-add',
                    handler: function () {
                        var ob = $("#TableContainer").datagrid('getSelections');
                        if (ob.length > 0) {
                            //if (ob.length > 8) {
                            //    HDialog.Info("单次开票不能超过8条费用");
                            //    return;
                            //}
                            $("#BillData").val(JSON.stringify(ob));
                            var CustID = ob[0].CustID;
                            var RoomID = ob[0].RoomID;
                            var allAreWaive = true;
                            for (var i = 0; i < ob.length; i++) {
                                if (ob[i].CustID != CustID) {
                                    HDialog.Info("请选择同一客户");
                                    return;
                                }
                                if (ob[i].State == "1") {
                                    HDialog.Info("费用已发起开票");
                                    return;
                                }
                                if (ob[i].State == "2") {
                                    HDialog.Info("费用已完成开票");
                                    return;
                                }
                                //if (ob[i].State == "5") {
                                //    HDialog.Info("费用已发起扫码开票");
                                //    return;
                                //}
                                //判断是否全为减免（FType= "7"）
                                if (ob[i].FType !== "7") {
                                    allAreWaive = false;
                                    break;
                                }
                            }
                            if (allAreWaive) {
                                HDialog.Info("减免费用不能单独开票，请选择其他业务类型一起开票");
                                return;
                            }
                            //判断开票费项是否属于同一销方
                            $.tool.DataPostNoLoading("EInvoiceManage", "CheckEInvoiceSells", $('#frmForm').serialize(),
                                function Init() { },
                                function callback(_Data) {
                                    //发起开票
                                    if (_Data == "true") {

                                        var FeesMsgs = new Array();
                                        for (var i = 0; i < ob.length; i++) {
                                            FeesMsgs.push(ob[i].RFID + "|" + ob[i].RoomID + "|" + ob[i].FType);
                                        }
                                        sessionStorage.setItem("BillFeesMsg", FeesMsgs.join(","));

                                        var w = 900;
                                        var h = $(window).height();
                                        HDialog.OpenWin(w, h, "../ChargesNew/EInvoiceManage.aspx?CustName=" + ob[0].CustName + "&CustID=" + CustID + "&RoomID=" + RoomID, "开票确认", true, function callback(_Data) {
                                            if (_Data != '') {
                                                LoadData(1);
                                            }
                                        });
                                    }
                                    else {
                                        HDialog.Info("当前选择的开票费用不属于同一销方,请重新选择");
                                    }
                                },
                                function completeCallback() {
                                },
                                function errorCallback() {
                                }
                            );

                        }
                        else {
                            HDialog.Info("请选择费用");
                        }

                    }
                }
                , '-',
                //{
                //    text: '查询发票',
                //    iconCls: 'icon-print',
                //    handler: function () {

                //        var ob = $("#TableContainer").datagrid('getSelections');
                //        if (ob.length > 0) {
                //            $("#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(1);
                //                },
                //                function completeCallback() {
                //                },
                //                function errorCallback() {
                //                }
                //            );
                //        }
                //        else {
                //            HDialog.Info("请选择费用");
                //        }

                //    }
                //}, '-',
                {
                    text: 'Excel导出',
                    iconCls: 'icon-page_white_excel',
                    handler: function () {
                        window.open("../ChargesNew/EInvoiceBrowseCreExcel.aspx");
                    }
                }
            ];

            var strCustID = sessionStorage.getItem("OnlineCust");
            if (strCustID != "") {
                $("#CustID").val(strCustID);
            }
            //sessionStorage.removeItem("OnlineCust");

            //加载数据
            function LoadData(Type) {

                $("#TableContainer").datagrid({
                    url: '/HM/M_Main/HC/DataPostControl.aspx',
                    method: "post",
                    nowrap: false,
                    pageSize: top.ListPageSize,
                    pageList: top.ListPageList,
                    columns: Headcolumn,
                    fitColumns: false,
                    singleSelect: false,
                    pagination: true,
                    remoteSort: false,
                    rownumbers: true,
                    toolbar: toolbar,
                    border: false,
                    sortOrder: "asc",
                    onLoadSuccess: function (data) {
                        //$.each(data.rows, function (rowindex, rowdata) {
                        //    if (rowdata.spbm == "" || rowdata.spbm == null || rowdata.spbm == undefined) {
                        //        $("input[type='checkbox']")[rowindex + 1].disabled = true;
                        //    }
                        //});
                    },
                    onClickRow: function (rowindex, rowdata) {
                        //if (rowdata.spbm == "" || rowdata.spbm == null || rowdata.spbm == undefined) {
                        //    $('#TableContainer').datagrid('uncheckRow', rowindex);
                        //}
                    },
                    onBeforeLoad: function (param) {
                        if (Type == "1") {
                            $("#IsCreate").val("1");
                        }
                        else {
                            $("#IsCreate").val("0");
                        }
                        param = $.JQForm.GetParam("EInvoiceManage", "FeesList", "TableContainer", param);
                    },
                    rowStyler: function (index, row) {
                        return 'height:20px;';
                    }
                });
                $("#SearchDlg").dialog("close");
            }

            //展示进度
            LoadData(1);


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