Class FinAccountHelper
- java.lang.Object
-
- org.apache.ofbiz.order.finaccount.FinAccountHelper
-
public class FinAccountHelper extends java.lang.Object
A package of methods for improving efficiency of financial accounts services
-
-
Field Summary
Fields Modifier and Type Field Description static int
decimals
A word on precision: since we're just adding and subtracting, the interim figures should have one more decimal place of precision than the final numbers.static java.lang.String
giftCertFinAccountTypeId
static java.lang.String
module
static java.math.RoundingMode
rounding
static java.math.BigDecimal
ZERO
-
Constructor Summary
Constructors Constructor Description FinAccountHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.math.BigDecimal
addFirstEntryAmount(java.math.BigDecimal initialValue, java.util.List<GenericValue> transactions, java.lang.String fieldName, int decimals, java.math.RoundingMode rounding)
A convenience method which adds transactions.get(0).get(fieldName) to initialValue, all done in BigDecimal to decimals and roundingstatic boolean
checkFinAccountNumber(java.lang.String number)
static java.lang.String
generateRandomFinNumber(Delegator delegator, int length, boolean isId)
Generate a random financial numberstatic java.math.BigDecimal
getAvailableBalance(java.lang.String finAccountId, java.sql.Timestamp asOfDateTime, Delegator delegator)
Returns the net balance (see above) minus the sum of all authorization amounts which are not expired and were authorized by the as of datestatic java.math.BigDecimal
getBalance(java.lang.String finAccountId, java.sql.Timestamp asOfDateTime, Delegator delegator)
Sum of all DEPOSIT and ADJUSTMENT transactions minus all WITHDRAWAL transactions whose transactionDate is before asOfDateTimestatic GenericValue
getFinAccountFromCode(java.lang.String finAccountCode, Delegator delegator)
Gets the first (and should be only) FinAccount based on finAccountCode, which will be cleaned up to be only uppercase and alphanumericstatic java.lang.String
getNewFinAccountCode(int codeLength, Delegator delegator)
Returns a unique randomly generated account code for FinAccount.finAccountCode composed of uppercase letters and numbersstatic boolean
validateFinAccount(GenericValue finAccount)
static boolean
validatePin(Delegator delegator, java.lang.String finAccountId, java.lang.String pinNumber)
Validates a FinAccount's PIN number
-
-
-
Field Detail
-
module
public static final java.lang.String module
-
decimals
public static final int decimals
A word on precision: since we're just adding and subtracting, the interim figures should have one more decimal place of precision than the final numbers.
-
rounding
public static final java.math.RoundingMode rounding
-
ZERO
public static final java.math.BigDecimal ZERO
-
giftCertFinAccountTypeId
public static final java.lang.String giftCertFinAccountTypeId
- See Also:
- Constant Field Values
-
-
Method Detail
-
addFirstEntryAmount
public static java.math.BigDecimal addFirstEntryAmount(java.math.BigDecimal initialValue, java.util.List<GenericValue> transactions, java.lang.String fieldName, int decimals, java.math.RoundingMode rounding) throws GenericEntityException
A convenience method which adds transactions.get(0).get(fieldName) to initialValue, all done in BigDecimal to decimals and rounding- Parameters:
initialValue
- the initial valuetransactions
- a List of GenericValue objects of transactionsfieldName
- the field name to get the value from the transactiondecimals
- number of decimalsrounding
- how to rounding- Returns:
- the new value in a BigDecimal field
- Throws:
GenericEntityException
-
getNewFinAccountCode
public static java.lang.String getNewFinAccountCode(int codeLength, Delegator delegator) throws GenericEntityException
Returns a unique randomly generated account code for FinAccount.finAccountCode composed of uppercase letters and numbers- Parameters:
codeLength
- length of code in number of charactersdelegator
- the delegator- Returns:
- returns a unique randomly generated account code for FinAccount.finAccountCode composed of uppercase letters and numbers
- Throws:
GenericEntityException
-
getFinAccountFromCode
public static GenericValue getFinAccountFromCode(java.lang.String finAccountCode, Delegator delegator) throws GenericEntityException
Gets the first (and should be only) FinAccount based on finAccountCode, which will be cleaned up to be only uppercase and alphanumeric- Parameters:
finAccountCode
- the financial account codedelegator
- the delegator- Returns:
- gets the first financial account by code
- Throws:
GenericEntityException
-
getBalance
public static java.math.BigDecimal getBalance(java.lang.String finAccountId, java.sql.Timestamp asOfDateTime, Delegator delegator) throws GenericEntityException
Sum of all DEPOSIT and ADJUSTMENT transactions minus all WITHDRAWAL transactions whose transactionDate is before asOfDateTime- Parameters:
finAccountId
- the financial account idasOfDateTime
- the validity datedelegator
- the delegator- Returns:
- returns the sum of all DEPOSIT and ADJUSTMENT transactions minus all WITHDRAWAL transactions
- Throws:
GenericEntityException
-
getAvailableBalance
public static java.math.BigDecimal getAvailableBalance(java.lang.String finAccountId, java.sql.Timestamp asOfDateTime, Delegator delegator) throws GenericEntityException
Returns the net balance (see above) minus the sum of all authorization amounts which are not expired and were authorized by the as of date- Parameters:
finAccountId
- the financial account idasOfDateTime
- the validity datedelegator
- the delegator- Returns:
- returns the net balance (see above) minus the sum of all authorization amounts which are not expired
- Throws:
GenericEntityException
-
validateFinAccount
public static boolean validateFinAccount(GenericValue finAccount)
-
validatePin
public static boolean validatePin(Delegator delegator, java.lang.String finAccountId, java.lang.String pinNumber)
Validates a FinAccount's PIN number- Parameters:
delegator
- the delegatorfinAccountId
- the financial account idpinNumber
- a pin number- Returns:
- true if the bin is valid
-
generateRandomFinNumber
public static java.lang.String generateRandomFinNumber(Delegator delegator, int length, boolean isId) throws GenericEntityException
Generate a random financial number- Parameters:
delegator
- the delegatorlength
- length of the number to generate (up to 19 digits)isId
- to be used as an ID (will check the DB to make sure it doesn't already exist)- Returns:
- Generated number
- Throws:
GenericEntityException
-
checkFinAccountNumber
public static boolean checkFinAccountNumber(java.lang.String number)
-
-