Procedura-SumAmountsForPaymentOrder

Popis:
Vrací souhrnné hodnoty za skupinu platebních příkazů

Parametry:

NázevPopisDatový typ
PaymentOrder_IDChar(10)
OrderGroupInteger
CountInGroupInteger

Návratové hodnoty:

NázevPopisDatový typ
AmountNumeric(15, 2)

Tělo:

BEGIN
  PosIndex = 0;
  MinPosIndex = (OrderGroup - 1) * CountInGroup + 1;
  MaxPosIndex = OrderGroup * CountInGroup;
  Amount = 0;
  TempCurrency = Null;
  for
    select A.Amount, A.Currency_ID from PaymentOrders2 A
      where A.Parent_ID = :PaymentOrder_ID and A.IsNotOK = 'N'
    order by A.PosIndex
    into TempAmount, CurrencyID
  do begin
    if (PosIndex = 0) then
      TempCurrency = CurrencyID;
    if ((TempCurrency <> CurrencyID) or
      (TempCurrency is null and CurrencyID is not null) or
      (TempCurrency is not null and CurrencyID is null))
    then begin
      TempCurrency = Null;
      Amount = 0;
    end
    PosIndex = PosIndex + 1;
    if (PosIndex >= MinPosIndex and PosIndex <= MaxPosIndex and TempCurrency is not Null) then
      Amount = Amount + TempAmount;
  end
  suspend;
END;

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