begin
for
select
SUM(A.Incomes),
SUM(A.Expenses),
A.BusTransaction_ID,
MAX(A.Nesting),
SUM(A.Incomes)-SUM(A.Expenses),
MAX(Z.Code),
MAX(Z.Parent_ID),
MAX(Z.Name)
from
RepBusTransactions1(:Audited, :DateFrom, :DateTo, :FirmSelID,
:InBusTransactionSelID, :InBusTransactionsWithChilds,
:InDivisionSelID, :InBusOrderSelID, :InBusOrdersWithChilds,
:InBusProjectSelID, :InBusProjectsWithChilds,
:Summarize, :IsRequest, :InDivisionsWithChilds) A
LEFT join BusTransactions Z ON A.BusTransaction_ID = Z.ID
where
( (:InBusTransactionSelID = '') or
(A.BusTransaction_ID in
(
SELECT Bx.ID FROM BusTransactions Bx WHERE Bx.Hidden = 'N' AND
( (Bx.ID in (select OBJ_ID from SELDAT where SEL_ID = :InBusTransactionSelID)) OR
((:InBusTransactionsWithChilds in ('1', 'A')) and (Bx.ID in (select ID from SYS$BusTransactions2 where Superior_ID in (select OBJ_ID from SELDAT where SEL_ID = :InBusTransactionSelID)))))
)
)
)
group by A.BusTransaction_ID
into Incomes, Expenses, BusTransaction_ID, Nesting, Profit, TempCode, TempParent_ID, TempName
do begin
if (Sorting = 0) then CompletePath = CAST(TempCode as CHAR(20)) || BusTransaction_ID;
if (Sorting = 1) then CompletePath = CAST(TempName as CHAR(100)) || BusTransaction_ID;
if (Sorting = 2) then CompletePath = ''; /* Tridi se podle vystupniho parametru Profit */
if (Sorting = 3) then CompletePath = CAST(TempCode as CHAR(20));
if (Sorting = 4) then CompletePath = CAST(TempName as CHAR(100));
i = 0;
while (BusTransaction_ID is not null and TempParent_ID is not null and i < 100) do begin
select Parent_ID, Code, ID, Name from BusTransactions where ID = :TempParent_ID
into TempParent_ID, TempCode, TempID, TempName;
i = i + 1;
if (Sorting = 0) then CompletePath = CAST(TempCode as CHAR(20)) || TempID || CompletePath;
if (Sorting = 1) then CompletePath = CAST(TempName as CHAR(100)) || TempID || CompletePath;
end
Nesting = i;
if ((FromLevel + MaxNesting) >= Nesting and FromLevel <= Nesting) then suspend;
end
end;