use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class SavingsBO method createDepositTrxnsForMandatoryAccountsAfterAdjust.
private Set<AccountTrxnEntity> createDepositTrxnsForMandatoryAccountsAfterAdjust(final AccountPaymentEntity newAccountPayment, final AccountPaymentEntity lastAccountPayment, Money newAmount, LocalDate adjustmentDate, PersonnelBO createdBy) {
Set<AccountTrxnEntity> newTrxns = new LinkedHashSet<AccountTrxnEntity>();
SavingsTrxnDetailEntity accountTrxn = null;
CustomerBO customer = null;
Date trxnDate = adjustmentDate.toDateMidnight().toDate();
for (AccountTrxnEntity oldAccntTrxn : lastAccountPayment.getAccountTrxns()) {
customer = oldAccntTrxn.getCustomer();
break;
}
List<AccountActionDateEntity> accountActionList = getAccountActions(lastAccountPayment.getPaymentDate(), customer.getCustomerId());
for (AccountActionDateEntity accountActionDateEntity : accountActionList) {
SavingsScheduleEntity accountAction = (SavingsScheduleEntity) accountActionDateEntity;
if (newAmount.isZero()) {
break;
}
accountTrxn = null;
// if payment covers required deposit
if (accountAction.getDeposit().isLessThanOrEqual(newAmount)) {
this.savingsBalance = this.savingsBalance.add(accountAction.getDeposit());
Short installmentId = accountAction.getInstallmentId();
Date dueDate = accountAction.getActionDate();
Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, accountAction.getDeposit(), createdBy, dueDate, trxnDate, transactionCreatedDate, installmentId);
newAmount = newAmount.subtract(accountAction.getDeposit());
accountAction.setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
accountAction.setPaymentStatus(PaymentStatus.PAID);
} else {
this.savingsBalance = this.savingsBalance.add(newAmount);
Short installmentId = accountAction.getInstallmentId();
Date dueDate = accountAction.getActionDate();
Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, newAmount, createdBy, dueDate, trxnDate, transactionCreatedDate, installmentId);
newAmount = newAmount.subtract(newAmount);
accountAction.setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
accountAction.setPaymentStatus(PaymentStatus.UNPAID);
}
accountAction.setPaymentDate(new DateTimeService().getCurrentJavaSqlDate());
getSavingsPerformance().setTotalDeposits(getSavingsPerformance().getTotalDeposits().add(accountTrxn.getDepositAmount()));
newTrxns.add(accountTrxn);
}
// add trxn for excess amount
if (newAmount.isGreaterThanZero()) {
this.savingsBalance = this.savingsBalance.add(newAmount);
Short installmentId = null;
Date dueDate = null;
Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, newAmount, createdBy, dueDate, trxnDate, transactionCreatedDate, installmentId);
newAmount = newAmount.subtract(newAmount);
getSavingsPerformance().setTotalDeposits(getSavingsPerformance().getTotalDeposits().add(accountTrxn.getDepositAmount()));
newTrxns.add(accountTrxn);
}
return newTrxns;
}
use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class SavingsBO method createDepositTrxnsForVolAccountsAfterAdjust.
/*
* FIXME - keithw - it doesnt make sense to be that voluntary account break up account payments into more than one account transaction
* just because the amount deposited is greater than the 'recommended' amount.
*
* As a result there is no need to make a distinction between the amount deposited (be it less or greater than recommended amount)
*/
private Set<AccountTrxnEntity> createDepositTrxnsForVolAccountsAfterAdjust(final AccountPaymentEntity newAccountPayment, final AccountPaymentEntity lastAccountPayment, Money newAmount, LocalDate adjustmentDate, PersonnelBO loggedInUser) {
Set<AccountTrxnEntity> newTrxns = new LinkedHashSet<AccountTrxnEntity>();
SavingsTrxnDetailEntity accountTrxn = null;
CustomerBO customer = null;
Date trxnDate = adjustmentDate.toDateMidnight().toDate();
for (AccountTrxnEntity oldAccntTrxn : lastAccountPayment.getAccountTrxns()) {
customer = oldAccntTrxn.getCustomer();
break;
}
Short installmentId = null;
Date dueDate = null;
Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
for (AccountTrxnEntity oldAccntTrxn : lastAccountPayment.getAccountTrxns()) {
if (oldAccntTrxn.getAccountActionEntity().getId().equals(AccountActionTypes.SAVINGS_DEPOSIT.getValue())) {
SavingsTrxnDetailEntity oldSavingsAccntTrxn = (SavingsTrxnDetailEntity) oldAccntTrxn;
if (oldAccntTrxn.getInstallmentId() != null) {
SavingsScheduleEntity accountAction = (SavingsScheduleEntity) getAccountActionDate(oldSavingsAccntTrxn.getInstallmentId(), oldSavingsAccntTrxn.getCustomer().getCustomerId());
installmentId = accountAction.getInstallmentId();
dueDate = accountAction.getActionDate();
// if recommended amount is covered by payment
if (accountAction.getDeposit().isLessThanOrEqual(newAmount)) {
this.savingsBalance = this.savingsBalance.add(accountAction.getDeposit());
accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, accountAction.getDeposit(), loggedInUser, dueDate, trxnDate, transactionCreatedDate, installmentId);
newAmount = newAmount.subtract(accountAction.getDeposit());
accountAction.setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
accountAction.setPaymentStatus(PaymentStatus.PAID);
accountAction.setPaymentDate(new DateTimeService().getCurrentJavaSqlDate());
this.savingsPerformance.setTotalDeposits(this.savingsPerformance.getTotalDeposits().add(accountTrxn.getDepositAmount()));
} else if (newAmount.isNonZero()) {
// not zero and amount paid is less that recommended amount
this.savingsBalance = this.savingsBalance.add(newAmount);
accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, newAmount, loggedInUser, dueDate, trxnDate, transactionCreatedDate, installmentId);
newAmount = newAmount.subtract(newAmount);
accountAction.setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
accountAction.setPaymentStatus(PaymentStatus.UNPAID);
accountAction.setPaymentDate(new DateTimeService().getCurrentJavaSqlDate());
this.savingsPerformance.setTotalDeposits(this.savingsPerformance.getTotalDeposits().add(accountTrxn.getDepositAmount()));
}
break;
}
}
}
if (accountTrxn != null) {
newTrxns.add(accountTrxn);
}
// Create a new transaction with remaining amount
if (newAmount.isGreaterThanZero()) {
this.savingsBalance = this.savingsBalance.add(newAmount);
accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, newAmount, loggedInUser, dueDate, trxnDate, transactionCreatedDate, installmentId);
this.savingsPerformance.setTotalDeposits(this.savingsPerformance.getTotalDeposits().add(accountTrxn.getDepositAmount()));
newTrxns.add(accountTrxn);
}
return newTrxns;
}
use of org.mifos.accounts.business.AccountTrxnEntity 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.AccountTrxnEntity 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.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);
}
Aggregations