Search in sources :

Example 1 with CreateGroupLoanAccount

use of org.mifos.clientportfolio.newloan.applicationservice.CreateGroupLoanAccount in project head by mifos.

the class GroupLoanAccountController method submitGroupLoanApplication.

public LoanCreationResultDto submitGroupLoanApplication(Integer accountState, LoanAccountFormBean formBean, LoanAccountQuestionGroupFormBean loanAccountQuestionGroupFormBean, LoanAccountCashFlow loanAccountCashFlow, CashFlowSummaryFormBean cashFlowSummaryFormBean, LoanScheduleFormBean loanScheduleFormBean) {
    LocalDate disbursementDate = LoanCreationHelper.translateDisbursementDateToLocalDate(formBean);
    RecurringSchedule recurringSchedule = LoanCreationHelper.determineRecurringSchedule(formBean);
    List<CreateAccountFeeDto> accountFees = LoanCreationHelper.translateToAccountFeeDtos(formBean);
    List<CreateAccountFeeDto> additionalAccountFees = LoanCreationHelper.translateToAdditionalAccountFeeDtos(formBean);
    List<CreateAccountPenaltyDto> accountPenalties = LoanCreationHelper.translateToAccountPenaltyDtos(formBean);
    accountFees.addAll(additionalAccountFees);
    Map<String, List<CreateAccountFeeDto>> memberAccountsFees = LoanCreationHelper.translateToMemberAccountsFeeDtos(formBean);
    Map<String, List<CreateAccountFeeDto>> memberAccountsAdditionalFees = LoanCreationHelper.translateToMemberAccountsAdditionalFeeDtos(formBean);
    for (Map.Entry<String, List<CreateAccountFeeDto>> memberAccountEntry : memberAccountsAdditionalFees.entrySet()) {
        memberAccountsFees.get(memberAccountEntry.getKey()).addAll(memberAccountsAdditionalFees.get(memberAccountEntry.getKey()));
    }
    BigDecimal loanAmount = BigDecimal.valueOf(formBean.getAmount().doubleValue());
    BigDecimal minAllowedLoanAmount = BigDecimal.valueOf(formBean.getMinAllowedAmount().doubleValue());
    BigDecimal maxAllowedLoanAmount = BigDecimal.valueOf(formBean.getMaxAllowedAmount().doubleValue());
    CreateLoanAccount loanAccountDetails = prepareLoanAccount(accountState, formBean, disbursementDate, recurringSchedule, accountFees, accountPenalties, loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount);
    LoanCreationResultDto loanCreationResultDto = null;
    List<CreateLoanAccount> memberAccounts = createGroupLoanMembers(accountState, formBean, disbursementDate, recurringSchedule, memberAccountsFees, accountPenalties, loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount);
    BigDecimal totalLoanAmount = BigDecimal.valueOf(formBean.getAmount().doubleValue());
    CreateGroupLoanAccount createGroupLoanAccount = new CreateGroupLoanAccount(memberAccounts, totalLoanAmount, loanAccountDetails);
    loanCreationResultDto = groupLoanAccountServiceFacade.createGroupLoan(createGroupLoanAccount, loanAccountQuestionGroupFormBean.getQuestionGroups(), loanAccountCashFlow);
    return loanCreationResultDto;
}
Also used : LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) RecurringSchedule(org.mifos.clientportfolio.loan.service.RecurringSchedule) CreateLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount) CreateAccountPenaltyDto(org.mifos.dto.domain.CreateAccountPenaltyDto) CreateGroupLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateGroupLoanAccount) ArrayList(java.util.ArrayList) List(java.util.List) CreateAccountFeeDto(org.mifos.dto.domain.CreateAccountFeeDto) LoanCreationResultDto(org.mifos.dto.screen.LoanCreationResultDto) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with CreateGroupLoanAccount

use of org.mifos.clientportfolio.newloan.applicationservice.CreateGroupLoanAccount in project head by mifos.

the class GroupLoanAccountController method retrieveLoanSchedule.

public LoanScheduleDto retrieveLoanSchedule(int customerId, int productId, LoanAccountFormBean formBean, LoanScheduleFormBean loanScheduleFormBean, boolean resetRedoLoanAccountDetails) {
    LoanApplicationStateDto applicationState = loanAccountServiceFacade.retrieveLoanApplicationState();
    Integer accountState = applicationState.getConfiguredApplicationId();
    LocalDate disbursementDate = LoanCreationHelper.translateDisbursementDateToLocalDate(formBean);
    RecurringSchedule recurringSchedule = LoanCreationHelper.determineRecurringSchedule(formBean);
    List<CreateAccountFeeDto> accountFees = LoanCreationHelper.translateToAccountFeeDtos(formBean);
    List<CreateAccountFeeDto> additionalAccountFees = LoanCreationHelper.translateToAdditionalAccountFeeDtos(formBean);
    List<CreateAccountPenaltyDto> accountPenalties = LoanCreationHelper.translateToAccountPenaltyDtos(formBean);
    accountFees.addAll(additionalAccountFees);
    Map<String, List<CreateAccountFeeDto>> memberAccountsFees = LoanCreationHelper.translateToMemberAccountsFeeDtos(formBean);
    Map<String, List<CreateAccountFeeDto>> memberAccountsAdditionalFees = LoanCreationHelper.translateToMemberAccountsAdditionalFeeDtos(formBean);
    for (Map.Entry<String, List<CreateAccountFeeDto>> memberAccountEntry : memberAccountsAdditionalFees.entrySet()) {
        memberAccountsFees.get(memberAccountEntry.getKey()).addAll(memberAccountsAdditionalFees.get(memberAccountEntry.getKey()));
    }
    BigDecimal loanAmount = BigDecimal.valueOf(formBean.getAmount().doubleValue());
    BigDecimal minAllowedLoanAmount = BigDecimal.valueOf(formBean.getMinAllowedAmount().doubleValue());
    BigDecimal maxAllowedLoanAmount = BigDecimal.valueOf(formBean.getMaxAllowedAmount().doubleValue());
    CreateLoanAccount loanAccountDetails = prepareLoanAccount(accountState, formBean, disbursementDate, recurringSchedule, accountFees, accountPenalties, loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount);
    List<CreateLoanAccount> memberAccounts = createGroupLoanMembers(accountState, formBean, disbursementDate, recurringSchedule, memberAccountsFees, accountPenalties, loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount);
    BigDecimal totalLoanAmount = BigDecimal.valueOf(formBean.getAmount().doubleValue());
    CreateGroupLoanAccount createGroupLoanAccount = new CreateGroupLoanAccount(memberAccounts, totalLoanAmount, loanAccountDetails);
    GroupLoanScheduleDto groupLoanScheduleDto = groupLoanAccountServiceFacade.getGroupLoanScheduleDto(createGroupLoanAccount, memberAccounts);
    List<String> globalMemberIds = loanControllerHelper.getSelectedMemberGlobalIds(formBean);
    List<Integer> memberIds = loanControllerHelper.getSelectedMemberIdsFromFormBean(formBean);
    List<BigDecimal> memberAmounts = loanControllerHelper.getSelectedMemberAmounts(formBean);
    loanScheduleFormBean.setVariableInstallments(groupLoanScheduleDto.getInstallments());
    for (int i = 0; i < memberIds.size(); ++i) {
        Integer memberId = memberIds.get(i);
        String memberIdString = memberId.toString();
        LoanScheduleFormBean memberScheduleBean = loanScheduleFormBean.getMemberSchedules().get(memberIdString);
        if (memberScheduleBean == null) {
            memberScheduleBean = new LoanScheduleFormBean();
        }
        memberScheduleBean.setGlobalCustomerId(globalMemberIds.get(i));
        loanScheduleFormBean.getMemberSchedules().put(memberIdString, memberScheduleBean);
        LoanScheduleDto memberLoanSchedule = groupLoanScheduleDto.getMemberSchedules().get(memberId);
        loanControllerHelper.populateFormBeanFromDto(memberId, productId, formBean, memberScheduleBean, disbursementDate, memberLoanSchedule, resetRedoLoanAccountDetails);
        memberScheduleBean.setLoanPrincipal(memberAmounts.get(i));
        loanScheduleFormBean.setInstallments(memberScheduleBean.getInstallments());
    }
    loanScheduleFormBean.setActualPaymentAmounts(new ArrayList<Number>());
    return groupLoanScheduleDto;
}
Also used : LoanApplicationStateDto(org.mifos.clientportfolio.newloan.applicationservice.LoanApplicationStateDto) LocalDate(org.joda.time.LocalDate) CreateLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount) CreateAccountPenaltyDto(org.mifos.dto.domain.CreateAccountPenaltyDto) CreateGroupLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateGroupLoanAccount) ArrayList(java.util.ArrayList) List(java.util.List) CreateAccountFeeDto(org.mifos.dto.domain.CreateAccountFeeDto) LoanScheduleDto(org.mifos.dto.screen.LoanScheduleDto) GroupLoanScheduleDto(org.mifos.dto.screen.GroupLoanScheduleDto) BigDecimal(java.math.BigDecimal) RecurringSchedule(org.mifos.clientportfolio.loan.service.RecurringSchedule) HashMap(java.util.HashMap) Map(java.util.Map) GroupLoanScheduleDto(org.mifos.dto.screen.GroupLoanScheduleDto)

Example 3 with CreateGroupLoanAccount

use of org.mifos.clientportfolio.newloan.applicationservice.CreateGroupLoanAccount in project head by mifos.

the class GroupLoanAccountController method submitLoanWithBackdatedPaymentsApplication.

private LoanCreationResultDto submitLoanWithBackdatedPaymentsApplication(Integer accountState, LoanAccountFormBean formBean, LoanAccountQuestionGroupFormBean loanAccountQuestionGroupFormBean, LoanAccountCashFlow loanAccountCashFlow, CashFlowSummaryFormBean cashFlowSummaryFormBean, LoanScheduleFormBean loanScheduleFormBean) {
    LocalDate disbursementDate = LoanCreationHelper.translateDisbursementDateToLocalDate(formBean);
    RecurringSchedule recurringSchedule = LoanCreationHelper.determineRecurringSchedule(formBean);
    List<CreateAccountFeeDto> accountFees = LoanCreationHelper.translateToAccountFeeDtos(formBean);
    List<CreateAccountPenaltyDto> accountPenalties = LoanCreationHelper.translateToAccountPenaltyDtos(formBean);
    List<CreateAccountFeeDto> additionalAccountFees = LoanCreationHelper.translateToAdditionalAccountFeeDtos(formBean);
    accountFees.addAll(additionalAccountFees);
    Map<String, List<CreateAccountFeeDto>> memberAccountsFees = LoanCreationHelper.translateToMemberAccountsFeeDtos(formBean);
    Map<String, List<CreateAccountFeeDto>> memberAccountsAdditionalFees = LoanCreationHelper.translateToMemberAccountsAdditionalFeeDtos(formBean);
    for (Map.Entry<String, List<CreateAccountFeeDto>> memberAccountEntry : memberAccountsAdditionalFees.entrySet()) {
        memberAccountsFees.get(memberAccountEntry.getKey()).addAll(memberAccountsAdditionalFees.get(memberAccountEntry.getKey()));
    }
    BigDecimal loanAmount = BigDecimal.valueOf(formBean.getAmount().doubleValue());
    BigDecimal minAllowedLoanAmount = BigDecimal.valueOf(formBean.getMinAllowedAmount().doubleValue());
    BigDecimal maxAllowedLoanAmount = BigDecimal.valueOf(formBean.getMaxAllowedAmount().doubleValue());
    Map<Integer, List<LoanPaymentDto>> backdatedMemberLoanPayments = new HashMap<Integer, List<LoanPaymentDto>>();
    List<Integer> memberIds = loanControllerHelper.getSelectedMemberIdsFromFormBean(formBean);
    for (Integer memberId : memberIds) {
        String memberIdString = memberId.toString();
        List<Number> actualPaymentAmountDetails = loanScheduleFormBean.getMemberSchedules().get(memberIdString).getActualPaymentAmounts();
        List<LoanPaymentDto> backdatedLoanPayments = new ArrayList<LoanPaymentDto>();
        List<DateTime> actualPaymentDates = loanScheduleFormBean.getMemberSchedules().get(memberIdString).getActualPaymentDates();
        List<Short> actualPaymentTypes = loanScheduleFormBean.getMemberSchedules().get(memberIdString).getActualPaymentTypes();
        for (int i = 0; i < actualPaymentAmountDetails.size(); ++i) {
            Number actualPaymentAmount = actualPaymentAmountDetails.get(i);
            if (actualPaymentAmount.doubleValue() > 0) {
                LocalDate transactionDate = new LocalDate(actualPaymentDates.get(i));
                backdatedLoanPayments.add(new LoanPaymentDto(actualPaymentAmount.toString(), transactionDate, actualPaymentTypes.get(i), null));
            }
        }
        backdatedMemberLoanPayments.put(memberId, backdatedLoanPayments);
    }
    CreateLoanAccount loanAccountDetails = prepareLoanAccount(accountState, formBean, disbursementDate, recurringSchedule, accountFees, accountPenalties, loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount);
    List<CreateLoanAccount> memberAccounts = createGroupLoanMembers(accountState, formBean, disbursementDate, recurringSchedule, memberAccountsFees, accountPenalties, loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount);
    BigDecimal totalLoanAmount = BigDecimal.valueOf(formBean.getAmount().doubleValue());
    CreateGroupLoanAccount createGroupLoanAccount = new CreateGroupLoanAccount(memberAccounts, totalLoanAmount, loanAccountDetails);
    return groupLoanAccountServiceFacade.createBackdatedGroupLoan(createGroupLoanAccount, backdatedMemberLoanPayments, loanAccountQuestionGroupFormBean.getQuestionGroups(), loanAccountCashFlow);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) CreateLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount) CreateAccountPenaltyDto(org.mifos.dto.domain.CreateAccountPenaltyDto) CreateGroupLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateGroupLoanAccount) LoanPaymentDto(org.mifos.dto.domain.LoanPaymentDto) ArrayList(java.util.ArrayList) List(java.util.List) CreateAccountFeeDto(org.mifos.dto.domain.CreateAccountFeeDto) BigDecimal(java.math.BigDecimal) RecurringSchedule(org.mifos.clientportfolio.loan.service.RecurringSchedule) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 LocalDate (org.joda.time.LocalDate)3 RecurringSchedule (org.mifos.clientportfolio.loan.service.RecurringSchedule)3 CreateGroupLoanAccount (org.mifos.clientportfolio.newloan.applicationservice.CreateGroupLoanAccount)3 CreateLoanAccount (org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount)3 CreateAccountFeeDto (org.mifos.dto.domain.CreateAccountFeeDto)3 CreateAccountPenaltyDto (org.mifos.dto.domain.CreateAccountPenaltyDto)3 DateTime (org.joda.time.DateTime)1 LoanApplicationStateDto (org.mifos.clientportfolio.newloan.applicationservice.LoanApplicationStateDto)1 LoanPaymentDto (org.mifos.dto.domain.LoanPaymentDto)1 GroupLoanScheduleDto (org.mifos.dto.screen.GroupLoanScheduleDto)1 LoanCreationResultDto (org.mifos.dto.screen.LoanCreationResultDto)1 LoanScheduleDto (org.mifos.dto.screen.LoanScheduleDto)1