Class FIN_Utility


  • public class FIN_Utility
    extends Object
    • Constructor Detail

      • FIN_Utility

        public FIN_Utility()
    • Method Detail

      • getOBObjectList

        public static <T extends BaseOBObjectList<T> getOBObjectList​(Class<T> t,
                                                                       String _strSelectedIds)
        Parses the string of comma separated id's to return a List object of the given class
        Type Parameters:
        T -
        Parameters:
        t - class of the OBObject the id's belong to
        _strSelectedIds - String containing a comma separated list of id's
        Returns:
        a List object containing the parsed OBObjects
      • getMapFromStringList

        public static Map<String,​String> getMapFromStringList​(String _strSelectedIds)
        Parameters:
        _strSelectedIds - Identifiers string list with the following structure: ('ID', 'ID', 'ID')
        Returns:
        Map<K,V> using the ID as key and value <ID,ID> for each identifier.
      • getShownScheduledPayments

        public static FieldProvider[] getShownScheduledPayments​(VariablesSecureApp vars,
                                                                List<FIN_PaymentSchedule> selectedScheduledPayments,
                                                                List<FIN_PaymentSchedule> filteredScheduledPayments)
        Returns a FieldProvider object containing the Scheduled Payments.
        Parameters:
        vars -
        selectedScheduledPayments - List of FIN_PaymentSchedule that need to be selected by default
        filteredScheduledPayments - List of FIN_PaymentSchedule that need to unselected by default
      • getExceptionMessage

        public static String getExceptionMessage​(Throwable t)
        Returns the cause of a trigger exception (BatchupdateException). Hibernate and JDBC will wrap the exception thrown by the trigger in another exception (the java.sql.BatchUpdateException) and this exception is sometimes wrapped again. Also the java.sql.BatchUpdateException stores the underlying trigger exception in the nextException and not in the cause property.
        Parameters:
        t - exception.
        Returns:
        the underlying trigger message.
      • getDocumentType

        public static DocumentType getDocumentType​(Organization org,
                                                   String docCategory)
        Returns the DocumentType defined for the Organization (or parent organization tree) and document category.
        Parameters:
        org - the Organization for which the Document Type is defined. The Document Type can belong to the parent organization tree of the specified Organization.
        docCategory - the document category of the Document Type.
        Returns:
        the Document Type
      • getDocumentNo

        public static String getDocumentNo​(DocumentType docType,
                                           String tableName)
        Returns the next sequence number of the Document Type defined for the Organization and document category. The current number of the sequence is also updated.
        Parameters:
        docType - Document type of the document
        tableName - the name of the table from which the sequence will be taken if the Document Type does not have any sequence associated.
        Returns:
        the next sequence number of the Document Type defined for the Organization and document category. Null if no sequence is found.
      • getDocumentNo

        public static String getDocumentNo​(DocumentType docType,
                                           String tableName,
                                           boolean updateNext)
        Returns the next sequence number of the Document Type defined for the Organization and document category.
        Parameters:
        docType - Document type of the document
        tableName - the name of the table from which the sequence will be taken if the Document Type does not have any sequence associated.
        updateNext - Flag to update the current number of the sequence
        Returns:
        the next sequence number of the Document Type defined for the Organization and document category. Null if no sequence is found.
      • getDocumentNo

        public static String getDocumentNo​(boolean updateNext,
                                           Sequence seqParam)
      • getDocumentNo

        public static String getDocumentNo​(Organization org,
                                           String docCategory,
                                           String tableName)
        Returns the next sequence number of the Document Type defined for the Organization and document category. The current number of the sequence is also updated.
        Parameters:
        org - the Organization for which the Document Type is defined. The Document Type can belong to the parent organization tree of the specified Organization.
        docCategory - the document category of the Document Type.
        tableName - the name of the table from which the sequence will be taken if the Document Type does not have any sequence associated.
        Returns:
        the next sequence number of the Document Type defined for the Organization and document category. Null if no sequence is found.
      • getDocumentNo

        public static String getDocumentNo​(Organization org,
                                           String docCategory,
                                           String tableName,
                                           boolean updateNext)
        Returns the next sequence number of the Document Type defined for the Organization and document category.
        Parameters:
        org - the Organization for which the Document Type is defined. The Document Type can belong to the parent organization tree of the specified Organization.
        docCategory - the document category of the Document Type.
        tableName - the name of the table from which the sequence will be taken if the Document Type does not have any sequence associated.
        Returns:
        the next sequence number of the Document Type defined for the Organization and document category. Null if no sequence is found.
      • getPaymentMethodList

        public static String getPaymentMethodList​(String strPaymentMethodId,
                                                  String strFinancialAccountId,
                                                  String strOrgId,
                                                  boolean isMandatory,
                                                  boolean excludePaymentMethodWithoutAccount,
                                                  boolean isInPayment)
        Gets the available Payment Methods and returns in a String the html code containing all the Payment Methods in the natural tree of the given organization filtered by the Financial Account.
        Parameters:
        strPaymentMethodId - the Payment Method id that will be selected by default in case it is present in the list.
        strFinancialAccountId - optional Financial Account id to filter the Payment Methods.
        strOrgId - the Organization id the record belongs to.
        isMandatory - boolean parameter to add an extra blank option if the drop-down is optional.
        excludePaymentMethodWithoutAccount - if the strPaymentMethodId is empty or null then depending on this parameter the list will include payment methods with no Financial Accounts associated or only show the Payment Methods that belongs to at least on Financial Account
        isInPayment - specifies the type of payment to get payment methods for. If true, will return payment methods with Payment In enabled, if false will return payment methods with Payment Out enabled.
        Returns:
        a String with the html code with the options to fill the drop-down of Payment Methods.
      • getFinancialAccountList

        public static String getFinancialAccountList​(String strPaymentMethodId,
                                                     String strFinancialAccountId,
                                                     String strOrgId,
                                                     boolean isMandatory,
                                                     String strCurrencyId,
                                                     boolean isInPayment)
        Gets the available Financial Accounts and returns in a String the html code containing all the Financial Accounts in the natural tree of the given organization filtered by the Payment Method.
        Parameters:
        strPaymentMethodId - optional Payment Method id to filter the Financial Accounts.
        strFinancialAccountId - the Financial Account id that will be selected by default in case it is present in the list.
        strOrgId - the Organization id the record belongs to.
        strCurrencyId - optional Currency id to filter the Financial Accounts.
        isInPayment - specifies the type of payment to that is being made. If true, will return accounts with payment methods that have Payment In enabled, if false will return accounts with payment methods that have Payment Out enabled.
        Returns:
        a String with the html code with the options to fill the drop-down of Financial Accounts.
      • getOptionsList

        public static <T extends BaseOBObjectString getOptionsList​(List<T> obObjectList,
                                                                     String selectedValue,
                                                                     boolean isMandatory)
        Returns a String containing the html code with the options based on the given List of BaseOBObjects
        Type Parameters:
        T - Class that extends BaseOBObject.
        Parameters:
        obObjectList - List containing the values to be included in the options.
        selectedValue - value to set as selected by default.
        isMandatory - boolean to add a blank option in the options list.
        Returns:
        a String containing the html code with the options. *
      • getOptionsList

        public static <T extends BaseOBObjectString getOptionsList​(List<T> obObjectList,
                                                                     String selectedValue,
                                                                     boolean isMandatory,
                                                                     boolean isRefList)
        Returns a String containing the html code with the options based on the given List of BaseOBObjects
        Type Parameters:
        T - Class that extends BaseOBObject.
        Parameters:
        obObjectList - List containing the values to be included in the options.
        selectedValue - value to set as selected by default.
        isMandatory - boolean to add a blank option in the options list.
        isRefList - boolean to let know if the options belong to a refList. In that case, the value must be the search key of the list item instead of it's id.
        Returns:
        a String containing the html code with the options. *
      • getOptionsListFromFieldProvider

        public static <T extends BaseOBObjectString getOptionsListFromFieldProvider​(FieldProvider[] fieldProvider,
                                                                                      String selectedValue,
                                                                                      boolean isMandatory)
      • getDaysToDue

        public static Long getDaysToDue​(Date date)
        Method used to calculate the Day still due for the payment.
        Parameters:
        date - . Due date of the payment.
        Returns:
        dayStillDue. Calculated Day Still due.
      • getDaysBetween

        public static Long getDaysBetween​(Date beginDate,
                                          Date endDate)
        Returns the amount of days between two given dates
      • isAutomaticDepositWithdrawn

        public static boolean isAutomaticDepositWithdrawn​(FIN_Payment payment)
      • isAutomaticDepositWithdrawn

        public static boolean isAutomaticDepositWithdrawn​(FIN_PaymentProposal paymentProposal)
      • getAllInstances

        public static <T extends BaseOBObjectList<T> getAllInstances​(Class<T> clazz,
                                                                       boolean setFilterClient,
                                                                       boolean setFilterOrg,
                                                                       Value... values)
        Generic OBCriteria.
        Parameters:
        clazz - Class (entity).
        setFilterClient - If true then only objects from readable clients are returned, if false then objects from all clients are returned
        setFilterOrg - If true then when querying (for example call list()) a filter on readable organizations is added to the query, if false then this is not done
        values - Value. Property, value and operator.
        Returns:
        All the records that satisfy the conditions.
      • getAllInstances

        public static <T extends BaseOBObjectList<T> getAllInstances​(Class<T> clazz,
                                                                       Value... values)
        Generic OBCriteria with filter on readable clients and organizations active.
        Parameters:
        clazz - Class (entity).
        values - Value. Property, value and operator.
        Returns:
        All the records that satisfy the conditions.
      • getOneInstance

        public static <T extends BaseOBObject> T getOneInstance​(Class<T> clazz,
                                                                Value... values)
        Generic OBCriteria.
        Parameters:
        clazz - Class (entity).
        values - Value. Property, value and operator.
        Returns:
        One record that satisfies the conditions.
      • multiCurrencyAmountToDisplay

        public static String multiCurrencyAmountToDisplay​(BigDecimal amt,
                                                          Currency currency,
                                                          BigDecimal convertedAmt,
                                                          Currency convertedCurrency)
        Convert a multi currency amount to a string for display in the UI. If amount has been converted to a different currency, then output that converted amount and currency as well
        Parameters:
        amt - Amount of payment
        currency - Currency payment was made in
        convertedAmt - Amount of payment in converted currency
        convertedCurrency - Currency payment was converted to/from
        Returns:
        String version of amount formatted for display to user
      • getConversionRate

        public static ConversionRate getConversionRate​(Currency fromCurrency,
                                                       Currency toCurrency,
                                                       Date conversionDate,
                                                       Organization org)
        Determine the conversion rate from one currency to another on a given date. Will use the spot conversion rate defined by the system for that date
        Parameters:
        fromCurrency - Currency to convert from
        toCurrency - Currency being converted to
        conversionDate - Date conversion is being performed
        Returns:
        A valid conversion rate for the parameters, or null if no conversion rate can be found
      • getConversionRateDoc

        public static ConversionRateDoc getConversionRateDoc​(Currency fromCurrency,
                                                             Currency toCurrency,
                                                             String documentId,
                                                             Entity entity)
        Determine the conversion rate from one currency to another on a given date and given documentId. Will use the spot conversion rate defined by the system for that date
        Parameters:
        fromCurrency - Currency to convert from
        toCurrency - Currency being converted to
        documentId - DocumentId to find the value in table c_conversion_rate_document
        entity - Entity type of the document
        Returns:
        A valid conversion rate for the parameters, or null if no conversion rate can be found
      • getConversionRatePrecision

        public static int getConversionRatePrecision​(VariablesSecureApp vars)
      • formatNumber

        public static String formatNumber​(BigDecimal number,
                                          String javaFormat,
                                          String _decimalSeparator,
                                          String _groupingSeparator)
        Formats a number using the given format, decimal and grouping separator.
        Parameters:
        number - Number to be formatted.
        javaFormat - Java number format pattern.
        _decimalSeparator - Symbol used as decimal separator.
        _groupingSeparator - Symbol used as grouping separator.
        Returns:
        Formatted string.
      • formatNumber

        public static String formatNumber​(BigDecimal number)
        Formats a number using the euroEdition (see Format.xml) format.
        Parameters:
        number - Number to be formatted.
        Returns:
        Formatted string.
      • formatNumber

        public static String formatNumber​(BigDecimal number,
                                          String formatId,
                                          String qualifier)
        Formats a number using the provided formatId and qualifier (see Format.xml) format.
        Parameters:
        number - Number to be formatted.
        formatId - euro, price, qty, etc.
        qualifier - Edition, Relation, etc,
        Returns:
        Formatted string.
      • getDesiredDocumentNo

        public static String getDesiredDocumentNo​(Organization organization,
                                                  Invoice invoice)
        Returns either the Invoice's Document Number or the Invoice's Supplier Reference based on the Organization's configuration. In case the Supplier Reference is empty, the invoice's document number is returned
        Parameters:
        organization - to get its configuration. In case no configuration is available, the invoice's document number is returned
      • isPaymentConfirmed

        public static boolean isPaymentConfirmed​(String status,
                                                 FIN_PaymentScheduleDetail psd)
        Returns if given payment status and related payment schedule detail belong to a confirmed payment
      • getListPaymentConfirmed

        public static List<String> getListPaymentConfirmed()
        Returns a list confirmed Payment Status
      • getListPaymentNotConfirmed

        public static List<String> getListPaymentNotConfirmed()
        Returns a list not confirmed Payment Status
      • getLegalEntityOrg

        public static Organization getLegalEntityOrg​(Organization org)
        Returns the legal entity of the given organization
        Parameters:
        org - organization to get its legal entity
        Returns:
        legal entity (with or without accounting) organization or null if not found
      • isPeriodOpen

        public static boolean isPeriodOpen​(String client,
                                           String documentType,
                                           String org,
                                           String dateAcct)
        Return true if the period is open for a client, document type, organization and accounting date
        Parameters:
        client - the client for which it wants to know if the period is open
        documentType - It is the docbasetype from the document type
        org - the Organization for which it wants to know if the period is open
        dateAcct - The accounting date from the document
        Returns:
        boolean
      • periodControlOpened

        public static boolean periodControlOpened​(String tableName,
                                                  String recordId,
                                                  String idColumnName,
                                                  String orgType)
      • isBlockedBusinessPartner

        public static boolean isBlockedBusinessPartner​(String strBPartnerId,
                                                       boolean issotrx,
                                                       int docType)
        Returns true if the Business Partner is blocked for the document type selected.
        Parameters:
        strBPartnerId - . Business Partner Id.
        issotrx - . True if Sales, False if Purchase.
        docType - 1: Order. 2: Goods Receipt / Shipment. 3: Invoice. 4: Payment.
      • getOrderedPaymentDetailList

        public static List<String> getOrderedPaymentDetailList​(String paymentId)
        Returns Payment Details from a Payment ordered by Invoice and Order
      • isReversePayment

        public static boolean isReversePayment​(FIN_Payment payment)
        Returns true if the payment is a reverse payment not a reversed one.
      • invoicePaymentStatus

        public static String invoicePaymentStatus​(FIN_Payment payment)
        Returns the invoice payment status value configured in the payment method in the financial account for a payment
      • invoicePaymentStatus

        public static String invoicePaymentStatus​(FIN_PaymentMethod paymentMethod,
                                                  FIN_FinancialAccount financialAccount,
                                                  boolean isReceipt)
        Returns the invoice payment status value configured in the payment method in the financial account for a payment
      • updatePaymentAmounts

        public static void updatePaymentAmounts​(FIN_PaymentScheduleDetail psd)
        This function should only be called when it should update the payment amounts
      • updateBusinessPartnerCredit

        public static void updateBusinessPartnerCredit​(FIN_Payment payment)
      • seqnumberpaymentstatus

        public static int seqnumberpaymentstatus​(String status)
        Returns the sequence number of payment status in reference list
      • restorePaidAmounts

        public static void restorePaidAmounts​(FIN_PaymentScheduleDetail paymentScheduleDetail)
        This function should only be called when it should update the payment amounts
      • getFinancialAccountPaymentMethod

        public static FinAccPaymentMethod getFinancialAccountPaymentMethod​(String paymentMethodId,
                                                                           String financialAccountId,
                                                                           boolean issotrx,
                                                                           String currencyId)
      • getFinancialAccountPaymentMethod

        public static FinAccPaymentMethod getFinancialAccountPaymentMethod​(String paymentMethodId,
                                                                           String financialAccountId,
                                                                           boolean issotrx,
                                                                           String currencyId,
                                                                           String orgId)
        Get an active FinAccPaymentMethod related to paymentMethodId FIN_PaymentMethod and financialAccountId FIN_FinancialAccount, if exists. If paymentMethodId is null it will retrieve any FinAccPaymentMethod related to paymentMethodId FIN_PaymentMethod ordered by default field. FinAccPaymentMethod must have pay in/out active and must be compatible with currencyId Currency if currencyId is not null.
      • getFinAccTransactionDescription

        public static String getFinAccTransactionDescription​(String description,
                                                             String removeDescription,
                                                             String appendDescription)
        Appends existing Financial Account Transaction description with either GL Item Description or Payment description in a new line