Procedura-StoreFlowsByDates

Parametry:

NázevPopisDatový typ
ADateFromFloat(0, 0)
ADateToFloat(0, 0)
AStoreSelIDChar(10)
AStoreCardSelIDChar(10)
AFirmSelIDChar(10)
ADivisionSelIDChar(10)
ABusOrderSelIDChar(10)
ABusTransactionSelIDChar(10)
ABusProjectSelIDChar(10)
ADivisionsWithChildsChar(1)
ABusOrdersWithChildsChar(1)
ABusTransactionsWithChildsChar(1)
ABusProjectsWithChildsChar(1)
AStore_IDChar(10)
AStoreCard_IDChar(10)

Návratové hodnoty:

NázevPopisDatový typ
Store_IDChar(10)
StoreCard_IDChar(10)
BegQuantityNumeric(15, 6)
BegLocalAmountNumeric(15, 2)
QuantityNumeric(15, 6)
LocalAmountNumeric(15, 2)
QuantityInNumeric(15, 6)
LocalAmountInNumeric(15, 2)
QuantityOutNumeric(15, 6)
LocalAmountOutNumeric(15, 2)
QuantityTransNumeric(15, 6)
LocalAmountTransNumeric(15, 2)
QuantityInvNumeric(15, 6)
LocalAmountInvNumeric(15, 2)
UnClosedRowsInteger

Závislosti:

NázevPopisTřída
StoreFlowsByDatesSQLQueryVrátí dynamicky sestavený dotaz pro skladové pohyby (použije se v jiných stored procedurách)Procedures

Tělo:

begin
  --natahnem SQL pohybu
  Select SQ from StoreFlowsByDatesSQLQuery(:ADateFrom, :ADateTo, :AStoreSelID, :AStoreCardSelID, :AFirmSelID, :ADivisionSelID,
    :ABusOrderSelID, :ABusTransactionSelID, :ABusProjectSelID,
    :ADivisionsWithChilds, :ABusOrdersWithChilds, 
    :ABusTransactionsWithChilds, :ABusProjectsWithChilds,
    :AStore_ID, :AStoreCard_ID, 0) into :SQLStatRun;
  --jeden cyklus pres vsechno
  BegLocalAmount = 0;
  BegQuantity = 0;
  Quantity = 0;
  LocalAmount = 0;
  QuantityIn = 0;
  LocalAmountIn = 0;
  QuantityOut = 0;
  LocalAmountOut = 0;
  QuantityTrans = 0;
  LocalAmountTrans = 0;
  QuantityInv = 0;
  LocalAmountInv = 0;
  UnClosedRows = 0;
  --vyznam to ma v nespustini suspendu pri prvnim pruchodu
  StoreCard_ID = NULL;
  --EXCEPTION ERRPERIODS SQLStatRun; --pro ladeni
  for EXECUTE STATEMENT SQLStatRun
  into mStore_ID, mStoreCard_ID, mQuantity, mLocalAmount, mIdent, mUnClosedRows
  do begin
    if (mQuantity IS NULL) then
      mQuantity = 0;
    if (mLocalAmount IS NULL) then
      mLocalAmount = 0;
    if ((mStore_ID <> Store_ID) or (mStoreCard_ID <> StoreCard_ID)) then
    begin
      suspend;
      BegLocalAmount = 0;
      BegQuantity = 0;
      Quantity = 0;
      LocalAmount = 0;
      QuantityIn = 0;
      LocalAmountIn = 0;
      QuantityOut = 0;
      LocalAmountOut = 0;
      QuantityTrans = 0;
      LocalAmountTrans = 0;
      QuantityInv = 0;
      LocalAmountInv = 0;
      UnClosedRows = 0;
    end
    /* zda se jedna o vydeje nebo prijmy */
    if (mIdent = 'BB' or mIdent = '22' or mIdent = '21' or
      mIdent = '26' or mIdent = '27' or mIdent = '30' or
      mIdent = '36' or mIdent = '38')
    then
      i = -1;
    else
      i = 1;
    /* zda se jedna o pocatky nebo obraty */
    if (mIdent = '00' or mIdent = 'AA' or mIdent = 'BB') then
    begin
      BegLocalAmount = BegLocalAmount + i * mLocalAmount;
      BegQuantity = BegQuantity + i * mQuantity;
    end
    else
    begin
      LocalAmount = LocalAmount + i * mLocalAmount;
      Quantity = Quantity + i * mQuantity;
    end
    /* zda se jedna o prijemky */
    if (mIdent = '20' or mIdent = '28' or mIdent = '37' or mIdent = '39') then
    begin
      LocalAmountIn = LocalAmountIn + mLocalAmount;
      QuantityIn = QuantityIn + mQuantity;
    end
    /* zda se jedna o dodaky a vratky */
    if (mIdent = '21' or mIdent = '23' or mIdent = '27' or mIdent = '29'  or mIdent = '30' or
      mIdent = '36' or mIdent = '38') then
    begin
        LocalAmountOut = LocalAmountOut + i * mLocalAmount;
        QuantityOut = QuantityOut + i * mQuantity;
    end
    /* zda se jedna o prevodky */
    if (mIdent = '22' or mIdent = '24') then
    begin
      LocalAmountTrans = LocalAmountTrans + i * mLocalAmount;
      QuantityTrans = QuantityTrans + i * mQuantity;
    end
    /* zda se jedna o inventury */
    if (mIdent = '25' or mIdent = '26') then
    begin
      LocalAmountInv = LocalAmountInv + i * mLocalAmount;
      QuantityInv = QuantityInv + i * mQuantity;
    end
    Store_ID = mStore_ID;
    StoreCard_ID = mStoreCard_ID;
    UnCLosedRows = UnCLosedRows + mUnClosedRows;
  end
  if (mStoreCard_ID <> '') then
    suspend;
end

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