Search in sources :

Example 1 with ConfigurationPersistence

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

the class RepayLoanActionStrutsTest method tearDown.

@After
public void tearDown() throws Exception {
    new ConfigurationPersistence().updateConfigurationKeyValueInteger(LoanConstants.REPAYMENT_SCHEDULES_INDEPENDENT_OF_MEETING_IS_ENABLED, lsim);
    new DateTimeService().resetToCurrentSystemDateTime();
    accountBO = null;
    group = null;
    center = null;
}
Also used : ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) DateTimeService(org.mifos.framework.util.DateTimeService) After(org.junit.After)

Example 2 with ConfigurationPersistence

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

the class SavingsDepositWithdrawalAction method makePayment.

@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward makePayment(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    SavingsBO savedAccount = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    SavingsBO savings = savingsDao.findById(savedAccount.getAccountId());
    checkVersionMismatch(savedAccount.getVersionNo(), savings.getVersionNo());
    savings.setVersionNo(savedAccount.getVersionNo());
    SavingsDepositWithdrawalActionForm actionForm = (SavingsDepositWithdrawalActionForm) form;
    UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    Date trxnDate = getDateFromString(actionForm.getTrxnDate(), uc.getPreferredLocale());
    monthClosingServiceFacade.validateTransactionDate(trxnDate);
    Date meetingDate = new CustomerPersistence().getLastMeetingDateForCustomer(savings.getCustomer().getCustomerId());
    boolean repaymentIndependentOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
    if (!savings.isTrxnDateValid(trxnDate, meetingDate, repaymentIndependentOfMeetingEnabled)) {
        throw new AccountException(AccountConstants.ERROR_INVALID_TRXN);
    }
    Long savingsId = Long.valueOf(savings.getAccountId());
    Long customerId = Long.valueOf(savings.getCustomer().getCustomerId());
    if (StringUtils.isNotBlank(actionForm.getCustomerId())) {
        customerId = Long.valueOf(actionForm.getCustomerId());
    }
    Locale preferredLocale = uc.getPreferredLocale();
    LocalDate dateOfDepositOrWithdrawalTransaction = new LocalDate(trxnDate);
    Double amount = Double.valueOf(actionForm.getAmount());
    Integer modeOfPayment = Integer.valueOf(actionForm.getPaymentTypeId());
    String receiptId = actionForm.getReceiptId();
    LocalDate dateOfReceipt = null;
    if (StringUtils.isNotBlank(actionForm.getReceiptDate())) {
        dateOfReceipt = new LocalDate(getDateFromString(actionForm.getReceiptDate(), preferredLocale));
    }
    try {
        Short trxnTypeId = Short.valueOf(actionForm.getTrxnTypeId());
        if (trxnTypeId.equals(AccountActionTypes.SAVINGS_DEPOSIT.getValue())) {
            SavingsDepositDto savingsDeposit = new SavingsDepositDto(savingsId, customerId, dateOfDepositOrWithdrawalTransaction, amount, modeOfPayment, receiptId, dateOfReceipt, preferredLocale);
            this.savingsServiceFacade.deposit(savingsDeposit);
        } else if (trxnTypeId.equals(AccountActionTypes.SAVINGS_WITHDRAWAL.getValue())) {
            SavingsWithdrawalDto savingsWithdrawal = new SavingsWithdrawalDto(savingsId, customerId, dateOfDepositOrWithdrawalTransaction, amount, modeOfPayment, receiptId, dateOfReceipt, preferredLocale);
            this.savingsServiceFacade.withdraw(savingsWithdrawal);
        }
    } catch (BusinessRuleException e) {
        throw new AccountException(e.getMessageKey(), e);
    }
    return mapping.findForward(ActionForwards.account_details_page.toString());
}
Also used : Locale(java.util.Locale) UserContext(org.mifos.security.util.UserContext) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) SavingsDepositWithdrawalActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsDepositWithdrawalActionForm) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SavingsWithdrawalDto(org.mifos.dto.domain.SavingsWithdrawalDto) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) BusinessRuleException(org.mifos.service.BusinessRuleException) SavingsDepositDto(org.mifos.dto.domain.SavingsDepositDto) AccountException(org.mifos.accounts.exceptions.AccountException) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 3 with ConfigurationPersistence

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

the class LoanPrdAction method setRepaymentIndepOfMeetingEnabledFlag.

private void setRepaymentIndepOfMeetingEnabledFlag(HttpServletRequest request) throws PageExpiredException {
    boolean repaymentIndepOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
    SessionUtils.setAttribute(LoanConstants.REPAYMENT_SCHEDULES_INDEPENDENT_OF_MEETING_IS_ENABLED, repaymentIndepOfMeetingEnabled ? 1 : 0, request);
}
Also used : ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence)

Example 4 with ConfigurationPersistence

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

the class SavingsApplyAdjustmentAction method adjustLastUserAction.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward adjustLastUserAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    request.setAttribute("method", "adjustLastUserAction");
    UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    Integer accountId = savings.getAccountId();
    Integer versionNum = savings.getVersionNo();
    savings = savingsDao.findById(accountId);
    // NOTE: initialise so when error occurs when apply adjustment, savings object is correctly initialised for
    // use within Tag library in jsp.
    new SavingsPersistence().initialize(savings);
    checkVersionMismatch(versionNum, savings.getVersionNo());
    savings.setUserContext(uc);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, savings, request);
    if (savings.getPersonnel() != null) {
        getBizService().checkPermissionForAdjustment(AccountTypes.SAVINGS_ACCOUNT, null, uc, savings.getOffice().getOfficeId(), savings.getPersonnel().getPersonnelId());
    } else {
        getBizService().checkPermissionForAdjustment(AccountTypes.SAVINGS_ACCOUNT, null, uc, savings.getOffice().getOfficeId(), uc.getId());
    }
    SavingsApplyAdjustmentActionForm actionForm = (SavingsApplyAdjustmentActionForm) form;
    if (actionForm.getLastPaymentAmount() == null) {
        throw new MifosRuntimeException("Null payment amount is not allowed");
    }
    // date validation
    Date meetingDate = new CustomerPersistence().getLastMeetingDateForCustomer(savings.getCustomer().getCustomerId());
    boolean repaymentIndependentOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
    if (!savings.isTrxnDateValid(actionForm.getTrxnDateLocal().toDateMidnight().toDate(), meetingDate, repaymentIndependentOfMeetingEnabled)) {
        throw new AccountException(AccountConstants.ERROR_INVALID_TRXN);
    }
    Long savingsId = Long.valueOf(accountId.toString());
    Double adjustedAmount = Double.valueOf(actionForm.getLastPaymentAmount());
    String note = actionForm.getNote();
    AccountPaymentEntity adjustedPayment = savings.findPaymentById(actionForm.getPaymentId());
    AccountPaymentEntity otherTransferPayment = adjustedPayment.getOtherTransferPayment();
    try {
        if (otherTransferPayment == null || otherTransferPayment.isSavingsDepositOrWithdrawal()) {
            // regular savings payment adjustment or savings-savings transfer adjustment
            SavingsAdjustmentDto savingsAdjustment = new SavingsAdjustmentDto(savingsId, adjustedAmount, note, actionForm.getPaymentId(), actionForm.getTrxnDateLocal());
            this.savingsServiceFacade.adjustTransaction(savingsAdjustment);
        } else {
            // adjust repayment from savings account
            AccountBO account = adjustedPayment.getOtherTransferPayment().getAccount();
            AdjustedPaymentDto adjustedPaymentDto = new AdjustedPaymentDto(actionForm.getLastPaymentAmount(), actionForm.getTrxnDateLocal().toDateMidnight().toDate(), otherTransferPayment.getPaymentType().getId());
            this.accountServiceFacade.applyHistoricalAdjustment(account.getGlobalAccountNum(), otherTransferPayment.getPaymentId(), note, uc.getId(), adjustedPaymentDto);
        }
    } catch (BusinessRuleException e) {
        throw new AccountException(e.getMessageKey(), e);
    } finally {
        doCleanUp(request);
    }
    return mapping.findForward("account_detail_page");
}
Also used : SavingsPersistence(org.mifos.accounts.savings.persistence.SavingsPersistence) UserContext(org.mifos.security.util.UserContext) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) SavingsAdjustmentDto(org.mifos.dto.domain.SavingsAdjustmentDto) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) AccountBO(org.mifos.accounts.business.AccountBO) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) AdjustedPaymentDto(org.mifos.dto.domain.AdjustedPaymentDto) SavingsApplyAdjustmentActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsApplyAdjustmentActionForm) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) MifosRuntimeException(org.mifos.core.MifosRuntimeException) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 5 with ConfigurationPersistence

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

the class SavingsBOIntegrationTest method testIsTrxnDateValid_AfterFirstMeeting.

@Test
public void testIsTrxnDateValid_AfterFirstMeeting() throws Exception {
    createInitialObjects();
    savingsOffering = TestObjectFactory.createSavingsProduct("dfasdasd1", "sad1", RecommendedAmountUnit.COMPLETE_GROUP);
    savings = helper.createSavingsAccount(savingsOffering, group, AccountState.SAVINGS_ACTIVE, userContext);
    savings = TestObjectFactory.getObject(SavingsBO.class, savings.getAccountId());
    int i = -5;
    for (AccountActionDateEntity actionDate : savings.getAccountActionDates()) {
        ((SavingsScheduleEntity) actionDate).setActionDate(offSetCurrentDate(i--));
    }
    savings.update();
    savings = TestObjectFactory.getObject(SavingsBO.class, savings.getAccountId());
    java.util.Date trxnDate = offSetCurrentDate(-5);
    Date meetingDate = new CustomerPersistence().getLastMeetingDateForCustomer(savings.getCustomer().getCustomerId());
    boolean repaymentIndependentOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
    if (AccountingRules.isBackDatedTxnAllowed()) {
        Assert.assertTrue(savings.isTrxnDateValid(trxnDate, meetingDate, repaymentIndependentOfMeetingEnabled));
    } else {
        Assert.assertFalse(savings.isTrxnDateValid(trxnDate, meetingDate, repaymentIndependentOfMeetingEnabled));
    }
    group = TestObjectFactory.getGroup(group.getCustomerId());
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Date(java.util.Date) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) SavingsScheduleEntity(org.mifos.accounts.savings.business.SavingsScheduleEntity) Date(java.util.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