use of org.mifos.accounts.business.AccountTrxnEntity 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));
}
}
}
use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class AdminDocumentsServiceImpl method getAdminDocumentsForAccountPayment.
@Override
public List<AdminDocumentDto> getAdminDocumentsForAccountPayment(Integer paymentId) {
try {
List<AdminDocumentDto> adminDocuments = new ArrayList<AdminDocumentDto>();
AccountPaymentEntity accountPaymentEntity = legacyAccountDao.findPaymentById(paymentId);
Set<AccountTrxnEntity> accountTrxnEntities = accountPaymentEntity.getAccountTrxns();
for (AccountTrxnEntity accountTrxnEntity : accountTrxnEntities) {
List<AdminDocumentBO> adminDocumentBOs = legacyAdminDocumentDao.getActiveAdminDocumentsByAccountActionId(accountTrxnEntity.getAccountActionEntity().getId());
if (adminDocumentBOs != null && !adminDocumentBOs.isEmpty()) {
for (AdminDocumentBO adminDocumentBO : adminDocumentBOs) {
AdminDocumentDto adminDocumentDto = new AdminDocumentDto(adminDocumentBO.getAdmindocId().intValue(), adminDocumentBO.getAdminDocumentName(), adminDocumentBO.getAdminDocumentIdentifier(), BooleanUtils.toBoolean(adminDocumentBO.getIsActive().intValue()));
if (!adminDocuments.contains(adminDocumentDto)) {
adminDocuments.add(adminDocumentDto);
}
}
}
}
return adminDocuments;
} catch (PersistenceException e) {
throw new MifosRuntimeException(e);
}
}
use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class ImportTransactionsServiceFacadeWebTier method getUndoImportDateToValidate.
/**
* Method currently returns last problem found for each account.
*/
@Override
public Map<String, Map<String, String>> getUndoImportDateToValidate(String importTransactionsFileName) {
Map<String, Map<String, String>> validationResults = new HashMap<String, Map<String, String>>();
Map<String, String> accountStatusValidationResults = new HashMap<String, String>();
;
Map<String, String> trxnToUndo = new HashMap<String, String>();
;
List<AccountTrxnEntity> trxnData = new ArrayList<AccountTrxnEntity>(this.importedFilesService.getImportedFileByName(importTransactionsFileName).getImportedTrxn());
TreeSet<String> accountsWithAdjustedPayments = new TreeSet<String>();
Integer iterator = 0;
Boolean error_flag = Boolean.FALSE;
for (AccountTrxnEntity trxn : trxnData) {
error_flag = Boolean.FALSE;
if (trxn.getAccount().getAccountState().isLoanCanceled() || trxn.getAccount().getAccountState().isLoanClosedWrittenOff()) {
accountStatusValidationResults.put(trxn.getAccount().getGlobalAccountNum(), ApplicationContextProvider.getBean(MessageLookup.class).lookup("ftlDefinedLabels.undoImport.invalidAccountState") + trxn.getAccount().getAccountState().getName());
error_flag = Boolean.TRUE;
} else {
try {
validateForAdjustedPayments(trxn, accountsWithAdjustedPayments);
monthClosingServiceFacade.validateTransactionDate(trxn.getAccountPayment().getPaymentDate());
} catch (BusinessRuleException e) {
accountStatusValidationResults.put(trxn.getAccount().getGlobalAccountNum(), ApplicationContextProvider.getBean(MessageLookup.class).lookup(e.getMessageKey()));
error_flag = Boolean.TRUE;
}
}
if (error_flag) {
iterator += 1;
}
}
Integer valid_trxn = trxnData.size() - iterator;
validationResults.put(INVALID_TRXN, accountStatusValidationResults);
trxnToUndo.put(valid_trxn.toString(), ((Integer) trxnData.size()).toString());
validationResults.put(VALID_TRXN, trxnToUndo);
return validationResults;
}
use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class ImportedFilesServiceImpl method saveImportedFileName.
@Override
public void saveImportedFileName(String fileName, PersonnelBO submittedBy, List<AccountTrxDto> idsToUndoImport, Boolean phaseOut, Boolean undoable) {
Timestamp submittedOn = new Timestamp(new DateTimeService().getCurrentDateTime().getMillis());
Set<AccountTrxnEntity> accTrxEnt = new HashSet<AccountTrxnEntity>();
ImportedFilesEntity importedFile = new ImportedFilesEntity(fileName, submittedOn, submittedBy, accTrxEnt, phaseOut, undoable);
if (null != idsToUndoImport) {
for (AccountTrxDto trx : idsToUndoImport) {
accTrxEnt.add(importedFileDao.getAccTrxById(trx.getId()));
}
importedFile.setImportedTrxn(accTrxEnt);
}
try {
hibernateTransactionHelper.startTransaction();
importedFileDao.saveImportedFile(importedFile);
hibernateTransactionHelper.commitTransaction();
} catch (Exception e) {
hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
hibernateTransactionHelper.closeSession();
}
}
use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class LoanBOTest method repayInstallmentsShouldPopulateCalculatedInterestsForDIPBLoansWithWaiverInterest.
@Test
public void repayInstallmentsShouldPopulateCalculatedInterestsForDIPBLoansWithWaiverInterest() throws PersistenceException {
final LegacyLoanDao legacyLoanDao = mock(LegacyLoanDao.class);
final CustomerBO customerBO = mock(CustomerBO.class);
final LoanSummaryEntity loanSummaryEntity = mock(LoanSummaryEntity.class);
LoanBO loanBO = new LoanBO() {
@Override
public boolean isDecliningBalanceInterestRecalculation() {
return true;
}
@Override
public LegacyLoanDao getlegacyLoanDao() {
return legacyLoanDao;
}
@Override
public CustomerBO getCustomer() {
return customerBO;
}
@Override
public LoanSummaryEntity getLoanSummary() {
return loanSummaryEntity;
}
@Override
public MifosCurrency getCurrency() {
return rupee;
}
};
AccountActionTypes accountActionTypes = AccountActionTypes.LOAN_REPAYMENT;
AccountActionEntity accountActionEntity = mock(AccountActionEntity.class);
AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntityBuilder().with(loanBO).build();
PersonnelBO user = new PersonnelBO();
Money extraInterestDue = new Money(rupee, "0.98");
Money interest = new Money(rupee, "10");
Money interestDue = new Money(rupee, "0");
when(legacyLoanDao.getPersistentObject(AccountActionEntity.class, accountActionTypes.getValue())).thenReturn(accountActionEntity);
when(loanScheduleEntity.getPrincipalDue()).thenReturn(new Money(rupee, "1000"));
when(loanScheduleEntity.getTotalFeeDueWithMiscFeeDue()).thenReturn(new Money(rupee, "10"));
when(loanScheduleEntity.getPenaltyDue()).thenReturn(new Money(rupee, "10"));
when(loanScheduleEntity.getPenalty()).thenReturn(new Money(rupee, "100"));
when(loanScheduleEntity.getExtraInterestDue()).thenReturn(extraInterestDue);
when(loanScheduleEntity.getExtraInterestPaid()).thenReturn(extraInterestDue);
when(loanScheduleEntity.getInterest()).thenReturn(interest);
loanBO.repayInstallmentWithInterestWaiver(loanScheduleEntity, accountPaymentEntity, "", accountActionTypes, user);
Set<AccountTrxnEntity> accountTrxns = accountPaymentEntity.getAccountTrxns();
AccountTrxnEntity accountTrxnEntity = accountTrxns.toArray(new AccountTrxnEntity[accountTrxns.size()])[0];
LoanTrxnDetailEntity loanTrxnDetailEntity = (LoanTrxnDetailEntity) accountTrxnEntity;
assertThat(loanTrxnDetailEntity.getInterestAmount().getAmount().doubleValue(), is(0.98));
CalculatedInterestOnPayment calculatedInterestOnPayment = loanTrxnDetailEntity.getCalculatedInterestOnPayment();
assertNotNull(calculatedInterestOnPayment);
assertThat(calculatedInterestOnPayment.getExtraInterestPaid(), is(extraInterestDue));
assertThat(calculatedInterestOnPayment.getInterestDueTillPaid(), is(interestDue));
assertThat(calculatedInterestOnPayment.getOriginalInterest(), is(interest));
Mockito.verify(loanScheduleEntity).makeEarlyRepaymentEntries(LoanConstants.PAY_FEES_PENALTY, interestDue, accountPaymentEntity.getPaymentDate());
}
Aggregations