use of org.mifos.application.master.business.PaymentTypeEntity 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.application.master.business.PaymentTypeEntity 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);
}
use of org.mifos.application.master.business.PaymentTypeEntity in project head by mifos.
the class SavingsDepositWithdrawalAction method load.
@TransactionDemarcate(joinToken = true)
public ActionForward load(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
SavingsDepositWithdrawalActionForm actionForm = (SavingsDepositWithdrawalActionForm) form;
clearActionForm(actionForm);
Long savingsId = savings.getAccountId().longValue();
Integer customerId = savings.getCustomer().getCustomerId();
if (StringUtils.isNotBlank(actionForm.getCustomerId())) {
customerId = Integer.valueOf(actionForm.getCustomerId());
}
DepositWithdrawalReferenceDto depositWithdrawalReferenceDto = this.savingsServiceFacade.retrieveDepositWithdrawalReferenceData(savingsId, customerId);
savings = this.savingsDao.findById(savingsId);
SessionUtils.setAttribute(Constants.BUSINESS_KEY, savings, request);
if (savings.isGroupModelWithIndividualAccountability()) {
List<CustomerBO> activeAndOnHoldClients = new CustomerPersistence().getActiveAndOnHoldChildren(savings.getCustomer().getSearchId(), savings.getCustomer().getOfficeId(), CustomerLevel.CLIENT);
SessionUtils.setCollectionAttribute(SavingsConstants.CLIENT_LIST, activeAndOnHoldClients, request);
} else {
SessionUtils.setAttribute(SavingsConstants.CLIENT_LIST, new ArrayList<CustomerBO>(), request);
}
LegacyAcceptedPaymentTypeDao persistence = legacyAcceptedPaymentTypeDao;
List<PaymentTypeEntity> acceptedPaymentTypes = persistence.getAcceptedPaymentTypesForATransaction(uc.getLocaleId(), TrxnTypes.savings_deposit.getValue());
SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, acceptedPaymentTypes, request);
List<AccountActionEntity> trxnTypes = new ArrayList<AccountActionEntity>();
trxnTypes.add(getAccountsService().getAccountAction(AccountActionTypes.SAVINGS_DEPOSIT.getValue(), uc.getLocaleId()));
trxnTypes.add(getAccountsService().getAccountAction(AccountActionTypes.SAVINGS_WITHDRAWAL.getValue(), uc.getLocaleId()));
SessionUtils.setCollectionAttribute(AccountConstants.TRXN_TYPES, trxnTypes, request);
SessionUtils.setAttribute(SavingsConstants.IS_BACKDATED_TRXN_ALLOWED, depositWithdrawalReferenceDto.isBackDatedTransactionsAllowed(), request);
AccountPaymentEntity lastPayment = savings.findMostRecentDepositOrWithdrawalByDate();
if (lastPayment != null) {
actionForm.setLastTrxnDate(lastPayment.getPaymentDate());
}
actionForm.setTrxnDate(DateUtils.getCurrentDate(uc.getPreferredLocale()));
return mapping.findForward(ActionForwards.load_success.toString());
}
use of org.mifos.application.master.business.PaymentTypeEntity in project head by mifos.
the class FinancialBusinessServiceIntegrationTest method testLoanRescheduleAccountingEntries.
@Test
public void testLoanRescheduleAccountingEntries() throws Exception {
loan = getLoanAccount();
loan.setUserContext(TestUtils.makeUser());
AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(loan, TestUtils.createMoney(630), null, null, new PaymentTypeEntity(Short.valueOf("1")), new Date(System.currentTimeMillis()));
FinancialBusinessService financialBusinessService = new FinancialBusinessService();
AccountActionDateEntity accountActionDateEntity = loan.getAccountActionDate(Short.valueOf("1"));
PersonnelBO personnel = legacyPersonnelDao.getPersonnel(loan.getUserContext().getId());
LoanTrxnDetailEntity loanTrxnDetailEntity = new LoanTrxnDetailEntity(accountPaymentEntity, AccountActionTypes.LOAN_RESCHEDULED, accountActionDateEntity.getInstallmentId(), accountActionDateEntity.getActionDate(), personnel, new Date(System.currentTimeMillis()), ((LoanScheduleEntity) accountActionDateEntity).getPrincipal(), "Loan Rescheduled", null, ((LoanScheduleEntity) accountActionDateEntity).getPrincipal(), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), null, null);
accountPaymentEntity.addAccountTrxn(loanTrxnDetailEntity);
AccountTestUtils.addAccountPayment(accountPaymentEntity, loan);
financialBusinessService.buildAccountingEntries(loanTrxnDetailEntity);
TestObjectFactory.updateObject(loan);
Set<FinancialTransactionBO> finTrxnSet = loanTrxnDetailEntity.getFinancialTransactions();
Assert.assertEquals(finTrxnSet.size(), 2);
for (FinancialTransactionBO finTrxn : finTrxnSet) {
if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("23")) && finTrxn.isCreditEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("100"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("100"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("22"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("23")) && finTrxn.isDebitEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("100"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("100"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("7"));
} else {
Assert.fail("There should not be any other entry");
}
}
}
use of org.mifos.application.master.business.PaymentTypeEntity in project head by mifos.
the class FinancialBusinessServiceIntegrationTest method testLoanAdjustmentAccountingEntries.
@Test
public void testLoanAdjustmentAccountingEntries() throws Exception {
Date currentDate = new Date(System.currentTimeMillis());
loan = getLoanAccount();
loan.setUserContext(TestUtils.makeUser());
AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(loan, TestUtils.createMoney(630), "1111", currentDate, new PaymentTypeEntity(Short.valueOf("1")), new Date(System.currentTimeMillis()));
FinancialBusinessService financialBusinessService = new FinancialBusinessService();
AccountTrxnEntity accountTrxnEntity = getAccountTrxnObj(accountPaymentEntity);
accountPaymentEntity.addAccountTrxn(accountTrxnEntity);
AccountTestUtils.addAccountPayment(accountPaymentEntity, loan);
financialBusinessService.buildAccountingEntries(accountTrxnEntity);
TestObjectFactory.updateObject(loan);
for (FinancialTransactionBO finTrxn : accountTrxnEntity.getFinancialTransactions()) {
if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("1")) && finTrxn.isCreditEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("200"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("200"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("7"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("1")) && finTrxn.isDebitEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("200"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("200"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("22"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("2")) && finTrxn.isCreditEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("300"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("300"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("7"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("2")) && finTrxn.isDebitEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("300"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("300"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("43"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("3")) && finTrxn.isCreditEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("100"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("100"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("7"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("3")) && finTrxn.isDebitEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("100"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("100"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("52"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("4")) && finTrxn.isCreditEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("10"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("10"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("7"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("4")) && finTrxn.isDebitEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("10"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("10"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("52"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("6")) && finTrxn.isCreditEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("20"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("20"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("7"));
} else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("6")) && finTrxn.isDebitEntry()) {
Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("20"));
Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("20"));
Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("44"));
} else {
//--fail("There should not be any other entry");
}
}
}
Aggregations