use of org.mifos.security.MifosUser in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveStatusChangeHistory.
@Override
public List<SavingsStatusChangeHistoryDto> retrieveStatusChangeHistory(String globalAccountNum) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
SavingsBO savingsAccount = this.savingsDao.findBySystemId(globalAccountNum);
savingsAccount.updateDetails(userContext);
List<SavingsStatusChangeHistoryDto> dtoList = new ArrayList<SavingsStatusChangeHistoryDto>();
List<AccountStatusChangeHistoryEntity> statusChangeHistory = savingsAccount.getAccountStatusChangeHistory();
for (AccountStatusChangeHistoryEntity accountStatusChangeHistory : statusChangeHistory) {
dtoList.add(accountStatusChangeHistory.toDto());
}
return dtoList;
}
use of org.mifos.security.MifosUser in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveDepositWithdrawalReferenceData.
@Override
public DepositWithdrawalReferenceDto retrieveDepositWithdrawalReferenceData(Long savingsId, Integer customerId) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
try {
SavingsBO savingsAccount = savingsDao.findById(savingsId);
String depositDue = savingsAccount.getTotalPaymentDue(customerId).toString();
String withdrawalDue = "0";
List<ListElement> clients = new ArrayList<ListElement>();
if (savingsAccount.isGroupModelWithIndividualAccountability()) {
List<CustomerBO> activeAndOnHoldClients = new CustomerPersistence().getActiveAndOnHoldChildren(savingsAccount.getCustomer().getSearchId(), savingsAccount.getCustomer().getOfficeId(), CustomerLevel.CLIENT);
for (CustomerBO client : activeAndOnHoldClients) {
clients.add(new ListElement(client.getCustomerId(), client.getDisplayName()));
}
}
List<AccountActionEntity> trxnTypes = new ArrayList<AccountActionEntity>();
trxnTypes.add(new AccountBusinessService().getAccountAction(AccountActionTypes.SAVINGS_DEPOSIT.getValue(), userContext.getLocaleId()));
trxnTypes.add(new AccountBusinessService().getAccountAction(AccountActionTypes.SAVINGS_WITHDRAWAL.getValue(), userContext.getLocaleId()));
List<ListElement> transactionTypes = new ArrayList<ListElement>();
for (AccountActionEntity accountActionEntity : trxnTypes) {
LookUpValueEntity lookupValue = accountActionEntity.getLookUpValue();
String messageText = lookupValue.getMessageText();
if (StringUtils.isBlank(messageText)) {
messageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupValue.getPropertiesKey());
}
transactionTypes.add(new ListElement(accountActionEntity.getId().intValue(), messageText));
}
List<ListElement> depositPaymentTypes = retrieveDepositPaymentTypes(userContext);
List<ListElement> withdrawalPaymentTypes = new ArrayList<ListElement>();
List<PaymentTypeEntity> withdrawalPaymentEntityTypes = legacyAcceptedPaymentTypeDao.getAcceptedPaymentTypesForATransaction(userContext.getLocaleId(), TrxnTypes.savings_withdrawal.getValue());
for (PaymentTypeEntity paymentTypeEntity : withdrawalPaymentEntityTypes) {
LookUpValueEntity lookupValue = paymentTypeEntity.getLookUpValue();
String messageText = lookupValue.getMessageText();
if (StringUtils.isBlank(messageText)) {
messageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupValue.getPropertiesKey());
}
withdrawalPaymentTypes.add(new ListElement(paymentTypeEntity.getId().intValue(), messageText));
}
boolean backDatedTransactionsAllowed = AccountingRules.isBackDatedTxnAllowed();
LocalDate defaultTransactionDate = new LocalDate();
return new DepositWithdrawalReferenceDto(transactionTypes, depositPaymentTypes, withdrawalPaymentTypes, clients, backDatedTransactionsAllowed, defaultTransactionDate, depositDue, withdrawalDue);
} catch (ServiceException e) {
throw new MifosRuntimeException(e);
} catch (PersistenceException e) {
throw new MifosRuntimeException(e);
}
}
use of org.mifos.security.MifosUser 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.MifosUser 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.MifosUser 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();
}
}
Aggregations