Search in sources :

Example 31 with LocalDate

use of org.joda.time.LocalDate in project head by mifos.

the class SavingsBO method createWithdrawalTrxnsAfterAdjust.

private Set<AccountTrxnEntity> createWithdrawalTrxnsAfterAdjust(final AccountPaymentEntity newAccountPayment, final AccountPaymentEntity lastAccountPayment, final Money newAmount, final LocalDate adjustmentDate, PersonnelBO loggedInUser) {
    Set<AccountTrxnEntity> newTrxns = new LinkedHashSet<AccountTrxnEntity>();
    SavingsTrxnDetailEntity accountTrxn = null;
    // create transaction for withdrawal
    SavingsTrxnDetailEntity oldSavingsAccntTrxn = null;
    for (AccountTrxnEntity oldAccntTrxn : lastAccountPayment.getAccountTrxns()) {
        oldSavingsAccntTrxn = (SavingsTrxnDetailEntity) oldAccntTrxn;
        break;
    }
    this.savingsBalance = this.savingsBalance.subtract(newAmount);
    Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
    accountTrxn = SavingsTrxnDetailEntity.savingsWithdrawal(newAccountPayment, oldSavingsAccntTrxn.getCustomer(), newAmount, newAmount, loggedInUser, oldSavingsAccntTrxn.getDueDate(), adjustmentDate.toDateMidnight().toDate(), transactionCreatedDate);
    this.savingsPerformance.setTotalWithdrawals(this.savingsPerformance.getTotalWithdrawals().add(accountTrxn.getWithdrawlAmount()));
    newTrxns.add(accountTrxn);
    return newTrxns;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 32 with LocalDate

use of org.joda.time.LocalDate in project head by mifos.

the class SavingsBO method generateAccountActivationDetails.

public static SavingsAccountActivationDetail generateAccountActivationDetails(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 = 0;
        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 33 with LocalDate

use of org.joda.time.LocalDate in project head by mifos.

the class SavingsBO method generateNextSetOfMeetingDates.

public void generateNextSetOfMeetingDates(final List<Days> workingDays, final List<Holiday> holidays) throws AccountException {
    CustomerBO customerBO = getCustomer();
    if (customerBO.getCustomerMeeting() != null && customerBO.getCustomerMeeting().getMeeting() != null) {
        MeetingBO depositSchedule = customerBO.getCustomerMeeting().getMeeting();
        Date oldMeetingDate = depositSchedule.getStartDate();
        Short lastInstallmentId = getLastInstallmentId();
        AccountActionDateEntity lastInstallment = getAccountActionDate(lastInstallmentId);
        if (lastInstallment == null) {
            // a special workaround for MIFOS-5107
            lastInstallment = new SavingsScheduleEntity(this, this.getCustomer(), (short) 0, new java.sql.Date(new LocalDate().minusDays(1).toDateMidnight().getMillis()), PaymentStatus.UNPAID, new Money(Money.getDefaultCurrency(), 0.0));
        }
        depositSchedule.setMeetingStartDate(lastInstallment.getActionDate());
        if (customerBO.getCustomerLevel().getId().equals(CustomerLevel.CLIENT.getValue()) || customerBO.getCustomerLevel().getId().equals(CustomerLevel.GROUP.getValue()) && getRecommendedAmntUnit().getId().equals(RecommendedAmountUnit.COMPLETE_GROUP.getValue())) {
            generateDepositAccountActions(customerBO, depositSchedule, lastInstallment, workingDays, holidays);
        } else {
            List<CustomerBO> children;
            try {
                children = getCustomer().getChildren(CustomerLevel.CLIENT, ChildrenStateType.OTHER_THAN_CLOSED);
            } catch (CustomerException ce) {
                throw new AccountException(ce);
            }
            for (CustomerBO customer : children) {
                generateDepositAccountActions(customer, depositSchedule, lastInstallment, workingDays, holidays);
            }
        }
        depositSchedule.setStartDate(oldMeetingDate);
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) CustomerException(org.mifos.customers.exceptions.CustomerException) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CustomerBO(org.mifos.customers.business.CustomerBO) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 34 with LocalDate

use of org.joda.time.LocalDate in project head by mifos.

the class SavingsBO method regenerateFutureInstallments.

@Override
protected void regenerateFutureInstallments(final AccountActionDateEntity nextInstallment, final List<Days> workingDays, final List<Holiday> holidays) throws AccountException {
    MeetingBO customerMeeting = getCustomer().getCustomerMeetingValue();
    ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(customerMeeting);
    LocalDate currentDate = new LocalDate();
    LocalDate thisIntervalStartDate = customerMeeting.startDateForMeetingInterval(currentDate);
    LocalDate nextMatchingDate = new LocalDate(scheduledEvent.nextEventDateAfter(thisIntervalStartDate.toDateTimeAtStartOfDay()));
    DateTime futureIntervalStartDate = customerMeeting.startDateForMeetingInterval(nextMatchingDate).toDateTimeAtStartOfDay();
    ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, holidays);
    int numberOfInstallmentsToGenerate = getLastInstallmentId();
    List<DateTime> meetingDates = dateGeneration.generateScheduledDates(numberOfInstallmentsToGenerate, futureIntervalStartDate, scheduledEvent, false);
    if (getCustomer().getCustomerLevel().getId().equals(CustomerLevel.CLIENT.getValue()) || getCustomer().getCustomerLevel().getId().equals(CustomerLevel.GROUP.getValue()) && getRecommendedAmntUnit().getId().equals(RecommendedAmountUnit.COMPLETE_GROUP.getValue())) {
        updateSchedule(nextInstallment.getInstallmentId(), meetingDates);
    } else {
        List<CustomerBO> children;
        try {
            children = getCustomer().getChildren(CustomerLevel.CLIENT, ChildrenStateType.OTHER_THAN_CLOSED);
        } catch (CustomerException ce) {
            throw new AccountException(ce);
        }
        updateSavingsSchedule(nextInstallment.getInstallmentId(), meetingDates, children);
    }
}
Also used : InterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent) ScheduledEvent(org.mifos.schedule.ScheduledEvent) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration) ScheduledDateGeneration(org.mifos.schedule.ScheduledDateGeneration) CustomerException(org.mifos.customers.exceptions.CustomerException) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CustomerBO(org.mifos.customers.business.CustomerBO) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)

Example 35 with LocalDate

use of org.joda.time.LocalDate in project head by mifos.

the class SavingsBO method goActiveForFristTimeAndGenerateSavingsSchedule.

/**
     * use minimal constructor which generates scheduled savings payments correctly and does not
     * do through this method.
     */
@Deprecated
private void goActiveForFristTimeAndGenerateSavingsSchedule(final CustomerBO customer) throws AccountException {
    HolidayDao holidayDao = ApplicationContextProvider.getBean(HolidayDao.class);
    CalendarEvent futureCalendarEventsApplicableToOffice = holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
    this.activationDate = new DateTime(new DateTimeService().getCurrentJavaDateTime()).toDate();
    List<Days> workingDays = futureCalendarEventsApplicableToOffice.getWorkingDays();
    List<Holiday> holidays = futureCalendarEventsApplicableToOffice.getHolidays();
    logger.debug("In SavingsBO::generateDepositAccountActions()");
    // center/group with individual deposits, insert row for every client
    if (this.getCustomer().getCustomerMeeting() != null && this.getCustomer().getCustomerMeeting().getMeeting() != null) {
        MeetingBO depositSchedule = this.getCustomer().getCustomerMeeting().getMeeting();
        if (this.getCustomer().getCustomerLevel().getId().equals(CustomerLevel.CLIENT.getValue()) || this.getCustomer().getCustomerLevel().getId().equals(CustomerLevel.GROUP.getValue()) && this.getRecommendedAmntUnit().getId().equals(RecommendedAmountUnit.COMPLETE_GROUP.getValue())) {
            this.generateDepositAccountActions(this.getCustomer(), depositSchedule, workingDays, holidays, new DateTime(this.activationDate));
        } else {
            List<CustomerBO> children;
            try {
                children = this.getCustomer().getChildren(CustomerLevel.CLIENT, ChildrenStateType.ACTIVE_AND_ONHOLD);
            } catch (CustomerException ce) {
                throw new AccountException(ce);
            }
            for (CustomerBO customer1 : children) {
                this.generateDepositAccountActions(customer1, depositSchedule, workingDays, holidays, new DateTime(this.activationDate));
            }
        }
    }
    InterestScheduledEvent interestPostingEvent = new SavingsInterestScheduledEventFactory().createScheduledEventFrom(this.savingsOffering.getFreqOfPostIntcalc().getMeeting());
    this.nextIntPostDate = interestPostingEvent.nextMatchingDateAfter(new LocalDate(startOfFiscalYear()), new LocalDate(this.activationDate)).toDateMidnight().toDate();
}
Also used : SavingsInterestScheduledEventFactory(org.mifos.accounts.savings.interest.schedule.SavingsInterestScheduledEventFactory) CustomerException(org.mifos.customers.exceptions.CustomerException) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CalendarEvent(org.mifos.calendar.CalendarEvent) LocalDate(org.joda.time.LocalDate) HolidayDao(org.mifos.application.holiday.persistence.HolidayDao) DateTime(org.joda.time.DateTime) InterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent) AccountException(org.mifos.accounts.exceptions.AccountException) Holiday(org.mifos.application.holiday.business.Holiday) Days(org.joda.time.Days) CustomerBO(org.mifos.customers.business.CustomerBO) DateTimeService(org.mifos.framework.util.DateTimeService)

Aggregations

LocalDate (org.joda.time.LocalDate)1094 Test (org.testng.annotations.Test)553 BigDecimal (java.math.BigDecimal)401 DateTime (org.joda.time.DateTime)231 ArrayList (java.util.ArrayList)217 Test (org.junit.Test)187 Invoice (org.killbill.billing.invoice.api.Invoice)165 UUID (java.util.UUID)148 Account (org.killbill.billing.account.api.Account)139 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)118 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)104 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)101 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)95 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)85 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)82 RepairAdjInvoiceItem (org.killbill.billing.invoice.model.RepairAdjInvoiceItem)71 ItemAdjInvoiceItem (org.killbill.billing.invoice.model.ItemAdjInvoiceItem)69 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)63 Date (java.util.Date)57 MockPlan (org.killbill.billing.catalog.MockPlan)52