use of org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment in project head by mifos.
the class LoanUIHelperFnStrutsTest method testRepaymentScheduleInstallment.
@Test
public void testRepaymentScheduleInstallment() {
long l = System.currentTimeMillis();
RepaymentScheduleInstallment repaymentScheduleInstallment = new RepaymentScheduleInstallment(10, new Date(l), new Money(getCurrency(), "100.0"), new Money(getCurrency(), "100.0"), new Money(getCurrency(), "100.0"), new Money(getCurrency(), "100.0"), new Money(getCurrency(), "100.0"));
Money m = new Money(getCurrency(), "100");
Assert.assertEquals("Due date", new Date(l), repaymentScheduleInstallment.getDueDateValue());
Assert.assertEquals("fees", m, repaymentScheduleInstallment.getFees());
Assert.assertEquals("Installment", "10", repaymentScheduleInstallment.getInstallmentNumberAsString());
Assert.assertEquals("Interest", m, repaymentScheduleInstallment.getFees());
Assert.assertEquals("Misc fees", m, repaymentScheduleInstallment.getMiscFees());
Assert.assertEquals("Misc penalty", m, repaymentScheduleInstallment.getMiscPenalty());
Assert.assertEquals("principal", m, repaymentScheduleInstallment.getPrincipal());
}
use of org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment in project head by mifos.
the class LoanServiceFacadeWebTierTest method shouldValidateForInstallmentDateBeyondCashFlowData.
@Ignore
@Test
public void shouldValidateForInstallmentDateBeyondCashFlowData() {
ArrayList<MonthlyCashFlowDetail> monthlyCashFlows = new ArrayList<MonthlyCashFlowDetail>();
DateTime dateTime = new DateTime().withDate(2010, 10, 30);
monthlyCashFlows.add(new MonthlyCashFlowDetail(dateTime, new BigDecimal(123), new BigDecimal(234), ""));
monthlyCashFlows.add(new MonthlyCashFlowDetail(dateTime.plusMonths(1), new BigDecimal(123), new BigDecimal(234), ""));
monthlyCashFlows.add(new MonthlyCashFlowDetail(dateTime.plusMonths(2), new BigDecimal(123), new BigDecimal(234), ""));
CashFlowDetail cashFlowDetail = new CashFlowDetail(monthlyCashFlows);
CashFlowForm cashFlowForm = new CashFlowForm(cashFlowDetail, false, new BigDecimal(1000), 10d);
cashFlowForm.setTotalExpenses(BigDecimal.valueOf(76));
cashFlowForm.setTotalRevenues(BigDecimal.valueOf(55));
RepaymentScheduleInstallment installment = installmentBuilder.reset(locale).withPrincipal(new Money(rupee, "4.9")).withTotalValue("10").withDueDateValue("30-Nov-2010").build();
RepaymentScheduleInstallment installmentBeforeCashFlowDate = installmentBuilder.reset(locale).withPrincipal(new Money(rupee, "4.9")).withTotalValue("10").withDueDateValue("30-Nov-2010").build();
List<RepaymentScheduleInstallment> installments = asList(installment);
Errors errors;
// errors = loanServiceFacade.validateCashFlowForInstallments(installments, cashFlowForm, 1600d);
// assertThat(errors.hasErrorEntryWithCode(AccountConstants.INSTALLMENT_BEYOND_CASHFLOW_DATE), is(false));
RepaymentScheduleInstallment installmentBeyondCashFlowDate = installmentBuilder.reset(locale).withPrincipal(new Money(rupee, "4.9")).withTotalValue("10").withDueDateValue("30-Jan-2011").build();
installments = asList(installmentBeyondCashFlowDate);
// errors = loanServiceFacade.validateCashFlowForInstallments(installments, cashFlowForm, 1600d);
// assertThat(errors.hasErrorEntryWithCode(AccountConstants.INSTALLMENT_BEYOND_CASHFLOW_DATE), is(true));
// errors = loanServiceFacade.validateCashFlowForInstallments(installments, cashFlowForm, 1700d);
// assertThat(errors.hasErrorEntryWithCode(AccountConstants.INSTALLMENT_BEYOND_CASHFLOW_DATE), is(true));
}
use of org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment in project head by mifos.
the class LoanAccountServiceFacadeWebTier method retrieveOriginalLoanSchedule.
@Override
public OriginalScheduleInfoDto retrieveOriginalLoanSchedule(String globalAccountNum) {
LoanBO loanBO = this.loanDao.findByGlobalAccountNum(globalAccountNum);
Integer accountId = loanBO.getAccountId();
try {
List<OriginalLoanScheduleEntity> loanScheduleEntities = loanBusinessService.retrieveOriginalLoanSchedule(accountId);
ArrayList<RepaymentScheduleInstallmentDto> repaymentScheduleInstallments = new ArrayList<RepaymentScheduleInstallmentDto>();
for (OriginalLoanScheduleEntity loanScheduleEntity : loanScheduleEntities) {
RepaymentScheduleInstallment repaymentScheduleInstallment = loanScheduleEntity.toDto();
RepaymentScheduleInstallmentDto installmentDto = new RepaymentScheduleInstallmentDto(repaymentScheduleInstallment.getInstallment(), repaymentScheduleInstallment.getPrincipal().toString(), repaymentScheduleInstallment.getInterest().toString(), repaymentScheduleInstallment.getFees().toString(), repaymentScheduleInstallment.getMiscFees().toString(), repaymentScheduleInstallment.getFeesWithMiscFee().toString(), repaymentScheduleInstallment.getMiscPenalty().toString(), repaymentScheduleInstallment.getTotal(), repaymentScheduleInstallment.getDueDate());
repaymentScheduleInstallments.add(installmentDto);
}
return new OriginalScheduleInfoDto(loanBO.getLoanAmount().toString(), loanBO.getDisbursementDate(), repaymentScheduleInstallments);
} catch (PersistenceException e) {
throw new MifosRuntimeException(e);
}
}
use of org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment in project head by mifos.
the class GroupIndividualLoanAccountAction method get.
@TransactionDemarcate(saveToken = true)
public ActionForward get(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
LoanAccountActionForm loanAccountActionForm = (LoanAccountActionForm) form;
loanAccountActionForm.clearDetailsForLoan();
String globalAccountNum = request.getParameter(GLOBAL_ACCOUNT_NUM);
UserContext userContext = getUserContext(request);
LoanInformationDto loanInformationDto;
try {
loanInformationDto = this.loanAccountServiceFacade.retrieveLoanInformation(globalAccountNum);
} catch (MifosRuntimeException e) {
if (e.getCause() instanceof ApplicationException) {
throw (ApplicationException) e.getCause();
}
throw e;
}
final String accountStateNameLocalised = ApplicationContextProvider.getBean(MessageLookup.class).lookup(loanInformationDto.getAccountStateName());
SessionUtils.removeThenSetAttribute("accountStateNameLocalised", accountStateNameLocalised, request);
final String gracePeriodTypeNameLocalised = ApplicationContextProvider.getBean(MessageLookup.class).lookup(loanInformationDto.getGracePeriodTypeName());
SessionUtils.removeThenSetAttribute("gracePeriodTypeNameLocalised", gracePeriodTypeNameLocalised, request);
final String interestTypeNameLocalised = ApplicationContextProvider.getBean(MessageLookup.class).lookup(loanInformationDto.getInterestTypeName());
SessionUtils.removeThenSetAttribute("interestTypeNameLocalised", interestTypeNameLocalised, request);
final Set<String> accountFlagStateEntityNamesLocalised = new HashSet<String>();
for (String name : loanInformationDto.getAccountFlagNames()) {
accountFlagStateEntityNamesLocalised.add(ApplicationContextProvider.getBean(MessageLookup.class).lookup(name));
}
SessionUtils.setCollectionAttribute("accountFlagNamesLocalised", accountFlagStateEntityNamesLocalised, request);
SessionUtils.removeAttribute(BUSINESS_KEY, request);
Integer loanIndividualMonitoringIsEnabled = configurationPersistence.getConfigurationValueInteger(LOAN_INDIVIDUAL_MONITORING_IS_ENABLED);
if (null != loanIndividualMonitoringIsEnabled && loanIndividualMonitoringIsEnabled.intValue() != 0) {
SessionUtils.setAttribute(LOAN_INDIVIDUAL_MONITORING_IS_ENABLED, loanIndividualMonitoringIsEnabled.intValue(), request);
}
Boolean GroupLoanWithMembers = AccountingRules.isGroupLoanWithMembers();
if (null != GroupLoanWithMembers && GroupLoanWithMembers != false) {
SessionUtils.setAttribute("GroupLoanWithMembers", GroupLoanWithMembers.booleanValue(), request);
}
List<ValueListElement> allLoanPurposes = this.loanProductDao.findAllLoanPurposes();
SessionUtils.setCollectionAttribute(MasterConstants.BUSINESS_ACTIVITIES, allLoanPurposes, request);
if (((null != loanIndividualMonitoringIsEnabled && 0 != loanIndividualMonitoringIsEnabled.intValue()) || (null != GroupLoanWithMembers && GroupLoanWithMembers != false)) && loanInformationDto.isGroup()) {
List<LoanAccountDetailsDto> loanAccountDetails = this.loanAccountServiceFacade.retrieveLoanAccountDetails(loanInformationDto);
addEmptyBuisnessActivities(loanAccountDetails);
SessionUtils.setCollectionAttribute("loanAccountDetailsView", loanAccountDetails, request);
}
SessionUtils.setCollectionAttribute(CUSTOM_FIELDS, new ArrayList<CustomFieldDefinitionEntity>(), request);
// Retrieve and set into the session all collateral types from the
// lookup_value_locale table associated with the current user context
// locale
SessionUtils.setCollectionAttribute(MasterConstants.COLLATERAL_TYPES, legacyMasterDao.getLookUpEntity(MasterConstants.COLLATERAL_TYPES).getCustomValueListElements(), request);
SessionUtils.setAttribute(AccountConstants.LAST_PAYMENT_ACTION, loanBusinessService.getLastPaymentAction(loanInformationDto.getAccountId()), request);
SessionUtils.removeThenSetAttribute("loanInformationDto", loanInformationDto, request);
// inject preferred date
List<LoanActivityDto> activities = loanInformationDto.getRecentAccountActivity();
for (LoanActivityDto activity : activities) {
activity.setUserPrefferedDate(DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), activity.getActionDate().toString()));
}
SessionUtils.setCollectionAttribute(RECENTACCOUNTACTIVITIES, activities, request);
request.getSession().setAttribute("guarantyInformation", loanAccountServiceFacade.handleGuaranties(loanInformationDto));
request.setAttribute(CustomerConstants.SURVEY_KEY, loanInformationDto.getAccountSurveys());
request.setAttribute(CustomerConstants.SURVEY_COUNT, loanInformationDto.getActiveSurveys());
request.setAttribute(AccountConstants.SURVEY_KEY, loanInformationDto.getAccountSurveys());
Integer administrativeDocumentsIsEnabled = configurationPersistence.getConfigurationValueInteger(ADMINISTRATIVE_DOCUMENT_IS_ENABLED);
if (null != administrativeDocumentsIsEnabled && administrativeDocumentsIsEnabled.intValue() == 1) {
SessionUtils.setCollectionAttribute(AdminDocumentsContants.ADMINISTRATIVEDOCUMENTSLIST, legacyAdminDocumentDao.getAllActiveAdminDocuments(), request);
SessionUtils.setCollectionAttribute(AdminDocumentsContants.ADMINISTRATIVEDOCUMENTSACCSTATEMIXLIST, legacyAdminDocAccStateMixDao.getAllMixedAdminDocuments(), request);
}
List<QuestionGroupInstanceDetail> questions = new ArrayList<QuestionGroupInstanceDetail>();
questions.addAll(questionnaireServiceFacade.getQuestionGroupInstancesWithUnansweredQuestionGroups(loanInformationDto.getAccountId(), "Create", "Loan"));
questions.addAll(questionnaireServiceFacade.getQuestionGroupInstancesWithUnansweredQuestionGroups(loanInformationDto.getAccountId(), "Approve", "Loan"));
questions.addAll(questionnaireServiceFacade.getQuestionGroupInstancesWithUnansweredQuestionGroups(loanInformationDto.getAccountId(), "View", "Loan"));
questions.addAll(questionnaireServiceFacade.getQuestionGroupInstancesWithUnansweredQuestionGroups(loanInformationDto.getAccountId(), "Disburse", "Loan"));
questions.addAll(questionnaireServiceFacade.getQuestionGroupInstancesWithUnansweredQuestionGroups(loanInformationDto.getAccountId(), "Close", "Loan"));
SessionUtils.setCollectionAttribute("questionGroups", questions, request);
SessionUtils.setCollectionAttribute("personalInformationOrder", informationOrderServiceFacade.getInformationOrder("Loan"), request);
LoanBO loan = getLoan(loanInformationDto.getAccountId());
SessionUtils.setAttribute(Constants.BUSINESS_KEY, loan, request);
setCurrentPageUrl(request, loan);
setOverpayments(request, loan);
List<RepaymentScheduleInstallment> installments = loan.toRepaymentScheduleDto(userContext.getPreferredLocale());
loanAccountActionForm.initializeInstallments(installments);
return mapping.findForward(ActionForwards.get_success.toString());
}
use of org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment in project head by mifos.
the class LoanBusinessService method applyDailyInterestRates.
public void applyDailyInterestRates(LoanScheduleGenerationDto loanScheduleGenerationDto, boolean flatInterestType) {
Double dailyInterestFactor = loanScheduleGenerationDto.getInterestRate() / (AccountingRules.getNumberOfInterestDays() * 100d);
Money principalOutstanding = loanScheduleGenerationDto.getLoanAmountValue();
Money runningPrincipal = new Money(loanScheduleGenerationDto.getLoanAmountValue().getCurrency());
Date initialDueDate = loanScheduleGenerationDto.getDisbursementDate();
int installmentIndex, numInstallments;
for (installmentIndex = 0, numInstallments = loanScheduleGenerationDto.getInstallments().size(); installmentIndex < numInstallments - 1; installmentIndex++) {
RepaymentScheduleInstallment installment = loanScheduleGenerationDto.getInstallments().get(installmentIndex);
Date currentDueDate = installment.getDueDateValue();
long duration = DateUtils.getNumberOfDaysBetweenTwoDates(currentDueDate, initialDueDate);
Money fees = installment.getFees();
Money interest = computeInterestAmount(dailyInterestFactor, principalOutstanding, installment, duration);
Money miscFee = installment.getMiscFees();
Money miscPenality = installment.getMiscPenalty();
Money total = installment.getTotalValue();
Money principal = total.subtract(interest.add(fees).add(miscFee).add(miscPenality));
installment.setPrincipalAndInterest(interest, principal);
initialDueDate = currentDueDate;
if (!flatInterestType) {
principalOutstanding = principalOutstanding.subtract(principal);
}
runningPrincipal = runningPrincipal.add(principal);
}
RepaymentScheduleInstallment lastInstallment = loanScheduleGenerationDto.getInstallments().get(installmentIndex);
long duration = DateUtils.getNumberOfDaysBetweenTwoDates(lastInstallment.getDueDateValue(), initialDueDate);
Money interest = computeInterestAmount(dailyInterestFactor, principalOutstanding, lastInstallment, duration);
Money fees = lastInstallment.getFees();
Money principal = loanScheduleGenerationDto.getLoanAmountValue().subtract(runningPrincipal);
Money total = principal.add(interest).add(fees);
lastInstallment.setTotalAndTotalValue(total);
lastInstallment.setPrincipalAndInterest(interest, principal);
}
Aggregations