use of org.mifos.accounts.business.AccountFeesActionDetailEntity in project head by mifos.
the class LoanAccountServiceFacadeWebTier method updateMemberLoansFeeAmounts.
@Override
public void updateMemberLoansFeeAmounts(Integer accountId) {
LoanBO loan = this.loanDao.findById(accountId);
List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(accountId);
try {
transactionHelper.startTransaction();
Map<Integer, LoanScheduleEntity> parentScheduleEntities = loan.getLoanScheduleEntityMap();
for (Integer installmentId : parentScheduleEntities.keySet()) {
LoanScheduleEntity parentEntity = parentScheduleEntities.get(installmentId);
Map<Short, BigDecimal> feeAmountsForInstallment = new HashMap<Short, BigDecimal>();
for (AccountFeesActionDetailEntity feesActionDetailEntity : parentEntity.getAccountFeesActionDetails()) {
feeAmountsForInstallment.put(feesActionDetailEntity.getFee().getFeeId(), feesActionDetailEntity.getFeeAmount().getAmount());
}
for (int i = 0; i < individualLoans.size(); i++) {
LoanScheduleEntity memberEntity = individualLoans.get(i).getLoanScheduleEntityMap().get(installmentId);
for (AccountFeesActionDetailEntity feesActionDetailEntity : memberEntity.getAccountFeesActionDetails()) {
if (feesActionDetailEntity.getFee().getFeeType().equals(RateAmountFlag.RATE)) {
continue;
}
BigDecimal currentAmount = feeAmountsForInstallment.get(feesActionDetailEntity.getFee().getFeeId());
currentAmount = currentAmount.subtract(feesActionDetailEntity.getFeeAmount().getAmount());
if (currentAmount.compareTo(BigDecimal.ZERO) != 0 && i == individualLoans.size() - 1) {
BigDecimal toUpdate = feesActionDetailEntity.getFeeAmount().getAmount().add(currentAmount);
feesActionDetailEntity.updateFeeAmount(toUpdate);
currentAmount = BigDecimal.ZERO;
}
feeAmountsForInstallment.put(feesActionDetailEntity.getFee().getFeeId(), currentAmount);
}
}
}
for (LoanBO memberLoan : individualLoans) {
memberLoan.updateLoanSummary();
loanDao.save(memberLoan);
}
loanDao.save(loan);
transactionHelper.flushSession();
this.loanBusinessService.clearAndPersistOriginalSchedule(loan);
for (LoanBO memberLoan : individualLoans) {
this.loanBusinessService.clearAndPersistOriginalSchedule(memberLoan);
}
transactionHelper.commitTransaction();
} catch (BusinessRuleException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getMessageKey(), e);
} catch (PersistenceException e) {
throw new MifosRuntimeException();
} finally {
this.transactionHelper.closeSession();
}
}
use of org.mifos.accounts.business.AccountFeesActionDetailEntity in project head by mifos.
the class LoanTestUtils method assertOneInstallmentFee.
/**
* Check amount of the account fee in the installment. Note that this only
* works correctly if the installment has just one account fee.
*/
public static void assertOneInstallmentFee(Money expected, LoanScheduleEntity installment) {
Set<AccountFeesActionDetailEntity> actionDetails = installment.getAccountFeesActionDetails();
Assert.assertFalse("expected fee > 0.0 but loan has no account fees", expected.getAmountDoubleValue() > 0.0 & actionDetails.size() == 0);
for (AccountFeesActionDetailEntity detail : actionDetails) {
Assert.assertEquals(expected, detail.getFeeDue());
}
}
use of org.mifos.accounts.business.AccountFeesActionDetailEntity in project head by mifos.
the class LoanScheduleEntityTest method shouldPayComponents.
@Test
public void shouldPayComponents() {
loanScheduleEntity = new LoanScheduleEntity() {
@Override
public Money getTotalDueWithFees() {
return Money.zero(RUPEE);
}
};
when(loanBO.getCurrency()).thenReturn(RUPEE);
loanScheduleEntity.setAccount(loanBO);
loanScheduleEntity.setPrincipalPaid(Money.zero(RUPEE));
loanScheduleEntity.setInterestPaid(Money.zero(RUPEE));
loanScheduleEntity.setExtraInterestPaid(Money.zero(RUPEE));
loanScheduleEntity.setPenaltyPaid(Money.zero(RUPEE));
loanScheduleEntity.setMiscPenaltyPaid(Money.zero(RUPEE));
loanScheduleEntity.setMiscFeePaid(Money.zero(RUPEE));
AccountFeesActionDetailEntity feesActionDetailEntity = new LoanFeeScheduleEntity(loanScheduleEntity, mock(FeeBO.class), mock(AccountFeesEntity.class), new Money(RUPEE, 100d));
feesActionDetailEntity.setAccountFeesActionDetailId(1);
loanScheduleEntity.addAccountFeesAction(feesActionDetailEntity);
loanScheduleEntity.payComponents(getInstallment(), RUPEE, paymentDate);
PaymentAllocation paymentAllocation = loanScheduleEntity.getPaymentAllocation();
assertEquals(new Money(RUPEE, 90.0), paymentAllocation.getPrincipalPaid());
assertEquals(new Money(RUPEE, 80.0), paymentAllocation.getInterestPaid());
assertEquals(new Money(RUPEE, 70.0), paymentAllocation.getExtraInterestPaid());
assertEquals(new Money(RUPEE, 60.0), paymentAllocation.getTotalFeesPaid());
assertEquals(new Money(RUPEE, 50.0), paymentAllocation.getMiscFeePaid());
assertEquals(new Money(RUPEE, 40.0), paymentAllocation.getPenaltyPaid());
assertEquals(new Money(RUPEE, 30.0), paymentAllocation.getMiscPenaltyPaid());
assertEquals(new Money(RUPEE, 100.0), loanScheduleEntity.getExtraInterest());
assertEquals(new Money(RUPEE, 100.0), loanScheduleEntity.getInterest());
}
use of org.mifos.accounts.business.AccountFeesActionDetailEntity in project head by mifos.
the class DefaultLoanScheduleRounderHelper method roundInstallmentAccountFeesDue_v2.
private LoanScheduleEntity roundInstallmentAccountFeesDue_v2(final LoanScheduleEntity installment) {
for (Object element : installment.getAccountFeesActionDetails()) {
AccountFeesActionDetailEntity e = (AccountFeesActionDetailEntity) element;
e.roundFeeAmount(MoneyUtils.currencyRound(e.getFeeDue().add(e.getFeeAmountPaid())));
}
return installment;
}
use of org.mifos.accounts.business.AccountFeesActionDetailEntity in project head by mifos.
the class LoanBOTestUtils method createLoanAccountWithDisbursement.
/**
* Like
* {@link #createLoanAccount(String, CustomerBO, AccountState, Date, LoanOfferingBO)}
* but differs in various ways.
*
* Note: the manipulation done in this method looks very suspicious and
* possibly wrong. Tests that use this method should be considered as
* suspect.
*/
public static LoanBO createLoanAccountWithDisbursement(final CustomerBO customer, final AccountState state, final Date startDate, final LoanOfferingBO loanOffering, final int disbursalType, final Short noOfInstallments) {
Calendar calendar = new GregorianCalendar();
calendar.setTime(startDate);
MeetingBO meeting = TestObjectFactory.createLoanMeeting(customer.getCustomerMeeting().getMeeting());
List<Date> meetingDates = TestObjectFactory.getMeetingDates(customer.getOfficeId(), meeting, 6);
MifosCurrency currency = TestUtils.RUPEE;
List<CreateAccountFeeDto> accountFees = new ArrayList<CreateAccountFeeDto>();
AmountFeeBO maintanenceFee = (AmountFeeBO) TestObjectFactory.createPeriodicAmountFee("Mainatnence Fee", FeeCategory.LOAN, "100", RecurrenceType.WEEKLY, Short.valueOf("1"));
IntegrationTestObjectMother.saveFee(maintanenceFee);
accountFees.add(new CreateAccountFeeDto(maintanenceFee.getFeeId().intValue(), maintanenceFee.getFeeAmount().toString()));
AccountFeesEntity accountDisbursementFee = null;
AmountFeeBO disbursementFee = null;
AccountFeesEntity accountDisbursementFee2 = null;
AmountFeeBO disbursementFee2 = null;
if (disbursalType == 1 || disbursalType == 2) {
disbursementFee = (AmountFeeBO) TestObjectFactory.createOneTimeAmountFee("Disbursement Fee 1", FeeCategory.LOAN, "10", FeePayment.TIME_OF_DISBURSEMENT);
IntegrationTestObjectMother.saveFee(disbursementFee);
accountFees.add(new CreateAccountFeeDto(disbursementFee.getFeeId().intValue(), disbursementFee.getFeeAmount().toString()));
disbursementFee2 = (AmountFeeBO) TestObjectFactory.createOneTimeAmountFee("Disbursement Fee 2", FeeCategory.LOAN, "20", FeePayment.TIME_OF_DISBURSEMENT);
IntegrationTestObjectMother.saveFee(disbursementFee2);
accountFees.add(new CreateAccountFeeDto(disbursementFee2.getFeeId().intValue(), disbursementFee2.getFeeAmount().toString()));
}
BigDecimal loanAmount = BigDecimal.valueOf(DEFAULT_LOAN_AMOUNT);
BigDecimal minAllowedLoanAmount = loanAmount;
BigDecimal maxAllowedLoanAmount = loanAmount;
Double interestRate = Double.valueOf("10.0");
LocalDate disbursementDate = new LocalDate(meetingDates.get(0));
int numberOfInstallments = noOfInstallments;
int minAllowedNumberOfInstallments = loanOffering.getEligibleInstallmentSameForAllLoan().getMaxNoOfInstall();
int maxAllowedNumberOfInstallments = loanOffering.getEligibleInstallmentSameForAllLoan().getMaxNoOfInstall();
int graceDuration = 0;
Integer sourceOfFundId = null;
Integer loanPurposeId = null;
Integer collateralTypeId = null;
String collateralNotes = null;
String externalId = null;
boolean repaymentScheduleIndependentOfCustomerMeeting = false;
RecurringSchedule recurringSchedule = null;
CreateLoanAccount createLoanAccount = new CreateLoanAccount(customer.getCustomerId(), loanOffering.getPrdOfferingId().intValue(), state.getValue().intValue(), loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount, interestRate, disbursementDate, null, numberOfInstallments, minAllowedNumberOfInstallments, maxAllowedNumberOfInstallments, graceDuration, sourceOfFundId, loanPurposeId, collateralTypeId, collateralNotes, externalId, repaymentScheduleIndependentOfCustomerMeeting, recurringSchedule, accountFees, new ArrayList<CreateAccountPenaltyDto>());
SecurityContext securityContext = new SecurityContextImpl();
MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
Authentication authentication = new TestingAuthenticationToken(principal, principal);
securityContext.setAuthentication(authentication);
SecurityContextHolder.setContext(securityContext);
LoanBO loan = IntegrationTestObjectMother.createClientLoan(createLoanAccount);
loan.updateDetails(TestUtils.makeUser());
AccountFeesEntity accountPeriodicFee = new AccountFeesEntity(loan, maintanenceFee, new Double("10.0"));
AccountTestUtils.addAccountFees(accountPeriodicFee, loan);
if (disbursalType == 1 || disbursalType == 2) {
accountDisbursementFee = new AccountFeesEntity(loan, disbursementFee, new Double("10.0"));
AccountTestUtils.addAccountFees(accountDisbursementFee, loan);
accountDisbursementFee2 = new AccountFeesEntity(loan, disbursementFee2, new Double("20.0"));
AccountTestUtils.addAccountFees(accountDisbursementFee2, loan);
}
loan.setLoanMeeting(meeting);
if (// 2-Interest At Disbursement
disbursalType == 2) {
loan.setInterestDeductedAtDisbursement(true);
meetingDates = TestObjectFactory.getMeetingDates(customer.getOfficeId(), loan.getLoanMeeting(), 6);
short i = 0;
for (Date date : meetingDates) {
if (i == 0) {
i++;
loan.setDisbursementDate(date);
LoanScheduleEntity actionDate = (LoanScheduleEntity) loan.getAccountActionDate(i);
actionDate.setActionDate(new java.sql.Date(date.getTime()));
actionDate.setInterest(new Money(currency, "12.0"));
actionDate.setPaymentStatus(PaymentStatus.UNPAID);
AccountTestUtils.addAccountActionDate(actionDate, loan);
// periodic fee
AccountFeesActionDetailEntity accountFeesaction = new LoanFeeScheduleEntity(actionDate, maintanenceFee, accountPeriodicFee, new Money(currency, "10.0"));
setFeeAmountPaid(accountFeesaction, new Money(currency, "0.0"));
actionDate.addAccountFeesAction(accountFeesaction);
// dibursement fee one
AccountFeesActionDetailEntity accountFeesaction1 = new LoanFeeScheduleEntity(actionDate, disbursementFee, accountDisbursementFee, new Money(currency, "10.0"));
setFeeAmountPaid(accountFeesaction1, new Money(currency, "0.0"));
actionDate.addAccountFeesAction(accountFeesaction1);
// disbursementfee2
AccountFeesActionDetailEntity accountFeesaction2 = new LoanFeeScheduleEntity(actionDate, disbursementFee2, accountDisbursementFee2, new Money(currency, "20.0"));
setFeeAmountPaid(accountFeesaction2, new Money(currency, "0.0"));
actionDate.addAccountFeesAction(accountFeesaction2);
continue;
}
i++;
LoanScheduleEntity actionDate = (LoanScheduleEntity) loan.getAccountActionDate(i);
actionDate.setActionDate(new java.sql.Date(date.getTime()));
actionDate.setPrincipal(new Money(currency, "100.0"));
actionDate.setInterest(new Money(currency, "12.0"));
actionDate.setPaymentStatus(PaymentStatus.UNPAID);
AccountTestUtils.addAccountActionDate(actionDate, loan);
AccountFeesActionDetailEntity accountFeesaction = new LoanFeeScheduleEntity(actionDate, maintanenceFee, accountPeriodicFee, new Money(currency, "100.0"));
setFeeAmountPaid(accountFeesaction, new Money(currency, "0.0"));
actionDate.addAccountFeesAction(accountFeesaction);
}
} else if (disbursalType == 1 || disbursalType == 3) {
loan.setInterestDeductedAtDisbursement(false);
meetingDates = TestObjectFactory.getMeetingDates(customer.getOfficeId(), loan.getLoanMeeting(), 6);
short i = 0;
for (Date date : meetingDates) {
if (i == 0) {
i++;
loan.setDisbursementDate(date);
continue;
}
LoanScheduleEntity actionDate = (LoanScheduleEntity) loan.getAccountActionDate(i++);
actionDate.setActionDate(new java.sql.Date(date.getTime()));
actionDate.setPrincipal(new Money(currency, "100.0"));
actionDate.setInterest(new Money(currency, "12.0"));
actionDate.setPaymentStatus(PaymentStatus.UNPAID);
AccountTestUtils.addAccountActionDate(actionDate, loan);
AccountFeesActionDetailEntity accountFeesaction = new LoanFeeScheduleEntity(actionDate, maintanenceFee, accountPeriodicFee, new Money(currency, "100.0"));
setFeeAmountPaid(accountFeesaction, new Money(currency, "0.0"));
actionDate.addAccountFeesAction(accountFeesaction);
}
}
GracePeriodTypeEntity gracePeriodType = new GracePeriodTypeEntity(GraceType.NONE);
loan.setGracePeriodType(gracePeriodType);
loan.setCreatedBy(Short.valueOf("1"));
// Set collateral type to lookup id 109, which references the lookup
// value 'Type 1'
loan.setCollateralTypeId(Integer.valueOf("109"));
InterestTypesEntity interestTypes = new InterestTypesEntity(InterestType.FLAT);
loan.setInterestType(interestTypes);
loan.setInterestRate(10.0);
loan.setCreatedDate(new Date(System.currentTimeMillis()));
setLoanSummary(loan, currency);
return loan;
}
Aggregations