Search in sources :

Example 51 with GLCodeEntity

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

the class RescheduleAccountingEntry method applySpecificAccountActionEntry.

@Override
protected void applySpecificAccountActionEntry() throws FinancialException {
    LoanTrxnDetailEntity loanTrxn = (LoanTrxnDetailEntity) financialActivity.getAccountTrxn();
    FinancialActionTypeEntity finActionReschedule = FinancialActionCache.getFinancialAction(FinancialActionConstants.RESCHEDULE);
    addAccountEntryDetails(loanTrxn.getPrincipalAmount(), finActionReschedule, getGLcode(finActionReschedule.getApplicableDebitCharts()), FinancialConstants.DEBIT);
    GLCodeEntity glcodeCredit = ((LoanBO) loanTrxn.getAccount()).getLoanOffering().getPrincipalGLcode();
    addAccountEntryDetails(loanTrxn.getPrincipalAmount(), finActionReschedule, glcodeCredit, FinancialConstants.CREDIT);
// no 999 account entries are made for close-rescheduled loans because
// if some payments have already been made
// the 999 account amount is probably very small and is ignored in 1.1
// release. In the future if we want to
// calculate the 999 amount in this case we need to store the raw amount
// for each installment.
}
Also used : FinancialActionTypeEntity(org.mifos.accounts.financial.business.FinancialActionTypeEntity) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) LoanTrxnDetailEntity(org.mifos.accounts.loan.business.LoanTrxnDetailEntity)

Example 52 with GLCodeEntity

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

the class WriteOffAccountingEntry method applySpecificAccountActionEntry.

@Override
protected void applySpecificAccountActionEntry() throws FinancialException {
    LoanTrxnDetailEntity loanTrxn = (LoanTrxnDetailEntity) financialActivity.getAccountTrxn();
    FinancialActionTypeEntity finActionWriteOff = FinancialActionCache.getFinancialAction(FinancialActionConstants.WRITEOFF);
    addAccountEntryDetails(loanTrxn.getPrincipalAmount(), finActionWriteOff, getGLcode(finActionWriteOff.getApplicableDebitCharts()), FinancialConstants.DEBIT);
    GLCodeEntity glcodeCredit = ((LoanBO) loanTrxn.getAccount()).getLoanOffering().getPrincipalGLcode();
    addAccountEntryDetails(loanTrxn.getPrincipalAmount(), finActionWriteOff, glcodeCredit, FinancialConstants.CREDIT);
// no 999 account entries are made for write-off loans because if some
// payments have already been made
// the 999 account amount is probably very small and is ignored in 1.1
// release. In the future if we want to
// calculate the 999 amount in this case we need to store the raw amount
// for each installment.
}
Also used : FinancialActionTypeEntity(org.mifos.accounts.financial.business.FinancialActionTypeEntity) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) LoanTrxnDetailEntity(org.mifos.accounts.loan.business.LoanTrxnDetailEntity)

Example 53 with GLCodeEntity

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

the class LoanProductAssembler method fromDto.

public LoanOfferingBO fromDto(MifosUser user, LoanProductRequest loanProductRequest) {
    try {
        Integer userId = user.getUserId();
        ProductDetailsDto productDetails = loanProductRequest.getProductDetails();
        String name = productDetails.getName();
        String shortName = productDetails.getShortName();
        String description = productDetails.getDescription();
        Integer category = productDetails.getCategory();
        boolean loanCycleCounter = loanProductRequest.isIncludeInLoanCycleCounter();
        boolean waiverInterest = loanProductRequest.isWaiverInterest();
        PrdStatusEntity activeStatus = new PrdOfferingPersistence().getPrdStatus(PrdStatus.LOAN_ACTIVE);
        PrdStatusEntity inActiveStatus = new PrdOfferingPersistence().getPrdStatus(PrdStatus.LOAN_INACTIVE);
        PrdStatusEntity selectedStatus = activeStatus;
        if (productDetails.getStatus() != null && inActiveStatus.getOfferingStatusId().equals(productDetails.getStatus().shortValue())) {
            selectedStatus = inActiveStatus;
        }
        MifosCurrency currency = Money.getDefaultCurrency();
        if (AccountingRules.isMultiCurrencyEnabled()) {
            currency = AccountingRules.getCurrencyByCurrencyId(loanProductRequest.getCurrencyId().shortValue());
        }
        ProductCategoryBO productCategory = this.loanProductDao.findActiveProductCategoryById(category);
        DateTime startDate = productDetails.getStartDate();
        DateTime endDate = productDetails.getEndDate();
        ApplicableTo applicableTo = ApplicableTo.fromInt(productDetails.getApplicableFor());
        PrdApplicableMasterEntity applicableToEntity = this.loanProductDao.findApplicableProductType(applicableTo);
        LoanAmountCalculation loanAmountCalculation = this.loanProductCaluclationTypeAssembler.assembleLoanAmountCalculationFromDto(loanProductRequest.getLoanAmountDetails());
        InterestType interestType = InterestType.fromInt(loanProductRequest.getInterestRateType());
        Double minRate = loanProductRequest.getInterestRateRange().getMin().doubleValue();
        Double maxRate = loanProductRequest.getInterestRateRange().getMax().doubleValue();
        Double defaultRate = loanProductRequest.getInterestRateRange().getTheDefault().doubleValue();
        InterestTypesEntity interestTypeEntity = this.loanProductDao.findInterestType(interestType);
        RecurrenceType recurrence = RecurrenceType.fromInt(loanProductRequest.getRepaymentDetails().getFrequencyType().shortValue());
        Integer recurEvery = loanProductRequest.getRepaymentDetails().getRecurs();
        LoanInstallmentCalculation loanInstallmentCalculation = this.loanProductCaluclationTypeAssembler.assembleLoanInstallmentCalculationFromDto(loanProductRequest.getRepaymentDetails().getInstallmentCalculationDetails());
        GraceType gracePeriodType = GraceType.fromInt(loanProductRequest.getRepaymentDetails().getGracePeriodType());
        GracePeriodTypeEntity gracePeriodTypeEntity = this.loanProductDao.findGracePeriodType(gracePeriodType);
        Integer gracePeriodDuration = loanProductRequest.getRepaymentDetails().getGracePeriodDuration();
        List<FeeBO> applicableFees = new ArrayList<FeeBO>();
        List<Integer> applicableFeeIds = loanProductRequest.getApplicableFees();
        for (Integer feeId : applicableFeeIds) {
            FeeBO fee = ApplicationContextProvider.getBean(FeeDao.class).findById(feeId.shortValue());
            applicableFees.add(fee);
        }
        List<FundBO> applicableFunds = new ArrayList<FundBO>();
        List<Integer> applicableFundIds = loanProductRequest.getAccountDetails().getApplicableFunds();
        for (Integer fundId : applicableFundIds) {
            FundBO fund = this.fundDao.findById(fundId.shortValue());
            applicableFunds.add(fund);
        }
        List<PenaltyBO> applicablePenalties = new ArrayList<PenaltyBO>();
        List<Integer> applicablePenaltyIds = loanProductRequest.getApplicablePenalties();
        for (Integer penaltyId : applicablePenaltyIds) {
            PenaltyBO penalty = this.penaltyDao.findPenaltyById(penaltyId);
            applicablePenalties.add(penalty);
        }
        GLCodeEntity interestGlCode = this.generalLedgerDao.findGlCodeById(loanProductRequest.getAccountDetails().getInterestGlCodeId().shortValue());
        GLCodeEntity principalGlCode = this.generalLedgerDao.findGlCodeById(loanProductRequest.getAccountDetails().getPrincipalClCodeId().shortValue());
        String globalProductId = generateProductGlobalNum(user);
        LoanOfferingBO loanProduct = LoanOfferingBO.createNew(userId, globalProductId, name, shortName, description, productCategory, startDate, endDate, applicableToEntity, currency, interestTypeEntity, minRate, maxRate, defaultRate, recurrence, recurEvery, interestGlCode, principalGlCode, activeStatus, inActiveStatus, gracePeriodTypeEntity, gracePeriodDuration, waiverInterest, loanCycleCounter, loanAmountCalculation, loanInstallmentCalculation, applicableFees, applicableFunds, applicablePenalties);
        loanProduct.updateStatus(selectedStatus);
        return loanProduct;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : InterestTypesEntity(org.mifos.application.master.business.InterestTypesEntity) PrdOfferingPersistence(org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence) LoanInstallmentCalculation(org.mifos.accounts.productdefinition.LoanInstallmentCalculation) ArrayList(java.util.ArrayList) ProductDetailsDto(org.mifos.dto.domain.ProductDetailsDto) DateTime(org.joda.time.DateTime) GraceType(org.mifos.accounts.productdefinition.util.helpers.GraceType) GracePeriodTypeEntity(org.mifos.accounts.productdefinition.business.GracePeriodTypeEntity) MifosCurrency(org.mifos.application.master.business.MifosCurrency) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) ProductCategoryBO(org.mifos.accounts.productdefinition.business.ProductCategoryBO) FundBO(org.mifos.accounts.fund.business.FundBO) RecurrenceType(org.mifos.application.meeting.util.helpers.RecurrenceType) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) LoanAmountCalculation(org.mifos.accounts.productdefinition.LoanAmountCalculation) ApplicableTo(org.mifos.accounts.productdefinition.util.helpers.ApplicableTo) InterestType(org.mifos.accounts.productdefinition.util.helpers.InterestType) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) FeeBO(org.mifos.accounts.fees.business.FeeBO) PrdStatusEntity(org.mifos.accounts.productdefinition.business.PrdStatusEntity) PrdApplicableMasterEntity(org.mifos.accounts.productdefinition.business.PrdApplicableMasterEntity) FeeDao(org.mifos.accounts.fees.persistence.FeeDao) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 54 with GLCodeEntity

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

the class LegacyAccountDao method addGeneralLedgerAccount.

/**
     * @see #addGeneralLedgerAccount(String, String, String, GLCategoryType)
     */
public COABO addGeneralLedgerAccount(String name, String glcode, Short parent_id, GLCategoryType categoryType) {
    Short id = getAccountIdFromGlCode(glcode);
    if (id != null) {
        throw new MifosRuntimeException("An account already exists with glcode: " + glcode + ". id was " + id);
    }
    GLCodeEntity glCodeEntity = new GLCodeEntity(null, glcode);
    try {
        createOrUpdate(glCodeEntity);
        COABO newAccount = new COABO(name, glCodeEntity);
        newAccount.setCategoryType(categoryType);
        createOrUpdate(newAccount);
        COABO parentCOA;
        COAHierarchyEntity coaHierarchyEntity = null;
        if (null == parent_id) {
            coaHierarchyEntity = new COAHierarchyEntity(newAccount, null);
        } else {
            parentCOA = (COABO) StaticHibernateUtil.getSessionTL().load(COABO.class, parent_id.shortValue());
            coaHierarchyEntity = new COAHierarchyEntity(newAccount, parentCOA.getCoaHierarchy());
        }
        createOrUpdate(coaHierarchyEntity);
        newAccount.setCoaHierarchy(coaHierarchyEntity);
        StaticHibernateUtil.commitTransaction();
        return newAccount;
    } catch (PersistenceException e) {
        throw new RuntimeException(e);
    }
}
Also used : MifosRuntimeException(org.mifos.core.MifosRuntimeException) COABO(org.mifos.accounts.financial.business.COABO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) COAHierarchyEntity(org.mifos.accounts.financial.business.COAHierarchyEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 55 with GLCodeEntity

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

the class SavingsOfferingBOIntegrationTest method testBuildSavingsOfferingWithStartDateEqualToCurrentDate.

@Test
public void testBuildSavingsOfferingWithStartDateEqualToCurrentDate() throws SystemException, ProductDefinitionException {
    PrdApplicableMasterEntity prdApplicableMaster = new PrdApplicableMasterEntity(ApplicableTo.CLIENTS);
    SavingsTypeEntity savingsType = new SavingsTypeEntity(SavingsType.MANDATORY);
    InterestCalcTypeEntity intCalType = new InterestCalcTypeEntity(InterestCalcType.AVERAGE_BALANCE);
    MeetingBO intCalcMeeting = getMeeting();
    MeetingBO intPostMeeting = getMeeting();
    GLCodeEntity depglCodeEntity = (GLCodeEntity) StaticHibernateUtil.getSessionTL().get(GLCodeEntity.class, (short) 7);
    GLCodeEntity intglCodeEntity = (GLCodeEntity) StaticHibernateUtil.getSessionTL().get(GLCodeEntity.class, (short) 7);
    ProductCategoryBO productCategory = (ProductCategoryBO) TestObjectFactory.getObject(ProductCategoryBO.class, (short) 2);
    Date startDate = offSetCurrentDate(0);
    SavingsOfferingBO product = new SavingsOfferingBO(TestUtils.makeUser(), "Savings Offering", "Savi", productCategory, prdApplicableMaster, startDate, savingsType, intCalType, intCalcMeeting, intPostMeeting, new Money(getCurrency(), "10"), 10.0, depglCodeEntity, intglCodeEntity);
    Assert.assertNotNull(product.getGlobalPrdOfferingNum());
    Assert.assertEquals(PrdStatus.SAVINGS_ACTIVE, product.getStatus());
}
Also used : Money(org.mifos.framework.util.helpers.Money) MeetingBO(org.mifos.application.meeting.business.MeetingBO) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) Date(java.sql.Date) Test(org.junit.Test)

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