Search in sources :

Example 11 with ConfigurationPersistence

use of org.mifos.config.persistence.ConfigurationPersistence in project head by mifos.

the class MeetingBO method isValidMeetingDate.

public boolean isValidMeetingDate(final Date meetingDate, final Date endDate) throws MeetingException {
    validateMeetingDate(meetingDate);
    validateEndDate(endDate);
    DateTime currentScheduleDateTime = findNearestMatchingDate(new DateTime(this.meetingStartDate));
    Date currentScheduleDate = currentScheduleDateTime.toDate();
    Calendar c = Calendar.getInstance();
    c.setTime(currentScheduleDate);
    currentScheduleDate = getNextWorkingDay(c).getTime();
    Date meetingDateWOTimeStamp = DateUtils.getDateWithoutTimeStamp(meetingDate.getTime());
    Date endDateWOTimeStamp = DateUtils.getDateWithoutTimeStamp(endDate.getTime());
    if (meetingDateWOTimeStamp.compareTo(endDateWOTimeStamp) > 0) {
        return false;
    }
    while (currentScheduleDate.compareTo(meetingDateWOTimeStamp) < 0 && currentScheduleDate.compareTo(endDateWOTimeStamp) < 0) {
        currentScheduleDate = findNextMatchingDate(new DateTime(currentScheduleDate)).toDate();
        c.setTime(currentScheduleDate);
        currentScheduleDate = getNextWorkingDay(c).getTime();
    }
    boolean isRepaymentIndepOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
    if (isRepaymentIndepOfMeetingEnabled) {
        return currentScheduleDate.compareTo(endDateWOTimeStamp) <= 0;
    }
    // match
    return currentScheduleDate.compareTo(endDateWOTimeStamp) <= 0 && currentScheduleDate.compareTo(meetingDateWOTimeStamp) == 0;
}
Also used : ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) Calendar(java.util.Calendar) DateTime(org.joda.time.DateTime) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 12 with ConfigurationPersistence

use of org.mifos.config.persistence.ConfigurationPersistence in project head by mifos.

the class MeetingBO method isValidMeetingDate.

public boolean isValidMeetingDate(final Date meetingDate, final int occurrences) throws MeetingException {
    validateMeetingDate(meetingDate);
    validateOccurences(occurrences);
    DateTime currentScheduleDateTime = findNearestMatchingDate(new DateTime(this.meetingStartDate));
    Date currentScheduleDate = currentScheduleDateTime.toDate();
    Date meetingDateWOTimeStamp = DateUtils.getDateWithoutTimeStamp(meetingDate.getTime());
    for (int currentNumber = 1; currentScheduleDate.compareTo(meetingDateWOTimeStamp) < 0 && currentNumber < occurrences; currentNumber++) {
        currentScheduleDate = findNextMatchingDate(new DateTime(currentScheduleDate)).toDate();
    }
    boolean isRepaymentIndepOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
    if (!isRepaymentIndepOfMeetingEnabled) {
        // match
        return currentScheduleDate.compareTo(meetingDateWOTimeStamp) == 0;
    }
    return true;
}
Also used : ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) DateTime(org.joda.time.DateTime) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 13 with ConfigurationPersistence

use of org.mifos.config.persistence.ConfigurationPersistence in project head by mifos.

the class ConfigurationInitializer method createSystemConfiguration.

protected SystemConfiguration createSystemConfiguration() throws SystemException {
    MifosCurrency defaultCurrency = null;
    try {
        defaultCurrency = AccountingRules.getMifosCurrency(new ConfigurationPersistence());
    } catch (RuntimeException re) {
        throw new SystemException("cannot fetch default currency", re);
    }
    // TODO: pick timezone offset from database
    int timeZone = 19800000;
    return new SystemConfiguration(defaultCurrency, timeZone);
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) SystemConfiguration(org.mifos.config.business.SystemConfiguration) MifosCurrency(org.mifos.application.master.business.MifosCurrency)

Example 14 with ConfigurationPersistence

use of org.mifos.config.persistence.ConfigurationPersistence in project head by mifos.

the class StandardAccountService method validatePayment.

@Override
public List<InvalidPaymentReason> validatePayment(AccountPaymentParametersDto payment) throws PersistenceException, AccountException {
    List<InvalidPaymentReason> errors = new ArrayList<InvalidPaymentReason>();
    AccountBO accountBo = this.legacyAccountDao.getAccount(payment.getAccountId());
    Date meetingDate = new CustomerPersistence().getLastMeetingDateForCustomer(accountBo.getCustomer().getCustomerId());
    boolean repaymentIndependentOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
    if (!accountBo.isTrxnDateValid(payment.getPaymentDate().toDateMidnight().toDate(), meetingDate, repaymentIndependentOfMeetingEnabled)) {
        errors.add(InvalidPaymentReason.INVALID_DATE);
    }
    if (accountBo instanceof LoanBO) {
        if (((LoanBO) accountBo).paymentsNotAllowed()) {
            errors.add(InvalidPaymentReason.INVALID_LOAN_STATE);
        }
    }
    if (accountBo instanceof SavingsBO) {
        if (!accountBo.getState().equals(AccountState.SAVINGS_ACTIVE)) {
            errors.add(InvalidPaymentReason.INVALID_LOAN_STATE);
        }
    }
    if (AccountTypes.getAccountType(accountBo.getAccountType().getAccountTypeId()) == AccountTypes.LOAN_ACCOUNT) {
        if (!getLoanPaymentTypes().contains(payment.getPaymentType())) {
            errors.add(InvalidPaymentReason.UNSUPPORTED_PAYMENT_TYPE);
        }
    } else if (AccountTypes.getAccountType(accountBo.getAccountType().getAccountTypeId()) == AccountTypes.SAVINGS_ACCOUNT) {
        if (!getSavingsPaymentTypes().contains(payment.getPaymentType())) {
            errors.add(InvalidPaymentReason.UNSUPPORTED_PAYMENT_TYPE);
        }
    } else if (AccountTypes.getAccountType(accountBo.getAccountType().getAccountTypeId()) == AccountTypes.CUSTOMER_ACCOUNT) {
        if (!getFeePaymentTypes().contains(payment.getPaymentType())) {
            errors.add(InvalidPaymentReason.UNSUPPORTED_PAYMENT_TYPE);
        }
    }
    if (!accountBo.paymentAmountIsValid(new Money(accountBo.getCurrency(), payment.getPaymentAmount()), payment.getPaymentOptions())) {
        errors.add(InvalidPaymentReason.INVALID_PAYMENT_AMOUNT);
    }
    return errors;
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) Money(org.mifos.framework.util.helpers.Money) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 15 with ConfigurationPersistence

use of org.mifos.config.persistence.ConfigurationPersistence in project head by mifos.

the class AccountBOIntegrationTest method testIsTrxnDateValidWithLSIM.

/*
     * When LSIM is turned on, back dated transactions should be allowed.
     */
@Test
public void testIsTrxnDateValidWithLSIM() throws Exception {
    new ConfigurationPersistence().updateConfigurationKeyValueInteger("repaymentSchedulesIndependentOfMeetingIsEnabled", 1);
    DateTime transactionDate = new DateTime();
    transactionDate = transactionDate.plusDays(10);
    java.util.Date trxnDate = transactionDate.toDate();
    PersonnelBO loggedInUser = IntegrationTestObjectMother.testUser();
    groupLoan.changeStatus(AccountState.LOAN_APPROVED, null, "status changed", loggedInUser);
    Assert.assertTrue(AccountingRules.isBackDatedTxnAllowed());
    Date meetingDate = new CustomerPersistence().getLastMeetingDateForCustomer(groupLoan.getCustomer().getCustomerId());
    Assert.assertTrue(groupLoan.isTrxnDateValid(trxnDate, meetingDate, false));
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) DateTime(org.joda.time.DateTime) Date(java.sql.Date) Test(org.junit.Test)

Aggregations

ConfigurationPersistence (org.mifos.config.persistence.ConfigurationPersistence)28 LocalDate (org.joda.time.LocalDate)9 DateTime (org.joda.time.DateTime)8 CustomerPersistence (org.mifos.customers.persistence.CustomerPersistence)8 Date (java.util.Date)7 AccountException (org.mifos.accounts.exceptions.AccountException)6 Test (org.junit.Test)5 Money (org.mifos.framework.util.helpers.Money)5 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)4 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)4 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)4 BusinessRuleException (org.mifos.service.BusinessRuleException)4 LoanBO (org.mifos.accounts.loan.business.LoanBO)3 ConfigurationKeyValue (org.mifos.config.business.ConfigurationKeyValue)3 MifosConfigurationManager (org.mifos.config.business.MifosConfigurationManager)3 PersistenceException (org.mifos.framework.exceptions.PersistenceException)3 DateTimeService (org.mifos.framework.util.DateTimeService)3 ArrayList (java.util.ArrayList)2 After (org.junit.After)2 Before (org.junit.Before)2