project QadFinancials > class Business Component > method RoundAmount

function returns decimal

Description

Function to round amounts based on the rounding method linked to the currency.


Parameters


idUnroundedAmountinputdecimalUnrounded amount
iiCurrencyIDinputintegerCurrency ID
icCurrencyCodeinputcharacterCurrency Code


Internal usage


QadFinancials
method BAllocationBatch.ExecuteAllocationBatch
method BAllocationBatch.GetCountOfGroups
method BAllocationBatch.GetProposedAllocations
method BAPMatching.AdditionalUpdatesAllCreatePLCirec
method BAPMatching.AdditionalUpdatesAllLinesPLAddPostingLineOpAllocCode
method BAPMatching.AdditionalUpdatesAllLinesPLExpenseAcruals
method BAPMatching.AdditionalUpdatesAllLinesPLReceiptPvod
method BAPMatching.AdditionalUpdatesAllLinesPLVarRate
method BAPMatching.AdditionalUpdatesAllTaxNewOne
method BAPMatching.AdditionalUpdatesAllTaxNewTwo
method BAPMatching.AdditionalUpdatesAllTaxOldOne
method BAPMatching.AdditionalUpdatesAllTaxOldTwo
method BAPMatching.ApiGetAPMatchingLnByPvo
method BAPMatching.ApiGetMatchingInfoMulti
method BAPMatching.CalculatePostAPMLn
method BAPMatching.DefaultValuesInvoiceAmount
method BAPMatching.GetAmountPreferencingExpected
method BAPMatching.GetLogChargesPVOFromHeaderInfo
method BAPMatching.GetPendingVouchersLogCharges
method BAPMatching.GetPendingVouchersLogChargesQuery
method BAPMatching.GetPendingVouchersNoLogCharges
method BAPMatching.GetPendingVouchersNoLogChargesTax
method BAPMatching.GetPendingVouchersNoLogChargesTaxFiscal
method BAPMatching.GetPendingVouchersPOShipper
method BAPMatching.UpdateCInvoiceFromUIAPM
method BAPMatching.ValidateComponentPreAPMLn1
method BAPMatching.ValidateComponentPreAPMLnTax
method BAPMatchingReport.MatchingVariance
method BBankCharge.PreValidateComponent
method BBankEntry.AddBankEntryAllocateDocument
method BBankEntry.AdditionalUpdatesAssignments
method BBankEntry.AdditionalUpdatesInv
method BBankEntry.AdditionalUpdatesInvCIMovements
method BBankEntry.AdditionalUpdatesInvDeductions
method BBankEntry.AdditionalUpdatesInvDiscountCurrDiff
method BBankEntry.AdditionalUpdatesInvDiscountCurrDiffTax
method BBankEntry.AdditionalUpdatesInvPrePayments
method BBankEntry.ApiStdMaintainTTSub
method BBankEntry.CalculateAll
method BBankEntry.CalculateBankState
method BBankEntry.CreateDeduction
method BBankEntry.CreatePrepayment
method BBankEntry.DefaultBankStateAllocBank
method BBankEntry.GetGLForCurrencyReferenceLC
method BBankEntry.GetJournalEntryBalance
method BBankEntry.GetPossibleAllocationsCInvoice
method BBankEntry.GetPossibleAllocationsDInvoice
method BBankEntry.ValidateComponentPre
method BBankEntry.ValidateComponentPreUpdateBankStateAlloc
method BBankImportLine.GetInvoicesByBankImpLine
method BBankImportLine.GetInvoicesByBankImpLineXref
method BBankImportLine.GetInvoiceStagesByBankImpLineXref
method BBill.GetToBillDInvoice
method BBudget.ApiCheckBudget
method BBudget.ApiGetBudgetWBSWithFiguresCalculate
method BCashBox.GetCashGLInfo
method BCDocument.AdditionalUpdatesCCollection
method BCDocument.AdditionalUpdatesPostingBankCharge
method BCDocument.AdditionalUpdatesPostingBankChargeCtrl
method BCDocument.AdditionalUpdatesPostingCrossCy
method BCDocument.AdditionalUpdatesPostingDocCtrl3
method BCDocument.AdditionalUpdatesPostingDocExchangeRate
method BCDocument.AdditionalUpdatesPostingPrePayment
method BCDocument.AdditionalUpdatesPostingXrefCIDelTax
method BCDocument.AdditionalUpdatesPostingXrefCIDisc
method BCDocument.AdditionalUpdatesPostingXrefCIDiscTax
method BCDocument.AdditionalUpdatesPostingXrefDI
method BCDocument.AdditionalUpdatesPostingXrefDISuspTax
method BCDocument.AdditionalUpdatesPostingXRefWHT
method BCDocument.CalculateAll
method BCDocument.GetPossibleAllocationsByBank
method BCDocument.GetPossibleAllocationStages
method BCInvoice.AdditionalUpdatesAllAssignments
method BCInvoice.ApiStdMaintainTTCalcAmounts
method BCInvoice.ApiStdMaintainTTCreateVatWHT
method BCInvoice.ApiStdMaintainTTInitialDefaulting
method BCInvoice.Calculate
method BCInvoice.CalculateTax
method BCInvoice.CreateCInvoiceMovements
method BCInvoice.CreateCInvoiceMovementsCrossCy
method BCInvoice.CreateCInvoiceMovementsDelTax
method BCInvoice.CreateCInvoiceMovementsWHT
method BCInvoice.CreateCInvoicesPayment
method BCInvoice.CreateCInvoicesValidate
method BCInvoice.CreateCIPosting2
method BCInvoice.CreateCIPostingValidate
method BCInvoice.CreateMFPosting
method BCInvoice.CreatePostingCalculateTotInvAmount
method BCInvoice.DefaultValuesPaymentCondition
method BCInvoice.DefaultValuesTax
method BCInvoice.DefaultValuesWHTFees
method BCInvoice.GetAmountPreferencingExpected
method BCInvoice.GetInvoiceAmount
method BCInvoice.GetWHTDescriptionAndCCExch
method BCInvoice.UpdateCInvoiceBankToPayTC
method BCInvoice.UpdateCInvoiceFromAPM
method BCInvoice.UpdateCInvoiceVatDelay
method BCInvoice.ValidateComponentPre
method BCInvoice.ValidateComponentPreVat
method BCInvoice.ValidateComponentPreWHT
method BCInvoiceAPMatching.ApiGetCInvoiceAPMatchingDetails
method BClosingPostingsReport.IsGLAutoBalClear
method BConsolid.AdditionalUpdatesPosting
method BCreditor.CalculateBalanceOI
method BCreditor.CalculateBOIforCompanies
method BOpenBalance.ApiCalculateLCTCForOpenBalances
method BOpenBalance.GetInvoiceAmountTCChanges
method BCreditorReport.CreditorWithholdingTax
method BDCollection.RetrievePaySelInitial
method BDDocument.AdditionalUpdatesDCollection
method BDDocument.AdditionalUpdatesPostingDeduction
method BDDocument.AdditionalUpdatesPostingDocCtrl3
method BDDocument.AdditionalUpdatesPostingDocExchangeRate
method BDDocument.AdditionalUpdatesPostingPrePayment
method BDDocument.AdditionalUpdatesPostingXrefDIDisc3
method BDDocument.AdditionalUpdatesPostingXrefDISuspTax
method BDDocument.Calculate
method BDDocument.GetPossibleAllocationsByBank
method BDDocument.GetPossibleAllocationStages
method BDebtor.ApiCheckCreditLimit
method BDebtor.ApiExtractHighCreditInfo
method BDebtor.ApiGetCustomerInvoicePastDueTotal
method BDebtor.CalcOpenOrderTotal
method BDebtor.CalculateBalanceDrafts
method BDebtor.CalculateBalanceOpenItems
method BDebtor.CalculateBalanceSalesOrders
method BDebtor.CalculateBOIforCompanies
method BDebtor.CalculateBSOForCompany
method BDebtor.CalculateCreditOnTurnover
method BDebtor.GetCurrencyAmount
method BDebtorBalance.UpdateDBalanceAndDHistDebtorHighCredit
method BDebtorFinanceCharge.ApplyFilter
method BDebtorFinanceCharge.FCDInvoiceCommit
method BDebtorFinanceCharge.FCDInvoiceCommitCalculate
method BDebtorReport.CustomerCreditOverview
method BDInvoice.AdditionalUpdatesAllDebtorUpdates
method BDInvoice.ApiStdMaintainTTCalcAmounts
method BDInvoice.ApiStdMaintainTTWithIntPostCreateVat
method BDInvoice.AutoPopulateInvoiceStage
method BDInvoice.CalculateDInvoiceVat
method BDInvoice.CalculateTax
method BDInvoice.CreateDInvoiceMovements
method BDInvoice.CreateDInvoiceMovementsCrossCy
method BDInvoice.CreateDInvoiceMovementsSuspTax
method BDInvoice.CreateDInvoicesValidate
method BDInvoice.CreateDIPosting
method BDInvoice.CreateDIPostingSales
method BDInvoice.CreateDIPostingTax
method BDInvoice.CreateDIPostingValidate
method BDInvoice.DefaultValuesDueDates
method BDInvoice.DefaultValuesExchangeRateOriginal
method BDInvoice.DefaultValuesPaymentCondition
method BDInvoice.DefaultValuesTax
method BDInvoice.MoveSuspendedTax
method BDInvoice.StdMaintainTTCalcAmounts
method BDInvoice.UpdateDInvoiceBankToPayTC
method BDInvoice.ValidateComponentPre
method BDInvoice.ValidateComponentPreValidateVat
method BDInvoiceJournalEntry.ApiStdMaintainTTFillCCLC
method BDInvoiceJournalEntry.CalculateInvoiceDueDates
method BDPaymentSelection.CalculateStagedLineAmounts
method BDPaymentSelection.DPaySelLineCalcValues
method BDPaymentSelection.GetDDocumentInfo
method BDPaymentSelection.GetPaymentCurrencyAmounts
method BDPaymentSelection.GetToPayObjects
method BDPaymentSelection.GetToPayObjectsInitialLoad
method BDPaymentSelection.GetToPayObjectsStages
method BERSProcessor.ERSProcessAPMatching
method BERSProcessor.GetERSLegalDocumentsNoLC
method BERSProcessor.GetERSPendingVouchersPORec
method BExpenseNote.APIExpNoteRegister
method BExpenseNote.APIGetAdvancesInfo
method BExpenseNote.GetProposedAdvanceLink
method BExpenseNote.RefreshAdvances
method BFixedAssetAsset.CapitalizeAsset
method BFixedAssetDepreciation.APIDepreciationSimul
method BFixedAssetDepreciation.DepreciationMain
method BFixedAssetDepreciation.DepreciationMainSub
method BFixedAssetDisposal.DisposalCalcDetAmounts
method BFixedAssetDisposal.DisposalCreate
method BFixedAssetDisposal.DisposalCreateDet
method BFixedAssetDisposal.DisposalProposals
method BGLOpenItemProcessor.GLOpenItemInitializationPosting
method BPosting.AddControlPosting
method BPosting.AddPostingLineTaxForSuspDel
method BPosting.AddStandardPosting
method BPosting.AddTaxPostingDetail
method BPosting.AddTaxPostingFillCCAmounts
method BPosting.AddTaxPostingPartTwo
method BPosting.ApiStdMaintainTTSub1
method BPosting.CalculateCCAmount
method BPosting.StdMaintainTTSub1
method BPosting.ValidateComponentPostPostingLine4
method BPosting.ValidateComponentPostRounding
method BPosting.ValidateComponentPre
method BPosting.ValidateComponentPreAssignPostingLine
method BPosting.ValidateComponentPreAssignPostingVat
method BJournalEntry.CreateRecEntryPostingTemplate
method BJournalEntry.CreateTaxPosting
method BJournalEntry.DumpJEForConsolid
method BJournalEntry.LoadTemplate
method BJournalEntry.LoadVatTemplate
method BJournalEntry.PostingLineGLUpdate
method BJournalEntry.UpdatePostingLine
method BMFGLegalDocument.GetLegalDocumentDetForAPMatchingLCDist
method BMFGLegalDocument.GetLegalDocumentDetForAPMatchingTax
method BOpenItemAdjustment.OIAdjApplyFilterCreditor
method BOpenItemAdjustment.OIAdjApplyFilterDebtor
method BOpenItemAdjustment.OIAdjCommitSubCInvoice
method BOpenItemAdjustment.OIAdjCommitSubCInvoiceDiscount
method BOpenItemAdjustment.OIAdjCommitSubDInvoice
method BOpenItemAdjustment.OIAdjCommitSubDInvoiceDiscount
method BOpenItemAdjustment.OIAdjCommitSubOpenItemAdj
method BOpenItemAdjustment.OIAdjCommitValidateOne
method BPaymentSelection.AdditionalUpdatesRegister
method BPaymentSelection.AdditionalUpdatesRegisterPrePayment
method BPaymentSelection.ApiGetPaySelInfo
method BPaymentSelection.ApiGetToPayObjectsV01
method BPaymentSelection.ApiGetToPayObjectsV02
method BPaymentSelection.ApiGetToPayObjectsV03
method BPaymentSelection.ApiGetToPayObjectsV04
method BPaymentSelection.CreateProposedStagedLines
method BPaymentSelection.ExportBEInland
method BPaymentSelection.ExportNLInland
method BPaymentSelection.GetToPayObjectsForCInvoice
method BPaymentSelection.GetToPayObjectsInitLoadFromInst
method BQBudgetActual.AdditonalUpdatesDeleteSub
method BQBudgetCommitment.AdditionalUpdatesDeleteSub
method BQCInvoiceMovement.ApiCreateQCInvoiceMovement
method BQCrossCyPosting.ApiProcessQCrossCyPostingCalcAmount
method BQCrossCyPosting.ApiProcessQCrossCyPostingCalcAmountCI
method BQCrossCyPosting.ApiProcessQCrossCyPostingCalcAmountDI
method BQDInvoiceMovement.ApiCreateQDInvoiceMovement
method BRevaluation.CalcRevalBalance
method BRevaluation.SimulateAdjustCCtRevalGL
method BRevaluation.SimulateDocuments
method BSelfBill.ApiCreateInvPrepayPaymentSubOB
method BVATReport.GetAPTaxRegisterPostings
method BVATReport.ITARVATReg
method BVATReport.ITVATRegSusp
method BWithholdingTax.CreateAndOrUpdateWHTSubAssignLCCC
method BWithholdingTax.CreateAndOrUpdateWHTSubExpense
method BWithholdingTax.CreateAndOrUpdateWHTSubFee
method TConvertInstalNETXML.SetOutputData
method TConvertInstalNETXML.SetOutputDataSub
method BDDocument.AdditionalUpdatesDCollectionCopy
method BWithholdingTax.CreateAndOrUpdateWHTSubRoundTC

QadFitnesse
method BBankEntry.AddBankEntryAllocationV02
method BCInvoice.ApiGetStagedPaymentConditions


program code (program7/business.p)

define variable oiReturnStatus as integer no-undo. /* for query-usage in function */

/* ====================== */
/* Check input parameters */
/* ====================== */
if idUnroundedAmount = 0 or idUnroundedAmount = ?
then return 0.0.

if (iiCurrencyID   = 0    or iiCurrencyID   = ?) and
   (icCurrencyCode = '':U or icCurrencyCode = ?)
then return idUnroundedAmount.
   
/* =============================================== */                                                     
/* Check if temp-table if filled.  If not, fill it */
/* =============================================== */
if not can-find(first tCurrencyRounding)
then do:
    <Q-1 run CurrencyByCurrRoundingMethod (all) (Read) (NoCache)
       (input 0, (CurrencyID)
        input '':U, (CurrencyCode)
        input '':U, (RoundingMethodCode)
        output dataset tqCurrencyByCurrRoundingMethod) in BCurrency >

    for each tqCurrencyByCurrRoundingMethod where
             tqCurrencyByCurrRoundingMethod.tcRoundingMethodCode <> '':U and
             tqCurrencyByCurrRoundingMethod.tcRoundingMethodCode <> ?:
        create tCurrencyRounding.
        assign tCurrencyRounding.tiCurrencyID              = tqCurrencyByCurrRoundingMethod.tiCurrency_ID
               tCurrencyRounding.tcCurrencyCode            = tqCurrencyByCurrRoundingMethod.tcCurrencyCode
               tCurrencyRounding.tdRoundingMethodUnit      = tqCurrencyByCurrRoundingMethod.tdRoundingMethodUnit
               tCurrencyRounding.tdRoundingMethodThreshold = tqCurrencyByCurrRoundingMethod.tdRoundingMethodThreshold.
    end. /* for each tqCurrencyByCurrRoundingMethod: */

end. /* if not can-find(first tCurrencyRounding) */

/* ======================================================= */
/* Leave if no rounding method was linked to this currency */
/* ======================================================= */
find tCurrencyRounding where
     tCurrencyRounding.tiCurrencyID   = iiCurrencyID or
     tCurrencyRounding.tcCurrencyCode = icCurrencyCode
     no-lock no-error.
if not available tCurrencyRounding
then return idUnroundedAmount.

/* ============================ */                                  
/* Calculate the rounded amount */
/* ============================ */
/* Check if amount is negative. Make it positive */
if idUnroundedAmount < 0
then assign vlAmountIsNegative = true
            idUnroundedAmount  = idUnroundedAmount * -1.
else assign vlAmountIsNegative = false.

/* Get the truncated amount */
assign vdTruncatedAmount = trunc(idUnroundedAmount / tCurrencyRounding.tdRoundingMethodUnit, 0) * tCurrencyRounding.tdRoundingMethodUnit.

/* Get the remainder amount */
assign vdRemainderAmount = idUnroundedAmount - vdTruncatedAmount.

if vdRemainderAmount >= tCurrencyRounding.tdRoundingMethodThreshold
then assign vdRoundedAmount = vdTruncatedAmount + tCurrencyRounding.tdRoundingMethodUnit.
else assign vdRoundedAmount = vdTruncatedAmount.

/* Reset the correct sign */
if vlAmountIsNegative = true
then return vdRoundedAmount * -1.
else return vdRoundedAmount.