use of org.mifos.config.persistence.ConfigurationPersistence in project head by mifos.
the class LoanBO method applyMifos5763Fix.
public void applyMifos5763Fix() throws AccountException {
MeetingBO meetingBO = getLoanMeeting();
boolean isRepaymentIndepOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
for (LoanBO memberAccount : getMemberAccounts()) {
memberAccount.setNoOfInstallments(getNoOfInstallments());
memberAccount.setDisbursementDate(getDisbursementDate());
memberAccount.setLoanMeeting(meetingBO);
memberAccount.regeneratePaymentSchedule(isRepaymentIndepOfMeetingEnabled, meetingBO);
memberAccount.update();
for (int i = 0; i < getNoOfInstallments(); i++) {
memberAccount.getAccountActionDatesSortedByInstallmentId().get(i).setActionDate(getAccountActionDatesSortedByInstallmentId().get(i).getActionDate());
}
}
}
use of org.mifos.config.persistence.ConfigurationPersistence in project head by mifos.
the class DecliningBalancePrincipalWithInterestGenerator method generateEqualInstallments.
@Override
public List<InstallmentPrincipalAndInterest> generateEqualInstallments(LoanInterestCalculationDetails loanInterestCalculationDetails) {
GraceType graceType = loanInterestCalculationDetails.getGraceType();
Integer gracePeriodDuration = loanInterestCalculationDetails.getGracePeriodDuration();
Money loanAmount = loanInterestCalculationDetails.getLoanAmount();
Integer numberOfInstallments = loanInterestCalculationDetails.getNumberOfInstallments();
Double interestFractionalRatePerInstallment = loanInterestCalculationDetails.getInterestFractionalRatePerInstallment();
Double interestRate = loanInterestCalculationDetails.getInterestRate();
int prorateValue = 0;
List<InstallmentPrincipalAndInterest> lstInstallmntPricplIntrst = null;
LocalDate disbursalDateWithLocalDate = loanInterestCalculationDetails.getDisbursementDate();
DateTime disbursalDate = disbursalDateWithLocalDate.toDateTimeAtStartOfDay();
List<DateTime> dates = loanInterestCalculationDetails.getLoanScheduleDates();
if (dates.size() > 1) {
//check whether loanscheduledDates are there
DateTime firstRepaymentDay = dates.get(0);
long differenceOfTwoDatesinMilliseconds = (firstRepaymentDay.toDate().getTime() - disbursalDate.toDate().getTime());
long noOfDays = differenceOfTwoDatesinMilliseconds / (1000 * 60 * 60 * 24);
int noOfDaysBetweenFirstRepaymentDayAndDisbursalDate = (int) noOfDays;
DateTime secondRepaymentDay = dates.get(1);
long duration = (secondRepaymentDay.toDate().getTime() - firstRepaymentDay.toDate().getTime()) / (1000 * 60 * 60 * 24);
int noOfDaysInOneSchedule = (int) duration;
prorateValue = new ConfigurationPersistence().getConfigurationValueInteger(PRORATE_RULE);
if (prorateValue == 1)
lstInstallmntPricplIntrst = allDecliningInstallments_v2(loanAmount, numberOfInstallments, graceType, gracePeriodDuration, interestFractionalRatePerInstallment, interestRate, noOfDaysBetweenFirstRepaymentDayAndDisbursalDate, noOfDaysInOneSchedule);
}
if (prorateValue != 1) {
lstInstallmntPricplIntrst = allDecliningInstallments_v2(loanAmount, numberOfInstallments, graceType, gracePeriodDuration, interestFractionalRatePerInstallment, interestRate);
}
return lstInstallmntPricplIntrst;
}
use of org.mifos.config.persistence.ConfigurationPersistence in project head by mifos.
the class ApplicationInitializer method dbUpgrade.
public void dbUpgrade(ApplicationContext applicationContext) throws ConfigurationException, PersistenceException, FinancialException, TaskSystemException {
logger.info("Logger has been initialised");
initializeHibernate(applicationContext);
logger.info(getDatabaseConnectionInfo());
// if a database upgrade loads an instance of Money then MoneyCompositeUserType needs the default
// currency
MoneyCompositeUserType.setDefaultCurrency(AccountingRules.getMifosCurrency(new ConfigurationPersistence()));
// load the additional currencies
AccountingRules.init();
Money.setDefaultCurrency(AccountingRules.getMifosCurrency(new ConfigurationPersistence()));
final MifosConfigurationManager configuration = MifosConfigurationManager.getInstance();
final String imageStorageConfig = configuration.getString(IMAGESTORE_CONFIG_KEY);
if (imageStorageConfig == null || !imageStorageConfig.equals(DB_CONFIG)) {
ImageStorageManager.initStorage();
}
DatabaseMigrator migrator = new DatabaseMigrator();
initializeDBConnectionForHibernate(migrator);
if (!databaseError.isError) {
try {
migrator.upgrade(applicationContext);
} catch (Throwable t) {
setDatabaseError(DatabaseErrorCode.UPGRADE_FAILURE, "Failed to upgrade database.", t);
}
}
if (databaseError.isError) {
databaseError.logError();
} else {
initializeDB(applicationContext);
/*
* John W - Added in G Release and back patched to F Release.
* Related to jira issue MIFOS-4948
*
* Can find all code and the related query by searching for mifos4948
*
*/
CustomJDBCService customJdbcService = applicationContext.getBean(CustomJDBCService.class);
boolean keyExists = customJdbcService.mifos4948IssueKeyExists();
if (!keyExists) {
try {
StaticHibernateUtil.startTransaction();
applyMifos4948Fix();
customJdbcService.insertMifos4948Issuekey();
StaticHibernateUtil.commitTransaction();
} catch (AccountException e) {
StaticHibernateUtil.rollbackTransaction();
e.printStackTrace();
} finally {
StaticHibernateUtil.closeSession();
}
}
boolean key5722Exists = customJdbcService.mifos5722IssueKeyExists();
if (!key5722Exists) {
try {
applyMifos5722Fix();
customJdbcService.insertMifos5722Issuekey();
} catch (Exception e) {
logger.error("Could not apply Mifos-5692 and mifos-5722 fix");
e.printStackTrace();
} finally {
StaticHibernateUtil.closeSession();
}
}
boolean key5763Exists = customJdbcService.mifos5763IssueKeyExists();
if (!key5763Exists) {
try {
applyMifos5763Fix();
customJdbcService.insertMifos5763Issuekey();
} catch (Exception e) {
logger.info("Failed to apply Mifos-5763 fix");
e.printStackTrace();
} finally {
StaticHibernateUtil.closeSession();
}
}
boolean key5632Exists = customJdbcService.mifos5632IssueKeyExists();
if (!key5632Exists) {
try {
applyMifos5632();
customJdbcService.insertMifos5632IssueKey();
} catch (Exception e) {
logger.info("Failed to apply Mifos-5632 fix");
e.printStackTrace();
} finally {
StaticHibernateUtil.closeSession();
}
}
}
}
use of org.mifos.config.persistence.ConfigurationPersistence in project head by mifos.
the class StandardAccountService method validateLoanDisbursement.
/**
* Note that, since we don't store or otherwise utilize the amount disbursed (passed in
* AccountPaymentParametersDto.paymentAmount) we <em>do not</em> validate that digits after decimal for the amount
* disbursed fit in an allowed range. We <em>do</em> check that the amount disbursed matches the full amount of the
* loan.
*/
@Override
public List<InvalidPaymentReason> validateLoanDisbursement(AccountPaymentParametersDto payment) throws Exception {
List<InvalidPaymentReason> errors = new ArrayList<InvalidPaymentReason>();
LoanBO loanAccount = this.legacyLoanDao.getAccount(payment.getAccountId());
if ((loanAccount.getState() != AccountState.LOAN_APPROVED) && (loanAccount.getState() != AccountState.LOAN_DISBURSED_TO_LOAN_OFFICER)) {
errors.add(InvalidPaymentReason.INVALID_LOAN_STATE);
}
BigDecimal paymentAmount = payment.getPaymentAmount();
if ("MPESA".equals(payment.getPaymentType().getName())) {
paymentAmount = computeWithdrawnForMPESA(paymentAmount, loanAccount);
}
disbursalAmountMatchesFullLoanAmount(paymentAmount, errors, loanAccount);
Date meetingDate = new CustomerPersistence().getLastMeetingDateForCustomer(loanAccount.getCustomer().getCustomerId());
boolean repaymentIndependentOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
if (!loanAccount.isTrxnDateValid(payment.getPaymentDate().toDateMidnight().toDate(), meetingDate, repaymentIndependentOfMeetingEnabled)) {
errors.add(InvalidPaymentReason.INVALID_DATE);
}
if (!getLoanDisbursementTypes().contains(payment.getPaymentType())) {
errors.add(InvalidPaymentReason.UNSUPPORTED_PAYMENT_TYPE);
}
if (!loanAccount.paymentAmountIsValid(new Money(loanAccount.getCurrency(), payment.getPaymentAmount()), payment.getPaymentOptions())) {
errors.add(InvalidPaymentReason.INVALID_PAYMENT_AMOUNT);
}
if (loanAccount.getCustomer().isDisbursalPreventedDueToAnyExistingActiveLoansForTheSameProduct(loanAccount.getLoanOffering())) {
errors.add(InvalidPaymentReason.OTHER_ACTIVE_LOANS_FOR_THE_SAME_PRODUCT);
}
return errors;
}
use of org.mifos.config.persistence.ConfigurationPersistence in project head by mifos.
the class ClientCustActionFormTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
form = new ClientCustActionForm();
errors = new ActionErrors();
ConfigurationKeyValue groupCanApplyLoansKey = new ConfigurationKeyValue(ClientRules.GroupCanApplyLoansKey, 1);
ConfigurationKeyValue clientCanExistOutsideGroupKey = new ConfigurationKeyValue(ClientRules.ClientCanExistOutsideGroupKey, 1);
ConfigurationPersistence configPersistence = mock(ConfigurationPersistence.class);
when(configPersistence.getConfigurationKeyValue(ClientRules.GroupCanApplyLoansKey)).thenReturn(groupCanApplyLoansKey);
when(configPersistence.getConfigurationKeyValue(ClientRules.ClientCanExistOutsideGroupKey)).thenReturn(clientCanExistOutsideGroupKey);
ClientRules.setConfigPersistence(configPersistence);
minimumAgeForNewClientBeforeTestRun = ClientRules.getMinimumAgeForNewClient();
maximumAgeForNewClientBeforeTestRun = ClientRules.getMaximumAgeForNewClient();
ageCheckSettingBeforeTestRun = ClientRules.isAgeCheckEnabled();
}
Aggregations