begin
ExDiffs = 0;
if (BankAccount_ID is null and Period_ID is null) then
Exit;
select A.Beginning, A.BeginningLocal
from BankAccounts2 A
where A.Parent_ID = :BankAccount_ID and A.Period_ID = :Period_ID
into Beginning, BeginningLocal;
if (DateTo = 0) then begin
select SUM(A.CreditAmount - A.DebitAmount), SUM(A.LocalCreditAmount - A.LocalDebitAmount)
from BankStatements A
where A.BankAccount_ID = :BankAccount_ID and A.Period_ID = :Period_ID
into Turnover, TurnoverLocal;
end
if (DateTo = 0) then begin
FOR
select A.Amount, A.Profit from
BankExchangeDifferences A
where A.BankAccount_ID = :BankAccount_ID and A.Period_ID = :Period_ID
into mExDiff, mIsProfit
DO begin
if (mIsProfit = 'A') then
ExDiffs = ExDiffs + mExDiff;
else
ExDiffs = ExDiffs - mExDiff;
end
end
if (DateTo <> 0) then begin
select SUM(A.CreditAmount - A.DebitAmount), SUM(A.LocalCreditAmount - A.LocalDebitAmount)
from BankStatements A
where A.BankAccount_ID = :BankAccount_ID and A.Period_ID = :Period_ID and A.DocDate$DATE <= :DateTo
into Turnover, TurnoverLocal;
end
if (DateTo <> 0) then begin
FOR
select A.Amount, A.Profit from
BankExchangeDifferences A
where A.BankAccount_ID = :BankAccount_ID and A.Period_ID = :Period_ID and A.DocDate$DATE <= :DateTo
into mExDiff, mIsProfit
DO begin
if (mIsProfit = 'A') then
ExDiffs = ExDiffs + mExDiff;
else
ExDiffs = ExDiffs - mExDiff;
end
end
IF (Turnover IS NULL) THEN
Turnover = 0;
IF (TurnoverLocal IS NULL) THEN
TurnoverLocal = 0;
IF (ExDiffs IS NULL) THEN
ExDiffs = 0;
suspend;
end;