You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
5.7 KiB

1 year ago
if exists(select * from sysobjects where name='p_rz_prepare_fk' and xtype='p')
drop procedure p_rz_prepare_fk
go
create procedure p_rz_prepare_fk
(
@psorgcode varchar(10),
@psbillno varchar(20),
@psparams varchar(200),
@psmsg varchar(2000) out
)
as
begin
declare @optoverstatus varchar(10)
declare @ssupcode varchar(15)
declare @paytype varchar(1)
declare @pretotal numeric(19,4)
declare @prepay numeric(19,4)
declare @ssupstatus varchar(1)
declare @ssupvalidstatus varchar(1)
select @ssupcode=supcode,@paytype=paytype,@pretotal=pretotal from t_pay_head where billno=@psbillno
select @optoverstatus=itemvalue from t_syscfg where section='SYSTEM' and itemname='OVER'
if @optoverstatus<>'STOP'
begin
set @psmsg='<EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><EFBFBD><EFBFBD>Ӫҵ<EFBFBD>ս<EFBFBD><EFBFBD><EFBFBD>Ժ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
return(-1)
end
if not exists(select * from t_supplier where supcode=@ssupcode)
begin
set @psmsg='<EFBFBD><EFBFBD>Ӧ<EFBFBD>̲<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܼ<EFBFBD><EFBFBD><EFBFBD>'
return(-1)
end
select @ssupstatus=supstatus,
@ssupvalidstatus=case when (isnull(validdate,'')='' or validdate>=convert(varchar(100),getdate(),23)) then '1' else '0' end,
@prepay=prepay
from t_supplier where supcode=@ssupcode
if @ssupstatus<>'0'
begin
set @psmsg='<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>״̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܼ<EFBFBD><EFBFBD><EFBFBD>'
return(-1)
end
if @ssupvalidstatus='0'
begin
set @psmsg='<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܼ<EFBFBD><EFBFBD><EFBFBD>'
return(-1)
end
if @pretotal<>0
begin
if @paytype='0' --Ӧ<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>
begin
if @pretotal<0
begin
set @psmsg='ʹ<EFBFBD>õ<EFBFBD>Ԥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
return(-1)
end
if @prepay<@pretotal
begin
set @psmsg='û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>'
return(-1)
end
end
else --Ԥ<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>Գ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>
begin
if @prepay+@pretotal<0
begin
set @psmsg='û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
return(-1)
end
end
end
set @psmsg=''
return(1)
end
go
if exists(select * from sysobjects where name='p_rz_fk' and xtype='p')
drop procedure p_rz_fk
go
create procedure p_rz_fk
(
@psorgcode varchar(10),
@psbillno varchar(20),
@psparams varchar(200),
@psmsg varchar(2000) out
)
as
begin
declare @orgcode varchar(10)
declare @scurdate varchar(10)
declare @scurtime varchar(8)
declare @ssupcode varchar(15)
declare @jymode varchar(1)
declare @dztable varchar(20)
declare @paysoano varchar(20)
declare @dztotal numeric(19,4)
declare @jstotal numeric(19,4)
declare @bcjstotal numeric(19,4)
declare @sup_payable numeric(19,4)
declare @sup_prepaytotal numeric(19,4)
declare @fktotal numeric(19,4)
declare @bczrtotal numeric(19,4)
declare @pretotal numeric(19,4)
declare @ssql varchar(2000)
declare @svbktablename varchar(20)
select @orgcode=itemvalue from t_syscfg where section='SYSTEM' and itemname='BranchNo'
select @scurdate=convert(varchar(100),getdate(),23),@scurtime=convert(varchar(100),getdate(),108)
select @ssupcode=a.supcode,@jymode=b.jymode,@fktotal=a.bcjstotal,@bczrtotal=bczrtotal,@pretotal=pretotal
from t_pay_head a
left join t_supplier b on a.supcode=b.supcode
where billno=@psbillno
if (@jymode='0' or @jymode='1')
begin
set @dztable='t_paysoa_head'
end
else
begin
set @dztable='t_jopaysoa_head'
end
--CircleProcedure
--<EFBFBD>޸Ĺ<EFBFBD>Ӧ<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
declare cur cursor for select paysoano,dztotal,jstotal,bcjstotal from t_pay_body where billno=@psbillno
open cur
fetch next from cur into @paysoano,@dztotal,@jstotal,@bcjstotal
while @@fetch_status=0
begin
if (abs(@dztotal-@jstotal-@bcjstotal)<0.01)
begin
update a set isfinished='1'
from t_pay_bill a,t_paysoa_body b
where a.billtype=b.billtype and a.billno=b.ywbillno and a.orgcode=b.orgcode and b.billno=@paysoano and a.isaccounted='1'
end
--<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>ۼƸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
set @ssql='update '+@dztable+' set fktotal=fktotal+'+@bcjstotal+' where billno='''+@paysoano+''''
exec(@ssql)
fetch next from cur into @paysoano,@dztotal,@jstotal,@bcjstotal
end
close cur
deallocate cur
--AlterVendor
update t_supplier
set fktotal=fktotal+@fktotal,zrtotal=zrtotal+@bczrtotal,prepay=prepay-@pretotal
where supcode=@ssupcode
--WriteVendorBook
set @svbktablename='t_vbk_'+substring(convert(varchar(100),getdate(),112),1,6)
exec p_create_vbk @svbktablename,@psmsg out
if isnull(@psmsg,'')<>''
begin
return(-1)
end
select @sup_payable=case when (@jymode='0' or @jymode='1') then jhtotal-thtotal+tjtotal else amount-tctotal end,@sup_prepaytotal=prepay
from t_supplier
where supcode=@ssupcode
set @ssql='insert into t_vbk_'+ substring(convert(varchar(100),getdate(),112),1,6)+'(orgcode,bookdate,booktime,supcode ,billno,billtype,fsamount,yfjytotal,prejytotal)'
+' values('''+@orgcode+''','''+@scurdate+''','''+@scurtime+''','''+@ssupcode+''','''+@psbillno+''',''2'','+convert(varchar(20),@fktotal)+','+convert(varchar(20),@sup_payable-@fktotal)+','+convert(varchar(20),@sup_prepaytotal+@pretotal)+')'
exec(@ssql)
if (@bczrtotal<>0)
begin
set @ssql='insert into t_vbk_'+ substring(convert(varchar(100),getdate(),112),1,6)+'(orgcode,bookdate,booktime,supcode ,billno,billtype,fsamount,yfjytotal,prejytotal)'
+' values('''+@orgcode+''','''+@scurdate+''','''+@scurtime+''','''+@ssupcode+''','''+@psbillno+''',''A'','+convert(varchar(20),-@bczrtotal)+','+convert(varchar(20),@sup_payable-@fktotal-@bczrtotal)+','+convert(varchar(20),@sup_prepaytotal)+')'
exec(@ssql)
end
if (@pretotal<>0)
begin
set @ssql='insert into t_vbk_'+ substring(convert(varchar(100),getdate(),112),1,6)+'(orgcode,bookdate,booktime,supcode ,billno,billtype,fsamount,yfjytotal,prejytotal)'
+' values('''+@orgcode+''','''+@scurdate+''','''+@scurtime+''','''+@ssupcode+''','''+@psbillno+''',''3'','+convert(varchar(20),-@pretotal)+','+convert(varchar(20),@sup_prepaytotal)+','+convert(varchar(20),@sup_payable)+')'
exec(@ssql)
end
set @psmsg=''
return(1)
end
go