<!--#include file="Admin_Common.asp"-->
<%
'**************************************************************
' Software name: PowerEasy SiteWeaver
' Web: http://www.powereasy.net
' Copyright (C) 2005－2009 佛山市动易网络科技有限公司 版权所有
'**************************************************************

Const NeedCheckComeUrl = True   '是否需要检查外部访问

Const PurviewLevel = 2      '0--不检查，1--超级管理员，2--普通管理员
Const PurviewLevel_Channel = 0   '0--不检查，1--频道管理员，2--栏目总编，3--栏目管理员
Const PurviewLevel_Others = "Order_Invoice"   '其他权限

strFileName = "Admin_Invoice.asp?SearchType=" & SearchType & "&Field=" & strField & "&Keyword=" & Keyword

Response.Write "<html><head><title>发票记录查询</title>"
Response.Write "<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>"
Response.Write "<link rel='stylesheet' href='Admin_Style.css' type='text/css'>"
Response.Write "</head>"
Response.Write "<body leftmargin='2' topmargin='0' marginwidth='0' marginheight='0'>"
Response.Write "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' Class='border'>"
Call ShowPageTitle("发 票 记 录 查 询", 10206)
Response.Write "    <tr class='tdbg' height='30'> "
Response.Write "  <form name='form1' action='Admin_Invoice.asp' method='get'>"
Response.Write "      <td>快速查找："
Response.Write "      <select size=1 name='SearchType' onChange='javascript:submit()'>"
Response.Write "          <option value='0'"
If SearchType = 0 Then Response.Write " selected"
Response.Write ">所有记录</option>"
Response.Write "          <option value='1'"
If SearchType = 1 Then Response.Write " selected"
Response.Write ">最近10天内的新记录</option>"
Response.Write "          <option value='2'"
If SearchType = 2 Then Response.Write " selected"
Response.Write ">最近一月内的新记录</option>"
Response.Write "          <option value='3'"
If SearchType = 3 Then Response.Write " selected"
Response.Write ">所有地税普通发票</option>"
Response.Write "          <option value='4'"
If SearchType = 4 Then Response.Write " selected"
Response.Write ">所有国税普通发票</option>"
Response.Write "          <option value='5'"
If SearchType = 5 Then Response.Write " selected"
Response.Write ">所有增值税发票</option>"
Response.Write "        </select>&nbsp;&nbsp;&nbsp;&nbsp;<a href='Admin_Invoice.asp'>发票记录首页</a></td>"
Response.Write "  </form>"
Response.Write "<form name='form2' method='post' action='Admin_Invoice.asp'>"
Response.Write "    <td>高级查询："
Response.Write "      <select name='Field' id='Field'>"
Response.Write "      <option value='ClientName' selected>客户名称</option>"
Response.Write "      <option value='ContacterName'>收货人姓名</option>"
Response.Write "      <option value='UserName'>论坛用户名</option>"
Response.Write "      <option value='ExpressCompany'>快递公司名</option>"
Response.Write "      <option value='ExpressNumber'>快递单号</option>"
Response.Write "      <option value='HandlerName'>经手人</option>"
Response.Write "      <option value='InvoiceDate'>发票日期</option>"
Response.Write "      </select>"
Response.Write "      <input name='Keyword' type='text' id='Keyword' size='20' maxlength='30'>"
Response.Write "      <input type='submit' name='Submit2' value=' 查 询 '>"
Response.Write "      <input name='SearchType' type='hidden' id='SearchType' value='10'>"
Response.Write " </td>"
Response.Write "</form>"
Response.Write "</table>"
Response.Write "<br>"
If Action = "Show" Then
    Call Show
Else
    Call main
End If
If FoundErr = True Then
    Call WriteErrMsg(ErrMsg, ComeUrl)
End If
Response.Write "</body></html>"
Call CloseConn


Sub main()
    Dim rsInvoice, sql
    Dim TotalMoney
    TotalMoney = 0
    
    sql = "select I.*,O.OrderFormNum,C.ShortedForm as ClientName from PE_InvoiceItem I left join (PE_OrderForm O left join PE_Client C on O.ClientID=C.ClientID) on I.OrderFormID=O.OrderFormID "
    Response.Write "<table width='100%'><tr><td align='left'><img src='images/img_u.gif' align='absmiddle'>您现在的位置：<a href='Admin_Invoice.asp'>发票记录管理</a>&nbsp;&gt;&gt;&nbsp;"
    Select Case SearchType
        Case 0
            sql = sql & " order by I.InvoiceID desc"
            Response.Write "所有记录"
        Case 1
            sql = sql & " where datediff(" & PE_DatePart_D & ",I.InvoiceDate," & PE_Now & ")<10 order by I.InvoiceID desc"
            Response.Write "最近10天内的新记录"
        Case 2
            sql = sql & " where datediff(" & PE_DatePart_M & ",I.InvoiceDate," & PE_Now & ")<1 order by I.InvoiceID desc"
            Response.Write "最近一月内的新记录"
        Case 3
            sql = sql & " where I.InvoiceType=0 order by I.InvoiceID desc"
            Response.Write "所有地税普通发票"
        Case 4
            sql = sql & " where I.InvoiceType=1 order by I.InvoiceID desc"
            Response.Write "所有国税普通发票"
        Case 5
            sql = sql & " where I.InvoiceType=2 order by I.InvoiceID desc"
            Response.Write "所有增值税发票"
        Case 10
            If Keyword = "" Then
                sql = sql & " order by I.InvoiceID desc"
                Response.Write "所有记录"
            Else
                Select Case strField
                Case "ClientName"
                    sql = sql & " where C.ClientName like '%" & Keyword & "%' order by I.InvoiceID desc"
                    Response.Write "客户名称中含有“ <font color=red>" & Keyword & "</font> ”的记录"
                Case "Drawer"
                    sql = sql & " where I.Drawer='" & Keyword & "' order by I.InvoiceID desc"
                    Response.Write "开票人为 <font color=red>" & Keyword & "</font> 的记录"
                Case "InvoiceDate"
                    If IsDate(Keyword) = True Then
                        If SystemDatabaseType = "SQL" Then
                            sql = sql & " where I.InvoiceDate='" & Keyword & "'  order by I.InvoiceID desc"
                        Else
                            sql = sql & " where I.InvoiceDate=#" & Keyword & "#  order by I.InvoiceID desc"
                        End If
                        Response.Write "发票日期为 <font color=red>" & Keyword & "</font> 的记录"
                    Else
                        FoundErr = True
                        ErrMsg = ErrMsg & "<li>查询的发票日期格式不正确！</li>"
                    End If
                End Select
            End If
        Case Else
            FoundErr = True
            ErrMsg = ErrMsg & "<li>错误的参数！</li>"
    End Select
    Response.Write "</td></tr></table>"
    If FoundErr = True Then Exit Sub
    
    Response.Write "<table width='100%' border='0' cellpadding='2' cellspacing='1' class='border'>"
    Response.Write "  <tr align='center' class='title'>"
    Response.Write "    <td width='80'>日期</td>"
    Response.Write "    <td width='60'>客户名称</td>"
    Response.Write "    <td width='60'>用户名</td>"
    Response.Write "    <td width='100'>订单编号</td>"
    Response.Write "    <td width='80'>发票类型</td>"
    Response.Write "    <td width='80'>发票号码</td>"
    Response.Write "    <td>发票抬头</td>"
    Response.Write "    <td width='60'>发票金额</td>"
    Response.Write "    <td width='60'>开票人</td>"
    Response.Write "    <td width='40'>查看</td>"
    Response.Write "  </tr>"
    
    Set rsInvoice = Server.CreateObject("Adodb.RecordSet")
    rsInvoice.Open sql, Conn, 1, 1
    If rsInvoice.BOF And rsInvoice.EOF Then
        totalPut = 0
        Response.Write "<tr class='tdbg' height='50'><td colspan='20' align='center'>没有任何符合条件的记录！</td></tr>"
    Else
        totalPut = rsInvoice.RecordCount
        If CurrentPage < 1 Then
            CurrentPage = 1
        End If
        If (CurrentPage - 1) * MaxPerPage > totalPut Then
            If (totalPut Mod MaxPerPage) = 0 Then
                CurrentPage = totalPut \ MaxPerPage
            Else
                CurrentPage = totalPut \ MaxPerPage + 1
            End If
        End If
        If CurrentPage > 1 Then
            If (CurrentPage - 1) * MaxPerPage < totalPut Then
                rsInvoice.Move (CurrentPage - 1) * MaxPerPage
            Else
                CurrentPage = 1
            End If
        End If
    
        Dim i
        i = 0
        Do While Not rsInvoice.EOF
            Response.Write "  <tr class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">"
            Response.Write "    <td width='80' align='center'>" & rsInvoice("InvoiceDate") & "</td>"
            Response.Write "    <td width='60' align='center'><a href='Admin_Client.asp?Action=Show&InfoType=4&ClientID=" & rsInvoice("ClientID") & "'>" & rsInvoice("ClientName") & "</a></td>"
            Response.Write "    <td width='60' align='center'><a href='Admin_User.asp?Action=Show&UserName=" & rsInvoice("UserName") & "'>" & rsInvoice("UserName") & "</a></td>"
            Response.Write "    <td width='100' align='center'><a href='Admin_Order.asp?Action=ShowOrder&OrderFormID=" & rsInvoice("OrderFormID") & "'>" & rsInvoice("OrderFormNum") & "</a></td>"
            Response.Write "    <td width='80' align='center'>"
            Select Case rsInvoice("InvoiceType")
            Case 0
                Response.Write "地税普通发票"
            Case 1
                Response.Write "国税普通发票"
            Case 2
                Response.Write "增值税发票"
            End Select
            Response.Write "</td>"
            Response.Write "    <td width='80' align='center'><a href='Admin_Invoice.asp?Action=Show&InvoiceID=" & rsInvoice("InvoiceID") & "'>" & rsInvoice("InvoiceNum") & "</a></td>"
            Response.Write "    <td><a href='Admin_Invoice.asp?Action=Show&InvoiceID=" & rsInvoice("InvoiceID") & "'>" & rsInvoice("InvoiceTitle") & "</a></td>"
            Response.Write "    <td width='60' align='right'>" & rsInvoice("TotalMoney") & "</td>"
            Response.Write "    <td width='60' align='center'>" & rsInvoice("Drawer") & "</td>"
            Response.Write "    <td width='40' align='center'><a href='Admin_Invoice.asp?Action=Show&InvoiceID=" & rsInvoice("InvoiceID") & "'>查看</a></td>"
            Response.Write "  </tr>"
    
            i = i + 1
            If i >= MaxPerPage Then Exit Do
            rsInvoice.MoveNext
        Loop
    End If
    rsInvoice.Close
    Set rsInvoice = Nothing

    Response.Write "</table>"
    Response.Write ShowPage(strFileName, totalPut, MaxPerPage, CurrentPage, True, True, "条记录", True)
End Sub

Sub Show()
    Dim InvoiceID
    Dim rsInvoice
    Dim rsOrderForm, sqlOrderForm
    Dim OrderFormNum, MoneyTotal, MoneyReceipt
    InvoiceID = PE_CLng(Trim(Request("InvoiceID")))
    If InvoiceID <= 0 Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>参数不足！</li>"
        Exit Sub
    End If
    Set rsInvoice = Conn.Execute("select I.*,C.ShortedForm as ClientName from PE_InvoiceItem I left join PE_Client C on I.ClientID=C.ClientID where I.InvoiceID=" & InvoiceID & "")
    If rsInvoice.BOF And rsInvoice.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>找不到指定的发票记录！</li>"
        rsInvoice.Close
        Set rsInvoice = Nothing
        Exit Sub
    Else
        sqlOrderForm = "select * from PE_OrderForm where OrderFormID=" & rsInvoice("OrderFormID")
        Set rsOrderForm = Conn.Execute(sqlOrderForm)
        If Not (rsOrderForm.BOF And rsOrderForm.EOF) Then
            OrderFormNum = rsOrderForm("OrderFormNum")
            MoneyTotal = rsOrderForm("MoneyTotal")
            MoneyReceipt = rsOrderForm("MoneyReceipt")
        End If
    End If
    
    Response.Write "  <table width='100%' border='0' cellpadding='2' cellspacing='1' class='border'>"
    Response.Write "    <tr align='center' class='title'>"
    Response.Write "      <td height='22' colspan='2'><b>发 票 信 息</b></td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>客户名称：</td>"
    Response.Write "      <td>" & rsInvoice("ClientName") & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>订单编号：</td>"
    Response.Write "      <td>" & OrderFormNum & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>订单金额：</td>"
    Response.Write "      <td>" & MoneyTotal & "元</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>已 付 款：</td>"
    Response.Write "      <td>" & MoneyReceipt & "元</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>开票日期：</td>"
    Response.Write "      <td>" & rsInvoice("InvoiceDate") & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>发票类型：</td>"
    Response.Write "      <td>"
    Select Case rsInvoice("InvoiceType")
    Case 0
        Response.Write "地税普通发票"
    Case 1
        Response.Write "国税普通发票"
    Case 2
        Response.Write "增值税发票"
    End Select
    Response.Write "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>发票号码：</td>"
    Response.Write "      <td>" & rsInvoice("InvoiceNum") & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>发票抬头：</td>"
    Response.Write "      <td>" & rsInvoice("InvoiceTitle") & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>发票内容：</td>"
    Response.Write "      <td>" & PE_HTMLEncode(rsInvoice("InvoiceContent")) & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>发票金额：</td>"
    Response.Write "      <td>" & rsInvoice("TotalMoney") & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>开 票 人：</td>"
    Response.Write "      <td>" & rsInvoice("Drawer") & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>录 入 员：</td>"
    Response.Write "      <td>" & rsInvoice("Inputer") & "</td>"
    Response.Write "    </tr>"
    Response.Write "    <tr class='tdbg'>"
    Response.Write "      <td width='15%' class='tdbg5' align='right'>录入时间：</td>"
    Response.Write "      <td>" & rsInvoice("InputTime") & "</td>"
    Response.Write "    </tr>"
    Response.Write "  </table>"
    Response.Write "<br><div align='center'><input type='button' name='button' value=' 返 回 ' onclick='javascript:history.go(-1)'></div>"
    rsOrderForm.Close
    Set rsOrderForm = Nothing
    rsInvoice.Close
    Set rsInvoice = Nothing
    
End Sub
%>
