Search in sources :

Example 46 with CustomerBO

use of org.mifos.customers.business.CustomerBO in project head by mifos.

the class LoanAccountRESTController method applyCharge.

@RequestMapping(value = "/account/loan/num-{globalAccountNum}/charge", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> applyCharge(@PathVariable String globalAccountNum, @RequestParam BigDecimal amount, @RequestParam Short feeId) throws Exception {
    validateAmount(amount);
    List<String> applicableFees = new ArrayList<String>();
    for (Map<String, String> feeMap : this.getApplicableFees(globalAccountNum).values()) {
        applicableFees.add(feeMap.get("feeId"));
    }
    validateFeeId(feeId, applicableFees);
    Map<String, String> map = new HashMap<String, String>();
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    LoanBO loan = loanDao.findByGlobalAccountNum(globalAccountNum);
    Integer accountId = loan.getAccountId();
    CustomerBO client = loan.getCustomer();
    String outstandingBeforeCharge = loan.getLoanSummary().getOutstandingBalance().toString();
    this.accountServiceFacade.applyCharge(accountId, feeId, amount.doubleValue(), false);
    DateTime today = new DateTime();
    map.put("status", "success");
    map.put("clientName", client.getDisplayName());
    map.put("clientNumber", client.getGlobalCustNum());
    map.put("loanDisplayName", loan.getLoanOffering().getPrdOfferingName());
    map.put("chargeDate", today.toLocalDate().toString());
    map.put("chargeTime", today.toLocalTime().toString());
    map.put("chargeAmount", Double.valueOf(amount.doubleValue()).toString());
    map.put("chargeMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
    map.put("outstandingBeforeCharge", outstandingBeforeCharge);
    map.put("outstandingAfterCharge", loan.getLoanSummary().getOutstandingBalance().toString());
    return map;
}
Also used : HashMap(java.util.HashMap) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser) DateTime(org.joda.time.DateTime) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 47 with CustomerBO

use of org.mifos.customers.business.CustomerBO 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 48 with CustomerBO

use of org.mifos.customers.business.CustomerBO in project head by mifos.

the class CustomerPersistenceIntegrationTest method testGetAllChildern.

@Test
public void testGetAllChildern() throws Exception {
    CustomerPersistence customerPersistence = new CustomerPersistence();
    center = createCenter();
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group1", CustomerStatus.GROUP_ACTIVE, center);
    client = TestObjectFactory.createClient("client1", CustomerStatus.CLIENT_ACTIVE, group);
    ClientBO client2 = TestObjectFactory.createClient("client2", CustomerStatus.CLIENT_CLOSED, group);
    ClientBO client3 = TestObjectFactory.createClient("client3", CustomerStatus.CLIENT_CANCELLED, group);
    ClientBO client4 = TestObjectFactory.createClient("client4", CustomerStatus.CLIENT_PENDING, group);
    List<CustomerBO> customerList = customerPersistence.getChildren(center.getSearchId(), center.getOffice().getOfficeId(), CustomerLevel.CLIENT, ChildrenStateType.ALL);
    Assert.assertEquals(new Integer("4").intValue(), customerList.size());
    for (CustomerBO customer : customerList) {
        if (customer.getCustomerId().equals(client2.getCustomerId())) {
            Assert.assertTrue(true);
        }
    }
//        TestObjectFactory.cleanUp(client2);
//        TestObjectFactory.cleanUp(client3);
//        TestObjectFactory.cleanUp(client4);
}
Also used : ClientBO(org.mifos.customers.client.business.ClientBO) CustomerBO(org.mifos.customers.business.CustomerBO) Test(org.junit.Test)

Example 49 with CustomerBO

use of org.mifos.customers.business.CustomerBO in project head by mifos.

the class CustomerPersistenceIntegrationTest method testGetChildernActiveAndHold.

@Test
public void testGetChildernActiveAndHold() throws Exception {
    CustomerPersistence customerPersistence = new CustomerPersistence();
    center = createCenter();
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group1", CustomerStatus.GROUP_ACTIVE, center);
    client = TestObjectFactory.createClient("client1", CustomerStatus.CLIENT_ACTIVE, group);
    ClientBO client2 = TestObjectFactory.createClient("client2", CustomerStatus.CLIENT_PARTIAL, group);
    ClientBO client3 = TestObjectFactory.createClient("client3", CustomerStatus.CLIENT_PENDING, group);
    ClientBO client4 = TestObjectFactory.createClient("client4", CustomerStatus.CLIENT_HOLD, group);
    List<CustomerBO> customerList = customerPersistence.getChildren(center.getSearchId(), center.getOffice().getOfficeId(), CustomerLevel.CLIENT, ChildrenStateType.ACTIVE_AND_ONHOLD);
    Assert.assertEquals(new Integer("2").intValue(), customerList.size());
    for (CustomerBO customer : customerList) {
        if (customer.getCustomerId().intValue() == client.getCustomerId().intValue()) {
            Assert.assertTrue(true);
        }
        if (customer.getCustomerId().intValue() == client4.getCustomerId().intValue()) {
            Assert.assertTrue(true);
        }
    }
//        TestObjectFactory.cleanUp(client2);
//        TestObjectFactory.cleanUp(client3);
//        TestObjectFactory.cleanUp(client4);
}
Also used : ClientBO(org.mifos.customers.client.business.ClientBO) CustomerBO(org.mifos.customers.business.CustomerBO) Test(org.junit.Test)

Example 50 with CustomerBO

use of org.mifos.customers.business.CustomerBO in project head by mifos.

the class CustomerPersistenceIntegrationTest method testGetActiveCentersUnderUser.

@Test
public void testGetActiveCentersUnderUser() throws Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getTypicalMeeting());
    center = TestObjectFactory.createWeeklyFeeCenter("center", meeting, Short.valueOf("1"), Short.valueOf("1"));
    PersonnelBO personnel = TestObjectFactory.getPersonnel(Short.valueOf("1"));
    List<CustomerBO> customers = new CustomerPersistence().getActiveCentersUnderUser(personnel);
    Assert.assertNotNull(customers);
    Assert.assertEquals(1, customers.size());
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CustomerBO(org.mifos.customers.business.CustomerBO) Test(org.junit.Test)

Aggregations

CustomerBO (org.mifos.customers.business.CustomerBO)138 ArrayList (java.util.ArrayList)39 Money (org.mifos.framework.util.helpers.Money)38 MifosUser (org.mifos.security.MifosUser)38 UserContext (org.mifos.security.util.UserContext)37 LocalDate (org.joda.time.LocalDate)35 MifosRuntimeException (org.mifos.core.MifosRuntimeException)31 AccountException (org.mifos.accounts.exceptions.AccountException)30 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)27 BusinessRuleException (org.mifos.service.BusinessRuleException)27 MeetingBO (org.mifos.application.meeting.business.MeetingBO)23 ClientBO (org.mifos.customers.client.business.ClientBO)23 PersistenceException (org.mifos.framework.exceptions.PersistenceException)22 DateTime (org.joda.time.DateTime)20 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)20 Date (java.util.Date)19 Test (org.junit.Test)19 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)18 LoanBO (org.mifos.accounts.loan.business.LoanBO)17 HashMap (java.util.HashMap)15