Search in sources :

Example 16 with ClientBO

use of org.mifos.customers.client.business.ClientBO in project head by mifos.

the class LoanAccountActionIndividualLoansIntegrationTest method testShouldCallUpdateMethodIfExistingMembersChanged.

@Test
public void testShouldCallUpdateMethodIfExistingMembersChanged() throws Exception {
    GlimLoanUpdater glimLoanUpdaterMock = createMock(GlimLoanUpdater.class);
    LoanAccountAction loanAccountAction = new LoanAccountAction(ApplicationContextProvider.getBean(LoanBusinessService.class), new ConfigurationBusinessService(), glimLoanUpdaterMock);
    LoanBO loanMock = createMock(LoanBO.class);
    Locale locale = Locale.ENGLISH;
    expect(loanMock.getAccountId()).andReturn(2).anyTimes();
    ClientBO customerMock = createMock(ClientBO.class);
    expect(loanMock.getCustomer()).andReturn(customerMock).anyTimes();
    expect(customerMock.getCustomerId()).andReturn(3).anyTimes();
    LoanAccountActionForm loanAccountActionForm = new LoanAccountActionForm();
    List<LoanAccountDetailsDto> clientDetails = new ArrayList<LoanAccountDetailsDto>();
    LoanAccountDetailsDto LOAN_ACCOUNT_DETAILS_WITH_LOAN_AMOUNT_300 = LoanAccountDetailsDto.createInstanceForTest("3", "2", "300.0", "2");
    clientDetails.add(LOAN_ACCOUNT_DETAILS_WITH_LOAN_AMOUNT_300);
    List<LoanBO> loans = new ArrayList<LoanBO>();
    loans.add(loanMock);
    glimLoanUpdaterMock.updateIndividualLoan(null, null, null, LOAN_ACCOUNT_DETAILS_WITH_LOAN_AMOUNT_300, loanMock);
    expectLastCall().atLeastOnce();
    replay(glimLoanUpdaterMock, loanMock, customerMock);
    loanAccountAction.handleIndividualLoans(loanMock, loanAccountActionForm, true, clientDetails, loans, locale);
    verify(glimLoanUpdaterMock, loanMock, customerMock);
}
Also used : Locale(java.util.Locale) LoanAccountActionForm(org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm) LoanBusinessService(org.mifos.accounts.loan.business.service.LoanBusinessService) LoanBO(org.mifos.accounts.loan.business.LoanBO) ClientBO(org.mifos.customers.client.business.ClientBO) ConfigurationBusinessService(org.mifos.config.business.service.ConfigurationBusinessService) ArrayList(java.util.ArrayList) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) Test(org.junit.Test)

Example 17 with ClientBO

use of org.mifos.customers.client.business.ClientBO in project head by mifos.

the class ImportClientsServiceFacadeWebTier method save.

@Override
public ParsedClientsDto save(ParsedClientsDto parsedClientsDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
    userContext.setBranchGlobalNum(userOffice.getGlobalOfficeNum());
    DateTimeService dateTimeService = new DateTimeService();
    /* Construct ClientBO objects */
    List<NewClientDto> newClients = new ArrayList<NewClientDto>();
    for (ImportedClientDetail importedClient : parsedClientsDto.getSuccessfullyParsedRows()) {
        String secondMiddleName = null;
        ClientCreationDetail clientCreationDetail = importedClient.getClientCreationDetail();
        PersonnelBO formedBy = null;
        /* Client name details */
        ClientNameDetailDto clientNameDetails = clientCreationDetail.getClientNameDetailDto();
        ClientNameDetailEntity clientNameDetailEntity = new ClientNameDetailEntity(null, secondMiddleName, clientNameDetails);
        ClientDetailEntity clientDetailEntity = new ClientDetailEntity();
        clientDetailEntity.updateClientDetails(clientCreationDetail.getClientPersonalDetailDto());
        String clientFirstName = clientNameDetails.getFirstName();
        String clientLastName = clientNameDetails.getLastName();
        String secondLastName = clientNameDetails.getSecondLastName();
        /* Spouse/father name details */
        ClientNameDetailEntity spouseFatherNameDetailEntity = null;
        if (clientCreationDetail.getSpouseFatherName() != null) {
            spouseFatherNameDetailEntity = new ClientNameDetailEntity(null, secondMiddleName, clientCreationDetail.getSpouseFatherName());
        }
        /* Data conversion */
        DateTime dateOfBirth = new DateTime(clientCreationDetail.getDateOfBirth());
        DateTime mfiJoiningDate = new DateTime(clientCreationDetail.getMfiJoiningDate());
        DateTime trainedDateTime = null;
        if (clientCreationDetail.getTrainedDate() != null) {
            trainedDateTime = new DateTime(clientCreationDetail.getTrainedDate());
        }
        /* Status */
        CustomerStatus clientStatus = CustomerStatus.fromInt(clientCreationDetail.getClientStatus());
        CustomerStatus finalStatus = clientStatus;
        if (clientStatus == CustomerStatus.CLIENT_ACTIVE && clientCreationDetail.getActivationDate() == null) {
            clientStatus = CustomerStatus.CLIENT_PENDING;
        }
        /* Address */
        Address address = null;
        if (clientCreationDetail.getAddress() != null) {
            AddressDto dto = clientCreationDetail.getAddress();
            address = new Address(dto.getLine1(), dto.getLine2(), dto.getLine3(), dto.getCity(), dto.getState(), dto.getCountry(), dto.getZip(), dto.getPhoneNumber());
        }
        // empty list
        List<ClientInitialSavingsOfferingEntity> associatedOfferings = new ArrayList<ClientInitialSavingsOfferingEntity>();
        // client object
        ClientBO client;
        if (clientCreationDetail.getGroupFlag() == 1) {
            CustomerBO group = customerDao.findCustomerBySystemId(clientCreationDetail.getParentGroupId());
            if (clientCreationDetail.getFormedBy() != null) {
                formedBy = this.personnelDao.findPersonnelById(clientCreationDetail.getFormedBy());
            } else {
                formedBy = group.getPersonnel();
            }
            client = ClientBO.createNewInGroupHierarchy(userContext, clientCreationDetail.getClientName(), clientStatus, mfiJoiningDate, group, formedBy, clientNameDetailEntity, dateOfBirth, clientCreationDetail.getGovernmentId(), clientCreationDetail.isTrained(), trainedDateTime, clientCreationDetail.getGroupFlag(), clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, associatedOfferings, clientCreationDetail.getExternalId(), address, clientCreationDetail.getActivationDate());
        } else {
            Short officeId = clientCreationDetail.getOfficeId();
            Short officerId = clientCreationDetail.getLoanOfficerId();
            PersonnelBO loanOfficer = personnelDao.findPersonnelById(officerId);
            OfficeBO office = this.officeDao.findOfficeById(officeId);
            if (clientCreationDetail.getFormedBy() != null) {
                formedBy = this.personnelDao.findPersonnelById(clientCreationDetail.getFormedBy());
            } else {
                formedBy = loanOfficer;
            }
            int lastSearchIdCustomerValue = customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(officeId);
            /* meeting */
            final MeetingDto meetingDto = importedClient.getMeeting();
            MeetingBO clientMeeting = null;
            if (meetingDto != null) {
                clientMeeting = new MeetingFactory().create(meetingDto);
                clientMeeting.setUserContext(userContext);
            }
            client = ClientBO.createNewOutOfGroupHierarchy(userContext, clientCreationDetail.getClientName(), clientStatus, mfiJoiningDate, office, loanOfficer, clientMeeting, formedBy, clientNameDetailEntity, dateOfBirth, clientCreationDetail.getGovernmentId(), clientCreationDetail.isTrained(), trainedDateTime, clientCreationDetail.getGroupFlag(), clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, associatedOfferings, clientCreationDetail.getExternalId(), address, lastSearchIdCustomerValue);
            if (clientCreationDetail.getActivationDate() != null) {
                client.setCustomerActivationDate(clientCreationDetail.getActivationDate().toDateMidnight().toDate());
            }
        }
        // global id
        if (importedClient.getClientGlobalNum() != null) {
            client.setGlobalCustNum(importedClient.getClientGlobalNum());
        }
        NewClientDto newClient = new NewClientDto(client, finalStatus);
        newClients.add(newClient);
    }
    /* Validate client data */
    for (NewClientDto newClient : newClients) {
        ClientBO client = newClient.getClientBO();
        try {
            client.validate();
            customerDao.validateClientForDuplicateNameOrGovtId(client.getDisplayName(), client.getDateOfBirth(), client.getGovernmentId());
        } catch (CustomerException ex) {
            throw new MifosRuntimeException(ex);
        }
    }
    /* Save clients */
    // empty list
    List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>();
    try {
        hibernateTransactionHelper.startTransaction();
        for (NewClientDto newClient : newClients) {
            ClientBO client = newClient.getClientBO();
            CustomerStatus finalStatus = newClient.getCustomerStatus();
            // status to pending approval if active
            MeetingBO meeting = client.getCustomerMeetingValue();
            customerDao.save(client);
            hibernateTransactionHelper.flushSession();
            CalendarEvent applicableCalendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(client.getOfficeId());
            CustomerAccountBO customerAccount = customerAccountFactory.create(client, accountFees, meeting, applicableCalendarEvents);
            client.addAccount(customerAccount);
            customerDao.save(client);
            hibernateTransactionHelper.flushSession();
            if (client.getParentCustomer() != null) {
                customerDao.save(client.getParentCustomer());
            }
            if (client.getGlobalCustNum() == null) {
                client.generateGlobalCustomerNumber();
            }
            client.generateSearchId();
            customerDao.save(client);
            hibernateTransactionHelper.flushSession();
            if (client.getParentCustomer() != null) {
                customerDao.save(client.getParentCustomer());
            }
            /* activate client */
            if (finalStatus == CustomerStatus.CLIENT_ACTIVE) {
                hibernateTransactionHelper.flushSession();
                hibernateTransactionHelper.beginAuditLoggingFor(client);
                client.clearCustomerFlagsIfApplicable(client.getStatus(), finalStatus);
                client.updateCustomerStatus(finalStatus);
                // changeStatus(client, oldStatus, newStatus);
                if (client.getParentCustomer() != null) {
                    CustomerHierarchyEntity hierarchy = new CustomerHierarchyEntity(client, client.getParentCustomer());
                    client.addCustomerHierarchy(hierarchy);
                }
                if (client.getCustomerActivationDate() != null) {
                    client.setCustomerActivationDate(client.getCustomerActivationDate());
                } else {
                    client.setCustomerActivationDate(dateTimeService.getCurrentJavaDateTime());
                }
                customerAccount.createSchedulesAndFeeSchedulesForFirstTimeActiveCustomer(client, accountFees, meeting, applicableCalendarEvents, new DateTime(client.getCustomerActivationDate()));
                customerDao.save(client);
            }
        }
        hibernateTransactionHelper.commitTransaction();
    } catch (Exception ex) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(ex);
    }
    return parsedClientsDto;
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) Address(org.mifos.framework.business.util.Address) NewClientDto(org.mifos.customers.client.util.helpers.NewClientDto) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ClientBO(org.mifos.customers.client.business.ClientBO) ArrayList(java.util.ArrayList) ClientInitialSavingsOfferingEntity(org.mifos.customers.client.business.ClientInitialSavingsOfferingEntity) MeetingFactory(org.mifos.application.meeting.business.MeetingFactory) DateTime(org.joda.time.DateTime) ClientCreationDetail(org.mifos.dto.domain.ClientCreationDetail) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) ClientNameDetailEntity(org.mifos.customers.client.business.ClientNameDetailEntity) ClientDetailEntity(org.mifos.customers.client.business.ClientDetailEntity) CustomerBO(org.mifos.customers.business.CustomerBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) DateTimeService(org.mifos.framework.util.DateTimeService) CustomerException(org.mifos.customers.exceptions.CustomerException) CustomerHierarchyEntity(org.mifos.customers.business.CustomerHierarchyEntity) UserContext(org.mifos.security.util.UserContext) CalendarEvent(org.mifos.calendar.CalendarEvent) MifosUser(org.mifos.security.MifosUser) AddressDto(org.mifos.dto.domain.AddressDto) CustomerException(org.mifos.customers.exceptions.CustomerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) MeetingDto(org.mifos.dto.domain.MeetingDto) CustomerStatus(org.mifos.customers.util.helpers.CustomerStatus) ImportedClientDetail(org.mifos.dto.domain.ImportedClientDetail) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 18 with ClientBO

use of org.mifos.customers.client.business.ClientBO in project head by mifos.

the class IndividualLoanAssembler method assembleFrom.

@Override
public IndividualLoan assembleFrom(IndividualLoanRequest individualLoan) {
    LoanOfferingBO loanProduct = this.loanProductDao.findBySystemId(individualLoan.getLoanProductId().globalIdentity());
    ClientBO client = this.customerDao.findClientBySystemId(individualLoan.getClientId().globalIdentity());
    int occurences = 12;
    DateTime lastScheduledDate = new DateTime();
    ScheduledEvent scheduledEvent = scheduledEventFactory.createScheduledEventFrom(loanProduct.getLoanOfferingMeetingValue());
    List<DateTime> loanScheduleDates = scheduledDateGeneration.generateScheduledDates(occurences, lastScheduledDate, scheduledEvent, false);
    // FIXME - assemble loanAmount from dto
    Money loanAmount = null;
    Double interestRate = Double.valueOf("10.0");
    Integer interestDays = Integer.valueOf(AccountingRules.getNumberOfInterestDays());
    return new IndividualLoanImpl();
}
Also used : IndividualLoanImpl(org.mifos.clientportfolio.newloan.domain.IndividualLoanImpl) ScheduledEvent(org.mifos.schedule.ScheduledEvent) Money(org.mifos.framework.util.helpers.Money) ClientBO(org.mifos.customers.client.business.ClientBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) DateTime(org.joda.time.DateTime)

Example 19 with ClientBO

use of org.mifos.customers.client.business.ClientBO in project head by mifos.

the class AddGroupMembershipAction method updateParent.

@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward updateParent(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    AddGroupMembershipForm actionForm = (AddGroupMembershipForm) form;
    Integer parentGroupId = actionForm.getParentGroupIdValue();
    ClientBO clientInSession = (ClientBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    String globalCustNum = this.clientServiceFacade.transferClientToGroup(parentGroupId, clientInSession.getGlobalCustNum(), clientInSession.getVersionNo());
    ClientBO client = this.customerDao.findClientBySystemId(globalCustNum);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, client, request);
    return mapping.findForward(ActionForwards.view_client_details_page.toString());
}
Also used : ClientBO(org.mifos.customers.client.business.ClientBO) AddGroupMembershipForm(org.mifos.customers.group.struts.actionforms.AddGroupMembershipForm) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 20 with ClientBO

use of org.mifos.customers.client.business.ClientBO in project head by mifos.

the class CenterStatusChangeIntegrationTest method givenCenterIsInactiveAndAssignedLoanOfficerIsInactiveShouldNotPassValidationWhenTryingToTranistionClientToActive.

@Test
public void givenCenterIsInactiveAndAssignedLoanOfficerIsInactiveShouldNotPassValidationWhenTryingToTranistionClientToActive() throws Exception {
    // setup
    CenterBO existingCenter = new CenterBuilder().with(existingMeeting).withName("Center-IntegrationTest").with(existingOffice).withLoanOfficer(existingLoanOfficer).withUserContext().build();
    existingCenter.updateCustomerStatus(CustomerStatus.CENTER_INACTIVE);
    IntegrationTestObjectMother.createCenter(existingCenter, existingMeeting);
    existingLoanOfficer = this.personnelDao.findPersonnelById(existingLoanOfficer.getPersonnelId());
    updatePersonnel(existingLoanOfficer, PersonnelLevel.LOAN_OFFICER, PersonnelStatus.INACTIVE, existingOffice);
    GroupBO existingPartialGroup = new GroupBuilder().withName("newGroup").withStatus(CustomerStatus.GROUP_PARTIAL).withParentCustomer(existingCenter).formedBy(existingUser).build();
    IntegrationTestObjectMother.createGroup(existingPartialGroup, existingMeeting);
    ClientBO existingPartialClient = new ClientBuilder().withStatus(CustomerStatus.CLIENT_PARTIAL).withParentCustomer(existingPartialGroup).buildForIntegrationTests();
    IntegrationTestObjectMother.createClient(existingPartialClient, existingMeeting);
    StaticHibernateUtil.flushAndClearSession();
    existingCenter = this.customerDao.findCenterBySystemId(existingCenter.getGlobalCustNum());
    existingCenter.setUserContext(TestUtils.makeUser());
    existingPartialGroup = this.customerDao.findGroupBySystemId(existingPartialGroup.getGlobalCustNum());
    existingPartialClient = this.customerDao.findClientBySystemId(existingPartialClient.getGlobalCustNum());
    existingPartialClient.setUserContext(TestUtils.makeUser());
    CustomerStatusFlag customerStatusFlag = null;
    CustomerNoteEntity customerNote = new CustomerNoteEntity("go active", new Date(), existingCenter.getPersonnel(), existingCenter);
    // exercise test
    try {
        customerService.updateCenterStatus(existingCenter, CustomerStatus.CENTER_ACTIVE, customerStatusFlag, customerNote);
        fail("should fail validation");
    } catch (CustomerException expected) {
        assertThat(expected.getKey(), is(CustomerConstants.CUSTOMER_LOAN_OFFICER_INACTIVE_EXCEPTION));
        assertThat(existingCenter.getStatus(), is(CustomerStatus.CENTER_INACTIVE));
    }
}
Also used : CustomerNoteEntity(org.mifos.customers.business.CustomerNoteEntity) CustomerException(org.mifos.customers.exceptions.CustomerException) CustomerStatusFlag(org.mifos.customers.util.helpers.CustomerStatusFlag) GroupBuilder(org.mifos.domain.builders.GroupBuilder) ClientBO(org.mifos.customers.client.business.ClientBO) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) GroupBO(org.mifos.customers.group.business.GroupBO) Date(java.util.Date) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Aggregations

ClientBO (org.mifos.customers.client.business.ClientBO)93 ArrayList (java.util.ArrayList)27 Test (org.junit.Test)27 CustomerException (org.mifos.customers.exceptions.CustomerException)25 CustomerBO (org.mifos.customers.business.CustomerBO)23 GroupBO (org.mifos.customers.group.business.GroupBO)22 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)22 UserContext (org.mifos.security.util.UserContext)21 MifosRuntimeException (org.mifos.core.MifosRuntimeException)19 CenterBO (org.mifos.customers.center.business.CenterBO)19 BusinessRuleException (org.mifos.service.BusinessRuleException)17 ClientBuilder (org.mifos.domain.builders.ClientBuilder)16 PersistenceException (org.mifos.framework.exceptions.PersistenceException)16 OfficeBO (org.mifos.customers.office.business.OfficeBO)14 GroupBuilder (org.mifos.domain.builders.GroupBuilder)14 ClientNameDetailDto (org.mifos.dto.screen.ClientNameDetailDto)14 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)14 Date (java.util.Date)13 DateTime (org.joda.time.DateTime)13 AccountException (org.mifos.accounts.exceptions.AccountException)13