Search in sources :

Example 1 with WeeklySchedule

use of org.mifos.clientportfolio.loan.service.WeeklySchedule 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 2 with WeeklySchedule

use of org.mifos.clientportfolio.loan.service.WeeklySchedule in project head by mifos.

the class ImportLoansSavingsFacadeWebTier method saveLoans.

@Override
public ParsedLoansDto saveLoans(ParsedLoansDto parsedLoansDto) {
    List<CreateAccountFeeDto> defaultAccountFees = new ArrayList<CreateAccountFeeDto>();
    List<QuestionGroupDetail> questionGroupDetails = new ArrayList<QuestionGroupDetail>();
    List<CreateAccountPenaltyDto> defaultPenalties = new ArrayList<CreateAccountPenaltyDto>();
    for (ImportedLoanDetail detail : parsedLoansDto.getSuccessfullyParsedRows()) {
        LoanCreationLoanDetailsDto lcldd = loanAccountServiceFacade.retrieveLoanDetailsForLoanAccountCreation(detail.getCustomerId(), detail.getPrdOfferingId(), false);
        RecurringSchedule recurringSchedule = null;
        MeetingDto meetingDto = lcldd.getCustomerMeetingDetail();
        int meetingEvery = (lcldd.isRepaymentIndependentOfMeetingEnabled()) ? lcldd.getLoanOfferingMeetingDetail().getMeetingDetailsDto().getEvery() : meetingDto.getMeetingDetailsDto().getEvery();
        int loanRecurrenceTypeId = (lcldd.isRepaymentIndependentOfMeetingEnabled()) ? lcldd.getLoanOfferingMeetingDetail().getMeetingDetailsDto().getRecurrenceTypeId() : meetingDto.getMeetingDetailsDto().getRecurrenceTypeId();
        if (loanRecurrenceTypeId == 1) {
            recurringSchedule = new WeeklySchedule(meetingEvery, meetingDto.getMeetingDetailsDto().getRecurrenceDetails().getDayOfWeek());
        } else if (loanRecurrenceTypeId == 2) {
            if (meetingDto.getMeetingDetailsDto().getRecurrenceDetails().getWeekOfMonth().equals(0)) {
                recurringSchedule = new MonthlyOnDayOfMonthSchedule(meetingEvery, meetingDto.getMeetingDetailsDto().getRecurrenceDetails().getDayNumber());
            } else {
                recurringSchedule = new MonthlyOnWeekOfMonthSchedule(meetingEvery, meetingDto.getMeetingDetailsDto().getRecurrenceDetails().getWeekOfMonth(), meetingDto.getMeetingDetailsDto().getRecurrenceDetails().getDayOfWeek());
            }
        } else if (loanRecurrenceTypeId == 3) {
            recurringSchedule = new DailySchedule(meetingEvery);
        }
        CreateLoanAccount cla = new CreateLoanAccount(detail.getCustomerId(), new Integer(detail.getPrdOfferingId()), new Integer(detail.getStatus()), detail.getLoanAmount(), lcldd.getMinLoanAmount(), lcldd.getMaxLoanAmount(), detail.getInterestRate().doubleValue(), new LocalDate(detail.getDisbursalDate().getTime()), null, detail.getNumberOfInstallments(), lcldd.getMinNumberOfInstallments(), lcldd.getMaxNumberOfInstallments(), detail.getGracePeriod(), detail.getSourceOfFundId(), detail.getLoanPurposeId(), detail.getCollateralTypeId(), detail.getCollateralNotes(), detail.getExternalId(), lcldd.isRepaymentIndependentOfMeetingEnabled(), recurringSchedule, defaultAccountFees, defaultPenalties);
        cla.setPredefinedAccountNumber(detail.getAccountNumber());
        cla.setFlagId(detail.getFlag());
        this.loanAccountServiceFacade.createLoan(cla, questionGroupDetails, null);
    }
    return null;
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) ArrayList(java.util.ArrayList) WeeklySchedule(org.mifos.clientportfolio.loan.service.WeeklySchedule) LocalDate(org.joda.time.LocalDate) MeetingDto(org.mifos.dto.domain.MeetingDto) DailySchedule(org.mifos.clientportfolio.loan.service.DailySchedule) RecurringSchedule(org.mifos.clientportfolio.loan.service.RecurringSchedule) CreateLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount) CreateAccountPenaltyDto(org.mifos.dto.domain.CreateAccountPenaltyDto) MonthlyOnDayOfMonthSchedule(org.mifos.clientportfolio.loan.service.MonthlyOnDayOfMonthSchedule) CreateAccountFeeDto(org.mifos.dto.domain.CreateAccountFeeDto) LoanCreationLoanDetailsDto(org.mifos.dto.screen.LoanCreationLoanDetailsDto) MonthlyOnWeekOfMonthSchedule(org.mifos.clientportfolio.loan.service.MonthlyOnWeekOfMonthSchedule) ImportedLoanDetail(org.mifos.dto.domain.ImportedLoanDetail)

Aggregations

ArrayList (java.util.ArrayList)2 LocalDate (org.joda.time.LocalDate)2 MonthlyOnDayOfMonthSchedule (org.mifos.clientportfolio.loan.service.MonthlyOnDayOfMonthSchedule)2 MonthlyOnWeekOfMonthSchedule (org.mifos.clientportfolio.loan.service.MonthlyOnWeekOfMonthSchedule)2 RecurringSchedule (org.mifos.clientportfolio.loan.service.RecurringSchedule)2 WeeklySchedule (org.mifos.clientportfolio.loan.service.WeeklySchedule)2 CreateLoanAccount (org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount)2 CreateAccountFeeDto (org.mifos.dto.domain.CreateAccountFeeDto)2 CreateAccountPenaltyDto (org.mifos.dto.domain.CreateAccountPenaltyDto)2 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)2 BigDecimal (java.math.BigDecimal)1 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)1 FeeBO (org.mifos.accounts.fees.business.FeeBO)1 LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)1 LoanOfferingFeesEntity (org.mifos.accounts.productdefinition.business.LoanOfferingFeesEntity)1 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)1 MeetingBO (org.mifos.application.meeting.business.MeetingBO)1 MeetingDetailsEntity (org.mifos.application.meeting.business.MeetingDetailsEntity)1 RankOfDay (org.mifos.application.meeting.util.helpers.RankOfDay)1 WeekDay (org.mifos.application.meeting.util.helpers.WeekDay)1