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