USP_EDITDEPOSIT_RECREATEDEPOSITCORRECTIONGLDISTRIBUTIONS
Recreate the deposit correction GL distributions after a change in the deposit.
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@DEPOSITID | uniqueidentifier | IN | |
@CHANGEAGENTID | uniqueidentifier | IN |
Definition
Copy
CREATE procedure dbo.USP_EDITDEPOSIT_RECREATEDEPOSITCORRECTIONGLDISTRIBUTIONS
(
@DEPOSITID uniqueidentifier
,@CHANGEAGENTID uniqueidentifier = null
)
as
begin
if @CHANGEAGENTID is null
exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output
declare @CURRENTDATE datetime
set @CURRENTDATE = getdate();
declare @ORGAMOUNTORIGINCODE tinyint;
declare @ORGCURRENCYID uniqueidentifier;
select @ORGAMOUNTORIGINCODE = ORGANIZATIONAMOUNTORIGINCODE from dbo.MULTICURRENCYCONFIGURATION;
select @ORGCURRENCYID = ID from dbo.CURRENCY where ISORGANIZATIONCURRENCY = 1;
declare @CONTEXTCACHE varbinary(128);
set @CONTEXTCACHE = CONTEXT_INFO();
if @CHANGEAGENTID is not null
set CONTEXT_INFO @CHANGEAGENTID;
-- Delete all deposit correction distributions as we will recreate all of them (following the BBEC
-- model since it is impossible to keep track of edited distributions since there is no real link).
-- Deleting from dbo.GLTRANSACTION has a fk cascade delete on the dbo.BANKACCOUNTDEPOSITCORRECTIONGLDISTRIBUTION
-- table so this delete statement should take care of both tables.
delete from dbo.GLTRANSACTION where ID in
(
select DIST.GLTRANSACTIONID
from dbo.BANKACCOUNTDEPOSITCORRECTION as C
inner join dbo.BANKACCOUNTDEPOSITCORRECTIONGLDISTRIBUTION as DIST on C.ID = DIST.BANKACCOUNTDEPOSITCORRECTIONID
where C.DEPOSITID = @DEPOSITID
)
if not @CONTEXTCACHE is null
set CONTEXT_INFO @CONTEXTCACHE;
declare @PDACCOUNTSYSTEMID uniqueidentifier;
select @PDACCOUNTSYSTEMID = BA.PDACCOUNTSYSTEMID
from dbo.BANKACCOUNTTRANSACTION BAT
inner join dbo.BANKACCOUNT BA on BA.ID = BAT.BANKACCOUNTID
where BAT.ID = @DEPOSITID
declare @BANKACCOUNTDEPOSITCORRECTIONID uniqueidentifier;
declare recreatedistributions_cursor cursor for
select ID from dbo.BANKACCOUNTDEPOSITCORRECTION where DEPOSITID = @DEPOSITID
open recreatedistributions_cursor
fetch next from recreatedistributions_cursor
into @BANKACCOUNTDEPOSITCORRECTIONID
while @@FETCH_STATUS=0
begin
exec dbo.USP_BANKACCOUNTDEPOSITCORRECTION_CREATEDISTRIBUTION @BANKACCOUNTDEPOSITCORRECTIONID, @CHANGEAGENTID, @CURRENTDATE, @PDACCOUNTSYSTEMID;
fetch next from recreatedistributions_cursor into @BANKACCOUNTDEPOSITCORRECTIONID
end
close recreatedistributions_cursor
deallocate recreatedistributions_cursor
end