BEGIN
--konstukce obecne casti WHERE pro vsechny selecty tu pouzite
AToWhere = ':AliasRow.RowType = 3';
AToFrom = ' ';
--InDivisionSelID
if (:InDivisionSelID <> '') then begin
Select AResult from SYS$SQLTemplate2(:InDivisionSelID, :InDivisionsWithChilds, 'SYS$Divisions2', ':AliasRow.Division_ID', 'A') into :SQLConc;
if (SQLConc is not null) then
AToWhere = AToWhere || ' and '|| :SQLConc;
end
--InBusOrderSelID
if (:InBusOrderSelID <> '') then begin
Select AResult from SYS$SQLTemplate2(:InBusOrderSelID, :InBusOrdersWithChilds, 'SYS$BusOrders2', ':AliasRow.BusOrder_ID', 'A') into :SQLConc;
if (SQLConc is not null) then
begin
if (:ABusOrdersWithNull in ('1', 'A')) then
begin
AToWhere = AToWhere || ' and (' || :SQLConc || ' or :AliasRow.BusOrder_ID is null)';
end
else
begin
AToWhere = AToWhere || ' and '|| :SQLConc;
end
end
end
--InBusTransactionSelID
if (:InBusTransactionSelID <> '') then begin
Select AResult from SYS$SQLTemplate2(:InBusTransactionSelID, :InBusTransactionsWithChilds, 'SYS$BusTransactions2', ':AliasRow.BusTransaction_ID', 'A') into :SQLConc;
if (SQLConc is not null) then
begin
if (:ABusTransactionsWithNull in ('1', 'A')) then
begin
AToWhere = AToWhere || ' and (' || :SQLConc || ' or :AliasRow.BusTransaction_ID is null)';
end
else
begin
AToWhere = AToWhere || ' and '|| :SQLConc;
end
end
end
--InBusProjectSelID
if (:InBusProjectSelID <> '') then begin
Select AResult from SYS$SQLTemplate2(:InBusProjectSelID, :InBusProjectsWithChilds, 'SYS$BusProjects2', ':AliasRow.BusProject_ID', 'A') into :SQLConc;
if (SQLConc is not null) then
begin
if (:ABusProjectsWithNull in ('1', 'A')) then
begin
AToWhere = AToWhere || ' and (' || :SQLConc || ' or :AliasRow.BusProject_ID is null)';
end
else
begin
AToWhere = AToWhere || ' and '|| :SQLConc;
end
end
end
--FirmSelID
if (:FirmSelID <> '') then begin
Select AResult from SYS$SQLTemplate3(:FirmSelID, ':AliasHeader.Firm_ID', 'A') into :SQLConc;
if (SQLConc is not null) then
AToWhere = AToWhere || ' and '|| :SQLConc;
end
--StoreSelID
if (:StoreSelID <> '') then begin
Select AResult from SYS$SQLTemplate1(:StoreSelID, ':AliasRow.Store_ID', 'N', 'N') into :SQLConc;
if (SQLConc is not null) then
AToWhere = AToWhere || ' and '|| :SQLConc;
end
--DocQueueSelID
if (:DocQueueSelID <> '') then begin
Select AResult from SYS$SQLTemplate1(:DocQueueSelID, ':AliasHeader.DocQueue_ID', 'A', 'N') into :SQLConc;
if (SQLConc is not null) then
AToWhere = AToWhere || ' and '|| :SQLConc;
end
--CountrySelID
if (:CountrySelID <> '') then begin
Select AResult from SYS$SQLTemplate1(:CountrySelID, ':AliasHeader.Country_ID', 'A', 'N') into :SQLConc;
if (SQLConc is not null) then
AToWhere = AToWhere || ' and '|| :SQLConc;
end
--CurrencySelID
if (:CurrencySelID <> '') then begin
Select AResult from SYS$SQLTemplate1(:CurrencySelID, ':AliasHeader.Currency_ID', 'A', 'N') into :SQLConc;
if (SQLConc is not null) then
AToWhere = AToWhere || ' and '|| :SQLConc;
end
--CreatedBySelID
if (:CreatedBySelID <> '') then begin
Select AResult from SYS$SQLTemplate1(:CreatedBySelID, ':AliasHeader.CreatedBy_ID', 'N', 'N') into :SQLConc;
if (SQLConc is not null) then
AToWhere = AToWhere || ' and '|| :SQLConc;
end
--CorrectedBySelID
if (:CorrectedBySelID <> '') then begin
Select AResult from SYS$SQLTemplate1(:CorrectedBySelID, ':AliasHeader.CorrectedBy_ID', 'N', 'N') into :SQLConc;
if (SQLConc is not null) then
AToWhere = AToWhere || ' and '|| :SQLConc;
end
--FirmOfficeSelID
if (:FirmOfficeSelID <> '') then begin
Select AResult from SYS$SQLTemplate1(:FirmOfficeSelID, ':AliasHeader.FirmOffice_ID', 'N', 'N') into :SQLConc;
if (SQLConc is not null) then
AToWhere = AToWhere || ' and '|| :SQLConc;
end
--DocDate$Date
if (:DocDateUsed in ('1', 'A')) then begin
AToWhere = AToWhere || ' and :AliasHeader.DocDate$Date >= ' || :DocDateFrom || ' and :AliasHeader.DocDate$Date < ' || :DocDateTo;
end
--VATDate$Date
if (:VATDateUsed in ('1', 'A')) then begin
AToWhere = AToWhere || ' and :AliasHeader.VATDate$Date >= ' || :VATDateFrom || ' and :AliasHeader.VATDate$Date < ' || :VATDateTo;
end
--AccDate$Date
if (:AccDateUsed in ('1', 'A')) then begin
AToWhere = AToWhere || ' and :AliasHeader.AccDate$Date >= ' || :AccDateFrom || ' and :AliasHeader.AccDate$Date < ' || :AccDateTo;
end
--StoreCardSelID
if (:StoreCardSelID <> '') then begin
Select AResult from SYS$SQLTemplate1(:StoreCardSelID, ':AliasRow.StoreCard_ID', 'N', 'N') into :SQLConc;
if (SQLConc is not null) then
AToWhere = AToWhere || ' and '|| :SQLConc;
end
suspend;
END;