use of org.mifos.accounts.util.helpers.FeeInstallment in project head by mifos.
the class FeeInstallmentTest method createMergedFeeInstallmentsForOneFeeAccountScheduledEveryWeekFeeScheduledEveryOtherWeekShouldGetOneFeeInstallmentPerEveryOtherAccountEvent.
@Test
public void createMergedFeeInstallmentsForOneFeeAccountScheduledEveryWeekFeeScheduledEveryOtherWeekShouldGetOneFeeInstallmentPerEveryOtherAccountEvent() {
ScheduledEvent accountEvent = new ScheduledEventBuilder().every(1).weeks().build();
FeeBO feeBO = createWeeklyFeeBO(2);
AccountFeesEntity accountFeesEntity = createAccountFeesEntity(feeBO, 10.0);
List<FeeInstallment> feeInstallments = FeeInstallment.createMergedFeeInstallmentsForOneFee(accountEvent, accountFeesEntity, 4);
assertThat(feeInstallments.size(), is(2));
assertFeeInstallment(feeInstallments.get(0), 1, 10.0, feeBO);
assertFeeInstallment(feeInstallments.get(1), 3, 10.0, feeBO);
}
use of org.mifos.accounts.util.helpers.FeeInstallment in project head by mifos.
the class LoanBO method applyOneTimeFee.
private void applyOneTimeFee(final FeeBO fee, final Double charge, final AccountActionDateEntity accountActionDateEntity) throws AccountException {
LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountActionDateEntity;
AccountFeesEntity accountFee = new AccountFeesEntity(this, fee, charge, FeeStatus.ACTIVE.getValue(), new DateTimeService().getCurrentJavaDateTime(), null);
Set<AccountFeesEntity> accountFeeSet = new HashSet<AccountFeesEntity>();
accountFeeSet.add(accountFee);
populateAccountFeeAmount(accountFeeSet, loanSummary.getOriginalInterest());
List<AccountActionDateEntity> loanScheduleEntityList = new ArrayList<AccountActionDateEntity>();
loanScheduleEntityList.add(loanScheduleEntity);
List<InstallmentDate> installmentDates = new ArrayList<InstallmentDate>();
installmentDates.add(new InstallmentDate(accountActionDateEntity.getInstallmentId(), accountActionDateEntity.getActionDate()));
List<FeeInstallment> feeInstallmentList = new ArrayList<FeeInstallment>();
feeInstallmentList.add(handleOneTime(accountFee, installmentDates));
Money totalFeeAmountApplied = applyFeeToInstallments(feeInstallmentList, loanScheduleEntityList);
filterTimeOfDisbursementFees(loanScheduleEntity, fee);
updateLoanSummary(fee.getFeeId(), totalFeeAmountApplied);
updateLoanActivity(fee.getFeeId(), totalFeeAmountApplied, fee.getFeeName() + AccountConstants.APPLIED);
}
use of org.mifos.accounts.util.helpers.FeeInstallment in project head by mifos.
the class LoanBO method applyFeeToInstallments.
private Money applyFeeToInstallments(final List<FeeInstallment> feeInstallmentList, final List<AccountActionDateEntity> accountActionDateList) {
Date lastAppliedDate = null;
Money totalFeeAmountApplied = new Money(getCurrency());
AccountFeesEntity accountFeesEntity = null;
for (AccountActionDateEntity accountActionDateEntity : accountActionDateList) {
LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountActionDateEntity;
for (FeeInstallment feeInstallment : feeInstallmentList) {
if (feeInstallment.getInstallmentId().equals(loanScheduleEntity.getInstallmentId())) {
lastAppliedDate = loanScheduleEntity.getActionDate();
totalFeeAmountApplied = totalFeeAmountApplied.add(feeInstallment.getAccountFee());
/*
* AccountFeesActionDetailEntity accountFeesActionDetailEntity = new LoanFeeScheduleEntity(
* loanScheduleEntity, feeInstallment .getAccountFeesEntity().getFees(),
* feeInstallment.getAccountFeesEntity(), feeInstallment.getAccountFee()); loanScheduleEntity
* .addAccountFeesAction(accountFeesActionDetailEntity);
*/
if (feeInstallment.getAccountFeesEntity().getFees().isPeriodic() && loanScheduleEntity.isFeeAlreadyAttatched(feeInstallment.getAccountFeesEntity().getFees().getFeeId())) {
LoanFeeScheduleEntity loanFeeScheduleEntity = (LoanFeeScheduleEntity) loanScheduleEntity.getAccountFeesAction(feeInstallment.getAccountFeesEntity().getFees().getFeeId());
loanFeeScheduleEntity.setFeeAmount(loanFeeScheduleEntity.getFeeAmount().add(feeInstallment.getAccountFee()));
} else {
AccountFeesActionDetailEntity accountFeesActionDetailEntity = new LoanFeeScheduleEntity(loanScheduleEntity, feeInstallment.getAccountFeesEntity().getFees(), feeInstallment.getAccountFeesEntity(), feeInstallment.getAccountFee());
loanScheduleEntity.addAccountFeesAction(accountFeesActionDetailEntity);
}
accountFeesEntity = feeInstallment.getAccountFeesEntity();
}
}
}
accountFeesEntity.setLastAppliedDate(lastAppliedDate);
addAccountFees(accountFeesEntity);
return totalFeeAmountApplied;
}
use of org.mifos.accounts.util.helpers.FeeInstallment in project head by mifos.
the class CustomerAccountBO method applyPeriodicFee.
/*
* Package-level visibility for testing
*/
void applyPeriodicFee(final FeeBO fee, final Money charge, final List<AccountActionDateEntity> dueInstallments) throws AccountException {
AccountFeesEntity accountFee = getAccountFee(fee, charge.getAmountDoubleValue());
accountFee.setAccountFeeAmount(charge);
List<InstallmentDate> installmentDates = new ArrayList<InstallmentDate>();
for (AccountActionDateEntity accountActionDateEntity : dueInstallments) {
installmentDates.add(new InstallmentDate(accountActionDateEntity.getInstallmentId(), accountActionDateEntity.getActionDate()));
}
// List<FeeInstallment> feeInstallmentList = mergeFeeInstallments(handlePeriodic(accountFee, installmentDates));
ScheduledEvent loanScheduledEvent = ScheduledEventFactory.createScheduledEventFrom(this.getMeetingForAccount());
List<FeeInstallment> feeInstallmentList = FeeInstallment.createMergedFeeInstallmentsForOneFeeStartingWith(loanScheduledEvent, accountFee, dueInstallments.size(), dueInstallments.get(0).getInstallmentId());
// MIFOS-3701: we want to display only fee charge, not the totalFeeAmountApplied
applyFeeToInstallments(feeInstallmentList, dueInstallments);
updateCustomerActivity(fee.getFeeId(), charge, fee.getFeeName() + AccountConstants.APPLIED);
accountFee.setFeeStatus(FeeStatus.ACTIVE);
}
use of org.mifos.accounts.util.helpers.FeeInstallment in project head by mifos.
the class IndividualLoanScheduleFactory method createUnroundedLoanSchedulesFromInstallments.
private List<LoanScheduleEntity> createUnroundedLoanSchedulesFromInstallments(List<InstallmentDate> installmentDates, Money loanInterest, Money loanAmount, ScheduledEvent meetingScheduledEvent, List<InstallmentPrincipalAndInterest> principalWithInterestInstallments, List<AccountFeesEntity> accountFees, CustomerBO customer) {
List<LoanScheduleEntity> unroundedLoanSchedules = new ArrayList<LoanScheduleEntity>();
List<AccountFeesEntity> accountFeesWithNoTimeOfDibursementFees = new ArrayList<AccountFeesEntity>();
List<FeeInstallment> feeInstallments = new ArrayList<FeeInstallment>();
if (!accountFees.isEmpty()) {
InstallmentFeeCalculatorFactory installmentFeeCalculatorFactory = new InstallmentFeeCalculatorFactoryImpl();
for (AccountFeesEntity accountFeesEntity : accountFees) {
RateAmountFlag feeType = accountFeesEntity.getFees().getFeeType();
InstallmentFeeCalculator installmentFeeCalculator = installmentFeeCalculatorFactory.create(this.feeDao, feeType);
Double feeAmountOrRate = accountFeesEntity.getFeeAmount();
Money accountFeeAmount = installmentFeeCalculator.calculate(feeAmountOrRate, loanAmount, loanInterest, accountFeesEntity.getFees());
accountFeesEntity.setAccountFeeAmount(accountFeeAmount);
if (!accountFeesEntity.isTimeOfDisbursement()) {
accountFeesWithNoTimeOfDibursementFees.add(accountFeesEntity);
}
}
feeInstallments = FeeInstallment.createMergedFeeInstallments(meetingScheduledEvent, accountFeesWithNoTimeOfDibursementFees, installmentDates.size());
}
int installmentIndex = 0;
for (InstallmentDate installmentDate1 : installmentDates) {
InstallmentPrincipalAndInterest em = principalWithInterestInstallments.get(installmentIndex);
LoanScheduleEntity loanScheduleEntity = new LoanScheduleEntity(null, customer, installmentDate1.getInstallmentId(), new java.sql.Date(installmentDate1.getInstallmentDueDate().getTime()), PaymentStatus.UNPAID, em.getPrincipal(), em.getInterest());
for (FeeInstallment feeInstallment : feeInstallments) {
if (feeInstallment.getInstallmentId().equals(installmentDate1.getInstallmentId())) {
LoanFeeScheduleEntity loanFeeScheduleEntity = new LoanFeeScheduleEntity(loanScheduleEntity, feeInstallment.getAccountFeesEntity().getFees(), feeInstallment.getAccountFeesEntity(), feeInstallment.getAccountFee());
loanScheduleEntity.addAccountFeesAction(loanFeeScheduleEntity);
}
}
unroundedLoanSchedules.add(loanScheduleEntity);
installmentIndex++;
}
return unroundedLoanSchedules;
}
Aggregations