Search in sources :

Example 96 with LoanBO

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

the class PersonnelRESTController method addClientIfHasOverdueLoan.

private void addClientIfHasOverdueLoan(CustomerBO client, List<OverdueCustomer> overdueCustomers) {
    OverdueCustomer customerToAdd = null;
    Money amount = null;
    List<LoanBO> loans = client.isGroup() ? client.getOpenLoanAccountsAndGroupLoans() : client.getOpenLoanAccounts();
    for (LoanBO loan : loans) {
        if (loan.getTotalAmountInArrears() != null && loan.getTotalAmountInArrears().isNonZero()) {
            LoanInformationDto loanInfo = loanAccountServiceFacade.retrieveLoanInformation(loan.getGlobalAccountNum());
            if (loanInfo.isDisbursed()) {
                if (customerToAdd == null) {
                    customerToAdd = createOverdueCustomer(client);
                    overdueCustomers.add(customerToAdd);
                }
                Money partialAmount = loan.getRemainingPrincipalAmount();
                OverdueLoan overdueLoan = new OverdueLoan(loan.getTotalAmountInArrears().toString(), loan.getGlobalAccountNum(), loanInfo.getPrdOfferingName(), loan.getAccountState().getName(), new Integer(loan.getAccountState().getId()), loan.getTotalRepayableAmount().toString(), partialAmount.toString());
                if (amount == null) {
                    amount = partialAmount;
                } else {
                    amount = amount.add(partialAmount);
                }
                customerToAdd.getOverdueLoans().add(overdueLoan);
            }
        }
    }
    if (customerToAdd != null) {
        customerToAdd.setTotalCapitalOutstanding(amount == null ? "0" : amount.toString());
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) LoanBO(org.mifos.accounts.loan.business.LoanBO) LoanInformationDto(org.mifos.dto.screen.LoanInformationDto) OverdueLoan(org.mifos.dto.domain.OverdueLoan) OverdueCustomer(org.mifos.dto.domain.OverdueCustomer)

Example 97 with LoanBO

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

the class PersonnelRESTController method getLastRepayments.

@RequestMapping(value = "personnel/id-current/last-repayments", method = RequestMethod.GET)
@ResponseBody
public List<LastRepaymentDto> getLastRepayments() {
    List<LastRepaymentDto> lastRepayments = new ArrayList<LastRepaymentDto>();
    PersonnelBO loanOfficer = personnelDao.findPersonnelById(getCurrentPersonnel().getPersonnelId());
    List<CustomerBO> borrowers = new ArrayList<CustomerBO>();
    for (CustomerDetailDto group : this.customerDao.findGroupsUnderUser(loanOfficer)) {
        borrowers.add(customerDao.findGroupBySystemId(group.getGlobalCustNum()));
        for (ClientBO client : this.customerDao.findAllExceptClosedAndCancelledClientsUnderParent(group.getSearchId(), loanOfficer.getOffice().getOfficeId())) {
            borrowers.add(client);
        }
    }
    for (ClientBO client : this.customerDao.findAllExceptClosedAndCancelledClientsWithoutGroupForLoanOfficer(loanOfficer.getPersonnelId(), loanOfficer.getOffice().getOfficeId())) {
        borrowers.add(client);
    }
    for (CustomerBO borrower : borrowers) {
        List<LoanBO> loans = borrower.getOpenLoanAccountsAndGroupLoans();
        if (loans != null && loans.size() != 0) {
            LoanBO lastLoan = null;
            Date lastLoanDate = null;
            for (LoanBO loan : loans) {
                Date lastAction = null;
                for (AccountActionDateEntity accountAction : loan.getAccountActionDates()) {
                    if (lastAction == null || lastAction.before(accountAction.getActionDate())) {
                        lastAction = accountAction.getActionDate();
                    }
                }
                if (lastLoanDate == null || lastLoanDate.before(lastAction)) {
                    lastLoan = loan;
                    lastLoanDate = lastAction;
                }
            }
            if (lastLoan == null || lastLoanDate == null) {
                continue;
            }
            ClientDescriptionDto clientDescription = new ClientDescriptionDto(borrower.getCustomerId(), borrower.getDisplayName(), borrower.getGlobalCustNum(), borrower.getSearchId());
            LoanDetailDto loanDetails = new LoanDetailDto(lastLoan.getGlobalAccountNum(), lastLoan.getLoanOffering().getPrdOfferingName(), lastLoan.getAccountState().getId(), lastLoan.getAccountState().getName(), lastLoan.getLoanBalance().toString(), lastLoan.getTotalAmountDue().toString(), lastLoan.getAccountType().getAccountTypeId(), lastLoan.getTotalAmountInArrears().toString());
            LastRepaymentDto lastRepayment = new LastRepaymentDto(clientDescription, loanDetails, lastLoanDate);
            if (borrower instanceof GroupBO) {
                lastRepayment.setGroup(true);
            }
            lastRepayments.add(lastRepayment);
        }
    }
    return lastRepayments;
}
Also used : ClientBO(org.mifos.customers.client.business.ClientBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) LoanDetailDto(org.mifos.dto.domain.LoanDetailDto) ArrayList(java.util.ArrayList) ClientDescriptionDto(org.mifos.dto.domain.ClientDescriptionDto) Date(java.util.Date) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) LastRepaymentDto(org.mifos.dto.domain.LastRepaymentDto) CustomerDetailDto(org.mifos.dto.domain.CustomerDetailDto) CustomerBO(org.mifos.customers.business.CustomerBO) GroupBO(org.mifos.customers.group.business.GroupBO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 98 with LoanBO

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

the class GroupValidationTest method givenAnActiveLoanAccountExistsGroupTransferToCenterShouldFailValidation.

@Test
public void givenAnActiveLoanAccountExistsGroupTransferToCenterShouldFailValidation() {
    // setup
    CenterBO center = new CenterBuilder().build();
    GroupBO group = new GroupBuilder().withParentCustomer(center).build();
    LoanBO loan = new LoanAccountBuilder().activeInGoodStanding().build();
    group.addAccount(loan);
    // exercise test
    try {
        group.validateNoActiveAccountsExist();
        fail("should fail validation");
    } catch (CustomerException e) {
        assertThat(e.getKey(), is(CustomerConstants.ERRORS_HAS_ACTIVE_ACCOUNT));
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) LoanAccountBuilder(org.mifos.domain.builders.LoanAccountBuilder) GroupBuilder(org.mifos.domain.builders.GroupBuilder) LoanBO(org.mifos.accounts.loan.business.LoanBO) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) GroupBO(org.mifos.customers.group.business.GroupBO) Test(org.junit.Test)

Example 99 with LoanBO

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

the class PortfolioAtRiskCalculationIntegrationTest method testGeneratePortfolioAtRiskForTaskNoPayment.

@Test
public void testGeneratePortfolioAtRiskForTaskNoPayment() throws Exception {
    createInitialObject();
    StaticHibernateUtil.flushSession();
    group = TestObjectFactory.getGroup(group.getCustomerId());
    client = TestObjectFactory.getClient(client.getCustomerId());
    for (AccountBO account : group.getAccounts()) {
        if (account.getType() == AccountTypes.LOAN_ACCOUNT) {
            changeFirstInstallmentDate(account, 31);
            ((LoanBO) account).handleArrears();
        }
    }
    for (AccountBO account : client.getAccounts()) {
        if (account.getType() == AccountTypes.LOAN_ACCOUNT) {
            changeFirstInstallmentDate(account, 31);
            ((LoanBO) account).handleArrears();
        }
    }
    StaticHibernateUtil.flushSession();
    group = TestObjectFactory.getGroup(group.getCustomerId());
    double portfolioAtRisk = PortfolioAtRiskCalculation.generatePortfolioAtRiskForTask(group.getCustomerId(), group.getOffice().getOfficeId(), group.getSearchId() + ".%");
    Assert.assertEquals(1.0, portfolioAtRisk, DELTA);
    center = TestObjectFactory.getCenter(center.getCustomerId());
    group = TestObjectFactory.getGroup(group.getCustomerId());
    client = TestObjectFactory.getClient(client.getCustomerId());
    account1 = TestObjectFactory.getObject(AccountBO.class, account1.getAccountId());
    account2 = TestObjectFactory.getObject(AccountBO.class, account2.getAccountId());
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) Test(org.junit.Test)

Example 100 with LoanBO

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

the class LegacyLoanDao method getLoanAccountsActiveInGoodBadStanding.

@SuppressWarnings({ "cast", "unchecked" })
public List<LoanBO> getLoanAccountsActiveInGoodBadStanding(final Integer customerId) throws PersistenceException {
    List<LoanBO> activeLoanAccounts = new ArrayList<LoanBO>();
    try {
        HashMap<String, Object> queryParameters = new HashMap<String, Object>();
        queryParameters.put(LoanConstants.LOANACTIVEINGOODSTAND, AccountStates.LOANACC_ACTIVEINGOODSTANDING);
        queryParameters.put(LoanConstants.CUSTOMER, customerId);
        queryParameters.put(LoanConstants.LOANACTIVEINBADSTAND, AccountStates.LOANACC_BADSTANDING);
        queryParameters.put(LoanConstants.ACCOUNTTYPE_ID, AccountTypes.LOAN_ACCOUNT.getValue());
        List<LoanBO> customerLoans = (List<LoanBO>) executeNamedQuery(NamedQueryConstants.ACCOUNT_GETALLLOANBYCUSTOMER, queryParameters);
        if (customerLoans != null) {
            activeLoanAccounts = new ArrayList<LoanBO>(customerLoans);
        }
        return activeLoanAccounts;
    } catch (Exception e) {
        throw new PersistenceException(e);
    }
}
Also used : HashMap(java.util.HashMap) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ArrayList(java.util.ArrayList) List(java.util.List) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) HibernateException(org.hibernate.HibernateException)

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