Search in sources :

Example 1 with FeeStatus

use of org.mifos.accounts.fees.util.helpers.FeeStatus in project head by mifos.

the class FeeServiceImpl method update.

@Override
public void update(FeeUpdateRequest feeUpdateRequest, UserContext userContext) throws ApplicationException {
    FeeBO feeBo = this.feeDao.findById(feeUpdateRequest.getFeeId());
    feeBo.updateDetails(userContext);
    FeeChangeType feeChangeType;
    FeeStatus feeStatus = null;
    if (feeUpdateRequest.getFeeStatusValue() != null) {
        feeStatus = FeeStatus.getFeeStatus(feeUpdateRequest.getFeeStatusValue());
    }
    FeeStatusEntity feeStatusEntity = new FeeStatusEntity(feeStatus);
    if (feeBo.getFeeType().equals(RateAmountFlag.AMOUNT)) {
        AmountFeeBO amountFee = ((AmountFeeBO) feeBo);
        feeChangeType = amountFee.calculateNewFeeChangeType(new Money(getCurrency(feeUpdateRequest.getCurrencyId()), feeUpdateRequest.getAmount()), feeStatusEntity);
        amountFee.setFeeAmount(new Money(getCurrency(feeUpdateRequest.getCurrencyId()), feeUpdateRequest.getAmount()));
    } else {
        RateFeeBO rateFee = ((RateFeeBO) feeBo);
        feeChangeType = rateFee.calculateNewFeeChangeType(feeUpdateRequest.getRateValue(), feeStatusEntity);
        rateFee.setRate(feeUpdateRequest.getRateValue());
    }
    try {
        hibernateTransactionHelper.startTransaction();
        feeBo.updateStatus(feeStatus);
        feeBo.updateFeeChangeType(feeChangeType);
        this.feeDao.save(feeBo);
        hibernateTransactionHelper.commitTransaction();
    } catch (ApplicationException e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } catch (Exception e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        hibernateTransactionHelper.closeSession();
    }
}
Also used : RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) Money(org.mifos.framework.util.helpers.Money) FeeStatusEntity(org.mifos.accounts.fees.business.FeeStatusEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) FeeChangeType(org.mifos.accounts.fees.util.helpers.FeeChangeType) FeeBO(org.mifos.accounts.fees.business.FeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) FeeStatus(org.mifos.accounts.fees.util.helpers.FeeStatus) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) FeeException(org.mifos.accounts.fees.exceptions.FeeException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with FeeStatus

use of org.mifos.accounts.fees.util.helpers.FeeStatus in project head by mifos.

the class FeeAction method update.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward update(ActionMapping mapping, ActionForm form, @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    FeeActionForm feeActionForm = (FeeActionForm) form;
    FeeStatus feeStatus = feeActionForm.getFeeStatusValue();
    String forward = "";
    Short feeStatusValue = null;
    String whereToForward = "";
    if (feeStatus != null) {
        feeStatusValue = feeStatus.getValue();
    }
    FeeUpdateRequest feeUpdateRequest = new FeeUpdateRequest(Short.valueOf(feeActionForm.getFeeId()), feeActionForm.getCurrencyId(), feeActionForm.getAmount(), feeStatusValue, feeActionForm.getRateValue());
    if (feeUpdateRequest.getFeeStatusValue() == 2) {
        this.feeServiceFacade.updateFee(feeUpdateRequest);
        try {
            boolean remove = feeActionForm.isToRemove();
            this.feeServiceFacade.removeFee(feeUpdateRequest, remove);
            whereToForward = REMOVE_SUCCESS;
        } catch (MifosRuntimeException e) {
            ActionMessages messages = new ActionMessages();
            messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Fees.feeCannotBeRemoved"));
            saveMessages(request, messages);
            whereToForward = UPDATE_SUCCESS;
        }
    } else if (feeActionForm.isToRemove() && feeUpdateRequest.getFeeStatusValue() == 1) {
        ActionMessages errors = new ActionMessages();
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Fees.feeCantBeRemove"));
        saveErrors(request, errors);
        whereToForward = UPDATE_FAILURE;
    } else {
        this.feeServiceFacade.updateFee(feeUpdateRequest);
        whereToForward = UPDATE_SUCCESS;
    }
    if (whereToForward.equals(UPDATE_SUCCESS)) {
        forward = ActionForwards.update_success.toString();
    } else if (whereToForward.equals(UPDATE_FAILURE)) {
        forward = ActionForwards.update_failure.toString();
    } else if (whereToForward.equals(REMOVE_SUCCESS)) {
        forward = ActionForwards.remove_fee_success.toString();
    }
    return mapping.findForward(forward);
}
Also used : FeeActionForm(org.mifos.accounts.fees.struts.actionforms.FeeActionForm) ActionMessages(org.apache.struts.action.ActionMessages) FeeUpdateRequest(org.mifos.dto.domain.FeeUpdateRequest) ActionMessage(org.apache.struts.action.ActionMessage) FeeStatus(org.mifos.accounts.fees.util.helpers.FeeStatus) MifosRuntimeException(org.mifos.core.MifosRuntimeException) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

FeeStatus (org.mifos.accounts.fees.util.helpers.FeeStatus)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 ActionMessage (org.apache.struts.action.ActionMessage)1 ActionMessages (org.apache.struts.action.ActionMessages)1 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)1 FeeBO (org.mifos.accounts.fees.business.FeeBO)1 FeeStatusEntity (org.mifos.accounts.fees.business.FeeStatusEntity)1 RateFeeBO (org.mifos.accounts.fees.business.RateFeeBO)1 FeeException (org.mifos.accounts.fees.exceptions.FeeException)1 FeeActionForm (org.mifos.accounts.fees.struts.actionforms.FeeActionForm)1 FeeChangeType (org.mifos.accounts.fees.util.helpers.FeeChangeType)1 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)1 FeeUpdateRequest (org.mifos.dto.domain.FeeUpdateRequest)1 ApplicationException (org.mifos.framework.exceptions.ApplicationException)1 Money (org.mifos.framework.util.helpers.Money)1 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)1 BusinessRuleException (org.mifos.service.BusinessRuleException)1