Search in sources :

Example 1 with CustomerBO

use of org.mifos.customers.business.CustomerBO in project head by mifos.

the class SavingsBO method determineAccountActivationDetails.

public static SavingsAccountActivationDetail determineAccountActivationDetails(CustomerBO customer, SavingsOfferingBO savingsProduct, Money recommendedOrMandatoryAmount, AccountState savingsAccountState, CalendarEvent calendarEvents, List<CustomerBO> activeAndOnHoldClients) {
    List<AccountActionDateEntity> scheduledPayments = new ArrayList<AccountActionDateEntity>();
    LocalDate activationDate = new LocalDate();
    LocalDate nextInterestPostingDate = new LocalDate();
    if (savingsAccountState.isActiveSavingsAccountState()) {
        activationDate = new LocalDate();
        ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(customer.getCustomerMeetingValue());
        ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(calendarEvents.getWorkingDays(), calendarEvents.getHolidays());
        for (CustomerBO client : activeAndOnHoldClients) {
            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(client, 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) CustomerBO(org.mifos.customers.business.CustomerBO) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)

Example 2 with CustomerBO

use of org.mifos.customers.business.CustomerBO in project head by mifos.

the class LegacyAccountDao method getCoSigningClientsForGlim.

public List<CustomerBO> getCoSigningClientsForGlim(Integer accountId) throws PersistenceException {
    HashMap<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put(QueryParamConstants.ACCOUNT_ID, accountId);
    List<LoanBO> loans = executeNamedQuery(NamedQueryConstants.GET_COSIGNING_CLIENTS_FOR_GLIM, queryParameters);
    List<CustomerBO> clients = new ArrayList<CustomerBO>();
    for (LoanBO loanBO : loans) {
        clients.add(loanBO.getCustomer());
    }
    return clients;
}
Also used : HashMap(java.util.HashMap) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) CustomerBO(org.mifos.customers.business.CustomerBO)

Example 3 with CustomerBO

use of org.mifos.customers.business.CustomerBO in project head by mifos.

the class SavingsBO method updateSavingsSchedule.

private void updateSavingsSchedule(final Short nextInstallmentId, final List<DateTime> meetingDates, final List<CustomerBO> children) {
    short installmentId = nextInstallmentId;
    for (int count = 0; count < meetingDates.size(); count++) {
        for (CustomerBO customer : children) {
            AccountActionDateEntity accountActionDate = getAccountActionDate(installmentId, customer.getCustomerId());
            if (accountActionDate != null) {
                Date meetingDate = meetingDates.get(count).toDate();
                ((SavingsScheduleEntity) accountActionDate).setActionDate(new java.sql.Date(meetingDate.getTime()));
            }
        }
        installmentId++;
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) CustomerBO(org.mifos.customers.business.CustomerBO) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 4 with CustomerBO

use of org.mifos.customers.business.CustomerBO 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 5 with CustomerBO

use of org.mifos.customers.business.CustomerBO 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)

Aggregations

CustomerBO (org.mifos.customers.business.CustomerBO)138 ArrayList (java.util.ArrayList)39 Money (org.mifos.framework.util.helpers.Money)38 MifosUser (org.mifos.security.MifosUser)38 UserContext (org.mifos.security.util.UserContext)37 LocalDate (org.joda.time.LocalDate)35 MifosRuntimeException (org.mifos.core.MifosRuntimeException)31 AccountException (org.mifos.accounts.exceptions.AccountException)30 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)27 BusinessRuleException (org.mifos.service.BusinessRuleException)27 MeetingBO (org.mifos.application.meeting.business.MeetingBO)23 ClientBO (org.mifos.customers.client.business.ClientBO)23 PersistenceException (org.mifos.framework.exceptions.PersistenceException)22 DateTime (org.joda.time.DateTime)20 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)20 Date (java.util.Date)19 Test (org.junit.Test)19 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)18 LoanBO (org.mifos.accounts.loan.business.LoanBO)17 HashMap (java.util.HashMap)15