<!--#include file="../Inc/Conn.asp" -->
<!--#include file="../Inc/SK.Session.asp" -->
<!--#include file="../Inc/SK.Funtion.asp" -->
<%if Not (Getconfig("SK_Sales")="0" AND (Session("Manager")="1" OR (JudgePopedomTF(Session("UserName"),"SK300000000") AND JudgePopedomTF(Session("UserName"),"SK300000704")))) then Call ReturnError()%>
<%
if not isnumeric(JCID(F("ID"))) then Call ReturnError10()
set rs=server.createobject("adodb.recordset")
if Session("Manager")=1 or Session("Manager")=2 then
sql="SELECT * from SK_SalesReturns where ReturnsID="&JCID(F("ID"))&""
elseif Session("Manager")=3 then
sql="SELECT * from SK_SalesReturns INNER JOIN SK_SystemUsers ON SK_SalesReturns.SK_SalesID=SK_SystemUsers.UsersID where SK_SystemUsers.SK_Dept1="&Session("Dept1")&" and SK_SalesReturns.ReturnsID="&JCID(F("ID"))&""
elseif Session("Manager")=4 then
sql="SELECT * from SK_SalesReturns INNER JOIN SK_SystemUsers ON SK_SalesReturns.SK_SalesID=SK_SystemUsers.UsersID where SK_SystemUsers.SK_Dept1="&Session("Dept1")&" and SK_SystemUsers.SK_Dept2="&Session("Dept2")&" and SK_SalesReturns.ReturnsID="&JCID(F("ID"))&""
elseif Session("Manager")=5 then
sql="SELECT * from SK_SalesReturns INNER JOIN SK_SystemUsers ON SK_SalesReturns.SK_SalesID=SK_SystemUsers.UsersID where SK_SystemUsers.SK_Dept1="&Session("Dept1")&" and SK_SystemUsers.SK_Dept2="&Session("Dept2")&" and SK_SystemUsers.SK_Dept3="&Session("Dept3")&" and SK_SalesReturns.ReturnsID="&JCID(F("ID"))&""
elseif Session("Manager")=6 then
sql="SELECT * from SK_SalesReturns where SK_SalesID="&Session("UID")&" and ReturnsID="&JCID(F("ID"))&""
end if
rs.Open sql,conn,1,1
if rs.eof and rs.bof then Call ReturnError4()
Response.Buffer = True 
Response.ContentType = "application/vnd.ms-excel" 
SaveFilename=replace(replace(replace(now,":","")," ",""),"/","")
Response.AddHeader "content-disposition", "inline; filename = "&Rs("SK_ReturnsNo")&SaveFilename&".xls"

Response.Write("<table width=""98%"" align=""center"" border=""0"" cellspacing=""1"" cellpadding=""1"">")
Response.Write("<tr><td colspan=2 style=""font-size:18px;font-weight:bold; text-align:center;"">退货单</td></tr>")
Response.Write("<tr><td colspan=2 style=""background:#FFFFFF;text-align:center;font-size: 13px;height: 20px;line-height: 20px;font-weight:bold;"">"&getconfig("SK_Company")&"</td></tr>")
Response.Write("<tr><td colspan=2 style=""background:#FFFFFF;text-align:center;font-size: 12px;height: 18px;line-height: 18px;"">电话："&getconfig("SK_Tel")&"&nbsp;&nbsp; 传真："&getconfig("SK_Fax")&"</td></tr>")

Response.Write("<tr><td colspan=2 style=""background:#FFFFFF;text-align:left;font-size: 12px;height: 18px;line-height: 18px;"">退货编号：<b>"&Rs("SK_ReturnsNo")&"</b></td></tr>")

set rsClient=server.createobject("adodb.recordset")
sqlClient="select * from SK_Client where ClientID="&Rs("SK_ClientID")&""
rsClient.open sqlClient,conn,1,1
if rsClient.eof and rsClient.bof then Call ReturnError13()
Response.Write("<tr><td style=""background:#FFFFFF;text-align: left;font-size: 12px;height: 25px;line-height: 25px;padding: 2px 2px 2px 2px;"">客户名称：<b>"&RsClient("SK_Wname")&"</b></td>")
RsClient.close
Set RsClient=Nothing
Response.Write("<td style=""background:#FFFFFF;text-align:right;font-size: 12px;height: 25px;line-height: 25px;padding: 2px 10px 2px 2px;"">日期："&Rs("SK_ATime")&"</td></tr>")
Response.Write("<tr><td colspan=""2"">")

Dim Rs11,J
set rs11=Server.createobject("adodb.recordset")
sql11="select * from SK_SalesReturnsDetail where SK_ReturnsID="&Rs("ReturnsID")&" order by ReturnsDetailID asc"
rs11.open sql11,conn,1,1
if rs11.bof and rs11.eof then 
Call ReturnError8()
else
Response.Write("<table width=""100%"" cellpadding=""1"" cellspacing=""0"" style=""BORDER-top: #000000 1px solid; BORDER-left: #000000 1px solid;background-image:#000000;"">")
Response.Write("<tr>")
Response.Write("<th width=""25%"" style=""BORDER-RIGHT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid;background-color: #FFFFFF; height: 25px;line-height: 25px;font-size: 12px;"">产品名称</th>")
Response.Write("<th width=""18%"" style=""BORDER-RIGHT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid;background-color: #FFFFFF; height: 25px;line-height: 25px;font-size: 12px;"">产品编码</th>")
Response.Write("<th width=""18%"" style=""BORDER-RIGHT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid;background-color: #FFFFFF; height: 25px;line-height: 25px;font-size: 12px;"">产品型号</th>")
Response.Write("<th width=""13%"" style=""BORDER-RIGHT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid;background-color: #FFFFFF; height: 25px;line-height: 25px;font-size: 12px;"">数量</th>")
Response.Write("</tr>")
J=0
while not rs11.eof
J=J+1
set rsProduct=server.createobject("adodb.recordset")
sqlProduct="select * from SK_Product where ProID="&Rs11("SK_ProID")&""
rsProduct.open sqlProduct,conn,1,1
Response.Write("<tr>")
Response.Write("<td style=""BORDER-RIGHT: #000000 1px solid;BORDER-BOTTOM: #000000 1px solid;background-color: #FFFFFF;text-align: center;height: 25px;line-height: 25px;font-size: 12px;"">"&rsProduct("SK_ProName")&"</td>")
Response.Write("<td style=""BORDER-RIGHT: #000000 1px solid;BORDER-BOTTOM: #000000 1px solid;background-color: #FFFFFF;text-align: center;height: 25px;line-height: 25px;font-size: 12px;"">"&rsProduct("SK_ProNo")&"</td>")
Response.Write("<td style=""BORDER-RIGHT: #000000 1px solid;BORDER-BOTTOM: #000000 1px solid;background-color: #FFFFFF;text-align: center;height: 25px;line-height: 25px;font-size: 12px;"">"&rsProduct("SK_ProNum")&"</td>")

set RsUnit=server.createobject("adodb.recordset")
SqlUnit="select * from SK_SystemCategory where SK_Di=161 and CategoryID="&rsProduct("SK_Unit")&""
RsUnit.open SqlUnit,conn,1,1
Response.Write("<td style=""BORDER-RIGHT: #000000 1px solid;BORDER-BOTTOM: #000000 1px solid;background-color: #FFFFFF;text-align: center;height: 25px;line-height: 25px;font-size: 12px;"">"&Rs11("SK_Total")&" / "&RsUnit("SK_Name")&"</td>")
RsUnit.close
Set RsUnit=Nothing
Response.Write("</tr>")
RsProduct.close
RsProduct=Nothing
rs11.movenext
wend
Response.Write("<tr><td colspan=2 style=""BORDER-RIGHT: #000000 1px solid;BORDER-BOTTOM: #000000 1px solid;background-color: #FFFFFF;text-align: center;height: 25px;line-height: 25px;font-size: 12px;"">&nbsp;</td>")
Response.Write("<td style=""BORDER-RIGHT: #000000 1px solid;BORDER-BOTTOM: #000000 1px solid;background-color: #FFFFFF;text-align: center;height: 25px;line-height: 25px;font-size: 12px;"">合计</td>")
Response.Write("<td style=""BORDER-RIGHT: #000000 1px solid;BORDER-BOTTOM: #000000 1px solid;background-color: #FFFFFF;text-align: center;height: 25px;line-height: 25px;font-size: 12px;"">")
set RsAG=server.createobject("adodb.recordset")
AGSql="select sum(SK_Total) as AG from SK_SalesReturnsDetail where SK_ReturnsID="&Rs("ReturnsID")&""
RsAG.open AGSql,Conn,1,1
Response.Write("<font color=blue>"&RsAG("AG")&"</font>")
RsAG.close
set RsAG=Nothing

Response.Write("</td></tr>")
Response.Write("<tr><td colspan=4 valign=top style=""BORDER-RIGHT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid;background-color: #FFFFFF;text-align: left;height: 50px;font-size: 12px;padding: 2px 2px 2px 2px;"">")
Response.Write("备注："&Rs("SK_ReContent")&"")
Response.Write("</td></tr></table>")
end if
rs11.close
Set Rs11=Nothing
Response.Write("</td>")
Response.Write("</tr>")
Response.Write("<tr>")
Response.Write("<td style=""background:#FFFFFF;text-align: left;font-size: 12px;height: 25px;line-height: 25px;padding: 2px 2px 2px 2px;"">客户代表：</td>")

set RsSales=server.createobject("adodb.recordset")
SqlSales="select * from SK_SystemUsers where UsersID="&RS("SK_SalesID")&""
RsSales.open SqlSales,conn,1,1
Response.Write("<td style=""background:#FFFFFF;text-align: left;font-size: 12px;height: 25px;line-height: 25px;padding: 2px 2px 2px 2px;"">我方代表："&RsSales("SK_OName")&"</td>")
RsSales.close
Set RsSales=Nothing
Response.Write("</tr>")
Response.Write("</table>")
Call CloseDB()
%>
