Procedura-VATSummaryCashESL

Parametry:

NázevPopisDatový typ
AFirmSel_IDChar(10)
ADivisionSel_IDChar(10)
ABusOrderSel_IDChar(10)
ABusTransactionSel_IDChar(10)
ABusProjectSel_IDChar(10)
AESLDateFromFloat(0, 0)
AESLDateToFloat(0, 0)
ADivisionsWithChildrenChar(1)
ABusOrdersWithChildrenChar(1)
ABusTransactionsWithChildrenChar(1)
ABusProjectsWithChildrenChar(1)
VATCountry_IDChar(10)

Návratové hodnoty:

NázevPopisDatový typ
VATIndex_IDChar(10)
DocQueue_IDChar(10)
OrdNumberNumeric(8, 0)
Period_IDChar(10)
TAmountWithoutVATNumeric(13, 2)
LocalTAmountWithoutVATNumeric(13, 2)
TAmountNumeric(13, 2)
LocalTAmountNumeric(13, 2)
TextChar(160)
DescriptionChar(50)
Division_IDChar(10)
BusOrder_IDChar(10)
BusTransaction_IDChar(10)
BusProject_IDChar(10)
Firm_IDChar(10)
ESLDate$DateFloat(0, 0)
PosIndexInteger
ESLIndicator_IDChar(10)
Document_IDChar(10)
VIESKindChar(1)

Závislosti:

NázevPopisTřída
CheckDivisionAndBusXProcedures

Tělo:

BEGIN
  VIESKind = '';
  /* radky PP */
  FOR
    SELECT
      A.VATIndex_ID, B.DocQueue_ID, B.OrdNumber, B.Period_ID, A.ESLDate$Date,
      A.TAmountWithoutVAT, A.LocalTAmountWithoutVAT, A.TAmount, A.LocalTAmount,
      A.Text, B.Description, B.Firm_ID, A.Division_ID, A.BusOrder_ID, A.BusTransaction_ID, A.BusProject_ID,
      A.PosIndex, A.RowType, A.Quantity, VI.Income, A.ESLIndicator_ID, B.ID
    FROM
      CashReceived2 A
      join CashReceived B ON A.Parent_ID = B.ID
      left join VatIndexes VI on VI.ID = A.VatIndex_ID
    WHERE
      (A.RowType in (1,2,3,4)) and (A.ToESL = 'A') and (B.TradeType = 2) and
      B.VATDocument = 'A' and B.VATCountry_ID=:VATCountry_ID and
      A.VATIndex_ID IS NOT NULL and
      A.ESLDate$Date >= :AESLDateFrom and A.ESLDate$Date < :AESLDateTo and
      ( (:AFirmSel_ID = '') OR
        (B.Firm_ID in (select OBJ_ID from SELDAT where SEL_ID = :AFirmSel_ID)) OR
        (B.Firm_ID in (SELECT ID FROM Firms WHERE Firm_ID in (select OBJ_ID from SELDAT where SEL_ID = :AFirmSel_ID))) )
    INTO
      :VATIndex_ID, :DocQueue_ID, :OrdNumber, :Period_ID, :ESLDate$Date,
      :TAmountWithoutVAT, :LocalTAmountWithoutVAT, :TAmount, :LocalTAmount,
      :Text, :Description, :Firm_ID, :Division_ID, :BusOrder_ID, :BusTransaction_ID, :BusProject_ID,
      :PosIndex, :mRowType, :mQuantity, :mIncome, :ESLIndicator_ID, :Document_ID
  DO BEGIN
    EXECUTE PROCEDURE CheckDivisionAndBusX
      :Division_ID, :ADivisionSel_ID, :ADivisionsWithChildren,
      :BusOrder_ID, :ABusOrderSel_ID, :ABusOrdersWithChildren,
      :BusTransaction_ID, :ABusTransactionSel_ID, :ABusTransactionsWithChildren,
      :BusProject_ID, :ABusProjectSel_ID, :ABusProjectsWithChildren
    RETURNING_VALUES
      :mSuspend;
    IF (mSuspend > 0) THEN BEGIN
      IF (mRowType = 4) THEN 
        Text = '';
      IF ((mRowType = 3) AND (mQuantity < 0)) THEN BEGIN
        IF (mIncome = 'A') THEN BEGIN --ERR-2721/2009
          TAmountWithoutVAT = (-1) * TAmountWithoutVAT;
          LocalTAmountWithoutVAT = (-1) * LocalTAmountWithoutVAT;
          TAmount = (-1) * TAmount; 
          LocalTAmount = (-1) * LocalTAmount;
        END 
      END          
      SUSPEND;
    END
  END
  /* radky VP */
  FOR
    SELECT
      A.VATIndex_ID, B.DocQueue_ID, B.OrdNumber, B.Period_ID, A.ESLDate$Date,
      (-1*A.TAmountWithoutVAT), (-1*A.LocalTAmountWithoutVAT), (-1*A.TAmount), (-1*A.LocalTAmount),
      A.Text, B.Description, B.Firm_ID, A.Division_ID, A.BusOrder_ID, A.BusTransaction_ID, A.BusProject_ID,
      A.PosIndex, A.RowType, A.ESLIndicator_ID, B.ID
    FROM
      RefundedCashReceived2 A
      join RefundedCashReceived B ON A.Parent_ID = B.ID
    WHERE
      (A.RowType in (1,2,3,4)) and (A.ToESL = 'A') and (B.TradeType = 2) and
      B.VATDocument = 'A' and B.VATCountry_ID=:VATCountry_ID and
      A.VATIndex_ID IS NOT NULL and
      A.ESLDate$Date >= :AESLDateFrom and A.ESLDate$Date < :AESLDateTo and
      ( (:AFirmSel_ID = '') OR
        (B.Firm_ID in (select OBJ_ID from SELDAT where SEL_ID = :AFirmSel_ID)) OR
        (B.Firm_ID in (SELECT ID FROM Firms WHERE Firm_ID in (select OBJ_ID from SELDAT where SEL_ID = :AFirmSel_ID))) )
    INTO
      :VATIndex_ID, :DocQueue_ID, :OrdNumber, :Period_ID, :ESLDate$Date,
      :TAmountWithoutVAT, :LocalTAmountWithoutVAT, :TAmount, :LocalTAmount,
      :Text, :Description, :Firm_ID, :Division_ID, :BusOrder_ID, :BusTransaction_ID, :BusProject_ID,
      :PosIndex, :mRowType, :ESLIndicator_ID, :Document_ID
  DO BEGIN
    EXECUTE PROCEDURE CheckDivisionAndBusX
      :Division_ID, :ADivisionSel_ID, :ADivisionsWithChildren,
      :BusOrder_ID, :ABusOrderSel_ID, :ABusOrdersWithChildren,
      :BusTransaction_ID, :ABusTransactionSel_ID, :ABusTransactionsWithChildren,
      :BusProject_ID, :ABusProjectSel_ID, :ABusProjectsWithChildren
    RETURNING_VALUES
      :mSuspend;
    IF (mSuspend > 0) THEN BEGIN
      IF (mRowType = 4) THEN Text = '';
      SUSPEND;
    END
  END
END;

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