begin
Amount = 0;
DocDate$DATE = 0;
FOR
select LocalAmount, DocumentType, Document_ID from Payments
where PDocumenttype=:APDocumentType and PDocument_ID=:APDocument_ID and ComputedRow=:AComputedRow
INTO :mAmount, :mType, :mID
DO begin
Amount = :Amount + :mAmount;
if (mType = '09') then
select DocDate$Date from BankStatements2 where ID=:mID into :mDate;
else if (mType = '01') then
select DocDate$Date from OtherIncomes where ID=:mID into :mDate;
else if (mType = '02') then
select DocDate$Date from OtherExpenses where ID=:mID into :mDate;
else if (mType = '05') then
select DocDate$Date from CashReceived where ID=:mID into :mDate;
else if (mType = '06') then
select DocDate$Date from CashPaid where ID=:mID into :mDate;
else if (mType = 'U0') then
select PaymentDate$Date from IssuedDepositUsages where ID=:mID into :mDate;
else if (mType = 'U1') then
select PaymentDate$Date from ReceivedDepositUsages where ID=:mID into :mDate;
else if (mType = 'CM') then
select DocDate$Date from Compensations2 where ID=:mID into :mDate;
if (mDate > :DocDate$Date) then
DocDate$Date = mDate;
end
suspend;
end