begin
-- Načteme SQL k získání stavů
Select SQ from StoreBatchesFlowsByDatesSQL(
:ADateFrom,
:ADateTo,
:AStoreSelID,
:AStoreCardSelID,
:AStoreBatchSelID,
:AFirmSelID,
:ADivisionSelID,
:ABusOrderSelID,
:ABusTransactionSelID,
:ABusProjectSelID,
:ADivisionsWithChilds,
:ABusOrdersWithChilds,
:ABusTransactionsWithChilds,
:ABusProjectsWithChilds,
:AStore_ID,
:AStoreCard_ID,
:AStoreBatch_ID) into :SQLStatRun;
-- vykonání SQL
BegQuantity = 0;
Quantity = 0;
QuantityIn = 0;
QuantityOut = 0;
QuantityTrans = 0;
QuantityInv = 0;
StoreCard_ID = NULL;
for EXECUTE STATEMENT SQLStatRun
into mStore_ID, mStoreCard_ID, mStoreBatch_ID, mDocumentType, mQuantity do
begin
if ((mStore_ID <> Store_ID) or (mStoreCard_ID <> StoreCard_ID) or (mStoreBatch_ID <> StoreBatch_ID) ) then
begin
suspend;
BegQuantity = 0;
Quantity = 0;
QuantityIn = 0;
QuantityOut = 0;
QuantityTrans = 0;
QuantityInv = 0;
end
Store_ID = mStore_ID;
StoreCard_ID = mStoreCard_ID;
StoreBatch_ID = mStoreBatch_ID;
/* zda se jedna o vydeje nebo prijmy */
if (mDocumentType = 'BB' or mDocumentType = '22' or mDocumentType = '21' or
mDocumentType = '26' or mDocumentType = '27' or mDocumentType = '30' or
mDocumentType = '36' or mDocumentType = '38')
then
mFlowSign = -1;
else
mFlowSign = 1;
/* zda se jedna o pocatky nebo obraty */
if (mDocumentType = '00' or mDocumentType = 'AA' or mDocumentType = 'BB') then
begin
BegQuantity = BegQuantity + mFlowSign * mQuantity;
end
else
begin
Quantity = Quantity + mFlowSign * mQuantity;
end
/* zda se jedna o prijmy */
if (mDocumentType = '20' or mDocumentType = '28' or mDocumentType = '37' or mDocumentType = '39') then
begin
QuantityIn = QuantityIn + mFlowSign * mQuantity;
end
/* zda se jedna o výdeje */
if (mDocumentType = '21' or mDocumentType = '23' or mDocumentType = '27' or mDocumentType = '29' or mDocumentType = '30' or
mDocumentType = '36' or mDocumentType = '38') then
begin
QuantityOut = QuantityOut + mFlowSign * mQuantity;
end
/* zda se jedna o prevodky */
if (mDocumentType = '22' or mDocumentType = '24') then
begin
QuantityTrans = QuantityTrans + mFlowSign * mQuantity;
end
/* zda se jedna o inventury */
if (mDocumentType = '25' or mDocumentType = '26') then
begin
QuantityInv = QuantityInv + mFlowSign * mQuantity;
end
end
if (mStoreCard_ID <> '') then
suspend;
end