<!--#include file="conn.asp"-->
<%
	'检查访问的来源是否合法
	call checkPrePage()
	
	'检查用户访问的权限
	call checkuser(1)


strM_ID=Trim(Session("UserID"))
%>
<%
if GetQueryString("action")="save" then
	money=GetFormVariable("txtMoney")
	if Cdbl(money)<=0 then
		ShowMsg "添加失败，发生金额必须大于0！"
	end if

	'检查操作人的余额
	Set rsSub=Server.CreateObject("ADODB.RecordSet")
	rsSub.open "Select m_money From member Where id=" & Session("UserID"),conn,1,1
	RemainMoney=rsSub("m_money")
	rsSub.Close
		
		
	if GetFormVariable("selType")="入账" then
		call AutoBank(GetFormVariable("selMember"),strM_ID,money,"入账",GetFormVariable("txtNote") & " " & GetName(GetFormVariable("selMember")) & "<-" & GetName(strM_ID))
		'call AutoBank(strM_ID,strM_ID,0-money,"入账",GetFormVariable("txtNote") & " " & GetFormVariable("selMember") & "<-" & strM_ID)		'本人账号扣去入账款
	end if
	
	if GetFormVariable("selType")="退款" then
		call AutoBank(GetFormVariable("selMember"),strM_ID,money,"退款",GetFormVariable("txtNote") & " " & GetName(GetFormVariable("selMember")) & "<-" & GetName(strM_ID))		'将款退还到对象账号
		'call AutoBank(strM_ID,strM_ID,0-money,"退款",GetFormVariable("txtNote") & " " & GetFormVariable("selMember") & "<-" & strM_ID)		'本人账号扣去退还款
	end if
	
	
	if GetFormVariable("selType")="扣款" then
		call AutoBank(GetFormVariable("selMember"),strM_ID,0-money,"扣款",GetFormVariable("txtNote") & " " & GetName(strM_ID) & "<-" & GetName(GetFormVariable("selMember")))		'目标账号扣款
		'call AutoBank(strM_ID,strM_ID,money,"扣款",GetFormVariable("txtNote") & " " & strM_ID & "<-" & GetFormVariable("selMember"))			'将扣款加到自己账号上
	end if
	
	response.Write("<script language=javascript>" & chr(13))
	response.Write("alert('账单添加成功！　');" & chr(13))
	response.Write("</script>" & chr(13))
	
end if

'自动银行
Sub AutoBank(strM_ID,strAdminID,money,strType,strNote)

	'添加记录
	strSQL="Insert Into bank(m_id,b_adminid,b_money,b_type,b_note) Values("
	strSQL=strSQL & "" & strM_ID & ","
	strSQL=strSQL & "" & strAdminID & ","
	strSQL=strSQL & "" & money & ","
	strSQL=strSQL & "'" & strType & "',"
	strSQL=strSQL & "'" & strNote & "')"
	conn.execute strSQL,0,1
	
	'更新目标者余额
	strSQL="Update member Set m_money=m_money+" & Trim(money) & " Where id=" & strM_ID
	conn.execute strSQL,0,1
	
end Sub

Function GetName(strID)
	set rsName=Server.CreateObject("ADODB.RecordSet")
	rsName.open "Select m_name From member Where id=" & strID,conn,1,1
	GetName=rsName("m_name")
End Function
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>电子商务自助建站--您理想的助手</title>
<link href="common/styleMain.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="common/JS_CheckForm.js"></script>
<script language="JavaScript">
function checkform(theform){
	if(!CheckEmpty(theform.selType, "账单类型")) return false;
	if(!CheckEmpty(theform.selMember, "对　象")) return false;
	if(!CheckEmpty(theform.txtMoney, "发生金额")) return false;
	if(!CheckReal(theform.txtMoney, "发生金额")) return false;
}

function init(){
	SelectValue(form1.selType,"<%=GetVariable("type")%>");
	SelectValue(form1.selMember,"<%=GetVariable("id")%>");
	
	SelectValue(Banksearch.year,"<%=year(date)%>");
	SelectValue(Banksearch.month,"<%=month(date)%>");
	SelectValue(Banksearch.day,"<%=day(date)%>");
}

//自动选择用户
function SelectMember(strValue){

	if (strValue==""){
		form1.selMember.options[0].selected=true;
		return;
	}
	
	for(i=0;i<form1.selMember.options.length;i++){
		if (form1.selMember.options[i].text.indexOf(strValue)>=0 && form1.selMember.options[i].value!=""){
			form1.selMember.options[i].selected=true;
			break;
		}
	}
	if (i>=form1.selMember.options.length){
		form1.selMember.options[0].selected=true;
	}
}

</script>
</head>
<body leftmargin="0" topmargin="0" onLoad="init()">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
        <tr> 
          <td height="0" align="center">
		  <!--#include file="common/top.asp"-->
          </td>
        </tr>
        <tr> 
          <td height="100%" align="center" valign="top">
<TABLE class=table002 cellSpacing=0 cellPadding=0 border=0>
              <TBODY>
                <TR> 
                  <!--左边开始-->
                  <TD width="20%" align=right vAlign=top> <!--#include file="common/adminleft.asp"--> </TD>
                  <!--左边结束-->
                  <TD width="2%" background="images/rowline.gif">&nbsp;</TD>
                  <!--右边开始-->
                  <TD vAlign=top align=center width="78%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr> 
                        <td>
						
                            <TABLE width="100%" height="100%" border=0 cellPadding=6 cellSpacing=0>
                              <TBODY>
                                <TR> 
                                  
                                <TD height="300" align=left vAlign=top bgColor=#ffffff><strong><font color="#FF0000">新建账单</font></strong><BR> <HR SIZE=1>
                                    <table width="98%" border="0" cellspacing="0" cellpadding="0">
                                      <tr> 
                                        
                                      <td height="22" valign="bottom" bgcolor="#5F8AC5"><font color="#FFFFFF">&nbsp;<strong>添加账单</strong></font></td>
                                      </tr>
                                      <tr> 
                                        <td height="1" bgcolor="#5F8AC5"></td>
                                      </tr>
                                      <tr> 
                                        <td><table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#5F8AC5">
                                            <tr> 
                                              
                                            <td height="150" align="center" bgcolor="#FFFFFF"> 
                                              <form name="form1" method="post" action="?action=save" onSubmit="return checkform(this)">
                                                <table width="98%" border="0" cellspacing="0" cellpadding="3">
                                                  <tr> 
                                                    <td width="25%" align="right" bgcolor="#F9F9F9">账单类型：</td>
                                                    <td width="75%" bgcolor="#F9F9F9"><font color="#FF0000"> 
                                                      <select name="selType" id="selType">
                                                        <option value="">选择类型</option>
                                                        <option value="入账">入账</option>
                                                        <option value="退款">退款</option>
                                                        <option value="扣款">扣款</option>
                                                      </select>
                                                      </font></td>
                                                  </tr>
                                                  <tr> 
                                                    <td align="right" bgcolor="#FFFFFF">对　象： 
                                                    </td>
                                                    <td bgcolor="#FFFFFF"><input name="txtMember" type="text" id="txtMember" size="20" maxlength="50" onKeyUp="SelectMember(this.value)">
                                                      <select name="selMember" onChange="form1.txtMember.value=form1.selMember.options[form1.selMember.selectedIndex].text">
                                                        <option value="">无对象</option>
                                                        <%
													Set rSub=server.CreateObject("ADODB.RecordSet")
													'不是网站管家只能看到自己的用户
													if Trim(Session("UserCode"))<5 then
														strQuery=" And m_AgentName=" &  strM_ID
													end if
													
													rSub.open "Select id,m_name From member Where Not(m_name Like '%[_]%') " & strQuery & " Order by m_code",conn,1,1
													for i=1 to rSub.recordcount
														response.Write("<option value=" & rSub("id") & ">" & Trim(rSub("m_name")) & "</option>")
														rSub.movenext
													next
													rSub.close
											%>
                                                      </select> </td>
                                                  </tr>
                                                  <tr bgcolor="#F9F9F9"> 
                                                    <td align="right">发生金额：</td>
                                                    <td><input name="txtMoney" type="text" id="txtMoney" size="20" maxlength="20"> 
                                                    </td>
                                                  </tr>
                                                  <tr> 
                                                    <td align="right" bgcolor="#FFFFFF">账单说明：</td>
                                                    <td bgcolor="#FFFFFF"><textarea name="txtNote" cols="50" rows="4" id="txtNote"></textarea></td>
                                                  </tr>
                                                  <tr bgcolor="#F9F9F9"> 
                                                    <td height="35" align="right">&nbsp;</td>
                                                    <td height="35"><input type="submit" name="Submit3" value="提 交">
                                                      <input type="reset" name="Submit4" value="重 置">
                                                      <input type="button" name="Submit22" value="帮 助"> 
                                                    </td>
                                                  </tr>
                                                </table>
                                              </form> </td>
                                            </tr>
                                          </table></td>
                                      </tr>
                                    </table> 
                                </TD>
                                </TR>
                              </TBODY>
                            </TABLE>

						 </td>
                      </tr>
                      <tr>
                        <td align="center"> 
                          <form action="Admin_BankList.asp" method="post" name="Banksearch" id="Banksearch">
                            <table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#5F8AC5">
                              <tr> 
                                <td bgcolor="#5F8AC5">&nbsp<strong><font color="#FFFFFF">用户账单搜索</font></strong></td>
                              </tr>
                              <tr> 
                                <td height="100" align="center" bgcolor="F9F9F9"> 
                                  <table width="98%" border="0" cellspacing="1" cellpadding="3">
                                    <tr> 
                                      <td height="30"> 发生时间： 
                                        <select name="year" id="select2">
                                          <option value="">所有年</option>
                                          <%
											for i=year(date)-3 to year(date) + 5
										   %>
                                          <option value="<%=i%>"><%=i%></option>
                                          <%next%>
                                        </select>
                                        年 
                                        <select name="month" id="select3">
                                          <option value="">所有月</option>
                                          <option value="1">1</option>
                                          <option value="2">2</option>
                                          <option value="3">3</option>
                                          <option value="4">4</option>
                                          <option value="5">5</option>
                                          <option value="6">6</option>
                                          <option value="7">7</option>
                                          <option value="8">8</option>
                                          <option value="9">9</option>
                                          <option value="10">10</option>
                                          <option value="11">11</option>
                                          <option value="12">12</option>
                                        </select>
                                        月 
                                        <select name="day" id="select4">
                                          <option value="">所有日</option>
                                          <option value="1">1</option>
                                          <option value="2">2</option>
                                          <option value="3">3</option>
                                          <option value="4">4</option>
                                          <option value="5">5</option>
                                          <option value="6">6</option>
                                          <option value="7">7</option>
                                          <option value="8">8</option>
                                          <option value="9">9</option>
                                          <option value="10">10</option>
                                          <option value="11">11</option>
                                          <option value="12">12</option>
                                          <option value="13">13</option>
                                          <option value="14">14</option>
                                          <option value="15">15</option>
                                          <option value="16">16</option>
                                          <option value="17">17</option>
                                          <option value="18">18</option>
                                          <option value="19">19</option>
                                          <option value="20">20</option>
                                          <option value="21">21</option>
                                          <option value="22">22</option>
                                          <option value="23">23</option>
                                          <option value="24">24</option>
                                          <option value="25">25</option>
                                          <option value="26">26</option>
                                          <option value="27">27</option>
                                          <option value="28">28</option>
                                          <option value="29">29</option>
                                          <option value="30">30</option>
                                          <option value="31">31</option>
                                        </select>
                                        日 </td>
                                    </tr>
                                    <tr> 
                                      <td height="30"> 账单类型： 
                                        <select name="selType">
                                          <option value="" selected>全部类型</option>
                                          <option value="1">入账款项</option>
                                          <option value="2">被扣款项</option>
                                          <option value="4">退还款项</option>
                                        </select></td>
                                    </tr>
                                    <tr> 
                                      <td height="30"> 　对　象： 
                                        <select name="selAgent" id="select11">
                                          <option value="">选择对象</option>
                                          <%
													Set rSub=server.CreateObject("ADODB.RecordSet")
													'不是网站管家只能看到自己的用户
													if Trim(Session("UserCode"))<5 then
														strQuery=" And m_AgentName=" &  strM_ID
													end if
													
													rSub.open "Select id,m_name From member Where Not(m_name Like '%[_]%') " & strQuery & " Order by m_code",conn,1,1
													for i=1 to rSub.recordcount
														response.Write("<option value=" & rSub("id") & ">" & Trim(rSub("m_name")) & "</option>")
														rSub.movenext
													next
													rSub.close
											%>
                                        </select> </td>
                                    </tr>
                                    <tr> 
                                      <td height="30">关 键 字： 
                                        <input name="txtKey" type="text" id="txtKey2" onClick="this.value='';" size=30 maxlength="50">
                                        　<font color="#FF0000">＊输入用户名，或交易关键字</font> 
                                      </td>
                                    </tr>
                                    <tr> 
                                      <td height="30" align="center"> <input type="submit" name="submit" value=" 查 询 ">
                                        　 
                                        <input type="reset" name="Submit" value=" 取 消 ">
                                        　 
                                        <input type="button" name="Submit2" value=" 帮 助 "></td>
                                    </tr>
                                  </table></td>
                              </tr>
                            </table>
                          </form>
						  </td>
                      </tr>
                    </table> 
                  </TD>
                </TR>
              </TBODY>
            </TABLE></td>
        </tr>
        <tr> 
          <td height="0" align="center">
		  <!--#include file="common/bottom.asp"-->
		  </td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>
