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());
}
}
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;
}
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));
}
}
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());
}
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);
}
}
Aggregations