use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class SavingsBO method doPostInterest.
private void doPostInterest(LocalDate currentPostingDate, Money actualInterestToBePosted, PersonnelBO loggedInUser) {
this.savingsBalance = this.savingsBalance.add(actualInterestToBePosted);
this.savingsPerformance.setTotalInterestDetails(actualInterestToBePosted);
SavingsActivityEntity savingsActivity = SavingsActivityEntity.savingsInterestPosting(this, personnel, this.savingsBalance, actualInterestToBePosted, currentPostingDate.toDateMidnight().toDate());
savingsActivityDetails.add(savingsActivity);
AccountPaymentEntity interestPayment = AccountPaymentEntity.savingsInterestPosting(this, actualInterestToBePosted, currentPostingDate.toDateMidnight().toDate(), loggedInUser);
DateTime dueDate = new DateTime();
SavingsTrxnDetailEntity interestPostingTransaction = SavingsTrxnDetailEntity.savingsInterestPosting(interestPayment, this.customer, this.savingsBalance, currentPostingDate.toDateMidnight().toDate(), dueDate, loggedInUser);
interestPayment.addAccountTrxn(interestPostingTransaction);
this.addAccountPayment(interestPayment);
// NOTE: financial Transaction Processing should be decoupled from application domain model.
try {
BaseFinancialActivity baseFinancialActivity = new SavingsInterestPostingFinancialActivity(interestPostingTransaction);
baseFinancialActivity.buildAccountEntries();
} catch (FinancialException e) {
throw new MifosRuntimeException(e);
}
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class RepayLoanAction method loadRepayment.
@TransactionDemarcate(joinToken = true)
public ActionForward loadRepayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
logger.info("Loading repay loan page");
RepayLoanActionForm actionForm = (RepayLoanActionForm) form;
actionForm.setReceiptNumber(null);
actionForm.setReceiptDate(null);
actionForm.setPaymentTypeId(null);
actionForm.setWaiverInterest(true);
actionForm.setDateOfPayment(DateUtils.makeDateAsSentFromBrowser());
actionForm.setTransferPaymentTypeId(this.legacyAcceptedPaymentTypeDao.getSavingsTransferId());
actionForm.setPrintReceipt(false);
actionForm.setTruePrintReceipt(false);
UserContext userContext = getUserContext(request);
String globalAccountNum = request.getParameter("globalAccountNum");
RepayLoanDto repayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(globalAccountNum);
LoanBO loan = this.loanDao.findByGlobalAccountNum(globalAccountNum);
java.util.Date lastPaymentDate = new java.util.Date(0);
AccountPaymentEntity lastPayment = loan.findMostRecentNonzeroPaymentByPaymentDate();
if (lastPayment != null) {
lastPaymentDate = lastPayment.getPaymentDate();
}
actionForm.setLastPaymentDate(lastPaymentDate);
SessionUtils.setAttribute(LoanConstants.WAIVER_INTEREST, repayLoanDto.shouldWaiverInterest(), request);
SessionUtils.setAttribute(LoanConstants.WAIVER_INTEREST_SELECTED, repayLoanDto.shouldWaiverInterest(), request);
SessionUtils.setAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, new Money(loan.getCurrency(), repayLoanDto.getEarlyRepaymentMoney()), request);
SessionUtils.setAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, new Money(loan.getCurrency(), repayLoanDto.getWaivedRepaymentMoney()), request);
SessionUtils.setCollectionAttribute(Constants.ACCOUNTS_FOR_TRANSFER, repayLoanDto.getSavingsAccountsForTransfer(), request);
List<PaymentTypeEntity> loanPaymentTypes = legacyAcceptedPaymentTypeDao.getAcceptedPaymentTypesForATransaction(userContext.getLocaleId(), TrxnTypes.loan_repayment.getValue());
SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, loanPaymentTypes, request);
return mapping.findForward(Constants.LOAD_SUCCESS);
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class RepayLoanAction method loadGroupRepayment.
@TransactionDemarcate(joinToken = true)
public ActionForward loadGroupRepayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
logger.info("Loading repay group loan page");
RepayLoanActionForm actionForm = (RepayLoanActionForm) form;
actionForm.setReceiptNumber(null);
actionForm.setReceiptDate(null);
actionForm.setPaymentTypeId(null);
actionForm.setWaiverInterest(true);
actionForm.setDateOfPayment(DateUtils.makeDateAsSentFromBrowser());
actionForm.setTransferPaymentTypeId(this.legacyAcceptedPaymentTypeDao.getSavingsTransferId());
actionForm.setPrintReceipt(false);
actionForm.setTruePrintReceipt(false);
UserContext userContext = getUserContext(request);
LoanBO parent = loanDao.findByGlobalAccountNum(request.getParameter("globalAccountNum"));
RepayLoanDto parentRepayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(parent.getGlobalAccountNum());
Map<String, Double> memberNumWithAmount = new HashMap<String, Double>();
Money earlyRepaymentMoney;
Money waivedRepaymentMoney;
if (parent.isGroupLoanAccountMember()) {
earlyRepaymentMoney = new Money(parent.getCurrency(), parentRepayLoanDto.getEarlyRepaymentMoney());
waivedRepaymentMoney = new Money(parent.getCurrency(), parentRepayLoanDto.getWaivedRepaymentMoney());
} else {
earlyRepaymentMoney = new Money(parent.getCurrency());
waivedRepaymentMoney = new Money(parent.getCurrency());
}
for (LoanBO member : parent.getMemberAccounts()) {
RepayLoanDto memberRepayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(member.getGlobalAccountNum());
earlyRepaymentMoney = earlyRepaymentMoney.add(new Money(parent.getCurrency(), memberRepayLoanDto.getEarlyRepaymentMoney()));
waivedRepaymentMoney = waivedRepaymentMoney.add(new Money(parent.getCurrency(), memberRepayLoanDto.getWaivedRepaymentMoney()));
memberNumWithAmount.put(member.getAccountId().toString(), Double.valueOf(memberRepayLoanDto.getEarlyRepaymentMoney()));
}
java.util.Date lastPaymentDate = new java.util.Date(0);
AccountPaymentEntity lastPayment = parent.findMostRecentNonzeroPaymentByPaymentDate();
if (lastPayment != null) {
lastPaymentDate = lastPayment.getPaymentDate();
}
actionForm.setLastPaymentDate(lastPaymentDate);
SessionUtils.setAttribute(LoanConstants.WAIVER_INTEREST, parentRepayLoanDto.shouldWaiverInterest(), request);
SessionUtils.setAttribute(LoanConstants.WAIVER_INTEREST_SELECTED, parentRepayLoanDto.shouldWaiverInterest(), request);
SessionUtils.setAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, earlyRepaymentMoney, request);
SessionUtils.setAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, waivedRepaymentMoney, request);
SessionUtils.setCollectionAttribute(Constants.ACCOUNTS_FOR_TRANSFER, parentRepayLoanDto.getSavingsAccountsForTransfer(), request);
SessionUtils.setMapAttribute(LoanConstants.MEMBER_LOAN_REPAYMENT, new HashMap<String, Double>(memberNumWithAmount), request);
List<PaymentTypeEntity> loanPaymentTypes = legacyAcceptedPaymentTypeDao.getAcceptedPaymentTypesForATransaction(userContext.getLocaleId(), TrxnTypes.loan_repayment.getValue());
SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, loanPaymentTypes, request);
return mapping.findForward(Constants.LOAD_GROUP_SUCCESS);
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class SavingsClosureAction method load.
@TransactionDemarcate(joinToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
SavingsClosureActionForm actionForm = (SavingsClosureActionForm) form;
actionForm.clearForm();
UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
Long savingsId = Long.valueOf(savings.getAccountId());
savings = this.savingsDao.findById(savingsId);
savings.setUserContext(uc);
// NOTE: initialise so when error occurs when apply adjustment, savings object is correctly initialised for
// use within Tag library in jsp.
new SavingsPersistence().initialize(savings);
LocalDate accountCloseDate = new LocalDate();
SavingsAccountClosureDto closureDetails = this.savingsServiceFacade.retrieveClosingDetails(savingsId, accountCloseDate);
LegacyAcceptedPaymentTypeDao persistence = legacyAcceptedPaymentTypeDao;
List<PaymentTypeEntity> acceptedPaymentTypes = persistence.getAcceptedPaymentTypesForATransaction(uc.getLocaleId(), TrxnTypes.savings_withdrawal.getValue());
Money interestAmountDue = new Money(savings.getCurrency(), closureDetails.getInterestAmountAtClosure());
Money endOfAccountBalance = new Money(savings.getCurrency(), closureDetails.getBalance());
Date transactionDate = closureDetails.getClosureDate().toDateMidnight().toDate();
Money withdrawalAmountAtClosure = endOfAccountBalance.add(interestAmountDue);
AccountPaymentEntity payment = new AccountPaymentEntity(savings, withdrawalAmountAtClosure, null, null, null, transactionDate);
actionForm.setAmount(withdrawalAmountAtClosure.toString());
actionForm.setTrxnDate(DateUtils.getCurrentDate(uc.getPreferredLocale()));
SessionUtils.setAttribute(Constants.BUSINESS_KEY, savings, request);
SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, acceptedPaymentTypes, request);
SessionUtils.setAttribute(SavingsConstants.ACCOUNT_PAYMENT, payment, request);
return mapping.findForward("load_success");
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class SavingsClosureAction method preview.
@TransactionDemarcate(joinToken = true)
public ActionForward preview(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
SavingsClosureActionForm actionForm = (SavingsClosureActionForm) form;
AccountPaymentEntity payment = (AccountPaymentEntity) SessionUtils.getAttribute(SavingsConstants.ACCOUNT_PAYMENT, request);
AccountPaymentEntity accountPaymentEntity = null;
Date transactionDate = new DateTimeService().getCurrentJavaDateTime();
if (actionForm.getReceiptDate() != null && actionForm.getReceiptDate() != "") {
accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), new java.util.Date(DateUtils.getDateAsSentFromBrowser(actionForm.getReceiptDate()).getTime()), new PaymentTypeEntity(Short.valueOf(actionForm.getPaymentTypeId())), transactionDate);
} else {
if (actionForm.getPaymentTypeId() != null && !actionForm.getPaymentTypeId().equals("")) {
if (!(actionForm.getPaymentTypeId().equals(""))) {
accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), null, new PaymentTypeEntity(Short.valueOf(actionForm.getPaymentTypeId())), transactionDate);
} else {
accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), null, new PaymentTypeEntity(), transactionDate);
}
} else {
accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), null, new PaymentTypeEntity(), transactionDate);
}
}
SessionUtils.setAttribute(SavingsConstants.ACCOUNT_PAYMENT, accountPaymentEntity, request);
return closeSavingsQuestionnaire.fetchAppliedQuestions(mapping, actionForm, request, ActionForwards.preview_success);
}
Aggregations