<!--#include file="User_CommonCode.asp"-->
<!--#include file="../inc/function.asp"-->
<%
If CheckUserLogined() = False Then
    Call CloseConn
    Response.Redirect "User_Login.asp"
End If
%>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title><%=SiteName & " >> 会员中心"%></title>
<link href='../Skin/DefaultSkin.css' rel='stylesheet' type='text/css'>
</head>
<body leftmargin=0 topmargin=0>
<!--#include file="top.asp"-->
<!-- ********网页中部代码开始******** -->
<table width="756" border="0" align="center" cellpadding="0" cellspacing="0" class="user_border">
  <tr>
    <td valign="top">
      <table width="100%" border="0" cellpadding="5" cellspacing="0" class="user_box">
        <tr>
          <td class="user_righttitle"><img src="Images/point2.gif" align="absmiddle">
          <%
                Response.Write "您现在的位置：<a href='../'>" & SiteName & "</a> >> <a href='Index.asp'>会员中心</a> >> 我的对账单"
          %></td>
        </tr>
        <tr>
          <td height="200" valign='top'>
            <% Call Main() %>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<!--#include file="bottom.asp"-->
</body>
</html>
<% Call CloseConn %>
<!--用户页面开始-->

<%
Private MaxPerPage, CurrentPage, totalPut
Private strFileName, ScriptName, ClientName, ShortedForm
Private SearchType, Keyword, strField, OrderType

Private IncludeTax, TaxRate


Public Sub Main()

    FoundErr = False
    ErrMsg = ""

    ComeUrl = Trim(Request.ServerVariables("HTTP_REFERER"))
    ScriptName = Trim(Request.ServerVariables("SCRIPT_NAME"))
    strInstallDir = GetScriptPath(ScriptName, 1)
    Site_Sn = Replace(Replace(LCase(Request.ServerVariables("SERVER_NAME") & strInstallDir), "/", ""), ".", "")
    
  
    Dim rsClient
    Set rsClient = Conn.Execute("select ClientName,ShortedForm from PE_Client where ClientID=" & ClientID & "")
    If rsClient.BOF And rsClient.EOF Then
        ClientName = ""
        ShortedForm = ""
    Else
        ClientName = rsClient(0)
        ShortedForm = rsClient(1)
    End If
    rsClient.Close
    Set rsClient = Nothing

    MaxPerPage = PE_CLng(Trim(Request("MaxPerPage")))
    Keyword = Trim(Request("keyword"))
    strField = Trim(Request("Field"))
    SearchType = Trim(Request("SearchType"))
    Action = Trim(Request("Action"))

    
    If MaxPerPage <= 0 Then MaxPerPage = 20
    If Keyword <> "" Then
        Keyword = ReplaceBadChar(Keyword)
    End If
    If SearchType = "" Then
        SearchType = 0
    Else
        SearchType = PE_CLng(SearchType)
    End If
    OrderType = PE_CLng(Trim(Request("OrderType")))
    strFileName = "User_Bill.asp?Field=" & strField & "&Keyword=" & Keyword
    If Request("page") <> "" Then
        CurrentPage = CInt(Request("page"))
    Else
        CurrentPage = 1
    End If
  
    Response.Write "<br>"
    
    Response.Write "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>"
    Response.Write "  <tr align='center' class='title'>"
    Response.Write "    <td width='200'>交易时间</td>"
    Response.Write "    <td width='110'>订单号</td>"
    Response.Write "    <td width='80'>收入金额</td>"
    Response.Write "    <td width='80'>支出金额</td>"
    Response.Write "    <td>备注/说明</td>"
    Response.Write "  </tr>"
    
    Dim rsBankroll, sqlBankroll, TotalIncome, TotalPayout
    TotalIncome = 0
    TotalPayout = 0
    sqlBankroll = "select Max(O.OrderFormNum) as tOrderFormNum,sum(B.Money) as tMoney,Max(B.DateAndTime) as tDateAndTime,Max(B.Remark) as tRemark From PE_BankrollItem B Left join PE_OrderForm O On B.OrderFormID=O.OrderFormID where B.UserName='" & UserName & "' Group By B.OrderFormID"
    Set rsBankroll = Server.CreateObject("Adodb.RecordSet")
    rsBankroll.Open sqlBankroll, Conn, 1, 1
    If rsBankroll.BOF And rsBankroll.EOF Then
        totalPut = 0
        Response.Write "<tr class='tdbg' height='50'><td colspan='20' align='center'>没有任何资金明细记录！</td></tr>"
    Else
        totalPut = rsBankroll.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
                rsBankroll.Move (CurrentPage - 1) * MaxPerPage
            Else
                CurrentPage = 1
            End If
        End If
    
        Dim i
        i = 0
        Do While Not rsBankroll.EOF
            If rsBankroll("tMoney") > 0 Then
                TotalIncome = TotalIncome + rsBankroll("tMoney")
            Else
                TotalPayout = TotalPayout + rsBankroll("tMoney")
            End If
    
            Response.Write "  <tr class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">"
            Response.Write "    <td width='200' align='center'>" & rsBankroll("tDateAndTime") & "</td>"
            Response.Write "    <td width='110' align='center'>"
            Response.Write rsBankroll("tOrderFormNum")
            Response.Write "</td>"
            Response.Write "    <td width='80' align='right'>"
            If rsBankroll("tMoney") > 0 Then Response.Write FormatNumber(rsBankroll("tMoney"), 2, vbTrue, vbFalse, vbTrue)
            Response.Write "</td>"
            Response.Write "    <td width='80' align='right'>"
            If rsBankroll("tMoney") <= 0 Then Response.Write FormatNumber(Abs(rsBankroll("tMoney")), 2, vbTrue, vbFalse, vbTrue)
            Response.Write "</td>"
            Response.Write "    <td align='center'>" & rsBankroll("tRemark") & "</td>"
            Response.Write "  </tr>"
    
            i = i + 1
            If i >= MaxPerPage Then Exit Do
            rsBankroll.MoveNext
        Loop
    End If
    rsBankroll.Close
    Set rsBankroll = Nothing

    Response.Write "  <tr class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">"
    Response.Write "    <td colspan='2' align='right'>本页合计：</td>"
    Response.Write "    <td align='right'>" & FormatNumber(TotalIncome, 2, vbTrue, vbFalse, vbTrue) & "</td>"
    Response.Write "    <td align='right'>" & FormatNumber(Abs(TotalPayout), 2, vbTrue, vbFalse, vbTrue) & "</td>"
    Response.Write "    <td align='center'> </td>"
    
    Dim trs, TotalIncomeAll, TotalPayoutAll
    Set trs = Conn.Execute("select sum(Money) from PE_BankrollItem where Money>0 and UserName='" & UserName & "'")
    If IsNull(trs(0)) Then
        TotalIncomeAll = 0
    Else
        TotalIncomeAll = trs(0)
    End If
    Set trs = Nothing
    Set trs = Conn.Execute("select sum(Money) from PE_BankrollItem where Money<0 and UserName='" & UserName & "'")
    If IsNull(trs(0)) Then
        TotalPayoutAll = 0
    Else
        TotalPayoutAll = trs(0)
    End If
    Set trs = Nothing
    Response.Write "  <tr class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">"
    Response.Write "    <td colspan='2' align='right'>总计金额：</td>"
    Response.Write "    <td align='right'>" & FormatNumber(TotalIncomeAll, 2, vbTrue, vbFalse, vbTrue) & "</td>"
    Response.Write "    <td align='right'>" & FormatNumber(Abs(TotalPayoutAll), 2, vbTrue, vbFalse, vbTrue) & "</td>"
    Response.Write "    <td colspan='5' align='right'><strong>资金余额：" & FormatNumber(TotalIncomeAll + TotalPayoutAll, 2, vbTrue, vbFalse, vbTrue) & "</strong></td>"
    'Response.Write "    <td align='center'>资金余额：" & FormatNumber(TotalIncomeAll + TotalPayoutAll, 2, vbTrue, vbFalse, vbTrue) & "</td>"
    Response.Write "  </tr>"
    Response.Write "  </tr>"
    Response.Write "</table>"
    Response.Write ShowPage("User_Bill.asp", totalPut, MaxPerPage, CurrentPage, True, True, "条对账记录", True)

    If FoundErr = True Then
        Response.Write WriteErrMsg(ErrMsg, ComeUrl)
    End If
    Call CloseConn

End Sub


Private Function GetArrFromDictionary(strTableName, strFieldName)
    Dim rsDictionary
    Set rsDictionary = Conn.Execute("select FieldValue from PE_Dictionary where TableName='" & strTableName & "' and FieldName='" & strFieldName & "'")
    If rsDictionary.BOF And rsDictionary.EOF Then
        GetArrFromDictionary = ""
    Else
        GetArrFromDictionary = rsDictionary(0)
    End If
    Set rsDictionary = Nothing
End Function
%>