Search in sources :

Example 46 with GLCodeEntity

use of org.mifos.accounts.financial.business.GLCodeEntity in project head by mifos.

the class TestObjectFactory method createOneTimeAmountFee.

public static FeeBO createOneTimeAmountFee(final String feeName, final FeeCategory feeCategory, final String feeAmnt, final FeePayment feePayment, final UserContext userContext, String categoryTypeName) {
    GLCodeEntity glCode = (GLCodeEntity) StaticHibernateUtil.getSessionTL().get(GLCodeEntity.class, TestGeneralLedgerCode.FEES);
    try {
        CategoryTypeEntity categoryType = new CategoryTypeEntity(feeCategory);
        LookUpValueEntity lookUpValue = new LookUpValueEntity();
        lookUpValue.setLookUpName(categoryTypeName);
        categoryType.setLookUpValue(lookUpValue);
        FeeBO fee = new AmountFeeBO(userContext, feeName, categoryType, new FeeFrequencyTypeEntity(FeeFrequencyType.ONETIME), glCode, TestUtils.createMoney(feeAmnt), false, new FeePaymentEntity(feePayment));
        return testObjectPersistence.createFee(fee);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : MifosRuntimeException(org.mifos.core.MifosRuntimeException) FeeFrequencyTypeEntity(org.mifos.accounts.fees.business.FeeFrequencyTypeEntity) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) CategoryTypeEntity(org.mifos.accounts.fees.business.CategoryTypeEntity) FeePaymentEntity(org.mifos.accounts.fees.business.FeePaymentEntity) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) ProductDefinitionException(org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) CustomerException(org.mifos.customers.exceptions.CustomerException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) OfficeException(org.mifos.customers.office.exceptions.OfficeException) LookUpValueEntity(org.mifos.application.master.business.LookUpValueEntity)

Example 47 with GLCodeEntity

use of org.mifos.accounts.financial.business.GLCodeEntity in project head by mifos.

the class InterestAdjustmentAccountingEntry method logTransactions_v2.

private void logTransactions_v2(LoanTrxnDetailEntity loanTrxn) throws FinancialException {
    GLCodeEntity glcodeCredit = ((LoanBO) loanTrxn.getAccount()).getLoanOffering().getInterestGLcode();
    FinancialActionTypeEntity finActionInterest = FinancialActionCache.getFinancialAction(FinancialActionConstants.INTERESTPOSTING);
    addAccountEntryDetails(loanTrxn.getInterestAmount(), finActionInterest, getGLcode(finActionInterest.getApplicableDebitCharts()), FinancialConstants.CREDIT);
    addAccountEntryDetails(loanTrxn.getInterestAmount(), finActionInterest, glcodeCredit, FinancialConstants.DEBIT);
    boolean isLastPayment = ((LoanBO) loanTrxn.getAccount()).isLastInstallment(loanTrxn.getInstallmentId());
    if (!isLastPayment) {
        return;
    }
    boolean interestWasCharged = loanTrxn.getInterestAmount().isLessThanZero();
    // log the reversed 999 account
    if (!interestWasCharged) {
        return;
    }
    Money account999 = ((LoanBO) loanTrxn.getAccount()).calculate999Account(!isLastPayment);
    Money zeroAmount = new Money(account999.getCurrency(), "0");
    // only log if amount > or < 0
    if (account999.equals(zeroAmount)) {
        return;
    }
    FinancialActionTypeEntity finActionRounding = FinancialActionCache.getFinancialAction(FinancialActionConstants.ROUNDING);
    GLCodeEntity codeToDebit = null;
    GLCodeEntity codeToCredit = null;
    if (account999.isGreaterThanZero()) {
        // this code is defined as below in chart of account
        // <GLAccount code="31401" name="Income from 999 Account" />
        codeToDebit = getGLcode(finActionRounding.getApplicableCreditCharts());
        codeToCredit = glcodeCredit;
    } else if (account999.isLessThanZero()) {
        codeToDebit = glcodeCredit;
        codeToCredit = getGLcode(finActionRounding.getApplicableDebitCharts());
        account999 = account999.negate();
    }
    addAccountEntryDetails(account999, finActionRounding, codeToDebit, FinancialConstants.DEBIT);
    addAccountEntryDetails(account999, finActionRounding, codeToCredit, FinancialConstants.CREDIT);
}
Also used : Money(org.mifos.framework.util.helpers.Money) FinancialActionTypeEntity(org.mifos.accounts.financial.business.FinancialActionTypeEntity) LoanBO(org.mifos.accounts.loan.business.LoanBO) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity)

Example 48 with GLCodeEntity

use of org.mifos.accounts.financial.business.GLCodeEntity in project head by mifos.

the class InterestAdjustmentAccountingEntry method logTransactions_v1.

private void logTransactions_v1(LoanTrxnDetailEntity loanTrxn) throws FinancialException {
    GLCodeEntity glcodeCredit = ((LoanBO) loanTrxn.getAccount()).getLoanOffering().getInterestGLcode();
    FinancialActionTypeEntity finActionInterest = FinancialActionCache.getFinancialAction(FinancialActionConstants.INTERESTPOSTING);
    addAccountEntryDetails(loanTrxn.getInterestAmount(), finActionInterest, getGLcode(finActionInterest.getApplicableDebitCharts()), FinancialConstants.CREDIT);
    addAccountEntryDetails(loanTrxn.getInterestAmount(), finActionInterest, glcodeCredit, FinancialConstants.DEBIT);
    // check if rounding is required
    Money roundedAmount = Money.round(loanTrxn.getInterestAmount(), loanTrxn.getInterestAmount().getCurrency().getRoundingAmount(), AccountingRules.getCurrencyRoundingMode());
    if (!roundedAmount.equals(loanTrxn.getInterestAmount())) {
        FinancialActionTypeEntity finActionRounding = FinancialActionCache.getFinancialAction(FinancialActionConstants.ROUNDING);
        addAccountEntryDetails(roundedAmount.subtract(loanTrxn.getInterestAmount()).negate(), finActionRounding, getGLcode(finActionInterest.getApplicableCreditCharts()), FinancialConstants.DEBIT);
        addAccountEntryDetails(roundedAmount.subtract(loanTrxn.getInterestAmount()), finActionRounding, getGLcode(finActionRounding.getApplicableCreditCharts()), FinancialConstants.CREDIT);
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) FinancialActionTypeEntity(org.mifos.accounts.financial.business.FinancialActionTypeEntity) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity)

Example 49 with GLCodeEntity

use of org.mifos.accounts.financial.business.GLCodeEntity in project head by mifos.

the class PrincipalAccountingEntry method applySpecificAccountActionEntry.

@Override
protected void applySpecificAccountActionEntry() throws FinancialException {
    LoanTrxnDetailEntity loanTrxn = (LoanTrxnDetailEntity) financialActivity.getAccountTrxn();
    GLCodeEntity glcodeCredit = ((LoanBO) loanTrxn.getAccount()).getLoanOffering().getPrincipalGLcode();
    Money principalAmountNotRounded = loanTrxn.getPrincipalAmount();
    Money amountToPost = null;
    if (((LoanBO) loanTrxn.getAccount()).isLastInstallment(loanTrxn.getInstallmentId())) {
        amountToPost = Money.round(loanTrxn.getPrincipalAmount(), AccountingRules.getFinalRoundOffMultiple(loanTrxn.getPrincipalAmount().getCurrency()), AccountingRules.getCurrencyRoundingMode());
    } else {
        amountToPost = principalAmountNotRounded;
    }
    FinancialActionTypeEntity finActionPrincipal = FinancialActionCache.getFinancialAction(FinancialActionConstants.PRINCIPALPOSTING);
    addAccountEntryDetails(amountToPost, finActionPrincipal, getGLcode(finActionPrincipal.getApplicableDebitCharts()), FinancialConstants.DEBIT);
    addAccountEntryDetails(amountToPost, finActionPrincipal, glcodeCredit, FinancialConstants.CREDIT);
    LoanBO loan = (LoanBO) loanTrxn.getAccount();
    // interest account and not to the principal account
    if (!loan.isLegacyLoan()) {
        return;
    }
    // v1 version log the 999 account to the principal account
    // check if rounding is required
    FinancialActionTypeEntity finActionRounding = FinancialActionCache.getFinancialAction(FinancialActionConstants.ROUNDING);
    if (amountToPost.getAmount().compareTo(principalAmountNotRounded.getAmount()) > 0) {
        addAccountEntryDetails(amountToPost.subtract(principalAmountNotRounded), finActionRounding, glcodeCredit, FinancialConstants.DEBIT);
        addAccountEntryDetails(amountToPost.subtract(principalAmountNotRounded), finActionRounding, getGLcode(finActionRounding.getApplicableCreditCharts()), FinancialConstants.CREDIT);
    } else if (amountToPost.getAmount().compareTo(principalAmountNotRounded.getAmount()) < 0) {
        addAccountEntryDetails(principalAmountNotRounded.subtract(amountToPost), finActionRounding, getGLcode(finActionRounding.getApplicableDebitCharts()), FinancialConstants.DEBIT);
        addAccountEntryDetails(principalAmountNotRounded.subtract(amountToPost), finActionRounding, glcodeCredit, FinancialConstants.CREDIT);
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) FinancialActionTypeEntity(org.mifos.accounts.financial.business.FinancialActionTypeEntity) LoanBO(org.mifos.accounts.loan.business.LoanBO) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) LoanTrxnDetailEntity(org.mifos.accounts.loan.business.LoanTrxnDetailEntity)

Example 50 with GLCodeEntity

use of org.mifos.accounts.financial.business.GLCodeEntity in project head by mifos.

the class PrincipalAdjustmentAccountingEntry method applySpecificAccountActionEntry.

@Override
protected void applySpecificAccountActionEntry() throws FinancialException {
    LoanTrxnDetailEntity loanTrxn = (LoanTrxnDetailEntity) financialActivity.getAccountTrxn();
    GLCodeEntity glcodeCredit = ((LoanBO) loanTrxn.getAccount()).getLoanOffering().getPrincipalGLcode();
    FinancialActionTypeEntity finActionPrincipal = FinancialActionCache.getFinancialAction(FinancialActionConstants.PRINCIPALPOSTING);
    addAccountEntryDetails(loanTrxn.getPrincipalAmount(), finActionPrincipal, getGLcode(finActionPrincipal.getApplicableDebitCharts()), FinancialConstants.CREDIT);
    addAccountEntryDetails(loanTrxn.getPrincipalAmount(), finActionPrincipal, glcodeCredit, FinancialConstants.DEBIT);
    LoanBO loan = (LoanBO) loanTrxn.getAccount();
    if (!loan.isLegacyLoan()) {
        return;
    }
    // check if rounding is required
    Money roundedAmount = Money.round(loanTrxn.getPrincipalAmount(), loanTrxn.getPrincipalAmount().getCurrency().getRoundingAmount(), AccountingRules.getCurrencyRoundingMode());
    if (!roundedAmount.equals(loanTrxn.getPrincipalAmount())) {
        FinancialActionTypeEntity finActionRounding = FinancialActionCache.getFinancialAction(FinancialActionConstants.ROUNDING);
        addAccountEntryDetails(roundedAmount.subtract(loanTrxn.getPrincipalAmount()).negate(), finActionRounding, getGLcode(finActionPrincipal.getApplicableCreditCharts()), FinancialConstants.CREDIT);
        addAccountEntryDetails(roundedAmount.subtract(loanTrxn.getPrincipalAmount()), finActionRounding, getGLcode(finActionRounding.getApplicableCreditCharts()), FinancialConstants.DEBIT);
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) FinancialActionTypeEntity(org.mifos.accounts.financial.business.FinancialActionTypeEntity) LoanBO(org.mifos.accounts.loan.business.LoanBO) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) LoanTrxnDetailEntity(org.mifos.accounts.loan.business.LoanTrxnDetailEntity)

Aggregations

GLCodeEntity (org.mifos.accounts.financial.business.GLCodeEntity)58 Money (org.mifos.framework.util.helpers.Money)21 MeetingBO (org.mifos.application.meeting.business.MeetingBO)18 ProductDefinitionException (org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException)17 Test (org.junit.Test)16 MifosRuntimeException (org.mifos.core.MifosRuntimeException)15 FinancialActionTypeEntity (org.mifos.accounts.financial.business.FinancialActionTypeEntity)14 Date (java.sql.Date)12 ArrayList (java.util.ArrayList)11 FeeBO (org.mifos.accounts.fees.business.FeeBO)11 ProductCategoryBO (org.mifos.accounts.productdefinition.business.ProductCategoryBO)11 COABO (org.mifos.accounts.financial.business.COABO)10 PersistenceException (org.mifos.framework.exceptions.PersistenceException)10 PrdApplicableMasterEntity (org.mifos.accounts.productdefinition.business.PrdApplicableMasterEntity)9 PrdStatusEntity (org.mifos.accounts.productdefinition.business.PrdStatusEntity)9 ApplicationException (org.mifos.framework.exceptions.ApplicationException)8 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)7 SystemException (org.mifos.framework.exceptions.SystemException)7 CategoryTypeEntity (org.mifos.accounts.fees.business.CategoryTypeEntity)6 FeeFrequencyTypeEntity (org.mifos.accounts.fees.business.FeeFrequencyTypeEntity)6