use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class LoanAccountServiceFacadeWebTier method getApplicablePayments.
private List<LoanActivityDto> getApplicablePayments(LoanBO loan) {
List<LoanActivityDto> payments = new ArrayList<LoanActivityDto>();
List<AccountPaymentEntity> accountPayments = loan.getAccountPayments();
int i = accountPayments.size() - 1;
if (accountPayments.size() > 0) {
for (AccountPaymentEntity accountPayment : accountPayments) {
if (accountPayment.getAmount().isGreaterThanZero()) {
Money amount = new Money(accountPayment.getAmount().getCurrency());
if (i == 0) {
for (AccountTrxnEntity accountTrxn : accountPayment.getAccountTrxns()) {
short accountActionTypeId = accountTrxn.getAccountActionEntity().getId().shortValue();
boolean isLoanRepayment = accountActionTypeId == AccountActionTypes.LOAN_REPAYMENT.getValue();
boolean isFeeRepayment = accountActionTypeId == AccountActionTypes.FEE_REPAYMENT.getValue();
if (isLoanRepayment || isFeeRepayment) {
amount = amount.add(accountTrxn.getAmount());
}
}
} else {
amount = accountPayment.getAmount();
}
if (amount.isGreaterThanZero()) {
LoanActivityDto loanActivityDto = new LoanActivityDto();
loanActivityDto.setActionDate(accountPayment.getPaymentDate());
loanActivityDto.setTotal(amount.toString());
loanActivityDto.setTotalValue(amount.getAmount().doubleValue());
payments.add(0, loanActivityDto);
}
}
i--;
}
}
return payments;
}
use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class StandardAccountServiceIntegrationTest method testMakePaymentForSavingsAccountOnDeposit.
@Test
public void testMakePaymentForSavingsAccountOnDeposit() throws Exception {
savingsBO = createClientSavingsAccount();
String deposit = "400";
CustomerDto clientDto = new CustomerDto();
clientDto.setCustomerId(client.getCustomerId());
//FIXME why one day in future payment is allowed
LocalDate paymentDate = new LocalDate().plusDays(1);
LocalDate receiptDate = new LocalDate().minusDays(3);
String receiptNumber = "AA/03/UX-9Q";
Assert.assertEquals(0, savingsBO.getAccountPayments().size());
AccountPaymentParametersDto depositPayment = new AccountPaymentParametersDto(new UserReferenceDto(savingsBO.getPersonnel().getPersonnelId()), new AccountReferenceDto(savingsBO.getAccountId()), new BigDecimal(deposit), paymentDate, defaultPaymentType, "comment", receiptDate, receiptNumber, clientDto);
standardAccountService.makePayment(depositPayment);
TestObjectFactory.updateObject(savingsBO);
Assert.assertEquals("The amount returned for the payment should have been " + deposit, Double.parseDouble(deposit), savingsBO.getLastPmntAmnt());
Assert.assertEquals(1, savingsBO.getAccountPayments().size());
for (AccountPaymentEntity payment : savingsBO.getAccountPayments()) {
Assert.assertEquals(TestUtils.createMoney(deposit), payment.getAmount());
Assert.assertEquals(1, payment.getAccountTrxns().size());
Assert.assertEquals(paymentDate.toDateMidnight().toDate(), payment.getPaymentDate());
Assert.assertEquals(defaultPaymentType.getName(), payment.getPaymentType().getName());
Assert.assertEquals("comment", payment.getComment());
Assert.assertEquals(savingsBO, payment.getAccount());
Assert.assertEquals(savingsBO.getPersonnel(), payment.getCreatedByUser());
Assert.assertEquals(receiptDate.toDateMidnight().toDate(), payment.getReceiptDate());
Assert.assertEquals(receiptNumber, payment.getReceiptNumber());
Assert.assertNull(payment.getCheckNumber());
Assert.assertNull(payment.getBankName());
Assert.assertNull(payment.getVoucherNumber());
Assert.assertTrue(payment.isSavingsDeposit());
Assert.assertFalse(payment.isSavingsWithdrawal());
Assert.assertTrue(payment.isSavingsDepositOrWithdrawal());
for (AccountTrxnEntity accountTrxn : payment.getAccountTrxns()) {
Assert.assertEquals(client.getCustomerId(), accountTrxn.getCustomer().getCustomerId());
}
}
}
use of org.mifos.accounts.business.AccountTrxnEntity 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.business.AccountTrxnEntity in project head by mifos.
the class SavingsBOIntegrationTest method testSavingsTrxnDetailsWithZeroAmt.
@Test
public void testSavingsTrxnDetailsWithZeroAmt() throws Exception {
savings = createSavingsAccountPayment();
for (AccountPaymentEntity accountPaymentEntity : savings.getAccountPayments()) {
for (AccountTrxnEntity accountTrxnEntity : accountPaymentEntity.getAccountTrxns()) {
SavingsTrxnDetailEntity trxnEntity = (SavingsTrxnDetailEntity) accountTrxnEntity;
Assert.assertEquals(new Money(getCurrency(), "5500"), trxnEntity.getBalance());
Assert.assertEquals(new Money(getCurrency()), trxnEntity.getDepositAmount());
Assert.assertEquals(new Money(getCurrency()), trxnEntity.getInterestAmount());
Assert.assertEquals(new Money(getCurrency()), trxnEntity.getWithdrawlAmount());
break;
}
}
}
use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class ImportTransactionsServiceFacadeWebTier method undoFullImport.
@Override
public void undoFullImport(String importTransactionsFileName) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
TreeSet<String> accountsWithAdjustedPayments = new TreeSet<String>();
try {
ImportedFilesEntity filesEntity = this.importedFilesService.getImportedFileByName(importTransactionsFileName);
List<AccountTrxnEntity> trxUndo = new ArrayList<AccountTrxnEntity>(filesEntity.getImportedTrxn());
List<ImportedAccPaymentDto> accPaymentList = new ArrayList<ImportedAccPaymentDto>();
for (AccountTrxnEntity trxn : trxUndo) {
try {
validateForAdjustedPayments(trxn, accountsWithAdjustedPayments);
accPaymentList.add(new ImportedAccPaymentDto(trxn.getAccount().getGlobalAccountNum(), trxn.getAccountPayment().getPaymentId()));
} catch (BusinessRuleException e) {
//nothing to do
}
}
for (ImportedAccPaymentDto accDto : accPaymentList) {
try {
this.accountServiceFacade.applyHistoricalAdjustment(accDto.getGlobalNum(), accDto.getPaymentId(), IMPORT_UNDONE, userContext.getId(), null);
} catch (MifosRuntimeException e) {
// TODO: validation will be added with MIFOS-5779
}
}
this.importedFilesService.saveImportedFileName(filesEntity.getFileName(), filesEntity.getSubmittedBy(), null, Boolean.TRUE, filesEntity.getUndoable());
} catch (Exception e) {
throw new MifosRuntimeException(e);
}
}
Aggregations