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);
}
}
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);
}
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();
}
}
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");
}
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");
}
Aggregations