Search in sources :

Example 16 with CustomerPersistence

use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.

the class AccountBOIntegrationTest method testIsTrxnDateValid.

@Test
public void testIsTrxnDateValid() throws Exception {
    Calendar calendar = new GregorianCalendar();
    // Added by rajender on 24th July as test case was not passing
    calendar.add(Calendar.DAY_OF_MONTH, 10);
    java.util.Date trxnDate = new Date(calendar.getTimeInMillis());
    Date meetingDate = new CustomerPersistence().getLastMeetingDateForCustomer(groupLoan.getCustomer().getCustomerId());
    if (AccountingRules.isBackDatedTxnAllowed()) {
        Assert.assertTrue(groupLoan.isTrxnDateValid(trxnDate, meetingDate, false));
    } else {
        Assert.assertFalse(groupLoan.isTrxnDateValid(trxnDate, meetingDate, false));
    }
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) Date(java.sql.Date) Test(org.junit.Test)

Example 17 with CustomerPersistence

use of org.mifos.customers.persistence.CustomerPersistence 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 18 with CustomerPersistence

use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.

the class SavingsServiceFacadeWebTier method retrieveDepositWithdrawalReferenceData.

@Override
public DepositWithdrawalReferenceDto retrieveDepositWithdrawalReferenceData(Long savingsId, Integer customerId) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        SavingsBO savingsAccount = savingsDao.findById(savingsId);
        String depositDue = savingsAccount.getTotalPaymentDue(customerId).toString();
        String withdrawalDue = "0";
        List<ListElement> clients = new ArrayList<ListElement>();
        if (savingsAccount.isGroupModelWithIndividualAccountability()) {
            List<CustomerBO> activeAndOnHoldClients = new CustomerPersistence().getActiveAndOnHoldChildren(savingsAccount.getCustomer().getSearchId(), savingsAccount.getCustomer().getOfficeId(), CustomerLevel.CLIENT);
            for (CustomerBO client : activeAndOnHoldClients) {
                clients.add(new ListElement(client.getCustomerId(), client.getDisplayName()));
            }
        }
        List<AccountActionEntity> trxnTypes = new ArrayList<AccountActionEntity>();
        trxnTypes.add(new AccountBusinessService().getAccountAction(AccountActionTypes.SAVINGS_DEPOSIT.getValue(), userContext.getLocaleId()));
        trxnTypes.add(new AccountBusinessService().getAccountAction(AccountActionTypes.SAVINGS_WITHDRAWAL.getValue(), userContext.getLocaleId()));
        List<ListElement> transactionTypes = new ArrayList<ListElement>();
        for (AccountActionEntity accountActionEntity : trxnTypes) {
            LookUpValueEntity lookupValue = accountActionEntity.getLookUpValue();
            String messageText = lookupValue.getMessageText();
            if (StringUtils.isBlank(messageText)) {
                messageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupValue.getPropertiesKey());
            }
            transactionTypes.add(new ListElement(accountActionEntity.getId().intValue(), messageText));
        }
        List<ListElement> depositPaymentTypes = retrieveDepositPaymentTypes(userContext);
        List<ListElement> withdrawalPaymentTypes = new ArrayList<ListElement>();
        List<PaymentTypeEntity> withdrawalPaymentEntityTypes = legacyAcceptedPaymentTypeDao.getAcceptedPaymentTypesForATransaction(userContext.getLocaleId(), TrxnTypes.savings_withdrawal.getValue());
        for (PaymentTypeEntity paymentTypeEntity : withdrawalPaymentEntityTypes) {
            LookUpValueEntity lookupValue = paymentTypeEntity.getLookUpValue();
            String messageText = lookupValue.getMessageText();
            if (StringUtils.isBlank(messageText)) {
                messageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupValue.getPropertiesKey());
            }
            withdrawalPaymentTypes.add(new ListElement(paymentTypeEntity.getId().intValue(), messageText));
        }
        boolean backDatedTransactionsAllowed = AccountingRules.isBackDatedTxnAllowed();
        LocalDate defaultTransactionDate = new LocalDate();
        return new DepositWithdrawalReferenceDto(transactionTypes, depositPaymentTypes, withdrawalPaymentTypes, clients, backDatedTransactionsAllowed, defaultTransactionDate, depositDue, withdrawalDue);
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LocalDate(org.joda.time.LocalDate) AccountActionEntity(org.mifos.accounts.business.AccountActionEntity) PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) ListElement(org.mifos.dto.screen.ListElement) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) DepositWithdrawalReferenceDto(org.mifos.dto.screen.DepositWithdrawalReferenceDto) LookUpValueEntity(org.mifos.application.master.business.LookUpValueEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 19 with CustomerPersistence

use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.

the class CenterBOIntegrationTest method testSuccessfulCreateWithoutFee.

@Test
public void testSuccessfulCreateWithoutFee() throws Exception {
    String name = "Center";
    meeting = getMeeting();
    center = new CenterBO(TestUtils.makeUser(), name, null, getCustomFields(), null, null, null, officeBo, meeting, personnelBo, new CustomerPersistence());
    new CenterPersistence().saveCenter(center);
    StaticHibernateUtil.flushSession();
    center = TestObjectFactory.getCenter(center.getCustomerId());
    Assert.assertEquals(name, center.getDisplayName());
    Assert.assertEquals(officeId, center.getOffice().getOfficeId());
    Assert.assertEquals(2, center.getCustomFields().size());
}
Also used : CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) CenterPersistence(org.mifos.customers.center.persistence.CenterPersistence) Test(org.junit.Test)

Example 20 with CustomerPersistence

use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.

the class CenterBOIntegrationTest method testSearchIdOnlyUniquePerOffice.

@Test
public void testSearchIdOnlyUniquePerOffice() throws Exception {
    Date startDate = new Date();
    StaticHibernateUtil.startTransaction();
    // In real life, would be another branch rather than an area
    OfficeBO branch1 = new OfficePersistence().getOffice(TestObjectFactory.SAMPLE_AREA_OFFICE);
    MeetingBO meeting = new MeetingBO(WeekDay.THURSDAY, (short) 1, startDate, MeetingType.CUSTOMER_MEETING, "Delhi");
    PersonnelBO systemUser = legacyPersonnelDao.getPersonnel(PersonnelConstants.SYSTEM_USER);
    center = new CenterBO(TestUtils.makeUser(), "Center", null, null, null, null, startDate, branch1, meeting, systemUser, new CustomerPersistence());
    StaticHibernateUtil.getSessionTL().save(center);
    CenterBO center2 = new CenterBO(TestUtils.makeUser(), "center2", null, null, null, null, startDate, new OfficePersistence().getOffice(TestObjectFactory.SAMPLE_BRANCH_OFFICE), meeting, systemUser, new CustomerPersistence());
    CenterBO sameBranch = new CenterBO(TestUtils.makeUser(), "sameBranch", null, null, null, null, startDate, branch1, meeting, systemUser, new CustomerPersistence());
    StaticHibernateUtil.getSessionTL().save(center);
    StaticHibernateUtil.flushSession();
    Assert.assertEquals("1.1", center.getSearchId());
    Assert.assertEquals("1.1", center2.getSearchId());
    Assert.assertEquals("1.2", sameBranch.getSearchId());
}
Also used : OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) Date(java.util.Date) Test(org.junit.Test)

Aggregations

CustomerPersistence (org.mifos.customers.persistence.CustomerPersistence)40 PersistenceException (org.mifos.framework.exceptions.PersistenceException)15 UserContext (org.mifos.security.util.UserContext)14 ArrayList (java.util.ArrayList)13 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)11 Date (java.util.Date)10 Test (org.junit.Test)9 MifosRuntimeException (org.mifos.core.MifosRuntimeException)9 ConfigurationPersistence (org.mifos.config.persistence.ConfigurationPersistence)8 CustomerBO (org.mifos.customers.business.CustomerBO)8 LocalDate (org.joda.time.LocalDate)7 AccountException (org.mifos.accounts.exceptions.AccountException)7 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)7 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)7 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)6 CustomerException (org.mifos.customers.exceptions.CustomerException)6 BusinessRuleException (org.mifos.service.BusinessRuleException)6 AccountBO (org.mifos.accounts.business.AccountBO)5 CenterPersistence (org.mifos.customers.center.persistence.CenterPersistence)5 DateTime (org.joda.time.DateTime)4