Search in sources :

Example 6 with CustomerAccountBO

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);
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) PaymentData(org.mifos.accounts.util.helpers.PaymentData) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) LegacyPersonnelDao(org.mifos.customers.personnel.persistence.LegacyPersonnelDao) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) Money(org.mifos.framework.util.helpers.Money) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 7 with CustomerAccountBO

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);
    }
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager) Test(org.junit.Test)

Example 8 with CustomerAccountBO

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);
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO)

Example 9 with CustomerAccountBO

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;
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO)

Example 10 with CustomerAccountBO

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));
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) MeetingBO(org.mifos.application.meeting.business.MeetingBO) GroupBuilder(org.mifos.domain.builders.GroupBuilder) ArrayList(java.util.ArrayList) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) LocalDate(org.joda.time.LocalDate) CalendarEventBuilder(org.mifos.domain.builders.CalendarEventBuilder) DateTime(org.joda.time.DateTime) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) GroupBO(org.mifos.customers.group.business.GroupBO) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Test(org.junit.Test)

Aggregations

CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)36 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)15 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)15 MeetingBO (org.mifos.application.meeting.business.MeetingBO)12 DateTime (org.joda.time.DateTime)11 LocalDate (org.joda.time.LocalDate)11 AccountBO (org.mifos.accounts.business.AccountBO)10 CenterBuilder (org.mifos.domain.builders.CenterBuilder)10 MeetingBuilder (org.mifos.domain.builders.MeetingBuilder)10 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)9 CenterBO (org.mifos.customers.center.business.CenterBO)8 CalendarEventBuilder (org.mifos.domain.builders.CalendarEventBuilder)8 MifosRuntimeException (org.mifos.core.MifosRuntimeException)7 GroupBO (org.mifos.customers.group.business.GroupBO)7 GroupBuilder (org.mifos.domain.builders.GroupBuilder)7 AccountException (org.mifos.accounts.exceptions.AccountException)6 LoanBO (org.mifos.accounts.loan.business.LoanBO)6 UserContext (org.mifos.security.util.UserContext)6 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)5