if exists(select * from sysobjects where name='p_rz_prepare_ys' and xtype='p') drop procedure p_rz_prepare_ys go create procedure p_rz_prepare_ys ( @psorgcode varchar(10), @psbillno varchar(20), @psparams varchar(200), @psmsg varchar(2000) out ) as begin declare @scustcode varchar(15) declare @billprepay numeric(19,2) declare @prepay numeric(19,2) select @scustcode=custcode,@billprepay=paytotal from t_whprepay_head where billno=@psbillno select @prepay=prepay from t_customer where custcode=@scustcode if @prepay+@billprepay<0 begin set @psmsg='客户'+@scustcode+'的退款金额'+cast(@billprepay as varchar)+'超过了其预付结余金额'+cast(@prepay as varchar) return(-1) end set @psmsg='' return(1) end go if exists(select * from sysobjects where name='p_rz_ys' and xtype='p') drop procedure p_rz_ys go create procedure p_rz_ys ( @psorgcode varchar(10), @psbillno varchar(20), @psparams varchar(200), @psmsg varchar(2000) out ) as begin declare @sorgcode varchar(10) declare @scustcode varchar(15) declare @scurdate varchar(10) declare @scurtime varchar(8) declare @pfprepaydate varchar(10) declare @username varchar(10) declare @zdrname varchar(10) declare @custbook_name varchar(20) declare @billprepay numeric(19,2) declare @ssql varchar(8000) declare @sinfo varchar(8000) declare @irtn int select @scurdate=convert(varchar(10),getdate(),120),@scurtime=convert(varchar(8),getdate(),108) select @scustcode=custcode,@billprepay=paytotal,@pfprepaydate=bizdate,@username=username,@zdrname=zdrname,@sorgcode=orgcode from t_whprepay_head where billno=@psbillno set @custbook_name='t_whcbk_yyyymm' set @ssql='update t_customer set prepay=prepay+'+cast(@billprepay as varchar)+' where custcode='''+@scustcode+'''' exec (@ssql) if @@error <> 0 begin set @psmsg='更新批发客户预收款总账失败' return(-1) end set @ssql='insert into '+@custbook_name+'(bookdate,booktime,bizdate,custcode,billtype,billno, username,ywname,ctotal,ysjytotal,prepayjytotal,orgcode,tag,accdate) select '''+@scurdate+''' as bookdate,'''+@scurtime+''' as booktime,'''+@pfprepaydate+''' as bizdate, custcode,''2'' as billtype,'''+@psbillno+''' as billno,'''+@username+''' as username, '''+@zdrname+''' as ywname,'+cast(@billprepay as varchar)+' as ctotal, pftotal-thtotal-fktotal as ysjytotal,prepay as prepayjytotal,'''+@sorgcode+''' as orgcode,''0'' as tag,'''' as accdate from t_customer where custcode='''+@scustcode+'''' exec (@ssql) if @@error <> 0 begin set @psmsg='生成批发客户台帐失败' return(-1) end set @psmsg='' return(1) end go