Search in sources :

Example 26 with PaymentData

use of org.mifos.accounts.util.helpers.PaymentData in project head by mifos.

the class CustomerAccountBOIntegrationTest method testPayMiscChargePlusWeeklyFeeExactPreviousDay.

@Test
public void testPayMiscChargePlusWeeklyFeeExactPreviousDay() throws Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter("Center_Active_test", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group_Active_test", CustomerStatus.GROUP_ACTIVE, center);
    StaticHibernateUtil.flushSession();
    center = TestObjectFactory.getCustomer(center.getCustomerId());
    group = TestObjectFactory.getCustomer(group.getCustomerId());
    customerAccountBO = group.getCustomerAccount();
    UserContext uc = TestUtils.makeUser();
    customerAccountBO.setUserContext(uc);
    customerAccountBO.applyCharge(Short.valueOf("-1"), new Double("33"));
    CustomerScheduleEntity firstInstallment = null;
    for (AccountActionDateEntity accountActionDateEntity : customerAccountBO.getAccountActionDates()) {
        CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDateEntity;
        if (customerScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) {
            firstInstallment = customerScheduleEntity;
            Assert.assertEquals(new Money(getCurrency(), "33.0"), customerScheduleEntity.getMiscFee());
        }
    }
    DateMidnight pDate = new DateMidnight(firstInstallment.getActionDate());
    PaymentData paymentData = PaymentData.createPaymentData(new Money(getCurrency(), "133.0"), center.getPersonnel(), (short) 1, pDate.minusDays(1).toDate());
    customerAccountBO.applyPayment(paymentData);
    for (AccountActionDateEntity accountActionDateEntity : customerAccountBO.getAccountActionDates()) {
        CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDateEntity;
        if (customerScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) {
            Assert.assertEquals(new Money(getCurrency(), "33"), customerScheduleEntity.getMiscFee());
            Assert.assertEquals(new Money(getCurrency(), "33"), customerScheduleEntity.getMiscFeePaid());
        }
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) PaymentData(org.mifos.accounts.util.helpers.PaymentData) DateMidnight(org.joda.time.DateMidnight) MeetingBO(org.mifos.application.meeting.business.MeetingBO) UserContext(org.mifos.security.util.UserContext) Test(org.junit.Test)

Example 27 with PaymentData

use of org.mifos.accounts.util.helpers.PaymentData in project head by mifos.

the class CustomerAccountBOIntegrationTest method testPayMiscChargePlusPartOfWeeklyFeePreviousDay.

@Test
public void testPayMiscChargePlusPartOfWeeklyFeePreviousDay() throws Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter("Center_Active_test", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group_Active_test", CustomerStatus.GROUP_ACTIVE, center);
    StaticHibernateUtil.flushSession();
    center = TestObjectFactory.getCustomer(center.getCustomerId());
    group = TestObjectFactory.getCustomer(group.getCustomerId());
    customerAccountBO = group.getCustomerAccount();
    UserContext uc = TestUtils.makeUser();
    customerAccountBO.setUserContext(uc);
    customerAccountBO.applyCharge(Short.valueOf("-1"), new Double("33"));
    CustomerScheduleEntity firstInstallment = null;
    for (AccountActionDateEntity accountActionDateEntity : customerAccountBO.getAccountActionDates()) {
        CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDateEntity;
        if (customerScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) {
            firstInstallment = customerScheduleEntity;
            Assert.assertEquals(new Money(getCurrency(), "33.0"), customerScheduleEntity.getMiscFee());
        }
    }
    DateMidnight pDate = new DateMidnight(firstInstallment.getActionDate());
    PaymentData paymentData = PaymentData.createPaymentData(new Money(getCurrency(), "50.0"), center.getPersonnel(), (short) 1, pDate.minusDays(1).toDate());
    customerAccountBO.applyPayment(paymentData);
    for (AccountActionDateEntity accountActionDateEntity : customerAccountBO.getAccountActionDates()) {
        CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDateEntity;
        if (customerScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) {
            Assert.assertEquals(new Money(getCurrency(), "33"), customerScheduleEntity.getMiscFee());
            Assert.assertEquals(new Money(getCurrency(), "0"), customerScheduleEntity.getMiscFeePaid());
            Assert.assertEquals(new Money(getCurrency(), "100"), customerScheduleEntity.getAccountFeesActionDetailsSortedByFeeId().get(0).getFeeAmount());
            Assert.assertEquals(new Money(getCurrency(), "50"), customerScheduleEntity.getAccountFeesActionDetailsSortedByFeeId().get(0).getFeeAmountPaid());
        }
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) PaymentData(org.mifos.accounts.util.helpers.PaymentData) DateMidnight(org.joda.time.DateMidnight) MeetingBO(org.mifos.application.meeting.business.MeetingBO) UserContext(org.mifos.security.util.UserContext) Test(org.junit.Test)

Example 28 with PaymentData

use of org.mifos.accounts.util.helpers.PaymentData in project head by mifos.

the class CustomerAccountBOIntegrationTest method testActivityForMultiplePayments.

@Test
public void testActivityForMultiplePayments() throws Exception {
    // setup
    createCenter();
    CustomerAccountBO customerAccount = center.getCustomerAccount();
    Assert.assertNotNull(customerAccount);
    Date transactionDate = incrementCurrentDate(14);
    final Money paymentForThisInstallmentAndLastTwoInstallmentsInArrears = TestUtils.createMoney("300.0");
    List<AccountActionDateEntity> dueActionDates = TestObjectFactory.getDueActionDatesForAccount(customerAccount.getAccountId(), transactionDate);
    Assert.assertEquals("The size of the due insallments is ", dueActionDates.size(), 3);
    PaymentData accountPaymentDataView = TestObjectFactory.getCustomerAccountPaymentDataView(dueActionDates, paymentForThisInstallmentAndLastTwoInstallmentsInArrears, null, center.getPersonnel(), "3424324", Short.valueOf("1"), transactionDate, transactionDate);
    center = TestObjectFactory.getCustomer(center.getCustomerId());
    customerAccount = center.getCustomerAccount();
    // exercise test
    customerAccount.applyPayment(accountPaymentDataView);
    // verification
    assertThat(customerAccount.getCustomerActivitDetails().size(), is(1));
    assertThat("The size of the payments done is", customerAccount.getAccountPayments().size(), is(1));
    assertThat("The size of the due insallments after payment is", TestObjectFactory.getDueActionDatesForAccount(customerAccount.getAccountId(), transactionDate).size(), is(0));
    assertThat(customerAccount.getAccountPayments().size(), is(1));
    for (AccountPaymentEntity accountPayment : customerAccount.getAccountPayments()) {
        assertThat(accountPayment.getAccountTrxns().size(), is(3));
        for (AccountTrxnEntity accountTrxnEntity : accountPayment.getAccountTrxns()) {
            assertThat(accountTrxnEntity.getFinancialTransactions().size(), is(2));
        }
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) PaymentData(org.mifos.accounts.util.helpers.PaymentData) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.sql.Date) Test(org.junit.Test)

Example 29 with PaymentData

use of org.mifos.accounts.util.helpers.PaymentData in project head by mifos.

the class CustomerAccountBOIntegrationTest method verifyExpectedMessageThrown.

private void verifyExpectedMessageThrown(final CustomerBO customer, final Money paymentAmount, final Integer numberOfDaysForward, final String expectedErrorMessage) throws Exception {
    CustomerAccountBO customerAccount = customer.getCustomerAccount();
    Date transactionDate = incrementCurrentDate(numberOfDaysForward);
    PaymentData paymentData = PaymentData.createPaymentData(paymentAmount, customer.getPersonnel(), Short.valueOf("1"), transactionDate);
    paymentData.setCustomer(customer);
    String actualErrorMessage = "No Error Message";
    try {
        customerAccount.makePayment(paymentData);
    } catch (AccountException e) {
        actualErrorMessage = (String) e.getValues()[0];
    }
    Assert.assertEquals(expectedErrorMessage, actualErrorMessage);
}
Also used : PaymentData(org.mifos.accounts.util.helpers.PaymentData) AccountException(org.mifos.accounts.exceptions.AccountException) Date(java.sql.Date)

Example 30 with PaymentData

use of org.mifos.accounts.util.helpers.PaymentData in project head by mifos.

the class StandardAccountService method makeImportedPayments.

/**
     * method created for undo transaction import ability MIFOS-5702
     * returns Id of transaction  
     * */
public AccountBO makeImportedPayments(AccountPaymentParametersDto accountPaymentParametersDto, Integer savingsPaymentId) 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()) {
        AccountPaymentParametersDto parentPaymentParametersDto = this.createParentLoanPaymentData(account, accountPaymentParametersDto);
        return makeImportedPayments(parentPaymentParametersDto, savingsPaymentId);
    }
    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 (accountPaymentParametersDto.getPaymentOptions().contains(PaymentOptions.ALLOW_OVERPAYMENTS)) {
        paymentData.setAllowOverpayment(true);
    }
    AccountPaymentEntity paymentEntity = account.applyPayment(paymentData);
    handleParentGroupLoanPayment(account, accountPaymentParametersDto, savingsPaymentId, paymentEntity);
    this.legacyAccountDao.createOrUpdate(account);
    /*
         * Return null when only overpayment is being apply
         */
    if (amount.isZero() && overpaymentAmount != null && overpaymentAmount.isGreaterThanZero()) {
        return null;
    }
    return 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)

Aggregations

PaymentData (org.mifos.accounts.util.helpers.PaymentData)59 Money (org.mifos.framework.util.helpers.Money)34 Test (org.junit.Test)32 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)24 Date (java.util.Date)22 AccountException (org.mifos.accounts.exceptions.AccountException)22 LoanBO (org.mifos.accounts.loan.business.LoanBO)22 ArrayList (java.util.ArrayList)19 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)18 Date (java.sql.Date)17 MeetingBO (org.mifos.application.meeting.business.MeetingBO)15 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)15 LocalDate (org.joda.time.LocalDate)11 UserContext (org.mifos.security.util.UserContext)11 BigDecimal (java.math.BigDecimal)10 SavingsPaymentData (org.mifos.accounts.util.helpers.SavingsPaymentData)9 MifosRuntimeException (org.mifos.core.MifosRuntimeException)8 MifosUser (org.mifos.security.MifosUser)7 AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)6 DateTimeService (org.mifos.framework.util.DateTimeService)6