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