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

Sub Main()
    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='border2'>"
    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)
End Sub
%>
