begin
if (InAlias is not null and InAlias <> '') then
mAlias = InAlias || '.';
else
mAlias = '';
mRet = 'XXX';
--InAccDateFrom
if (InAccDateFrom <> 0.0) then
mRet = mRet || ' and ' || mAlias || 'AccDate$DATE >= ' || InAccDateFrom;
--InAccDateTo
if (InAccDateTo <> 0.0) then
mRet = mRet || ' and ' || mAlias || 'AccDate$DATE < ' || InAccDateTo;
--InAllowRequest
if (InAllowRequest = 'N') then
mRet = mRet || ' and ' || mAlias || 'IsRequest =' || '''N''';
--InAudited
if (InAudited <> '%') then
mRet = mRet || ' and ' || mAlias || 'Audited = ''' || InAudited || '''';
--InDivisionSelID
if (InDivisionSelID is not null and InDivisionSelID <> '') then begin
mRet = mRet || ' and ( ';
--regulerni ID
mRet = mRet || 'exists(select 1 from SELDAT where OBJ_ID = ' || mAlias || 'Division_ID and SEL_ID = ''' || InDivisionSelID || ''')';
--podrizene ID
if (InDivisionsWithChilds in ('1', 'A')) then
mRet = mRet || ' or exists(select 1 from SELDAT SLD join SYS$Divisions2 SD2 on SD2.Superior_ID = SLD.OBJ_ID where SD2.ID = ' || mAlias || 'Division_ID and SLD.SEL_ID = ''' || InDivisionSelID || ''')';
mRet = mRet || ' ) ';
end
--InBusOrderSelID
if (InBusOrderSelID is not null and InBusOrderSelID <> '') then begin
mRet = mRet || ' and ( ';
--regulerni ID
mRet = mRet || 'exists(select 1 from SELDAT where OBJ_ID = ' || mAlias || 'BusOrder_ID and SEL_ID = ''' || InBusOrderSelID || ''')';
--podrizene ID
if (InBusOrdersWithChilds in ('1', 'A')) then
mRet = mRet || ' or exists(select 1 from SELDAT SLD join SYS$BusOrders2 SD2 on SD2.Superior_ID = SLD.OBJ_ID where SD2.ID = ' || mAlias || 'BusOrder_ID and SLD.SEL_ID = ''' || InBusOrderSelID || ''')';
--nevyplnene ID
if (InBusOrdersWithNull in ('1', 'A')) then
mRet = mRet || ' or ' || mAlias || 'BusOrder_ID is NULL';
mRet = mRet || ' ) ';
end
--InBusTransactionSelID
if (InBusTransactionSelID is not null and InBusTransactionSelID <> '') then begin
mRet = mRet || ' and ( ';
--regulerni ID
mRet = mRet || 'exists(select 1 from SELDAT where OBJ_ID = ' || mAlias || 'BusTransaction_ID and SEL_ID = ''' || InBusTransactionSelID || ''')';
--podrizene ID
if (InBusTransactionsWithChilds in ('1', 'A')) then
mRet = mRet || ' or exists(select 1 from SELDAT SLD join SYS$BusTransactions2 SD2 on SD2.Superior_ID = SLD.OBJ_ID where SD2.ID = ' || mAlias || 'BusTransaction_ID and SLD.SEL_ID = ''' || InBusTransactionSelID || ''')';
--nevyplnene ID
if (InBusTransactionsWithNull in ('1', 'A')) then
mRet = mRet || ' or ' || mAlias || 'BusTransaction_ID is NULL';
mRet = mRet || ' ) ';
end
--InBusProjectSelID
if (InBusProjectSelID is not null and InBusProjectSelID <> '') then begin
mRet = mRet || ' and ( ';
--regulerni ID
mRet = mRet || 'exists(select 1 from SELDAT where OBJ_ID = ' || mAlias || 'BusProject_ID and SEL_ID = ''' || InBusProjectSelID || ''')';
--podrizene ID
if (InBusProjectsWithChilds in ('1', 'A')) then
mRet = mRet || ' or exists(select 1 from SELDAT SLD join SYS$BusProjects2 SD2 on SD2.Superior_ID = SLD.OBJ_ID where SD2.ID = ' || mAlias || 'BusProject_ID and SLD.SEL_ID = ''' || InBusProjectSelID || ''')';
--nevyplnene ID
if (InBusProjectsWithNull in ('1', 'A')) then
mRet = mRet || ' or ' || mAlias || 'BusProject_ID is NULL';
mRet = mRet || ' ) ';
end
--InFirmSelID
if (InFirmSelID is not null and InFirmSelID <> '') then begin
mRet = mRet || ' and ( ';
--regulerni ID
mRet = mRet || 'exists(select 1 from SELDAT where OBJ_ID = ' || mAlias || 'Firm_ID and SEL_ID = ''' || InFirmSelID || ''')';
--ID predchudcu
mRet = mRet || ' or exists(select 1 from SELDAT SLD join Firms F on F.Firm_ID = SLD.OBJ_ID where F.ID = ' || mAlias || 'Firm_ID and SLD.SEL_ID = ''' || InFirmSelID || ''')';
mRet = mRet || ' ) ';
end
--InAmountFrom .. InAmountTo
if ((InAmountFrom is not null) and (InAmountTo is not null)) then begin
mRet = mRet || ' and (';
mRet = mRet || mAlias || 'Amount between ' || InAmountFrom || ' and ' || InAmountTo;
mRet = mRet || ' or ';
mRet = mRet || '-1* ' || mAlias || 'Amount between ' || InAmountFrom || ' and ' || InAmountTo;
mRet = mRet || ')';
end else begin
--InAmountFrom
if (InAmountFrom is not null) then
mRet = mRet || ' and (' || mAlias || 'Amount >=' || InAmountFrom || ' and ' || mAlias || 'Amount <= -1*' || InAmountFrom || ')';
--InAmountTo
if (InAmountTo is not null) then
mRet = mRet || ' and (' || mAlias || 'Amount >= -1*' || InAmountTo || ' and ' || mAlias || 'Amount <=' || InAmountTo || ')';
end
if (mRet = 'XXX') then
mRet = ' ';
else
mRet = ib_string_replace(mRet, 'XXX and', ' ');
suspend;
end