use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class CustomerAccountBOIntegrationTest method testTrxnDetailEntityObjectsForMultipleInstallmentsWhenOnlyCustomerAccountChargesAreDue.
@Test
public void testTrxnDetailEntityObjectsForMultipleInstallmentsWhenOnlyCustomerAccountChargesAreDue() throws Exception {
MeetingBO weeklyMeeting = new MeetingBuilder().customerMeeting().weekly().every(1).startingToday().build();
center = new CenterBuilder().with(weeklyMeeting).withName("Center").with(sampleBranchOffice()).withLoanOfficer(testUser()).build();
IntegrationTestObjectMother.createCenter((CenterBO) center, weeklyMeeting);
CustomerAccountBO customerAccount = center.getCustomerAccount();
final Money fiftyAmount = new Money(getCurrency(), "50.0");
final Money seventyAmount = new Money(getCurrency(), "70.0");
final Money oneHundredTwentyAmount = new Money(getCurrency(), "120.0");
final Money twoHundredFortyAmount = new Money(getCurrency(), "240.0");
for (AccountActionDateEntity accountActionDateEntity : customerAccount.getAccountActionDates()) {
CustomerScheduleEntity customerSchedule = (CustomerScheduleEntity) accountActionDateEntity;
if (customerSchedule.getInstallmentId() != 2) {
customerSchedule.setMiscFee(fiftyAmount);
customerSchedule.setMiscPenalty(seventyAmount);
}
}
Date transactionDate = incrementCurrentDate(14);
PaymentData paymentData = PaymentData.createPaymentData(twoHundredFortyAmount, center.getPersonnel(), Short.valueOf("1"), transactionDate);
paymentData.setCustomer(center);
IntegrationTestObjectMother.applyAccountPayment(customerAccount, paymentData);
if (customerAccount.getAccountPayments() != null && customerAccount.getAccountPayments().size() == 1) {
for (AccountPaymentEntity accountPaymentEntity : customerAccount.getAccountPayments()) {
final Money zeroAmount = new Money(accountPaymentEntity.getAmount().getCurrency(), "0.0");
if (accountPaymentEntity.getAccountTrxns() != null && accountPaymentEntity.getAccountTrxns().size() == 3) {
for (AccountTrxnEntity accountTrxnEntity : accountPaymentEntity.getAccountTrxns()) {
CustomerTrxnDetailEntity customerTrxnDetailEntity = (CustomerTrxnDetailEntity) accountTrxnEntity;
if (customerTrxnDetailEntity.getInstallmentId() != 2) {
Assert.assertEquals(oneHundredTwentyAmount, customerTrxnDetailEntity.getAmount());
Assert.assertEquals(oneHundredTwentyAmount, customerTrxnDetailEntity.getTotalAmount());
Assert.assertEquals(fiftyAmount, customerTrxnDetailEntity.getMiscFeeAmount());
Assert.assertEquals(seventyAmount, customerTrxnDetailEntity.getMiscPenaltyAmount());
} else {
Assert.assertEquals(zeroAmount, customerTrxnDetailEntity.getAmount());
Assert.assertEquals(zeroAmount, customerTrxnDetailEntity.getTotalAmount());
Assert.assertEquals(zeroAmount, customerTrxnDetailEntity.getMiscFeeAmount());
Assert.assertEquals(zeroAmount, customerTrxnDetailEntity.getMiscPenaltyAmount());
}
Assert.assertEquals(0, customerTrxnDetailEntity.getFeesTrxnDetails().size());
}
} else {
throw new Exception("Expected three CustomerTrxnDetailEntity, found none or not three");
}
}
} else {
throw new Exception("Expected one AccountPaymentEntity, found none or more than one");
}
}
use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class SavingsPostInterestTest method whenPostingInterestASingleAccountTransactionIsAssociatedWithAccountPayment.
@Test
public void whenPostingInterestASingleAccountTransactionIsAssociatedWithAccountPayment() {
// setup
InterestScheduledEvent postingSchedule = new MonthlyOnLastDayOfMonthInterestScheduledEvent(1);
Money interestToBePosted = TestUtils.createMoney("100");
DateTime activationDate = new DateTime().withDate(2010, 7, 20);
DateTime nextInterestPostingDate = new DateTime().withDate(2010, 7, 31);
savingsAccount = new SavingsAccountBuilder().active().withActivationDate(activationDate).withNextInterestPostingDateOf(nextInterestPostingDate).withSavingsProduct(savingsProduct).withCustomer(client).build();
// pre verification
assertTrue(savingsAccount.getAccountPayments().isEmpty());
InterestCalculationPeriodResult calculationPeriod = new InterestCalculationPeriodResultBuilder().withCalculatedInterest("100").build();
InterestPostingPeriodResult interestPostingPeriodResult = new InterestPostingPeriodResultBuilder().from(nextInterestPostingDate.toLocalDate()).to(nextInterestPostingDate.toLocalDate()).with(calculationPeriod).build();
PersonnelBO createdBy = new PersonnelBuilder().build();
// exercise
savingsAccount.postInterest(postingSchedule, interestPostingPeriodResult, createdBy);
// verification
AccountPaymentEntity interestPostingPayment = savingsAccount.getAccountPayments().get(0);
assertFalse(interestPostingPayment.getAccountTrxns().isEmpty());
List<AccountTrxnEntity> accountTransactions = new ArrayList<AccountTrxnEntity>(interestPostingPayment.getAccountTrxns());
SavingsTrxnDetailEntity interestPostingTransaction = (SavingsTrxnDetailEntity) accountTransactions.get(0);
assertThat(interestPostingTransaction.getAccount(), is((AccountBO) savingsAccount));
assertThat(interestPostingTransaction.getAmount(), is(interestToBePosted));
assertThat(interestPostingTransaction.getInterestAmount(), is(interestToBePosted));
assertThat(interestPostingTransaction.getAccountActionEntity().getId(), is(AccountActionTypes.SAVINGS_INTEREST_POSTING.getValue()));
assertThat(new LocalDate(interestPostingTransaction.getActionDate()), is(nextInterestPostingDate.toLocalDate()));
assertThat(new LocalDate(interestPostingTransaction.getDueDate()), is(today()));
assertThat(datePartOf(interestPostingTransaction.getTrxnCreatedDate()), is(today()));
}
use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class TestObjectFactory method deleteAccountPayment.
private static void deleteAccountPayment(final AccountPaymentEntity accountPayment, final Session session) {
Set<AccountTrxnEntity> loanTrxns = accountPayment.getAccountTrxns();
for (AccountTrxnEntity accountTrxn : loanTrxns) {
if (accountTrxn instanceof LoanTrxnDetailEntity) {
LoanTrxnDetailEntity loanTrxn = (LoanTrxnDetailEntity) accountTrxn;
for (FeesTrxnDetailEntity feesTrxn : loanTrxn.getFeesTrxnDetails()) {
session.delete(feesTrxn);
}
for (FinancialTransactionBO financialTrxn : loanTrxn.getFinancialTransactions()) {
session.delete(financialTrxn);
}
session.delete(loanTrxn);
}
}
session.delete(accountPayment);
}
use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class LoanBO method buildLoanActivity.
private LoanActivityEntity buildLoanActivity(final Collection<AccountTrxnEntity> accountTrxnDetails, final PersonnelBO personnel, String comments, final Date trxnDate) {
Date activityDate = trxnDate;
Money principal = new Money(getCurrency());
Money interest = new Money(getCurrency());
Money penalty = new Money(getCurrency());
Money fees = new Money(getCurrency());
for (AccountTrxnEntity accountTrxn : accountTrxnDetails) {
if (!accountTrxn.isTrxnForReversalOfLoanDisbursal()) {
LoanTrxnDetailEntity loanTrxn = (LoanTrxnDetailEntity) accountTrxn;
principal = principal.add(removeSign(loanTrxn.getPrincipalAmount()));
interest = interest.add(removeSign(loanTrxn.getInterestAmount()));
penalty = penalty.add(removeSign(loanTrxn.getPenaltyAmount())).add(removeSign(loanTrxn.getMiscPenaltyAmount()));
fees = fees.add(removeSign(loanTrxn.getMiscFeeAmount()));
for (FeesTrxnDetailEntity feesTrxn : loanTrxn.getFeesTrxnDetails()) {
fees = fees.add(removeSign(feesTrxn.getFeeAmount()));
}
}
if (accountTrxn.isTrxnForReversalOfLoanDisbursal() || accountTrxn.getAccountActionEntity().getId().equals(AccountActionTypes.LOAN_REVERSAL.getValue())) {
comments = "Loan Reversal";
}
}
Money interestOutstanding = loanSummary.getOriginalInterest().subtract(loanSummary.getInterestPaid());
if (isDecliningBalanceInterestRecalculation()) {
for (LoanScheduleEntity loanScheduleEntity : getLoanScheduleEntities()) {
interestOutstanding = interestOutstanding.add(loanScheduleEntity.getExtraInterest());
}
}
return new LoanActivityEntity(this, personnel, comments, principal, loanSummary.getOriginalPrincipal().subtract(loanSummary.getPrincipalPaid()), interest, interestOutstanding, fees, loanSummary.getOriginalFees().subtract(loanSummary.getFeesPaid()), penalty, loanSummary.getOriginalPenalty().subtract(loanSummary.getPenaltyPaid()), activityDate);
}
use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveTransactionHistory.
@Override
public List<SavingsTransactionHistoryDto> retrieveTransactionHistory(String globalAccountNum) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
SavingsBO savingsAccount = this.savingsDao.findBySystemId(globalAccountNum);
CustomerBO customerBO = savingsAccount.getCustomer();
savingsAccount.updateDetails(userContext);
try {
personnelDao.checkAccessPermission(userContext, customerBO.getOfficeId(), customerBO.getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
List<SavingsTransactionHistoryDto> savingsTransactionHistoryViewList = new ArrayList<SavingsTransactionHistoryDto>();
// Check for order-by clause in AccountBO.hbm.xml,
// AccountPayment.hbm.xml and AccountTrxnEntity.hbm.xml for
// accountPaymentSet ,
// accountTrxnSet and financialBoSet. They all should be set for their
// primay key column desc in both. If stated is not there, the code
// below will behave abnormally.
List<AccountPaymentEntity> accountPaymentSet = savingsAccount.getAccountPayments();
for (AccountPaymentEntity accountPaymentEntity : accountPaymentSet) {
Set<AccountTrxnEntity> accountTrxnEntitySet = accountPaymentEntity.getAccountTrxns();
for (AccountTrxnEntity accountTrxnEntity : accountTrxnEntitySet) {
Set<FinancialTransactionBO> financialTransactionBOSet = accountTrxnEntity.getFinancialTransactions();
for (FinancialTransactionBO financialTransactionBO : financialTransactionBOSet) {
SavingsTransactionHistoryDto savingsTransactionHistoryDto = new SavingsTransactionHistoryDto();
savingsTransactionHistoryDto.setTransactionDate(financialTransactionBO.getActionDate());
String preferredTransactionDate = DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), financialTransactionBO.getActionDate().toString());
savingsTransactionHistoryDto.setUserPrefferedTransactionDate(preferredTransactionDate);
savingsTransactionHistoryDto.setPaymentId(accountTrxnEntity.getAccountPayment().getPaymentId());
savingsTransactionHistoryDto.setAccountTrxnId(accountTrxnEntity.getAccountTrxnId());
savingsTransactionHistoryDto.setType(financialTransactionBO.getFinancialAction().getName());
savingsTransactionHistoryDto.setGlcode(financialTransactionBO.getGlcode().getGlcode());
savingsTransactionHistoryDto.setGlname(financialTransactionBO.getGlcode().getAssociatedCOA().getAccountName());
if (financialTransactionBO.isDebitEntry()) {
savingsTransactionHistoryDto.setDebit(String.valueOf(removeSign(financialTransactionBO.getPostedAmount())));
} else if (financialTransactionBO.isCreditEntry()) {
savingsTransactionHistoryDto.setCredit(String.valueOf(removeSign(financialTransactionBO.getPostedAmount())));
}
savingsTransactionHistoryDto.setBalance(String.valueOf(removeSign(((SavingsTrxnDetailEntity) accountTrxnEntity).getBalance())));
savingsTransactionHistoryDto.setClientName(accountTrxnEntity.getCustomer().getDisplayName());
savingsTransactionHistoryDto.setPostedDate(financialTransactionBO.getPostedDate());
String preferredDate = DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), financialTransactionBO.getPostedDate().toString());
savingsTransactionHistoryDto.setUserPrefferedPostedDate(preferredDate);
if (accountTrxnEntity.getPersonnel() != null) {
savingsTransactionHistoryDto.setPostedBy(accountTrxnEntity.getPersonnel().getDisplayName());
}
if (financialTransactionBO.getNotes() != null && !financialTransactionBO.getNotes().equals("")) {
savingsTransactionHistoryDto.setNotes(financialTransactionBO.getNotes());
}
savingsTransactionHistoryViewList.add(savingsTransactionHistoryDto);
}
}
}
return savingsTransactionHistoryViewList;
}
Aggregations