Procedura-GetBankAccountTurnover

Popis:
Vrací obraty na bankovních účtech

Parametry:

NázevPopisDatový typ
BankAccount_IDChar(10)
Period_IDChar(10)
DateToDouble(0, 0)

Návratové hodnoty:

NázevPopisDatový typ
BeginningLocalNumeric(15, 2)
BeginningNumeric(15, 2)
TurnoverLocalNumeric(15, 2)
TurnoverNumeric(15, 2)
ExDiffsNumeric(15, 2)

Tělo:

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;

Generated by ABRA Software a.s. 27.10.2021 16:34:14