<!--#include file="check.asp"-->
<%
Call hrPower(7.2,0)
dim action
action=request.QueryString("action")
upline=request.QueryString("upline")
Nowpage=cint(request.QueryString("page"))
id=cint(request.QueryString("id"))

dim gRs,ycount,lcount,xcount


Sub count_mobile(upline)





	xcount=0
	Set gRs=Server.CreateObject("ADODB.Recordset")
	gRs.Open "Select * from mobile where tuiguang='"&upline&"'"&searchstr&" and  regdate < '"&date()&"' and state2=0 and ebank<>'BANK' and ebank<>'alipay' and ebank<>'tenpay' and ebank<>'wangying' order by number", Conn, 1, 1
	if not gRs.eof then 
		do while not gRs.eof

			SubMoney = gRs("Price")
			xcount=xcount+1

				Rate = 0
					set urs = GrateRs("select * from agent where username='"&upline&"' ",1)


						Rate = urs("dltc")

					urs.close
				gmm=zero(formatnumber(gmm+gRs("price")*(Rate/100)))


			gRs.movenext
		loop
	end if

End Sub

%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>代理结算</title>
<link href="images/main.css" rel="stylesheet" type="text/css" media="all" />
<script src="js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
</head>
<!--#include file="top.asp"-->
<div id="systime"><p id="servertime"></p></div>
<div id="mainBody" >

<div class="space">&nbsp;</div>
<div class="list">

          <%
		  select case action
		  case "list"
		  %>		  

<script language="javascript">
try{
    var nav="H08";
    var subnav="L0802";
	
    document.getElementById(nav).className="current";
    document.getElementById(subnav).className="first current";
    document.getElementById(subnav).parentNode.parentNode.style.display="block";

}catch(e){
	document.getElementById("H08").className="current";
}
</script>

<table class="listtable">
  <thead>
    <tr>
      <th scope="col">代理ID</th>
	  <th scope="col">代理名</th>
            <th scope="col">已支付金额</th>
            <th scope="col">未支付金额</th>
            <th scope="col">已结算金额</th>
            <th scope="col">可结算个数</th>
            <th scope="col">可结算金额</th>
            <th scope="col">操作</th>

    </tr>
  </thead>
  <tbody> 




           <%
		   set Rs=GrateRs("select * from agent order by nopay desc",1)
		   i=0
		   do while not Rs.eof
		   gmm=0
		   call count_mobile(Rs("username"))
		   cMobile=xcount
		   if cMobile>=0 then

		   %>
<%if i mod 2 =0 then%>
         <tr class="listtr1" >
<%else%>
         <tr class="listtr2" >
<%end IF%>
              <td>&nbsp;&nbsp;<%=Rs("adminid")%></td>
              <td>&nbsp;&nbsp;<%=Rs("username")%></td>
              <td><%=zero(formatnumber(Rs("pay")))%></td>
              <td><%=zero(formatnumber(Rs("nopay"))-formatnumber(Rs("pay")))%></td>
              <td><%=zero(formatnumber(Rs("nopay")))%></td>
              <td><%=cMobile%></td>
              <td><%=gmm%></td>
              <td><a href="dl_ship.asp?action=ship&upline=<%=Rs("username")%>" onClick="return confirm('确定要执行结算操作吗？')">结算</a>  / <a href="agent.asp?action=show&id=<%=Rs("adminid")%>">资料</a> </td>
            </tr>
			<%
		   	i=i+1
		   end if
		   Rs.movenext
		   loop
		  %>
<tr onmouseover="this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='infobackground'" onmouseout="this.style.backgroundColor=this.oldcolor" style="color:#284775;background-color:White;">
		      <td height="26" colspan="8">&nbsp;<strong>&nbsp;&nbsp;统计: :</strong>
<%
 response.write("共："&i&"条记录.")
		%>&nbsp;</td>
		      </tr>
		  
          </table>
		<%
		case "show"
		%>

<script language="javascript">
try{
    var nav="H08";
    var subnav="L0804";
	
    document.getElementById(nav).className="current";
    document.getElementById(subnav).className="first current";
    document.getElementById(subnav).parentNode.parentNode.style.display="block";

}catch(e){
	document.getElementById("H08").className="current";
}
</script>

<table class="listtable">
  <thead>
    <tr>
      <th scope="col">代理名</th>
	  <th scope="col">结算个数</th>
            <th scope="col">结算金额</th>
            <th scope="col">结算时间</th>
            <th scope="col">操作</th>

    </tr>
  </thead>
  <tbody> 




          <%
		   if upline="" then upline=request.form("upline")
		   startdate=request.form("startdate")
		   if startdate="" then startdate=date()
		   enddate=request.form("enddate")
		   if enddate="" then enddate=date()
		   searchstr=""
		   if upline<>"" then searchstr="Uname='"&upline&"'"
		   if isdate(startdate) then 
		      if not searchstr="" then searchstr=searchstr+" and "
 		      searchstr=searchstr+"datediff(d,shipdate,'"&startdate&"')<=0"
 		      'searchstr=searchstr+"shipdate >= '"&startdate&"'"
		   end if
		   if isdate(enddate) then 
		      if not searchstr="" then searchstr=searchstr+" and "
		      searchstr=searchstr+"datediff(d,shipdate,'"&enddate&"')>=0"
 		      'searchstr=searchstr+"shipdate <= '"&enddate&"'"
		   end if
		   if not searchstr="" then searchstr=" where "+searchstr	
		   set Rs=GrateRs("select * from H_work"&searchstr&" order by id desc",1)
		   Rs.PageSize=30
		   if not Rs.eof then 
		   If Nowpage=0 then Nowpage=1
		   Rs.AbsolutePage=Nowpage 
		   i=1
		   do while not Rs.eof and i<=Rs.pagesize
		   %>
<%if i mod 2 =0 then%>
         <tr class="listtr1" >
<%else%>
         <tr class="listtr2" >
<%end IF%>
            <td><%=Rs("Uname")%></td>
            <td><%=Rs("count")%></td>
            <td><%=zero(formatnumber(Rs("money")))%>&nbsp;&nbsp;&nbsp;</td>
            <td><%=Rs("shipdate")%></td>
            <td><a href="dl_pay.asp?action=pay&upline=<%=Rs("Uname")%>">支付</a> / <a href="dl_ship.asp?action=show&upline=<%=Rs("Uname")%>">详单</a> </td>
          </tr>
          <%
		   i=i+1
		   Rs.movenext
		   loop
		   else
		   %>
<tr onmouseover="this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='infobackground'" onmouseout="this.style.backgroundColor=this.oldcolor" style="color:#284775;background-color:White;">
            <td height="20" colspan="6">对不起，尚无结算记录</td>
            </tr>
		   <%
		   end if
		  %>
<tr onmouseover="this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='infobackground'" onmouseout="this.style.backgroundColor=this.oldcolor" style="color:#333333;background-color:#F7F6F3;">
            <td height="26" colspan="6">&nbsp;<strong>&nbsp;&nbsp;翻页: :</strong>
                <%
				
  myurl="dl_ship.asp?action=show"&"&startdate="&startdate&"&enddate="&enddate&"&upline="&upline&"&"
 response.write("共："&Rs.recordcount&"条记录，共:"&Rs.PageCount&"页,"&Rs.PageSize&"条/页,第"&NowPage&"页&nbsp;")
  response.write("<a href='"&myurl&"page=1'>"&"首页</a>&nbsp;")
  if NowPage>1 then response.write("<a href='"&myurl&"page="&Nowpage-1&"'>上一页</a>&nbsp;")
  if NowPage<Rs.PageCount then response.write("<a href='"&myurl&"page="&Nowpage+1&"'>下一页</a>&nbsp;")
  response.write("<a href='"&myurl&"page="&Rs.PageCount&"'>尾页</a>&nbsp;")
		%>
          &nbsp;</td>
          </tr>
          <tr align="center" bgcolor="#F1F1F1">
          <form name="form1" method="post" action="dl_ship.asp?action=show">  <td height="20" colspan="6">
           
              商户名&nbsp;&nbsp;
              <input name="upline" type="text" class="inputbox" id="upline" value="<%=upline%>" size="20">
              &nbsp;&nbsp;&nbsp;开始时间&nbsp;&nbsp;              <input name="startdate" type="text" class="inputbox" id="startdate" size="20" value="<%=startdate%>" onClick="WdatePicker()" readonly>
              &nbsp;&nbsp;&nbsp;&nbsp;结束时间&nbsp;&nbsp;
              <input name="enddate" type="text" class="inputbox" id="enddate" value="<%=enddate%>" size="20" onClick="WdatePicker()" readonly>
              &nbsp;&nbsp;&nbsp;&nbsp;
              <input name="Submit" type="submit" class="inputbutton" value="  立即查询  "></td> </form>
            </tr>
        </table>
		<%
		case "ship"
		'on error resume next
		 call count_mobile(upline)
		 cMobile=xcount
		 if cMobile>=1 then 
		 set Rs=GrateRs("select * from mobile where regdate < '"&date()&"' and state2=0 and tuiguang='"&upline&"'    and ebank<>'BANK' and ebank<>'alipay' and ebank<>'tenpay' and ebank<>'wangying' order by id desc",3)
		  if not Rs.eof then





		   'GM收入//////////////////////////////////////////
		   sqlInfo = "Select * from mobile where tuiguang='"&upline&"' and  state2=0  and  regdate < '"&date()&"'    and ebank<>'BANK' and ebank<>'alipay' and ebank<>'tenpay' and ebank<>'wangying' order by regdate desc"
		   set Rst=GrateRs(sqlInfo,1)
		   if not Rst.eof then 
		   do while not Rst.eof
		   	
				Rate = 0

					set urs = GrateRs("select * from agent where username='"&upline&"' ",1)


						Rate = urs("dltc")

					urs.close


				gmm=zero(formatnumber(gmm+rst("price")*(Rate/100)))
		 Rst.movenext
		   loop
		   end if



	 	i0=0
	 	   do while not Rs.eof
				i0=i0+1
				Rs("state2")=1

			Rs.update
	  	 	Rs.movenext
	 	  loop
	     else
		i0=0
	     end if
		
		   Rs.movefirst
		   %>

<table class="listtable">
  <thead>
    <tr>
      <th scope="col">订单号</th>
	  <th scope="col">时间</th>
            <th scope="col">状态</th>

    </tr>
  </thead>
  <tbody> 


		<%
		   do while not Rs.eof 
		%>
         <tr class="listtr1" >

            <td><%=Rs("num")%></td>
            <td><%=Rs("regDate")%></td>
            <td>
			<%
			select case Rs("state2")
			case 1
			 response.write("已结")
			case 2
			 response.write("重复")
			case else
			 response.write("无效")
			end select
			%>
			</td>
            </tr>
<%
	Rs.movenext
	loop








	set Rs=GrateRs("select * from agent where username='"&upline&"'",3)
	if not Rs.eof then 
 	 totalm=zero(formatnumber(Rs("nopay")+gmm))
	 removeM=zero(formatnumber(Rs("pay")))
	 Rs("nopay")=totalM
	 Rs.update
	 
	%> <tr align="center" bgcolor="#E3E2C3">
            <td colspan="3"><table width="100%"  border="0" cellpadding="0" cellspacing="1">
              <tr align="left" bgcolor="#FFFFFF">
                <td height="26" colspan="2" bgcolor="#E3E2C3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>: : 本次结算列表 : : </strong> </td>
                </tr>
              <tr bgcolor="#FFFFFF">
                <td width="21%" height="20" align="center">代理商户名</td>
                <td width="79%" height="20"><%=upline%></td>
              </tr>
              <tr bgcolor="#FFFFFF">
                <td height="20" align="center">本次结算</td>
                <td height="20">&nbsp;金额：<font color=red><%=gmm%></font>元；</td>
                </tr>
              <tr bgcolor="#FFFFFF">
                <td height="20" align="center">本次结算后</td>
                <td height="20">站长总金额为：<font color=red><%=totalm%></font>元&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 已支付金额：<font color=red><%=removeM%></font>元&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 未支付金额：<font color=red><%=totalm-removeM%></font>元</td>
              </tr>
              <tr align="center" bgcolor="#FFFFFF">
                <td height="20">&nbsp;</td>
                <td height="20" align="left"><input name="Submit" type="submit" class="inputbutton" value=" 继续结算 " onclick="window.location='<%=Request.ServerVariables("HTTP_REFERER")%>';">
&nbsp;&nbsp;&nbsp;
<input name="Submit" type="submit" class="inputbutton" value="支付[<%=upline%>]" onclick="window.location='dl_pay.asp?action=pay&upline=<%=upline%>';">
</td>
              </tr>
            </table></td>
            </tr>
        </table>
		   <%
		   	set Rs=GrateRs("select * from H_work",3)
			Rs.addnew
			Rs("Uname")=upline
			Rs("shipdate")=now()
			Rs("update")=date()
			Rs("count")=i0
			Rs("total")=gmm
			Rs("money")=gmm
			Rs.update
		   else
		      response.write "<script language='JavaScript'>{window.alert('对不起，该代理商户不存在，无法完成结算！');window.location='"&Request.ServerVariables("HTTP_REFERER")&"';}</script>"
		   end if
		 else
		   response.write "<script language='JavaScript'>{window.alert('对不起，该代理商户订单个数未满"&JS_count&"个，还不能结算！');window.location='"&Request.ServerVariables("HTTP_REFERER")&"';}</script>"
		 end if
		end select
		%>
       </td>
      </tr>
	  

    </table></td>
  </tr>
</table>
</body>
</html>
<%
call DBConnEnd
%>
