使用SQL语句在K3里进行反结帐- -
使用SQL语句在K3里进行反结帐
Declare @CurYear Int, --当前年份
@CurPeriod int, --当前会计期间
@staryear int, --启用年份
@starperiod int, --启用期间
@totalmonth int --每个会计年度的总的期间数
使用SQL语句在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
注:请将对应的账套执行以下语句进行反结账,执行一次反结一期,请谨慎使用,如
果使用了计划价核算的账套(可能存在计划价调价),不能使用以下语句反结账.