Search in sources :

Example 6 with ConfigurationPersistence

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());
        }
    }
}
Also used : MeetingBO(org.mifos.application.meeting.business.MeetingBO) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence)

Example 7 with ConfigurationPersistence

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;
}
Also used : Money(org.mifos.framework.util.helpers.Money) GraceType(org.mifos.accounts.productdefinition.util.helpers.GraceType) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) InstallmentPrincipalAndInterest(org.mifos.accounts.loan.util.helpers.InstallmentPrincipalAndInterest) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime)

Example 8 with ConfigurationPersistence

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();
            }
        }
    }
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) DatabaseMigrator(org.mifos.framework.persistence.DatabaseMigrator) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) CustomJDBCService(org.mifos.application.servicefacade.CustomJDBCService) SystemException(org.mifos.framework.exceptions.SystemException) TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) XMLReaderException(org.mifos.framework.exceptions.XMLReaderException) HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) AppNotConfiguredException(org.mifos.framework.exceptions.AppNotConfiguredException) AccountException(org.mifos.accounts.exceptions.AccountException) FinancialException(org.mifos.accounts.financial.exceptions.FinancialException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) HibernateStartUpException(org.mifos.framework.exceptions.HibernateStartUpException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager)

Example 9 with ConfigurationPersistence

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;
}
Also used : Money(org.mifos.framework.util.helpers.Money) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) BigDecimal(java.math.BigDecimal) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 10 with ConfigurationPersistence

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();
}
Also used : ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) ConfigurationKeyValue(org.mifos.config.business.ConfigurationKeyValue) ActionErrors(org.apache.struts.action.ActionErrors)

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