use of org.mifos.accounts.util.helpers.InstallmentDate in project head by mifos.
the class LoanBO method createUnroundedLoanSchedulesFromInstallments.
private List<LoanScheduleEntity> createUnroundedLoanSchedulesFromInstallments(List<InstallmentDate> installmentDates, Money loanInterest, Money loanAmount, ScheduledEvent meetingScheduledEvent, List<InstallmentPrincipalAndInterest> principalWithInterestInstallments, Set<AccountFeesEntity> accountFees) {
List<LoanScheduleEntity> unroundedLoanSchedules = new ArrayList<LoanScheduleEntity>();
List<FeeInstallment> feeInstallments = new ArrayList<FeeInstallment>();
if (!getAccountFees().isEmpty()) {
InstallmentFeeCalculatorFactory installmentFeeCalculatorFactory = new InstallmentFeeCalculatorFactoryImpl();
for (AccountFeesEntity accountFeesEntity : accountFees) {
RateAmountFlag feeType = accountFeesEntity.getFees().getFeeType();
InstallmentFeeCalculator installmentFeeCalculator = installmentFeeCalculatorFactory.create(getFeeDao(), feeType);
Double feeAmount = accountFeesEntity.getFeeAmount();
Money accountFeeAmount = installmentFeeCalculator.calculate(feeAmount, loanAmount, loanInterest, accountFeesEntity.getFees());
accountFeesEntity.setAccountFeeAmount(accountFeeAmount);
}
feeInstallments = FeeInstallment.createMergedFeeInstallments(meetingScheduledEvent, accountFees, installmentDates.size());
}
int installmentIndex = 0;
for (InstallmentDate installmentDate1 : installmentDates) {
InstallmentPrincipalAndInterest em = principalWithInterestInstallments.get(installmentIndex);
LoanScheduleEntity loanScheduleEntity = new LoanScheduleEntity(this, getCustomer(), 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()) && !feeInstallment.getAccountFeesEntity().getFees().isTimeOfDisbursement()) {
LoanFeeScheduleEntity loanFeeScheduleEntity = new LoanFeeScheduleEntity(loanScheduleEntity, feeInstallment.getAccountFeesEntity().getFees(), feeInstallment.getAccountFeesEntity(), feeInstallment.getAccountFee());
loanScheduleEntity.addAccountFeesAction(loanFeeScheduleEntity);
} else if (feeInstallment.getInstallmentId().equals(installmentDate1.getInstallmentId()) && isInterestDeductedAtDisbursement() && feeInstallment.getAccountFeesEntity().getFees().isTimeOfDisbursement()) {
// FIXME - keithw - isInterestDeductedAtDisbursement is not relevant but one integration test fails
// when this is removed. leaving in but test is most likely wrong. LoanBOIntegrationTest.testRemoveLoanDisbursalFee
LoanFeeScheduleEntity loanFeeScheduleEntity = new LoanFeeScheduleEntity(loanScheduleEntity, feeInstallment.getAccountFeesEntity().getFees(), feeInstallment.getAccountFeesEntity(), feeInstallment.getAccountFee());
loanScheduleEntity.addAccountFeesAction(loanFeeScheduleEntity);
}
}
unroundedLoanSchedules.add(loanScheduleEntity);
installmentIndex++;
}
return unroundedLoanSchedules;
}
use of org.mifos.accounts.util.helpers.InstallmentDate in project head by mifos.
the class LoanBO method applyPeriodicFee.
/**
* The fee (new or to be updated) is applied to the given list of AccountActionDateEntity(s). Note that the entities
* are the actual entity objects referenced by the loan, so this method acts by side-effect, adding fees to the
* given entities.
*
* @param fee
* the periodic FeeBO to apply to the given AccountActionDateEntity(s)
* @param charge
* the
* @param dueInstallments
* @throws AccountException
* @throws PersistenceException
*/
private void applyPeriodicFee(final FeeBO fee, final Double charge, final List<AccountActionDateEntity> dueInstallments) throws AccountException {
// Create an AccountFeesEntity linking the loan to the given fee fee and charge if the fee hasn't been applied,
// or
// update the applied fee's AccountFeesEntity.feeAmount with the given charge. Then set the
// AccountFeeEntity.accountFeeAmount to this loan's originalInterest.
AccountFeesEntity accountFee = getAccountFee(fee, charge);
Set<AccountFeesEntity> accountFeeSet = new HashSet<AccountFeesEntity>();
accountFeeSet.add(accountFee);
populateAccountFeeAmount(accountFeeSet, loanSummary.getOriginalInterest());
// Extract the list of InstallmentDate(s) from the given AccountActionDateEntity(s). Note that
// the installmentId(s) likely do not start with 1 since the fee may be applied after some
// installment dates have passed.
List<InstallmentDate> installmentDates = new ArrayList<InstallmentDate>();
for (AccountActionDateEntity accountActionDateEntity : dueInstallments) {
installmentDates.add(new InstallmentDate(accountActionDateEntity.getInstallmentId(), accountActionDateEntity.getActionDate()));
}
// Get the full list of all loan InstallmentDate(s), past, present and future, without adjusting for holidays.
// This will work correctly only if adjusting periodic fees is done when no installments have been paid
// boolean isRepaymentIndepOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
// List<InstallmentDate> nonAdjustedInstallmentDates = getInstallmentDates(getLoanMeeting(), noOfInstallments,
// getInstallmentSkipToStartRepayment(), isRepaymentIndepOfMeetingEnabled,
// false);
// Use handlePeriodic to adjust fee installments for holiday periods and combine multiple fee installments due
// for the
// same loan installment. Finally, apply these updated fees to the given dueInstallments list and update
// loan summary and activity tables.
/*
* old way List<FeeInstallment> feeInstallmentList = mergeFeeInstallments(handlePeriodic(accountFee,
* installmentDates, nonAdjustedInstallmentDates));
*/
// new way
ScheduledEvent loanScheduledEvent = ScheduledEventFactory.createScheduledEventFrom(this.getMeetingForAccount());
List<FeeInstallment> feeInstallmentList = FeeInstallment.createMergedFeeInstallmentsForOneFeeStartingWith(loanScheduledEvent, accountFee, dueInstallments.size(), dueInstallments.get(0).getInstallmentId());
Money totalFeeAmountApplied = applyFeeToInstallments(feeInstallmentList, dueInstallments);
updateLoanSummary(fee.getFeeId(), totalFeeAmountApplied);
updateLoanActivity(fee.getFeeId(), totalFeeAmountApplied, fee.getFeeName() + AccountConstants.APPLIED);
}
use of org.mifos.accounts.util.helpers.InstallmentDate in project head by mifos.
the class AnyScheduledEventLoanInstallmentGenerator method generate.
@Override
public List<InstallmentDate> generate(LocalDate actualDisbursementDate, int numberOfInstallments, GraceType graceType, int gracePeriodDuration, Short officeId) {
List<InstallmentDate> installmentDates = new ArrayList<InstallmentDate>();
if (numberOfInstallments > 0) {
List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
List<Holiday> holidays = new ArrayList<Holiday>();
LocalDate startFromMeetingDate = null;
if (scheduledEvent instanceof DailyScheduledEvent) {
startFromMeetingDate = actualDisbursementDate.plusDays(scheduledEvent.getEvery());
} else {
startFromMeetingDate = actualDisbursementDate.plusDays(1);
}
holidays = holidayDao.findAllHolidaysFromDateAndNext(officeId, startFromMeetingDate.toString());
int occurrences = numberOfInstallments;
if (graceType == GraceType.GRACEONALLREPAYMENTS) {
occurrences += gracePeriodDuration;
}
ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, holidays);
List<Date> dueDates = new ArrayList<Date>();
List<DateTime> installmentDateTimes = dateGeneration.generateScheduledDates(occurrences, startFromMeetingDate.toDateMidnight().toDateTime(), scheduledEvent, false);
for (DateTime installmentDate : installmentDateTimes) {
dueDates.add(installmentDate.toDate());
}
installmentDates = createInstallmentDates(dueDates);
if (graceType == GraceType.GRACEONALLREPAYMENTS) {
removeInstallmentsNeedNotPay(gracePeriodDuration, installmentDates);
}
}
return installmentDates;
}
use of org.mifos.accounts.util.helpers.InstallmentDate in project head by mifos.
the class AnyScheduledEventLoanInstallmentGenerator method removeInstallmentsNeedNotPay.
private void removeInstallmentsNeedNotPay(final int installmentSkipToStartRepayment, final List<InstallmentDate> installmentDates) {
int removeCounter = 0;
for (int i = 0; i < installmentSkipToStartRepayment; i++) {
installmentDates.remove(removeCounter);
}
// re-adjust the installment ids
if (installmentSkipToStartRepayment > 0) {
int count = installmentDates.size();
for (int i = 0; i < count; i++) {
InstallmentDate instDate = installmentDates.get(i);
instDate.setInstallmentId(new Short(Integer.toString(i + 1)));
}
}
}
use of org.mifos.accounts.util.helpers.InstallmentDate in project head by mifos.
the class AnyScheduledEventLoanInstallmentGenerator method createInstallmentDates.
private List<InstallmentDate> createInstallmentDates(final List<Date> dueDates) {
List<InstallmentDate> installmentDates = new ArrayList<InstallmentDate>();
int installmentId = 1;
for (Date date : dueDates) {
installmentDates.add(new InstallmentDate((short) installmentId++, date));
}
return installmentDates;
}
Aggregations