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

 %> 
 
<% if request.QueryString("ac")="" then  %>
<table width="100%"  height="100" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center">
	<span class="STYLE2">挂单</span><br />
<span class="STYLE14">TIK.COLOGANDO</span><br />
<span class="STYLE2"><%= request.Form("key") %></span>
</td>
 </tr>
</table>

<div align="right">
  <%



 
conn.open Str
sql = "select SUM(total) AS ttotal,SUM(cantidadtotal) AS tcantidadtotal,COUNT(*) AS tLineaTotal from TicketColgando " 
set rs = conn.execute(sql)
ttotal=rs("ttotal")
tcantidadtotal=rs("tcantidadtotal")
tLineaTotal=rs("tLineaTotal")
set rs=nothing

sql = "select * from TicketColgando order by DocumentoNo desc "
set rs = conn.execute(sql)
 %>
  
  
   <a href="?ac=check&amp;ac2=addnt"><img src="img/jia.png" width="25" height="25" border="0"  /></a>
</div>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="25%"  height="30" style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;"><div align="center"><span class="Menu1">时间</span><br /><span class="Menu2">Fecha</span></div></td>
    <td width="25%" style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;"><div align="center"><span class="Menu1">备注</span><br /><span class="Menu2">Nota</span></div></td>
    <td width="25%" style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;"><div align="center"><span class="Menu1">总价</span><br /><span class="Menu2">TOTAL</span></div></td>
	<td height="30" colspan="2"  style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;"><div align="center"><span class="Menu1">操作</span><br /><span class="Menu2">OBRA</span></div></td>
  </tr>
 
<%
       while not rs.eof
   %>
  
  <tr>
    <td width="25%" height="35"  background="img/bj35.png"><div align="center"><%= rs("FechaEntrada") %></div></td>
    <td width="25%" height="35"  background="img/bj35.png"><div align="center"><%= rs("ColgarNota") %></div></td>
    <td width="25%" height="35"  background="img/bj35.png"><div align="center"><%= formatnumber(rs("Total"),2,-1,-1,0) %></div></td>
	<td height="35" background="img/bj35.png">
    <div align="center">
<a href="javascript:if(confirm('确实要删除该行吗?\nEstás seguro eliminar esta linea ?'))location='?ac=delt&DocumentoNo=<%=rs("DocumentoNo")%>'"><img src="img/del.png" width="20" height="20" border="0" /></a></div>
	</div></td>
    <td background="img/bj35.png"><div align="center"><a href="?ac=check&DocumentoNo=<%= rs("DocumentoNo") %>"/><img src="img/labi.png" width="20" height="20" border="0" /></a></div></td>
  </tr>
  
<% 
  rs.movenext
  wend
  rs.close
  conn.close
  set rs=nothing 

%>
</table>
 <table width="100%"  height="30" border="0" cellpadding="0" cellspacing="0"  style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;">
  <tr>
  
    <td align="center"><span class="Menu1">总单数：<%= tArticuloCategoria %></span></div></td>
    <td align="center"><span class="Menu1">总数量：<%= tcantidadtotal %></span></td>
    <td align="center"><span class="Menu1">总价：<%=  ttotal %></span></td>
    <td align="center"></td>
	
  </tr>
</table>
<% end if %>
<!----分界线---->

<% 


 if request.QueryString("ac")="add" and request.QueryString("DocumentoNo")<>"" then
 conn.open Str
sql = "select COUNT(*) AS NumberOfOrders,MAX(Ordenno) AS MaxordenNo from TicketColgandoarticulo where DocumentoNo= '"&request.QueryString("DocumentoNo")&"' "
set rs = conn.execute(sql)
if rs("NumberOfOrders")="0" then
MaxordenNo=1
else
MaxordenNo=RS("MaxordenNo")+1
end if
set rs=nothing

 
  sql = "select * from articulo where ArticuloID = '"&request.Form("key")&"'or Codigobarra = '"&request.Form("key")&"' OR FIND_IN_SET('"&request.Form("key")&"',multicodigo)"
  set rs = conn.execute(sql)
  
  if not(rs.bof and rs.eof) then 
  
  	if ventamode="1" then
	precio=rs("preciodetalle")
	else
	precio=rs("preciomayor")
	end if
	
	if billetecode="1" then
	precioxs=formatnumber(precio,2,-1,-1,0)
	else
	precioxs=precio
	end if
  
set add=conn.execute("insert TicketColgandoarticulo (DocumentoNo,ArticuloID,CodigoBarra,NombreES,NombreCN,Precio,Cantidad,CodigoBarraBalanza,Descuento,Comentario,Temporal,OrdenNo)values('"& request.QueryString("DocumentoNo") &"','"& rs("ArticuloID") &"','"& rs("CodigoBarra") &"','"& rs("NombreES") &"','"& rs("NombreCN") &"','"& precioxs &"',1,0,0,0,0,'"& MaxordenNo &"' )")
  
response.Redirect("?ac=check&DocumentoNo="&request.QueryString("DocumentoNo")&"")
response.End()

  else
  
  response.write("<script language='javascript'>alert('无此产品！\nArticulo no hay!');")   
response.write("javascript:history.go(-1);window.android.playFailed();</script>")
response.End()
end if








   conn.close
  set rs=nothing 
 end if

 if request.QueryString("ac")="upnota" and request.QueryString("DocumentoNo")<>"" then
 conn.open Str
set updatearticulo=conn.execute("update TicketColgando set ColgarNota='"& request.Form("ColgarNota") &"' where DocumentoNo='"&request.QueryString("DocumentoNo")&"' ")
response.Redirect("?")
response.End()
  conn.close
  set rs=nothing
end if

 if request.QueryString("ac")="mas" and request.QueryString("DocumentoNo")<>"" and request.QueryString("OrdenNo")<>"" then
 conn.open Str
set updatearticulo=conn.execute("update TicketColgandoarticulo set Cantidad='"& request.QueryString("Cantidad")+1 &"' where DocumentoNo='"&request.QueryString("DocumentoNo")&"' and  OrdenNo='"&request.QueryString("OrdenNo")&"' ")
response.Redirect("?ac=check&DocumentoNo="&request.QueryString("DocumentoNo")&"")
response.End()
  conn.close
  set rs=nothing
end if

if request.QueryString("ac")="menos" and request.QueryString("DocumentoNo")<>"" and request.QueryString("OrdenNo")<>"" then
 conn.open Str
set updatearticulo=conn.execute("update TicketColgandoarticulo set Cantidad='"& request.QueryString("Cantidad")-1 &"' where DocumentoNo='"&request.QueryString("DocumentoNo")&"' and  OrdenNo='"&request.QueryString("OrdenNo")&"' ")
response.Redirect("?ac=check&DocumentoNo="&request.QueryString("DocumentoNo")&"")
response.End()
  conn.close
  set rs=nothing
end if

if request.QueryString("ac")="accant" and request.QueryString("DocumentoNo")<>"" and request.QueryString("OrdenNo")<>"" then
 conn.open Str
set updatearticulo=conn.execute("update TicketColgandoarticulo set Cantidad='"& request.Form("Cantidad") &"',Precio='"& request.Form("Precio") &"' where DocumentoNo='"&request.QueryString("DocumentoNo")&"' and  OrdenNo='"&request.QueryString("OrdenNo")&"' ")
response.Redirect("?ac=check&DocumentoNo="&request.QueryString("DocumentoNo")&"")
response.End()
  conn.close
  set rs=nothing
end if


if request.QueryString("ac")="del" and request.QueryString("DocumentoNo")<>"" and request.QueryString("OrdenNo")<>"" then
 conn.open Str
sql = "delete from TicketColgandoarticulo where DocumentoNo='"&request.QueryString("DocumentoNo")&"' and  OrdenNo='"&request.QueryString("OrdenNo")&"'"
set rs = conn.execute(sql)
response.Redirect("?ac=check&DocumentoNo="&request.QueryString("DocumentoNo")&"")
response.End()
  conn.close
  set rs=nothing
end if


if request.QueryString("ac")="delt" and request.QueryString("DocumentoNo")<>"" then
 conn.open Str

sql = "delete from TicketColgando where DocumentoNo='"&request.QueryString("DocumentoNo")&"'"
set rs = conn.execute(sql)

sql = "delete from TicketColgandoarticulo where DocumentoNo='"&request.QueryString("DocumentoNo")&"'"
set rs = conn.execute(sql)

response.Redirect("?")  
response.End()
  conn.close
  set rs=nothing
end if



conn.open Str
sql = "delete from TicketColgandoarticulo where cantidad=0"
set rs = conn.execute(sql)
set rs=nothing
conn.close

conn.open Str
sql = "select SUM(cantidad*precio) AS total,SUM(Cantidad) AS cantidadtotal,COUNT(*) AS LineaTotal from TicketColgandoarticulo where DocumentoNo= '"&request.QueryString("DocumentoNo")&"' "
set rs = conn.execute(sql)

IF RS("LineaTotal")="0" THEN 

total="0"
Cantidadtotal="0"
LineaTotal="0"

ELSE
total=RS("TOTAL")
Cantidadtotal=RS("cantidadtotal")
LineaTotal=rs("LineaTotal")
END IF

set rs=nothing

set updateticketcolgando=conn.execute("update ticketcolgando set total='"& total &"',cantidadtotal='"&cantidadtotal &"',LineaTotal='"&LineaTotal &"',OperadorId='"&session("Empleadoid") &"' where DocumentoNo='"&request.QueryString("DocumentoNo")&"'")
conn.close


conn.open Str
sql = "delete from TicketColgando where cantidadTOTAL=0 and ColgarNota='' "
set rs = conn.execute(sql)
set rs=nothing
conn.close

if request.QueryString("DocumentoNo") <>"" then
conn.open Str
sql = "select * from TicketColgando where DocumentoNo= '"&request.QueryString("DocumentoNo")&"'"
set rs = conn.execute(sql)

If rs.bof and rs.eof then
response.Redirect("?")  
response.End()
else
colgarnota=rs("colgarnota")
end if


set rs=nothing
conn.close
end if

if request.QueryString("ac")="check" then



 %>

<table width="100%"  height="80" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center">
	<span class="STYLE2">挂单单据</span><br />
<span class="STYLE14">Ticket Colgando</span><br />
<span class="STYLE2"><%= request.Form("key") %></span>
</td>
 </tr>
</table>
<form id="form1" name="form1" method="post" action="?ac=add&DocumentoNo=<%= request.QueryString("DocumentoNo") %>">
<table width="100%"  height="30" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td>
      <label>
        <input name="key" type="text" id="key" style=" width:100%;height:30px;" autofocus="autofocus" align="right" autocomplete="off"/>
      </label></td>
		<td width="5%">
	  <INPUT type=image height="30" width="30" src="img/BUSCA.png" border=0 name="form1" onClick="this.form.submit()" autocomplete="off" /></td>
  </tr>
  <tr>
    <td height="20">&nbsp;</td>
    <td height="20">&nbsp;</td>
  </tr>
</table>
</form>

<% 

conn.open Str

if request.QueryString("ac2")="addnt" then
sql = "select * from TicketColgando"
set rs = conn.execute(sql)


If rs.bof and rs.eof then
set addnt=conn.execute("insert TicketColgando (DocumentoNo,Fechaentrada,fecha,ColgarNota)values('1 ','"& now() &"','"& now() &"','pda-' )")
else
set addnt=conn.execute("insert TicketColgando (Fechaentrada,fecha,ColgarNota)values('"& now() &"','"& now() &"','pda-' )")
end if


sql = "select max(DocumentoNo) as TDocumentoNo  from TicketColgando"
set rs = conn.execute(sql)

response.Redirect("?ac=check&DocumentoNo="&rs("TDocumentoNo") )
response.End()
set rs=nothing
end if


sql = "select * from TicketColgandoarticulo where DocumentoNo= '"&request.QueryString("DocumentoNo")&"'  order by ordenno desc "
set rs = conn.execute(sql)



 %>


 <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
    <td width="30%" height="35"  background="img/bj35.png" style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;" style="font-weight: bold">
      <div align="right" style="font-size: 24"><div align="center"><span class="Menu1">LINEA：<%= ArticuloCategoria %></span></div></div></td>
    <td width="25%"  background="img/bj35.png" style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;" ><div align="center" style="font-size: 24; font-weight: bold">
      <div align="center"><span class="Menu1">CANTIDAD:<%= cantidadtotal %></span></div>
    </div></td>
    <td height="35" colspan="3"  background="img/bj35.png" style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;"   ><div align="center" style="font-size: 24; font-weight: bold"><span class="Menu1">TOTAL:<%= total %></span></div>  </td>
   </tr>
<form action="?ac=upnota&DocumentoNo=<%= request.QueryString("DocumentoNo") %>" method="post" name="form3" id="form3">  
  <tr>
    <td  height="30"><div align="center">备注Nota：</div></td>
    <td colspan="3"><input name="ColgarNota" type="text" id="ColgarNota" value="<%= colgarnota %>" required="required"  style="width:100px; height:25px;"/><input type="submit" name="Submit" value="提交" style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;" class="Menu1"/></td>
    <td  height="30">
	<% if ArticuloCategoria<>"0" then %>
	<a href="recibo.asp?ac=print&url=tikcolgando.asp&DocumentoNo=<%= request.QueryString("DocumentoNo") %>"><img src="img/print.png" width="25" height="25" border="0" /></a>
	
	<% end if  %>
	</td>
  </tr>
  </form>
  <tr>
    <td width="30%"  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="25%" style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;"><div align="center"><span class="Menu1">数量</span><br /><span class="Menu2">CANT</span></div></div></td>
    <td width="10%" style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;"><div align="center"><span class="Menu1">售价</span><br /><span class="Menu2">PRECIO</span></div></div></td>
	<td width="15%" style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;"><div align="center"><span class="Menu1">小计</span><br /><span class="Menu2">SUMA</span></div></div></td>
	<td width="20%" style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;"><div align="center"><span class="Menu1"> 操作</span><br /><span class="Menu2">OBRA</span></div></td>
   </tr>
<%
       while not rs.eof
	  
   %>
    <form id="form2" name="form2" method="post" action="?ac=accant&DocumentoNo=<%=request.QueryString("DocumentoNo")%>&OrdenNo=<%=rs("OrdenNo")%>">

  <tr>
    <td width="30%" height="35"  background="img/bj35.png"><div align="center"><span class="STYLE15"><%= rs("NombreES") %><br /><%= rs("ArticuloID") %></span></div></td>
    <td width="25%"  background="img/bj35.png"><div align="center">
      <a href="?ac=menos&DocumentoNo=<%=request.QueryString("DocumentoNo")%>&OrdenNo=<%=rs("OrdenNo")%>&Cantidad=<%=rs("Cantidad")%>"/><img src="img/jian1.png" width="15" height="15" /></a>
      <input name="cantidad" type="number"/ id="cantidad"  style=" width:30px;height:20px; font-size:16px; text-align:center" value="<%= rs("Cantidad") %>" maxlength="3" autocomplete="off"  required="required" />
      <a href="?ac=mas&DocumentoNo=<%=request.QueryString("DocumentoNo")%>&OrdenNo=<%=rs("OrdenNo")%>&Cantidad=<%=rs("Cantidad")%>"/><img src="img/jia1.png" width="15" height="17" /></a></div></td>
    <td width="10%" height="35"  background="img/bj35.png">
	 <div align="center">
	   <label>
	   <input name="Precio" type="text" onKeyUp="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')" id="Precio"  style=" width:40px;height:20px; font-size:16px; text-align:center"  value="<%= formatnumber(rs("precio"),2,-1,-1,0) %>" autocomplete="off"  required="required" />
	   </label>
</div>	</td>
	<td width="15%" height="35"  background="img/bj35.png"><div align="center"> <%= formatnumber(ccur(rs("precio"))*ccur(rs("Cantidad")),2,-1,-1,0)  %></div></td>
	<td width="20%"  height="35" valign="middle" background="img/bj35.png"><label>
    <div align="center"><input type="image" name="ac" src="img/ac.png" width="20" height="20" onClick="document.form2.submit()">
<a href="javascript:if(confirm('确实要删除该产品吗?\nEstás seguro eliminar esta linea ?'))location='?ac=del&DocumentoNo=<%=request.QueryString("DocumentoNo")%>&OrdenNo=<%=rs("OrdenNo")%>'"><img src="img/del.png" width="20" height="20" border="0" /></a></div>
	</label>   </tr>
	</form>
	
	<% 
  rs.movenext
  wend
  rs.close
  conn.close
  set rs=nothing 

%>

</table>
<% end if %>
<div style="height:30px:"></div>
<!--#include file="fooder.asp"-->