-------------脚本开始------------------------
declare @keyId int
declare @lendinfoid int
declare @collectcorups decimal(18,4)
declare @collectinterest decimal(18,4)
declare @payid int
declare @returnperiods int
begin
set @returnperiods=15;
set @lendinfoid=6218
update CHK_collect_plan_info set is_finished=1,receive_corpus=collect_corpus ,receive_interest=collect_interest where
lend_info_id=@lendinfoid and return_periods=@returnperiods
-------------------------添加收回表-------------------------------------
select @keyId = Max_Id+1 from Table_Key where Table_Name='CLN_capital_interest'
select @collectcorups =collect_corpus ,@collectinterest=collect_interest from CHK_collect_plan_info where lend_info_id=@lendinfoid and return_periods=@returnperiods
INSERT INTO [CLN_capital_interest]
([pay_id]
,[lend_info_id]
,[receive_volume]
,[receive_capital]
,[receive_interest]
)VALUES
(@keyId,@lendinfoid,@returnperiods,@collectcorups,@collectinterest)
update Table_Key set max_id=@keyId where Table_Name='CLN_capital_interest'
update CLN_capital_interest set collect_capital=receive_capital ,collect_interest =receive_interest ,receive_total_money=receive_capital+receive_interest
where lend_info_id=@lendinfoid and receive_volume =@returnperiods
--------------添加收回表明细表-------------------
select @payid=pay_id from CLN_capital_interest where lend_info_id=@lendinfoid and receive_volume =@returnperiods
select @keyId = Max_Id+1 from Table_Key where Table_Name='CLN_repay_detail'
INSERT INTO [CLN_repay_detail]
([paper_fee_id]
,[lend_info_id]
,[cost_id]
,[cost_name]
,[collect_money]
,[pay_id]
,[receive_volume]
,[is_recieved]
)VALUES
(@keyId,@lendinfoid,'-500','本金',@collectcorups,@payid,@returnperiods ,1)
update Table_Key set max_id=@keyId where Table_Name='CLN_repay_detail'
---------利息------
select @keyId = Max_Id+1 from Table_Key where Table_Name='CLN_repay_detail'
INSERT INTO [CLN_repay_detail]
([paper_fee_id]
,[lend_info_id]
,[cost_id]
,[cost_name]
,[collect_money]
,[pay_id]
,[receive_volume]
,[is_recieved]
)VALUES
(@keyId,@lendinfoid,'-400','利息',@collectinterest,@payid,@returnperiods ,1)
update Table_Key set max_id=@keyId where Table_Name='CLN_repay_detail'
update CLN_repay_detail set receive_money=collect_money ,statistics_cost_way=2,before_or_after=2,add_date=GETDATE() where lend_info_id=@lendinfoid and receive_volume=@returnperiods
end