Search in sources :

Example 6 with ScheduledEvent

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);
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) ScheduledEvent(org.mifos.schedule.ScheduledEvent) Money(org.mifos.framework.util.helpers.Money) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) ArrayList(java.util.ArrayList) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate)

Example 7 with ScheduledEvent

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;
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) ArrayList(java.util.ArrayList)

Example 8 with ScheduledEvent

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();
}
Also used : IndividualLoanImpl(org.mifos.clientportfolio.newloan.domain.IndividualLoanImpl) ScheduledEvent(org.mifos.schedule.ScheduledEvent) Money(org.mifos.framework.util.helpers.Money) ClientBO(org.mifos.customers.client.business.ClientBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) DateTime(org.joda.time.DateTime)

Example 9 with ScheduledEvent

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;
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) LocalDate(org.joda.time.LocalDate) LocalDate(org.joda.time.LocalDate) Date(java.util.Date)

Example 10 with ScheduledEvent

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);
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) LocalDate(org.joda.time.LocalDate) HolidayDao(org.mifos.application.holiday.persistence.HolidayDao)

Aggregations

ScheduledEvent (org.mifos.schedule.ScheduledEvent)38 DateTime (org.joda.time.DateTime)23 LocalDate (org.joda.time.LocalDate)16 ArrayList (java.util.ArrayList)14 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)13 Test (org.junit.Test)12 FeeInstallment (org.mifos.accounts.util.helpers.FeeInstallment)12 ScheduledDateGeneration (org.mifos.schedule.ScheduledDateGeneration)12 HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration (org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)12 Date (java.util.Date)11 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)11 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)10 FeeBO (org.mifos.accounts.fees.business.FeeBO)9 ScheduledEventBuilder (org.mifos.domain.builders.ScheduledEventBuilder)9 InstallmentDate (org.mifos.accounts.util.helpers.InstallmentDate)8 MeetingBO (org.mifos.application.meeting.business.MeetingBO)7 InterestScheduledEvent (org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent)6 HolidayDao (org.mifos.application.holiday.persistence.HolidayDao)5 Days (org.joda.time.Days)4 Holiday (org.mifos.application.holiday.business.Holiday)4