<!--#include file="conn.asp"-->
<% 
if session("login")<>"1" then
response.write("<script>alert('未登录或者登陆超时，请重新登陆！');window.location.href='login.asp';</script>")   
response.end() 
end if

if session("PoderArqueroCierre")="0" then
response.write("<script>alert('无权限！\nNo tienes permiso!');window.location.href='index.asp?get=good';</script>")   
response.end() 
end if

 %>
 <table width="100%"  height="80" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center">
	<span class="STYLE2">销售排行</span><br />
<span class="STYLE14">RANKING DE VENTAS</span><br />
<span class="STYLE2"><%= request.Form("key") %></span>
</td>
 </tr>
</table>

<% 

if request.Form("fecha")="" then
fecha=replace(year(DateAdd("d",-0,date()))&"-"&right("0"&month(DateAdd("d",-0,date())),2)&"-"&right("0"&day(DateAdd("d",-0,date())),2),"/","-")
else
fecha=replace(year(DateAdd("d",-0,request.Form("fecha")))&"-"&right("0"&month(DateAdd("d",-0,request.Form("fecha"))),2)&"-"&right("0"&day(DateAdd("d",-0,request.Form("fecha"))),2),"/","-")
end if

if request.Form("fecha2")="" then
fecha2=replace(year(DateAdd("d",-0,date()))&"-"&right("0"&month(DateAdd("d",-0,date())),2)&"-"&right("0"&day(DateAdd("d",-0,date())),2),"/","-")
else
fecha2=replace(year(DateAdd("d",-0,request.Form("fecha2")))&"-"&right("0"&month(DateAdd("d",-0,request.Form("fecha2"))),2)&"-"&right("0"&day(DateAdd("d",-0,request.Form("fecha2"))),2),"/","-")
end if

 %>
<form id="form1" name="form1" method="post" action="?get=consulta">
 <table width="100%" height="30px" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td>
    <div align="center">
      <input name="fecha" type="date" id="fecha" value="<%= fecha %>"  style="width:100px; height:25px;"/>
    -
    <input name="fecha2" type="date" id="fecha2" value="<%= fecha2 %>"  style="width:100px; height:25px;"/>
    <label>
    <select name="top" id="top"  style="width:80px; height:29px;">
	<% if request.Form("top")="" then %>
      <option value="10" selected="selected">TOP10</option>
      <option value="50">TOP50</option>
      <option value="100">TOP100</option>
      <option value="500">TOP500</option>
      <option value="1000">TOP1000</option>
	  <% else %>
	   <option value="<%= request.Form("top") %>" selected="selected">TOP<%= request.Form("top") %></option>
	   <option value="10">TOP10</option>
      <option value="50">TOP50</option>
      <option value="100">TOP100</option>
      <option value="500">TOP500</option>
      <option value="1000">TOP1000</option>
	  
	   <% end if %>
    </select>
    </label>
    </div>
    </label></td>
    <td width="30"><label>
      <div align="left" >
	   <INPUT type=image height="30" width="30" src="img/BUSCA.png" border=0 name="Submit2" onClick="this.form.submit()" autocomplete="off"/> 
      </div> </label></td>
  </tr>
  <tr>
    <td colspan="3">&nbsp; </td>
    </tr>
</table>
</form>


 <table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>
    <td width="30%" height="30" style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;"><div align="center"><span class="Menu1">条码</span><br /><span class="Menu2"> CODIGO</span></div></td>
    <td width="40%" height="30" style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;"><div align="center"><span class="Menu1">产品</span><br /><span class="Menu2"> PRODUCTO</span></div></td>
    <td width="15%" height="30" style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;"><div align="center"><span class="Menu1">销售量</span><br /><span class="Menu2"> VENTAS</span></div></td>
    <td width="15%" height="30" style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;"><div align="center"><span class="Menu1">库存</span><br /><span class="Menu2"> STOCK</span></div></td>
  </tr>
  <% 
if request.QueryString("get")="consulta"  then
conn.open Str
sql = "select *,Sum(Cantidad) as sum from ticketarticulo where left(DocumentoNo,6) BETWEEN '"& right(replace(fecha,"-",""),6) &"' and '"& right(replace(fecha2,"-",""),6) &"' GROUP BY ArticuloID ORDER BY Sum(Cantidad) DESC LIMIT "& request.Form("top") &"" 
set rs = conn.execute(sql)


 %>
  
  <%
       while not rs.eof
   %>
  
  <tr>
    <td width="30%" height="35" background="img/bj35.png"><div align="center"><a href="updategood.asp?ac=update&articuloid=<%= rs("ArticuloID") %>"><%= rs("ArticuloID") %></a></div></td>
	
	
    <td width="40%" height="35" background="img/bj35.png"><div align="center"><%= rs("Nombrees") %></div></td>	
    <td width="15%" height="35" background="img/bj35.png"><div align="center"><%= rs("sum") %></div></td>
	
	<%  
	sql2 = "select * from stock where ArticuloID = '"&rs("ArticuloID")&"'"
 set rs2 = conn.execute(sql2)
 
  if rs2.bof and rs2.eof then
stock="0"
else
stock=rs2("stock")
 end if
 
  %>
	
    <td width="15%" height="35" background="img/bj35.png"><div align="center"><%= stock %></div></td>
  </tr>
  <% 
  rs.movenext
  wend
rs.close 
  set rs=nothing 
  end if
%>
    <tr height="40">
  <td>  </td>
  </tr>
</table>
<div style="height:100px"/></div>
<!--#include file="fooder.asp"-->