use of org.mifos.accounts.business.AccountPaymentEntity 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.accounts.business.AccountPaymentEntity 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.accounts.business.AccountPaymentEntity 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");
}
}
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class StandardAccountServiceIntegrationTest method testMakePaymentForLoanAccount.
@Test
public void testMakePaymentForLoanAccount() throws Exception {
String payemntAmount = "700";
CustomerDto clientDto = new CustomerDto();
clientDto.setCustomerId(client.getCustomerId());
LocalDate paymentDate = new LocalDate();
LocalDate receiptDate = new LocalDate().minusDays(3);
String receiptNumber = "AA/03/UX-9Q";
AccountPaymentParametersDto loanPayment = new AccountPaymentParametersDto(new UserReferenceDto(groupLoan.getPersonnel().getPersonnelId()), new AccountReferenceDto(groupLoan.getAccountId()), new BigDecimal(payemntAmount), paymentDate, defaultPaymentType, "comment", receiptDate, receiptNumber, clientDto);
standardAccountService.makePayment(loanPayment);
TestObjectFactory.updateObject(groupLoan);
Assert.assertEquals("The amount returned for the payment should have been " + payemntAmount, Double.parseDouble(payemntAmount), groupLoan.getLastPmntAmnt());
Assert.assertEquals(1, groupLoan.getAccountPayments().size());
for (AccountPaymentEntity payment : groupLoan.getAccountPayments()) {
Assert.assertEquals(TestUtils.createMoney(payemntAmount), payment.getAmount());
Assert.assertEquals(paymentDate.toDateMidnight().toDate(), payment.getPaymentDate());
Assert.assertEquals(defaultPaymentType.getName(), payment.getPaymentType().getName());
Assert.assertEquals("comment", payment.getComment());
Assert.assertEquals(groupLoan, payment.getAccount());
Assert.assertEquals(groupLoan.getPersonnel(), payment.getCreatedByUser());
Assert.assertEquals(receiptDate.toDateMidnight().toDate(), payment.getReceiptDate());
Assert.assertEquals(receiptNumber, payment.getReceiptNumber());
Assert.assertNull(payment.getCheckNumber());
Assert.assertNull(payment.getBankName());
Assert.assertNull(payment.getVoucherNumber());
Assert.assertFalse(payment.isSavingsDeposit());
Assert.assertFalse(payment.isSavingsWithdrawal());
Assert.assertFalse(payment.isSavingsDepositOrWithdrawal());
for (AccountTrxnEntity accountTrxn : payment.getAccountTrxns()) {
Assert.assertEquals(group.getCustomerId(), accountTrxn.getCustomer().getCustomerId());
}
}
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class LegacyAccountDaoIntegrationTest method testFindingAccountPaymentShouldReturnZeroPayments.
@Test
public void testFindingAccountPaymentShouldReturnZeroPayments() throws Exception {
savingsBO = createSavingsAccount();
AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(savingsBO, TestUtils.createMoney(100), "2222", new Date(System.currentTimeMillis()), new PaymentTypeEntity(Short.valueOf("1")), new Date(System.currentTimeMillis()));
List<AccountPaymentEntity> payments = new ArrayList<AccountPaymentEntity>();
payments.add(accountPaymentEntity);
savingsBO.setAccountPayments(payments);
legacyAccountDao.createOrUpdate(savingsBO);
StaticHibernateUtil.commitTransaction();
List<AccountPaymentEntity> result = legacyAccountDao.findAccountPaymentsByReceiptNumber("1111");
Assert.assertNotNull(result);
Assert.assertEquals(0, result.size());
}
Aggregations