Search in sources :

Example 91 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class CustomerAccountBO method createCustomerFeeScheduleForInstallment.

private void createCustomerFeeScheduleForInstallment(final AccountFeesEntity fee, CustomerScheduleEntity nextInstallment) throws AccountException {
    CustomerFeeScheduleEntity accountFeesaction = new CustomerFeeScheduleEntity(nextInstallment, fee.getFees(), fee, fee.getAccountFeeAmount());
    accountFeesaction.setFeeAmountPaid(new Money(fee.getAccountFeeAmount().getCurrency(), "0.0"));
    nextInstallment.addAccountFeesAction(accountFeesaction);
    String description = fee.getFees().getFeeName() + " " + AccountConstants.FEES_APPLIED;
    try {
        addCustomerActivity(new CustomerActivityEntity(this, ApplicationContextProvider.getBean(LegacyPersonnelDao.class).getPersonnel(Short.valueOf("1")), fee.getAccountFeeAmount(), description, new DateTimeService().getCurrentJavaDateTime()));
    } catch (PersistenceException e) {
        throw new AccountException(e);
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountException(org.mifos.accounts.exceptions.AccountException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) LegacyPersonnelDao(org.mifos.customers.personnel.persistence.LegacyPersonnelDao) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 92 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class CustomerAccountBO method updateCustomerActivity.

private void updateCustomerActivity(final Short chargeType, final Money charge, final String comments) throws AccountException {
    try {
        PersonnelBO personnel = ApplicationContextProvider.getBean(LegacyPersonnelDao.class).getPersonnel(getUserContext().getId());
        CustomerActivityEntity customerActivityEntity = null;
        if (chargeType != null && chargeType.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {
            customerActivityEntity = new CustomerActivityEntity(this, personnel, charge, AccountConstants.MISC_PENALTY_APPLIED, new DateTimeService().getCurrentJavaDateTime());
        } else if (chargeType != null && chargeType.equals(Short.valueOf(AccountConstants.MISC_FEES))) {
            customerActivityEntity = new CustomerActivityEntity(this, personnel, charge, AccountConstants.MISC_FEES_APPLIED, new DateTimeService().getCurrentJavaDateTime());
        } else {
            customerActivityEntity = new CustomerActivityEntity(this, personnel, charge, comments, new DateTimeService().getCurrentJavaDateTime());
        }
        addCustomerActivity(customerActivityEntity);
    } catch (PersistenceException e) {
        throw new AccountException(e);
    }
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) LegacyPersonnelDao(org.mifos.customers.personnel.persistence.LegacyPersonnelDao) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 93 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class CustomerAccountBO method applyOneTimeFee.

private void applyOneTimeFee(final FeeBO fee, final Money charge, final AccountActionDateEntity accountActionDateEntity) throws AccountException {
    CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDateEntity;
    AccountFeesEntity accountFee = new AccountFeesEntity(this, fee, charge.getAmountDoubleValue(), FeeStatus.ACTIVE.getValue(), new DateTimeService().getCurrentJavaDateTime(), null);
    List<AccountActionDateEntity> customerScheduleList = new ArrayList<AccountActionDateEntity>();
    customerScheduleList.add(customerScheduleEntity);
    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, customerScheduleList);
    updateCustomerActivity(fee.getFeeId(), totalFeeAmountApplied, fee.getFeeName() + AccountConstants.APPLIED);
    accountFee.setFeeStatus(FeeStatus.ACTIVE);
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) ArrayList(java.util.ArrayList) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) DateTimeService(org.mifos.framework.util.DateTimeService) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate)

Example 94 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class CustomerAccountBO method updateFee.

public void updateFee(final AccountFeesEntity fee, final FeeBO feeBO) throws BatchJobException {
    boolean feeApplied = isFeeAlreadyApplied(fee, feeBO);
    if (!feeApplied) {
        // update this account fee
        try {
            if (feeBO.getFeeChangeType().equals(FeeChangeType.AMOUNT_AND_STATUS_UPDATED)) {
                if (!feeBO.isActive()) {
                    removeFeesAssociatedWithUpcomingAndAllKnownFutureInstallments(feeBO.getFeeId(), Short.valueOf("1"));
                    fee.changeFeesStatus(FeeStatus.INACTIVE, new DateTimeService().getCurrentJavaDateTime());
                    updateAccountFee(fee, (AmountFeeBO) feeBO);
                } else {
                    // generate repayment schedule and enable fee
                    fee.changeFeesStatus(FeeStatus.ACTIVE, new DateTimeService().getCurrentJavaDateTime());
                    updateAccountFee(fee, (AmountFeeBO) feeBO);
                    associateFeeWithAllKnownFutureInstallments(fee);
                }
            } else if (feeBO.getFeeChangeType().equals(FeeChangeType.STATUS_UPDATED)) {
                if (!feeBO.isActive()) {
                    removeFeesAssociatedWithUpcomingAndAllKnownFutureInstallments(feeBO.getFeeId(), Short.valueOf("1"));
                } else {
                    fee.changeFeesStatus(FeeStatus.ACTIVE, new DateTimeService().getCurrentJavaDateTime());
                    associateFeeWithAllKnownFutureInstallments(fee);
                }
            } else if (feeBO.getFeeChangeType().equals(FeeChangeType.AMOUNT_UPDATED)) {
                updateAccountFee(fee, (AmountFeeBO) feeBO);
                updateUpcomingAndFutureInstallments(fee);
            }
        } catch (PropertyNotFoundException e) {
            throw new BatchJobException(e);
        } catch (AccountException e) {
            throw new BatchJobException(e);
        }
    }
}
Also used : BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) PropertyNotFoundException(org.mifos.framework.exceptions.PropertyNotFoundException) AccountException(org.mifos.accounts.exceptions.AccountException) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 95 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class ApplyHolidayChangesHelper method reschedule.

private void reschedule(Holiday holiday, AccountBatch accountBatch) throws PersistenceException {
    long rescheduleStartTime = new DateTimeService().getCurrentDateTime().getMillis();
    List<Object[]> accountIdsArray = accountBatch.getAccountIdsWithDatesIn(holiday);
    accountCount = accountIdsArray.size();
    logMessage("No. of " + accountBatch.getAccountTypeName() + " Accounts to Process: " + accountCount + " : Query took: " + (new DateTimeService().getCurrentDateTime().getMillis() - rescheduleStartTime) + " ms");
    rollingStartTime = new DateTimeService().getCurrentDateTime().getMillis();
    currentRecordNumber = 0;
    StaticHibernateUtil.getSessionTL();
    StaticHibernateUtil.startTransaction();
    for (Object[] accountIds : accountIdsArray) {
        Integer accountId = (Integer) accountIds[0];
        Short officeId = (Short) accountIds[1];
        Integer meetingId = (Integer) accountIds[2];
        currentRecordNumber++;
        ScheduledDateGeneration officeScheduledDateGeneration = getScheduledDateGeneration(officeId);
        DateTime amendedThruDate = holiday.getThruDate();
        // Normal holidays only affect installments between the fromDate and thruDate
        if (holiday.getRepaymentRuleType().getValue().equals(RepaymentRuleTypes.REPAYMENT_MORATORIUM.getValue())) {
            amendedThruDate = holiday.getThruDate().plusYears(10);
        }
        List<AccountActionDateEntity> futureAffectedInstallments = accountBatch.getAffectedInstallments(accountId, holiday.getFromDate(), amendedThruDate);
        MeetingBO meeting = (MeetingBO) StaticHibernateUtil.getSessionTL().get(MeetingBO.class, meetingId);
        rescheduleDatesForNewHolidays(officeScheduledDateGeneration, futureAffectedInstallments, meeting);
        houseKeeping();
    }
    StaticHibernateUtil.commitTransaction();
    long rescheduleEndTime = new DateTimeService().getCurrentDateTime().getMillis();
    String message = "" + currentRecordNumber + " updated, " + (accountCount - currentRecordNumber) + " remaining, batch time: " + (rescheduleEndTime - rollingStartTime) + " ms";
    logMessage(message);
    String finalMessage = accountBatch.getAccountTypeName() + " accounts Processed in: " + (rescheduleEndTime - rescheduleStartTime) + " ms";
    logMessage(finalMessage);
}
Also used : MeetingBO(org.mifos.application.meeting.business.MeetingBO) DateTime(org.joda.time.DateTime) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration) ScheduledDateGeneration(org.mifos.schedule.ScheduledDateGeneration) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) DateTimeService(org.mifos.framework.util.DateTimeService)

Aggregations

DateTimeService (org.mifos.framework.util.DateTimeService)99 Test (org.junit.Test)24 Date (java.util.Date)21 Money (org.mifos.framework.util.helpers.Money)20 DateTime (org.joda.time.DateTime)19 PersistenceException (org.mifos.framework.exceptions.PersistenceException)19 MeetingBO (org.mifos.application.meeting.business.MeetingBO)16 MifosRuntimeException (org.mifos.core.MifosRuntimeException)16 LocalDate (org.joda.time.LocalDate)15 AccountException (org.mifos.accounts.exceptions.AccountException)14 LoanBO (org.mifos.accounts.loan.business.LoanBO)14 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)14 ArrayList (java.util.ArrayList)13 CustomerBO (org.mifos.customers.business.CustomerBO)10 CustomerException (org.mifos.customers.exceptions.CustomerException)10 UserContext (org.mifos.security.util.UserContext)10 BusinessRuleException (org.mifos.service.BusinessRuleException)9 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)8 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)8 ApplicationException (org.mifos.framework.exceptions.ApplicationException)8