<%
'功能:资金明细出入函数
'参数:UserName-用户名,ClientName-客户姓名,Money-金钱,MoneyType-类型,InOrOutFlag-操作类型1收入2支出,PayTime-汇款日期,OrderID-订单号,Inputer-操作员,Remark-操作备注,MustIn -强行写入 1是 0否
Function MoneyInOrOut(UserName,ClientName,Money,MoneyType,InorOutFlag,PayTime,OrderID,Inputer,Remark,ChannelID,InfoID,MustIn)
  If Not isNumeric(InOrOutFlag) Or Not isNumeric(Money) Or Money="0" Then MoneyInOrOut=false:Exit Function
  Dim MoneyParam,CurrMoney,rsObj1,rsObj1eof,rs
  If InOrOutFlag=1 Then 
	  MoneyParam="Set [{pre}Money]=[{pre}Money]+"&Money
  ElseIF InOrOutFlag=2 Then
	  MoneyParam="Set [{pre}Money]=[{pre}Money]-"&Money
  Else
	  MoneyInOrOut=false:Exit Function
  End If
  set rsObj1=conn.db("Select top 1 * From {pre}LogMoney Where {pre}UserName='"&UserName&"' and {pre}ChannelID="&ChannelID&" and {pre}InfoID="&InfoID&" And {pre}IncomeOrPayOut="&InOrOutFlag,"records1")
  rsObj1eof=rsObj1.Eof:rsObj1.Close:Set rsObj1=Nothing
  If rsObj1eof Or (ChannelID=0 And InfoID=0) Or MustIn=1 Then'true
    set rs=conn.db("Select top 1 {pre}Money From {pre}user Where {pre}Name='"&UserName&"'","records1")
	If rs.eof Then Exit Function
	CurrMoney=rs(0)
	rs.Close:Set rs=Nothing
	If InOrOutFlag=2 and CurrMoney-Money<0 Then Exit Function
	conn.db "update {pre}user "&MoneyParam&" Where {pre}Name='"&UserName&"'","execute"
	CurrMoney=conn.db("Select top 1 {pre}Money From {pre}user Where {pre}Name='"&UserName&"'","execute")(0)
	conn.db "Insert into {pre}LogMoney([{pre}UserName],[{pre}ClientName],[{pre}Money],[{pre}MoneyType],[{pre}IncomeOrPayOut],[{pre}OrderID],[{pre}Remark],[{pre}PayTime],[{pre}LogTime],[{pre}Inputer],[{pre}IP],[{pre}CurrMoney],[{pre}ChannelID],[{pre}InfoID],[{pre}Times],[{pre}PaymentID]) values('"&UserName&"','"&ClientName&"',"&Money&","&MoneyType&","&InOrOutFlag&",'"&OrderID&"','"&replace(Remark,"'","""")&"',"&SQLNowString&","&SQLNowString&",'"&replace(inputer,"'","""")&"','"&replace(conn.getIp,"'","""")&"',"&CurrMoney&","&ChannelID&","&InfoID&",1,1)","execute"
  End If
End Function

%>