Search in sources :

Example 21 with BusinessRuleException

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

the class FeeServiceFacadeWebTier method updateFee.

@Override
public void updateFee(FeeUpdateRequest feeUpdateRequest) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    try {
        this.feeService.update(feeUpdateRequest, userContext);
    } catch (ApplicationException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory)

Example 22 with BusinessRuleException

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

the class FeeServiceFacadeWebTier method parameters.

private FeeParameters parameters() {
    try {
        List<GLCodeEntity> glCodes = generalLedgerDao.retreiveGlCodesBy(FinancialActionConstants.FEEPOSTING, FinancialConstants.CREDIT);
        List<CategoryTypeEntity> categories = this.feeDao.doRetrieveFeeCategories();
        List<FeeFormulaEntity> formulas = this.feeDao.retrieveFeeFormulae();
        List<FeeFrequencyTypeEntity> frequencies = this.feeDao.retrieveFeeFrequencies();
        List<FeePaymentEntity> timesOfCharging = this.feeDao.retrieveFeePayments();
        List<MasterDataEntity> timesOfChargeingCustomer = new ArrayList<MasterDataEntity>();
        for (MasterDataEntity timeOfCharging : timesOfCharging) {
            if (timeOfCharging.getId().equals(FeePayment.UPFRONT.getValue())) {
                timesOfChargeingCustomer.add(timeOfCharging);
            }
        }
        return new FeeParameters(listToMap(categories), listToMap(timesOfCharging), listToMap(timesOfChargeingCustomer), listToMap(formulas), listToMap(frequencies), glCodesToMap(glCodes));
    } catch (FinancialException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : MasterDataEntity(org.mifos.application.master.business.MasterDataEntity) ArrayList(java.util.ArrayList) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) FeePaymentEntity(org.mifos.accounts.fees.business.FeePaymentEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) FeeFormulaEntity(org.mifos.accounts.fees.business.FeeFormulaEntity) FeeFrequencyTypeEntity(org.mifos.accounts.fees.business.FeeFrequencyTypeEntity) CategoryTypeEntity(org.mifos.accounts.fees.business.CategoryTypeEntity) FinancialException(org.mifos.accounts.financial.exceptions.FinancialException) FeeParameters(org.mifos.dto.screen.FeeParameters)

Example 23 with BusinessRuleException

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

the class LoanBO method waiveOverdueChargesFromMemberAccounts.

public void waiveOverdueChargesFromMemberAccounts(String chargeType) {
    for (LoanBO member : getMemberAccounts()) {
        List<AccountActionDateEntity> memberAccountActionDateList = member.getApplicableIdsForNextInstallmentAndArrears();
        List<LoanScheduleEntity> overdueMemberAccountActionDateEntities = new ArrayList<LoanScheduleEntity>();
        for (AccountActionDateEntity accountActionDateEntity : memberAccountActionDateList) {
            if (accountActionDateEntity.getActionDate().before(DateUtils.getCurrentDateWithoutTimeStamp())) {
                overdueMemberAccountActionDateEntities.add((LoanScheduleEntity) accountActionDateEntity);
            }
        }
        Money principal = new Money(getCurrency());
        Money interest = new Money(getCurrency());
        Money fee = new Money(getCurrency());
        Money penalty = new Money(getCurrency());
        if (chargeType == LoanConstants.FEE_WAIVED) {
            for (LoanScheduleEntity memberAccountActionDateEntity : overdueMemberAccountActionDateEntities) {
                fee = fee.add(memberAccountActionDateEntity.waiveFeeCharges());
            }
            member.updateTotalFeeAmount(fee);
        } else if (chargeType == LoanConstants.PENALTY_WAIVED) {
            for (LoanScheduleEntity memberAccountActionDateEntity : overdueMemberAccountActionDateEntities) {
                penalty = penalty.add(memberAccountActionDateEntity.waivePenaltyCharges());
            }
            member.updateTotalPenaltyAmount(penalty);
        }
        try {
            member.updateAccountActivity(principal, interest, fee, penalty, userContext.getId(), chargeType);
        } catch (AccountException e) {
            throw new BusinessRuleException(e.getKey());
        }
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) ArrayList(java.util.ArrayList)

Example 24 with BusinessRuleException

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

the class HolidayServiceImpl method create.

@Override
public void create(HolidayDetails holidayDetails, List<Short> officeIds) {
    HolidayBO holiday = HolidayBO.fromDto(holidayDetails);
    holiday.validate();
    List<OfficeBO> offices = new ArrayList<OfficeBO>();
    for (Short officeId : officeIds) {
        OfficeBO office = officeDao.findOfficeById(officeId);
        offices.add(office);
        if (office.hasChildWithAnyOf(officeIds)) {
            throw new BusinessRuleException(HolidayConstants.HOLIDAY_CREATION_EXCEPTION);
        // "Holidays can only be associated with one level of office in an office hierarchy."
        }
    }
    try {
        hibernateTransactionHelper.startTransaction();
        this.holidayDao.save(holiday);
        for (OfficeBO office : offices) {
            office.addHoliday(holiday);
        }
        hibernateTransactionHelper.commitTransaction();
    } catch (Exception e) {
        hibernateTransactionHelper.rollbackTransaction();
    } finally {
        hibernateTransactionHelper.closeSession();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) OfficeBO(org.mifos.customers.office.business.OfficeBO) ArrayList(java.util.ArrayList) HolidayBO(org.mifos.application.holiday.business.HolidayBO) BusinessRuleException(org.mifos.service.BusinessRuleException)

Example 25 with BusinessRuleException

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

the class ImportTransactionsServiceFacadeWebTier method undoFullImport.

@Override
public void undoFullImport(String importTransactionsFileName) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    TreeSet<String> accountsWithAdjustedPayments = new TreeSet<String>();
    try {
        ImportedFilesEntity filesEntity = this.importedFilesService.getImportedFileByName(importTransactionsFileName);
        List<AccountTrxnEntity> trxUndo = new ArrayList<AccountTrxnEntity>(filesEntity.getImportedTrxn());
        List<ImportedAccPaymentDto> accPaymentList = new ArrayList<ImportedAccPaymentDto>();
        for (AccountTrxnEntity trxn : trxUndo) {
            try {
                validateForAdjustedPayments(trxn, accountsWithAdjustedPayments);
                accPaymentList.add(new ImportedAccPaymentDto(trxn.getAccount().getGlobalAccountNum(), trxn.getAccountPayment().getPaymentId()));
            } catch (BusinessRuleException e) {
            //nothing to do   
            }
        }
        for (ImportedAccPaymentDto accDto : accPaymentList) {
            try {
                this.accountServiceFacade.applyHistoricalAdjustment(accDto.getGlobalNum(), accDto.getPaymentId(), IMPORT_UNDONE, userContext.getId(), null);
            } catch (MifosRuntimeException e) {
            // TODO: validation will be added with MIFOS-5779
            }
        }
        this.importedFilesService.saveImportedFileName(filesEntity.getFileName(), filesEntity.getSubmittedBy(), null, Boolean.TRUE, filesEntity.getUndoable());
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) ImportedFilesEntity(org.mifos.application.importexport.business.ImportedFilesEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) TreeSet(java.util.TreeSet) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

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