Search in sources :

Example 6 with SavingsInterestScheduledEventFactory

use of org.mifos.accounts.savings.interest.schedule.SavingsInterestScheduledEventFactory in project head by mifos.

the class SavingsBO method determineAccountActivationDetails.

public static SavingsAccountActivationDetail determineAccountActivationDetails(CustomerBO customer, SavingsOfferingBO savingsProduct, Money recommendedOrMandatoryAmount, AccountState savingsAccountState, CalendarEvent calendarEvents, LocalDate activationDate) {
    List<AccountActionDateEntity> scheduledPayments = new ArrayList<AccountActionDateEntity>();
    LocalDate nextInterestPostingDate = new LocalDate();
    if (savingsAccountState.isActiveSavingsAccountState()) {
        ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(customer.getCustomerMeetingValue());
        ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(calendarEvents.getWorkingDays(), calendarEvents.getHolidays());
        List<DateTime> depositDates = dateGeneration.generateScheduledDates(10, activationDate.toDateTimeAtStartOfDay(), scheduledEvent, false);
        short installmentNumber = 1;
        for (DateTime date : depositDates) {
            java.sql.Date depositDueDate = new java.sql.Date(date.toDate().getTime());
            AccountActionDateEntity scheduledSavingsDeposit = new SavingsScheduleEntity(customer, installmentNumber, depositDueDate, PaymentStatus.UNPAID, recommendedOrMandatoryAmount, savingsProduct.getCurrency());
            scheduledPayments.add(scheduledSavingsDeposit);
        }
        InterestScheduledEvent interestPostingEvent = new SavingsInterestScheduledEventFactory().createScheduledEventFrom(savingsProduct.getFreqOfPostIntcalc().getMeeting());
        nextInterestPostingDate = interestPostingEvent.nextMatchingDateAfter(new LocalDate(startOfFiscalYear()), activationDate);
    }
    return new SavingsAccountActivationDetail(activationDate, nextInterestPostingDate, scheduledPayments);
}
Also used : SavingsInterestScheduledEventFactory(org.mifos.accounts.savings.interest.schedule.SavingsInterestScheduledEventFactory) InterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent) ScheduledEvent(org.mifos.schedule.ScheduledEvent) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration) ScheduledDateGeneration(org.mifos.schedule.ScheduledDateGeneration) InterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)

Example 7 with SavingsInterestScheduledEventFactory

use of org.mifos.accounts.savings.interest.schedule.SavingsInterestScheduledEventFactory in project head by mifos.

the class SavingsBO method isTrxnDateValid.

@Override
public boolean isTrxnDateValid(Date trxnDate, Date lastMeetingDate, boolean repaymentIndependentOfMeetingEnabled) {
    LocalDate transactionLocalDate = new LocalDate(trxnDate);
    LocalDate today = new LocalDate();
    if (AccountingRules.isBackDatedTxnAllowed()) {
        if (repaymentIndependentOfMeetingEnabled) {
            Date activationDate = this.getActivationDate();
            return trxnDate.compareTo(DateUtils.getDateWithoutTimeStamp(activationDate)) >= 0;
        }
        InterestScheduledEvent postingEvent = new SavingsInterestScheduledEventFactory().createScheduledEventFrom(this.getInterestPostingMeeting());
        LocalDate nextPostingDate = new LocalDate(this.nextIntPostDate);
        LocalDate currentPostingPeriodStartDate = postingEvent.findFirstDateOfPeriodForMatchingDate(nextPostingDate);
        if (getInterestPostingMeeting().isDaily()) {
            if (lastIntPostDate == null) {
                currentPostingPeriodStartDate = new LocalDate(activationDate);
            } else {
                currentPostingPeriodStartDate = new LocalDate(lastIntPostDate).plusDays(1);
            }
        }
        // FIXME throw an exception with the correct reason instead of returning false
        if (transactionLocalDate.isBefore(currentPostingPeriodStartDate)) {
            return false;
        }
        LocalDate activationDate = new LocalDate(this.activationDate);
        if (lastMeetingDate != null) {
            LocalDate meetingDate = new LocalDate(lastMeetingDate);
            return (transactionLocalDate.isAfter(meetingDate) || transactionLocalDate.isEqual(meetingDate)) && (transactionLocalDate.isAfter(activationDate) || transactionLocalDate.isEqual(activationDate));
        }
        return (transactionLocalDate.isAfter(activationDate) || transactionLocalDate.isEqual(activationDate)) && (transactionLocalDate.isBefore(today) || transactionLocalDate.isEqual(today));
    }
    return transactionLocalDate.isEqual(today);
}
Also used : SavingsInterestScheduledEventFactory(org.mifos.accounts.savings.interest.schedule.SavingsInterestScheduledEventFactory) InterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Aggregations

InterestScheduledEvent (org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent)7 SavingsInterestScheduledEventFactory (org.mifos.accounts.savings.interest.schedule.SavingsInterestScheduledEventFactory)7 LocalDate (org.joda.time.LocalDate)6 Date (java.util.Date)4 DateTime (org.joda.time.DateTime)4 ArrayList (java.util.ArrayList)3 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)3 ScheduledDateGeneration (org.mifos.schedule.ScheduledDateGeneration)3 ScheduledEvent (org.mifos.schedule.ScheduledEvent)3 HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration (org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)3 SavingsProductHistoricalInterestDetail (org.mifos.accounts.savings.interest.SavingsProductHistoricalInterestDetail)2 CustomerBO (org.mifos.customers.business.CustomerBO)2 Days (org.joda.time.Days)1 AccountException (org.mifos.accounts.exceptions.AccountException)1 InterestCalcType (org.mifos.accounts.productdefinition.util.helpers.InterestCalcType)1 CalendarPeriod (org.mifos.accounts.savings.interest.CalendarPeriod)1 SavingsInterestDetail (org.mifos.accounts.savings.interest.SavingsInterestDetail)1 Holiday (org.mifos.application.holiday.business.Holiday)1 HolidayDao (org.mifos.application.holiday.persistence.HolidayDao)1 MifosCurrency (org.mifos.application.master.business.MifosCurrency)1