Search in sources :

Example 6 with LoanBO

use of org.mifos.accounts.loan.business.LoanBO in project head by mifos.

the class CenterServiceFacadeWebTier method waiveChargesDue.

@Override
public void waiveChargesDue(Integer accountId, Integer waiveType) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        AccountBO account = new AccountBusinessService().getAccount(accountId);
        account.updateDetails(userContext);
        PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
        WaiveEnum waiveEnum = WaiveEnum.fromInt(waiveType);
        if (account.getPersonnel() != null) {
            new AccountBusinessService().checkPermissionForWaiveDue(waiveEnum, account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), account.getPersonnel().getPersonnelId());
        } else {
            new AccountBusinessService().checkPermissionForWaiveDue(waiveEnum, account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), userContext.getId());
        }
        try {
            this.transactionHelper.startTransaction();
            if (account instanceof LoanBO) {
                ((LoanBO) account).waiveAmountDue(waiveEnum);
            } else if (account instanceof SavingsBO) {
                ((SavingsBO) account).waiveNextDepositAmountDue(loggedInUser);
            } else {
                ((CustomerAccountBO) account).waiveAmountDue();
            }
            this.customerDao.save(account);
            this.transactionHelper.commitTransaction();
        } catch (Exception e) {
            this.transactionHelper.rollbackTransaction();
            throw new BusinessRuleException(account.getAccountId().toString(), e);
        } finally {
            this.transactionHelper.closeSession();
        }
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    } catch (ApplicationException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : WaiveEnum(org.mifos.accounts.util.helpers.WaiveEnum) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) ServiceException(org.mifos.framework.exceptions.ServiceException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ServiceException(org.mifos.framework.exceptions.ServiceException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 7 with LoanBO

use of org.mifos.accounts.loan.business.LoanBO in project head by mifos.

the class CenterServiceFacadeWebTier method removeAccountFee.

@Override
public void removeAccountFee(Integer accountId, Short feeId) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        AccountBO account = new AccountBusinessService().getAccount(accountId);
        if (account instanceof LoanBO) {
            List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(account.getAccountId());
            if (individualLoans != null && individualLoans.size() > 0) {
                for (LoanBO individual : individualLoans) {
                    individual.updateDetails(userContext);
                    individual.removeFeesAssociatedWithUpcomingAndAllKnownFutureInstallments(feeId, userContext.getId());
                    this.customerDao.save(individual);
                }
            }
        }
        account.updateDetails(userContext);
        if (account.getPersonnel() != null) {
            new AccountBusinessService().checkPermissionForRemoveFees(account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), account.getPersonnel().getPersonnelId());
        } else {
            new AccountBusinessService().checkPermissionForRemoveFees(account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), userContext.getId());
        }
        this.transactionHelper.startTransaction();
        account.removeFeesAssociatedWithUpcomingAndAllKnownFutureInstallments(feeId, userContext.getId());
        this.customerDao.save(account);
        this.transactionHelper.commitTransaction();
    } catch (ServiceException e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (AccountException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } catch (ApplicationException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ServiceException(org.mifos.framework.exceptions.ServiceException) AccountException(org.mifos.accounts.exceptions.AccountException) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 8 with LoanBO

use of org.mifos.accounts.loan.business.LoanBO in project head by mifos.

the class ClientServiceFacadeWebTier method getClientInformationDto.

@Override
public ClientInformationDto getClientInformationDto(String globalCustNum) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    ClientBO client = customerDao.findClientBySystemId(globalCustNum);
    if (client == null) {
        throw new MifosRuntimeException("Client not found for globalCustNum, levelId: " + globalCustNum);
    }
    try {
        personnelDao.checkAccessPermission(userContext, client.getOfficeId(), client.getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException("Access denied!", e);
    }
    ClientDisplayDto clientDisplay = this.customerDao.getClientDisplayDto(client.getCustomerId(), userContext);
    Integer clientId = client.getCustomerId();
    CustomerAccountSummaryDto customerAccountSummary = this.customerDao.getCustomerAccountSummaryDto(clientId);
    ClientPerformanceHistoryDto clientPerformanceHistory = assembleClientPerformanceHistoryDto(client.getClientPerformanceHistory(), clientId);
    CustomerAddressDto clientAddress = this.customerDao.getCustomerAddressDto(client);
    List<CustomerNoteDto> recentCustomerNotes = customerDao.getRecentCustomerNoteDto(clientId);
    List<CustomerFlagDto> customerFlags = customerDao.getCustomerFlagDto(client.getCustomerFlags());
    List<LoanDetailDto> loanDetail = customerDao.getLoanDetailDto(client.getOpenLoanAccounts());
    List<LoanDetailDto> groupLoanDetail = customerDao.getLoanDetailDto(client.getOpenGroupLoanAccounts());
    List<SavingsDetailDto> savingsDetail = customerDao.getSavingsDetailDto(clientId, userContext);
    CustomerMeetingDto customerMeeting = customerDao.getCustomerMeetingDto(client.getCustomerMeeting(), userContext);
    List<AccountBO> allClosedLoanAndSavingsAccounts = customerDao.retrieveAllClosedLoanAndSavingsAccounts(clientId);
    List<LoanDetailDto> closedLoanAccounts = new ArrayList<LoanDetailDto>();
    List<SavingsDetailDto> closedSavingsAccounts = new ArrayList<SavingsDetailDto>();
    for (AccountBO closedAccount : allClosedLoanAndSavingsAccounts) {
        if (closedAccount.getAccountType().getAccountTypeId() == AccountTypes.LOAN_ACCOUNT.getValue().intValue()) {
            closedLoanAccounts.add(new LoanDetailDto(closedAccount.getGlobalAccountNum(), ((LoanBO) closedAccount).getLoanOffering().getPrdOfferingName(), closedAccount.getAccountState().getId(), closedAccount.getAccountState().getName(), ((LoanBO) closedAccount).getLoanSummary().getOutstandingBalance().toString(), closedAccount.getTotalAmountDue().toString(), closedAccount.getTotalAmountInArrears().toString()));
        } else {
            closedSavingsAccounts.add(new SavingsDetailDto(closedAccount.getGlobalAccountNum(), ((SavingsBO) closedAccount).getSavingsOffering().getPrdOfferingName(), closedAccount.getAccountState().getId(), closedAccount.getAccountState().getName(), ((SavingsBO) closedAccount).getSavingsBalance().toString()));
        }
    }
    Boolean activeSurveys = Boolean.FALSE;
    //        Boolean activeSurveys = new SurveysPersistence().isActiveSurveysForSurveyType(SurveyType.CLIENT);
    List<SurveyDto> customerSurveys = new ArrayList<SurveyDto>();
    List<LoanDetailDto> guarantedLoanAccounts = new ArrayList<LoanDetailDto>();
    try {
        List<GuarantyEntity> guaranties = legacyAccountDao.getGuarantyByGurantorId(clientId);
        if (guaranties != null && guaranties.size() > 0) {
            for (GuarantyEntity guaranty : guaranties) {
                if (guaranty != null && guaranty.getState() != null && guaranty.getState()) {
                    LoanBO loan = loanDao.findById(guaranty.getLoanId());
                    guarantedLoanAccounts.add(new LoanDetailDto(loan.getGlobalAccountNum(), loan.getLoanOffering().getPrdOfferingName(), loan.getAccountState().getId(), loan.getAccountState().getName(), loan.getLoanSummary().getOutstandingBalance().toString(), loan.getTotalAmountDue().toString(), loan.getAccountType().getAccountTypeId(), loan.getTotalAmountInArrears().toString()));
                }
            }
        }
    } catch (PersistenceException e) {
        throw new MifosRuntimeException("Can not get guaranted loan accounts", e);
    }
    return new ClientInformationDto(clientDisplay, customerAccountSummary, clientPerformanceHistory, clientAddress, recentCustomerNotes, customerFlags, loanDetail, groupLoanDetail, savingsDetail, customerMeeting, activeSurveys, customerSurveys, closedLoanAccounts, closedSavingsAccounts, guarantedLoanAccounts);
}
Also used : CustomerAccountSummaryDto(org.mifos.dto.domain.CustomerAccountSummaryDto) SurveyDto(org.mifos.dto.domain.SurveyDto) ClientBO(org.mifos.customers.client.business.ClientBO) ArrayList(java.util.ArrayList) CustomerAddressDto(org.mifos.dto.domain.CustomerAddressDto) GuarantyEntity(org.mifos.accounts.loan.business.GuarantyEntity) AccountBO(org.mifos.accounts.business.AccountBO) CustomerMeetingDto(org.mifos.dto.domain.CustomerMeetingDto) CustomerNoteDto(org.mifos.dto.domain.CustomerNoteDto) ClientPerformanceHistoryDto(org.mifos.dto.screen.ClientPerformanceHistoryDto) SavingsDetailDto(org.mifos.dto.domain.SavingsDetailDto) ClientDisplayDto(org.mifos.dto.screen.ClientDisplayDto) UserContext(org.mifos.security.util.UserContext) LoanDetailDto(org.mifos.dto.domain.LoanDetailDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) CustomerFlagDto(org.mifos.dto.domain.CustomerFlagDto) AccountException(org.mifos.accounts.exceptions.AccountException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ClientInformationDto(org.mifos.dto.screen.ClientInformationDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 9 with LoanBO

use of org.mifos.accounts.loan.business.LoanBO in project head by mifos.

the class CustomerBO method getDelinquentPortfolioAmount.

/*
     * This method is unused and is a candidate for removal.
     */
@Deprecated
public BigDecimal getDelinquentPortfolioAmount(MifosCurrency currency) {
    Money amountOverDue = new Money(currency);
    Money totalOutStandingAmount = new Money(currency);
    for (AccountBO accountBO : getAccounts()) {
        if (accountBO.getType() == AccountTypes.LOAN_ACCOUNT && ((LoanBO) accountBO).isAccountActive()) {
            amountOverDue = amountOverDue.add(((LoanBO) accountBO).getTotalPrincipalAmountInArrears());
            totalOutStandingAmount = totalOutStandingAmount.add(((LoanBO) accountBO).getLoanSummary().getOriginalPrincipal());
        }
    }
    if (totalOutStandingAmount.isNonZero()) {
        return amountOverDue.divide(totalOutStandingAmount);
    }
    return BigDecimal.ZERO;
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountBO(org.mifos.accounts.business.AccountBO) LoanBO(org.mifos.accounts.loan.business.LoanBO)

Example 10 with LoanBO

use of org.mifos.accounts.loan.business.LoanBO in project head by mifos.

the class CustomerServiceImpl method handleChangeInMeetingSchedule.

private void handleChangeInMeetingSchedule(CustomerBO customer, final List<Days> workingDays, final List<Holiday> orderedUpcomingHolidays) throws AccountException {
    boolean lsimEnabled = this.configurationHelper.isLoanScheduleRepaymentIndependentOfCustomerMeetingEnabled();
    Set<AccountBO> accounts = customer.getAccounts();
    for (AccountBO account : accounts) {
        if (account instanceof LoanBO && lsimEnabled) {
        // do not change schedules when LSIm is on for loan accounts
        } else {
            account.handleChangeInMeetingSchedule(workingDays, orderedUpcomingHolidays, customer.isTopOfHierarchy());
            customerDao.save(account);
        }
    }
    for (CustomerBO child : customer.getChildren()) {
        handleChangeInMeetingSchedule(child, workingDays, orderedUpcomingHolidays);
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) CustomerBO(org.mifos.customers.business.CustomerBO)

Aggregations

LoanBO (org.mifos.accounts.loan.business.LoanBO)215 ArrayList (java.util.ArrayList)76 Test (org.junit.Test)62 Money (org.mifos.framework.util.helpers.Money)60 UserContext (org.mifos.security.util.UserContext)45 MifosRuntimeException (org.mifos.core.MifosRuntimeException)42 Date (java.util.Date)37 AccountException (org.mifos.accounts.exceptions.AccountException)35 AccountBO (org.mifos.accounts.business.AccountBO)34 MifosUser (org.mifos.security.MifosUser)33 BigDecimal (java.math.BigDecimal)30 HashMap (java.util.HashMap)28 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)26 LocalDate (org.joda.time.LocalDate)23 PaymentData (org.mifos.accounts.util.helpers.PaymentData)22 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)22 PersistenceException (org.mifos.framework.exceptions.PersistenceException)21 ServiceException (org.mifos.framework.exceptions.ServiceException)19 BusinessRuleException (org.mifos.service.BusinessRuleException)19 LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)18