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;
}
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;
}
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);
}
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;
}
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));
}
Aggregations