Search in sources :

Example 6 with MeetingFactory

use of org.mifos.application.meeting.business.MeetingFactory in project head by mifos.

the class GroupLoanAccountServiceFacadeWebTier method getGroupLoanScheduleDto.

@Override
public GroupLoanScheduleDto getGroupLoanScheduleDto(CreateGroupLoanAccount loanAccountInfo, List<CreateLoanAccount> memberDetails) {
    DateTime creationDate = new DateTime();
    // 0. verify member details for GLIM group accounts
    for (CreateLoanAccount groupMemberAccount : memberDetails) {
        ClientBO member = this.customerDao.findClientById(groupMemberAccount.getCustomerId());
        if (creationDate.isBefore(new DateTime(member.getCreatedDate()))) {
            throw new BusinessRuleException("errors.cannotCreateLoan.because.clientsAreCreatedInFuture");
        }
    }
    // 1. assemble loan details
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    OfficeBO userOffice = this.officeDao.findOfficeById(user.getBranchId());
    PersonnelBO createdBy = this.personnelDao.findPersonnelById(userContext.getId());
    CustomerBO customer = this.customerDao.findCustomerById(loanAccountInfo.getGroupLoanAccountDetails().getCustomerId());
    if (customer.isGroup()) {
        customer = this.customerDao.findGroupBySystemId(customer.getGlobalCustNum());
    }
    // assemble
    LoanAccountDetail loanAccountDetail = assembleLoanAccountDetail(loanAccountInfo);
    List<AccountFeesEntity> accountFeeEntities = assembleAccountFees(loanAccountInfo.getGroupLoanAccountDetails().getAccountFees());
    List<AccountPenaltiesEntity> accountPenaltyEntities = assembleAccountPenalties(loanAccountInfo.getGroupLoanAccountDetails().getAccountPenalties());
    LoanProductOverridenDetail overridenDetail = new LoanProductOverridenDetail(loanAccountDetail.getLoanAmount(), loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), loanAccountInfo.getGroupLoanAccountDetails().getInterestRate(), loanAccountInfo.getGroupLoanAccountDetails().getNumberOfInstallments(), loanAccountInfo.getGroupLoanAccountDetails().getGraceDuration(), accountFeeEntities, accountPenaltyEntities);
    Integer interestDays = Integer.valueOf(AccountingRules.getNumberOfInterestDays().intValue());
    boolean loanScheduleIndependentOfCustomerMeetingEnabled = loanAccountInfo.getGroupLoanAccountDetails().isRepaymentScheduleIndependentOfCustomerMeeting();
    LoanScheduleConfiguration configuration = new LoanScheduleConfiguration(loanScheduleIndependentOfCustomerMeetingEnabled, interestDays);
    MeetingBO repaymentDayMeeting = null;
    if (loanScheduleIndependentOfCustomerMeetingEnabled) {
        repaymentDayMeeting = this.createNewMeetingForRepaymentDay(loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), loanAccountInfo.getGroupLoanAccountDetails(), loanAccountDetail.getCustomer());
    } else {
        MeetingDto customerMeetingDto = customer.getCustomerMeetingValue().toDto();
        repaymentDayMeeting = new MeetingFactory().create(customerMeetingDto);
        Short recurAfter = loanAccountDetail.getLoanProduct().getLoanOfferingMeeting().getMeeting().getRecurAfter();
        repaymentDayMeeting.getMeetingDetails().setRecurAfter(recurAfter);
    }
    List<DateTime> loanScheduleDates = new ArrayList<DateTime>();
    LoanSchedule loanSchedule = assembleLoanSchedule(loanAccountDetail.getCustomer(), loanAccountDetail.getLoanProduct(), overridenDetail, configuration, repaymentDayMeeting, userOffice, loanScheduleDates, loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), new ArrayList<Number>());
    // 2. create loan
    InstallmentRange installmentRange = new MaxMinNoOfInstall(loanAccountInfo.getGroupLoanAccountDetails().getMinAllowedNumberOfInstallments().shortValue(), loanAccountInfo.getGroupLoanAccountDetails().getMaxAllowedNumberOfInstallments().shortValue(), null);
    AmountRange amountRange = new MaxMinLoanAmount(loanAccountInfo.getGroupLoanAccountDetails().getMaxAllowedLoanAmount().doubleValue(), loanAccountInfo.getGroupLoanAccountDetails().getMinAllowedLoanAmount().doubleValue(), null);
    creationDate = loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate().toDateMidnight().toDateTime();
    CreationDetail creationDetail = new CreationDetail(creationDate, Integer.valueOf(user.getUserId()));
    LoanBO loan = LoanBO.openGroupLoanAccount(loanAccountDetail.getLoanProduct(), loanAccountDetail.getCustomer(), repaymentDayMeeting, loanSchedule, loanAccountDetail.getAccountState(), loanAccountDetail.getFund(), overridenDetail, configuration, installmentRange, amountRange, creationDetail, createdBy);
    loan.setBusinessActivityId(loanAccountInfo.getGroupLoanAccountDetails().getLoanPurposeId());
    loan.setExternalId(loanAccountInfo.getGroupLoanAccountDetails().getExternalId());
    loan.setCollateralNote(loanAccountInfo.getGroupLoanAccountDetails().getCollateralNotes());
    loan.setCollateralTypeId(loanAccountInfo.getGroupLoanAccountDetails().getCollateralTypeId());
    loan.markAsCreatedWithBackdatedPayments();
    //set up predefined loan account for importing loans
    if (loanAccountInfo.getGroupLoanAccountDetails().getPredefinedAccountNumber() != null) {
        loan.setGlobalAccountNum(loanAccountInfo.getGroupLoanAccountDetails().getPredefinedAccountNumber());
    }
    // for GLIM loans only
    List<CreateLoanAccount> individualMembersOfGroupLoan = new ArrayList<CreateLoanAccount>();
    List<BigDecimal> radio = new ArrayList<BigDecimal>(loan.getNoOfInstallments());
    List<LoanProductOverridenDetail> memberOverridenDetails = new ArrayList<LoanProductOverridenDetail>();
    List<LoanSchedule> memberLoanSchedules = new ArrayList<LoanSchedule>();
    List<ClientBO> clients = new ArrayList<ClientBO>();
    for (CreateLoanAccount groupMemberAccount : memberDetails) {
        ClientBO member = this.customerDao.findClientById(groupMemberAccount.getCustomerId());
        Money loanAmount = new Money(loanAccountDetail.getLoanProduct().getCurrency(), groupMemberAccount.getLoanAmount());
        List<CreateAccountPenaltyDto> defaultAccountPenalties = new ArrayList<CreateAccountPenaltyDto>();
        radio.add(loanAmount.divide(loan.getLoanAmount()));
        int memberCount = memberDetails.size();
        for (CreateAccountPenaltyDto createAccountPenaltyDto : loanAccountInfo.getGroupLoanAccountDetails().getAccountPenalties()) {
            Integer penaltyId = createAccountPenaltyDto.getPenaltyId();
            String amount = createAccountPenaltyDto.getAmount();
            PenaltyBO penaltyBO = this.penaltyDao.findPenaltyById(penaltyId.shortValue());
            if (penaltyBO instanceof AmountPenaltyBO) {
                amount = String.valueOf(Double.valueOf(createAccountPenaltyDto.getAmount()) / memberCount);
            }
            defaultAccountPenalties.add(new CreateAccountPenaltyDto(penaltyId, amount));
        }
        List<AccountFeesEntity> feeEntities = assembleAccountFees(groupMemberAccount.getAccountFees());
        List<AccountPenaltiesEntity> penaltyEntities = assembleAccountPenalties(defaultAccountPenalties);
        LoanProductOverridenDetail memberOverridenDetail = new LoanProductOverridenDetail(loanAmount, feeEntities, overridenDetail, penaltyEntities);
        LoanSchedule memberSchedule = assembleLoanSchedule(member, loanAccountDetail.getLoanProduct(), memberOverridenDetail, configuration, repaymentDayMeeting, userOffice, new ArrayList<DateTime>(), loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), new ArrayList<Number>());
        memberOverridenDetails.add(memberOverridenDetail);
        memberLoanSchedules.add(memberSchedule);
        clients.add(member);
        individualMembersOfGroupLoan.add(groupMemberAccount);
    }
    //for original schedule persisting
    List<LoanBO> memberLoans = new ArrayList<LoanBO>();
    int index = 0;
    for (CreateLoanAccount groupMemberAccount : individualMembersOfGroupLoan) {
        LoanBO memberLoan = LoanBO.openGroupLoanForAccount(loan, loanAccountDetail.getLoanProduct(), clients.get(index), repaymentDayMeeting, memberLoanSchedules.get(index), memberOverridenDetails.get(index), configuration, installmentRange, amountRange, creationDetail, createdBy, Boolean.TRUE);
        if (groupMemberAccount.getLoanPurposeId() > 0) {
            memberLoan.setBusinessActivityId(groupMemberAccount.getLoanPurposeId());
        }
        memberLoan.markAsCreatedWithBackdatedPayments();
        memberLoans.add(memberLoan);
        index++;
    }
    // update loan schedule for Group Loan Account
    loanSchedule = this.loanScheduleService.generateGroupLoanSchedule(loanAccountDetail.getLoanProduct(), repaymentDayMeeting, loanSchedule, memberLoanSchedules, loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), overridenDetail, configuration, userOffice.getOfficeId(), loanAccountDetail.getCustomer(), accountFeeEntities);
    fixMemberAndParentInstallmentDetails(loan, memberLoans);
    // translate schedules to dto form
    Map<Integer, LoanScheduleEntity> parentScheduleEntities = loan.getLoanScheduleEntityMap();
    List<LoanCreationInstallmentDto> parentInstallments = new ArrayList<LoanCreationInstallmentDto>();
    Map<Integer, List<LoanCreationInstallmentDto>> memberInstallments = new HashMap<Integer, List<LoanCreationInstallmentDto>>();
    for (CreateLoanAccount member : memberDetails) {
        memberInstallments.put(member.getCustomerId(), new ArrayList<LoanCreationInstallmentDto>());
    }
    Short digitsAfterDecimal = AccountingRules.getDigitsAfterDecimal();
    for (Integer installmentId : parentScheduleEntities.keySet()) {
        LoanScheduleEntity loanScheduleEntity = parentScheduleEntities.get(installmentId);
        parentInstallments.add(loanScheduleEntity.toLoanCreationInstallmentDto(digitsAfterDecimal));
        for (LoanBO memberLoan : memberLoans) {
            LoanScheduleEntity memberLoanScheduleEntity = memberLoan.getLoanScheduleEntityMap().get(installmentId);
            memberInstallments.get(memberLoan.getCustomer().getCustomerId()).add(memberLoanScheduleEntity.toLoanCreationInstallmentDto(digitsAfterDecimal));
        }
    }
    GroupLoanScheduleDto groupScheduleDto = new GroupLoanScheduleDto(customer.getDisplayName(), Double.valueOf(loan.getLoanAmount().getAmountDoubleValue()), loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), loan.getGraceType().getValue().intValue(), parentInstallments);
    groupScheduleDto.setMemberSchedules(new HashMap<Integer, LoanScheduleDto>());
    for (LoanBO memberLoan : memberLoans) {
        Integer id = memberLoan.getCustomer().getCustomerId();
        LoanScheduleDto memberScheduleDto = new LoanScheduleDto(memberLoan.getCustomer().getDisplayName(), Double.valueOf(memberLoan.getLoanAmount().getAmountDoubleValue()), loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), loan.getGraceType().getValue().intValue(), memberInstallments.get(id));
        groupScheduleDto.getMemberSchedules().put(id, memberScheduleDto);
    }
    return groupScheduleDto;
}
Also used : HashMap(java.util.HashMap) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ClientBO(org.mifos.customers.client.business.ClientBO) ArrayList(java.util.ArrayList) MeetingFactory(org.mifos.application.meeting.business.MeetingFactory) DateTime(org.joda.time.DateTime) CreateLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ArrayList(java.util.ArrayList) List(java.util.List) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) AmountPenaltyBO(org.mifos.accounts.penalties.business.AmountPenaltyBO) LoanSchedule(org.mifos.clientportfolio.newloan.domain.LoanSchedule) LoanBO(org.mifos.accounts.loan.business.LoanBO) LoanScheduleDto(org.mifos.dto.screen.LoanScheduleDto) GroupLoanScheduleDto(org.mifos.dto.screen.GroupLoanScheduleDto) LoanAccountDetail(org.mifos.clientportfolio.newloan.domain.LoanAccountDetail) MaxMinLoanAmount(org.mifos.accounts.loan.business.MaxMinLoanAmount) LoanProductOverridenDetail(org.mifos.clientportfolio.newloan.domain.LoanProductOverridenDetail) LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) AccountPenaltiesEntity(org.mifos.accounts.business.AccountPenaltiesEntity) LoanScheduleConfiguration(org.mifos.clientportfolio.newloan.domain.LoanScheduleConfiguration) Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) CreateAccountPenaltyDto(org.mifos.dto.domain.CreateAccountPenaltyDto) InstallmentRange(org.mifos.accounts.productdefinition.business.InstallmentRange) AmountRange(org.mifos.accounts.productdefinition.business.AmountRange) CustomerBO(org.mifos.customers.business.CustomerBO) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) CreationDetail(org.mifos.clientportfolio.newloan.domain.CreationDetail) LoanCreationInstallmentDto(org.mifos.dto.domain.LoanCreationInstallmentDto) BigDecimal(java.math.BigDecimal) MeetingDto(org.mifos.dto.domain.MeetingDto) MaxMinNoOfInstall(org.mifos.accounts.loan.business.MaxMinNoOfInstall) AmountPenaltyBO(org.mifos.accounts.penalties.business.AmountPenaltyBO) GroupLoanScheduleDto(org.mifos.dto.screen.GroupLoanScheduleDto)

Example 7 with MeetingFactory

use of org.mifos.application.meeting.business.MeetingFactory in project head by mifos.

the class ClientServiceFacadeWebTier method createNewClient.

@Override
public CustomerDetailsDto createNewClient(ClientCreationDetail clientCreationDetail, MeetingDto meetingDto, List<SavingsDetailDto> allowedSavingProducts) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
    userContext.setBranchGlobalNum(userOffice.getGlobalOfficeNum());
    try {
        ClientBO client = null;
        List<AccountFeesEntity> feesForCustomerAccount = convertFeeViewsToAccountFeeEntities(clientCreationDetail.getFeesToApply());
        List<SavingsOfferingBO> selectedOfferings = new ArrayList<SavingsOfferingBO>();
        for (Short productId : clientCreationDetail.getSelectedSavingProducts()) {
            if (productId != null) {
                for (SavingsDetailDto savingsOffering : allowedSavingProducts) {
                    if (productId.equals(savingsOffering.getPrdOfferingId())) {
                        SavingsOfferingBO savingsProduct = savingsProductDao.findById(productId.intValue());
                        selectedOfferings.add(savingsProduct);
                    }
                }
            }
        }
        List<ClientInitialSavingsOfferingEntity> offeringsAssociatedInCreate = new ArrayList<ClientInitialSavingsOfferingEntity>();
        for (SavingsOfferingBO offering : selectedOfferings) {
            offeringsAssociatedInCreate.add(new ClientInitialSavingsOfferingEntity(null, offering));
        }
        Short personnelId = null;
        Short officeId = null;
        ClientNameDetailDto spouseNameDetailView = null;
        if (ClientRules.isFamilyDetailsRequired()) {
        //                actionForm.setFamilyDateOfBirth();
        //                actionForm.constructFamilyDetails();
        } else {
            spouseNameDetailView = clientCreationDetail.getSpouseFatherName();
        }
        String secondMiddleName = null;
        ClientNameDetailEntity clientNameDetailEntity = new ClientNameDetailEntity(null, secondMiddleName, clientCreationDetail.getClientNameDetailDto());
        ClientNameDetailEntity spouseFatherNameDetailEntity = null;
        if (spouseNameDetailView != null) {
            spouseFatherNameDetailEntity = new ClientNameDetailEntity(null, secondMiddleName, spouseNameDetailView);
        }
        ClientDetailEntity clientDetailEntity = new ClientDetailEntity();
        clientDetailEntity.updateClientDetails(clientCreationDetail.getClientPersonalDetailDto());
        DateTime dob = new DateTime(clientCreationDetail.getDateOfBirth());
        boolean trainedBool = clientCreationDetail.isTrained();
        DateTime trainedDateTime = null;
        if (clientCreationDetail.getTrainedDate() != null) {
            trainedDateTime = new DateTime(clientCreationDetail.getTrainedDate());
        }
        String clientFirstName = clientCreationDetail.getClientNameDetailDto().getFirstName();
        String clientLastName = clientCreationDetail.getClientNameDetailDto().getLastName();
        String secondLastName = clientCreationDetail.getClientNameDetailDto().getSecondLastName();
        CustomerStatus clientStatus = CustomerStatus.fromInt(clientCreationDetail.getClientStatus());
        PersonnelBO formedBy = this.personnelDao.findPersonnelById(clientCreationDetail.getFormedBy());
        Address address = null;
        if (clientCreationDetail.getAddress() != null) {
            AddressDto dto = clientCreationDetail.getAddress();
            address = new Address(dto.getLine1(), dto.getLine2(), dto.getLine3(), dto.getCity(), dto.getState(), dto.getCountry(), dto.getZip(), dto.getPhoneNumber());
        }
        if (YesNoFlag.YES.getValue().equals(clientCreationDetail.getGroupFlag())) {
            Integer parentGroupId = Integer.parseInt(clientCreationDetail.getParentGroupId());
            CustomerBO group = this.customerDao.findCustomerById(parentGroupId);
            if (group.getPersonnel() != null) {
                personnelId = group.getPersonnel().getPersonnelId();
            }
            officeId = group.getOffice().getOfficeId();
            client = ClientBO.createNewInGroupHierarchy(userContext, clientCreationDetail.getClientName(), clientStatus, new DateTime(clientCreationDetail.getMfiJoiningDate()), group, formedBy, clientNameDetailEntity, dob, clientCreationDetail.getGovernmentId(), trainedBool, trainedDateTime, clientCreationDetail.getGroupFlag(), clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, offeringsAssociatedInCreate, clientCreationDetail.getExternalId(), address, clientCreationDetail.getActivationDate());
            if (ClientRules.isFamilyDetailsRequired()) {
                client.setFamilyAndNameDetailSets(clientCreationDetail.getFamilyNames(), clientCreationDetail.getFamilyDetails());
            }
            this.customerService.createClient(client, client.getCustomerMeetingValue(), feesForCustomerAccount, selectedOfferings);
        } else {
            personnelId = clientCreationDetail.getLoanOfficerId();
            officeId = clientCreationDetail.getOfficeId();
            PersonnelBO loanOfficer = this.personnelDao.findPersonnelById(personnelId);
            OfficeBO office = this.officeDao.findOfficeById(officeId);
            int lastSearchIdCustomerValue = customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(officeId);
            MeetingBO clientMeeting = null;
            if (meetingDto != null) {
                clientMeeting = new MeetingFactory().create(meetingDto);
                clientMeeting.setUserContext(userContext);
            }
            client = ClientBO.createNewOutOfGroupHierarchy(userContext, clientCreationDetail.getClientName(), clientStatus, new DateTime(clientCreationDetail.getMfiJoiningDate()), office, loanOfficer, clientMeeting, formedBy, clientNameDetailEntity, dob, clientCreationDetail.getGovernmentId(), trainedBool, trainedDateTime, clientCreationDetail.getGroupFlag(), clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, offeringsAssociatedInCreate, clientCreationDetail.getExternalId(), address, lastSearchIdCustomerValue);
            if (ClientRules.isFamilyDetailsRequired()) {
                client.setFamilyAndNameDetailSets(clientCreationDetail.getFamilyNames(), clientCreationDetail.getFamilyDetails());
            }
            try {
                personnelDao.checkAccessPermission(userContext, client.getOfficeId(), client.getLoanOfficerId());
            } catch (AccountException e) {
                throw new MifosRuntimeException("Access denied!", e);
            }
            this.customerService.createClient(client, clientMeeting, feesForCustomerAccount, selectedOfferings);
        }
        clientPhotoService.create(client.getCustomerId().longValue(), clientCreationDetail.getPicture());
        return new CustomerDetailsDto(client.getCustomerId(), client.getGlobalCustNum());
    } catch (CustomerException e) {
        throw new BusinessRuleException(e.getKey(), e.getValues(), e);
    }
}
Also used : Address(org.mifos.framework.business.util.Address) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ClientBO(org.mifos.customers.client.business.ClientBO) ArrayList(java.util.ArrayList) ClientInitialSavingsOfferingEntity(org.mifos.customers.client.business.ClientInitialSavingsOfferingEntity) MeetingFactory(org.mifos.application.meeting.business.MeetingFactory) DateTime(org.joda.time.DateTime) BusinessRuleException(org.mifos.service.BusinessRuleException) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) ClientNameDetailEntity(org.mifos.customers.client.business.ClientNameDetailEntity) ClientDetailEntity(org.mifos.customers.client.business.ClientDetailEntity) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerDetailsDto(org.mifos.dto.domain.CustomerDetailsDto) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) SavingsDetailDto(org.mifos.dto.domain.SavingsDetailDto) CustomerException(org.mifos.customers.exceptions.CustomerException) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) CustomerAddressDto(org.mifos.dto.domain.CustomerAddressDto) AddressDto(org.mifos.dto.domain.AddressDto) AccountException(org.mifos.accounts.exceptions.AccountException) CustomerStatus(org.mifos.customers.util.helpers.CustomerStatus) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 8 with MeetingFactory

use of org.mifos.application.meeting.business.MeetingFactory in project head by mifos.

the class LoanAccountServiceFacadeWebTier method createLoanSchedule.

@Override
public LoanScheduleDto createLoanSchedule(CreateLoanSchedule createLoanSchedule) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    // assemble into domain entities
    LoanOfferingBO loanProduct = this.loanProductDao.findById(createLoanSchedule.getProductId());
    CustomerBO customer = this.customerDao.findCustomerById(createLoanSchedule.getCustomerId());
    Money loanAmountDisbursed = new Money(loanProduct.getCurrency(), createLoanSchedule.getLoanAmount());
    List<AccountFeesEntity> accountFeeEntities = assembleAccountFees(createLoanSchedule.getAccountFeeEntities());
    LoanProductOverridenDetail overridenDetail = new LoanProductOverridenDetail(loanAmountDisbursed, createLoanSchedule.getDisbursementDate(), createLoanSchedule.getInterestRate(), createLoanSchedule.getNumberOfInstallments(), createLoanSchedule.getGraceDuration(), accountFeeEntities, new ArrayList<AccountPenaltiesEntity>());
    Integer interestDays = Integer.valueOf(AccountingRules.getNumberOfInterestDays().intValue());
    boolean loanScheduleIndependentOfCustomerMeetingEnabled = createLoanSchedule.isRepaymentIndependentOfCustomerMeetingSchedule();
    MeetingBO loanMeeting = null;
    if (loanScheduleIndependentOfCustomerMeetingEnabled) {
        loanMeeting = this.createNewMeetingForRepaymentDay(createLoanSchedule.getDisbursementDate(), createLoanSchedule, customer);
        if (loanProduct.isVariableInstallmentsAllowed()) {
            loanMeeting.setMeetingStartDate(createLoanSchedule.getDisbursementDate().toDateMidnight().toDate());
        }
    } else {
        MeetingDto customerMeetingDto = customer.getCustomerMeetingValue().toDto();
        loanMeeting = new MeetingFactory().create(customerMeetingDto);
        Short recurAfter = loanProduct.getLoanOfferingMeeting().getMeeting().getRecurAfter();
        loanMeeting.getMeetingDetails().setRecurAfter(recurAfter);
    }
    LoanScheduleConfiguration configuration = new LoanScheduleConfiguration(loanScheduleIndependentOfCustomerMeetingEnabled, interestDays);
    LoanSchedule loanSchedule = this.loanScheduleService.generate(loanProduct, customer, loanMeeting, overridenDetail, configuration, userContext.getBranchId(), accountFeeEntities, createLoanSchedule.getDisbursementDate());
    // translate to DTO form
    List<LoanCreationInstallmentDto> installments = new ArrayList<LoanCreationInstallmentDto>();
    Short digitsAfterDecimal = AccountingRules.getDigitsAfterDecimal();
    for (LoanScheduleEntity loanScheduleEntity : loanSchedule.getRoundedLoanSchedules()) {
        Integer installmentNumber = loanScheduleEntity.getInstallmentId().intValue();
        LocalDate dueDate = new LocalDate(loanScheduleEntity.getActionDate());
        String principal = loanScheduleEntity.getPrincipal().toString(digitsAfterDecimal);
        String interest = loanScheduleEntity.getInterest().toString(digitsAfterDecimal);
        String fees = loanScheduleEntity.getTotalFees().toString(digitsAfterDecimal);
        String penalty = "0.0";
        String total = loanScheduleEntity.getPrincipal().add(loanScheduleEntity.getInterest()).add(loanScheduleEntity.getTotalFees()).toString(digitsAfterDecimal);
        LoanCreationInstallmentDto installment = new LoanCreationInstallmentDto(installmentNumber, dueDate, Double.valueOf(principal), Double.valueOf(interest), Double.valueOf(fees), Double.valueOf(penalty), Double.valueOf(total));
        installments.add(installment);
    }
    return new LoanScheduleDto(customer.getDisplayName(), Double.valueOf(createLoanSchedule.getLoanAmount().doubleValue()), createLoanSchedule.getDisbursementDate(), loanProduct.getGraceType().getValue().intValue(), installments);
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) AccountPenaltiesEntity(org.mifos.accounts.business.AccountPenaltiesEntity) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ArrayList(java.util.ArrayList) MeetingFactory(org.mifos.application.meeting.business.MeetingFactory) LocalDate(org.joda.time.LocalDate) LoanScheduleConfiguration(org.mifos.clientportfolio.newloan.domain.LoanScheduleConfiguration) Money(org.mifos.framework.util.helpers.Money) CustomerBO(org.mifos.customers.business.CustomerBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) CreateLoanSchedule(org.mifos.clientportfolio.loan.service.CreateLoanSchedule) LoanSchedule(org.mifos.clientportfolio.newloan.domain.LoanSchedule) UserContext(org.mifos.security.util.UserContext) LoanScheduleDto(org.mifos.dto.screen.LoanScheduleDto) MifosUser(org.mifos.security.MifosUser) LoanCreationInstallmentDto(org.mifos.dto.domain.LoanCreationInstallmentDto) LoanProductOverridenDetail(org.mifos.clientportfolio.newloan.domain.LoanProductOverridenDetail) MeetingDto(org.mifos.dto.domain.MeetingDto) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO)

Aggregations

AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)8 MeetingBO (org.mifos.application.meeting.business.MeetingBO)8 MeetingFactory (org.mifos.application.meeting.business.MeetingFactory)8 MifosUser (org.mifos.security.MifosUser)8 UserContext (org.mifos.security.util.UserContext)8 DateTime (org.joda.time.DateTime)7 OfficeBO (org.mifos.customers.office.business.OfficeBO)7 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)7 ArrayList (java.util.ArrayList)6 MifosRuntimeException (org.mifos.core.MifosRuntimeException)6 CustomerBO (org.mifos.customers.business.CustomerBO)6 AccountException (org.mifos.accounts.exceptions.AccountException)5 ClientBO (org.mifos.customers.client.business.ClientBO)5 MeetingDto (org.mifos.dto.domain.MeetingDto)5 BusinessRuleException (org.mifos.service.BusinessRuleException)5 AccountPenaltiesEntity (org.mifos.accounts.business.AccountPenaltiesEntity)4 BigDecimal (java.math.BigDecimal)3 LocalDate (org.joda.time.LocalDate)3 LoanBO (org.mifos.accounts.loan.business.LoanBO)3 MaxMinLoanAmount (org.mifos.accounts.loan.business.MaxMinLoanAmount)3