use of org.mifos.customers.business.CustomerAccountBO in project head by mifos.
the class StandardAccountService method makePaymentNoCommit.
public void makePaymentNoCommit(AccountPaymentParametersDto accountPaymentParametersDto, Integer savingsPaymentId, AccountPaymentEntity parentPayment) throws PersistenceException, AccountException {
final int accountId = accountPaymentParametersDto.getAccountId();
final AccountBO account = this.legacyAccountDao.getAccount(accountId);
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
try {
personnelDao.checkAccessPermission(userContext, account.getOfficeId(), account.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED, e);
}
monthClosingServiceFacade.validateTransactionDate(accountPaymentParametersDto.getPaymentDate().toDateMidnight().toDate());
/**
* Handle member payment if parent payment data not provided.
* Situation may occur when payment is executed directly on group member account (e.g. from transaction import).
* Loan Group Member payments should be posted after parent payment.
*/
if (account.isGroupLoanAccountMember() && parentPayment == null) {
AccountPaymentParametersDto parentPaymentParametersDto = this.createParentLoanPaymentData(account, accountPaymentParametersDto);
makePaymentNoCommit(parentPaymentParametersDto, savingsPaymentId, null);
return;
}
PersonnelBO loggedInUser = ApplicationContextProvider.getBean(LegacyPersonnelDao.class).findPersonnelById(accountPaymentParametersDto.getUserMakingPayment().getUserId());
List<InvalidPaymentReason> validationErrors = validatePayment(accountPaymentParametersDto);
if (!(account instanceof CustomerAccountBO) && validationErrors.contains(InvalidPaymentReason.INVALID_DATE)) {
throw new AccountException("errors.invalidTxndate");
}
Money overpaymentAmount = null;
Money amount = new Money(account.getCurrency(), accountPaymentParametersDto.getPaymentAmount());
if (account instanceof LoanBO && accountPaymentParametersDto.getPaymentOptions().contains(AccountPaymentParametersDto.PaymentOptions.ALLOW_OVERPAYMENTS) && amount.isGreaterThan(((LoanBO) account).getTotalRepayableAmount())) {
overpaymentAmount = amount.subtract(((LoanBO) account).getTotalRepayableAmount());
amount = ((LoanBO) account).getTotalRepayableAmount();
}
Date receiptDate = null;
if (accountPaymentParametersDto.getReceiptDate() != null) {
receiptDate = accountPaymentParametersDto.getReceiptDate().toDateMidnight().toDate();
}
PaymentData paymentData = account.createPaymentData(amount, accountPaymentParametersDto.getPaymentDate().toDateMidnight().toDate(), accountPaymentParametersDto.getReceiptId(), receiptDate, accountPaymentParametersDto.getPaymentType().getValue(), loggedInUser);
if (savingsPaymentId != null) {
AccountPaymentEntity withdrawal = legacyAccountDao.findPaymentById(savingsPaymentId);
paymentData.setOtherTransferPayment(withdrawal);
}
if (accountPaymentParametersDto.getCustomer() != null) {
paymentData.setCustomer(customerDao.findCustomerById(accountPaymentParametersDto.getCustomer().getCustomerId()));
}
paymentData.setComment(accountPaymentParametersDto.getComment());
paymentData.setOverpaymentAmount(overpaymentAmount);
if (account instanceof LoanBO && account.isGroupLoanAccountMember() && parentPayment != null) {
paymentData.setParentPayment(parentPayment);
}
AccountPaymentEntity paymentEntity = account.applyPayment(paymentData);
handleParentGroupLoanPayment(account, accountPaymentParametersDto, savingsPaymentId, paymentEntity);
this.legacyAccountDao.createOrUpdate(account);
}
use of org.mifos.customers.business.CustomerAccountBO in project head by mifos.
the class GenerateMeetingsForCustomerAndSavingsHelperIntegrationTest method testExecuteForCustomerAndSavingsAccount.
@Test
public void testExecuteForCustomerAndSavingsAccount() throws Exception {
// jpw - this test is similar to testExecuteForSavingsAccount
// Re-using much of it to test that customer and savings accounts are processed as have made separate queries to
// return the two different types of accounts.
int configuredValue = GeneralConfig.getOutputIntervalForBatchJobs();
MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
int outputInterval = 1;
try {
// force output for every account
configMgr.setProperty(GeneralConfig.OutputIntervalForBatchJobs, outputInterval);
savings = getSavingsAccountForCenter();
int noOfInstallments = savings.getAccountActionDates().size();
AccountTestUtils.changeInstallmentDatesToPreviousDate(savings);
CustomerAccountBO centerCustomerAccount = center.getCustomerAccount();
Integer centerCustomerAccountInstallments = centerCustomerAccount.getAccountActionDates().size();
AccountTestUtils.changeInstallmentDatesToPreviousDate(centerCustomerAccount);
CustomerAccountBO groupCustomerAccount = group.getCustomerAccount();
Integer groupCustomerAccountInstallments = groupCustomerAccount.getAccountActionDates().size();
AccountTestUtils.changeInstallmentDatesToPreviousDate(groupCustomerAccount);
CustomerAccountBO client1CustomerAccount = client1.getCustomerAccount();
Integer client1CustomerAccountInstallments = client1CustomerAccount.getAccountActionDates().size();
AccountTestUtils.changeInstallmentDatesToPreviousDate(client1CustomerAccount);
CustomerAccountBO client2CustomerAccount = client2.getCustomerAccount();
Integer client2CustomerAccountInstallments = client2CustomerAccount.getAccountActionDates().size();
AccountTestUtils.changeInstallmentDatesToPreviousDate(client2CustomerAccount);
StaticHibernateUtil.flushSession();
savings = TestObjectFactory.getObject(SavingsBO.class, savings.getAccountId());
new GenerateMeetingsForCustomerAndSavingsTask().getTaskHelper().execute(System.currentTimeMillis());
savings = TestObjectFactory.getObject(SavingsBO.class, savings.getAccountId());
centerCustomerAccount = TestObjectFactory.getObject(CustomerAccountBO.class, centerCustomerAccount.getAccountId());
groupCustomerAccount = TestObjectFactory.getObject(CustomerAccountBO.class, groupCustomerAccount.getAccountId());
client1CustomerAccount = TestObjectFactory.getObject(CustomerAccountBO.class, client1CustomerAccount.getAccountId());
client2CustomerAccount = TestObjectFactory.getObject(CustomerAccountBO.class, client2CustomerAccount.getAccountId());
Assert.assertEquals(noOfInstallments + 20, savings.getAccountActionDates().size());
Assert.assertEquals(centerCustomerAccountInstallments + 10, centerCustomerAccount.getAccountActionDates().size());
Assert.assertEquals(groupCustomerAccountInstallments + 10, groupCustomerAccount.getAccountActionDates().size());
Assert.assertEquals(client1CustomerAccountInstallments + 10, client1CustomerAccount.getAccountActionDates().size());
Assert.assertEquals(client2CustomerAccountInstallments + 10, client2CustomerAccount.getAccountActionDates().size());
} finally {
// restore original output interval value
configMgr.setProperty(GeneralConfig.OutputIntervalForBatchJobs, configuredValue);
}
}
use of org.mifos.customers.business.CustomerAccountBO in project head by mifos.
the class ApplyHolidayChangesHelperIntegrationTest method getCustomerAccountAndVerifyDates.
private void getCustomerAccountAndVerifyDates(CustomerBO customer, LocalDate[] expectedResultDates) {
CustomerAccountBO refreshedCustomerAccount = (CustomerAccountBO) StaticHibernateUtil.getSessionTL().get(CustomerAccountBO.class, customer.getCustomerAccount().getAccountId());
verifyAccountActionDates(refreshedCustomerAccount.getAccountActionDates(), expectedResultDates);
}
use of org.mifos.customers.business.CustomerAccountBO in project head by mifos.
the class CenterBuilder method build.
public CenterBO build() {
if (meeting == null && meetingBuilder != null) {
meeting = meetingBuilder.build();
}
center = CenterBO.createNew(userContext, name, mfiJoiningDate, meeting, loanOfficer, office, address, externalId, activationDate);
center.updateCustomerStatus(status);
center.setSearchId("1." + numberOfCustomersInOfficeAlready);
if (versionNumber != null) {
center.setVersionNo(versionNumber);
}
if (customerAccountBuilder != null) {
CustomerAccountBO customerAccount = customerAccountBuilder.withCustomer(center).buildForUnitTests();
center.addAccount(customerAccount);
}
if (loanAccount != null) {
center.addAccount(loanAccount);
}
return center;
}
use of org.mifos.customers.business.CustomerAccountBO in project head by mifos.
the class CustomerAccountCreationTest method givenMonthlyFrequencyAndChildCreatedAfterParentsFirstScheduleFirstCustomerScheduleForChildSynchsWithNearestScheduleOfParent.
@Test
public void givenMonthlyFrequencyAndChildCreatedAfterParentsFirstScheduleFirstCustomerScheduleForChildSynchsWithNearestScheduleOfParent() throws Exception {
// setup
applicableCalendarEvents = new CalendarEventBuilder().build();
DateTime tue19thOfApril = new DateTime().withDate(2011, 4, 19);
DateTime thursday26thOfMay = new DateTime().withDate(2011, 5, 26);
accountFees = new ArrayList<AccountFeesEntity>();
MeetingBO centerMeeting = new MeetingBuilder().customerMeeting().monthly().every(1).occuringOnA(WeekDay.MONDAY).startingFrom(tue19thOfApril.minusDays(1).toDate()).onDayOfMonth(18).build();
MeetingBO groupMeeting = new MeetingBuilder().customerMeeting().monthly().every(1).occuringOnA(WeekDay.MONDAY).startingFrom(thursday26thOfMay.minusDays(1).toDate()).onDayOfMonth(18).build();
CenterBO center = new CenterBuilder().active().withActivationDate(tue19thOfApril).with(centerMeeting).build();
GroupBO group = new GroupBuilder().active().withParentCustomer(center).withActivationDate(thursday26thOfMay).withMeeting(groupMeeting).build();
// exercise test
CustomerAccountBO centerAccount = CustomerAccountBO.createNew(center, accountFees, centerMeeting, applicableCalendarEvents);
CustomerAccountBO groupAccount = CustomerAccountBO.createNew(group, accountFees, groupMeeting, applicableCalendarEvents);
// verification
List<AccountActionDateEntity> centerSchedules = new ArrayList<AccountActionDateEntity>(centerAccount.getAccountActionDates());
List<AccountActionDateEntity> groupSchedules = new ArrayList<AccountActionDateEntity>(groupAccount.getAccountActionDates());
LocalDate secondCenterDate = new LocalDate(centerSchedules.get(1).getActionDate());
LocalDate firstGroupDate = new LocalDate(groupSchedules.get(0).getActionDate());
assertThat(firstGroupDate, is(secondCenterDate));
}
Aggregations