Search in sources :

Example 91 with LoanOfferingBO

use of org.mifos.accounts.productdefinition.business.LoanOfferingBO in project head by mifos.

the class LoanTrxnDetailEntityIntegrationTest method testSuccessSetRunningBalance.

@Test
public void testSuccessSetRunningBalance() throws Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getTypicalMeeting());
    center = TestObjectFactory.createWeeklyFeeCenter("Center_Active", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
    Date sampleDate = new Date(System.currentTimeMillis());
    LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering(sampleDate, meeting);
    account = TestObjectFactory.createLoanAccount("42423142341", group, AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, sampleDate, loanOffering);
    StaticHibernateUtil.flushSession();
    account = legacyAccountDao.getAccount(account.getAccountId());
    Assert.assertEquals(((LoanBO) account).getLoanOffering().getPrdOfferingName(), "Loan");
    List<AccountActionDateEntity> accountActionsToBeUpdated = new ArrayList<AccountActionDateEntity>();
    accountActionsToBeUpdated.add(account.getAccountActionDates().iterator().next());
    PaymentData paymentData = TestObjectFactory.getLoanAccountPaymentData(accountActionsToBeUpdated, TestUtils.createMoney("700.0"), null, account.getPersonnel(), "423423", Short.valueOf("1"), sampleDate, sampleDate);
    IntegrationTestObjectMother.applyAccountPayment(account, paymentData);
    Assert.assertEquals(1, account.getAccountPayments().size());
    //        AccountPaymentEntity payment = account.getAccountPayments().iterator().next();
    //        Assert.assertEquals(4, payment.getAccountTrxns().size());
    // Should we assert something about each of those transactions?
    LoanSummaryEntity loanSummaryEntity = ((LoanBO) account).getLoanSummary();
    Assert.assertEquals(loanSummaryEntity.getOriginalPrincipal().subtract(loanSummaryEntity.getPrincipalPaid()), ((LoanBO) account).getLoanActivityDetails().iterator().next().getPrincipalOutstanding());
}
Also used : PaymentData(org.mifos.accounts.util.helpers.PaymentData) MeetingBO(org.mifos.application.meeting.business.MeetingBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) ArrayList(java.util.ArrayList) Date(java.util.Date) LoanSummaryEntity(org.mifos.accounts.loan.business.LoanSummaryEntity) Test(org.junit.Test)

Example 92 with LoanOfferingBO

use of org.mifos.accounts.productdefinition.business.LoanOfferingBO in project head by mifos.

the class AdminServiceFacadeWebTier method updateLoanProduct.

@Override
public PrdOfferingDto updateLoanProduct(LoanProductRequest loanProductRequest) {
    LoanOfferingBO loanProductForUpdate = this.loanProductDao.findById(loanProductRequest.getProductDetails().getId());
    // enforced by integrity constraints on table also.
    if (loanProductForUpdate.isDifferentName(loanProductRequest.getProductDetails().getName())) {
        this.savingsProductDao.validateProductWithSameNameDoesNotExist(loanProductRequest.getProductDetails().getName());
    }
    if (loanProductForUpdate.isDifferentShortName(loanProductRequest.getProductDetails().getShortName())) {
        this.savingsProductDao.validateProductWithSameShortNameDoesNotExist(loanProductRequest.getProductDetails().getShortName());
    }
    // domain rule validation - put on domain entity
    if (loanProductForUpdate.isDifferentStartDate(loanProductRequest.getProductDetails().getStartDate())) {
        validateStartDateIsNotBeforeToday(loanProductRequest.getProductDetails().getStartDate());
        validateStartDateIsNotOverOneYearFromToday(loanProductRequest.getProductDetails().getStartDate());
        validateEndDateIsPastStartDate(loanProductRequest.getProductDetails().getStartDate(), loanProductRequest.getProductDetails().getEndDate());
    }
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    LoanOfferingBO newLoanProductDetails = this.loanProductAssembler.fromDto(user, loanProductRequest);
    loanProductForUpdate.updateDetails(userContext);
    HibernateTransactionHelper transactionHelper = new HibernateTransactionHelperForStaticHibernateUtil();
    try {
        transactionHelper.startTransaction();
        transactionHelper.beginAuditLoggingFor(loanProductForUpdate);
        loanProductForUpdate.updateDetailsOfProductNotInUse(newLoanProductDetails.getPrdOfferingName(), newLoanProductDetails.getPrdOfferingShortName(), newLoanProductDetails.getDescription(), newLoanProductDetails.getPrdCategory(), newLoanProductDetails.getStartDate(), newLoanProductDetails.getEndDate(), newLoanProductDetails.getPrdApplicableMaster(), newLoanProductDetails.getPrdStatus());
        loanProductForUpdate.update(newLoanProductDetails.isIncludeInLoanCounter(), newLoanProductDetails.isInterestWaived());
        if (newLoanProductDetails.isLoanAmountTypeSameForAllLoan()) {
            loanProductForUpdate.updateLoanAmountDetails(newLoanProductDetails.getEligibleLoanAmountSameForAllLoan());
        } else if (newLoanProductDetails.isLoanAmountTypeAsOfLastLoanAmount()) {
            loanProductForUpdate.updateLoanAmountByLastLoanDetails(newLoanProductDetails.getLoanAmountFromLastLoan());
        } else if (newLoanProductDetails.isLoanAmountTypeFromLoanCycle()) {
            loanProductForUpdate.updateLoanAmountLoanCycleDetails(newLoanProductDetails.getLoanAmountFromLoanCycle());
        }
        loanProductForUpdate.updateInterestRateDetails(newLoanProductDetails.getMinInterestRate(), newLoanProductDetails.getMaxInterestRate(), newLoanProductDetails.getDefInterestRate());
        PrdOfferingMeetingEntity entity = newLoanProductDetails.getLoanOfferingMeeting();
        MeetingBO meeting = new MeetingBO(entity.getMeeting().getRecurrenceType(), entity.getMeeting().getRecurAfter(), entity.getMeeting().getStartDate(), MeetingType.LOAN_INSTALLMENT);
        loanProductForUpdate.updateRepaymentDetails(meeting, newLoanProductDetails.getGracePeriodType(), newLoanProductDetails.getGracePeriodDuration());
        if (newLoanProductDetails.isNoOfInstallTypeSameForAllLoan()) {
            loanProductForUpdate.updateInstallmentDetails(newLoanProductDetails.getNoOfInstallSameForAllLoan());
        } else if (newLoanProductDetails.isNoOfInstallTypeFromLastLoan()) {
            loanProductForUpdate.updateInstallmentByLastLoanDetails(newLoanProductDetails.getNoOfInstallFromLastLoan());
        } else if (newLoanProductDetails.isNoOfInstallTypeFromLoanCycle()) {
            loanProductForUpdate.updateInstallmentLoanCycleDetails(newLoanProductDetails.getNoOfInstallFromLoanCycle());
        }
        loanProductForUpdate.updateFees(newLoanProductDetails.getLoanOfferingFees());
        loanProductForUpdate.updateFunds(newLoanProductDetails.getLoanOfferingFunds());
        loanProductForUpdate.updatePenalties(newLoanProductDetails.getLoanOfferingPenalties());
        this.loanProductDao.save(loanProductForUpdate);
        transactionHelper.commitTransaction();
        return loanProductForUpdate.toDto();
    } catch (Exception e) {
        transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        transactionHelper.closeSession();
    }
}
Also used : HibernateTransactionHelper(org.mifos.framework.hibernate.helper.HibernateTransactionHelper) PrdOfferingMeetingEntity(org.mifos.accounts.productdefinition.business.PrdOfferingMeetingEntity) HibernateTransactionHelperForStaticHibernateUtil(org.mifos.framework.hibernate.helper.HibernateTransactionHelperForStaticHibernateUtil) UserContext(org.mifos.security.util.UserContext) MeetingBO(org.mifos.application.meeting.business.MeetingBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 93 with LoanOfferingBO

use of org.mifos.accounts.productdefinition.business.LoanOfferingBO in project head by mifos.

the class XlsLoansAccountImporter method validateProductName.

private LoanOfferingBO validateProductName(String productName, CustomerBO customerBO, HSSFRow row, int currentCell) throws XlsParsingException {
    // check if blank
    if (StringUtils.isBlank(productName)) {
        throw new XlsParsingException(getCellError(XlsMessageConstants.MISSING_PRODUCT_NAME, row, currentCell, null));
    }
    // check if product is definied
    List<LoanOfferingBO> products = loanProductDao.findActiveLoanProductsApplicableToCustomerLevel(customerBO.getCustomerLevel());
    LoanOfferingBO foundProduct = null;
    for (LoanOfferingBO loanOfferingBO : products) {
        if (loanOfferingBO.getPrdOfferingName().equals(productName) && loanOfferingBO.isActive()) {
            foundProduct = loanOfferingBO;
            break;
        }
    }
    if (foundProduct == null) {
        List<Object> params = new ArrayList<Object>();
        params.add(productName);
        throw new XlsParsingException(getCellError(XlsMessageConstants.PRODUCT_NOT_FOUND, row, currentCell, params));
    }
    // check if installments date is synchronized with meetings
    boolean meetingOk = (foundProduct.getLoanOfferingMeeting().getMeeting().hasSameRecurrenceAs(customerBO.getCustomerMeetingValue()) || configurationPersistence.isRepaymentIndepOfMeetingEnabled());
    if (!meetingOk) {
        throw new XlsParsingException(getCellError(XlsMessageConstants.DIFFERENT_MEETING_FREQUENCY, row, currentCell, null));
    }
    return foundProduct;
}
Also used : LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) ArrayList(java.util.ArrayList)

Example 94 with LoanOfferingBO

use of org.mifos.accounts.productdefinition.business.LoanOfferingBO in project head by mifos.

the class QGFlowsServiceImpl method applyToAllLoanProducts.

@Override
public void applyToAllLoanProducts(Integer questionGroupId) throws SystemException {
    LoanPrdBusinessService loanPrdBusinessService = new LoanPrdBusinessService();
    try {
        List<LoanOfferingBO> offerings = loanPrdBusinessService.getAllLoanOfferings((short) 1);
        if (offerings.size() > 0) {
            QuestionGroupReference questionGroupReference = new QuestionGroupReference();
            questionGroupReference.setQuestionGroupId(questionGroupId);
            for (LoanOfferingBO offering : offerings) {
                offering.getQuestionGroups().add(questionGroupReference);
                offering.save();
            }
            StaticHibernateUtil.commitTransaction();
        }
    } catch (ServiceException e) {
        throw new SystemException(e);
    } catch (ProductDefinitionException e) {
        throw new SystemException(e);
    }
}
Also used : QuestionGroupReference(org.mifos.accounts.productdefinition.business.QuestionGroupReference) ServiceException(org.mifos.framework.exceptions.ServiceException) SystemException(org.mifos.framework.exceptions.SystemException) ProductDefinitionException(org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException) LoanPrdBusinessService(org.mifos.accounts.productdefinition.business.service.LoanPrdBusinessService) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO)

Example 95 with LoanOfferingBO

use of org.mifos.accounts.productdefinition.business.LoanOfferingBO in project head by mifos.

the class LoanDisbursementActionStrutsTest method getLoanAccount.

private LoanBO getLoanAccount(AccountState state, Date startDate, int disbursalType) {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getTypicalMeeting());
    center = TestObjectFactory.createWeeklyFeeCenter("Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
    LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering(startDate, meeting);
    return TestObjectFactory.createLoanAccountWithDisbursement("99999999999", group, state, startDate, loanOffering, disbursalType);
}
Also used : MeetingBO(org.mifos.application.meeting.business.MeetingBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO)

Aggregations

LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)135 MeetingBO (org.mifos.application.meeting.business.MeetingBO)44 Date (java.util.Date)37 Test (org.junit.Test)37 ArrayList (java.util.ArrayList)26 Date (java.sql.Date)21 LoanBO (org.mifos.accounts.loan.business.LoanBO)18 LocalDate (org.joda.time.LocalDate)17 CustomerBO (org.mifos.customers.business.CustomerBO)12 LoanProductBuilder (org.mifos.domain.builders.LoanProductBuilder)11 UserContext (org.mifos.security.util.UserContext)9 ClientBuilder (org.mifos.domain.builders.ClientBuilder)8 Money (org.mifos.framework.util.helpers.Money)8 MifosUser (org.mifos.security.MifosUser)8 BusinessRuleException (org.mifos.service.BusinessRuleException)8 ProductCategoryBO (org.mifos.accounts.productdefinition.business.ProductCategoryBO)7 MifosRuntimeException (org.mifos.core.MifosRuntimeException)7 BigDecimal (java.math.BigDecimal)6 AccountException (org.mifos.accounts.exceptions.AccountException)6 FeeBO (org.mifos.accounts.fees.business.FeeBO)6