Search in sources :

Example 1 with CreateLoanAccount

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

the class LoanBOTestUtils method createLoanAccountWithDisbursement.

/**
     * Like
     * {@link #createLoanAccount(String, CustomerBO, AccountState, Date, LoanOfferingBO)}
     * but differs in various ways.
     *
     * Note: the manipulation done in this method looks very suspicious and
     * possibly wrong. Tests that use this method should be considered as
     * suspect.
     */
public static LoanBO createLoanAccountWithDisbursement(final CustomerBO customer, final AccountState state, final Date startDate, final LoanOfferingBO loanOffering, final int disbursalType, final Short noOfInstallments) {
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(startDate);
    MeetingBO meeting = TestObjectFactory.createLoanMeeting(customer.getCustomerMeeting().getMeeting());
    List<Date> meetingDates = TestObjectFactory.getMeetingDates(customer.getOfficeId(), meeting, 6);
    MifosCurrency currency = TestUtils.RUPEE;
    List<CreateAccountFeeDto> accountFees = new ArrayList<CreateAccountFeeDto>();
    AmountFeeBO maintanenceFee = (AmountFeeBO) TestObjectFactory.createPeriodicAmountFee("Mainatnence Fee", FeeCategory.LOAN, "100", RecurrenceType.WEEKLY, Short.valueOf("1"));
    IntegrationTestObjectMother.saveFee(maintanenceFee);
    accountFees.add(new CreateAccountFeeDto(maintanenceFee.getFeeId().intValue(), maintanenceFee.getFeeAmount().toString()));
    AccountFeesEntity accountDisbursementFee = null;
    AmountFeeBO disbursementFee = null;
    AccountFeesEntity accountDisbursementFee2 = null;
    AmountFeeBO disbursementFee2 = null;
    if (disbursalType == 1 || disbursalType == 2) {
        disbursementFee = (AmountFeeBO) TestObjectFactory.createOneTimeAmountFee("Disbursement Fee 1", FeeCategory.LOAN, "10", FeePayment.TIME_OF_DISBURSEMENT);
        IntegrationTestObjectMother.saveFee(disbursementFee);
        accountFees.add(new CreateAccountFeeDto(disbursementFee.getFeeId().intValue(), disbursementFee.getFeeAmount().toString()));
        disbursementFee2 = (AmountFeeBO) TestObjectFactory.createOneTimeAmountFee("Disbursement Fee 2", FeeCategory.LOAN, "20", FeePayment.TIME_OF_DISBURSEMENT);
        IntegrationTestObjectMother.saveFee(disbursementFee2);
        accountFees.add(new CreateAccountFeeDto(disbursementFee2.getFeeId().intValue(), disbursementFee2.getFeeAmount().toString()));
    }
    BigDecimal loanAmount = BigDecimal.valueOf(DEFAULT_LOAN_AMOUNT);
    BigDecimal minAllowedLoanAmount = loanAmount;
    BigDecimal maxAllowedLoanAmount = loanAmount;
    Double interestRate = Double.valueOf("10.0");
    LocalDate disbursementDate = new LocalDate(meetingDates.get(0));
    int numberOfInstallments = noOfInstallments;
    int minAllowedNumberOfInstallments = loanOffering.getEligibleInstallmentSameForAllLoan().getMaxNoOfInstall();
    int maxAllowedNumberOfInstallments = loanOffering.getEligibleInstallmentSameForAllLoan().getMaxNoOfInstall();
    int graceDuration = 0;
    Integer sourceOfFundId = null;
    Integer loanPurposeId = null;
    Integer collateralTypeId = null;
    String collateralNotes = null;
    String externalId = null;
    boolean repaymentScheduleIndependentOfCustomerMeeting = false;
    RecurringSchedule recurringSchedule = null;
    CreateLoanAccount createLoanAccount = new CreateLoanAccount(customer.getCustomerId(), loanOffering.getPrdOfferingId().intValue(), state.getValue().intValue(), loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount, interestRate, disbursementDate, null, numberOfInstallments, minAllowedNumberOfInstallments, maxAllowedNumberOfInstallments, graceDuration, sourceOfFundId, loanPurposeId, collateralTypeId, collateralNotes, externalId, repaymentScheduleIndependentOfCustomerMeeting, recurringSchedule, accountFees, new ArrayList<CreateAccountPenaltyDto>());
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
    LoanBO loan = IntegrationTestObjectMother.createClientLoan(createLoanAccount);
    loan.updateDetails(TestUtils.makeUser());
    AccountFeesEntity accountPeriodicFee = new AccountFeesEntity(loan, maintanenceFee, new Double("10.0"));
    AccountTestUtils.addAccountFees(accountPeriodicFee, loan);
    if (disbursalType == 1 || disbursalType == 2) {
        accountDisbursementFee = new AccountFeesEntity(loan, disbursementFee, new Double("10.0"));
        AccountTestUtils.addAccountFees(accountDisbursementFee, loan);
        accountDisbursementFee2 = new AccountFeesEntity(loan, disbursementFee2, new Double("20.0"));
        AccountTestUtils.addAccountFees(accountDisbursementFee2, loan);
    }
    loan.setLoanMeeting(meeting);
    if (// 2-Interest At Disbursement
    disbursalType == 2) {
        loan.setInterestDeductedAtDisbursement(true);
        meetingDates = TestObjectFactory.getMeetingDates(customer.getOfficeId(), loan.getLoanMeeting(), 6);
        short i = 0;
        for (Date date : meetingDates) {
            if (i == 0) {
                i++;
                loan.setDisbursementDate(date);
                LoanScheduleEntity actionDate = (LoanScheduleEntity) loan.getAccountActionDate(i);
                actionDate.setActionDate(new java.sql.Date(date.getTime()));
                actionDate.setInterest(new Money(currency, "12.0"));
                actionDate.setPaymentStatus(PaymentStatus.UNPAID);
                AccountTestUtils.addAccountActionDate(actionDate, loan);
                // periodic fee
                AccountFeesActionDetailEntity accountFeesaction = new LoanFeeScheduleEntity(actionDate, maintanenceFee, accountPeriodicFee, new Money(currency, "10.0"));
                setFeeAmountPaid(accountFeesaction, new Money(currency, "0.0"));
                actionDate.addAccountFeesAction(accountFeesaction);
                // dibursement fee one
                AccountFeesActionDetailEntity accountFeesaction1 = new LoanFeeScheduleEntity(actionDate, disbursementFee, accountDisbursementFee, new Money(currency, "10.0"));
                setFeeAmountPaid(accountFeesaction1, new Money(currency, "0.0"));
                actionDate.addAccountFeesAction(accountFeesaction1);
                // disbursementfee2
                AccountFeesActionDetailEntity accountFeesaction2 = new LoanFeeScheduleEntity(actionDate, disbursementFee2, accountDisbursementFee2, new Money(currency, "20.0"));
                setFeeAmountPaid(accountFeesaction2, new Money(currency, "0.0"));
                actionDate.addAccountFeesAction(accountFeesaction2);
                continue;
            }
            i++;
            LoanScheduleEntity actionDate = (LoanScheduleEntity) loan.getAccountActionDate(i);
            actionDate.setActionDate(new java.sql.Date(date.getTime()));
            actionDate.setPrincipal(new Money(currency, "100.0"));
            actionDate.setInterest(new Money(currency, "12.0"));
            actionDate.setPaymentStatus(PaymentStatus.UNPAID);
            AccountTestUtils.addAccountActionDate(actionDate, loan);
            AccountFeesActionDetailEntity accountFeesaction = new LoanFeeScheduleEntity(actionDate, maintanenceFee, accountPeriodicFee, new Money(currency, "100.0"));
            setFeeAmountPaid(accountFeesaction, new Money(currency, "0.0"));
            actionDate.addAccountFeesAction(accountFeesaction);
        }
    } else if (disbursalType == 1 || disbursalType == 3) {
        loan.setInterestDeductedAtDisbursement(false);
        meetingDates = TestObjectFactory.getMeetingDates(customer.getOfficeId(), loan.getLoanMeeting(), 6);
        short i = 0;
        for (Date date : meetingDates) {
            if (i == 0) {
                i++;
                loan.setDisbursementDate(date);
                continue;
            }
            LoanScheduleEntity actionDate = (LoanScheduleEntity) loan.getAccountActionDate(i++);
            actionDate.setActionDate(new java.sql.Date(date.getTime()));
            actionDate.setPrincipal(new Money(currency, "100.0"));
            actionDate.setInterest(new Money(currency, "12.0"));
            actionDate.setPaymentStatus(PaymentStatus.UNPAID);
            AccountTestUtils.addAccountActionDate(actionDate, loan);
            AccountFeesActionDetailEntity accountFeesaction = new LoanFeeScheduleEntity(actionDate, maintanenceFee, accountPeriodicFee, new Money(currency, "100.0"));
            setFeeAmountPaid(accountFeesaction, new Money(currency, "0.0"));
            actionDate.addAccountFeesAction(accountFeesaction);
        }
    }
    GracePeriodTypeEntity gracePeriodType = new GracePeriodTypeEntity(GraceType.NONE);
    loan.setGracePeriodType(gracePeriodType);
    loan.setCreatedBy(Short.valueOf("1"));
    // Set collateral type to lookup id 109, which references the lookup
    // value 'Type 1'
    loan.setCollateralTypeId(Integer.valueOf("109"));
    InterestTypesEntity interestTypes = new InterestTypesEntity(InterestType.FLAT);
    loan.setInterestType(interestTypes);
    loan.setInterestRate(10.0);
    loan.setCreatedDate(new Date(System.currentTimeMillis()));
    setLoanSummary(loan, currency);
    return loan;
}
Also used : InterestTypesEntity(org.mifos.application.master.business.InterestTypesEntity) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) Money(org.mifos.framework.util.helpers.Money) CreateLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount) CreateAccountPenaltyDto(org.mifos.dto.domain.CreateAccountPenaltyDto) CreateAccountFeeDto(org.mifos.dto.domain.CreateAccountFeeDto) GracePeriodTypeEntity(org.mifos.accounts.productdefinition.business.GracePeriodTypeEntity) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) MifosCurrency(org.mifos.application.master.business.MifosCurrency) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) BigDecimal(java.math.BigDecimal) RecurringSchedule(org.mifos.clientportfolio.loan.service.RecurringSchedule) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext)

Example 2 with CreateLoanAccount

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

the class LoanAccountServiceFacadeWebTier method createMultipleLoans.

@Override
public List<String> createMultipleLoans(List<CreateLoanRequest> multipleLoans) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
    userContext.setBranchGlobalNum(userOffice.getGlobalOfficeNum());
    List<String> createdLoanAccountNumbers = new ArrayList<String>();
    for (CreateLoanRequest loanDetail : multipleLoans) {
        CustomerBO center = this.customerDao.findCustomerById(loanDetail.getCenterId());
        Short loanProductId = loanDetail.getLoanProductId();
        LoanOfferingBO loanProduct = this.loanProductDao.findById(loanProductId.intValue());
        List<QuestionGroupDetail> questionGroups = new ArrayList<QuestionGroupDetail>();
        LoanAccountCashFlow loanAccountCashFlow = null;
        BigDecimal loanAmount = BigDecimal.valueOf(Double.valueOf(loanDetail.getLoanAmount()));
        BigDecimal minAllowedLoanAmount = BigDecimal.valueOf(Double.valueOf(loanDetail.getMinLoanAmount()));
        BigDecimal maxAllowedLoanAmount = BigDecimal.valueOf(Double.valueOf(loanDetail.getMaxLoanAmount()));
        Double interestRate = loanProduct.getDefInterestRate();
        LocalDate disbursementDate = new LocalDate(center.getCustomerAccount().getNextMeetingDate());
        int numberOfInstallments = loanDetail.getDefaultNoOfInstall();
        int minAllowedNumberOfInstallments = loanDetail.getMinNoOfInstall();
        int maxAllowedNumberOfInstallments = loanDetail.getMaxNoOfInstall();
        int graceDuration = loanProduct.getGracePeriodDuration();
        boolean isRepaymentIndepOfMeetingEnabled = new ConfigurationBusinessService().isRepaymentIndepOfMeetingEnabled();
        Integer sourceOfFundId = null;
        Integer loanPurposeId = loanDetail.getLoanPurpose();
        Integer collateralTypeId = null;
        String collateralNotes = null;
        String externalId = null;
        List<CreateAccountFeeDto> accountFees = new ArrayList<CreateAccountFeeDto>();
        for (LoanOfferingFeesEntity loanOfferingFeesEntity : loanProduct.getLoanOfferingFees()) {
            FeeBO feeBO = loanOfferingFeesEntity.getFees();
            FeeDto feeDto = feeBO.toDto();
            String amountOrRate = feeDto.getAmountOrRate().toString();
            accountFees.add(new CreateAccountFeeDto(feeBO.getFeeId().intValue(), amountOrRate));
        }
        RecurringSchedule recurringSchedule = null;
        if (isRepaymentIndepOfMeetingEnabled) {
            MeetingBO meetingBO = loanProduct.getLoanOfferingMeetingValue();
            MeetingDetailsEntity meetingDetailsEntity = meetingBO.getMeetingDetails();
            Integer recursEvery = meetingDetailsEntity.getRecurAfter().intValue();
            Short dayOfMonth = meetingDetailsEntity.getDayNumber();
            RankOfDay weekOfMonth = meetingDetailsEntity.getWeekRank();
            WeekDay dayOfWeek = meetingDetailsEntity.getWeekDay();
            MeetingDetailsEntity customerMeetingDetailsEntity = center.getCustomerAccount().getMeetingForAccount().getMeetingDetails();
            Short customerRecurrenceType = customerMeetingDetailsEntity.getRecurrenceType().getRecurrenceId();
            if (meetingDetailsEntity.getRecurrenceType().getRecurrenceId().equals(customerRecurrenceType)) {
                dayOfMonth = customerMeetingDetailsEntity.getDayNumber();
                weekOfMonth = customerMeetingDetailsEntity.getWeekRank();
                dayOfWeek = customerMeetingDetailsEntity.getWeekDay();
            }
            if (meetingBO.isMonthly()) {
                if (meetingBO.isMonthlyOnDate()) {
                    recurringSchedule = new MonthlyOnDayOfMonthSchedule(recursEvery, dayOfMonth.intValue());
                } else {
                    recurringSchedule = new MonthlyOnWeekOfMonthSchedule(recursEvery, weekOfMonth.getValue().intValue(), dayOfWeek.getValue().intValue());
                }
            } else if (meetingBO.isWeekly()) {
                recurringSchedule = new WeeklySchedule(recursEvery, dayOfWeek.getValue().intValue());
            }
        }
        CreateLoanAccount loanAccountInfo = new CreateLoanAccount(loanDetail.getClientId(), loanDetail.getLoanProductId().intValue(), loanDetail.getAccountStateId().intValue(), loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount, interestRate, disbursementDate, null, numberOfInstallments, minAllowedNumberOfInstallments, maxAllowedNumberOfInstallments, graceDuration, sourceOfFundId, loanPurposeId, collateralTypeId, collateralNotes, externalId, isRepaymentIndepOfMeetingEnabled, recurringSchedule, accountFees, new ArrayList<CreateAccountPenaltyDto>());
        LoanCreationResultDto result = this.createLoan(loanAccountInfo, questionGroups, loanAccountCashFlow);
        createdLoanAccountNumbers.add(result.getGlobalAccountNum());
    //            try {
    //                CustomerBO center = this.customerDao.findCustomerById(loanDetail.getCenterId());
    //
    //                Short loanProductId = loanDetail.getLoanProductId();
    //                LoanOfferingBO loanProduct = this.loanProductDao.findById(loanProductId.intValue());
    //                CustomerBO client = this.customerDao.findCustomerById(loanDetail.getClientId());
    //
    //                AccountState accountState = AccountState.fromShort(loanDetail.getAccountStateId());
    //                Money loanAmount = new Money(loanProduct.getCurrency(), loanDetail.getLoanAmount());
    //                Short defaultNumOfInstallments = loanDetail.getDefaultNoOfInstall();
    //                Date disbursementDate = center.getCustomerAccount().getNextMeetingDate();
    //                boolean interestDeductedAtDisbursement = loanProduct.isIntDedDisbursement();
    //                boolean isRepaymentIndepOfMeetingEnabled = new ConfigurationBusinessService().isRepaymentIndepOfMeetingEnabled();
    //
    //                MeetingBO newMeetingForRepaymentDay = null;
    //                if (isRepaymentIndepOfMeetingEnabled) {
    //                    MeetingBO meeting = center.getCustomerAccount().getMeetingForAccount();
    //                    LoanAccountMeetingDto loanAccountMeetingDto = null;
    //
    //                    if (meeting.isWeekly()) {
    //                        loanAccountMeetingDto = new LoanAccountMeetingDto(RecurrenceType.WEEKLY.getValue().toString(),
    //                                meeting.getMeetingDetails().getWeekDay().getValue().toString(),
    //                                meeting.getMeetingDetails().getRecurAfter().toString(),
    //                                null, null, null, null, null, null);
    //                    } else if (meeting.isMonthly()) {
    //                        if (meeting.isMonthlyOnDate()) {
    //                            loanAccountMeetingDto = new LoanAccountMeetingDto(RecurrenceType.MONTHLY.getValue().toString(),
    //                                    null, null, "1",
    //                                    meeting.getMeetingDetails().getDayNumber().toString(),
    //                                    meeting.getMeetingDetails().getRecurAfter().toString(),
    //                                    null, null, null);
    //                        } else {
    //                            loanAccountMeetingDto = new LoanAccountMeetingDto(RecurrenceType.MONTHLY.getValue().toString(),
    //                                    null, null, "2", null, null,
    //                                    meeting.getMeetingDetails().getWeekDay().getValue().toString(),
    //                                    meeting.getMeetingDetails().getRecurAfter().toString(),
    //                                    meeting.getMeetingDetails().getWeekRank().getValue().toString());
    //                        }
    //                    }
    //
    //                    newMeetingForRepaymentDay = this.createNewMeetingForRepaymentDay(new LocalDate(disbursementDate), loanAccountMeetingDto, client);
    //                }
    //
    //                checkPermissionForCreate(accountState.getValue(), userContext, userContext.getBranchId(), userContext.getId());
    //
    //                List<FeeDto> additionalFees = new ArrayList<FeeDto>();
    //                List<FeeDto> defaultFees = new ArrayList<FeeDto>();
    //
    //                new LoanProductService().getDefaultAndAdditionalFees(loanProductId, userContext, defaultFees, additionalFees);
    //
    //                FundBO fund = null;
    //                List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
    //                boolean isRedone = false;
    //
    //                // FIXME - keithw - tidy up constructor and use domain concepts rather than primitives, e.g. money v double, loanpurpose v integer.
    //
    //                LoanBO loan = new LoanBO(userContext, loanProduct, client, accountState, loanAmount, defaultNumOfInstallments,
    //                        disbursementDate, interestDeductedAtDisbursement, interestRate, gracePeriodDuration, fund, defaultFees,
    //                        customFields, isRedone, maxLoanAmount, minLoanAmount,
    //                        loanProduct.getMaxInterestRate(), loanProduct.getMinInterestRate(),
    //                        maxNoOfInstall, minNoOfInstall, isRepaymentIndepOfMeetingEnabled, newMeetingForRepaymentDay);
    //                loan.setBusinessActivityId(loanDetail.getLoanPurpose());
    //
    //                PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
    //                AccountStateEntity newAccountState = new AccountStateEntity(accountState);
    //                AccountStatusChangeHistoryEntity statusChange = new AccountStatusChangeHistoryEntity(null, newAccountState, loggedInUser, loan);
    //
    //                this.transactionHelper.startTransaction();
    //                loan.addAccountStatusChangeHistory(statusChange);
    //                this.loanDao.save(loan);
    //                this.transactionHelper.flushSession();
    //                String globalAccountNum = loan.generateId(userContext.getBranchGlobalNum());
    //                loan.setGlobalAccountNum(globalAccountNum);
    //                this.loanDao.save(loan);
    //                this.transactionHelper.commitTransaction();
    //
    //                createdLoanAccountNumbers.add(loan.getGlobalAccountNum());
    //            } catch (ServiceException e) {
    //                this.transactionHelper.rollbackTransaction();
    //                throw new MifosRuntimeException(e);
    //            } catch (PersistenceException e) {
    //                this.transactionHelper.rollbackTransaction();
    //                throw new MifosRuntimeException(e);
    //            } catch (AccountException e) {
    //                this.transactionHelper.rollbackTransaction();
    //                throw new BusinessRuleException(e.getKey(), e);
    //            }
    }
    return createdLoanAccountNumbers;
}
Also used : MeetingBO(org.mifos.application.meeting.business.MeetingBO) ArrayList(java.util.ArrayList) WeeklySchedule(org.mifos.clientportfolio.loan.service.WeeklySchedule) LocalDate(org.joda.time.LocalDate) RankOfDay(org.mifos.application.meeting.util.helpers.RankOfDay) CreateLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount) CreateAccountPenaltyDto(org.mifos.dto.domain.CreateAccountPenaltyDto) OfficeBO(org.mifos.customers.office.business.OfficeBO) ConfigurationBusinessService(org.mifos.config.business.service.ConfigurationBusinessService) CustomerBO(org.mifos.customers.business.CustomerBO) CreateAccountFeeDto(org.mifos.dto.domain.CreateAccountFeeDto) MonthlyOnWeekOfMonthSchedule(org.mifos.clientportfolio.loan.service.MonthlyOnWeekOfMonthSchedule) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) LoanOfferingFeesEntity(org.mifos.accounts.productdefinition.business.LoanOfferingFeesEntity) UserContext(org.mifos.security.util.UserContext) CreateAccountFeeDto(org.mifos.dto.domain.CreateAccountFeeDto) FeeDto(org.mifos.dto.domain.FeeDto) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) CreateLoanRequest(org.mifos.dto.domain.CreateLoanRequest) BigDecimal(java.math.BigDecimal) WeekDay(org.mifos.application.meeting.util.helpers.WeekDay) RecurringSchedule(org.mifos.clientportfolio.loan.service.RecurringSchedule) MonthlyOnDayOfMonthSchedule(org.mifos.clientportfolio.loan.service.MonthlyOnDayOfMonthSchedule) MeetingDetailsEntity(org.mifos.application.meeting.business.MeetingDetailsEntity) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) LoanAccountCashFlow(org.mifos.clientportfolio.newloan.applicationservice.LoanAccountCashFlow) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) LoanCreationResultDto(org.mifos.dto.screen.LoanCreationResultDto)

Example 3 with CreateLoanAccount

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

the class LoanAccountRESTController method createLoanAccount.

@RequestMapping(value = "/account/loan/create", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> createLoanAccount(@RequestBody String request) throws Throwable {
    ObjectMapper om = createLoanAccountMapping();
    Map<String, String> map = new HashMap<String, String>();
    CreationLoanAccountDto creationDetails = null;
    try {
        creationDetails = om.readValue(request, CreationLoanAccountDto.class);
    } catch (JsonMappingException e) {
        e.getCause();
    }
    loanValidator(creationDetails);
    List<QuestionGroupDetail> questionGroups = new ArrayList<QuestionGroupDetail>();
    LoanCreationResultDto loanResult = null;
    LoanBO loanInfo = null;
    CreateLoanAccount loanAccount = createLoan(creationDetails);
    if (creationDetails.getGlim()) {
        List<GroupMemberAccountDto> memberAccounts = creationDetails.glimsAsGroupMemberAccountDto(creationDetails.getGlimAccounts());
        CreateGlimLoanAccount createGroupLoanAccount = new CreateGlimLoanAccount(memberAccounts, creationDetails.getLoanAmount(), loanAccount);
        loanResult = loanAccountServiceFacade.createGroupLoanWithIndividualMonitoring(createGroupLoanAccount, questionGroups, null);
        List<LoanBO> individuals = loanDao.findIndividualLoans(loanResult.getAccountId());
        for (int i = 0; i < individuals.size(); i++) {
            map.put("individualCustomer[" + i + "]", individuals.get(i).getCustomer().getDisplayName());
            map.put("individualAccount[" + i + "]", individuals.get(i).getGlobalAccountNum());
            map.put("individualAmmount[" + i + "]", individuals.get(i).getLoanAmount().toString());
        }
    } else {
        loanResult = loanAccountServiceFacade.createLoan(loanAccount, questionGroups, null);
    }
    loanInfo = loanDao.findByGlobalAccountNum(loanResult.getGlobalAccountNum());
    map.put("status", "success");
    map.put("accountNum", loanInfo.getGlobalAccountNum());
    map.put("GLIM", creationDetails.getGlim().toString());
    map.put("customer", loanInfo.getCustomer().getDisplayName());
    map.put("loanAmmount", loanInfo.getLoanAmount().toString());
    map.put("noOfInstallments", loanInfo.getNoOfInstallments().toString());
    map.put("externalId", loanInfo.getExternalId());
    return map;
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) HashMap(java.util.HashMap) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) GroupMemberAccountDto(org.mifos.clientportfolio.newloan.applicationservice.GroupMemberAccountDto) CreateLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) LoanCreationResultDto(org.mifos.dto.screen.LoanCreationResultDto) CreateGlimLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateGlimLoanAccount) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) CreationLoanAccountDto(org.mifos.application.servicefacade.CreationLoanAccountDto) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with CreateLoanAccount

use of org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount 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 5 with CreateLoanAccount

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

the class GroupLoanAccountController method createGroupLoanMembers.

private List<CreateLoanAccount> createGroupLoanMembers(Integer accountState, LoanAccountFormBean formBean, LocalDate disbursementDate, RecurringSchedule recurringSchedule, Map<String, List<CreateAccountFeeDto>> accountFees, List<CreateAccountPenaltyDto> accountPenalties, BigDecimal loanAmount, BigDecimal minAllowedLoanAmount, BigDecimal maxAllowedLoanAmount) {
    List<CreateLoanAccount> memberAccounts = new ArrayList<CreateLoanAccount>();
    int index = 0;
    for (Boolean clientSelected : formBean.getClientSelectForGroup()) {
        if (clientSelected != null && clientSelected.booleanValue()) {
            String clientGlobalId = formBean.getClientGlobalId()[index];
            CreateLoanAccount memberAccount = prepareGroupLoanAccountMember(accountState, formBean, disbursementDate, recurringSchedule, accountFees.get(clientGlobalId), accountPenalties, BigDecimal.valueOf(formBean.getClientAmount()[index].doubleValue()), minAllowedLoanAmount, maxAllowedLoanAmount, index);
            memberAccounts.add(memberAccount);
        }
        index++;
    }
    return memberAccounts;
}
Also used : CreateLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount) ArrayList(java.util.ArrayList)

Aggregations

CreateLoanAccount (org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount)17 ArrayList (java.util.ArrayList)15 CreateAccountPenaltyDto (org.mifos.dto.domain.CreateAccountPenaltyDto)14 BigDecimal (java.math.BigDecimal)13 LocalDate (org.joda.time.LocalDate)13 RecurringSchedule (org.mifos.clientportfolio.loan.service.RecurringSchedule)12 CreateAccountFeeDto (org.mifos.dto.domain.CreateAccountFeeDto)12 MeetingBO (org.mifos.application.meeting.business.MeetingBO)8 MifosUser (org.mifos.security.MifosUser)6 HashMap (java.util.HashMap)5 List (java.util.List)5 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)5 LoanCreationResultDto (org.mifos.dto.screen.LoanCreationResultDto)5 Date (java.util.Date)4 DateTime (org.joda.time.DateTime)4 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)4 LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)4 LoanBO (org.mifos.accounts.loan.business.LoanBO)3 CreateGlimLoanAccount (org.mifos.clientportfolio.newloan.applicationservice.CreateGlimLoanAccount)3 GroupMemberAccountDto (org.mifos.clientportfolio.newloan.applicationservice.GroupMemberAccountDto)3