Search in sources :

Example 31 with UserContext

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

the class LoanAccountServiceFacadeWebTier method makeEarlyGroupRepayment.

@Override
public void makeEarlyGroupRepayment(RepayLoanInfoDto repayLoanInfoDto, Map<String, Double> memberNumWithAmount) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    LoanBO parentLoan = this.loanDao.findByGlobalAccountNum(repayLoanInfoDto.getGlobalAccountNum());
    try {
        personnelDao.checkAccessPermission(userContext, parentLoan.getOfficeId(), parentLoan.getCustomer().getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException(e.getMessage(), e);
    }
    monthClosingServiceFacade.validateTransactionDate(repayLoanInfoDto.getDateOfPayment());
    if (!isTrxnDateValid(parentLoan.getAccountId(), repayLoanInfoDto.getDateOfPayment())) {
        throw new BusinessRuleException("errors.invalidTxndate");
    }
    try {
        if (repayLoanInfoDto.isWaiveInterest() && !parentLoan.isInterestWaived()) {
            throw new BusinessRuleException(LoanConstants.WAIVER_INTEREST_NOT_CONFIGURED);
        }
        BigDecimal interestDueForCurrentInstallment = calculateInterestDueForCurrentInstalmanet(repayLoanInfoDto);
        org.mifos.dto.domain.AccountPaymentDto paymentDto = new org.mifos.dto.domain.AccountPaymentDto(repayLoanInfoDto.getTotalRepaymentAmount().doubleValue(), repayLoanInfoDto.getDateOfPayment(), repayLoanInfoDto.getReceiptNumber(), repayLoanInfoDto.getReceiptDate(), repayLoanInfoDto.getId(), generateAmountWithInterest(memberNumWithAmount, repayLoanInfoDto));
        paymentDto.setPaymentTypeId(Short.valueOf(repayLoanInfoDto.getPaymentTypeId()));
        if (repayLoanInfoDto.getSavingsPaymentId() != null) {
            parentLoan.makeEarlyRepayment(paymentDto, repayLoanInfoDto.getId(), repayLoanInfoDto.isWaiveInterest(), new Money(parentLoan.getCurrency(), interestDueForCurrentInstallment), repayLoanInfoDto.getSavingsPaymentId(), null);
        } else {
            parentLoan.makeEarlyRepayment(paymentDto, repayLoanInfoDto.getId(), repayLoanInfoDto.isWaiveInterest(), new Money(parentLoan.getCurrency(), interestDueForCurrentInstallment));
        }
    } catch (AccountException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) BigDecimal(java.math.BigDecimal) Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) AccountPaymentDto(org.mifos.dto.screen.AccountPaymentDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 32 with UserContext

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

the class LoanAccountServiceFacadeWebTier method retrieveLoanPaymentsForReversal.

@Override
public List<LoanActivityDto> retrieveLoanPaymentsForReversal(String globalAccountNum) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
    userContext.setOfficeLevelId(userOffice.getOfficeLevel().getValue());
    LoanBO loan = null;
    LoanBO searchedLoan = this.loanDao.findByGlobalAccountNum(globalAccountNum);
    if (searchedLoan != null && isAccountUnderUserScope(searchedLoan, userContext)) {
        loan = searchedLoan;
    }
    if (loan == null) {
        throw new BusinessRuleException(LoanConstants.NOSEARCHRESULTS);
    }
    if (!loan.isAccountActive() || loan.isGroupLoanAccountMember()) {
        throw new BusinessRuleException(LoanConstants.NOSEARCHRESULTS);
    }
    return getApplicablePayments(loan);
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) OfficeBO(org.mifos.customers.office.business.OfficeBO) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory)

Example 33 with UserContext

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

the class LoanAccountServiceFacadeWebTier method removeLoanPenalty.

@Override
public void removeLoanPenalty(Integer loanId, Short penaltyId) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        AccountBO account = new AccountBusinessService().getAccount(loanId);
        if (account instanceof LoanBO) {
            LoanBO loanAccount = (LoanBO) account;
            List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(account.getAccountId());
            if (individualLoans != null && individualLoans.size() > 0) {
                for (LoanBO individual : individualLoans) {
                    individual.updateDetails(userContext);
                    individual.removePenalty(penaltyId, userContext.getId());
                    this.customerDao.save(individual);
                }
            }
            account.updateDetails(userContext);
            if (account.getPersonnel() != null) {
                new AccountBusinessService().checkPermissionForRemovePenalties(account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), account.getPersonnel().getPersonnelId());
            } else {
                new AccountBusinessService().checkPermissionForRemovePenalties(account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), userContext.getId());
            }
            this.transactionHelper.startTransaction();
            loanAccount.removePenalty(penaltyId, userContext.getId());
            this.loanDao.save(loanAccount);
            this.transactionHelper.commitTransaction();
        }
    } catch (ServiceException e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (AccountException e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) AccountException(org.mifos.accounts.exceptions.AccountException) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 34 with UserContext

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

the class OpenBalanceAction method submit.

public ActionForward submit(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    OpenBalanceActionForm actionForm = (OpenBalanceActionForm) form;
    UserContext context = getUserContext(request);
    //
    GlBalancesBO glBalancesBO = new GlBalancesBO();
    String finacialYearId = (String) (actionForm.getFinancialYearId() == "" ? "0" : actionForm.getFinancialYearId());
    glBalancesBO.setFinancialYearBO(accountingServiceFacade.getFinancialYearBO(new Integer(finacialYearId)));
    glBalancesBO.setCreatedBy(context.getId());
    glBalancesBO.setCreatedDate(DateUtils.getCurrentDateWithoutTimeStamp());
    glBalancesBO.setOfficeLevel(new Integer(actionForm.getOfficeHierarchy()));
    glBalancesBO.setOfficeId(actionForm.getOffice());
    glBalancesBO.setGlCodeValue(actionForm.getCoaName());
    glBalancesBO.setOpeningBalance(new BigDecimal(actionForm.getAmountAction() + actionForm.getOpenBalance()));
    glBalancesBO.setClosingBalance(new BigDecimal(actionForm.getAmountAction() + actionForm.getOpenBalance()));
    glBalancesBO.setTransactionDebitSum(new BigDecimal(0.0));
    glBalancesBO.setTransactionCreditSum(new BigDecimal(0.0));
    accountingServiceFacade.savingOpeningBalances(glBalancesBO);
    return mapping.findForward("submit_success");
}
Also used : OpenBalanceActionForm(org.mifos.accounting.struts.actionform.OpenBalanceActionForm) UserContext(org.mifos.security.util.UserContext) GlBalancesBO(org.mifos.application.accounting.business.GlBalancesBO) BigDecimal(java.math.BigDecimal)

Example 35 with UserContext

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

the class ProcessAccountingTransactionsAction method process.

public ActionForward process(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    /*ProcessAccountingTransactionsActionForm actionForm = (ProcessAccountingTransactionsActionForm) form;
		accountingServiceFacade.processMisPostings(
				DateUtils.getDate(actionForm.getLastProcessDate()),
				DateUtils.getDate(actionForm.getProcessTillDate()),getUserContext(request).getId());
		actionForm.setLastProcessDate(accountingServiceFacade
				.getLastProcessDate());
		storingSession(request, "ProcessAccountingTransactionsActionForm", actionForm);*/
    ProcessAccountingTransactionsActionForm actionForm = (ProcessAccountingTransactionsActionForm) form;
    UserContext userContext = getUserContext(request);
    monthClosingServiceFacade.validateTransactionDate(DateUtils.getDate(actionForm.getProcessTillDate()));
    accountingServiceFacade.processMisPostings(DateUtils.getDate(actionForm.getLastProcessDate()), DateUtils.getDate(actionForm.getProcessTillDate()), getUserContext(request).getId(), actionForm.getOffice());
    /*
		 * actionForm.setLastProcessDate(accountingServiceFacade
		 * .getLastProcessDate());
		 */
    actionForm.setLastProcessDate(accountingServiceFacade.getLastProcessUpdatedDate(actionForm.getOffice()));
    storingSession(request, "ProcessAccountingTransactionsActionForm", actionForm);
    return mapping.findForward("submit_success");
}
Also used : UserContext(org.mifos.security.util.UserContext) ProcessAccountingTransactionsActionForm(org.mifos.accounting.struts.actionform.ProcessAccountingTransactionsActionForm)

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