Search in sources :

Example 1 with SavingsPaymentData

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

the class SavingsBOIntegrationTest method testSuccessfulApplyPayment.

@Test
public void testSuccessfulApplyPayment() throws AccountException, Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter("Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
    client1 = TestObjectFactory.createClient("Client", CustomerStatus.CLIENT_ACTIVE, group);
    savingsOffering = helper.createSavingsOffering("dfasdasd1", "sad1");
    savings = TestObjectFactory.createSavingsAccount("43245434", client1, AccountStates.SAVINGS_ACC_INACTIVE, new Date(System.currentTimeMillis()), savingsOffering);
    savings = (SavingsBO) legacyAccountDao.getAccount(savings.getAccountId());
    savings.setSavingsBalance(new Money(getCurrency()));
    Money enteredAmount = new Money(currency, "100.0");
    PaymentData paymentData = PaymentData.createPaymentData(enteredAmount, savings.getPersonnel(), Short.valueOf("1"), new Date(System.currentTimeMillis()));
    paymentData.setCustomer(client1);
    paymentData.setReceiptDate(new Date(System.currentTimeMillis()));
    paymentData.setReceiptNum("34244");
    AccountActionDateEntity accountActionDate = savings.getAccountActionDate(Short.valueOf("1"));
    SavingsPaymentData savingsPaymentData = new SavingsPaymentData(accountActionDate);
    paymentData.addAccountPaymentData(savingsPaymentData);
    IntegrationTestObjectMother.applyAccountPayment(savings, paymentData);
    Assert.assertEquals(AccountStates.SAVINGS_ACC_APPROVED, savings.getAccountState().getId().shortValue());
    Assert.assertEquals(TestUtils.createMoney(100.0), savings.getSavingsBalance());
    Assert.assertEquals(1, savings.getSavingsActivityDetails().size());
    savings.getAccountPayments().clear();
    client1 = IntegrationTestObjectMother.findCustomerById(client1.getCustomerId());
}
Also used : SavingsPaymentData(org.mifos.accounts.util.helpers.SavingsPaymentData) Money(org.mifos.framework.util.helpers.Money) PaymentData(org.mifos.accounts.util.helpers.PaymentData) SavingsPaymentData(org.mifos.accounts.util.helpers.SavingsPaymentData) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) MeetingBO(org.mifos.application.meeting.business.MeetingBO) Date(java.util.Date) Test(org.junit.Test)

Example 2 with SavingsPaymentData

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

the class SavingsBOIntegrationTest method testSuccessfulDepositForCenterAccount.

@Test
public void testSuccessfulDepositForCenterAccount() throws AccountException, Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter("Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
    client1 = TestObjectFactory.createClient("Client", CustomerStatus.CLIENT_ACTIVE, group);
    savingsOffering = helper.createSavingsOffering("dfasdasd1", "sad1");
    savings = TestObjectFactory.createSavingsAccount("43245434", center, AccountStates.SAVINGS_ACC_APPROVED, new Date(System.currentTimeMillis()), savingsOffering);
    savings.setSavingsBalance(new Money(getCurrency()));
    savings = (SavingsBO) legacyAccountDao.getAccount(savings.getAccountId());
    Money enteredAmount = new Money(currency, "100.0");
    PaymentData paymentData = PaymentData.createPaymentData(enteredAmount, savings.getPersonnel(), Short.valueOf("1"), new Date(System.currentTimeMillis()));
    paymentData.setCustomer(client1);
    paymentData.setReceiptDate(new Date(System.currentTimeMillis()));
    paymentData.setReceiptNum("34244");
    AccountActionDateEntity accountActionDate = savings.getAccountActionDate(Short.valueOf("1"));
    SavingsPaymentData savingsPaymentData = new SavingsPaymentData(accountActionDate);
    paymentData.addAccountPaymentData(savingsPaymentData);
    IntegrationTestObjectMother.applyAccountPayment(savings, paymentData);
    savings = (SavingsBO) legacyAccountDao.getAccount(savings.getAccountId());
    Assert.assertEquals(AccountStates.SAVINGS_ACC_APPROVED, savings.getAccountState().getId().shortValue());
    Assert.assertEquals(TestUtils.createMoney(100.0), savings.getSavingsBalance());
    Assert.assertEquals(1, savings.getSavingsActivityDetails().size());
    List<AccountPaymentEntity> payments = savings.getAccountPayments();
    Assert.assertEquals(1, payments.size());
    for (AccountPaymentEntity payment : payments) {
        Assert.assertEquals(1, payment.getAccountTrxns().size());
        for (AccountTrxnEntity accountTrxn : payment.getAccountTrxns()) {
            SavingsTrxnDetailEntity trxn = (SavingsTrxnDetailEntity) accountTrxn;
            Assert.assertEquals(enteredAmount, trxn.getBalance());
            Assert.assertEquals(client1.getCustomerId(), trxn.getCustomer().getCustomerId());
        }
    }
    client1 = IntegrationTestObjectMother.findCustomerById(client1.getCustomerId());
}
Also used : SavingsPaymentData(org.mifos.accounts.util.helpers.SavingsPaymentData) Money(org.mifos.framework.util.helpers.Money) PaymentData(org.mifos.accounts.util.helpers.PaymentData) SavingsPaymentData(org.mifos.accounts.util.helpers.SavingsPaymentData) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) MeetingBO(org.mifos.application.meeting.business.MeetingBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsTrxnDetailEntity(org.mifos.accounts.savings.business.SavingsTrxnDetailEntity) Date(java.util.Date) Test(org.junit.Test)

Example 3 with SavingsPaymentData

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

the class SavingsApplyAdjustmentActionStrutsTest method createSavingsAccountWithPayment.

private SavingsBO createSavingsAccountWithPayment(String globalAccountNum, SavingsOfferingBO savingsOffering, CustomerBO group, AccountState state) throws Exception {
    SavingsBO savings = TestObjectFactory.createSavingsAccount(globalAccountNum, group, state, new Date(), savingsOffering, userContext);
    PaymentData paymentData = PaymentData.createPaymentData(new Money(getCurrency(), "100"), savings.getPersonnel(), Short.valueOf("1"), new Date(System.currentTimeMillis()));
    paymentData.setCustomer(group);
    paymentData.setReceiptDate(new Date(System.currentTimeMillis()));
    paymentData.setReceiptNum("34244");
    AccountActionDateEntity accountActionDate = null;
    paymentData.addAccountPaymentData(new SavingsPaymentData(accountActionDate));
    IntegrationTestObjectMother.applyAccountPayment(savings, paymentData);
    return savingsDao.findById(savings.getAccountId());
}
Also used : SavingsPaymentData(org.mifos.accounts.util.helpers.SavingsPaymentData) SavingsPaymentData(org.mifos.accounts.util.helpers.SavingsPaymentData) PaymentData(org.mifos.accounts.util.helpers.PaymentData) Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) Date(java.util.Date)

Example 4 with SavingsPaymentData

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

the class SavingsServiceFacadeWebTier method deposit.

@Override
public PaymentDto deposit(SavingsDepositDto savingsDeposit, boolean inTransaction) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    SavingsBO savingsAccount = this.savingsDao.findById(savingsDeposit.getSavingsId());
    try {
        personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException(e.getMessage(), e);
    }
    savingsAccount.updateDetails(userContext);
    PersonnelBO createdBy = this.personnelDao.findPersonnelById(Short.valueOf((short) user.getUserId()));
    CustomerBO customer = this.customerDao.findCustomerById(savingsDeposit.getCustomerId().intValue());
    Money totalAmount = new Money(savingsAccount.getCurrency(), BigDecimal.valueOf(savingsDeposit.getAmount()));
    PaymentData payment = PaymentData.createPaymentData(totalAmount, createdBy, savingsDeposit.getModeOfPayment().shortValue(), savingsDeposit.getDateOfDeposit().toDateMidnight().toDate());
    if (savingsDeposit.getDateOfReceipt() != null) {
        payment.setReceiptDate(savingsDeposit.getDateOfReceipt().toDateMidnight().toDate());
    }
    payment.setReceiptNum(savingsDeposit.getReceiptId());
    payment.setCustomer(customer);
    for (AccountActionDateEntity installment : savingsAccount.getTotalInstallmentsDue(savingsDeposit.getCustomerId().intValue())) {
        AccountPaymentData accountPaymentData = new SavingsPaymentData(installment);
        payment.addAccountPaymentData(accountPaymentData);
    }
    try {
        if (!inTransaction) {
            this.transactionHelper.startTransaction();
            this.transactionHelper.beginAuditLoggingFor(savingsAccount);
        }
        AccountPaymentEntity newPaymentEntity = savingsAccount.applyPayment(payment);
        this.savingsDao.save(savingsAccount);
        Date lastIntPostDate = savingsAccount.getLastIntPostDate();
        if (lastIntPostDate != null && DateUtils.dateFallsOnOrBeforeDate(payment.getTransactionDate(), lastIntPostDate)) {
            this.recalculateInterestPostings(savingsAccount.getAccountId(), new LocalDate(payment.getTransactionDate()));
        }
        // commit
        if (inTransaction) {
            this.transactionHelper.flushSession();
        } else {
            this.transactionHelper.commitTransaction();
        }
        return newPaymentEntity.toDto();
    } catch (AccountException e) {
        if (!inTransaction) {
            this.transactionHelper.rollbackTransaction();
        }
        throw new BusinessRuleException(e.getKey(), e);
    } finally {
        if (!inTransaction) {
            this.transactionHelper.closeSession();
        }
    }
}
Also used : AccountPaymentData(org.mifos.accounts.util.helpers.AccountPaymentData) PaymentData(org.mifos.accounts.util.helpers.PaymentData) SavingsPaymentData(org.mifos.accounts.util.helpers.SavingsPaymentData) AccountPaymentData(org.mifos.accounts.util.helpers.AccountPaymentData) UserContext(org.mifos.security.util.UserContext) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) SavingsPaymentData(org.mifos.accounts.util.helpers.SavingsPaymentData) Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CustomerBO(org.mifos.customers.business.CustomerBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

Date (java.util.Date)4 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)4 PaymentData (org.mifos.accounts.util.helpers.PaymentData)4 SavingsPaymentData (org.mifos.accounts.util.helpers.SavingsPaymentData)4 Money (org.mifos.framework.util.helpers.Money)4 Test (org.junit.Test)2 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)2 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)2 MeetingBO (org.mifos.application.meeting.business.MeetingBO)2 LocalDate (org.joda.time.LocalDate)1 AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)1 AccountException (org.mifos.accounts.exceptions.AccountException)1 SavingsTrxnDetailEntity (org.mifos.accounts.savings.business.SavingsTrxnDetailEntity)1 AccountPaymentData (org.mifos.accounts.util.helpers.AccountPaymentData)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 CustomerBO (org.mifos.customers.business.CustomerBO)1 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)1 MifosUser (org.mifos.security.MifosUser)1 UserContext (org.mifos.security.util.UserContext)1 BusinessRuleException (org.mifos.service.BusinessRuleException)1