<!-- #include file="../conn.asp" -->
<!-- #include file="../const.asp" -->
<%
Response.Buffer = True 
Response.ExpiresAbsolute = Now() - 1 
Response.Expires = 0 

call chksunzom()
if instr(quanxs,"m"&mxid&"x")<=0 and nowuserid<>1 then call sunzomqx()

mxid=requestA("mxid")
zdid=requestA("zdid")
chk=requestA("chk")
cid=chk0(requestA("cid"))
gid=chk0(requestA("gid"))


'取得搜索关键字
soxs=chk0(requestA("soxs"))
nowstartdate=requestA("startdate") 

if nowstartdate="quan" then nowstartdate=""
if nowstartdate="now" then nowstartdate=date()
if nowstartdate="yue" or nowstartdate="" then nowstartdate=""&year(now)&"-"&month(now)&"-01"
if day(now)<8 then zhoushu=1 else zhoushu=day(now)-7
if nowstartdate="zhou" then nowstartdate=""&year(now)&"-"&month(now)&"-"&zhoushu&""
if len(nowstartdate)=""  then   nowstartdate=(date()-day(date()-1))&" 00:00:00"
nowenddate=requestA("enddate") 
if len(nowenddate)="" or nowenddate="" then  nowenddate=date()&" 23:59:59"

nowkeyword=requestA("keyword")
nowriqi=request("riqi")
nowkey2=request("key2")
if nowriqi<>"" and len(nowriqi)>3 then nowstartdate=nowriqi&" 00:00:00":nowenddate=nowriqi&" 23:59:59"
if nowstartdate<>"" and nowenddate<>"" then
if formatdatetime(nowstartdate,2)=formatdatetime(nowenddate,2) then nowriqi=formatdatetime(nowenddate,2)
if right(nowstartdate,2)<>"00" then nowstartdate=nowstartdate&" 00:00:00"
if right(nowenddate,2)<>"59" then nowenddate=nowenddate&" 23:59:59" 

'if nowstartdate>nowenddate then  Response.Write "<script language='javascript'>alert('结束时间不能小于开始时间！');history.back();</script>" :response.end

sj1=formatdatetime(nowstartdate,1):sj2=formatdatetime(nowenddate,1)
sjxx=""&sj1&"—"&sj2&""
if sj1=sj2 then sjxx=sj1
elseif nowstartdate<>"" and  nowenddate="" then
sjxx=formatdatetime(nowstartdate,1)
elseif nowstartdate="" and  nowenddate<>"" then
sjxx=formatdatetime(nowenddate,1)
end if


sql="select * from sz_mx where id="&mxid&""  
set rs1 =server.createobject("ADODB.RecordSet")	
rs1.open sql,conn,1,3
if not rs1.eof then
mxname=rs1("mxname"):mxml=rs1("mxml"):mxdat=rs1("mxdat"):xmname=rs1("xmname"):mxdw=rs1("mxdw"):mxms=rs1("mxms"):mxzt=rs1("mxzt"):bdys=chk0(rs1("bdys")):bid=chk0(rs1("bid")):bzd=rs1("bzd"):bbal=rs1("bbal")
if bdys=10 then bdys=3
end if
rs1.close:set rs1=nothing
if bid>0 then 
mxdat0=cdatx("mxdat","SZ_mx","where id="&bid&"")
gxname=cdatx("mxname","SZ_mx","where id="&bid&"")
end if

sExport=requestA("export")
If sExport = "excel" Then Response.ContentType = "application/vnd.ms-excel":Response.AddHeader "Content-Disposition", "attachment; filename="&sjxx&""&mxname&".xls"
If sExport = "word" Then Response.ContentType = "application/vnd.ms-word":Response.AddHeader "Content-Disposition:", "attachment; filename="&sjxx&""&mxname&".doc"
If sExport = "csv" Then Response.ContentType = "application/csv":Response.AddHeader "Content-Disposition:", "attachment; filename="&sjxx&""&mxname&".csv"

sql="select * from SZ_zd where ChannelID="&mxid&" and ShowOnForm=1 and zdbbxs=1 order by OrderID desc,id asc"
set rsc2=conn.execute(sql)
if not rsc2.bof then
do while not rsc2.eof
zdid4=rsc2("id"):bdTitle4=rsc2("Title"):bdname4=rsc2("FieldName"):zdhz4=rsc2("zdhz")
if Instr(zdhz4,"sorq")>0 then issorq=1:sorq=sorq&" and "&bdname4&"-#SJ# "
if Instr(zdhz4,"sook")>0 then sozd=sozd&""&bdname4&"|"
if Instr(zdhz4,"baoA")>0 then baos=baos&""&bdname4&"|"

rsc2.movenext
loop
end if
rsc2.close:set rsc2=nothing

%>
<!-- #include file="../jq1.html" -->
<title><%=mxname%> -详情</title>

<link href="../images/sunzom.css" rel="stylesheet" type="text/css">
<style media="print" type="text/css"> .NoPrint{DISPLAY:none}</style>
<script language=javascript>
function doPrint() { 
bdhtml=window.document.body.innerHTML; 
sprnstr="<!--startprint-->"; 
eprnstr="<!--endprint-->"; 
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); 
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); 
window.document.body.innerHTML=prnhtml; 
window.print(); 
window.document.body.innerHTML=bdhtml;
}
function killErrors() {return true;}
window.onerror = killErrors;
</script>
<div id="navTab" class="tabsPage NoPrint">
<form  method="POST" action="baob.asp?id=<%=mxid%>&cid=<%=cid%>&gid=<%=gid%>">	  <img src="../images/s.gif">选择时间段：<input name="startdate" title="开始日期" class="date" value="<%=nowstartdate%>" style="width:80px">→<input title="结束日期" name="enddate" class="date" value="<%=nowenddate%>"  style="width:80px">
关键词：<input name="keyword" value="<%=nowkeyword%>" style="width:100px" title="输入查询关键词"><input type="submit" value="查询">&nbsp;
</form></div>
<div class="bdys<%=bdys%> ddyy">
<!--startprint-->

<h2 align="center"><%=mxname%></h2>

<%
sql="select * from "&mxdat&" where 1=1 "

'if nowstartdate<>"" then 
'if issorq=1 then sorqa=replace(sorq,"#SJ#","#"&nowstartdate&"#>=0"):sql=sql&" "&sorqa&" "  else  sql=sql&" and tjsj-#"&nowstartdate&"#>=0"
'end if
'if nowenddate<>"" then 
'if issorq=1 then  sorqb=replace(sorq,"#SJ#","#"&nowenddate&"#<=0"):sql=sql&" "&sorqb&" "  else  sql=sql&" and tjsj-#"&nowenddate&"#<=0"
'end if

if nowkeyword<>"" then
soxx1=split(sozd,"|")
for ss=0 to Cntshu(sozd,"|")-1
soxxs=soxxs&" "&soxx1(ss)&" like '%"&nowkeyword&"%' or"
next  
if soxxs<>"" then soxxs1=" and ("&left(soxxs,len(soxxs)-2)&") "
sql=sql&soxxs1
end if 

sql=sql&" order by tjsj asc,id asc"
set rsb2=conn.execute(sql)
if not rsb2.bof then
do while not rsb2.eof
zdida=chk0(rsb2("id"))
ZD_BM=rsb2("ZD_BM"):ZD_RQ=rsb2("ZD_RQ")
'zdtit=""&ZD_RQ&"- "&ZD_BM&""
zdtit=""&sjxx&"- "&ZD_BM&""
Response.Write "<hr><font style=""font-size: 16pt"">"&zdtit&"</font>"

'''''''''''''''''''''''''''''''''''1级循环开始

sqlz1="select * from SZ_mx where bid="&mxid&" and instr(bbal,'dyin')>0 order by bid desc,id asc"
set rsz1=conn.execute(sqlz1)
if not rsz1.bof then
do while not rsz1.eof
'mxidz1=rsz1("id"):mxbiao=rsz1("mxdat")
mxbiao1=rsz1("mxdat")
sql="select * from SZ_zd where ChannelID="&rsz1("id")&" and ShowOnForm=1 and zdbbxs=1 order by OrderID desc,id asc"
set rsc2=conn.execute(sql)
if not rsc2.bof then
do while not rsc2.eof
zdid3=rsc2("id"):bdTitle=rsc2("Title"):bdname=rsc2("FieldName"):zdhz=rsc2("zdhz")
hzbt=hzbt&"<td class=""category"">"&bdTitle&"</td>"

if Instr(zdhz,"sorq")>0 then issorq=2:sorq=sorq&" and "&bdname&"-#SJ# "

if instr(zdhz,"ltj")>0  then 
zdtjs=zdtjs&"|"&bdTitle
hzbta=hzbta&"<td align=""center"">"&bdTitle&"</td>"
else
hzbta=hzbta&"<td></td>"
end if

hzhes=hzhes&""&zdhz&"|"
if Instr(zdhz,"sook")>0 then sozd=sozd&""&bdname&"|"
hzsjx=hzsjx&""&bdname&"|"
rsc2.movenext
loop
end if
rsc2.close:set rsc2=nothing

sql="select * from "&mxbiao1&" where gid="&zdida&" "  
  
'if request.Cookies("sunzom_id")=1 then
'elseif soxs=1 then
'sql=sql&" and Instr('"&nowxs&"',zduser)>0 "
'else
'sql=sql&" and zduser='"&nowuser&"' "
'end if

'sorqa=replace(sorq,"#SJ#","#"&formatdatetime(nowstartdate,2)&"#>=0")
'Response.Write ""&sorqa&"":Response.end

if nowstartdate<>"" then 
if issorq=2 then sorqa=replace(sorq,"#SJ#","#"&formatdatetime(nowstartdate,2)&"#>=0"):sql=sql&" "&sorqa&" "  else  sql=sql&" and tjsj-#"&nowstartdate&"#>=0"
end if
if nowenddate<>"" then 
if issorq=2 then  sorqb=replace(sorq,"#SJ#","#"&formatdatetime(nowenddate,2)&"#<=0"):sql=sql&" "&sorqb&" "  else  sql=sql&" and tjsj-#"&nowenddate&"#<=0"
end if
  
if nowkeyword<>"" then
soxx1=split(sozd,"|")
for ss=0 to Cntshu(sozd,"|")-1
soxxs=soxxs&" "&soxx1(ss)&" like '%"&nowkeyword&"%' or"
next  
if soxxs<>"" then soxxs1=" and ("&left(soxxs,len(soxxs)-2)&") "
sql=sql&soxxs1
end if 
  
if request("order1")<>"" then
sql=sql&" order by tjsj "&request("order1")
else
sql=sql&" order by id desc"  
end if   
  
set rsxiao =server.createobject("ADODB.RecordSet")	
rsxiao.open sql,conn,1,3
if not rsxiao.eof then
%></div>
<br><br><h4 align="center"><%=zdtit%>  &nbsp;&nbsp; <%=rsz1("xmname")%></h4>
<table align="center" cellpadding="4" class="toptable" border="1">
<tr align="center">    
<%if instr(bbxian,"xsid")>0 then%><td>ID</td><%end if%>
<%=hzbt%>
<%if instr(bbxian,"xssj")>0 then%><td>日期</td><%end if%>
<%if instr(allsx,"bbnocz")>0 then%><%if instr(quanxs,"smxc")>0 then%><%end if%><%end if%>
</tr>
<%
do while not rsxiao.eof
zdid=rsxiao("id")
%>
<tr>
<%if instr(bbxian,"xsid")>0 then%><td align="center"><%=zdid%></td><%end if%>
<%
hzsj1=split(hzsjx,"|")
for hh=0 to Cntshu(hzsjx,"|")-1

zdhz0=cdatx("zdhz","SZ_zd","where ChannelID="&rsz1("id")&" and FieldName='"&hzsj1(hh)&"'")
if instr(zdhz0,"ltj")>0  then 
zdhz1=cdatx("Title","SZ_zd","where ChannelID="&rsz1("id")&" and FieldName='"&hzsj1(hh)&"'")
tjsjc=tjsjc&"[#]"&zdhz1&"|"&CDbl(chk0(rsxiao(""&hzsj1(hh)&"")))&""
end if
'Response.Write ""&zdhz1&""
Response.Write "<td align=""center"">"
if hzsj1(hh)="zdsh" then Response.Write ""&chksh(rsxiao(""&hzsj1(hh))&"")&"" else Response.Write ""&rsxiao(""&hzsj1(hh)&"")&""
Response.Write "</td>"
next%>
<%if instr(allsx,"bbnocz")>0 then%><%if instr(bbxian,"xssj")>0 then%><td align="center"><%=rsxiao("tjsj")%></td><%end if%>
<%end if%></tr>
<%
'end if
rsxiao.movenext
loop
end if%>
<%
zzdd=split(zdtjs,"|")
for zz=1 to Cntshu(zdtjs,"|")
if zz>1 then hhe0=0
ttss=split(tjsjc,"[#]")
for tt=1 to Cntshu(tjsjc,"[#]")
if zzdd(zz)=split(ttss(tt),"|")(0) then 
hhe0=hhe0+CDbl(split(ttss(tt),"|")(1))
end if
hhe1=hhe0
next
if instr(hzbta,">"&zzdd(zz)&"")>0 then hzbta=replace(hzbta,">"&zzdd(zz)&"",">"&hhe1&"")
'hhee=hhee&""&zzdd(zz)&"：<b>"&FormatNumber(hhe1,2,-2)&"</b>，"
next
if right(hhee,1)="，" then hhee=left(hhee,len(hhee)-1):hhee="["&rsz1("xmname")&"]合计"&hhee
if instr(hhee,"应收")>0 then ysjin=hhe1
if instr(hhee,"应付")>0 then yfjin=hhe1
%>
<%'=hhee%>
<tr><%=hzbta%></tr>
</table>
<%
hzbta="":zdhz0="":zdhz1="":hzsjx="":hzsj1="":zdtjs="":tjsjc="":hzbt="":hhee="":hhe1=0:hhe0=0:mxname1="":mxbiao1="":zdid=requestA("zdid")
rsz1.movenext
loop
end if
rsz1.close:set rsz1=nothing

''''''''''''''''''''
rsb2.movenext
loop
end if
rsb2.close:set rsb2=nothing
%>

<!--endprint--><br><br><p align="center"><%=dayin%>  &nbsp;&nbsp;<a title="数据导出为Excel" href="baoB.asp?id=<%=mxid%>&zdid=<%=zdid%>&export=excel&keyword=<%=escape(nowkeyword)%>&startdate=<%=nowstartdate%>&enddate=<%=nowenddate%>&page=<%=ipage-1%>&mxiang=<%=mxiang%>"><img src="../images/exportxls.gif" width="16" height="16" border="0" class="NoPrint"></a>
&nbsp;&nbsp;<a  title="数据导出为WORD" href="baoB.asp?id=<%=mxid%>&zdid=<%=zdid%>&export=word&keyword=<%=escape(nowkeyword)%>&startdate=<%=nowstartdate%>&enddate=<%=nowenddate%>&page=<%=ipage-1%>&mxiang=<%=mxiang%>"><img src="../images/exportdoc.gif" width="16" height="16" border="0" class="NoPrint"></a>
&nbsp;&nbsp;<a  title="数据导出为CSV" href="baoB.asp?id=<%=mxid%>&zdid=<%=zdid%>&export=csv&keyword=<%=escape(nowkeyword)%>&startdate=<%=nowstartdate%>&enddate=<%=nowenddate%>&page=<%=ipage-1%>&mxiang=<%=mxiang%>"><img src="../images/exportcsv.gif" width="16" height="16" border="0" class="NoPrint"></a></p>