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;