Procedura-GetPricesByPriceDefinitions

Popis:
Vrací prodejní ceny pro zadané definice cen

Parametry:

NázevPopisDatový typ
StorePriceIDChar(10)
PriceDefID1Char(10)
PriceDefID2Char(10)
PriceDefID3Char(10)
PriceDefID4Char(10)
PriceDefID5Char(10)
OnlyMainUnitChar(1)
StoreCardIDChar(10)

Návratové hodnoty:

NázevPopisDatový typ
PriceAmountOneNumeric(15, 5)
PriceAmountTwoNumeric(15, 5)
PriceAmountThreeNumeric(15, 5)
PriceAmountFourNumeric(15, 5)
PriceAmountFiveNumeric(15, 5)
PriceDefIDOneChar(10)
PriceDefIDTwoChar(10)
PriceDefIDThreeChar(10)
PriceDefIDFourChar(10)
PriceDefIDFiveChar(10)
QUnitChar(5)

Závislosti:

NázevPopisTřída
CalculatePriceVrací prodejní cenu pro zadané parametryProcedures

Tělo:

BEGIN
  /* dodrzet poradi - delat petkrat dotaz */
  if (:OnlyMainUnit = 'N') then begin
    for select U.Code from StoreUnits U where
    U.Parent_ID = :StoreCardID
      into :QUnit
    do begin
      PriceAmountOne = 0;
      PriceAmountTwo = 0;
      PriceAmountThree = 0;
      PriceAmountFour = 0;
      PriceAmountFive = 0;
      if (:PriceDefID1 <> '') then begin
        SELECT A.Amount, A.Price_ID FROM
         StorePrices2 A where
            A.Parent_ID = :StorePriceID and A.QUnit = :QUnit and
              (A.Price_ID = :PriceDefID1)
          into :PriceAmountOne, :PriceDefIDOne;
        if (PriceAmountOne = 0) then
          select PriceAmount, OutPriceDefID from CalculatePrice(:StorePriceID, :PriceDefID1, :QUnit)
            into :PriceAmountOne, :PriceDefIDOne;
      end
      if (:PriceDefID2 <> '') then begin
        SELECT A.Amount, A.Price_ID FROM
          StorePrices2 A where
            A.Parent_ID = :StorePriceID and A.QUnit = :QUnit and
              (A.Price_ID = :PriceDefID2)
          into :PriceAmountTwo, :PriceDefIDTwo;
        if (PriceAmountTwo = 0) then
          select PriceAmount, OutPriceDefID from CalculatePrice(:StorePriceID, :PriceDefID2, :QUnit)
            into :PriceAmountTwo, :PriceDefIDTwo;
      end
      if (:PriceDefID3 <> '') then begin
        SELECT A.Amount, A.Price_ID FROM
          StorePrices2 A where
            A.Parent_ID = :StorePriceID and A.QUnit = :QUnit and
              (A.Price_ID = :PriceDefID3)
          into :PriceAmountThree, :PriceDefIDThree;
        if (PriceAmountThree = 0) then
          select PriceAmount, OutPriceDefID from CalculatePrice(:StorePriceID, :PriceDefID3, :QUnit)
            into :PriceAmountThree, :PriceDefIDThree;
      end
      if (:PriceDefID4 <> '') then begin
        SELECT A.Amount, A.Price_ID FROM
          StorePrices2 A where
            A.Parent_ID = :StorePriceID and A.QUnit = :QUnit and
              (A.Price_ID = :PriceDefID4)
          into :PriceAmountFour, :PriceDefIDFour;
        if (PriceAmountFour = 0) then
          select PriceAmount, OutPriceDefID from CalculatePrice(:StorePriceID, :PriceDefID4, :QUnit)
            into :PriceAmountFour, :PriceDefIDFour;
      end
      if (:PriceDefID5 <> '') then begin
        SELECT A.Amount, A.Price_ID FROM
          StorePrices2 A where
            A.Parent_ID = :StorePriceID and A.QUnit = :QUnit and
              (A.Price_ID = :PriceDefID5)
          into :PriceAmountFive, :PriceDefIDFive;
        if (PriceAmountFive = 0) then
          select PriceAmount, OutPriceDefID from CalculatePrice(:StorePriceID, :PriceDefID5, :QUnit)
            into :PriceAmountFive, :PriceDefIDFive;
      end
      Suspend;
    end
  end
  else begin
    PriceAmountOne = 0;
    PriceAmountTwo = 0;
    PriceAmountThree = 0;
    PriceAmountFour = 0;
    PriceAmountFive = 0;
    if (:PriceDefID1 <> '') then begin
      SELECT A.Amount, A.Price_ID, A.QUnit FROM
        StorePrices2 A 
        join StorePrices SP on SP.ID = A.Parent_ID 
        join StoreCards SC on SC.ID = SP.StoreCard_ID and SC.MainUnitCode = A.QUnit
        where
          A.Parent_ID = :StorePriceID and SP.StoreCard_ID = :StoreCardID and A.Price_ID = :PriceDefID1
        into :PriceAmountOne, :PriceDefIDOne, :QUnit;
      if (PriceAmountOne = 0) then
        select PriceAmount, OutPriceDefID from CalculatePrice(:StorePriceID, :PriceDefID1, :QUnit)
          into :PriceAmountOne, :PriceDefIDOne;
    end
    if (:PriceDefID2 <> '') then begin
      SELECT A.Amount, A.Price_ID, A.QUnit FROM
        StorePrices2 A 
        join StorePrices SP on SP.ID = A.Parent_ID 
        join StoreCards SC on SC.ID = SP.StoreCard_ID and SC.MainUnitCode = A.QUnit
        where
          A.Parent_ID = :StorePriceID and SP.StoreCard_ID = :StoreCardID and A.Price_ID = :PriceDefID2
        into :PriceAmountTwo, :PriceDefIDTwo, :QUnit;
      if (PriceAmountTwo = 0) then
        select PriceAmount, OutPriceDefID from CalculatePrice(:StorePriceID, :PriceDefID2, :QUnit)
          into :PriceAmountTwo, :PriceDefIDTwo;
    end    
    if (:PriceDefID3 <> '') then begin
      SELECT A.Amount, A.Price_ID, A.QUnit FROM
        StorePrices2 A 
        join StorePrices SP on SP.ID = A.Parent_ID 
        join StoreCards SC on SC.ID = SP.StoreCard_ID and SC.MainUnitCode = A.QUnit
        where
          A.Parent_ID = :StorePriceID and SP.StoreCard_ID = :StoreCardID and A.Price_ID = :PriceDefID3
        into :PriceAmountThree, :PriceDefIDThree, :QUnit;
      if (PriceAmountThree = 0) then
        select PriceAmount, OutPriceDefID from CalculatePrice(:StorePriceID, :PriceDefID3, :QUnit)
          into :PriceAmountThree, :PriceDefIDThree;
    end    
    if (:PriceDefID4 <> '') then begin
      SELECT A.Amount, A.Price_ID, A.QUnit FROM
        StorePrices2 A 
        join StorePrices SP on SP.ID = A.Parent_ID 
        join StoreCards SC on SC.ID = SP.StoreCard_ID and SC.MainUnitCode = A.QUnit
        where
          A.Parent_ID = :StorePriceID and SP.StoreCard_ID = :StoreCardID and A.Price_ID = :PriceDefID4
        into :PriceAmountFour, :PriceDefIDFour, :QUnit;
      if (PriceAmountFour = 0) then
        select PriceAmount, OutPriceDefID from CalculatePrice(:StorePriceID, :PriceDefID4, :QUnit)
          into :PriceAmountFour, :PriceDefIDFour;
    end    
    if (:PriceDefID5 <> '') then begin
      SELECT A.Amount, A.Price_ID, A.QUnit FROM
        StorePrices2 A 
        join StorePrices SP on SP.ID = A.Parent_ID 
        join StoreCards SC on SC.ID = SP.StoreCard_ID and SC.MainUnitCode = A.QUnit
        where
          A.Parent_ID = :StorePriceID and SP.StoreCard_ID = :StoreCardID and A.Price_ID = :PriceDefID5
        into :PriceAmountFive, :PriceDefIDFive, :QUnit;
      if (PriceAmountFive = 0) then
        select PriceAmount, OutPriceDefID from CalculatePrice(:StorePriceID, :PriceDefID5, :QUnit)
          into :PriceAmountFive, :PriceDefIDFive;
    end        
    Suspend;
  end
end;

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