<!--#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"),"SK300000404")))) then Call ReturnError()%>
<%
Dim i,str2

Sub ToExcelList()
set RsClass=server.createobject("adodb.recordset")
SqlClass="select * from SK_SystemCategory where SK_Di=44 and CategoryID="&RS("SK_Di")&""
RsClass.open SqlClass,conn,1,1
Response.Write("<td align=left>"&RsClass("SK_Name")&"</td>")
RsClass.close
Set RsClass=Nothing
Response.Write("<td align=left>"&Rs("SK_OrdersNo")&"</td>")
Response.Write("<td align=left>"&Rs("SK_OrdersTitle")&"</td>")
set rsClient=server.createobject("adodb.recordset")
sqlClient="select * from SK_Client where ClientID="&Rs("SK_ClientID")&""
rsClient.open sqlClient,conn,1,1
Response.Write("<td align=left>"&RsClient("SK_Wname")&"</td>")
RsClient.close
Set RsClient=Nothing
set RsCurrency=server.createobject("adodb.recordset")
SqlCurrency="select * from SK_SystemCategory where SK_Di=142 and CategoryID="&Rs("SK_Currency")&""
RsCurrency.open SqlCurrency,conn,1,1
set RsAG=server.createobject("adodb.recordset")
AGSql="select sum(SK_Total*SK_Price) as AG from SK_SalesOrdersDetail where SK_ProOrdersID="&Rs("OrdersID")&""
RsAG.open AGSql,Conn,1,1
Response.Write("<td align=left><font color=""#999999"">"&RsCurrency("SK_Name")&"</font></td>")
Response.Write("<td align=left><font color=blue>"&formatnumber(RsAG("AG"),2)&"</font></td>")
RsAG.close
set RsAG=Nothing
RsCurrency.close
Set RsCurrency=Nothing

set RsFeet=server.createobject("adodb.recordset")
SqlFeet="select * from SK_SystemCategory where SK_Di=45 and CategoryID="&RS("SK_Feet")&""
RsFeet.open SqlFeet,conn,1,1
Response.Write("<td align=left>"&RsFeet("SK_Name")&"</td>")
RsFeet.close
Set RsFeet=Nothing

Response.Write("<td align=left>"&Rs("SK_OrdersTime")&"</td>")

if Rs("SK_ShFeet")=0 then
Response.Write("<td align=left><font color=""#009999"">未审核</font></td>")
elseif Rs("SK_ShFeet")=1 then
Response.Write("<td align=left><font color=""#0066FF"">已通过</font></td>")
elseif Rs("SK_ShFeet")=2 then
Response.Write("<td align=left><font color=""red"">未通过</font></td>")
end if

if Rs("SK_Delivery")=0 then
Response.Write("<td align=left>否</td>")
else
Response.Write("<td align=left>是</td>")
end if

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 align=left>"&RsSales("SK_OName")&"</td>")
RsSales.close
Set RsSales=Nothing
Response.Write("<td align=left>"&Rs("SK_Addor")&"</td>")
Response.Write("<td align=left>"&Rs("SK_Time")&"</td>")
set RsEditor=server.createobject("adodb.recordset")
SqlEditor="select * from SK_SystemUsers where UsersID="&RS("SK_Editor")&""
RsEditor.open SqlEditor,conn,1,1
Response.Write("<td align=left>"&RsEditor("SK_OName")&"</td>")
RsEditor.close
Set RsEditor=Nothing
Response.Write("<td align=left>"&Rs("SK_Etime")&"</td>")
Response.Write("<td align=left>"&Rs("SK_Content")&"</td>")
End Sub

'导出订单信息到Excel开始
Response.Buffer = True 
Response.ContentType = "application/vnd.ms-excel" 
SaveFilename=replace(replace(replace(now,":","")," ",""),"/","")
Thead="ProOrder_"
Response.AddHeader "content-disposition", "inline; filename = "&Thead&SaveFilename&".xls"

Response.Write("<table width=""100%"" align=""center"" cellpadding=""3"" cellspacing=""1"" border=""1"">"&VBCrlf)
Response.Write("<tr bgcolor=""#E8E8E8"">"&VBCrlf)
Response.Write("<td width=""4%""><b>订单类别</b></td>")
Response.Write("<td width=""12%""><b>订单编号</b></td>")
Response.Write("<td width=""12%""><b>订单主题</b></td>")
Response.Write("<td width=""9%""><b>关联客户</b></td>")
Response.Write("<td width=""9%""><b>货币</b></td>")
Response.Write("<td width=""9%""><b>金额</b></td>")
Response.Write("<td width=""9%""><b>状态</b></td>")
Response.Write("<td width=""9%""><b>签约日期</b></td>")
Response.Write("<td width=""9%""><b>审核</b></td>")
Response.Write("<td width=""9%""><b>发货否</b></td>")
Response.Write("<td width=""9%""><b>业务人员</b></td>")
Response.Write("<td width=""5%""><b>创建人</b></td>")
Response.Write("<td width=""5%""><b>创建时间</b></td>")
Response.Write("<td width=""15%""><b>修改人</b></td>")
Response.Write("<td width=""15%""><b>修改时间</b></td>")
Response.Write("<td width=""15%""><b>备注</b></td>")
Response.Write("</tr>"&VBCrlf)

if F("id")="" then
Set RS = Server.CreateObject("ADODB.Recordset")
if Session("Manager")=1 or Session("Manager")=2 then
sql="select * from SK_SalesOrders where SK_Del=0"
elseif Session("Manager")=3 then
sql="select * from SK_SalesOrders INNER JOIN SK_SystemUsers ON SK_SalesOrders.SK_SalesID=SK_SystemUsers.UsersID where SK_SalesOrders.SK_Del=0 and SK_SystemUsers.SK_Dept1="&Session("Dept1")&""
elseif Session("Manager")=4 then
sql="select * from SK_SalesOrders INNER JOIN SK_SystemUsers ON SK_SalesOrders.SK_SalesID=SK_SystemUsers.UsersID where SK_SalesOrders.SK_Del=0 and SK_SystemUsers.SK_Dept1="&Session("Dept1")&" and SK_SystemUsers.SK_Dept2="&Session("Dept2")&""
elseif Session("Manager")=5 then
sql="select * from SK_SalesOrders INNER JOIN SK_SystemUsers ON SK_SalesOrders.SK_SalesID=SK_SystemUsers.UsersID where SK_SalesOrders.SK_Del=0 and SK_SystemUsers.SK_Dept1="&Session("Dept1")&" and SK_SystemUsers.SK_Dept2="&Session("Dept2")&" and SK_SystemUsers.SK_Dept3="&Session("Dept3")&""
elseif Session("Manager")=6 then
sql="select * from SK_SalesOrders where SK_Del=0 and SK_SalesID="&Session("UID")&""
end if
RS.Open Sql,Conn,1,1
if rs.bof and rs.eof then Call ReturnError4()
K=0
while not Rs.eof
K=K+1
Response.Write("<tr bgcolor=FFFFFF>"&VBCrlf)
Call ToExcelList()
Response.Write("</tr>"&VBCrlf)
rs.movenext
wend

elseif F("id")<>"" then '当选择有ID时输出数据开始
str2=split(F("id"),",")
for i=0 to ubound(str2)
Set Rs = Server.CreateObject("ADODB.Recordset")
if Session("Manager")=1 or Session("Manager")=2 then
sql="select * from SK_SalesOrders where SK_Del=0 and OrdersID="&trim(str2(i))
elseif Session("Manager")=3 then
sql="select * from SK_SalesOrders INNER JOIN SK_SystemUsers ON SK_SalesOrders.SK_SalesID=SK_SystemUsers.UsersID where SK_SalesOrders.SK_Del=0 and  SK_SystemUsers.SK_Dept1="&Session("Dept1")&" and SK_SalesOrders.OrdersID="&trim(str2(i))
elseif Session("Manager")=4 then
sql="select * from SK_SalesOrders INNER JOIN SK_SystemUsers ON SK_SalesOrders.SK_SalesID=SK_SystemUsers.UsersID where SK_SalesOrders.SK_Del=0 and SK_SystemUsers.SK_Dept1="&Session("Dept1")&" and SK_SystemUsers.SK_Dept2="&Session("Dept2")&" and SK_SalesOrders.OrdersID="&trim(str2(i))
elseif Session("Manager")=5 then
sql="select * from SK_SalesOrders INNER JOIN SK_SystemUsers ON SK_SalesOrders.SK_SalesID=SK_SystemUsers.UsersID where SK_SalesOrders.SK_Del=0 and SK_SystemUsers.SK_Dept1="&Session("Dept1")&" and SK_SystemUsers.SK_Dept2="&Session("Dept2")&" and SK_SystemUsers.SK_Dept3="&Session("Dept3")&" and SK_SalesOrders.OrdersID="&trim(str2(i))
elseif Session("Manager")=6 then
sql="select * from SK_SalesOrders where SK_Del=0 and SK_SalesID="&Session("UID")&" and OrdersID="&trim(str2(i))
end if
RS.Open Sql,Conn,1,1
Response.Write("<tr bgcolor=FFFFFF>"&VBCrlf)
Call ToExcelList()
Response.Write("</tr>"&VBCrlf)
next
end if '当选择有ID时输出数据结束

Response.Write("</table>")
Call CloseDB()
'导出订单到Excel结束
%>