Procedura-DocumentsForClosingDate

Parametry:

NázevPopisDatový typ
DocQueue_IDChar(10)
DocumentTypeChar(2)
DateTo$DATEFloat(0, 0)
LocalCurrency_IDChar(10)

Návratové hodnoty:

NázevPopisDatový typ
IDChar(10)

Tělo:

BEGIN
  /* Doklady pro uzávěrku fakturace k datu vřetné omezovacích podmínek. */
  /* JCD */
  if (:DocumentType = '12') then begin
    for
      select
        A.ID
      from
        CustomsDeclarations A
      where
        A.DocDate$DATE <= :DateTo$DATE and
        A.DocQueue_ID = :DocQueue_ID and
        A.Currency_ID <> :LocalCurrency_ID and
        ((A.ClosingPeriod_ID is Null) or
         (A.LastPaymentPeriod_ID is Null) or
         (A.ClosingPeriod_ID <> A.LastPaymentPeriod_ID))
      into
        ID
    do begin
      suspend;
    end
  end

  /* Ostatní příjmy */
  if (:DocumentType = '01') then begin
    for
      select
        A.ID
      from
        OtherIncomes A
      where
        A.DocDate$DATE <= :DateTo$DATE and
        A.DocQueue_ID = :DocQueue_ID and
        A.Currency_ID <> :LocalCurrency_ID and
        ((A.ClosingPeriod_ID is Null) or
         (A.LastPaymentPeriod_ID is Null) or
         (A.ClosingPeriod_ID <> A.LastPaymentPeriod_ID))
      into
        ID
    do begin
      suspend;
    end
  end

  /* Ostatní výdaje */
  if (:DocumentType = '02') then begin
    for
      select
        A.ID
      from
        OtherExpenses A
      where
        A.DocDate$DATE <= :DateTo$DATE and
        A.DocQueue_ID = :DocQueue_ID and
        A.Currency_ID <> :LocalCurrency_ID and
        ((A.ClosingPeriod_ID is Null) or
         (A.LastPaymentPeriod_ID is Null) or
         (A.ClosingPeriod_ID <> A.LastPaymentPeriod_ID))
      into
        ID
    do begin
      suspend;
    end
  end

  /* Zálohové listy k faktuře přijaté */
  if (:DocumentType = '11') then begin
    for 
      select
        A.ID
      from
        ReceivedDInvoices A
      where
        A.DocDate$DATE <= :DateTo$DATE and
        A.DocQueue_ID = :DocQueue_ID and
        A.Currency_ID <> :LocalCurrency_ID and
        ((A.ClosingPeriod_ID is Null) or
         (A.LastPaymentPeriod_ID is Null) or
         (A.ClosingPeriod_ID <> A.LastPaymentPeriod_ID))
      into
        ID
    do begin
      suspend;
    end
  end

  /* Zálohové listy k faktuře vydané */
  if (:DocumentType = '10') then begin
    for 
      select
        A.ID
      from
        IssuedDInvoices A
      where
        A.DocDate$DATE <= :DateTo$DATE and
        A.DocQueue_ID = :DocQueue_ID and
        A.Currency_ID <> :LocalCurrency_ID and
        ((A.ClosingPeriod_ID is Null) or
         (A.LastPaymentPeriod_ID is Null) or
         (A.ClosingPeriod_ID <> A.LastPaymentPeriod_ID))
      into
        ID
    do begin
      suspend;
    end
  end

  /* Faktury vydané */
  if (:DocumentType = '03') then begin
    for 
      select
        A.ID
      from
        IssuedInvoices A
      where
        A.DocDate$DATE <= :DateTo$DATE and
        A.DocQueue_ID = :DocQueue_ID and
        A.Currency_ID <> :LocalCurrency_ID and
        ((A.ClosingPeriod_ID is Null) or
         (A.LastPaymentPeriod_ID is Null) or
         (A.ClosingPeriod_ID <> A.LastPaymentPeriod_ID))
      into
        ID
    do begin
      suspend;
    end
  end

  /* Faktury přijaté */
  if (:DocumentType = '04') then begin
    for 
      select
        A.ID
      from
        ReceivedInvoices A
      where
        A.DocDate$DATE <= :DateTo$DATE and
        A.DocQueue_ID = :DocQueue_ID and
        A.Currency_ID <> :LocalCurrency_ID and
        ((A.ClosingPeriod_ID is Null) or
         (A.LastPaymentPeriod_ID is Null) or
         (A.ClosingPeriod_ID <> A.LastPaymentPeriod_ID))
      into
        ID
    do begin
      suspend;
    end
  end

  /* Penalizační faktury */
  if (:DocumentType = '17') then begin
    for
      select
        A.ID
      from
        PenaltyInvoices A
      where
        A.DocDate$DATE <= :DateTo$DATE and
        A.DocQueue_ID = :DocQueue_ID and
        A.Currency_ID <> :LocalCurrency_ID and
        ((A.ClosingPeriod_ID is Null) or
         (A.LastPaymentPeriod_ID is Null) or
         (A.ClosingPeriod_ID <> A.LastPaymentPeriod_ID))
      into
        ID
    do begin
      suspend;
    end
  end

  /* Dobropisy faktur vydaných */
  if (:DocumentType = '60') then begin
    for 
      select
        A.ID
      from
        IssuedCreditNotes A
      where
        A.DocDate$DATE <= :DateTo$DATE and
        A.DocQueue_ID = :DocQueue_ID and
        A.Currency_ID <> :LocalCurrency_ID and
        ((A.ClosingPeriod_ID is Null) or
         (A.LastPaymentPeriod_ID is Null) or
         (A.ClosingPeriod_ID <> A.LastPaymentPeriod_ID))
      into
        ID
    do begin
      suspend;
    end
  end

  /* Dobropisy faktur přijatých */
  if (:DocumentType = '61') then begin
    for 
      select
        A.ID
      from
        ReceivedCreditNotes A
      where
        A.DocDate$DATE <= :DateTo$DATE and
        A.DocQueue_ID = :DocQueue_ID and
        A.Currency_ID <> :LocalCurrency_ID and
        ((A.ClosingPeriod_ID is Null) or
         (A.LastPaymentPeriod_ID is Null) or
         (A.ClosingPeriod_ID <> A.LastPaymentPeriod_ID))
      into
        ID
    do begin
      suspend;
    end
  end

  /* Danove zalohove listy vydane */
  if (:DocumentType = '62') then begin
    for
      select
        A.ID
      from
        VATIssuedDInvoices A
      where
        A.DocDate$DATE <= :DateTo$DATE and
        A.DocQueue_ID = :DocQueue_ID and
        A.Currency_ID <> :LocalCurrency_ID and
        ((A.ClosingPeriod_ID is Null) or
         (A.LastPaymentPeriod_ID is Null) or
         (A.ClosingPeriod_ID <> A.LastPaymentPeriod_ID))
      into
        ID
    do begin
      suspend;
    end
  end

  /* Dobropisy danovych zalohovych listu vydanych */
  if (:DocumentType = '63') then begin
    for
      select
        A.ID
      from
        VATIssuedDCreditNotes A
      where
        A.DocDate$DATE <= :DateTo$DATE and
        A.DocQueue_ID = :DocQueue_ID and
        A.Currency_ID <> :LocalCurrency_ID and
        ((A.ClosingPeriod_ID is Null) or
         (A.LastPaymentPeriod_ID is Null) or
         (A.ClosingPeriod_ID <> A.LastPaymentPeriod_ID))
      into
        ID
    do begin
      suspend;
    end
  end

  /* Danove zalohove listy prijate */
  if (:DocumentType = '64') then begin
    for
      select
        A.ID
      from
        VATReceivedDInvoices A
      where
        A.DocDate$DATE <= :DateTo$DATE and
        A.DocQueue_ID = :DocQueue_ID and
        A.Currency_ID <> :LocalCurrency_ID and
        ((A.ClosingPeriod_ID is Null) or
         (A.LastPaymentPeriod_ID is Null) or
         (A.ClosingPeriod_ID <> A.LastPaymentPeriod_ID))
      into
        ID
    do begin
      suspend;
    end
  end

  /* Dobropisy danovych zalohovych listu prijatych */
  if (:DocumentType = '65') then begin
    for
      select
        A.ID
      from
        VATReceivedDCreditNotes A
      where
        A.DocDate$DATE <= :DateTo$DATE and
        A.DocQueue_ID = :DocQueue_ID and
        A.Currency_ID <> :LocalCurrency_ID and
        ((A.ClosingPeriod_ID is Null) or
         (A.LastPaymentPeriod_ID is Null) or
         (A.ClosingPeriod_ID <> A.LastPaymentPeriod_ID))
      into
        ID
    do begin
      suspend;
    end
  end
END; 

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