Search in sources :

Example 16 with InstallmentDate

use of org.mifos.accounts.util.helpers.InstallmentDate in project head by mifos.

the class AccountGetFeeDatesIntegrationTest method getScheduledDatesForFeesForGivenCustomerForWeeklySchedules.

@Test
public void getScheduledDatesForFeesForGivenCustomerForWeeklySchedules() throws Exception {
    // setup
    DateTime firstTuesdayInstallmentDate = new DateMidnight().toDateTime().withDate(2010, 4, 20);
    weeklyMeeting = new MeetingBuilder().customerMeeting().weekly().every(1).withStartDate(firstTuesdayInstallmentDate).build();
    IntegrationTestObjectMother.saveMeeting(weeklyMeeting);
    MeetingBuilder weeklyMeetingForFees = new MeetingBuilder().periodicFeeMeeting().weekly().every(1).withStartDate(firstTuesdayInstallmentDate);
    weeklyPeriodicFeeForCenterOnly = new FeeBuilder().appliesToCenterOnly().withFeeAmount("100.0").withName("Center Weekly Periodic Fee").with(weeklyMeetingForFees).with(sampleBranchOffice()).build();
    IntegrationTestObjectMother.saveFee(weeklyPeriodicFeeForCenterOnly);
    center = new CenterBuilder().with(weeklyMeeting).withName("Center").with(sampleBranchOffice()).withLoanOfficer(testUser()).build();
    IntegrationTestObjectMother.createCenter(center, weeklyMeeting, weeklyPeriodicFeeForCenterOnly);
    center = customerDao.findCenterBySystemId(center.getGlobalCustNum());
    DateTime meetingStartDate = firstTuesdayInstallmentDate.minusDays(7);
    MeetingBO feeMeetingFrequency = new MeetingBuilder().periodicFeeMeeting().weekly().every(1).occuringOnA(WeekDay.MONDAY).startingFrom(meetingStartDate.toDate()).build();
    InstallmentDate installment1 = new InstallmentDate(Short.valueOf("1"), firstTuesdayInstallmentDate.toDate());
    InstallmentDate installment2 = new InstallmentDate(Short.valueOf("2"), firstTuesdayInstallmentDate.plusWeeks(1).toDate());
    InstallmentDate installment3 = new InstallmentDate(Short.valueOf("3"), firstTuesdayInstallmentDate.plusWeeks(2).toDate());
    InstallmentDate installment4 = new InstallmentDate(Short.valueOf("4"), firstTuesdayInstallmentDate.plusWeeks(3).toDate());
    List<InstallmentDate> installmentDates = Arrays.asList(installment1, installment2, installment3, installment4);
    // exercise test
    CustomerAccountBO customerAccount = center.getCustomerAccount();
    List<Date> feeDates = customerAccount.getFeeDates(feeMeetingFrequency, installmentDates);
    // verification
    assertThat(feeDates.get(0), is(firstTuesdayInstallmentDate.toDate()));
    assertThat(feeDates.get(1), is(firstTuesdayInstallmentDate.plusWeeks(1).toDate()));
    assertThat(feeDates.get(2), is(firstTuesdayInstallmentDate.plusWeeks(2).toDate()));
    assertThat(feeDates.get(3), is(firstTuesdayInstallmentDate.plusWeeks(3).toDate()));
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) FeeBuilder(org.mifos.domain.builders.FeeBuilder) DateMidnight(org.joda.time.DateMidnight) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) DateTime(org.joda.time.DateTime) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) Test(org.junit.Test)

Example 17 with InstallmentDate

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

Example 18 with InstallmentDate

use of org.mifos.accounts.util.helpers.InstallmentDate 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);
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) DailyScheduledEvent(org.mifos.schedule.internal.DailyScheduledEvent) ScheduledEvent(org.mifos.schedule.ScheduledEvent) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) ArrayList(java.util.ArrayList) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate)

Example 19 with InstallmentDate

use of org.mifos.accounts.util.helpers.InstallmentDate in project head by mifos.

the class IndependentOfCustomerMeetingScheduleLoanInstallmentGenerator method getInstallmentDates.

private final List<InstallmentDate> getInstallmentDates(final ScheduledEvent scheduledEvent, LocalDate meetingStartDate, final int noOfInstallments, final int installmentToSkip, Short officeId) {
    List<InstallmentDate> dueInstallmentDates = new ArrayList<InstallmentDate>();
    if (noOfInstallments > 0) {
        List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
        List<Holiday> holidays = new ArrayList<Holiday>();
        DateTime startFromMeetingDate = meetingStartDate.toDateMidnight().toDateTime();
        holidays = holidayDao.findAllHolidaysFromDateAndNext(officeId, startFromMeetingDate.toLocalDate().toString());
        final int occurrences = noOfInstallments + installmentToSkip;
        ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, holidays);
        List<Date> dueDates = new ArrayList<Date>();
        DateTime startFromDayAfterAssignedMeetingDateRatherThanSkippingInstallments = startFromMeetingDate;
        // ensure loans that are created or disbursed on a meeting date start on next valid meeting date and not todays meeting
        // ensure loans that are created or disbursed before a meeting date start on next valid meeting date
        startFromDayAfterAssignedMeetingDateRatherThanSkippingInstallments = startFromMeetingDate.plusDays(1);
        List<DateTime> installmentDates = dateGeneration.generateScheduledDates(occurrences, startFromDayAfterAssignedMeetingDateRatherThanSkippingInstallments, scheduledEvent, false);
        for (DateTime installmentDate : installmentDates) {
            dueDates.add(installmentDate.toDate());
        }
        dueInstallmentDates = createInstallmentDates(installmentToSkip, dueDates);
    }
    return dueInstallmentDates;
}
Also used : ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration) ScheduledDateGeneration(org.mifos.schedule.ScheduledDateGeneration) Holiday(org.mifos.application.holiday.business.Holiday) Days(org.joda.time.Days) FiscalCalendarRules(org.mifos.config.FiscalCalendarRules) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)

Example 20 with InstallmentDate

use of org.mifos.accounts.util.helpers.InstallmentDate in project head by mifos.

the class IndependentOfCustomerMeetingScheduleLoanInstallmentGenerator 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)));
        }
    }
}
Also used : InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate)

Aggregations

InstallmentDate (org.mifos.accounts.util.helpers.InstallmentDate)25 ArrayList (java.util.ArrayList)18 Date (java.util.Date)12 LocalDate (org.joda.time.LocalDate)12 Money (org.mifos.framework.util.helpers.Money)10 DateTime (org.joda.time.DateTime)9 FeeInstallment (org.mifos.accounts.util.helpers.FeeInstallment)9 ScheduledEvent (org.mifos.schedule.ScheduledEvent)7 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)6 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)6 MeetingBO (org.mifos.application.meeting.business.MeetingBO)5 Days (org.joda.time.Days)4 InstallmentPrincipalAndInterest (org.mifos.accounts.loan.util.helpers.InstallmentPrincipalAndInterest)4 Holiday (org.mifos.application.holiday.business.Holiday)4 FiscalCalendarRules (org.mifos.config.FiscalCalendarRules)4 ScheduledDateGeneration (org.mifos.schedule.ScheduledDateGeneration)4 HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration (org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)4 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 RateAmountFlag (org.mifos.accounts.fees.util.helpers.RateAmountFlag)2