Procedura-ESLReportByVATDate62

Parametry:

NázevPopisDatový typ
AFirmSelIDChar(10)
ADivisionsSelIDChar(10)
ABusOrdersSelIDChar(10)
ABusTransactionsSelIDChar(10)
ABusProjectsSelIDChar(10)
AVATDateFromFloat(0, 0)
AVATDateToFloat(0, 0)
ADivisionsWithChildsChar(1)
ABusOrdersWithChildsChar(1)
ABusTransactionsWithChildsChar(1)
ABusProjectsWithChildsChar(1)
AVATCountry_IDChar(10)
ACreatedBySelIDChar(10)
ACorrectedBySelIDChar(10)
ACurrencySelIDChar(10)
ACountrySelIDChar(10)

Návratové hodnoty:

NázevPopisDatový typ
DocumentTypeVarChar(2)
ESLIndicatorVarChar(1)
LocalAmountNumeric(13, 2)
AmountNumeric(13, 2)
VATIdentNumberVarChar(20)
DocumentCountInteger

Tělo:

begin
  /* Danove zalohove listy vydane */
  for select
    '62' as DocumentType,
    E.Code as ESLIndicator,
    sum(A.LocalTAmountWithoutVAT) as LocalAmount,
    sum(A.TAmountWithoutVAT) as Amount,
    F.VATIdentNumber as VATIdentNumber,
    count(distinct P.ID) as DocumentCount
  from
  VATIssuedDInvoices2 A
  join VATIssuedDInvoices P on A.Parent_ID=P.ID
  join Firms F on F.ID=P.Firm_ID
  left join ESLIndicators E on E.ID=A.ESLIndicator_ID
  where (A.RowType = 4) and (A.ToESL = 'A') and (P.TradeType = 2)
  /* datum plneni */
  and (P.VATDate$DATE >= :AVATDateFrom) and (P.VATDate$DATE < :AVATDateTo)
  /* stredisko */
  and ((:ADivisionsSelID = '')
  or ((A.Division_ID in (select Bx.ID from Divisions Bx where Bx.Hidden = 'N'
  and (Bx.ID in (select OBJ_ID from SELDAT where SEL_ID = :ADivisionsSelID))
  or ((:ADivisionsWithChilds in ('1', 'A'))
  and (Bx.ID in (select ID from SYS$Divisions2 where Superior_ID in
  (select OBJ_ID from SELDAT where SEL_ID = :ADivisionsSelID))))))))
  /* zakazka */
  and ((:ABusOrdersSelID = '')
  or (A.BusOrder_ID in (select Bx.ID from BusOrders Bx where Bx.Hidden = 'N'
  and ((Bx.ID in (select OBJ_ID from SELDAT where SEL_ID = :ABusOrdersSelID))
  or ((:ABusOrdersWithChilds in ('1', 'A'))
  and (Bx.ID in (select ID from SYS$BusOrders2 where Superior_ID in
  (select OBJ_ID from SELDAT where SEL_ID = :ABusOrdersSelID))))))))
  /* obch. pripad */
  and ((:ABusTransactionsSelID = '')
  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 = :ABusTransactionsSelID))
  or ((:ABusTransactionsWithChilds in ('1', 'A'))
  and (Bx.ID in (select ID from SYS$BusTransactions2 where Superior_ID in
  (select OBJ_ID from SELDAT where SEL_ID = :ABusTransactionsSelID))))))))
  /* projekt */
  and ((:ABusProjectsSelID = '')
  or (A.BusProject_ID in (select Bx.ID from BusProjects Bx where Bx.Hidden = 'N'
  and ((Bx.ID in (select OBJ_ID from SELDAT where SEL_ID = :ABusProjectsSelID))
  or ((:ABusProjectsWithChilds in ('1', 'A'))
  and (Bx.ID in (select ID from SYS$BusProjects2 where Superior_ID in
  (select OBJ_ID from SELDAT where SEL_ID = :ABusProjectsSelID))))))))
  /* firma */
  and ((:AFirmSelID = '')
  or (P.Firm_ID in (select OBJ_ID from SelDat where SEL_ID = :AFirmSelID))
  or (P.Firm_ID in (select ID from Firms where Firm_ID in
  (select OBJ_ID from SelDat where SEL_ID = :AFirmSelID))))
  /* zeme DPH */
  and (P.VATCountry_ID = :AVATCountry_ID)
  /* vytvoril */
  and ((:ACreatedBySelID = '')
  or (P.CreatedBy_ID in (select Obj_ID from SelDat where Sel_ID = :ACreatedBySelID)))
  /* opravil */
  and ((:ACorrectedBySelID = '')
  or (P.CorrectedBy_ID in (select Obj_ID from SelDat where Sel_ID = :ACorrectedBySelID)))
  /* mena */
  and ((:ACurrencySelID = '')
  or (P.Currency_ID in (select Obj_ID from SelDat where Sel_ID = :ACurrencySelID)))
  /* zeme */
  and ((:ACountrySelID = '')
  or (P.Country_ID in (select Obj_ID from SelDat where Sel_ID = :ACountrySelID)))
  group by E.Code, F.VATIdentNumber
  into :DocumentType, :ESLIndicator, :LocalAmount, :Amount, :VATIdentNumber, :DocumentCount
  do begin
    suspend;
  end
end;

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