<!--#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_SaleCount"   '其他权限

strFileName = "Admin_SaleCount.asp?Action=" & Action & "&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("销 售 统 计", 10203)
Response.Write "    <tr class='tdbg' height='30'> "
If Action = "NoDeliverCount" Then
    Response.Write "  <form name='form1' action='Admin_SaleCount.asp?Action=NoDeliverCount' method='post'>"
    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 ">今天未发货统计</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 "        </select>&nbsp;&nbsp;&nbsp;<a href='Admin_SaleCount.asp'>销售统计首页</a>&nbsp;|&nbsp;<a href='Admin_SaleCount.asp?Action=NoDeliverCount'>未发货商品统计</a></td>"
    Response.Write "  </form>"
    Response.Write "<form name='form2' method='post' action='Admin_SaleCount.asp?Action=NoDeliverCount'>"
    Response.Write "    <td>高级查询："
    Response.Write "      <select name='Field' id='Field'>"
    Response.Write "      <option value='ProductName'>商品名称</option>"
    Response.Write "      <option value='InputTime'>购买时间</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>"
Else
    Response.Write "  <form name='form1' action='Admin_SaleCount.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 ">今天销售统计</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 "        </select>&nbsp;&nbsp;&nbsp;<a href='Admin_SaleCount.asp'>销售统计首页</a>&nbsp;|&nbsp;<a href='Admin_SaleCount.asp?Action=NoDeliverCount'>未发货商品统计</a></td>"
    Response.Write "  </form>"
    Response.Write "<form name='form2' method='post' action='Admin_SaleCount.asp'>"
    Response.Write "    <td>高级查询："
    Response.Write "      <select name='Field' id='Field'>"
    Response.Write "      <option value='ProductName'>商品名称</option>"
    Response.Write "      <option value='InputTime'>购买时间</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>"
End If
Response.Write "</table>"
Response.Write "<br>"

If Action = "NoDeliverCount" Then
    Call NoDeliverCount
Else
    Call main
End If
If FoundErr = True Then
    Call WriteErrMsg(ErrMsg, ComeUrl)
End If
Response.Write "</body></html>"
Call CloseConn


Sub main()
    Dim rsCount, sql, i, iNum
    Dim OrderType
    OrderType = Trim(Request("OrderType"))
    If OrderType = "" Then
        OrderType = 1
    Else
        OrderType = PE_CLng(OrderType)
    End If
    
    Response.Write "<table width='100%'><tr><td align='left'><img src='images/img_u.gif' align='absmiddle'>您现在的位置：<a href='Admin_SaleCount.asp'>销售统计</a>&nbsp;&gt;&gt;&nbsp;"
    
    sql = "select I.ProductID,P.ProductName,P.Unit,sum(I.Amount) as tAmount,sum(I.SubTotal) as tSubTotal from PE_OrderFormItem I inner join PE_Product P on P.ProductID=I.ProductID "
    sql = sql & " where I.OrderFormID in (select OrderFormID from PE_OrderForm where MoneyReceipt>=MoneyTotal or MoneyReceipt>0) "
    Select Case SearchType
        Case 0
            Response.Write "所有商品销售统计"
        Case 1
            sql = sql & " and datediff(" & PE_DatePart_D & ",I.BeginDate," & PE_Now & ")<1"
            Response.Write "今天的商品销售统计"
        Case 2
            sql = sql & " and datediff(" & PE_DatePart_W & ",I.BeginDate," & PE_Now & ")<1"
            Response.Write "本周的商品销售统计"
        Case 3
            sql = sql & " and datediff(" & PE_DatePart_M & ",I.BeginDate," & PE_Now & ")<1"
            Response.Write "本月的商品销售统计"
        Case 10
            If Keyword = "" Then
                Response.Write "所有商品销售记录"
            Else
                Select Case strField
                Case "ProductName"
                    sql = sql & " and P.ProductName like '%" & Keyword & "%'"
                    Response.Write "商品名称中含有“ <font color=red>" & Keyword & "</font> ”的商品销售记录"
                Case "InputTime"
                    If IsDate(Keyword) = True Then
                        If SystemDatabaseType = "SQL" Then
                            sql = sql & " and I.BeginDate='" & Keyword & "'"
                        Else
                            sql = sql & " and I.BeginDate=#" & Keyword & "#"
                        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
    sql = sql & " group by I.ProductID,P.ProductName,P.Unit"
    Response.Write "</td></tr></table>"
    If FoundErr = True Then Exit Sub
    If OrderType = 1 Then
        sql = sql & " order by sum(I.Amount) desc"
    Else
        sql = sql & " order by sum(I.SubTotal) desc"
    End If
    Response.Write "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>"
    Response.Write "  <tr class='title' height='22' align='center'>"
    Response.Write "    <td width='60'><b>名次</b></td>"
    Response.Write "    <td><b>商 品 名 称</b></td>"
    Response.Write "    <td width='60'><b>单位</b></td>"
    Response.Write "    <td width='80'><b><a href='" & strFileName & "&MaxPerPage=" & MaxPerPage & "&OrderType=1'>销售数量</a></b></td>"
    Response.Write "    <td width='80'><b><a href='" & strFileName & "&MaxPerPage=" & MaxPerPage & "&OrderType=2'>销售金额</a></b></td>"
    Response.Write "  </tr>"
    
    Set rsCount = Server.CreateObject("Adodb.RecordSet")
    rsCount.Open sql, Conn, 1, 1
    If rsCount.BOF And rsCount.EOF Then
        totalPut = 0
        Response.Write "<tr class='tdbg' height='50'><td colspan='20' align='center'>没有任何商品销售记录！</td></tr>"
    Else
        strFileName = strFileName & "&OrderType=" & OrderType
        totalPut = rsCount.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
                rsCount.Move (CurrentPage - 1) * MaxPerPage
            Else
                CurrentPage = 1
            End If
        End If

        iNum = MaxPerPage * (CurrentPage - 1) + 1
        Do While Not rsCount.EOF
            Response.Write "  <tr class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">"
            Response.Write "    <td width='60' align=center>" & iNum & "</td>"
            Response.Write "    <td><a href='Admin_OrderItem.asp?SearchType=4&ProductID=" & rsCount("ProductID") & "'>" & rsCount("ProductName") & "</a></td>"
            Response.Write "    <td width='60' align=center>" & rsCount("Unit") & "</td>"
            Response.Write "    <td width='80' align='center'>" & rsCount("tAmount") & "</td>"
            Response.Write "    <td width='80' align='right'>" & FormatNumber(rsCount("tSubTotal"), 2, vbTrue, vbFalse, vbTrue) & "</td>"
            Response.Write "  </tr>"
            iNum = iNum + 1
            i = i + 1
            If i >= MaxPerPage Then Exit Do
            rsCount.MoveNext
        Loop
    End If
    rsCount.Close
    Set rsCount = Nothing
    
    Response.Write "</table>"
    Response.Write ShowPage(strFileName, totalPut, MaxPerPage, CurrentPage, True, True, "条商品记录", True)
    Response.Write "<br><b>提示：</b>点击“销售数量”或“销售金额”，可以改变排序方式。点击某个商品名称，可以查看详细的销售明细情况。"
End Sub

Sub NoDeliverCount()
    Dim rsCount, sql, i, iNum
    Dim OrderType, OrderType2
    OrderType = Trim(Request("OrderType"))
    If OrderType = "" Then
        OrderType = 1
    Else
        OrderType = PE_CLng(OrderType)
    End If
    OrderType2 = OrderType
    Response.Write "<table width='100%'><tr><td align='left'><img src='images/img_u.gif' align='absmiddle'>您现在的位置：<a href='Admin_SaleCount.asp?Action=NoDeliverCount'>未发货商品统计</a>&nbsp;&gt;&gt;&nbsp;"
    
    sql = "select I.ProductID,P.ProductName,P.Unit,sum(I.Amount) as NoDeliverAmount from PE_OrderFormItem I inner join PE_Product P on P.ProductID=I.ProductID "
    sql = sql & " where I.OrderFormID in (select OrderFormID from PE_OrderForm where (MoneyReceipt>=MoneyTotal or MoneyReceipt>0) And DeliverStatus<=1) "
    Select Case SearchType
        Case 0
            Response.Write "所有未发货商品统计"
        Case 1
            sql = sql & " and datediff(" & PE_DatePart_D & ",I.BeginDate," & PE_Now & ")<1"
            Response.Write "今天的未发货商品统计"
        Case 2
            sql = sql & " and datediff(" & PE_DatePart_W & ",I.BeginDate," & PE_Now & ")<1"
            Response.Write "本周的未发货商品统计"
        Case 3
            sql = sql & " and datediff(" & PE_DatePart_M & ",I.BeginDate," & PE_Now & ")<1"
            Response.Write "本月的未发货商品统计"
        Case 10
            If Keyword = "" Then
                Response.Write "所有未发货商品记录"
            Else
                Select Case strField
                Case "ProductName"
                    sql = sql & " and P.ProductName like '%" & Keyword & "%'"
                    Response.Write "商品名称中含有“ <font color=red>" & Keyword & "</font> ”的未发货商品记录"
                Case "InputTime"
                    If IsDate(Keyword) = True Then
                        If SystemDatabaseType = "SQL" Then
                            sql = sql & " and I.BeginDate='" & Keyword & "'"
                        Else
                            sql = sql & " and I.BeginDate=#" & Keyword & "#"
                        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
    sql = sql & " group by I.ProductID,P.ProductName,P.Unit"
    Response.Write "</td></tr></table>"
    If FoundErr = True Then Exit Sub
    If OrderType = 1 Then
        sql = sql & " order by sum(I.Amount) desc"
        OrderType = 2
    Else
        sql = sql & " order by sum(I.Amount) asc"
        OrderType = 1
    End If
    Response.Write "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>"
    Response.Write "  <tr class='title' height='22' align='center'>"
    Response.Write "    <td width='60'><b>名次</b></td>"
    Response.Write "    <td><b>商 品 名 称</b></td>"
    Response.Write "    <td width='60'><b>单位</b></td>"
    Response.Write "    <td width='80'><b><a href='" & strFileName & "&MaxPerPage=" & MaxPerPage & "&OrderType=" & OrderType & "'>未发货数量</a></b></td>"
    Response.Write "  </tr>"
    
    Set rsCount = Server.CreateObject("Adodb.RecordSet")
    rsCount.Open sql, Conn, 1, 1
    If rsCount.BOF And rsCount.EOF Then
        totalPut = 0
        Response.Write "<tr class='tdbg' height='50'><td colspan='20' align='center'>没有任何未发货商品记录！</td></tr>"
    Else
        strFileName = strFileName & "&OrderType=" & OrderType2
        totalPut = rsCount.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
                rsCount.Move (CurrentPage - 1) * MaxPerPage
            Else
                CurrentPage = 1
            End If
        End If

        iNum = MaxPerPage * (CurrentPage - 1) + 1
        Do While Not rsCount.EOF
            Response.Write "  <tr class='tdbg' onmouseout=""this.className='tdbg'"" onmouseover=""this.className='tdbgmouseover'"">"
            Response.Write "    <td width='60' align=center>" & iNum & "</td>"
            Response.Write "    <td><a href='Admin_OrderItem.asp?SearchType=4&ProductID=" & rsCount("ProductID") & "'>" & rsCount("ProductName") & "</a></td>"
            Response.Write "    <td width='60' align=center>" & rsCount("Unit") & "</td>"
            Response.Write "    <td width='80' align='center'>" & rsCount("NoDeliverAmount") & "</td>"
            Response.Write "  </tr>"
            iNum = iNum + 1
            i = i + 1
            If i >= MaxPerPage Then Exit Do
            rsCount.MoveNext
        Loop
    End If
    rsCount.Close
    Set rsCount = Nothing
    
    Response.Write "</table>"
    Response.Write ShowPage(strFileName, totalPut, MaxPerPage, CurrentPage, True, True, "条商品记录", True)
    Response.Write "<br><b>提示：</b>点击“未发货数量”，可以改变排序方式。点击某个商品名称，可以查看详细的销售明细情况。"
End Sub
%>
