Search in sources :

Example 81 with BusinessRuleException

use of org.mifos.service.BusinessRuleException in project head by mifos.

the class GroupLoanAccountServiceFacadeWebTier method createNewMeetingForRepaymentDay.

private MeetingBO createNewMeetingForRepaymentDay(LocalDate disbursementDate, RecurringSchedule recurringSchedule, CustomerBO customer) {
    MeetingBO newMeetingForRepaymentDay = null;
    final int minDaysInterval = configurationPersistence.getConfigurationValueInteger(MIN_DAYS_BETWEEN_DISBURSAL_AND_FIRST_REPAYMENT_DAY);
    final Date repaymentStartDate = disbursementDate.plusDays(minDaysInterval).toDateMidnight().toDateTime().toDate();
    try {
        if (recurringSchedule.isWeekly()) {
            WeekDay weekDay = WeekDay.getWeekDay(recurringSchedule.getDay().shortValue());
            Short recurEvery = recurringSchedule.getEvery().shortValue();
            newMeetingForRepaymentDay = new MeetingBO(weekDay, recurEvery, repaymentStartDate, MeetingType.LOAN_INSTALLMENT, customer.getCustomerMeeting().getMeeting().getMeetingPlace());
        } else if (recurringSchedule.isMonthly()) {
            if (recurringSchedule.isMonthlyOnDayOfMonth()) {
                Short dayOfMonth = recurringSchedule.getDay().shortValue();
                Short dayRecurMonth = recurringSchedule.getEvery().shortValue();
                newMeetingForRepaymentDay = new MeetingBO(dayOfMonth, dayRecurMonth, repaymentStartDate, MeetingType.LOAN_INSTALLMENT, customer.getCustomerMeeting().getMeeting().getMeetingPlace());
            } else {
                Short weekOfMonth = recurringSchedule.getDay().shortValue();
                Short monthRank = recurringSchedule.getWeek().shortValue();
                Short everyMonth = recurringSchedule.getEvery().shortValue();
                newMeetingForRepaymentDay = new MeetingBO(weekOfMonth, everyMonth, repaymentStartDate, MeetingType.LOAN_INSTALLMENT, customer.getCustomerMeeting().getMeeting().getMeetingPlace(), monthRank);
            }
        } else {
            Short recurEvery = recurringSchedule.getEvery().shortValue();
            newMeetingForRepaymentDay = new MeetingBO(recurEvery, repaymentStartDate, MeetingType.LOAN_INSTALLMENT, customer.getCustomerMeeting().getMeeting().getMeetingPlace());
        }
        return newMeetingForRepaymentDay;
    } catch (NumberFormatException nfe) {
        throw new MifosRuntimeException(nfe);
    } catch (MeetingException me) {
        throw new BusinessRuleException(me.getKey(), me);
    }
}
Also used : WeekDay(org.mifos.application.meeting.util.helpers.WeekDay) BusinessRuleException(org.mifos.service.BusinessRuleException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) MeetingBO(org.mifos.application.meeting.business.MeetingBO) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 82 with BusinessRuleException

use of org.mifos.service.BusinessRuleException in project head by mifos.

the class GroupServiceFacadeWebTier method transferGroupToBranch.

@Override
public CustomerDetailDto transferGroupToBranch(String globalCustNum, Short officeId, Integer previousGroupVersionNo) {
    try {
        MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        UserContext userContext = toUserContext(user);
        GroupBO group = this.customerDao.findGroupBySystemId(globalCustNum);
        group.updateDetails(userContext);
        checkVersionMismatch(previousGroupVersionNo, group.getVersionNo());
        OfficeBO transferToOffice = this.officeDao.findOfficeById(officeId);
        transferToOffice.setUserContext(userContext);
        String groupGlobalCustNum = this.customerService.transferGroupTo(group, transferToOffice);
        GroupBO transferedGroup = this.customerDao.findGroupBySystemId(groupGlobalCustNum);
        return transferedGroup.toCustomerDetailDto();
    } catch (ApplicationException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) OfficeBO(org.mifos.customers.office.business.OfficeBO) UserContext(org.mifos.security.util.UserContext) GroupBO(org.mifos.customers.group.business.GroupBO) MifosUser(org.mifos.security.MifosUser)

Example 83 with BusinessRuleException

use of org.mifos.service.BusinessRuleException in project head by mifos.

the class GroupServiceFacadeWebTier method retrieveCustomerHistoricalData.

@Override
public CustomerHistoricalDataDto retrieveCustomerHistoricalData(String globalCustNum) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    CustomerBO customer = this.customerDao.findCustomerBySystemId(globalCustNum);
    boolean client = false;
    boolean group = false;
    if (customer.isClient()) {
        client = true;
    } else if (customer.isGroup()) {
        group = true;
    }
    CustomerHistoricalDataEntity customerHistoricalDataEntity = customer.getHistoricalData();
    if (customerHistoricalDataEntity == null) {
        customerHistoricalDataEntity = new CustomerHistoricalDataEntity(customer);
    }
    try {
        String currentDate = DateUtils.getCurrentDate(userContext.getPreferredLocale());
        java.sql.Date mfiJoiningDate = null;
        if (customerHistoricalDataEntity.getMfiJoiningDate() == null) {
            mfiJoiningDate = DateUtils.getLocaleDate(userContext.getPreferredLocale(), currentDate);
        } else {
            mfiJoiningDate = new Date(customerHistoricalDataEntity.getMfiJoiningDate().getTime());
        }
        return new CustomerHistoricalDataDto(client, group, mfiJoiningDate);
    } catch (InvalidDateException e) {
        throw new BusinessRuleException(e.getMessage(), e);
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerHistoricalDataDto(org.mifos.dto.screen.CustomerHistoricalDataDto) UserContext(org.mifos.security.util.UserContext) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) CustomerHistoricalDataEntity(org.mifos.customers.business.CustomerHistoricalDataEntity) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser) Date(java.sql.Date) Date(java.sql.Date)

Example 84 with BusinessRuleException

use of org.mifos.service.BusinessRuleException in project head by mifos.

the class GroupServiceFacadeWebTier method updateCustomerHistoricalData.

@Override
public void updateCustomerHistoricalData(String globalCustNum, CustomerHistoricalDataUpdateRequest historicalData) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    CustomerBO customerBO = this.customerDao.findCustomerBySystemId(globalCustNum);
    customerBO.updateDetails(userContext);
    try {
        CustomerHistoricalDataEntity customerHistoricalDataEntity = customerBO.getHistoricalData();
        if (customerBO.getPersonnel() != null) {
            checkPermissionForAddingHistoricalData(customerBO.getLevel(), userContext, customerBO.getOffice().getOfficeId(), customerBO.getPersonnel().getPersonnelId());
        } else {
            checkPermissionForAddingHistoricalData(customerBO.getLevel(), userContext, customerBO.getOffice().getOfficeId(), userContext.getId());
        }
        // Integer oldLoanCycleNo = 0;
        if (customerHistoricalDataEntity == null) {
            customerHistoricalDataEntity = new CustomerHistoricalDataEntity(customerBO);
            customerHistoricalDataEntity.setCreatedBy(customerBO.getUserContext().getId());
            customerHistoricalDataEntity.setCreatedDate(new DateTimeService().getCurrentJavaDateTime());
        } else {
            // oldLoanCycleNo =
            // customerHistoricalDataEntity.getLoanCycleNumber();
            customerHistoricalDataEntity.setUpdatedDate(new DateTimeService().getCurrentJavaDateTime());
            customerHistoricalDataEntity.setUpdatedBy(customerBO.getUserContext().getId());
        }
        customerHistoricalDataEntity.setInterestPaid(StringUtils.isBlank(historicalData.getInterestPaid()) ? null : new Money(Money.getDefaultCurrency(), historicalData.getInterestPaid()));
        customerHistoricalDataEntity.setLoanAmount(StringUtils.isBlank(historicalData.getLoanAmount()) ? null : new Money(Money.getDefaultCurrency(), historicalData.getLoanAmount()));
        customerHistoricalDataEntity.setLoanCycleNumber(historicalData.getLoanCycleNumber());
        customerHistoricalDataEntity.setMissedPaymentsCount(historicalData.getMissedPaymentsCount());
        customerHistoricalDataEntity.setNotes(historicalData.getNotes());
        customerHistoricalDataEntity.setProductName(historicalData.getProductName());
        customerHistoricalDataEntity.setTotalAmountPaid(StringUtils.isBlank(historicalData.getTotalAmountPaid()) ? null : new Money(Money.getDefaultCurrency(), historicalData.getTotalAmountPaid()));
        customerHistoricalDataEntity.setTotalPaymentsCount(historicalData.getTotalPaymentsCount());
        customerHistoricalDataEntity.setMfiJoiningDate(historicalData.getMfiJoiningDate());
        this.transactionHelper.startTransaction();
        this.transactionHelper.beginAuditLoggingFor(customerBO);
        customerBO.updateHistoricalData(customerHistoricalDataEntity);
        this.customerDao.save(customerBO);
        this.transactionHelper.commitTransaction();
    } catch (ApplicationException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) UserContext(org.mifos.security.util.UserContext) CustomerHistoricalDataEntity(org.mifos.customers.business.CustomerHistoricalDataEntity) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 85 with BusinessRuleException

use of org.mifos.service.BusinessRuleException in project head by mifos.

the class ClientServiceFacadeWebTier method updateClientPersonalInfo.

@Override
public void updateClientPersonalInfo(ClientPersonalInfoUpdate personalInfo, String clientStatus, short loanOfficerId) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        this.customerService.updateClientPersonalInfo(userContext, personalInfo);
    } catch (CustomerException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) BusinessRuleException(org.mifos.service.BusinessRuleException) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser)

Aggregations

BusinessRuleException (org.mifos.service.BusinessRuleException)140 MifosRuntimeException (org.mifos.core.MifosRuntimeException)68 UserContext (org.mifos.security.util.UserContext)63 MifosUser (org.mifos.security.MifosUser)61 AccountException (org.mifos.accounts.exceptions.AccountException)46 PersistenceException (org.mifos.framework.exceptions.PersistenceException)43 ApplicationException (org.mifos.framework.exceptions.ApplicationException)33 LocalDate (org.joda.time.LocalDate)31 ServiceException (org.mifos.framework.exceptions.ServiceException)30 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)26 ArrayList (java.util.ArrayList)23 CustomerBO (org.mifos.customers.business.CustomerBO)22 Money (org.mifos.framework.util.helpers.Money)22 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)20 CustomerException (org.mifos.customers.exceptions.CustomerException)19 LoanBO (org.mifos.accounts.loan.business.LoanBO)18 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)16 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)16 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)16 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)16