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