use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.
the class LoanAccountServiceFacadeWebTier method retrieveLoanRepaymentDetails.
@Override
public RepayLoanDto retrieveLoanRepaymentDetails(String globalAccountNumber) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
LoanBO loan = this.loanDao.findByGlobalAccountNum(globalAccountNumber);
try {
personnelDao.checkAccessPermission(userContext, loan.getOfficeId(), loan.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException(e.getMessage(), e);
}
Money repaymentAmount;
Money waiverAmount;
if (loan.isDecliningBalanceInterestRecalculation()) {
RepaymentResultsHolder repaymentResultsHolder = scheduleCalculatorAdaptor.computeRepaymentAmount(loan, DateUtils.getCurrentDateWithoutTimeStamp());
repaymentAmount = new Money(loan.getCurrency(), repaymentResultsHolder.getTotalRepaymentAmount());
waiverAmount = new Money(loan.getCurrency(), repaymentResultsHolder.getWaiverAmount());
} else {
repaymentAmount = loan.getEarlyRepayAmount();
waiverAmount = loan.waiverAmount();
}
Money waivedRepaymentAmount = repaymentAmount.subtract(waiverAmount);
List<SavingsDetailDto> savingsInUse = clientServiceFacade.retrieveSavingsInUseForClient(loan.getCustomer().getCustomerId());
List<SavingsDetailDto> accountsForTransfer = new ArrayList<SavingsDetailDto>();
if (savingsInUse != null) {
for (SavingsDetailDto savingsAccount : savingsInUse) {
if (savingsAccount.getAccountStateId().equals(AccountState.SAVINGS_ACTIVE.getValue())) {
accountsForTransfer.add(savingsAccount);
}
}
}
return new RepayLoanDto(repaymentAmount.toString(), waivedRepaymentAmount.toString(), loan.isInterestWaived(), accountsForTransfer);
}
use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.
the class LoanAccountServiceFacadeWebTier method retrieveInstallmentDetails.
@Override
public LoanInstallmentDetailsDto retrieveInstallmentDetails(Integer accountId) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
LoanBO loanBO = this.loanDao.findById(accountId);
try {
personnelDao.checkAccessPermission(userContext, loanBO.getOfficeId(), loanBO.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException(e.getMessage(), e);
}
InstallmentDetailsDto viewUpcomingInstallmentDetails;
InstallmentDetailsDto viewOverDueInstallmentDetails;
if (loanBO.isGroupLoanAccount() && null == loanBO.getParentAccount()) {
List<AccountActionDateEntity> memberDetailsOfNextInstallment = new ArrayList<AccountActionDateEntity>();
List<List<AccountActionDateEntity>> memberDetailsOfInstallmentsInArrears = new ArrayList<List<AccountActionDateEntity>>();
for (LoanBO member : loanBO.getMemberAccounts()) {
memberDetailsOfNextInstallment.add(member.getDetailsOfNextInstallment());
memberDetailsOfInstallmentsInArrears.add(member.getDetailsOfInstallmentsInArrears());
}
viewUpcomingInstallmentDetails = getUpcomingInstallmentDetailsForGroupLoan(memberDetailsOfNextInstallment, loanBO.getCurrency());
viewOverDueInstallmentDetails = getOverDueInstallmentDetailsForGroupLoan(memberDetailsOfInstallmentsInArrears, loanBO.getCurrency());
} else {
viewUpcomingInstallmentDetails = getUpcomingInstallmentDetails(loanBO.getDetailsOfNextInstallment(), loanBO.getCurrency());
viewOverDueInstallmentDetails = getOverDueInstallmentDetails(loanBO.getDetailsOfInstallmentsInArrears(), loanBO.getCurrency());
}
Money upcomingInstallmentSubTotal = new Money(loanBO.getCurrency(), viewUpcomingInstallmentDetails.getSubTotal());
Money overdueInstallmentSubTotal = new Money(loanBO.getCurrency(), viewOverDueInstallmentDetails.getSubTotal());
Money totalAmountDue = upcomingInstallmentSubTotal.add(overdueInstallmentSubTotal);
return new LoanInstallmentDetailsDto(viewUpcomingInstallmentDetails, viewOverDueInstallmentDetails, totalAmountDue.toString(), loanBO.getNextMeetingDate());
}
use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.
the class LoanAccountServiceFacadeWebTier method makeEarlyRepaymentFromSavings.
public void makeEarlyRepaymentFromSavings(RepayLoanInfoDto repayLoanInfoDto, String savingsAccGlobalNum) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
SavingsAccountDetailDto savingsAcc = savingsServiceFacade.retrieveSavingsAccountDetails(savingsAccGlobalNum);
Long savingsId = savingsAcc.getAccountId().longValue();
Long customerId = savingsAcc.getCustomerId().longValue();
LocalDate trxnDate = new LocalDate(repayLoanInfoDto.getDateOfPayment());
Double amount = Double.parseDouble(repayLoanInfoDto.getEarlyRepayAmount());
Integer paymentTypeId = Integer.parseInt(repayLoanInfoDto.getPaymentTypeId());
String receiptId = repayLoanInfoDto.getReceiptNumber();
LocalDate receiptDate = new LocalDate(repayLoanInfoDto.getReceiptDate());
Locale preferredLocale = userContext.getPreferredLocale();
SavingsWithdrawalDto savingsWithdrawalDto = new SavingsWithdrawalDto(savingsId, customerId, trxnDate, amount, paymentTypeId, receiptId, receiptDate, preferredLocale);
try {
transactionHelper.startTransaction();
PaymentDto withdrawal = savingsServiceFacade.withdraw(savingsWithdrawalDto, true);
repayLoanInfoDto.setSavingsPaymentId(withdrawal.getPaymentId());
makeEarlyRepayment(repayLoanInfoDto);
transactionHelper.commitTransaction();
} catch (BusinessRuleException e) {
transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getMessageKey(), e);
} catch (Exception e) {
transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
}
}
use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.
the class LoanAccountServiceFacadeWebTier method makeEarlyRepayment.
@Override
public void makeEarlyRepayment(RepayLoanInfoDto repayLoanInfoDto) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
LoanBO loan = this.loanDao.findByGlobalAccountNum(repayLoanInfoDto.getGlobalAccountNum());
try {
personnelDao.checkAccessPermission(userContext, loan.getOfficeId(), loan.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException(e.getMessage(), e);
}
monthClosingServiceFacade.validateTransactionDate(repayLoanInfoDto.getDateOfPayment());
if (!isTrxnDateValid(loan.getAccountId(), repayLoanInfoDto.getDateOfPayment())) {
throw new BusinessRuleException("errors.invalidTxndate");
}
try {
if (repayLoanInfoDto.isWaiveInterest() && !loan.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(Double.valueOf(repayLoanInfoDto.getEarlyRepayAmount()), repayLoanInfoDto.getDateOfPayment(), repayLoanInfoDto.getReceiptNumber(), repayLoanInfoDto.getReceiptDate(), repayLoanInfoDto.getId());
paymentDto.setPaymentTypeId(Short.valueOf(repayLoanInfoDto.getPaymentTypeId()));
if (repayLoanInfoDto.getSavingsPaymentId() != null) {
paymentDto.setMemberNumWithAmount(generateAmountWithInterest(null == repayLoanInfoDto.getMembersValue() ? new HashMap<String, Double>() : repayLoanInfoDto.getMembersValue(), repayLoanInfoDto));
loan.makeEarlyRepayment(paymentDto, repayLoanInfoDto.getId(), repayLoanInfoDto.isWaiveInterest(), new Money(loan.getCurrency(), interestDueForCurrentInstallment), repayLoanInfoDto.getSavingsPaymentId(), null);
} else {
loan.makeEarlyRepayment(paymentDto, repayLoanInfoDto.getId(), repayLoanInfoDto.isWaiveInterest(), new Money(loan.getCurrency(), interestDueForCurrentInstallment));
}
} catch (AccountException e) {
throw new BusinessRuleException(e.getKey(), e);
}
}
use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.
the class LoanAccountServiceFacadeWebTier method retrieveLoanOfficerDetailsForBranch.
@Override
public ChangeAccountStatusDto retrieveLoanOfficerDetailsForBranch(Short officeId) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
CenterCreation officeDetails = new CenterCreation(officeId, userContext.getId(), userContext.getLevelId(), userContext.getPreferredLocale());
List<PersonnelDto> loanOfficers = this.personnelDao.findActiveLoanOfficersForOffice(officeDetails);
boolean loanPendingApprovalStateEnabled = ProcessFlowRules.isLoanPendingApprovalStateEnabled();
Short accountState = AccountState.LOAN_PARTIAL_APPLICATION.getValue();
if (loanPendingApprovalStateEnabled) {
accountState = AccountState.LOAN_PENDING_APPROVAL.getValue();
}
boolean centerHierarchyExists = ClientRules.getCenterHierarchyExists();
return new ChangeAccountStatusDto(new ArrayList<OfficeDetailsDto>(), loanOfficers, loanPendingApprovalStateEnabled, accountState, centerHierarchyExists);
}
Aggregations