老K3反结账语句

Declare @CurYear Int, --当前年份
@CurPeriod int, --当前会计期间
@staryear int, --启用年份
@starperiod int, --启用期间
@totalmonth int --每个会计年度的总的期间数
Select @CurPeriod=FValue From t_Systemprofile Where FKey='CurrentPeriod' And FCategory='IC'
Select @CurYear=FValue From t_Systemprofile Where FKey='CurrentYear' And FCategory='IC'
Select @staryear=FValue From t_Systemprofile Where FKey='StartYear' And FCategory='IC'
Select @starperiod=FValue From t_Systemprofile Where FKey='StartPeriod' And FCategory='IC'
Select @totalmonth=FValue From t_Systemprofile Where FKey='PeriodCount' And FCategory='gl'
--Select * From t_systemprofile Where fcategory='ic'

if @CurPeriod=@starperiod and @CurYear=@staryear-----如果目前为启用期间不能反结账
begin
print '目前为启用期间不需要反结账'
end
else

if @CurPeriod <>1------中间期间
begin
Update t_systemprofile Set FValue=@CurPeriod-1 Where FKey='CurrentPeriod' and fcategory='IC'
Delete Icbal Where FPeriod=@CurPeriod And Fyear=@CurYear
Delete IcInvbal Where FPeriod=@CurPeriod And Fyear=@CurYear
Delete Poinvbal Where FPeriod=@CurPeriod And Fyear=@CurYear
print '反结账后目前物流处于'+convert(varchar(10),@CurYear)+'年第'+convert(varchar(10),@CurPeriod-1)+'期'
end
else---------下一年转到上年

begin
Update t_systemprofile Set FValue=@totalmonth Where FKey='CurrentPeriod' and fcategory='IC'
Update t_systemprofile Set FValue=@CurYear-1 Where FKey='CurrentYear' and fcategory='IC'
Delete Icbal Where FPeriod=@CurPeriod And Fyear=@CurYear
Delete IcInvbal Where FPeriod=@CurPeriod And Fyear=@CurYear
Delete Poinvbal Where FPeriod=@CurPeriod And Fyear=@CurYear
print '反结账后目前物流处于'+convert(varchar(10),@CurYear-1)+'年第'++convert(varchar(10),@totalmonth)+'期'
end

 

posted @ 2021-03-17 08:43  allen1991  阅读(143)  评论(0编辑  收藏  举报