use of org.mifos.application.servicefacade.CollectionSheetCustomerLoanDto in project head by mifos.
the class CollectionSheetDaoHibernate method findAllLoanRepaymentsForCustomerHierarchy.
/*
*
*/
@Override
@SuppressWarnings("unchecked")
public Map<Integer, List<CollectionSheetCustomerLoanDto>> findAllLoanRepaymentsForCustomerHierarchy(final Short branchId, final String searchId, final LocalDate transactionDate, final Integer customerAtTopOfHierarchyId) {
final Map<Integer, List<CollectionSheetCustomerLoanDto>> allLoanRepaymentsGroupedByCustomerId = new HashMap<Integer, List<CollectionSheetCustomerLoanDto>>();
final Map<String, Object> topOfHierarchyParameters = new HashMap<String, Object>();
topOfHierarchyParameters.put("BRANCH_ID", branchId);
topOfHierarchyParameters.put("CUSTOMER_ID", customerAtTopOfHierarchyId);
topOfHierarchyParameters.put("TRANSACTION_DATE", transactionDate.toString());
final List<CollectionSheetCustomerLoanDto> loanRepaymentsForCustomerAtTopOfHierarchy = executeNamedQueryWithResultTransformer("findLoanRepaymentsforCustomerAtTopOfHierarchyAsDto", topOfHierarchyParameters, CollectionSheetCustomerLoanDto.class);
if (loanRepaymentsForCustomerAtTopOfHierarchy != null) {
allLoanRepaymentsGroupedByCustomerId.put(customerAtTopOfHierarchyId, loanRepaymentsForCustomerAtTopOfHierarchy);
}
final Map<String, Object> queryParameters = new HashMap<String, Object>();
queryParameters.put("BRANCH_ID", branchId);
queryParameters.put("SEARCH_ID", searchId);
queryParameters.put("TRANSACTION_DATE", transactionDate.toString());
final List<CollectionSheetCustomerLoanDto> loanRepayments = executeNamedQueryWithResultTransformer("findLoanRepaymentsforCustomerHierarchyAsDto", queryParameters, CollectionSheetCustomerLoanDto.class);
for (CollectionSheetCustomerLoanDto customerLoan : loanRepayments) {
final Integer customerId = customerLoan.getCustomerId();
if (allLoanRepaymentsGroupedByCustomerId.containsKey(customerId)) {
final List<CollectionSheetCustomerLoanDto> loansForCustomer = allLoanRepaymentsGroupedByCustomerId.get(customerId);
Comparator<CollectionSheetCustomerLoanDto> comparator = new Comparator<CollectionSheetCustomerLoanDto>() {
@Override
public int compare(CollectionSheetCustomerLoanDto cseDto1, CollectionSheetCustomerLoanDto cseDto2) {
return cseDto1.getAccountId().compareTo(cseDto2.getAccountId());
}
};
Collections.sort(loansForCustomer, comparator);
if (Collections.binarySearch(loansForCustomer, customerLoan, comparator) < 0) {
loansForCustomer.add(customerLoan);
}
} else {
final List<CollectionSheetCustomerLoanDto> customerLoansForCustomer = new ArrayList<CollectionSheetCustomerLoanDto>();
customerLoansForCustomer.add(customerLoan);
allLoanRepaymentsGroupedByCustomerId.put(customerId, customerLoansForCustomer);
}
}
addInformationAboutActiveLoans(allLoanRepaymentsGroupedByCustomerId, queryParameters);
return allLoanRepaymentsGroupedByCustomerId;
}
use of org.mifos.application.servicefacade.CollectionSheetCustomerLoanDto in project head by mifos.
the class CollectionSheetDaoHibernate method addInformationAboutActiveLoans.
@SuppressWarnings("unchecked")
private void addInformationAboutActiveLoans(Map<Integer, List<CollectionSheetCustomerLoanDto>> allLoanRepaymentsGroupedByCustomerId, Map<String, Object> queryParameters) {
final List<CollectionSheetCustomerLoanDto> activeLoans = executeNamedQueryWithResultTransformer("findActiveLoansforCustomerHierarchyAsDto", queryParameters, CollectionSheetCustomerLoanDto.class);
for (CollectionSheetCustomerLoanDto customerLoan : activeLoans) {
final Integer customerId = customerLoan.getCustomerId();
if (allLoanRepaymentsGroupedByCustomerId.containsKey(customerId)) {
final List<CollectionSheetCustomerLoanDto> loansForCustomer = allLoanRepaymentsGroupedByCustomerId.get(customerId);
Comparator<CollectionSheetCustomerLoanDto> comparator = new Comparator<CollectionSheetCustomerLoanDto>() {
@Override
public int compare(CollectionSheetCustomerLoanDto cseDto1, CollectionSheetCustomerLoanDto cseDto2) {
return cseDto1.getAccountId().compareTo(cseDto2.getAccountId());
}
};
Collections.sort(loansForCustomer, comparator);
if (Collections.binarySearch(loansForCustomer, customerLoan, comparator) < 0) {
loansForCustomer.add(customerLoan);
}
} else {
final List<CollectionSheetCustomerLoanDto> customerLoansForCustomer = new ArrayList<CollectionSheetCustomerLoanDto>();
customerLoansForCustomer.add(customerLoan);
allLoanRepaymentsGroupedByCustomerId.put(customerId, customerLoansForCustomer);
}
}
}
use of org.mifos.application.servicefacade.CollectionSheetCustomerLoanDto in project head by mifos.
the class CollectionSheetDaoHibernate method populateLoanDisbursement.
private void populateLoanDisbursement(final Map<Integer, List<CollectionSheetCustomerLoanDto>> loanDisbursementsGroupedByCustomerId, final List<CollectionSheetCustomerLoanDto> allLoanDisbursements) {
for (CollectionSheetCustomerLoanDto loanDisbursementAccount : allLoanDisbursements) {
final Integer customerId = loanDisbursementAccount.getCustomerId();
final Integer accountId = loanDisbursementAccount.getAccountId();
Double amountDueAtDisbursement;
if (Constants.YES == loanDisbursementAccount.getPayInterestAtDisbursement()) {
amountDueAtDisbursement = findAmountDueWhenInterestIsDueAtDibursementTime(accountId);
} else {
amountDueAtDisbursement = legacyLoanDao.getFeeAmountAtDisbursement(accountId, Money.getDefaultCurrency()).getAmountDoubleValue();
}
loanDisbursementAccount.setAmountDueAtDisbursement(amountDueAtDisbursement);
if (loanDisbursementsGroupedByCustomerId.containsKey(customerId)) {
final List<CollectionSheetCustomerLoanDto> loanAccountList = loanDisbursementsGroupedByCustomerId.get(customerId);
loanAccountList.add(loanDisbursementAccount);
} else {
final List<CollectionSheetCustomerLoanDto> loanAccountList = new ArrayList<CollectionSheetCustomerLoanDto>();
loanAccountList.add(loanDisbursementAccount);
loanDisbursementsGroupedByCustomerId.put(customerId, loanAccountList);
}
}
}
use of org.mifos.application.servicefacade.CollectionSheetCustomerLoanDto in project head by mifos.
the class CollectionSheetDaoHibernateIntegrationTest method testShouldFindAllLoanRepaymentInCenterHierarchy.
@Test
@Ignore
public void testShouldFindAllLoanRepaymentInCenterHierarchy() {
// setup
Date startDate = new Date(System.currentTimeMillis());
loanOffering = TestObjectFactory.createLoanOffering("Loancfgb", "dhsq", ApplicableTo.GROUPS, startDate, PrdStatus.LOAN_ACTIVE, 300.0, 1.2, (short) 3, InterestType.FLAT, weeklyMeeting);
loan = TestObjectFactory.createLoanAccount("42423142341", group, AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, startDate, loanOffering);
final Integer customerAtTopOfHierarchyId = center.getCustomerId();
final Short branchId = center.getOffice().getOfficeId();
final String searchId = center.getSearchId() + ".%";
final LocalDate transactionDate = new LocalDate();
// exercise test
final Map<Integer, List<CollectionSheetCustomerLoanDto>> allLoanRepayments = collectionSheetDao.findAllLoanRepaymentsForCustomerHierarchy(branchId, searchId, transactionDate, customerAtTopOfHierarchyId);
// verification
Assert.assertNotNull(allLoanRepayments);
Assert.assertNotNull(allLoanRepayments.get(group.getCustomerId()));
List<CollectionSheetCustomerLoanDto> loansAgainstGroup = allLoanRepayments.get(group.getCustomerId());
Assert.assertThat(loansAgainstGroup.size(), is(1));
Assert.assertThat(loansAgainstGroup.get(0).getAccountId(), is(loan.getAccountId()));
Assert.assertThat(loansAgainstGroup.get(0).getAccountStateId(), is(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING.getValue()));
Assert.assertThat(loansAgainstGroup.get(0).getProductShortName(), is(loanOffering.getPrdOfferingShortName()));
Assert.assertThat(loansAgainstGroup.get(0).getTotalRepaymentDue(), is(Double.valueOf("112.00")));
}
use of org.mifos.application.servicefacade.CollectionSheetCustomerLoanDto in project head by mifos.
the class CollectionSheetDaoHibernateIntegrationTest method testShouldFindLoanAccountsInDisbursementState.
@Test
@Ignore
public void testShouldFindLoanAccountsInDisbursementState() {
// setup
Date startDate = new Date(System.currentTimeMillis());
loanOffering = TestObjectFactory.createLoanOffering("Loancfgb", "dhsq", ApplicableTo.GROUPS, startDate, PrdStatus.LOAN_ACTIVE, 300.0, 1.2, (short) 3, InterestType.FLAT, weeklyMeeting);
loan = TestObjectFactory.createLoanAccountWithDisbursement("42423142341", group, AccountState.LOAN_APPROVED, startDate, loanOffering, 1);
final Integer customerAtTopOfHierarchyId = center.getCustomerId();
final Short branchId = center.getOffice().getOfficeId();
final String searchId = center.getSearchId() + ".%";
final LocalDate transactionDate = new LocalDate();
// exercise test
final Map<Integer, List<CollectionSheetCustomerLoanDto>> allLoanDisbursements = collectionSheetDao.findLoanDisbursementsForCustomerHierarchy(branchId, searchId, transactionDate, customerAtTopOfHierarchyId);
// verification
Assert.assertNotNull(allLoanDisbursements);
final List<CollectionSheetCustomerLoanDto> loanDisbursements = allLoanDisbursements.get(group.getCustomerId());
Assert.assertThat(loanDisbursements.size(), is(1));
Assert.assertThat(loanDisbursements.get(0).getAccountId(), is(loan.getAccountId()));
Assert.assertThat(loanDisbursements.get(0).getAccountStateId(), is(AccountState.LOAN_APPROVED.getValue()));
Assert.assertThat(loanDisbursements.get(0).getCustomerId(), is(group.getCustomerId()));
Assert.assertThat(loanDisbursements.get(0).getPayInterestAtDisbursement(), is(Constants.NO));
Assert.assertThat(loanDisbursements.get(0).getTotalDisbursement(), is(Double.valueOf("300.0")));
Assert.assertThat(loanDisbursements.get(0).getAmountDueAtDisbursement(), is(Double.valueOf("30.0")));
}
Aggregations