Class 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  
    • 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 rounding
      static boolean checkFinAccountNumber​(java.lang.String number)  
      static java.lang.String generateRandomFinNumber​(Delegator delegator, int length, boolean isId)
      Generate a random financial number
      static 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 date
      static 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 asOfDateTime
      static 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 alphanumeric
      static java.lang.String getNewFinAccountCode​(int codeLength, Delegator delegator)
      Returns a unique randomly generated account code for FinAccount.finAccountCode composed of uppercase letters and numbers
      static boolean validateFinAccount​(GenericValue finAccount)  
      static boolean validatePin​(Delegator delegator, java.lang.String finAccountId, java.lang.String pinNumber)
      Validates a FinAccount's PIN number
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
    • Constructor Detail

      • FinAccountHelper

        public FinAccountHelper()
    • 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 value
        transactions - a List of GenericValue objects of transactions
        fieldName - the field name to get the value from the transaction
        decimals - number of decimals
        rounding - 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 characters
        delegator - 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 code
        delegator - 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 id
        asOfDateTime - the validity date
        delegator - 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 id
        asOfDateTime - the validity date
        delegator - 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 delegator
        finAccountId - the financial account id
        pinNumber - 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 delegator
        length - 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)