Search in sources :

Example 96 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class BaseActionForm method checkForMandatoryFields.

protected void checkForMandatoryFields(Short entityId, ActionErrors errors, HttpServletRequest request) {
    Map<Short, List<FieldConfigurationEntity>> entityMandatoryFieldMap = (Map<Short, List<FieldConfigurationEntity>>) request.getSession().getServletContext().getAttribute(Constants.FIELD_CONFIGURATION);
    List<FieldConfigurationEntity> mandatoryfieldList = entityMandatoryFieldMap.get(entityId);
    for (FieldConfigurationEntity fieldConfigurationEntity : mandatoryfieldList) {
        String propertyName = request.getParameter(fieldConfigurationEntity.getLabel());
        if (propertyName != null && !propertyName.equals("")) {
            String propertyValue = request.getParameter(propertyName);
            UserContext userContext = ((UserContext) request.getSession().getAttribute(LoginConstants.USERCONTEXT));
            if (propertyValue == null || propertyValue.equals("")) {
                errors.add(fieldConfigurationEntity.getLabel(), new ActionMessage(FieldConfigurationConstant.EXCEPTION_MANDATORY, FieldConfigurationHelper.getLocalSpecificFieldNames(fieldConfigurationEntity.getLabel(), userContext)));
            }
        }
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) ActionMessage(org.apache.struts.action.ActionMessage) FieldConfigurationEntity(org.mifos.framework.components.fieldConfiguration.business.FieldConfigurationEntity) List(java.util.List) Map(java.util.Map)

Example 97 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class LoanDisbursementAction method update.

@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward update(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    LoanDisbursementActionForm actionForm = (LoanDisbursementActionForm) form;
    UserContext uc = getUserContext(request);
    Date trxnDate = getDateFromString(actionForm.getTransactionDate(), uc.getPreferredLocale());
    trxnDate = DateUtils.getDateWithoutTimeStamp(trxnDate.getTime());
    Date receiptDate = getDateFromString(actionForm.getReceiptDate(), uc.getPreferredLocale());
    Integer loanAccountId = Integer.valueOf(actionForm.getAccountId());
    Integer accountForTransferId = (StringUtils.isBlank(actionForm.getAccountForTransfer())) ? null : legacyAccountDao.getAccountIdByGlobalAccountNumber(actionForm.getAccountForTransfer());
    AccountBO accountBO = new AccountBusinessService().getAccount(loanAccountId);
    Date originalDisbursementDate = DateUtils.getDateWithoutTimeStamp(((LoanBO) accountBO).getDisbursementDate());
    createGroupQuestionnaire.saveResponses(request, actionForm, loanAccountId);
    try {
        String paymentTypeIdStringForDisbursement = actionForm.getPaymentTypeId();
        String paymentTypeIdStringForFees = actionForm.getPaymentModeOfPayment();
        Short paymentTypeIdForDisbursement = StringUtils.isEmpty(paymentTypeIdStringForDisbursement) ? PaymentTypes.CASH.getValue() : Short.valueOf(paymentTypeIdStringForDisbursement);
        Short paymentTypeIdForFees = StringUtils.isEmpty(paymentTypeIdStringForFees) ? PaymentTypes.CASH.getValue() : Short.valueOf(paymentTypeIdStringForFees);
        Short paymentTypeId = Short.valueOf(paymentTypeIdForDisbursement);
        final String comment = "";
        final BigDecimal disbursalAmount = new BigDecimal(actionForm.getLoanAmount());
        CustomerDto customerDto = null;
        PaymentTypeDto paymentType = null;
        AccountPaymentParametersDto loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto(uc.getId()), new AccountReferenceDto(loanAccountId), disbursalAmount, new LocalDate(trxnDate), paymentType, comment, new LocalDate(receiptDate), actionForm.getReceiptId(), customerDto);
        monthClosingServiceFacade.validateTransactionDate(trxnDate);
        // GLIM
        List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(loanAccountId);
        for (LoanBO individual : individualLoans) {
            if (!loanAccountServiceFacade.isTrxnDateValid(Integer.valueOf(individual.getAccountId()), trxnDate)) {
                throw new BusinessRuleException("errors.invalidTxndateOfDisbursal");
            }
        }
        this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId, paymentTypeIdForFees, accountForTransferId);
        for (LoanBO individual : individualLoans) {
            loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto(uc.getId()), new AccountReferenceDto(individual.getAccountId()), individual.getLoanAmount().getAmount(), new LocalDate(trxnDate), paymentType, comment, new LocalDate(receiptDate), actionForm.getReceiptId(), customerDto);
            this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId, paymentTypeIdForFees, accountForTransferId);
        }
        if (!((LoanBO) accountBO).isFixedRepaymentSchedule() && !originalDisbursementDate.equals(((LoanBO) accountBO).getDisbursementDate())) {
            this.loanAccountServiceFacade.updateMemberLoansFeeAmounts(loanAccountId);
        }
    } catch (BusinessRuleException e) {
        throw new AccountException(e.getMessage());
    } catch (MifosRuntimeException e) {
        if (e.getCause() != null && e.getCause() instanceof AccountException) {
            throw new AccountException(e.getCause().getMessage());
        }
        String msg = "errors.cannotDisburseLoan.because.disburseFailed";
        logger.error(msg, e);
        throw new AccountException(msg);
    } catch (Exception e) {
        String msg = "errors.cannotDisburseLoan.because.disburseFailed";
        logger.error(msg, e);
        throw new AccountException(msg);
    }
    return mapping.findForward(Constants.UPDATE_SUCCESS);
}
Also used : UserContext(org.mifos.security.util.UserContext) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) CustomerDto(org.mifos.dto.domain.CustomerDto) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) DateUtils.getUserLocaleDate(org.mifos.framework.util.helpers.DateUtils.getUserLocaleDate) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) AccountException(org.mifos.accounts.exceptions.AccountException) ServiceException(org.mifos.framework.exceptions.ServiceException) UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) AccountBO(org.mifos.accounts.business.AccountBO) BusinessRuleException(org.mifos.service.BusinessRuleException) LoanDisbursementActionForm(org.mifos.accounts.loan.struts.actionforms.LoanDisbursementActionForm) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) AccountException(org.mifos.accounts.exceptions.AccountException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 98 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class RepayLoanAction method makeGroupRepayment.

public ActionForward makeGroupRepayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    logger.info("Performing loan repayment");
    UserContext userContext = getUserContext(request);
    RepayLoanActionForm repayLoanActionForm = (RepayLoanActionForm) form;
    Date receiptDate = null;
    if (StringUtils.isNotEmpty(repayLoanActionForm.getReceiptDate())) {
        receiptDate = repayLoanActionForm.getReceiptDateValue(userContext.getPreferredLocale());
    }
    String globalAccountNum = request.getParameter("globalAccountNum");
    LoanBO loan = loanDao.findByGlobalAccountNum(globalAccountNum);
    String forward = Constants.UPDATE_SUCCESS;
    BigDecimal totalRepaymentAmount = ((Money) SessionUtils.getAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, request)).getAmount();
    BigDecimal waivedAmount = ((Money) SessionUtils.getAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, request)).getAmount();
    RepayLoanInfoDto repayLoanInfoDto = null;
    Map<String, Double> memberRepayment = new HashMap<String, Double>();
    if (loan.isGroupLoanAccountParent()) {
        memberRepayment = (Map<String, Double>) SessionUtils.getAttribute(LoanConstants.MEMBER_LOAN_REPAYMENT, request);
        repayLoanInfoDto = new RepayLoanInfoDto(globalAccountNum, repayLoanActionForm.getAmount(), repayLoanActionForm.getReceiptNumber(), receiptDate, repayLoanActionForm.getPaymentTypeId(), userContext.getId(), repayLoanActionForm.isWaiverInterest(), repayLoanActionForm.getDateOfPaymentValue(userContext.getPreferredLocale()), totalRepaymentAmount, waivedAmount);
    } else if (loan.isGroupLoanAccountMember()) {
        repayLoanInfoDto = new RepayLoanInfoDto(loan.getParentAccount().getGlobalAccountNum(), repayLoanActionForm.getAmount(), repayLoanActionForm.getReceiptNumber(), receiptDate, repayLoanActionForm.getPaymentTypeId(), userContext.getId(), repayLoanActionForm.isWaiverInterest(), repayLoanActionForm.getDateOfPaymentValue(userContext.getPreferredLocale()), totalRepaymentAmount, waivedAmount);
        memberRepayment.put(loan.getAccountId().toString(), Double.valueOf(repayLoanInfoDto.getEarlyRepayAmount()));
    }
    if (repayLoanActionForm.isSavingsTransfer()) {
        this.loanAccountServiceFacade.makeEarlyRepaymentFromSavings(repayLoanInfoDto, repayLoanActionForm.getAccountForTransfer());
    } else {
        this.loanAccountServiceFacade.makeEarlyGroupRepayment(repayLoanInfoDto, memberRepayment);
    }
    SessionUtils.removeAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, request);
    SessionUtils.removeAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, request);
    SessionUtils.removeAttribute(Constants.ACCOUNTS_FOR_TRANSFER, request);
    request.getSession().setAttribute("globalAccountNum", globalAccountNum);
    if (repayLoanActionForm.getPrintReceipt()) {
        return mapping.findForward(ActionForwards.printPaymentReceipt.toString());
    }
    return mapping.findForward(forward);
}
Also used : Money(org.mifos.framework.util.helpers.Money) RepayLoanInfoDto(org.mifos.dto.screen.RepayLoanInfoDto) HashMap(java.util.HashMap) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) RepayLoanActionForm(org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm) Date(java.sql.Date) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal)

Example 99 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class RepayLoanAction method makeGroupMemberRepayment.

public ActionForward makeGroupMemberRepayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    logger.info("Performing loan repayment");
    UserContext userContext = getUserContext(request);
    UserReferenceDto userReferenceDto = new UserReferenceDto(userContext.getId());
    RepayLoanActionForm repayLoanActionForm = (RepayLoanActionForm) form;
    String globalAccountNum = request.getParameter("globalAccountNum");
    String forward = Constants.UPDATE_SUCCESS;
    Date receiptDate = null;
    if (StringUtils.isNotEmpty(repayLoanActionForm.getReceiptDate())) {
        receiptDate = repayLoanActionForm.getReceiptDateValue(userContext.getPreferredLocale());
    }
    PaymentTypeDto paymentTypeDto = getLoanPaymentTypeDtoForId(Short.valueOf(repayLoanActionForm.getPaymentTypeId()));
    LoanBO acctualMemberAccount = loanDao.findByGlobalAccountNum(globalAccountNum);
    Integer accountId = acctualMemberAccount.getAccountId();
    AccountPaymentDto accountPaymentDto = this.accountServiceFacade.getAccountPaymentInformation(accountId, repayLoanActionForm.getPaymentTypeId(), userContext.getLocaleId(), userReferenceDto, repayLoanActionForm.getDateOfPaymentValue(defaultLocale));
    LoanBO parrentAccount = acctualMemberAccount.getParentAccount();
    Integer parentAccountId = parrentAccount.getAccountId();
    AccountPaymentParametersDto accountPaymentParametersDto = new AccountPaymentParametersDto(userReferenceDto, new AccountReferenceDto(parentAccountId), new BigDecimal(repayLoanActionForm.getAmount()), new LocalDate(DateUtils.getDate(repayLoanActionForm.getDateOfPayment())), paymentTypeDto, AccountConstants.NO_COMMENT, new LocalDate(DateUtils.getDate(repayLoanActionForm.getReceiptDate())), repayLoanActionForm.getReceiptNumber(), accountPaymentDto.getCustomerDto());
    BigDecimal totalRepaymentAmount = ((Money) SessionUtils.getAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, request)).getAmount();
    BigDecimal waivedAmount = ((Money) SessionUtils.getAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, request)).getAmount();
    RepayLoanInfoDto repayLoanInfoDto = new RepayLoanInfoDto(globalAccountNum, repayLoanActionForm.getAmount(), repayLoanActionForm.getReceiptNumber(), receiptDate, repayLoanActionForm.getPaymentTypeId(), userContext.getId(), repayLoanActionForm.isWaiverInterest(), repayLoanActionForm.getDateOfPaymentValue(userContext.getPreferredLocale()), totalRepaymentAmount, waivedAmount);
    HashMap<Integer, String> individualValues = new HashMap<Integer, String>();
    for (LoanBO member : loanDao.findIndividualLoans(parentAccountId)) {
        if (member.isAccountActive()) {
            if (member.getAccountId().equals(acctualMemberAccount.getAccountId())) {
                individualValues.put(member.getAccountId(), repayLoanActionForm.getAmount());
            } else {
                individualValues.put(member.getAccountId(), "0.0");
            }
        }
    }
    accountPaymentParametersDto.setMemberInfo(individualValues);
    accountPaymentParametersDto.setMemberAccountIdToRepay(accountId);
    accountPaymentParametersDto.setRepayLoanInfoDto(repayLoanInfoDto);
    accountPaymentParametersDto.setInterestDueForCurrentInstalmanet(this.loanAccountServiceFacade.calculateInterestDueForCurrentInstalmanet(repayLoanInfoDto));
    if (repayLoanActionForm.isSavingsTransfer()) {
        this.accountServiceFacade.makePaymentFromSavingsAcc(accountPaymentParametersDto, repayLoanActionForm.getAccountForTransfer());
    } else {
        this.accountServiceFacade.makePayment(accountPaymentParametersDto);
    }
    SessionUtils.removeAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, request);
    SessionUtils.removeAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, request);
    SessionUtils.removeAttribute(Constants.ACCOUNTS_FOR_TRANSFER, request);
    request.getSession().setAttribute("globalAccountNum", globalAccountNum);
    if (repayLoanActionForm.getPrintReceipt()) {
        return mapping.findForward(ActionForwards.printPaymentReceipt.toString());
    }
    return mapping.findForward(forward);
}
Also used : RepayLoanInfoDto(org.mifos.dto.screen.RepayLoanInfoDto) HashMap(java.util.HashMap) UserContext(org.mifos.security.util.UserContext) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) RepayLoanActionForm(org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) LocalDate(org.joda.time.LocalDate) Date(java.sql.Date) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) Money(org.mifos.framework.util.helpers.Money) AccountPaymentDto(org.mifos.accounts.servicefacade.AccountPaymentDto)

Example 100 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class LoanAccountAction method getLoanRepaymentSchedule.

@TransactionDemarcate(saveToken = true)
public ActionForward getLoanRepaymentSchedule(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    LoanAccountActionForm loanAccountActionForm = (LoanAccountActionForm) form;
    UserContext userContext = getUserContext(request);
    Integer loanId = Integer.valueOf(request.getParameter(ACCOUNT_ID));
    Locale locale = userContext.getPreferredLocale();
    Date viewDate = loanAccountActionForm.getScheduleViewDateValue(locale);
    LoanBO loan = getLoan(loanId);
    setSessionAtributeForGLIM(request, loan);
    loan.updateDetails(userContext);
    Errors errors = loanBusinessService.computeExtraInterest(loan, viewDate);
    if (errors.hasErrors()) {
        loanAccountActionForm.resetScheduleViewDate();
    }
    OriginalScheduleInfoDto originalSchedule = this.loanServiceFacade.retrieveOriginalLoanSchedule(loanId);
    String memberAccountIdParam = request.getParameter("memberAccountId");
    if (StringUtils.isNotBlank(memberAccountIdParam)) {
        Integer memberId = Integer.valueOf(memberAccountIdParam);
        LoanBO member = loan.findMemberById(memberId);
        if (member != null) {
            SessionUtils.setAttribute(CustomerConstants.CUSTOMER_NAME, member.getCustomer().getDisplayName(), request);
            SessionUtils.setAttribute(CustomerConstants.GLOBAL_CUST_NUM, member.getCustomer().getGlobalCustNum(), request);
        }
    }
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, loan, request);
    SessionUtils.setAttribute(Constants.ORIGINAL_SCHEDULE_AVAILABLE, originalSchedule.hasOriginalInstallments(), request);
    SessionUtils.setAttribute(Constants.VIEW_DATE, viewDate, request);
    String forward = errors.hasErrors() ? ActionForwards.getLoanRepaymentScheduleFailure.toString() : ActionForwards.getLoanRepaymentSchedule.toString();
    addErrors(request, getActionErrors(errors));
    return mapping.findForward(forward);
}
Also used : Locale(java.util.Locale) LoanAccountActionForm(org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm) ActionErrors(org.apache.struts.action.ActionErrors) Errors(org.mifos.platform.validations.Errors) UserContext(org.mifos.security.util.UserContext) OriginalScheduleInfoDto(org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) Date(java.util.Date) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

UserContext (org.mifos.security.util.UserContext)369 MifosUser (org.mifos.security.MifosUser)134 MifosRuntimeException (org.mifos.core.MifosRuntimeException)102 ArrayList (java.util.ArrayList)97 Test (org.junit.Test)81 BusinessRuleException (org.mifos.service.BusinessRuleException)75 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)72 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)65 AccountException (org.mifos.accounts.exceptions.AccountException)55 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)49 Money (org.mifos.framework.util.helpers.Money)46 LoanBO (org.mifos.accounts.loan.business.LoanBO)45 LocalDate (org.joda.time.LocalDate)44 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)43 ServiceException (org.mifos.framework.exceptions.ServiceException)43 PersistenceException (org.mifos.framework.exceptions.PersistenceException)38 CustomerBO (org.mifos.customers.business.CustomerBO)37 MeetingBO (org.mifos.application.meeting.business.MeetingBO)34 Date (java.util.Date)31 CustomerException (org.mifos.customers.exceptions.CustomerException)31