Procedura-GetCashDeskTurnover

Popis:
Obraty a počátky pro uzávěrku pokladen.

Parametry:

NázevPopisDatový typ
CashDesk_IDChar(10)
Period_IDChar(10)
DateToDouble(0, 0)

Návratové hodnoty:

NázevPopisDatový typ
BeginningLocalNumeric(15, 2)
BeginningNumeric(15, 2)
TurnoverLocalNumeric(15, 2)
TurnoverNumeric(15, 2)
ExDiffsNumeric(15, 2)

Tělo:

begin
  if (CashDesk_ID is null and Period_ID is null) then
    Exit;
    
  ExDiffs = 0;
  mExDiffs = 0;
  mExDiffs2 = 0;  
  /* POČÁTKY */
  select A.Beginning, A.BeginningLocal
     from CashDesks2 A
     where A.Parent_ID = :CashDesk_ID and A.Period_ID = :Period_ID
     into Beginning, BeginningLocal;
  
  IF (Beginning IS NULL) THEN
    Beginning = 0;
  IF (BeginningLocal IS NULL) THEN
    BeginningLocal = 0;
  /* OBRATY */
  if (DateTo = 0) then begin
    select SUM(A.Amount), SUM(A.LocalAmount)
       from CashReceived A
       where A.CashDesk_ID = :CashDesk_ID and A.Period_ID = :Period_ID
       into mTurnover, mTurnoverLocal;
  end
  
  if (DateTo <> 0) then begin
    select SUM(A.Amount), SUM(A.LocalAmount)
       from CashReceived A
       where A.CashDesk_ID = :CashDesk_ID and A.Period_ID = :Period_ID and A.DocDate$DATE <= :DateTo
       into mTurnover, mTurnoverLocal;
  end
  
  IF (mTurnover IS NULL) THEN
    mTurnover = 0;
  IF (mTurnoverLocal IS NULL) THEN
    mTurnoverLocal = 0;
  
  Turnover = mTurnover;
  TurnoverLocal = mTurnoverLocal;
  if (DateTo = 0) then begin
    select SUM(A.Amount), SUM(A.LocalAmount)
       from CashPaid A
       where A.CashDesk_ID = :CashDesk_ID and A.Period_ID = :Period_ID
       into mTurnover, mTurnoverLocal;
  end
  
  if (DateTo <> 0) then begin
    select SUM(A.Amount), SUM(A.LocalAmount)
       from CashPaid A
       where A.CashDesk_ID = :CashDesk_ID and A.Period_ID = :Period_ID and A.DocDate$DATE <= :DateTo
       into mTurnover, mTurnoverLocal;  
  end   
  
  IF (mTurnover IS NULL) THEN
    mTurnover = 0;
  IF (mTurnoverLocal IS NULL) THEN
    mTurnoverLocal = 0;
  
  Turnover = Turnover - mTurnover;
  TurnoverLocal = TurnoverLocal - mTurnoverLocal;
  if (DateTo = 0) then begin
    select SUM(A.Amount), SUM(A.LocalAmount)
      from RefundedCashReceived A
      where A.CashDesk_ID = :CashDesk_ID and A.Period_ID = :Period_ID
      into mTurnover, mTurnoverLocal;
  end
  
  if (DateTo <> 0) then begin
    select SUM(A.Amount), SUM(A.LocalAmount)
      from RefundedCashReceived A
      where A.CashDesk_ID = :CashDesk_ID and A.Period_ID = :Period_ID and A.DocDate$DATE <= :DateTo
      into mTurnover, mTurnoverLocal;  
  end   
  
  IF (mTurnover IS NULL) THEN
    mTurnover = 0;
  IF (mTurnoverLocal IS NULL) THEN
    mTurnoverLocal = 0;
  
  Turnover = Turnover - mTurnover;
  TurnoverLocal = TurnoverLocal - mTurnoverLocal;
  if (DateTo = 0) then begin
    select SUM(A.Amount), SUM(A.LocalAmount)
      from RefundedCashPaid A
      where A.CashDesk_ID = :CashDesk_ID and A.Period_ID = :Period_ID
      into mTurnover, mTurnoverLocal;
  end
  
  if (DateTo <> 0) then begin
    select SUM(A.Amount), SUM(A.LocalAmount)
      from RefundedCashPaid A
      where A.CashDesk_ID = :CashDesk_ID and A.Period_ID = :Period_ID and A.DocDate$DATE <= :DateTo
      into mTurnover, mTurnoverLocal;  
  end
  
  if (DateTo = 0) then begin
    FOR 
      select A.Amount, A.Profit
        from CashDeskExchangeDifferences A
        where A.CashDesk_ID = :CashDesk_ID and A.Period_ID = :Period_ID and A.DocDate$DATE <= :DateTo
        into mExDiffs2, mIsProfit
    DO begin
      if (mIsProfit = 'A') then
        mExDiffs = mExDiffs + mExDiffs2;
      else
        mExDiffs = mExDiffs - mExDiffs2;
    end    
  end
  
  if (DateTo <> 0) then begin
    FOR 
      select A.Amount, A.Profit
        from CashDeskExchangeDifferences A
        where A.CashDesk_ID = :CashDesk_ID and A.Period_ID = :Period_ID and A.DocDate$DATE <= :DateTo
        into mExDiffs2, mIsProfit
    DO begin
      if (mIsProfit = 'A') then
        mExDiffs = mExDiffs + mExDiffs2;
      else
        mExDiffs = mExDiffs - mExDiffs2;
    end    
  end
  
  IF (mTurnover IS NULL) THEN
    mTurnover = 0;
  IF (mTurnoverLocal IS NULL) THEN
    mTurnoverLocal = 0;
  IF (mExDiffs IS NULL) THEN
    mExDiffs = 0;  
  
  Turnover = Turnover + mTurnover;
  TurnoverLocal = TurnoverLocal + mTurnoverLocal;
  ExDiffs = mExDiffs;
  suspend;
end;

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