Search in sources :

Example 16 with CustomerBO

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

the class LoanAccountServiceFacadeWebTier method assembleLoanAccountDetail.

private LoanAccountDetail assembleLoanAccountDetail(CreateLoanAccount loanAccountInfo) {
    CustomerBO customer = this.customerDao.findCustomerById(loanAccountInfo.getCustomerId());
    LoanOfferingBO loanProduct = this.loanProductDao.findById(loanAccountInfo.getProductId());
    Money loanAmount = new Money(loanProduct.getCurrency(), loanAccountInfo.getLoanAmount());
    AccountState accountStateType = AccountState.fromShort(loanAccountInfo.getAccountState().shortValue());
    FundBO fund = null;
    if (loanAccountInfo.getSourceOfFundId() != null) {
        fund = this.fundDao.findById(loanAccountInfo.getSourceOfFundId().shortValue());
    }
    return new LoanAccountDetail(customer, loanProduct, loanAmount, accountStateType, fund);
}
Also used : Money(org.mifos.framework.util.helpers.Money) FundBO(org.mifos.accounts.fund.business.FundBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) CustomerBO(org.mifos.customers.business.CustomerBO) LoanAccountDetail(org.mifos.clientportfolio.newloan.domain.LoanAccountDetail) AccountState(org.mifos.accounts.util.helpers.AccountState)

Example 17 with CustomerBO

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

the class MeetingServiceFacadeWebTier method updateCustomerMeeting.

@Override
public void updateCustomerMeeting(MeetingDto meetingUpdateRequest, Integer customerId) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = userContextFactory.create(user);
    MeetingBO meeting = meetingFactory.create(meetingUpdateRequest);
    meeting.updateDetails(userContext);
    CustomerBO customer = this.customerDao.findCustomerById(customerId);
    customer.updateDetails(userContext);
    customerService.updateCustomerMeetingSchedule(meeting, customer);
}
Also used : UserContext(org.mifos.security.util.UserContext) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser)

Example 18 with CustomerBO

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

the class GroupServiceFacadeWebTier method retrieveGroupFormCreationData.

@Override
public GroupFormCreationDto retrieveGroupFormCreationData(GroupCreation groupCreation) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    CustomerBO parentCustomer = null;
    Short parentOfficeId = groupCreation.getOfficeId();
    CustomerApplicableFeesDto applicableFees = CustomerApplicableFeesDto.empty();
    List<PersonnelDto> personnelList = new ArrayList<PersonnelDto>();
    CenterCreation centerCreation;
    boolean isCenterHierarchyExists = ClientRules.getCenterHierarchyExists();
    if (isCenterHierarchyExists) {
        parentCustomer = this.customerDao.findCenterBySystemId(groupCreation.getParentSystemId());
        parentOfficeId = parentCustomer.getOffice().getOfficeId();
        centerCreation = new CenterCreation(parentOfficeId, userContext.getId(), userContext.getLevelId(), userContext.getPreferredLocale());
        MeetingBO customerMeeting = parentCustomer.getCustomerMeetingValue();
        List<FeeBO> fees = customerDao.retrieveFeesApplicableToGroupsRefinedBy(customerMeeting);
        applicableFees = CustomerApplicableFeesDto.toDto(fees, userContext);
    } else {
        centerCreation = new CenterCreation(groupCreation.getOfficeId(), userContext.getId(), userContext.getLevelId(), userContext.getPreferredLocale());
        personnelList = this.personnelDao.findActiveLoanOfficersForOffice(centerCreation);
        List<FeeBO> fees = customerDao.retrieveFeesApplicableToGroups();
        applicableFees = CustomerApplicableFeesDto.toDto(fees, userContext);
    }
    List<ApplicableAccountFeeDto> applicableDefaultAccountFees = new ArrayList<ApplicableAccountFeeDto>();
    for (FeeDto fee : applicableFees.getDefaultFees()) {
        applicableDefaultAccountFees.add(new ApplicableAccountFeeDto(fee.getFeeIdValue().intValue(), fee.getFeeName(), fee.getAmount(), fee.isRemoved(), fee.isWeekly(), fee.isMonthly(), fee.isPeriodic(), fee.getFeeSchedule()));
    }
    List<ApplicableAccountFeeDto> applicableDefaultAdditionalFees = new ArrayList<ApplicableAccountFeeDto>();
    for (FeeDto fee : applicableFees.getAdditionalFees()) {
        applicableDefaultAdditionalFees.add(new ApplicableAccountFeeDto(fee.getFeeIdValue().intValue(), fee.getFeeName(), fee.getAmount(), fee.isRemoved(), fee.isWeekly(), fee.isMonthly(), fee.isPeriodic(), fee.getFeeSchedule()));
    }
    List<PersonnelDto> formedByPersonnel = customerDao.findLoanOfficerThatFormedOffice(centerCreation.getOfficeId());
    return new GroupFormCreationDto(isCenterHierarchyExists, personnelList, formedByPersonnel, applicableDefaultAccountFees, applicableDefaultAdditionalFees);
}
Also used : UserContext(org.mifos.security.util.UserContext) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ArrayList(java.util.ArrayList) ApplicableAccountFeeDto(org.mifos.dto.domain.ApplicableAccountFeeDto) FeeDto(org.mifos.accounts.fees.business.FeeDto) PersonnelDto(org.mifos.dto.domain.PersonnelDto) MifosUser(org.mifos.security.MifosUser) ApplicableAccountFeeDto(org.mifos.dto.domain.ApplicableAccountFeeDto) GroupFormCreationDto(org.mifos.dto.domain.GroupFormCreationDto) CenterCreation(org.mifos.dto.domain.CenterCreation) CustomerBO(org.mifos.customers.business.CustomerBO) FeeBO(org.mifos.accounts.fees.business.FeeBO)

Example 19 with CustomerBO

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

the class SaveCollectionSheetStructureValidator method execute.

public void execute(SaveCollectionSheetDto saveCollectionSheet) throws SaveCollectionSheetException {
    saveCollectionSheetCustomers = saveCollectionSheet.getSaveCollectionSheetCustomers();
    Boolean isTopCustomer = true;
    for (SaveCollectionSheetCustomerDto saveCollectionSheetCustomer : saveCollectionSheetCustomers) {
        CustomerBO customer;
        Integer currentErrorCount = validationErrors.size();
        try {
            customer = customerPersistence.getCustomer(saveCollectionSheetCustomer.getCustomerId());
        } catch (PersistenceException e) {
            throw new MifosRuntimeException(e);
        }
        if (customer == null) {
            if (isTopCustomer) {
                addValidationError(InvalidSaveCollectionSheetReason.INVALID_TOP_CUSTOMER, "Customer Id: " + saveCollectionSheetCustomer.getCustomerId());
                throw new SaveCollectionSheetException(validationErrors, validationErrorsExtended);
            }
            addValidationError(InvalidSaveCollectionSheetReason.CUSTOMER_NOT_FOUND, "Customer Id: " + saveCollectionSheetCustomer.getCustomerId());
        } else {
            if (isTopCustomer) {
                topCustomer = customer;
            }
            validateCustomer(customer, saveCollectionSheetCustomer);
        }
        if (currentErrorCount.compareTo(validationErrors.size()) == 0) {
            validateAttendanceType(customer, saveCollectionSheetCustomer.getAttendanceId());
            validateSaveCollectionSheetCustomerAccount(saveCollectionSheetCustomer.getCustomerId(), saveCollectionSheetCustomer.getSaveCollectionSheetCustomerAccount());
            validateSaveCollectionSheetCustomerLoans(saveCollectionSheetCustomer.getCustomerId(), saveCollectionSheetCustomer.getSaveCollectionSheetCustomerLoans());
            validateSaveCollectionSheetCustomerSavings(saveCollectionSheetCustomer.getCustomerId(), saveCollectionSheetCustomer.getSaveCollectionSheetCustomerSavings(), ValidationAccountTypes.SAVINGS);
            validateSaveCollectionSheetCustomerSavings(saveCollectionSheetCustomer.getCustomerId(), saveCollectionSheetCustomer.getSaveCollectionSheetCustomerIndividualSavings(), ValidationAccountTypes.INDIVIDUAL_SAVINGS);
        }
        isTopCustomer = false;
    }
    LocalDate validMeetingDate = getValidMeetingDateForTopCustomer(topCustomer.getCustomerId());
    if (saveCollectionSheet.getTransactionDate().compareTo(validMeetingDate) != 0) {
        addValidationError(InvalidSaveCollectionSheetReason.INVALID_DATE, "Transaction Date: " + saveCollectionSheet.getTransactionDate());
        throw new SaveCollectionSheetException(validationErrors, validationErrorsExtended);
    }
    if (validationErrors.size() > 0) {
        throw new SaveCollectionSheetException(validationErrors, validationErrorsExtended);
    }
}
Also used : PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerBO(org.mifos.customers.business.CustomerBO) LocalDate(org.joda.time.LocalDate) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 20 with CustomerBO

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

the class SavingsServiceFacadeWebTier method retrieveDepositWithdrawalReferenceData.

@Override
public DepositWithdrawalReferenceDto retrieveDepositWithdrawalReferenceData(Long savingsId, Integer customerId) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        SavingsBO savingsAccount = savingsDao.findById(savingsId);
        String depositDue = savingsAccount.getTotalPaymentDue(customerId).toString();
        String withdrawalDue = "0";
        List<ListElement> clients = new ArrayList<ListElement>();
        if (savingsAccount.isGroupModelWithIndividualAccountability()) {
            List<CustomerBO> activeAndOnHoldClients = new CustomerPersistence().getActiveAndOnHoldChildren(savingsAccount.getCustomer().getSearchId(), savingsAccount.getCustomer().getOfficeId(), CustomerLevel.CLIENT);
            for (CustomerBO client : activeAndOnHoldClients) {
                clients.add(new ListElement(client.getCustomerId(), client.getDisplayName()));
            }
        }
        List<AccountActionEntity> trxnTypes = new ArrayList<AccountActionEntity>();
        trxnTypes.add(new AccountBusinessService().getAccountAction(AccountActionTypes.SAVINGS_DEPOSIT.getValue(), userContext.getLocaleId()));
        trxnTypes.add(new AccountBusinessService().getAccountAction(AccountActionTypes.SAVINGS_WITHDRAWAL.getValue(), userContext.getLocaleId()));
        List<ListElement> transactionTypes = new ArrayList<ListElement>();
        for (AccountActionEntity accountActionEntity : trxnTypes) {
            LookUpValueEntity lookupValue = accountActionEntity.getLookUpValue();
            String messageText = lookupValue.getMessageText();
            if (StringUtils.isBlank(messageText)) {
                messageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupValue.getPropertiesKey());
            }
            transactionTypes.add(new ListElement(accountActionEntity.getId().intValue(), messageText));
        }
        List<ListElement> depositPaymentTypes = retrieveDepositPaymentTypes(userContext);
        List<ListElement> withdrawalPaymentTypes = new ArrayList<ListElement>();
        List<PaymentTypeEntity> withdrawalPaymentEntityTypes = legacyAcceptedPaymentTypeDao.getAcceptedPaymentTypesForATransaction(userContext.getLocaleId(), TrxnTypes.savings_withdrawal.getValue());
        for (PaymentTypeEntity paymentTypeEntity : withdrawalPaymentEntityTypes) {
            LookUpValueEntity lookupValue = paymentTypeEntity.getLookUpValue();
            String messageText = lookupValue.getMessageText();
            if (StringUtils.isBlank(messageText)) {
                messageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupValue.getPropertiesKey());
            }
            withdrawalPaymentTypes.add(new ListElement(paymentTypeEntity.getId().intValue(), messageText));
        }
        boolean backDatedTransactionsAllowed = AccountingRules.isBackDatedTxnAllowed();
        LocalDate defaultTransactionDate = new LocalDate();
        return new DepositWithdrawalReferenceDto(transactionTypes, depositPaymentTypes, withdrawalPaymentTypes, clients, backDatedTransactionsAllowed, defaultTransactionDate, depositDue, withdrawalDue);
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LocalDate(org.joda.time.LocalDate) AccountActionEntity(org.mifos.accounts.business.AccountActionEntity) PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) ListElement(org.mifos.dto.screen.ListElement) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) DepositWithdrawalReferenceDto(org.mifos.dto.screen.DepositWithdrawalReferenceDto) LookUpValueEntity(org.mifos.application.master.business.LookUpValueEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

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