Search in sources :

Example 1 with CollectionSheetCustomerLoanDto

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;
}
Also used : HashMap(java.util.HashMap) CollectionSheetCustomerLoanDto(org.mifos.application.servicefacade.CollectionSheetCustomerLoanDto) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Comparator(java.util.Comparator)

Example 2 with CollectionSheetCustomerLoanDto

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);
        }
    }
}
Also used : CollectionSheetCustomerLoanDto(org.mifos.application.servicefacade.CollectionSheetCustomerLoanDto) ArrayList(java.util.ArrayList) Comparator(java.util.Comparator)

Example 3 with CollectionSheetCustomerLoanDto

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);
        }
    }
}
Also used : CollectionSheetCustomerLoanDto(org.mifos.application.servicefacade.CollectionSheetCustomerLoanDto) ArrayList(java.util.ArrayList)

Example 4 with CollectionSheetCustomerLoanDto

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")));
}
Also used : CollectionSheetCustomerLoanDto(org.mifos.application.servicefacade.CollectionSheetCustomerLoanDto) List(java.util.List) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with CollectionSheetCustomerLoanDto

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")));
}
Also used : CollectionSheetCustomerLoanDto(org.mifos.application.servicefacade.CollectionSheetCustomerLoanDto) List(java.util.List) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

CollectionSheetCustomerLoanDto (org.mifos.application.servicefacade.CollectionSheetCustomerLoanDto)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Comparator (java.util.Comparator)2 Date (java.util.Date)2 LocalDate (org.joda.time.LocalDate)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1