use of org.mifos.schedule.ScheduledEvent 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.schedule.ScheduledEvent in project head by mifos.
the class FeeInstallment method createMergedFeeInstallmentsForOneFeeStartingWith.
public static List<FeeInstallment> createMergedFeeInstallmentsForOneFeeStartingWith(ScheduledEvent masterEvent, AccountFeesEntity accountFeesEntity, int numberOfInstallments, int startingInstallmentNumber) {
List<FeeInstallment> mergedFeeInstallments = new ArrayList<FeeInstallment>();
if (accountFeesEntity.getFees().isOneTime()) {
FeeInstallment feeInstallment = buildFeeInstallment(//Customer one-time fees are always up-front, due at the first meeting
(short) startingInstallmentNumber, accountFeesEntity.getAccountFeeAmount(), accountFeesEntity);
mergedFeeInstallments.add(feeInstallment);
} else {
// periodic fee
ScheduledEvent feesEvent = ScheduledEventFactory.createScheduledEventFrom(accountFeesEntity.getFees().getFeeFrequency().getFeeMeetingFrequency());
for (short installmentId = (short) startingInstallmentNumber; installmentId <= numberOfInstallments + startingInstallmentNumber - 1; installmentId++) {
int numberOfFeeInstallmentsToRollup = masterEvent.numberOfDependentOccurrencesRollingUpToThisOccurrenceStartingWith(feesEvent, installmentId, startingInstallmentNumber);
if (numberOfFeeInstallmentsToRollup > 0) {
FeeInstallment feeInstallment = buildFeeInstallment(installmentId, accountFeesEntity.getAccountFeeAmount().multiply(numberOfFeeInstallmentsToRollup), accountFeesEntity);
mergedFeeInstallments.add(feeInstallment);
}
}
}
return mergedFeeInstallments;
}
use of org.mifos.schedule.ScheduledEvent in project head by mifos.
the class IndividualLoanAssembler method assembleFrom.
@Override
public IndividualLoan assembleFrom(IndividualLoanRequest individualLoan) {
LoanOfferingBO loanProduct = this.loanProductDao.findBySystemId(individualLoan.getLoanProductId().globalIdentity());
ClientBO client = this.customerDao.findClientBySystemId(individualLoan.getClientId().globalIdentity());
int occurences = 12;
DateTime lastScheduledDate = new DateTime();
ScheduledEvent scheduledEvent = scheduledEventFactory.createScheduledEventFrom(loanProduct.getLoanOfferingMeetingValue());
List<DateTime> loanScheduleDates = scheduledDateGeneration.generateScheduledDates(occurences, lastScheduledDate, scheduledEvent, false);
// FIXME - assemble loanAmount from dto
Money loanAmount = null;
Double interestRate = Double.valueOf("10.0");
Integer interestDays = Integer.valueOf(AccountingRules.getNumberOfInterestDays());
return new IndividualLoanImpl();
}
use of org.mifos.schedule.ScheduledEvent in project head by mifos.
the class LoanDisbursmentDateFactoryImpl method create.
@Override
public LoanDisbursementStrategy create(CustomerBO customer, LoanOfferingBO loanProduct, boolean isRepaymentIndependentOfMeetingEnabled, boolean isLoanWithBackdatedPayments) {
RecurringScheduledEventFactory recurringScheduledEventFactory = new RecurringScheduledEventFactoryImpl();
ScheduledEvent customerMeetingSchedule = recurringScheduledEventFactory.createScheduledEventFrom(customer.getCustomerMeetingValue());
final Date nextMeetingDate = customer.getCustomerAccount().getNextMeetingDate();
LocalDate nextValidCustomerMeetingDate = new LocalDate(nextMeetingDate);
LoanDisbursementStrategy loanDisbursementStrategy = new LoanDisbursementCoupledToCustomerMeetingScheduleStrategyImpl(customerMeetingSchedule, nextValidCustomerMeetingDate);
if (isLoanWithBackdatedPayments) {
loanDisbursementStrategy = new LoanWithBackdatedPaymentsDisbursementStrategyImpl();
} else if (loanProduct.isVariableInstallmentsAllowed() || isRepaymentIndependentOfMeetingEnabled) {
// LSIM ON
loanDisbursementStrategy = new VariableInstallmentsLoanDisbursementStrategyImpl(customerMeetingSchedule);
}
return loanDisbursementStrategy;
}
use of org.mifos.schedule.ScheduledEvent in project head by mifos.
the class LoanInstallmentFactoryImpl method create.
@Override
public LoanInstallmentGenerator create(MeetingBO meeting, boolean repaymentsShouldNotHaveToMatchCustomerMeetingSchedule) {
HolidayDao holidayDao = ApplicationContextProvider.getBean(HolidayDao.class);
ScheduledEvent scheduledEvent = scheduledEventFactory.createScheduledEventFrom(meeting);
if (repaymentsShouldNotHaveToMatchCustomerMeetingSchedule) {
LocalDate meetingStartDate = new LocalDate(meeting.getMeetingStartDate());
return new IndependentOfCustomerMeetingScheduleLoanInstallmentGenerator(scheduledEvent, holidayDao, meetingStartDate);
}
return new AnyScheduledEventLoanInstallmentGenerator(scheduledEvent, holidayDao);
}
Aggregations