diff --git a/fineract-core/src/main/java/org/apache/fineract/commands/domain/CommandSource.java b/fineract-core/src/main/java/org/apache/fineract/commands/domain/CommandSource.java
index 7cdfa0623..e9c0d9f89 100644
--- a/fineract-core/src/main/java/org/apache/fineract/commands/domain/CommandSource.java
+++ b/fineract-core/src/main/java/org/apache/fineract/commands/domain/CommandSource.java
@@ -143,7 +143,7 @@ public class CommandSource extends AbstractPersistableCustom {
this.subResourceId = subResourceId;
this.commandAsJson = commandSerializedAsJson;
this.maker = maker;
- this.madeOnDate = DateUtils.getOffsetDateTimeOfTenant();
+ this.madeOnDate = DateUtils.getOffsetDateTimeOfTenantWithMostPrecision();
this.status = status;
this.idempotencyKey = idempotencyKey;
}
@@ -170,13 +170,13 @@ public class CommandSource extends AbstractPersistableCustom {
public void markAsChecked(final AppUser checker) {
this.checker = checker;
- this.checkedOnDate = DateUtils.getOffsetDateTimeOfTenant();
+ this.checkedOnDate = DateUtils.getOffsetDateTimeOfTenantWithMostPrecision();
this.status = CommandProcessingResultType.PROCESSED.getValue();
}
public void markAsRejected(final AppUser checker) {
this.checker = checker;
- this.checkedOnDate = DateUtils.getOffsetDateTimeOfTenant();
+ this.checkedOnDate = DateUtils.getOffsetDateTimeOfTenantWithMostPrecision();
this.status = CommandProcessingResultType.REJECTED.getValue();
}
diff --git a/fineract-investor/src/main/resources/db/changelog/tenant/module/investor/module-changelog-master.xml b/fineract-investor/src/main/resources/db/changelog/tenant/module/investor/module-changelog-master.xml
index 30a63050e..4bf40d012 100644
--- a/fineract-investor/src/main/resources/db/changelog/tenant/module/investor/module-changelog-master.xml
+++ b/fineract-investor/src/main/resources/db/changelog/tenant/module/investor/module-changelog-master.xml
@@ -32,4 +32,5 @@
+
diff --git a/fineract-investor/src/main/resources/db/changelog/tenant/module/investor/parts/0010_external_transafer_status_external_transfer_id_constraints.xml b/fineract-investor/src/main/resources/db/changelog/tenant/module/investor/parts/0010_external_transafer_status_external_transfer_id_constraints.xml
index 0bd4fc839..c4ea7dbe3 100644
--- a/fineract-investor/src/main/resources/db/changelog/tenant/module/investor/parts/0010_external_transafer_status_external_transfer_id_constraints.xml
+++ b/fineract-investor/src/main/resources/db/changelog/tenant/module/investor/parts/0010_external_transafer_status_external_transfer_id_constraints.xml
@@ -22,7 +22,7 @@
-
+
diff --git a/fineract-investor/src/main/resources/db/changelog/tenant/module/investor/parts/0011_set_datetime_precision.xml b/fineract-investor/src/main/resources/db/changelog/tenant/module/investor/parts/0011_set_datetime_precision.xml
new file mode 100644
index 000000000..02b188e4e
--- /dev/null
+++ b/fineract-investor/src/main/resources/db/changelog/tenant/module/investor/parts/0011_set_datetime_precision.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
index bc3964152..9c62a71a1 100644
--- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
+++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
@@ -345,7 +345,7 @@ public class Loan extends AbstractAuditableWithUTCDateTimeCustom {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "loan", orphanRemoval = true, fetch = FetchType.LAZY)
private List repaymentScheduleInstallments = new ArrayList<>();
- @OrderBy(value = "dateOf, id")
+ @OrderBy(value = "dateOf, createdDate, id")
@OneToMany(cascade = CascadeType.ALL, mappedBy = "loan", orphanRemoval = true, fetch = FetchType.LAZY)
private List loanTransactions = new ArrayList<>();
diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransaction.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransaction.java
index 1a9835b8c..9a2116c56 100644
--- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransaction.java
+++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransaction.java
@@ -841,7 +841,7 @@ public class LoanTransaction extends AbstractAuditableWithUTCDateTimeCustom {
}
public OffsetDateTime getCreatedDateTime() {
- return (this.getCreatedDate().isPresent() ? this.getCreatedDate().get() : DateUtils.getOffsetDateTimeOfTenant());
+ return (this.getCreatedDate().isPresent() ? this.getCreatedDate().get() : DateUtils.getOffsetDateTimeOfTenantWithMostPrecision());
}
public boolean isLastTransaction(final LoanTransaction loanTransaction) {
diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryRunningBalanceUpdateServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryRunningBalanceUpdateServiceImpl.java
index f890b3a7d..0d7db6d92 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryRunningBalanceUpdateServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryRunningBalanceUpdateServiceImpl.java
@@ -175,7 +175,8 @@ public class JournalEntryRunningBalanceUpdateServiceImpl implements JournalEntry
BigDecimal runningBalance = calculateRunningBalance(entryData, runningBalanceMap);
params.add(new Object[] { Boolean.TRUE, runningBalance, officeRunningBalance,
- platformSecurityContext.authenticatedUser().getId(), DateUtils.getOffsetDateTimeOfTenant(), entryData.getId() });
+ platformSecurityContext.authenticatedUser().getId(), DateUtils.getOffsetDateTimeOfTenantWithMostPrecision(),
+ entryData.getId() });
batchIndex++;
if (batchIndex == batchUpdateSize || index == entryDataList.size() - 1) {
this.jdbcTemplate.batchUpdate(sql, params);
@@ -212,7 +213,7 @@ public class JournalEntryRunningBalanceUpdateServiceImpl implements JournalEntry
for (JournalEntryData entryData : entryDataList) {
BigDecimal runningBalance = calculateRunningBalance(entryData, runningBalanceMap);
params.add(new Object[] { runningBalance, platformSecurityContext.authenticatedUser().getId(),
- DateUtils.getOffsetDateTimeOfTenant(), entryData.getId() });
+ DateUtils.getOffsetDateTimeOfTenantWithMostPrecision(), entryData.getId() });
}
this.jdbcTemplate.batchUpdate(sql, params);
}
diff --git a/fineract-provider/src/main/java/org/apache/fineract/cob/domain/LoanAccountLock.java b/fineract-provider/src/main/java/org/apache/fineract/cob/domain/LoanAccountLock.java
index e1861fbb5..ce151a272 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/cob/domain/LoanAccountLock.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/cob/domain/LoanAccountLock.java
@@ -64,7 +64,7 @@ public class LoanAccountLock {
public LoanAccountLock(Long loanId, LockOwner lockOwner, LocalDate lockPlacedOnCobBusinessDate) {
this.loanId = loanId;
this.lockOwner = lockOwner;
- this.lockPlacedOn = DateUtils.getOffsetDateTimeOfTenant();
+ this.lockPlacedOn = DateUtils.getOffsetDateTimeOfTenantWithMostPrecision();
this.lockPlacedOnCobBusinessDate = lockPlacedOnCobBusinessDate;
}
@@ -75,6 +75,6 @@ public class LoanAccountLock {
public void setNewLockOwner(LockOwner newLockOwner) {
this.lockOwner = newLockOwner;
- this.lockPlacedOn = DateUtils.getOffsetDateTimeOfTenant();
+ this.lockPlacedOn = DateUtils.getOffsetDateTimeOfTenantWithMostPrecision();
}
}
diff --git a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanLockingServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanLockingServiceImpl.java
index c3758b0f5..25c661ac2 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanLockingServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanLockingServiceImpl.java
@@ -67,7 +67,7 @@ public class LoanLockingServiceImpl implements LoanLockingService {
UPDATE m_loan_account_locks SET version= version + 1, lock_owner = ?, lock_placed_on = ? WHERE loan_id = ?
""", accountsToLock, getInClauseParameterSizeLimit(), (ps, id) -> {
ps.setString(1, lockOwner.name());
- ps.setObject(2, DateUtils.getOffsetDateTimeOfTenant());
+ ps.setObject(2, DateUtils.getOffsetDateTimeOfTenantWithMostPrecision());
ps.setLong(3, id);
});
}
@@ -97,7 +97,7 @@ public class LoanLockingServiceImpl implements LoanLockingService {
ps.setLong(1, loanId);
ps.setLong(2, 1);
ps.setString(3, lockOwner.name());
- ps.setObject(4, DateUtils.getOffsetDateTimeOfTenant());
+ ps.setObject(4, DateUtils.getOffsetDateTimeOfTenantWithMostPrecision());
ps.setObject(5, cobBusinessDate);
});
}
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/updatenpa/UpdateNpaTasklet.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/updatenpa/UpdateNpaTasklet.java
index f969abe46..08f22b158 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/updatenpa/UpdateNpaTasklet.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/updatenpa/UpdateNpaTasklet.java
@@ -63,7 +63,7 @@ public class UpdateNpaTasklet implements Tasklet {
resetNPASqlBuilder.append("set is_npa = false").append(", last_modified_by = ?, last_modified_on_utc = ? ").append(" FROM ")
.append(fromPart).append(wherePart);
}
- jdbcTemplate.update(resetNPASqlBuilder.toString(), user.getId(), DateUtils.getOffsetDateTimeOfTenant());
+ jdbcTemplate.update(resetNPASqlBuilder.toString(), user.getId(), DateUtils.getOffsetDateTimeOfTenantWithMostPrecision());
final StringBuilder updateSqlBuilder = new StringBuilder(900);
@@ -82,7 +82,8 @@ public class UpdateNpaTasklet implements Tasklet {
.append(fromPart).append(wherePart);
}
- final int result = jdbcTemplate.update(updateSqlBuilder.toString(), user.getId(), DateUtils.getOffsetDateTimeOfTenant());
+ final int result = jdbcTemplate.update(updateSqlBuilder.toString(), user.getId(),
+ DateUtils.getOffsetDateTimeOfTenantWithMostPrecision());
log.debug("{}: Records affected by updateNPA: {}", ThreadLocalContextUtil.getTenant().getName(), result);
return RepeatStatus.FINISHED;
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleHistoryWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleHistoryWritePlatformServiceImpl.java
index ea75aee9b..9ed49e01e 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleHistoryWritePlatformServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleHistoryWritePlatformServiceImpl.java
@@ -73,7 +73,7 @@ public class LoanScheduleHistoryWritePlatformServiceImpl implements LoanSchedule
final BigDecimal penaltyCharges = repaymentScheduleInstallment.getPenaltyChargesCharged(currency).getAmount();
Map oldDates = null;
- OffsetDateTime createdOnDate = DateUtils.getOffsetDateTimeOfTenant();
+ OffsetDateTime createdOnDate = DateUtils.getOffsetDateTimeOfTenantWithMostPrecision();
LocalDateTime oldCreatedOnDate = null;
LocalDateTime oldLastModifiedOnDate = null;
if (repaymentScheduleInstallment.getCreatedDate().isPresent()) {
@@ -89,7 +89,7 @@ public class LoanScheduleHistoryWritePlatformServiceImpl implements LoanSchedule
final Long lastModifiedByUser = repaymentScheduleInstallment.getLastModifiedBy()
.orElse(platformSecurityContext.authenticatedUser().getId());
- OffsetDateTime lastModifiedOnDate = DateUtils.getOffsetDateTimeOfTenant();
+ OffsetDateTime lastModifiedOnDate = DateUtils.getOffsetDateTimeOfTenantWithMostPrecision();
if (repaymentScheduleInstallment.getLastModifiedDate().isPresent()) {
lastModifiedOnDate = repaymentScheduleInstallment.getLastModifiedDate().get();
} else if (repaymentScheduleInstallment.getId() != null && oldDates == null) {
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java
index 50b2fabf2..e0d48ea3b 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java
@@ -318,7 +318,7 @@ public final class LoanApplicationCommandFromApiJsonHelper {
baseDataValidator.reset().parameter(LoanApiConstants.amortizationTypeParameterName).value(amortizationType).notNull()
.inMinMaxRange(0, 1);
- if (!amortizationType.equals(AmortizationMethod.EQUAL_PRINCIPAL.getValue()) && fixedPrincipalPercentagePerInstallment != null) {
+ if (!AmortizationMethod.EQUAL_PRINCIPAL.getValue().equals(amortizationType) && fixedPrincipalPercentagePerInstallment != null) {
baseDataValidator.reset().parameter(LoanApiConstants.fixedPrincipalPercentagePerInstallmentParamName).failWithCode(
"not.supported.principal.fixing.not.allowed.with.equal.installments",
"Principal fixing cannot be done with equal installment amortization");
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualWritePlatformServiceImpl.java
index 06df20322..c96c5e4cf 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualWritePlatformServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualWritePlatformServiceImpl.java
@@ -271,7 +271,7 @@ public class LoanAccrualWritePlatformServiceImpl implements LoanAccrualWritePlat
this.jdbcTemplate.update(transactionSql, scheduleAccrualData.getLoanId(), scheduleAccrualData.getOfficeId(),
externalIdFactory.create().getValue(), LoanTransactionType.ACCRUAL.getValue(), accruedTill, amount, interestPortion,
feePortion, penaltyPortion, DateUtils.getBusinessLocalDate(), user.getId(), user.getId(),
- DateUtils.getOffsetDateTimeOfTenant(), DateUtils.getOffsetDateTimeOfTenant());
+ DateUtils.getOffsetDateTimeOfTenantWithMostPrecision(), DateUtils.getOffsetDateTimeOfTenantWithMostPrecision());
final Long transactionId = this.jdbcTemplate.queryForObject("SELECT " + sqlGenerator.lastInsertId(), Long.class); // NOSONAR
Map applicableCharges = scheduleAccrualData.getApplicableCharges();
@@ -291,7 +291,7 @@ public class LoanAccrualWritePlatformServiceImpl implements LoanAccrualWritePlat
scheduleAccrualData.getRepaymentScheduleId());
String updateLoan = "UPDATE m_loan SET accrued_till=?, last_modified_by=?, last_modified_on_utc=? WHERE id=?";
- this.jdbcTemplate.update(updateLoan, accruedTill, user.getId(), DateUtils.getOffsetDateTimeOfTenant(),
+ this.jdbcTemplate.update(updateLoan, accruedTill, user.getId(), DateUtils.getOffsetDateTimeOfTenantWithMostPrecision(),
scheduleAccrualData.getLoanId());
Optional loanAccrualTransaction = loanTransactionRepository.findByIdAndLoanId(transactionId,
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java
index ef0b1a2cf..6c0f35c6a 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java
@@ -280,7 +280,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService, Loa
* TODO Vishwas: Remove references to "Contra" from the codebase
***/
final String sql = "select " + rm.loanPaymentsSchema() + " where tr.loan_id = ? and tr.transaction_type_enum not in (0, 3) "
- + " and (tr.is_reversed=false or tr.manually_adjusted_or_reversed = true) order by tr.transaction_date ASC,id ";
+ + " and (tr.is_reversed=false or tr.manually_adjusted_or_reversed = true) order by tr.transaction_date, tr.created_on_utc, tr.id ";
Collection loanTransactionData = this.jdbcTemplate.query(sql, rm, loanId); // NOSONAR
// TODO: would worth to rework in the future. It is not nice to fetch relations one by one... might worth to
// give a try to get rid of native queries
@@ -2140,7 +2140,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService, Loa
final LoanTransactionDerivedComponentMapper rm = new LoanTransactionDerivedComponentMapper(sqlGenerator);
final String sql = "select " + rm.schema()
- + " where tr.loan_id = ? and tr.transaction_type_enum = ? and tr.is_reversed=false order by tr.transaction_date ASC,id ";
+ + " where tr.loan_id = ? and tr.transaction_type_enum = ? and tr.is_reversed=false order by tr.transaction_date, tr.created_on_utc, tr.id ";
return this.jdbcTemplate.query(sql, rm, loanId, LoanTransactionType.WAIVE_INTEREST.getValue()); // NOSONAR
} catch (final EmptyResultDataAccessException e) {
return null;
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java
index 79eb8005c..ae2f6c9b7 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java
@@ -493,8 +493,8 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
AppUser user = context.authenticatedUser();
jdbcTemplate.update(transactionSql, loanId, loan.getOfficeId(), externalIdFactory.create().getValue(),
LoanTransactionType.ACCRUAL.getValue(), actualDisbursementDate, loanCharge.amount(), loanCharge.amount(),
- DateUtils.getBusinessLocalDate(), user.getId(), user.getId(), DateUtils.getOffsetDateTimeOfTenant(),
- DateUtils.getOffsetDateTimeOfTenant());
+ DateUtils.getBusinessLocalDate(), user.getId(), user.getId(),
+ DateUtils.getOffsetDateTimeOfTenantWithMostPrecision(), DateUtils.getOffsetDateTimeOfTenantWithMostPrecision());
}
}
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsSchedularInterestPoster.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsSchedularInterestPoster.java
index 557e9247e..310de4992 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsSchedularInterestPoster.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsSchedularInterestPoster.java
@@ -120,8 +120,8 @@ public class SavingsSchedularInterestPoster {
savingsAccountTransactionData.getId(), null, false, null, false,
savingsAccountTransactionData.getTransactionDate(), JournalEntryType.CREDIT.getValue().longValue(),
savingsAccountTransactionData.getAmount(), null, JournalEntryType.CREDIT.getValue().longValue(),
- savingsAccountData.getId(), DateUtils.getOffsetDateTimeOfTenant(),
- DateUtils.getOffsetDateTimeOfTenant(), false, BigDecimal.ZERO, BigDecimal.ZERO, null,
+ savingsAccountData.getId(), DateUtils.getOffsetDateTimeOfTenantWithMostPrecision(),
+ DateUtils.getOffsetDateTimeOfTenantWithMostPrecision(), false, BigDecimal.ZERO, BigDecimal.ZERO, null,
savingsAccountTransactionData.getTransactionDate(), null, userId, userId,
DateUtils.getBusinessLocalDate() });
@@ -131,8 +131,8 @@ public class SavingsSchedularInterestPoster {
savingsAccountTransactionData.getId(), null, false, null, false,
savingsAccountTransactionData.getTransactionDate(), JournalEntryType.DEBIT.getValue().longValue(),
savingsAccountTransactionData.getAmount(), null, JournalEntryType.DEBIT.getValue().longValue(),
- savingsAccountData.getId(), DateUtils.getOffsetDateTimeOfTenant(),
- DateUtils.getOffsetDateTimeOfTenant(), false, BigDecimal.ZERO, BigDecimal.ZERO, null,
+ savingsAccountData.getId(), DateUtils.getOffsetDateTimeOfTenantWithMostPrecision(),
+ DateUtils.getOffsetDateTimeOfTenantWithMostPrecision(), false, BigDecimal.ZERO, BigDecimal.ZERO, null,
savingsAccountTransactionData.getTransactionDate(), null, userId, userId,
DateUtils.getBusinessLocalDate() });
}
diff --git a/fineract-provider/src/main/resources/db/changelog/tenant-store/changelog-tenant-store.xml b/fineract-provider/src/main/resources/db/changelog/tenant-store/changelog-tenant-store.xml
index e0efb45cf..de38521da 100644
--- a/fineract-provider/src/main/resources/db/changelog/tenant-store/changelog-tenant-store.xml
+++ b/fineract-provider/src/main/resources/db/changelog/tenant-store/changelog-tenant-store.xml
@@ -30,4 +30,5 @@
+
diff --git a/fineract-provider/src/main/resources/db/changelog/tenant-store/parts/0010_set_datetime_precision.xml b/fineract-provider/src/main/resources/db/changelog/tenant-store/parts/0010_set_datetime_precision.xml
new file mode 100644
index 000000000..ce4955221
--- /dev/null
+++ b/fineract-provider/src/main/resources/db/changelog/tenant-store/parts/0010_set_datetime_precision.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml b/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml
index 0578e15a4..d8a9f8a1b 100644
--- a/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml
+++ b/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml
@@ -136,4 +136,5 @@
+
diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0117_set_datetime_precision.xml b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0117_set_datetime_precision.xml
new file mode 100644
index 000000000..75f961b0d
--- /dev/null
+++ b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0117_set_datetime_precision.xml
@@ -0,0 +1,152 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientLoanIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientLoanIntegrationTest.java
index b4980aa8a..77c2ece77 100644
--- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientLoanIntegrationTest.java
+++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientLoanIntegrationTest.java
@@ -44,6 +44,7 @@ import java.time.format.DateTimeFormatterBuilder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
+import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -53,6 +54,7 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.apache.fineract.accounting.glaccount.domain.GLAccountType;
+import org.apache.fineract.client.models.AllowAttributeOverrides;
import org.apache.fineract.client.models.BusinessDateRequest;
import org.apache.fineract.client.models.GetJournalEntriesTransactionIdResponse;
import org.apache.fineract.client.models.GetLoanTransactionRelation;
@@ -65,15 +67,23 @@ import org.apache.fineract.client.models.GetLoansLoanIdTransactionsTransactionId
import org.apache.fineract.client.models.JournalEntryTransactionItem;
import org.apache.fineract.client.models.PostChargesRequest;
import org.apache.fineract.client.models.PostChargesResponse;
+import org.apache.fineract.client.models.PostClientsRequest;
import org.apache.fineract.client.models.PostClientsResponse;
import org.apache.fineract.client.models.PostGLAccountsRequest;
import org.apache.fineract.client.models.PostGLAccountsResponse;
+import org.apache.fineract.client.models.PostLoanProductsRequest;
+import org.apache.fineract.client.models.PostLoanProductsResponse;
import org.apache.fineract.client.models.PostLoansLoanIdChargesChargeIdRequest;
import org.apache.fineract.client.models.PostLoansLoanIdChargesChargeIdResponse;
+import org.apache.fineract.client.models.PostLoansLoanIdChargesRequest;
+import org.apache.fineract.client.models.PostLoansLoanIdChargesResponse;
import org.apache.fineract.client.models.PostLoansLoanIdRequest;
+import org.apache.fineract.client.models.PostLoansLoanIdResponse;
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsRequest;
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsResponse;
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsTransactionIdRequest;
+import org.apache.fineract.client.models.PostLoansRequest;
+import org.apache.fineract.client.models.PostLoansResponse;
import org.apache.fineract.client.models.PutChargeTransactionChangesRequest;
import org.apache.fineract.client.util.CallFailedRuntimeException;
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
@@ -90,6 +100,7 @@ import org.apache.fineract.integrationtests.common.accounting.JournalEntryHelper
import org.apache.fineract.integrationtests.common.accounting.PeriodicAccrualAccountingHelper;
import org.apache.fineract.integrationtests.common.charges.ChargesHelper;
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
+import org.apache.fineract.integrationtests.common.loans.LoanProductHelper;
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
import org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension;
@@ -103,7 +114,6 @@ import org.apache.fineract.portfolio.charge.domain.ChargeCalculationType;
import org.apache.fineract.portfolio.charge.domain.ChargePaymentMode;
import org.apache.fineract.portfolio.charge.domain.ChargeTimeType;
import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.commons.util.StringUtils;
@@ -118,149 +128,163 @@ import org.slf4j.LoggerFactory;
@ExtendWith(LoanTestLifecycleExtension.class)
public class ClientLoanIntegrationTest {
- public static final String MINIMUM_OPENING_BALANCE = "1000.0";
- public static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";
+ private static final String MINIMUM_OPENING_BALANCE = "1000.0";
+ private static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";
private static final Logger LOG = LoggerFactory.getLogger(ClientLoanIntegrationTest.class);
private static final String NONE = "1";
private static final String CASH_BASED = "2";
private static final String ACCRUAL_PERIODIC = "3";
private static final String ACCRUAL_UPFRONT = "4";
- private ResponseSpecification responseSpec;
- private RequestSpecification requestSpec;
- private LoanTransactionHelper loanTransactionHelper;
- private JournalEntryHelper journalEntryHelper;
- private AccountHelper accountHelper;
- private SchedulerJobHelper schedulerJobHelper;
- private PeriodicAccrualAccountingHelper periodicAccrualAccountingHelper;
- private SavingsAccountHelper savingsAccountHelper;
- private AccountTransferHelper accountTransferHelper;
+ private static final ResponseSpecification RESPONSE_SPEC = createResponseSpecification(200);
+ private static final RequestSpecification REQUEST_SPEC = createRequestSpecification();
+ private static final LoanTransactionHelper LOAN_TRANSACTION_HELPER = new LoanTransactionHelper(REQUEST_SPEC, RESPONSE_SPEC);
+ private static final JournalEntryHelper JOURNAL_ENTRY_HELPER = new JournalEntryHelper(REQUEST_SPEC, RESPONSE_SPEC);
+ private static final AccountHelper ACCOUNT_HELPER = new AccountHelper(REQUEST_SPEC, RESPONSE_SPEC);
+ // asset
+ private static final Account LOANS_RECEIVABLE_ACCOUNT = ACCOUNT_HELPER.createAssetAccount();
+ private static final Account INTEREST_FEE_RECEIVABLE_ACCOUNT = ACCOUNT_HELPER.createAssetAccount();
+ private static final Account SUSPENSE_ACCOUNT = ACCOUNT_HELPER.createAssetAccount();
+ // liability
+ private static final Account SUSPENSE_CLEARING_ACCOUNT = ACCOUNT_HELPER.createLiabilityAccount();
+ private static final Account OVERPAYMENT_ACCOUNT = ACCOUNT_HELPER.createLiabilityAccount();
+ // income
+ private static final Account INTEREST_INCOME_ACCOUNT = ACCOUNT_HELPER.createIncomeAccount();
+ private static final Account FEE_INCOME_ACCOUNT = ACCOUNT_HELPER.createIncomeAccount();
+ private static final Account FEE_CHARGE_OFF_ACCOUNT = ACCOUNT_HELPER.createIncomeAccount();
+ private static final Account RECOVERIES_ACCOUNT = ACCOUNT_HELPER.createIncomeAccount();
+ private static final Account INTEREST_INCOME_CHARGE_OFF_ACCOUNT = ACCOUNT_HELPER.createIncomeAccount();
+ // expense
+ private static final Account CREDIT_LOSS_BAD_DEBT_ACCOUNT = ACCOUNT_HELPER.createExpenseAccount();
+ private static final Account CREDIT_LOSS_BAD_DEBT_FRAUD_ACCOUNT = ACCOUNT_HELPER.createExpenseAccount();
+ private static final Account WRITTEN_OFF_ACCOUNT = ACCOUNT_HELPER.createExpenseAccount();
+ private static final Account GOODWILL_EXPENSE_ACCOUNT = ACCOUNT_HELPER.createExpenseAccount();
+ private static final SchedulerJobHelper SCHEDULER_JOB_HELPER = new SchedulerJobHelper(REQUEST_SPEC);
+ private static final PeriodicAccrualAccountingHelper PERIODIC_ACCRUAL_ACCOUNTING_HELPER = new PeriodicAccrualAccountingHelper(
+ REQUEST_SPEC, RESPONSE_SPEC);
+ private static final SavingsAccountHelper SAVINGS_ACCOUNT_HELPER = new SavingsAccountHelper(REQUEST_SPEC, RESPONSE_SPEC);
+ private static final AccountTransferHelper ACCOUNT_TRANSFER_HELPER = new AccountTransferHelper(REQUEST_SPEC, RESPONSE_SPEC);
+ private static final LoanProductHelper LOAN_PRODUCT_HELPER = new LoanProductHelper();
+ private static final String DATETIME_PATTERN = "dd MMMM yyyy";
+ private static final DateTimeFormatter DATE_TIME_FORMATTER = new DateTimeFormatterBuilder().appendPattern(DATETIME_PATTERN)
+ .toFormatter();
+ private static final BusinessDateHelper BUSINESS_DATE_HELPER = new BusinessDateHelper();
+ private static final ChargesHelper CHARGES_HELPER = new ChargesHelper();
+ private static final ClientHelper CLIENT_HELPER = new ClientHelper(REQUEST_SPEC, RESPONSE_SPEC);
- private DateTimeFormatter dateFormatter = new DateTimeFormatterBuilder().appendPattern("dd MMMM yyyy").toFormatter();
- private BusinessDateHelper businessDateHelper;
- private ChargesHelper chargesHelper;
- private ClientHelper clientHelper;
-
- @BeforeEach
- public void setup() {
+ static {
Utils.initializeRESTAssured();
- this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
- this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
- this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
- this.requestSpec.header("Fineract-Platform-TenantId", "default");
- this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
- this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec);
- this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec);
- this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
- this.periodicAccrualAccountingHelper = new PeriodicAccrualAccountingHelper(this.requestSpec, this.responseSpec);
- this.journalEntryHelper = new JournalEntryHelper(this.requestSpec, this.responseSpec);
- this.businessDateHelper = new BusinessDateHelper();
- this.chargesHelper = new ChargesHelper();
- this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
+ }
+
+ private static RequestSpecification createRequestSpecification() {
+ RequestSpecification request = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
+
+ request.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
+ request.header("Fineract-Platform-TenantId", "default");
+ return request;
+ }
+
+ private static ResponseSpecification createResponseSpecification(int statusCode) {
+ return new ResponseSpecBuilder().expectStatusCode(statusCode).build();
}
@Test
public void checkClientLoanCreateAndDisburseFlow() {
- this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
- final Integer collateralId = CollateralManagementHelper.createCollateralProduct(this.requestSpec, this.responseSpec);
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
List collaterals = new ArrayList<>();
- final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
- ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
- final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(this.requestSpec, this.responseSpec,
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
String.valueOf(clientID), collateralId);
addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
final Integer loanProductID = createLoanProduct(false, NONE);
final Integer loanID = applyForLoanApplication(clientID, loanProductID, null, null, "12,000.00", collaterals);
- final ArrayList loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec,
- loanID);
+ final ArrayList loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
verifyLoanRepaymentSchedule(loanSchedule);
}
@Test
public void validateClientLoanWithUniqueExternalId() {
// Given
- this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
final ResponseSpecification responseSpec403 = new ResponseSpecBuilder().expectStatusCode(403).build();
- final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
final Integer loanProductID = createLoanProduct(false, NONE);
final String externalId = UUID.randomUUID().toString();
// When
- final Integer loanID = applyForLoanApplicationWithExternalId(this.requestSpec, this.responseSpec, clientID, loanProductID,
- "12,000.00", externalId);
+ final Integer loanID = applyForLoanApplicationWithExternalId(REQUEST_SPEC, RESPONSE_SPEC, clientID, loanProductID, "12,000.00",
+ externalId);
// Then
assertNotNull(loanID);
- applyForLoanApplicationWithExternalId(this.requestSpec, responseSpec403, clientID, loanProductID, "12,000.00", externalId);
+ applyForLoanApplicationWithExternalId(REQUEST_SPEC, responseSpec403, clientID, loanProductID, "12,000.00", externalId);
}
@Test
public void testAddingLoanChargeIncludesLoanIdInTheResponse() {
// given
- loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
- Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
+ Integer clientId = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
Integer loanProductId = createLoanProduct(false, NONE);
- Integer collateralId = CollateralManagementHelper.createCollateralProduct(this.requestSpec, this.responseSpec);
- Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(this.requestSpec, this.responseSpec,
+ Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
+ Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
String.valueOf(clientId), collateralId);
List collaterals = List.of(collaterals(clientCollateralId, BigDecimal.ONE));
- Integer chargeId = ChargesHelper.createCharges(requestSpec, responseSpec,
+ Integer chargeId = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
ChargesHelper.getLoanDisbursementJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1"));
List charges = List.of(charges(chargeId, "1", null));
// when
Integer loanId = applyForLoanApplication(clientId, loanProductId, charges, null, "12,000.00", collaterals);
// then
- List loanCharges = loanTransactionHelper.getLoanCharges(loanId);
+ List loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanId);
Integer loanChargeId = (Integer) loanCharges.get(0).get("id");
- HashMap loanChargeDetail = loanTransactionHelper.getLoanCharge(loanId, loanChargeId);
+ HashMap loanChargeDetail = LOAN_TRANSACTION_HELPER.getLoanCharge(loanId, loanChargeId);
assertEquals(loanId, loanChargeDetail.get("loanId"));
}
@Test
public void testLoanCharges_DISBURSEMENT_FEE() {
- this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
- final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
- ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID);
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
final Integer loanProductID = createLoanProduct(false, NONE);
- final Integer collateralId = CollateralManagementHelper.createCollateralProduct(this.requestSpec, this.responseSpec);
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
Assertions.assertNotNull(collateralId);
List collaterals = new ArrayList<>();
- final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(this.requestSpec, this.responseSpec,
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
String.valueOf(clientID), collateralId);
Assertions.assertNotNull(clientCollateralId);
addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
List charges = new ArrayList<>();
- Integer flatDisbursement = ChargesHelper.createCharges(requestSpec, responseSpec, ChargesHelper.getLoanDisbursementJSON());
+ Integer flatDisbursement = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC, ChargesHelper.getLoanDisbursementJSON());
- Integer amountPercentage = ChargesHelper.createCharges(requestSpec, responseSpec,
+ Integer amountPercentage = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
ChargesHelper.getLoanDisbursementJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1"));
addCharges(charges, amountPercentage, "1", null);
- Integer amountPlusInterestPercentage = ChargesHelper.createCharges(requestSpec, responseSpec,
+ Integer amountPlusInterestPercentage = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
ChargesHelper.getLoanDisbursementJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST, "1"));
addCharges(charges, amountPlusInterestPercentage, "1", null);
- Integer interestPercentage = ChargesHelper.createCharges(requestSpec, responseSpec,
+ Integer interestPercentage = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
ChargesHelper.getLoanDisbursementJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_INTEREST, "1"));
addCharges(charges, interestPercentage, "1", null);
final Integer loanID = applyForLoanApplication(clientID, loanProductID, charges, null, "12,000.00", collaterals);
Assertions.assertNotNull(loanID);
- HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
- ArrayList loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ ArrayList loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
HashMap disbursementDetail = loanSchedule.get(0);
- List loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
+ List loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
validateCharge(amountPercentage, loanCharges, "1.0", "120.0", "0.0", "0.0");
validateCharge(interestPercentage, loanCharges, "1.0", "6.06", "0.0", "0.0");
@@ -268,27 +292,26 @@ public class ClientLoanIntegrationTest {
validateNumberForEqual("252.12", String.valueOf(disbursementDetail.get("feeChargesDue")));
- this.loanTransactionHelper.addChargesForLoan(loanID,
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID,
LoanTransactionHelper.getDisbursementChargesForLoanAsJSON(String.valueOf(flatDisbursement)));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
disbursementDetail = loanSchedule.get(0);
validateCharge(flatDisbursement, loanCharges, "100.0", "100.0", "0.0", "0.0");
validateNumberForEqual("352.12", String.valueOf(disbursementDetail.get("feeChargesDue")));
- this.loanTransactionHelper.updateChargesForLoan(loanID, (Integer) getloanCharge(amountPercentage, loanCharges).get("id"),
+ LOAN_TRANSACTION_HELPER.updateChargesForLoan(loanID, (Integer) getloanCharge(amountPercentage, loanCharges).get("id"),
LoanTransactionHelper.getUpdateChargesForLoanAsJSON("2"));
- this.loanTransactionHelper.updateChargesForLoan(loanID, (Integer) getloanCharge(interestPercentage, loanCharges).get("id"),
+ LOAN_TRANSACTION_HELPER.updateChargesForLoan(loanID, (Integer) getloanCharge(interestPercentage, loanCharges).get("id"),
LoanTransactionHelper.getUpdateChargesForLoanAsJSON("2"));
- this.loanTransactionHelper.updateChargesForLoan(loanID,
- (Integer) getloanCharge(amountPlusInterestPercentage, loanCharges).get("id"),
+ LOAN_TRANSACTION_HELPER.updateChargesForLoan(loanID, (Integer) getloanCharge(amountPlusInterestPercentage, loanCharges).get("id"),
LoanTransactionHelper.getUpdateChargesForLoanAsJSON("2"));
- this.loanTransactionHelper.updateChargesForLoan(loanID, (Integer) getloanCharge(flatDisbursement, loanCharges).get("id"),
+ LOAN_TRANSACTION_HELPER.updateChargesForLoan(loanID, (Integer) getloanCharge(flatDisbursement, loanCharges).get("id"),
LoanTransactionHelper.getUpdateChargesForLoanAsJSON("150"));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
disbursementDetail = loanSchedule.get(0);
validateCharge(amountPercentage, loanCharges, "2.0", "240.0", "0.0", "0.0");
validateCharge(interestPercentage, loanCharges, "2.0", "12.12", "0.0", "0.0");
@@ -296,11 +319,11 @@ public class ClientLoanIntegrationTest {
validateCharge(flatDisbursement, loanCharges, "150.0", "150.0", "0.0", "0.0");
validateNumberForEqual("654.24", String.valueOf(disbursementDetail.get("feeChargesDue")));
- this.loanTransactionHelper.updateLoan(loanID,
+ LOAN_TRANSACTION_HELPER.updateLoan(loanID,
updateLoanJson(clientID, loanProductID, copyChargesForUpdate(loanCharges, null, null), null, collaterals));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
disbursementDetail = loanSchedule.get(0);
validateCharge(amountPercentage, loanCharges, "2.0", "200.0", "0.0", "0.0");
validateCharge(interestPercentage, loanCharges, "2.0", "10.1", "0.0", "0.0");
@@ -308,11 +331,11 @@ public class ClientLoanIntegrationTest {
validateCharge(flatDisbursement, loanCharges, "150.0", "150.0", "0.0", "0.0");
validateNumberForEqual("570.2", String.valueOf(disbursementDetail.get("feeChargesDue")));
- this.loanTransactionHelper.updateLoan(loanID,
+ LOAN_TRANSACTION_HELPER.updateLoan(loanID,
updateLoanJson(clientID, loanProductID, copyChargesForUpdate(loanCharges, flatDisbursement, "1"), null, collaterals));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
disbursementDetail = loanSchedule.get(0);
validateCharge(amountPercentage, loanCharges, "1.0", "100.0", "0.0", "0.0");
validateCharge(interestPercentage, loanCharges, "1.0", "5.05", "0.0", "0.0");
@@ -321,17 +344,17 @@ public class ClientLoanIntegrationTest {
charges.clear();
addCharges(charges, flatDisbursement, "100", null);
- this.loanTransactionHelper.updateLoan(loanID, updateLoanJson(clientID, loanProductID, charges, null, collaterals));
+ LOAN_TRANSACTION_HELPER.updateLoan(loanID, updateLoanJson(clientID, loanProductID, charges, null, collaterals));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
disbursementDetail = loanSchedule.get(0);
validateCharge(flatDisbursement, loanCharges, "100.0", "100.0", "0.0", "0.0");
validateNumberForEqual("100.0", String.valueOf(disbursementDetail.get("feeChargesDue")));
- this.loanTransactionHelper.deleteChargesForLoan(loanID, (Integer) getloanCharge(flatDisbursement, loanCharges).get("id"));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ LOAN_TRANSACTION_HELPER.deleteChargesForLoan(loanID, (Integer) getloanCharge(flatDisbursement, loanCharges).get("id"));
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
disbursementDetail = loanSchedule.get(0);
Assertions.assertEquals(0, loanCharges.size());
validateNumberForEqual("0.0", String.valueOf(disbursementDetail.get("feeChargesDue")));
@@ -340,28 +363,27 @@ public class ClientLoanIntegrationTest {
@Test
public void testLoanCharges_DISBURSEMENT_FEE_WITH_AMOUNT_CHANGE() {
- this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
- final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
- ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID);
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
final Integer loanProductID = createLoanProduct(false, NONE);
List charges = new ArrayList<>();
- Integer amountPercentage = ChargesHelper.createCharges(requestSpec, responseSpec,
+ Integer amountPercentage = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
ChargesHelper.getLoanDisbursementJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1"));
addCharges(charges, amountPercentage, "1", null);
- Integer amountPlusInterestPercentage = ChargesHelper.createCharges(requestSpec, responseSpec,
+ Integer amountPlusInterestPercentage = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
ChargesHelper.getLoanDisbursementJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST, "1"));
addCharges(charges, amountPlusInterestPercentage, "1", null);
- Integer interestPercentage = ChargesHelper.createCharges(requestSpec, responseSpec,
+ Integer interestPercentage = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
ChargesHelper.getLoanDisbursementJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_INTEREST, "1"));
addCharges(charges, interestPercentage, "1", null);
List collaterals = new ArrayList<>();
- final Integer collateralId = CollateralManagementHelper.createCollateralProduct(this.requestSpec, this.responseSpec);
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
Assertions.assertNotNull(collateralId);
- final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(this.requestSpec, this.responseSpec,
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
String.valueOf(clientID), collateralId);
Assertions.assertNotNull(clientCollateralId);
addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
@@ -369,13 +391,13 @@ public class ClientLoanIntegrationTest {
final Integer loanID = applyForLoanApplication(clientID, loanProductID, charges, null, "12,000.00", collaterals);
Assertions.assertNotNull(loanID);
- HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
- ArrayList loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ ArrayList loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
HashMap disbursementDetail = loanSchedule.get(0);
- List loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
+ List loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
validateCharge(amountPercentage, loanCharges, "1.0", "120.0", "0.0", "0.0");
validateCharge(interestPercentage, loanCharges, "1.0", "6.06", "0.0", "0.0");
@@ -383,19 +405,19 @@ public class ClientLoanIntegrationTest {
validateNumberForEqual("252.12", String.valueOf(disbursementDetail.get("feeChargesDue")));
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
- loanStatusHashMap = this.loanTransactionHelper.approveLoan("20 September 2011", loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.approveLoan("20 September 2011", loanID);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
// DISBURSE
- String loanDetails = this.loanTransactionHelper.getLoanDetails(this.requestSpec, this.responseSpec, loanID);
- loanStatusHashMap = this.loanTransactionHelper.disburseLoanWithNetDisbursalAmount("20 September 2011", loanID, "10000",
+ String loanDetails = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanWithNetDisbursalAmount("20 September 2011", loanID, "10000",
JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
LOG.info("DISBURSE {}", loanStatusHashMap.toString());
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
disbursementDetail = loanSchedule.get(0);
validateCharge(amountPercentage, loanCharges, "1.0", "0.0", "100.0", "0.0");
@@ -407,34 +429,33 @@ public class ClientLoanIntegrationTest {
@Test
public void testLoanDisbursedTodayIsRetrieved() {
- this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
- final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
- ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID);
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
final Integer loanProductID = createLoanProduct(false, NONE);
final Integer loanID = applyForLoanApplication(clientID, loanProductID, "5", null);
Assertions.assertNotNull(loanID);
- HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
- DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
+ DateFormat dateFormat = new SimpleDateFormat(DATETIME_PATTERN, Locale.US);
Calendar todaysDate = Calendar.getInstance(Utils.getTimeZoneOfTenant());
final String LOAN_DISBURSEMENT_DATE = dateFormat.format(todaysDate.getTime());
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
- loanStatusHashMap = this.loanTransactionHelper.approveLoan(LOAN_DISBURSEMENT_DATE, loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.approveLoan(LOAN_DISBURSEMENT_DATE, loanID);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
// DISBURSE on todays date so that loan can't be in arrears
- String loanDetails = this.loanTransactionHelper.getLoanDetails(this.requestSpec, this.responseSpec, loanID);
- loanStatusHashMap = this.loanTransactionHelper.disburseLoanWithNetDisbursalAmount(LOAN_DISBURSEMENT_DATE, loanID, "10000",
+ String loanDetails = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanWithNetDisbursalAmount(LOAN_DISBURSEMENT_DATE, loanID, "10000",
JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
LOG.info("DISBURSE {}", loanStatusHashMap.toString());
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
- loanDetails = this.loanTransactionHelper.getLoanDetails(this.requestSpec, this.responseSpec, loanID);
+ loanDetails = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
// Test added because loans created without arrears were failing to be retrieved (associations=all) due to inner
// join on m_loan_arrears_aging (now left join)
Assertions.assertNotNull(loanDetails, "Empty Loan Details");
@@ -444,33 +465,32 @@ public class ClientLoanIntegrationTest {
@Test
public void testLoanCharges_SPECIFIED_DUE_DATE_FEE() {
- this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
- final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
- ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID);
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
final Integer loanProductID = createLoanProduct(false, NONE);
List charges = new ArrayList<>();
- Integer flat = ChargesHelper.createCharges(requestSpec, responseSpec,
+ Integer flat = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, "100", false));
- Integer flatAccTransfer = ChargesHelper.createCharges(requestSpec, responseSpec,
+ Integer flatAccTransfer = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
ChargesHelper.getLoanSpecifiedDueDateWithAccountTransferJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, "100", false));
- Integer amountPercentage = ChargesHelper.createCharges(requestSpec, responseSpec,
+ Integer amountPercentage = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1", false));
addCharges(charges, amountPercentage, "1", "29 September 2011");
- Integer amountPlusInterestPercentage = ChargesHelper.createCharges(requestSpec, responseSpec, ChargesHelper
+ Integer amountPlusInterestPercentage = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC, ChargesHelper
.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST, "1", false));
addCharges(charges, amountPlusInterestPercentage, "1", "29 September 2011");
- Integer interestPercentage = ChargesHelper.createCharges(requestSpec, responseSpec,
+ Integer interestPercentage = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_INTEREST, "1", false));
addCharges(charges, interestPercentage, "1", "29 September 2011");
List collaterals = new ArrayList<>();
- final Integer collateralId = CollateralManagementHelper.createCollateralProduct(this.requestSpec, this.responseSpec);
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
Assertions.assertNotNull(collateralId);
- final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(this.requestSpec, this.responseSpec,
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
clientID.toString(), collateralId);
Assertions.assertNotNull(clientCollateralId);
addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
@@ -478,13 +498,13 @@ public class ClientLoanIntegrationTest {
final Integer loanID = applyForLoanApplication(clientID, loanProductID, charges, null, "12,000.00", collaterals);
Assertions.assertNotNull(loanID);
- HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
- ArrayList loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ ArrayList loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
HashMap firstInstallment = loanSchedule.get(1);
- List loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
+ List loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
validateCharge(amountPercentage, loanCharges, "1.0", "120.0", "0.0", "0.0");
validateCharge(interestPercentage, loanCharges, "1.0", "6.06", "0.0", "0.0");
@@ -492,27 +512,26 @@ public class ClientLoanIntegrationTest {
validateNumberForEqual("252.12", String.valueOf(firstInstallment.get("feeChargesDue")));
- this.loanTransactionHelper.addChargesForLoan(loanID,
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID,
LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(flat), "29 September 2011", "100"));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
firstInstallment = loanSchedule.get(1);
validateCharge(flat, loanCharges, "100.0", "100.0", "0.0", "0.0");
validateNumberForEqual("352.12", String.valueOf(firstInstallment.get("feeChargesDue")));
- this.loanTransactionHelper.updateChargesForLoan(loanID, (Integer) getloanCharge(amountPercentage, loanCharges).get("id"),
+ LOAN_TRANSACTION_HELPER.updateChargesForLoan(loanID, (Integer) getloanCharge(amountPercentage, loanCharges).get("id"),
LoanTransactionHelper.getUpdateChargesForLoanAsJSON("2"));
- this.loanTransactionHelper.updateChargesForLoan(loanID, (Integer) getloanCharge(interestPercentage, loanCharges).get("id"),
+ LOAN_TRANSACTION_HELPER.updateChargesForLoan(loanID, (Integer) getloanCharge(interestPercentage, loanCharges).get("id"),
LoanTransactionHelper.getUpdateChargesForLoanAsJSON("2"));
- this.loanTransactionHelper.updateChargesForLoan(loanID,
- (Integer) getloanCharge(amountPlusInterestPercentage, loanCharges).get("id"),
+ LOAN_TRANSACTION_HELPER.updateChargesForLoan(loanID, (Integer) getloanCharge(amountPlusInterestPercentage, loanCharges).get("id"),
LoanTransactionHelper.getUpdateChargesForLoanAsJSON("2"));
- this.loanTransactionHelper.updateChargesForLoan(loanID, (Integer) getloanCharge(flat, loanCharges).get("id"),
+ LOAN_TRANSACTION_HELPER.updateChargesForLoan(loanID, (Integer) getloanCharge(flat, loanCharges).get("id"),
LoanTransactionHelper.getUpdateChargesForLoanAsJSON("150"));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
firstInstallment = loanSchedule.get(1);
validateCharge(amountPercentage, loanCharges, "2.0", "240.0", "0.0", "0.0");
validateCharge(interestPercentage, loanCharges, "2.0", "12.12", "0.0", "0.0");
@@ -520,13 +539,12 @@ public class ClientLoanIntegrationTest {
validateCharge(flat, loanCharges, "150.0", "150.0", "0.0", "0.0");
validateNumberForEqual("654.24", String.valueOf(firstInstallment.get("feeChargesDue")));
- final Integer savingsId = SavingsAccountHelper.openSavingsAccount(this.requestSpec, this.responseSpec, clientID,
- MINIMUM_OPENING_BALANCE);
- this.loanTransactionHelper.updateLoan(loanID, updateLoanJson(clientID, loanProductID, copyChargesForUpdate(loanCharges, null, null),
+ final Integer savingsId = SavingsAccountHelper.openSavingsAccount(REQUEST_SPEC, RESPONSE_SPEC, clientID, MINIMUM_OPENING_BALANCE);
+ LOAN_TRANSACTION_HELPER.updateLoan(loanID, updateLoanJson(clientID, loanProductID, copyChargesForUpdate(loanCharges, null, null),
String.valueOf(savingsId), collaterals));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
firstInstallment = loanSchedule.get(1);
validateCharge(amountPercentage, loanCharges, "2.0", "200.0", "0.0", "0.0");
validateCharge(interestPercentage, loanCharges, "2.0", "10.1", "0.0", "0.0");
@@ -534,11 +552,11 @@ public class ClientLoanIntegrationTest {
validateCharge(flat, loanCharges, "150.0", "150.0", "0.0", "0.0");
validateNumberForEqual("570.2", String.valueOf(firstInstallment.get("feeChargesDue")));
- this.loanTransactionHelper.updateLoan(loanID,
+ LOAN_TRANSACTION_HELPER.updateLoan(loanID,
updateLoanJson(clientID, loanProductID, copyChargesForUpdate(loanCharges, flat, "1"), null, collaterals));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
firstInstallment = loanSchedule.get(1);
validateCharge(amountPercentage, loanCharges, "1.0", "100.0", "0.0", "0.0");
validateCharge(interestPercentage, loanCharges, "1.0", "5.05", "0.0", "0.0");
@@ -547,53 +565,53 @@ public class ClientLoanIntegrationTest {
charges.clear();
addCharges(charges, flat, "100", "29 September 2011");
- this.loanTransactionHelper.updateLoan(loanID, updateLoanJson(clientID, loanProductID, charges, null, collaterals));
+ LOAN_TRANSACTION_HELPER.updateLoan(loanID, updateLoanJson(clientID, loanProductID, charges, null, collaterals));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
firstInstallment = loanSchedule.get(1);
validateCharge(flat, loanCharges, "100.0", "100.0", "0.0", "0.0");
validateNumberForEqual("100.0", String.valueOf(firstInstallment.get("feeChargesDue")));
- this.loanTransactionHelper.deleteChargesForLoan(loanID, (Integer) getloanCharge(flat, loanCharges).get("id"));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ LOAN_TRANSACTION_HELPER.deleteChargesForLoan(loanID, (Integer) getloanCharge(flat, loanCharges).get("id"));
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
firstInstallment = loanSchedule.get(1);
Assertions.assertEquals(0, loanCharges.size());
validateNumberForEqual("0", String.valueOf(firstInstallment.get("feeChargesDue")));
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
- loanStatusHashMap = this.loanTransactionHelper.approveLoan("20 September 2011", loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.approveLoan("20 September 2011", loanID);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
- this.loanTransactionHelper.addChargesForLoan(loanID,
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID,
LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(flatAccTransfer), "29 September 2011", "100"));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
firstInstallment = loanSchedule.get(1);
validateCharge(flatAccTransfer, loanCharges, "100.0", "100.0", "0.0", "0.0");
validateNumberForEqual("100.0", String.valueOf(firstInstallment.get("feeChargesDue")));
// DISBURSE
- String loanDetails = this.loanTransactionHelper.getLoanDetails(this.requestSpec, this.responseSpec, loanID);
- loanStatusHashMap = this.loanTransactionHelper.disburseLoanWithNetDisbursalAmount("20 September 2011", loanID, "10000",
+ String loanDetails = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanWithNetDisbursalAmount("20 September 2011", loanID, "10000",
JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
LOG.info("DISBURSE {}", loanStatusHashMap.toString());
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
- this.loanTransactionHelper.addChargesForLoan(loanID,
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID,
LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(amountPercentage), "29 September 2011", "1"));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
firstInstallment = loanSchedule.get(1);
validateCharge(amountPercentage, loanCharges, "1.0", "100.0", "0.0", "0.0");
validateCharge(flatAccTransfer, loanCharges, "100.0", "100.0", "0.0", "0.0");
validateNumberForEqual("200.0", String.valueOf(firstInstallment.get("feeChargesDue")));
- this.loanTransactionHelper.waiveChargesForLoan(loanID, (Integer) getloanCharge(amountPercentage, loanCharges).get("id"), "");
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ LOAN_TRANSACTION_HELPER.waiveChargesForLoan(loanID, (Integer) getloanCharge(amountPercentage, loanCharges).get("id"), "");
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
firstInstallment = loanSchedule.get(1);
validateCharge(amountPercentage, loanCharges, "1.0", "0.0", "0.0", "100.0");
validateCharge(flatAccTransfer, loanCharges, "100.0", "100.0", "0.0", "0.0");
@@ -601,10 +619,10 @@ public class ClientLoanIntegrationTest {
validateNumberForEqual("100.0", String.valueOf(firstInstallment.get("feeChargesOutstanding")));
validateNumberForEqual("100.0", String.valueOf(firstInstallment.get("feeChargesWaived")));
- this.loanTransactionHelper.payChargesForLoan(loanID, (Integer) getloanCharge(flatAccTransfer, loanCharges).get("id"),
+ LOAN_TRANSACTION_HELPER.payChargesForLoan(loanID, (Integer) getloanCharge(flatAccTransfer, loanCharges).get("id"),
LoanTransactionHelper.getPayChargeJSON(SavingsAccountHelper.TRANSACTION_DATE, null));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
firstInstallment = loanSchedule.get(1);
validateCharge(amountPercentage, loanCharges, "1.0", "0.0", "0.0", "100.0");
validateCharge(flatAccTransfer, loanCharges, "100.0", "0.0", "100.0", "0.0");
@@ -616,44 +634,43 @@ public class ClientLoanIntegrationTest {
@Test
public void testLoanCharges_INSTALMENT_FEE() {
- this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
- final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
- ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID);
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
final Integer loanProductID = createLoanProduct(false, NONE);
List charges = new ArrayList<>();
- Integer flat = ChargesHelper.createCharges(requestSpec, responseSpec,
+ Integer flat = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
ChargesHelper.getLoanInstallmentJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, "50", false));
- Integer flatAccTransfer = ChargesHelper.createCharges(requestSpec, responseSpec,
+ Integer flatAccTransfer = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
ChargesHelper.getLoanInstallmentWithAccountTransferJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, "50", false));
- Integer amountPercentage = ChargesHelper.createCharges(requestSpec, responseSpec,
+ Integer amountPercentage = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
ChargesHelper.getLoanInstallmentJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1", false));
addCharges(charges, amountPercentage, "1", "29 September 2011");
- Integer amountPlusInterestPercentage = ChargesHelper.createCharges(requestSpec, responseSpec,
+ Integer amountPlusInterestPercentage = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
ChargesHelper.getLoanInstallmentJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST, "1", false));
addCharges(charges, amountPlusInterestPercentage, "1", "29 September 2011");
- Integer interestPercentage = ChargesHelper.createCharges(requestSpec, responseSpec,
+ Integer interestPercentage = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
ChargesHelper.getLoanInstallmentJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_INTEREST, "1", false));
addCharges(charges, interestPercentage, "1", "29 September 2011");
List collaterals = new ArrayList<>();
- final Integer collateralId = CollateralManagementHelper.createCollateralProduct(this.requestSpec, this.responseSpec);
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
- final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(this.requestSpec, this.responseSpec,
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
String.valueOf(clientID), collateralId);
addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
final Integer loanID = applyForLoanApplication(clientID, loanProductID, charges, null, "12,000.00", collaterals);
Assertions.assertNotNull(loanID);
- HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
- ArrayList loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ ArrayList loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
loanSchedule.remove(0);
- List loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
+ List loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
Float totalPerOfAmout = 0F;
Float totalPerOfAmoutPlusInt = 0F;
@@ -675,10 +692,10 @@ public class ClientLoanIntegrationTest {
validateChargeExcludePrecission(amountPlusInterestPercentage, loanCharges, "1.0", String.valueOf(totalPerOfAmoutPlusInt), "0.0",
"0.0");
- this.loanTransactionHelper.addChargesForLoan(loanID,
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID,
LoanTransactionHelper.getInstallmentChargesForLoanAsJSON(String.valueOf(flat), "50"));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
loanSchedule.remove(0);
totalPerOfAmout = 0F;
totalPerOfAmoutPlusInt = 0F;
@@ -701,18 +718,17 @@ public class ClientLoanIntegrationTest {
"0.0");
validateChargeExcludePrecission(flat, loanCharges, "50.0", "200", "0.0", "0.0");
- this.loanTransactionHelper.updateChargesForLoan(loanID, (Integer) getloanCharge(amountPercentage, loanCharges).get("id"),
+ LOAN_TRANSACTION_HELPER.updateChargesForLoan(loanID, (Integer) getloanCharge(amountPercentage, loanCharges).get("id"),
LoanTransactionHelper.getUpdateChargesForLoanAsJSON("2"));
- this.loanTransactionHelper.updateChargesForLoan(loanID, (Integer) getloanCharge(interestPercentage, loanCharges).get("id"),
+ LOAN_TRANSACTION_HELPER.updateChargesForLoan(loanID, (Integer) getloanCharge(interestPercentage, loanCharges).get("id"),
LoanTransactionHelper.getUpdateChargesForLoanAsJSON("2"));
- this.loanTransactionHelper.updateChargesForLoan(loanID,
- (Integer) getloanCharge(amountPlusInterestPercentage, loanCharges).get("id"),
+ LOAN_TRANSACTION_HELPER.updateChargesForLoan(loanID, (Integer) getloanCharge(amountPlusInterestPercentage, loanCharges).get("id"),
LoanTransactionHelper.getUpdateChargesForLoanAsJSON("2"));
- this.loanTransactionHelper.updateChargesForLoan(loanID, (Integer) getloanCharge(flat, loanCharges).get("id"),
+ LOAN_TRANSACTION_HELPER.updateChargesForLoan(loanID, (Integer) getloanCharge(flat, loanCharges).get("id"),
LoanTransactionHelper.getUpdateChargesForLoanAsJSON("100"));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
loanSchedule.remove(0);
totalPerOfAmout = 0F;
totalPerOfAmoutPlusInt = 0F;
@@ -735,13 +751,12 @@ public class ClientLoanIntegrationTest {
"0.0");
validateChargeExcludePrecission(flat, loanCharges, "100.0", "400", "0.0", "0.0");
- final Integer savingsId = SavingsAccountHelper.openSavingsAccount(this.requestSpec, this.responseSpec, clientID,
- MINIMUM_OPENING_BALANCE);
- this.loanTransactionHelper.updateLoan(loanID, updateLoanJson(clientID, loanProductID, copyChargesForUpdate(loanCharges, null, null),
+ final Integer savingsId = SavingsAccountHelper.openSavingsAccount(REQUEST_SPEC, RESPONSE_SPEC, clientID, MINIMUM_OPENING_BALANCE);
+ LOAN_TRANSACTION_HELPER.updateLoan(loanID, updateLoanJson(clientID, loanProductID, copyChargesForUpdate(loanCharges, null, null),
String.valueOf(savingsId), collaterals));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
loanSchedule.remove(0);
totalPerOfAmout = 0F;
totalPerOfAmoutPlusInt = 0F;
@@ -764,11 +779,11 @@ public class ClientLoanIntegrationTest {
"0.0");
validateChargeExcludePrecission(flat, loanCharges, "100.0", "400", "0.0", "0.0");
- this.loanTransactionHelper.updateLoan(loanID,
+ LOAN_TRANSACTION_HELPER.updateLoan(loanID,
updateLoanJson(clientID, loanProductID, copyChargesForUpdate(loanCharges, flat, "1"), null, collaterals));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
loanSchedule.remove(0);
totalPerOfAmout = 0F;
totalPerOfAmoutPlusInt = 0F;
@@ -792,33 +807,33 @@ public class ClientLoanIntegrationTest {
charges.clear();
addCharges(charges, flat, "50", "29 September 2011");
- this.loanTransactionHelper.updateLoan(loanID, updateLoanJson(clientID, loanProductID, charges, null, collaterals));
+ LOAN_TRANSACTION_HELPER.updateLoan(loanID, updateLoanJson(clientID, loanProductID, charges, null, collaterals));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
loanSchedule.remove(0);
for (HashMap installment : loanSchedule) {
validateNumberForEqualExcludePrecission("50", String.valueOf(installment.get("feeChargesDue")));
}
validateChargeExcludePrecission(flat, loanCharges, "50.0", "200", "0.0", "0.0");
- this.loanTransactionHelper.deleteChargesForLoan(loanID, (Integer) getloanCharge(flat, loanCharges).get("id"));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ LOAN_TRANSACTION_HELPER.deleteChargesForLoan(loanID, (Integer) getloanCharge(flat, loanCharges).get("id"));
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
loanSchedule.remove(0);
for (HashMap installment : loanSchedule) {
validateNumberForEqualExcludePrecission("0", String.valueOf(installment.get("feeChargesDue")));
}
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
- loanStatusHashMap = this.loanTransactionHelper.approveLoan("20 September 2011", loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.approveLoan("20 September 2011", loanID);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
- this.loanTransactionHelper.addChargesForLoan(loanID,
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID,
LoanTransactionHelper.getInstallmentChargesForLoanAsJSON(String.valueOf(flatAccTransfer), "100"));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
loanSchedule.remove(0);
for (HashMap installment : loanSchedule) {
validateNumberForEqualExcludePrecission("100", String.valueOf(installment.get("feeChargesDue")));
@@ -826,17 +841,17 @@ public class ClientLoanIntegrationTest {
validateChargeExcludePrecission(flatAccTransfer, loanCharges, "100.0", "400", "0.0", "0.0");
// DISBURSE
- String loanDetail = this.loanTransactionHelper.getLoanDetails(this.requestSpec, this.responseSpec, loanID);
- loanStatusHashMap = this.loanTransactionHelper.disburseLoanWithNetDisbursalAmount("20 September 2011", loanID, "10000",
+ String loanDetail = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanWithNetDisbursalAmount("20 September 2011", loanID, "10000",
JsonPath.from(loanDetail).get("netDisbursalAmount").toString());
LOG.info("DISBURSE {}", loanStatusHashMap.toString());
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
- this.loanTransactionHelper.addChargesForLoan(loanID,
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID,
LoanTransactionHelper.getInstallmentChargesForLoanAsJSON(String.valueOf(flat), "50"));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
loanSchedule.remove(0);
for (HashMap installment : loanSchedule) {
validateNumberForEqualExcludePrecission("150", String.valueOf(installment.get("feeChargesDue")));
@@ -845,18 +860,18 @@ public class ClientLoanIntegrationTest {
validateChargeExcludePrecission(flat, loanCharges, "50.0", "200", "0.0", "0.0");
Integer waivePeriodnum = 1;
- final Integer waivedChargeId = this.loanTransactionHelper.waiveChargesForLoan(loanID,
+ final Integer waivedChargeId = LOAN_TRANSACTION_HELPER.waiveChargesForLoan(loanID,
(Integer) getloanCharge(flat, loanCharges).get("id"),
LoanTransactionHelper.getWaiveChargeJSON(String.valueOf(waivePeriodnum)));
// Get loan transaction details
- ArrayList loanDetails = this.loanTransactionHelper.getLoanTransactionDetails(this.requestSpec, this.responseSpec, loanID);
+ ArrayList loanDetails = LOAN_TRANSACTION_HELPER.getLoanTransactionDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
Assertions.assertNotNull(loanDetails, "Empty Loan Details");
Gson gson = new Gson();
Integer transId = null;
Integer chargeId = null;
- for (int i = 0; i < loanDetails.size(); i++) {
- String resultObject = gson.toJson(loanDetails.get(i));
+ for (HashMap detail : loanDetails) {
+ String resultObject = gson.toJson(detail);
JsonObject reportObject = JsonParser.parseString(resultObject).getAsJsonObject();
JsonObject type = reportObject.getAsJsonObject("type");
final Integer transTypeId = type.get("id").getAsInt();
@@ -868,7 +883,7 @@ public class ClientLoanIntegrationTest {
map.put("id", transId.toString());
map.put("loanId", loanID.toString());
final String putBody = gson.toJson(map);
- chargeId = this.loanTransactionHelper.undoWaiveChargesForLoanReturnResourceId(loanID, transId, putBody);
+ chargeId = LOAN_TRANSACTION_HELPER.undoWaiveChargesForLoanReturnResourceId(loanID, transId, putBody);
break;
}
}
@@ -876,8 +891,7 @@ public class ClientLoanIntegrationTest {
Assertions.assertEquals(waivedChargeId, chargeId);
// Validate the undo process
- ArrayList loanTransactionDetails = this.loanTransactionHelper.getLoanTransactionDetails(this.requestSpec,
- this.responseSpec, loanID);
+ ArrayList loanTransactionDetails = LOAN_TRANSACTION_HELPER.getLoanTransactionDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
Assertions.assertNotNull(loanTransactionDetails, "Empty Loan Transaction Details");
for (int i = 0; i < loanTransactionDetails.size(); i++) {
String resultObject = gson.toJson(loanTransactionDetails.get(i));
@@ -886,7 +900,7 @@ public class ClientLoanIntegrationTest {
final Integer id = reportObject.get("id").getAsInt();
if (transId.compareTo(id) == 0) {
- final HashMap chargeDetails = this.loanTransactionHelper.getLoanCharge(loanID, waivedChargeId);
+ final HashMap chargeDetails = LOAN_TRANSACTION_HELPER.getLoanCharge(loanID, waivedChargeId);
String resultChargeObject = gson.toJson(chargeDetails);
JsonObject reportChargeObject = JsonParser.parseString(resultChargeObject).getAsJsonObject();
BigDecimal waiveAmount = reportChargeObject.get("amountWaived").getAsBigDecimal();
@@ -900,10 +914,10 @@ public class ClientLoanIntegrationTest {
}
// Re-waive charge
- this.loanTransactionHelper.waiveChargesForLoan(loanID, waivedChargeId,
+ LOAN_TRANSACTION_HELPER.waiveChargesForLoan(loanID, waivedChargeId,
LoanTransactionHelper.getWaiveChargeJSON(String.valueOf(waivePeriodnum)));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
loanSchedule.remove(0);
for (HashMap installment : loanSchedule) {
validateNumberForEqualExcludePrecission("150", String.valueOf(installment.get("feeChargesDue")));
@@ -920,10 +934,10 @@ public class ClientLoanIntegrationTest {
validateChargeExcludePrecission(flat, loanCharges, "50.0", "150", "0.0", "50.0");
Integer payPeriodnum = 2;
- this.loanTransactionHelper.payChargesForLoan(loanID, (Integer) getloanCharge(flatAccTransfer, loanCharges).get("id"),
+ LOAN_TRANSACTION_HELPER.payChargesForLoan(loanID, (Integer) getloanCharge(flatAccTransfer, loanCharges).get("id"),
LoanTransactionHelper.getPayChargeJSON(SavingsAccountHelper.TRANSACTION_DATE, String.valueOf(payPeriodnum)));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
loanSchedule.remove(0);
for (HashMap installment : loanSchedule) {
validateNumberForEqualExcludePrecission("150", String.valueOf(installment.get("feeChargesDue")));
@@ -943,22 +957,22 @@ public class ClientLoanIntegrationTest {
validateChargeExcludePrecission(flat, loanCharges, "50.0", "150", "0.0", "50.0");
// Loan Charges with US Locale using the amount as a number in the JSON body
- this.loanTransactionHelper.addChargesForLoan(loanID,
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID,
LoanTransactionHelper.getInstallmentChargesForLoanAsJSON(String.valueOf(flat), 50.05, Locale.US));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
loanSchedule.remove(0);
for (HashMap installment : loanSchedule) {
validateNumberForEqualExcludePrecission("200.05", String.valueOf(installment.get("feeChargesDue")));
}
// Loan Charges with other Locale using comma (,) as decimal delimiter
- this.loanTransactionHelper.addChargesForLoan(loanID,
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID,
LoanTransactionHelper.getInstallmentChargesForLoanAsJSON(String.valueOf(flat), "50,05", Locale.GERMAN));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
loanSchedule.remove(0);
for (HashMap installment : loanSchedule) {
validateNumberForEqualExcludePrecission("250.10", String.valueOf(installment.get("feeChargesDue")));
@@ -966,11 +980,11 @@ public class ClientLoanIntegrationTest {
// Loan Charges with German Locale (where the comma is the decimal delimiter) using the amount as a number in
// the JSON body
- this.loanTransactionHelper.addChargesForLoan(loanID,
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID,
LoanTransactionHelper.getInstallmentChargesForLoanAsJSON(String.valueOf(flat), 50.05, Locale.GERMAN));
- loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
- loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
loanSchedule.remove(0);
for (HashMap installment : loanSchedule) {
validateNumberForEqualExcludePrecission("300.15", String.valueOf(installment.get("feeChargesDue")));
@@ -979,20 +993,17 @@ public class ClientLoanIntegrationTest {
@Test
public void testLoanCharges_DISBURSEMENT_TO_SAVINGS() {
- this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
- SavingsAccountHelper savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
- final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
- ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID);
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
final Integer loanProductID = createLoanProduct(false, NONE);
- final Integer savingsId = SavingsAccountHelper.openSavingsAccount(this.requestSpec, this.responseSpec, clientID,
- MINIMUM_OPENING_BALANCE);
+ final Integer savingsId = SavingsAccountHelper.openSavingsAccount(REQUEST_SPEC, RESPONSE_SPEC, clientID, MINIMUM_OPENING_BALANCE);
List collaterals = new ArrayList<>();
- final Integer collateralId = CollateralManagementHelper.createCollateralProduct(this.requestSpec, this.responseSpec);
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
Assertions.assertNotNull(collateralId);
- final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(this.requestSpec, this.responseSpec,
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
String.valueOf(clientID), collateralId);
Assertions.assertNotNull(clientCollateralId);
addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
@@ -1000,34 +1011,34 @@ public class ClientLoanIntegrationTest {
final Integer loanID = applyForLoanApplication(clientID, loanProductID, null, savingsId.toString(), "12,000.00", collaterals);
Assertions.assertNotNull(loanID);
- HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
- loanStatusHashMap = this.loanTransactionHelper.approveLoan("20 September 2011", loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.approveLoan("20 September 2011", loanID);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
- HashMap summary = savingsAccountHelper.getSavingsSummary(savingsId);
- Float balance = Float.parseFloat(MINIMUM_OPENING_BALANCE);
+ HashMap summary = SAVINGS_ACCOUNT_HELPER.getSavingsSummary(savingsId);
+ float balance = Float.parseFloat(MINIMUM_OPENING_BALANCE);
assertEquals(balance, summary.get("accountBalance"), "Verifying opening Balance");
// DISBURSE
- String loanDetails = this.loanTransactionHelper.getLoanDetails(this.requestSpec, this.responseSpec, loanID);
- loanStatusHashMap = this.loanTransactionHelper.disburseLoanToSavings(SavingsAccountHelper.TRANSACTION_DATE, loanID,
+ String loanDetails = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanToSavings(SavingsAccountHelper.TRANSACTION_DATE, loanID,
JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
LOG.info("DISBURSE {}", loanStatusHashMap.toString());
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
- summary = savingsAccountHelper.getSavingsSummary(savingsId);
+ summary = SAVINGS_ACCOUNT_HELPER.getSavingsSummary(savingsId);
balance = Float.parseFloat(MINIMUM_OPENING_BALANCE) + Float.parseFloat("12000");
assertEquals(balance, summary.get("accountBalance"), "Verifying opening Balance");
- loanStatusHashMap = this.loanTransactionHelper.undoDisbursal(loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.undoDisbursal(loanID);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
- summary = savingsAccountHelper.getSavingsSummary(savingsId);
+ summary = SAVINGS_ACCOUNT_HELPER.getSavingsSummary(savingsId);
balance = Float.parseFloat(MINIMUM_OPENING_BALANCE);
assertEquals(balance, summary.get("accountBalance"), "Verifying opening Balance");
@@ -1035,9 +1046,8 @@ public class ClientLoanIntegrationTest {
@Test
public void testLoanCharges_DISBURSEMENT_WITH_TRANCHES() {
- this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
- final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
- ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID);
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
final Integer loanProductID = createLoanProduct(true, NONE);
List tranches = new ArrayList<>();
@@ -1046,9 +1056,9 @@ public class ClientLoanIntegrationTest {
List collaterals = new ArrayList<>();
- final Integer collateralId = CollateralManagementHelper.createCollateralProduct(this.requestSpec, this.responseSpec);
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
Assertions.assertNotNull(collateralId);
- final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(this.requestSpec, this.responseSpec,
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
clientID.toString(), collateralId);
Assertions.assertNotNull(clientCollateralId);
addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
@@ -1056,28 +1066,28 @@ public class ClientLoanIntegrationTest {
final Integer loanID = applyForLoanApplicationWithTranches(clientID, loanProductID, null, null, "45,000.00", tranches, collaterals);
Assertions.assertNotNull(loanID);
- HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
- loanStatusHashMap = this.loanTransactionHelper.approveLoan("01 March 2014", loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.approveLoan("01 March 2014", loanID);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
// DISBURSE first Tranche
- String loanDetails = this.loanTransactionHelper.getLoanDetails(this.requestSpec, this.responseSpec, loanID);
- loanStatusHashMap = this.loanTransactionHelper.disburseLoanWithNetDisbursalAmount("20 March 2014", loanID,
+ String loanDetails = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanWithNetDisbursalAmount("20 March 2014", loanID,
JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
LOG.info("DISBURSE {}", loanStatusHashMap);
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
// DISBURSE Second Tranche
- loanStatusHashMap = this.loanTransactionHelper.disburseLoanWithNetDisbursalAmount("23 April 2014", loanID,
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanWithNetDisbursalAmount("23 April 2014", loanID,
JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
LOG.info("DISBURSE {}", loanStatusHashMap.toString());
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
- loanStatusHashMap = this.loanTransactionHelper.undoDisbursal(loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.undoDisbursal(loanID);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
@@ -1085,15 +1095,11 @@ public class ClientLoanIntegrationTest {
@Test
public void testLoanCharges_DISBURSEMENT_TO_SAVINGS_WITH_TRANCHES() {
- this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
- SavingsAccountHelper savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
-
- final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
- ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID);
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
final Integer loanProductID = createLoanProduct(true, NONE);
- final Integer savingsId = SavingsAccountHelper.openSavingsAccount(this.requestSpec, this.responseSpec, clientID,
- MINIMUM_OPENING_BALANCE);
+ final Integer savingsId = SavingsAccountHelper.openSavingsAccount(REQUEST_SPEC, RESPONSE_SPEC, clientID, MINIMUM_OPENING_BALANCE);
List tranches = new ArrayList<>();
tranches.add(createTrancheDetail("01 March 2014", "25000"));
@@ -1101,9 +1107,9 @@ public class ClientLoanIntegrationTest {
List collaterals = new ArrayList<>();
- final Integer collateralId = CollateralManagementHelper.createCollateralProduct(this.requestSpec, this.responseSpec);
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
Assertions.assertNotNull(collateralId);
- final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(this.requestSpec, this.responseSpec,
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
String.valueOf(clientID), collateralId);
Assertions.assertNotNull(clientCollateralId);
addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
@@ -1112,49 +1118,5913 @@ public class ClientLoanIntegrationTest {
tranches, collaterals);
Assertions.assertNotNull(loanID);
- HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
- loanStatusHashMap = this.loanTransactionHelper.approveLoan("01 March 2014", loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.approveLoan("01 March 2014", loanID);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
- HashMap summary = savingsAccountHelper.getSavingsSummary(savingsId);
- Float balance = Float.parseFloat(MINIMUM_OPENING_BALANCE);
+ HashMap summary = SAVINGS_ACCOUNT_HELPER.getSavingsSummary(savingsId);
+ float balance = Float.parseFloat(MINIMUM_OPENING_BALANCE);
assertEquals(balance, summary.get("accountBalance"), "Verifying opening Balance");
// DISBURSE first Tranche
- String loanDetails = this.loanTransactionHelper.getLoanDetails(this.requestSpec, this.responseSpec, loanID);
- loanStatusHashMap = this.loanTransactionHelper.disburseLoanToSavings("01 March 2014", loanID,
+ String loanDetails = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanToSavings("01 March 2014", loanID,
JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
LOG.info("DISBURSE {}", loanStatusHashMap.toString());
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
- summary = savingsAccountHelper.getSavingsSummary(savingsId);
+ summary = SAVINGS_ACCOUNT_HELPER.getSavingsSummary(savingsId);
balance = Float.parseFloat(MINIMUM_OPENING_BALANCE) + Float.parseFloat("25000");
assertEquals(balance, summary.get("accountBalance"), "Verifying opening Balance");
// DISBURSE Second Tranche
- loanStatusHashMap = this.loanTransactionHelper.disburseLoanToSavings("23 April 2014", loanID,
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanToSavings("23 April 2014", loanID,
JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
LOG.info("DISBURSE {}", loanStatusHashMap.toString());
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
- summary = savingsAccountHelper.getSavingsSummary(savingsId);
+ summary = SAVINGS_ACCOUNT_HELPER.getSavingsSummary(savingsId);
balance = Float.parseFloat(MINIMUM_OPENING_BALANCE) + Float.parseFloat("25000") + Float.parseFloat("20000");
assertEquals(balance, summary.get("accountBalance"), "Verifying opening Balance");
- loanStatusHashMap = this.loanTransactionHelper.undoDisbursal(loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.undoDisbursal(loanID);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
- summary = savingsAccountHelper.getSavingsSummary(savingsId);
+ summary = SAVINGS_ACCOUNT_HELPER.getSavingsSummary(savingsId);
balance = Float.parseFloat(MINIMUM_OPENING_BALANCE);
assertEquals(balance, summary.get("accountBalance"), "Verifying opening Balance");
}
+ /***
+ * Test case for checking CashBasedAccounting functionality adding charges with calculation type flat
+ */
+ @Test
+ public void loanWithFlatCahargesAndCashBasedAccountingEnabled() {
+
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
+
+ // Add charges with payment mode regular
+ List charges = new ArrayList<>();
+ Integer flatDisbursement = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC, ChargesHelper.getLoanDisbursementJSON());
+ addCharges(charges, flatDisbursement, "100", null);
+ Integer flatSpecifiedDueDate = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, "100", false));
+ addCharges(charges, flatSpecifiedDueDate, "100", "29 September 2011");
+ Integer flatInstallmentFee = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanInstallmentJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, "50", false));
+ addCharges(charges, flatInstallmentFee, "50", null);
+
+ final Account assetAccount = ACCOUNT_HELPER.createAssetAccount();
+ final Account incomeAccount = ACCOUNT_HELPER.createIncomeAccount();
+ final Account expenseAccount = ACCOUNT_HELPER.createExpenseAccount();
+ final Account overpaymentAccount = ACCOUNT_HELPER.createLiabilityAccount();
+
+ List collaterals = new ArrayList<>();
+
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
+
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
+ String.valueOf(clientID), collateralId);
+ addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
+
+ final Integer loanProductID = createLoanProduct(false, CASH_BASED, assetAccount, incomeAccount, expenseAccount, overpaymentAccount);
+
+ final Integer loanID = applyForLoanApplication(clientID, loanProductID, charges, null, "12,000.00", collaterals);
+ Assertions.assertNotNull(loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
+
+ ArrayList loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ verifyLoanRepaymentSchedule(loanSchedule);
+
+ List loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(flatDisbursement, loanCharges, "100", "100.00", "0.0", "0.0");
+ validateCharge(flatSpecifiedDueDate, loanCharges, "100", "100.00", "0.0", "0.0");
+ validateCharge(flatInstallmentFee, loanCharges, "50", "200.00", "0.0", "0.0");
+
+ // check for disbursement fee
+ HashMap disbursementDetail = loanSchedule.get(0);
+ validateNumberForEqual("100.00", String.valueOf(disbursementDetail.get("feeChargesDue")));
+
+ // check for charge at specified date and installment fee
+ HashMap firstInstallment = loanSchedule.get(1);
+ validateNumberForEqual("150.00", String.valueOf(firstInstallment.get("feeChargesDue")));
+
+ // check for installment fee
+ HashMap secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("50.00", String.valueOf(secondInstallment.get("feeChargesDue")));
+
+ LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.approveLoan("20 September 2011", loanID);
+ LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
+ LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
+
+ LOG.info("-------------------------------DISBURSE LOAN-------------------------------------------");
+ String loanDetails = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanWithNetDisbursalAmount("20 September 2011", loanID,
+ JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
+ LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
+
+ final JournalEntry[] assetAccountInitialEntry = { new JournalEntry(Float.parseFloat("100.00"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("12000.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("12000.00"), JournalEntry.TransactionType.DEBIT) };
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 September 2011", assetAccountInitialEntry);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 September 2011",
+ new JournalEntry(Float.parseFloat("100.00"), JournalEntry.TransactionType.CREDIT));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(flatDisbursement, loanCharges, "100", "0.00", "100.0", "0.0");
+
+ LOG.info("-------------Make repayment 1-----------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 October 2011", Float.parseFloat("3301.49"), loanID);
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(flatDisbursement, loanCharges, "100", "0.00", "100.0", "0.0");
+ validateCharge(flatSpecifiedDueDate, loanCharges, "100", "0.00", "100.0", "0.0");
+ validateCharge(flatInstallmentFee, loanCharges, "50", "150.00", "50.0", "0.0");
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("3301.49"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("2911.49"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("150.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("240.00"), JournalEntry.TransactionType.CREDIT));
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(flatSpecifiedDueDate), "29 October 2011", "100"));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("150.00", String.valueOf(secondInstallment.get("feeChargesDue")));
+ LOAN_TRANSACTION_HELPER.waiveChargesForLoan(loanID, (Integer) getloanCharge(flatInstallmentFee, loanCharges).get("id"),
+ LoanTransactionHelper.getWaiveChargeJSON(String.valueOf(2)));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(flatInstallmentFee, loanCharges, "50", "100.00", "50.0", "50.0");
+
+ LOG.info("----------Make repayment 2------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3251.49"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("3251.49"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("2969.72"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("100.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("181.77"), JournalEntry.TransactionType.CREDIT));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("0", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("--------------Waive interest---------------");
+ LOAN_TRANSACTION_HELPER.waiveInterest("20 December 2011", String.valueOf(61.79), loanID);
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap thirdInstallment = loanSchedule.get(3);
+ validateNumberForEqual("60.59", String.valueOf(thirdInstallment.get("interestOutstanding")));
+
+ Integer flatPenaltySpecifiedDueDate = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, "100", true));
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(flatPenaltySpecifiedDueDate), "29 September 2011", "100"));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(flatPenaltySpecifiedDueDate, loanCharges, "100", "0.00", "100.0", "0.0");
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("100", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("3301.49"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("2811.49"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("100.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("150.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("240"), JournalEntry.TransactionType.CREDIT));
+
+ LOG.info("----------Make repayment 3 advance------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3301.49"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("3301.49"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3129.11"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("50.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("122.38"), JournalEntry.TransactionType.CREDIT));
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(flatPenaltySpecifiedDueDate), "10 January 2012", "100"));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap fourthInstallment = loanSchedule.get(4);
+ validateNumberForEqual("100", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
+ validateNumberForEqual("3239.68", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("----------Pay applied penalty ------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("100"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("100"), JournalEntry.TransactionType.DEBIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("100.00"), JournalEntry.TransactionType.CREDIT));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ fourthInstallment = loanSchedule.get(4);
+ validateNumberForEqual("0", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
+ validateNumberForEqual("3139.68", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("----------Make repayment 4 ------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("3139.68"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("3139.68"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3089.68"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("50.00"), JournalEntry.TransactionType.CREDIT));
+ }
+
+ /***
+ * Test case for checking CashBasedAccounting functionality adding charges with calculation type percentage of
+ * amount
+ */
+ @Test
+ public void loanWithCahargesOfTypeAmountPercentageAndCashBasedAccountingEnabled() {
+
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
+
+ // Add charges with payment mode regular
+ List charges = new ArrayList<>();
+ Integer percentageDisbursementCharge = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanDisbursementJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1"));
+ addCharges(charges, percentageDisbursementCharge, "1", null);
+
+ Integer percentageSpecifiedDueDateCharge = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1", false));
+ addCharges(charges, percentageSpecifiedDueDateCharge, "1", "29 September 2011");
+
+ Integer percentageInstallmentFee = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanInstallmentJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1", false));
+ addCharges(charges, percentageInstallmentFee, "1", "29 September 2011");
+
+ final Account assetAccount = ACCOUNT_HELPER.createAssetAccount();
+ final Account incomeAccount = ACCOUNT_HELPER.createIncomeAccount();
+ final Account expenseAccount = ACCOUNT_HELPER.createExpenseAccount();
+ final Account overpaymentAccount = ACCOUNT_HELPER.createLiabilityAccount();
+
+ List collaterals = new ArrayList<>();
+
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
+ Assertions.assertNotNull(collateralId);
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
+ clientID.toString(), collateralId);
+ Assertions.assertNotNull(clientCollateralId);
+ addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
+
+ final Integer loanProductID = createLoanProduct(false, CASH_BASED, assetAccount, incomeAccount, expenseAccount, overpaymentAccount);
+ final Integer loanID = applyForLoanApplication(clientID, loanProductID, charges, null, "12,000.00", collaterals);
+ Assertions.assertNotNull(loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
+
+ ArrayList loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ verifyLoanRepaymentSchedule(loanSchedule);
+
+ List loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(percentageDisbursementCharge, loanCharges, "1", "120.00", "0.0", "0.0");
+ validateCharge(percentageSpecifiedDueDateCharge, loanCharges, "1", "120.00", "0.0", "0.0");
+ validateCharge(percentageInstallmentFee, loanCharges, "1", "120.00", "0.0", "0.0");
+
+ // check for disbursement fee
+ HashMap disbursementDetail = loanSchedule.get(0);
+ validateNumberForEqual("120.00", String.valueOf(disbursementDetail.get("feeChargesDue")));
+
+ // check for charge at specified date and installment fee
+ HashMap firstInstallment = loanSchedule.get(1);
+ validateNumberForEqual("149.11", String.valueOf(firstInstallment.get("feeChargesDue")));
+
+ // check for installment fee
+ HashMap secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("29.70", String.valueOf(secondInstallment.get("feeChargesDue")));
+
+ LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.approveLoan("20 September 2011", loanID);
+ LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
+ LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
+
+ LOG.info("-------------------------------DISBURSE LOAN-------------------------------------------");
+ String loanDetails = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanWithNetDisbursalAmount("20 September 2011", loanID,
+ JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
+ LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
+
+ final JournalEntry[] assetAccountInitialEntry = { new JournalEntry(Float.parseFloat("120.00"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("12000.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("12000.00"), JournalEntry.TransactionType.DEBIT) };
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 September 2011", assetAccountInitialEntry);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 September 2011",
+ new JournalEntry(Float.parseFloat("120.00"), JournalEntry.TransactionType.CREDIT));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(percentageDisbursementCharge, loanCharges, "1", "0.0", "120.00", "0.0");
+
+ LOG.info("-------------Make repayment 1-----------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 October 2011", Float.parseFloat("3300.60"), loanID);
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(percentageDisbursementCharge, loanCharges, "1", "0.00", "120.00", "0.0");
+ validateCharge(percentageSpecifiedDueDateCharge, loanCharges, "1", "0.00", "120.0", "0.0");
+ validateCharge(percentageInstallmentFee, loanCharges, "1", "90.89", "29.11", "0.0");
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("3300.60"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("2911.49"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("149.11"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("240.00"), JournalEntry.TransactionType.CREDIT));
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(percentageSpecifiedDueDateCharge), "29 October 2011", "1"));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("149.70", String.valueOf(secondInstallment.get("feeChargesDue")));
+ LOAN_TRANSACTION_HELPER.waiveChargesForLoan(loanID, (Integer) getloanCharge(percentageInstallmentFee, loanCharges).get("id"),
+ LoanTransactionHelper.getWaiveChargeJSON(String.valueOf(2)));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(percentageInstallmentFee, loanCharges, "1", "61.19", "29.11", "29.70");
+
+ LOG.info("----------Make repayment 2------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3271.49"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("3271.49"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("2969.72"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("120.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("181.77"), JournalEntry.TransactionType.CREDIT));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("0", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("--------------Waive interest---------------");
+ LOAN_TRANSACTION_HELPER.waiveInterest("20 December 2011", String.valueOf(61.79), loanID);
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap thirdInstallment = loanSchedule.get(3);
+ validateNumberForEqual("60.59", String.valueOf(thirdInstallment.get("interestOutstanding")));
+
+ Integer percentagePenaltySpecifiedDueDate = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1", true));
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(percentagePenaltySpecifiedDueDate), "29 September 2011", "1"));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(percentagePenaltySpecifiedDueDate, loanCharges, "1", "0.00", "120.0", "0.0");
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("120", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("3300.60"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("2791.49"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("120.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("149.11"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("240"), JournalEntry.TransactionType.CREDIT));
+
+ LOG.info("----------Make repayment 3 advance------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3301.78"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("3301.78"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3149.11"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("30.29"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("122.38"), JournalEntry.TransactionType.CREDIT));
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(percentagePenaltySpecifiedDueDate), "10 January 2012", "1"));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap fourthInstallment = loanSchedule.get(4);
+ validateNumberForEqual("120", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
+ validateNumberForEqual("3240.58", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("----------Pay applied penalty ------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("120"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("120"), JournalEntry.TransactionType.DEBIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("120.00"), JournalEntry.TransactionType.CREDIT));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ fourthInstallment = loanSchedule.get(4);
+ validateNumberForEqual("0", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
+ validateNumberForEqual("3120.58", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("----------Make repayment 4 ------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("3120.58"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("3120.58"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3089.68"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("30.90"), JournalEntry.TransactionType.CREDIT));
+ }
+
+ /***
+ * Test case for checking CashBasedAccounting functionality adding charges with calculation type percentage of
+ * amount plus interest
+ */
+ @Test
+ public void loanWithCahargesOfTypeAmountPlusInterestPercentageAndCashBasedAccountingEnabled() {
+
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
+
+ // Add charges with payment mode regular
+ List charges = new ArrayList<>();
+ Integer amountPlusInterestPercentageDisbursementCharge = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanDisbursementJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST, "1"));
+ addCharges(charges, amountPlusInterestPercentageDisbursementCharge, "1", null);
+
+ Integer amountPlusInterestPercentageSpecifiedDueDateCharge = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC, ChargesHelper
+ .getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST, "1", false));
+ addCharges(charges, amountPlusInterestPercentageSpecifiedDueDateCharge, "1", "29 September 2011");
+
+ Integer amountPlusInterestPercentageInstallmentFee = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanInstallmentJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST, "1", false));
+ addCharges(charges, amountPlusInterestPercentageInstallmentFee, "1", "29 September 2011");
+
+ final Account assetAccount = ACCOUNT_HELPER.createAssetAccount();
+ final Account incomeAccount = ACCOUNT_HELPER.createIncomeAccount();
+ final Account expenseAccount = ACCOUNT_HELPER.createExpenseAccount();
+ final Account overpaymentAccount = ACCOUNT_HELPER.createLiabilityAccount();
+
+ List collaterals = new ArrayList<>();
+
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
+
+ Assertions.assertNotNull(collateralId);
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
+ clientID.toString(), collateralId);
+ Assertions.assertNotNull(collateralId);
+ addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
+
+ final Integer loanProductID = createLoanProduct(false, CASH_BASED, assetAccount, incomeAccount, expenseAccount, overpaymentAccount);
+ final Integer loanID = applyForLoanApplication(clientID, loanProductID, charges, null, "12,000.00", collaterals);
+ Assertions.assertNotNull(loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
+
+ ArrayList loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ verifyLoanRepaymentSchedule(loanSchedule);
+
+ List loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(amountPlusInterestPercentageDisbursementCharge, loanCharges, "1", "126.06", "0.0", "0.0");
+ validateCharge(amountPlusInterestPercentageSpecifiedDueDateCharge, loanCharges, "1", "126.06", "0.0", "0.0");
+ validateCharge(amountPlusInterestPercentageInstallmentFee, loanCharges, "1", "126.04", "0.0", "0.0");
+
+ // check for disbursement fee
+ HashMap disbursementDetail = loanSchedule.get(0);
+ validateNumberForEqual("126.06", String.valueOf(disbursementDetail.get("feeChargesDue")));
+
+ // check for charge at specified date and installment fee
+ HashMap firstInstallment = loanSchedule.get(1);
+ validateNumberForEqual("157.57", String.valueOf(firstInstallment.get("feeChargesDue")));
+
+ // check for installment fee
+ HashMap secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("31.51", String.valueOf(secondInstallment.get("feeChargesDue")));
+
+ LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.approveLoan("20 September 2011", loanID);
+ LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
+ LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
+
+ LOG.info("-------------------------------DISBURSE LOAN-------------------------------------------");
+ String loanDetails = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanWithNetDisbursalAmount("20 September 2011", loanID,
+ JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
+ LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
+
+ final JournalEntry[] assetAccountInitialEntry = { new JournalEntry(Float.parseFloat("126.06"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("12000.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("12000.00"), JournalEntry.TransactionType.DEBIT) };
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 September 2011", assetAccountInitialEntry);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 September 2011",
+ new JournalEntry(Float.parseFloat("126.06"), JournalEntry.TransactionType.CREDIT));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(amountPlusInterestPercentageDisbursementCharge, loanCharges, "1", "0.0", "126.06", "0.0");
+
+ LOG.info("-------------Make repayment 1-----------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 October 2011", Float.parseFloat("3309.06"), loanID);
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(amountPlusInterestPercentageDisbursementCharge, loanCharges, "1", "0.00", "126.06", "0.0");
+ validateCharge(amountPlusInterestPercentageSpecifiedDueDateCharge, loanCharges, "1", "0.00", "126.06", "0.0");
+ validateCharge(amountPlusInterestPercentageInstallmentFee, loanCharges, "1", "94.53", "31.51", "0.0");
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("3309.06"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("2911.49"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("157.57"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("240.00"), JournalEntry.TransactionType.CREDIT));
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(
+ String.valueOf(amountPlusInterestPercentageSpecifiedDueDateCharge), "29 October 2011", "1"));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("157.57", String.valueOf(secondInstallment.get("feeChargesDue")));
+ LOAN_TRANSACTION_HELPER.waiveChargesForLoan(loanID,
+ (Integer) getloanCharge(amountPlusInterestPercentageInstallmentFee, loanCharges).get("id"),
+ LoanTransactionHelper.getWaiveChargeJSON(String.valueOf(2)));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(amountPlusInterestPercentageInstallmentFee, loanCharges, "1", "63.02", "31.51", "31.51");
+
+ LOG.info("----------Make repayment 2------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3277.55"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("3277.55"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("2969.72"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("126.06"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("181.77"), JournalEntry.TransactionType.CREDIT));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("0", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("--------------Waive interest---------------");
+ LOAN_TRANSACTION_HELPER.waiveInterest("20 December 2011", String.valueOf(61.79), loanID);
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap thirdInstallment = loanSchedule.get(3);
+ validateNumberForEqual("60.59", String.valueOf(thirdInstallment.get("interestOutstanding")));
+
+ Integer amountPlusInterestPercentagePenaltySpecifiedDueDate = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1", true));
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(
+ String.valueOf(amountPlusInterestPercentagePenaltySpecifiedDueDate), "29 September 2011", "1"));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(amountPlusInterestPercentagePenaltySpecifiedDueDate, loanCharges, "1", "0.0", "120.0", "0.0");
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("120", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("3309.06"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("2791.49"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("120.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("157.57"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("240"), JournalEntry.TransactionType.CREDIT));
+
+ LOG.info("----------Make repayment 3 advance------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3303"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("3303"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3149.11"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("31.51"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("122.38"), JournalEntry.TransactionType.CREDIT));
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(
+ String.valueOf(amountPlusInterestPercentagePenaltySpecifiedDueDate), "10 January 2012", "1"));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap fourthInstallment = loanSchedule.get(4);
+ validateNumberForEqual("120", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
+ validateNumberForEqual("3241.19", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("----------Pay applied penalty ------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("120"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("120"), JournalEntry.TransactionType.DEBIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("120.00"), JournalEntry.TransactionType.CREDIT));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ fourthInstallment = loanSchedule.get(4);
+ validateNumberForEqual("0", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
+ validateNumberForEqual("3121.19", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("----------Make repayment 4 ------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("3121.19"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("3121.19"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3089.68"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("31.51"), JournalEntry.TransactionType.CREDIT));
+ }
+
+ /***
+ * Test case for checking AccuralUpfrontAccounting functionality adding charges with calculation type flat
+ */
+ @Test
+ public void loanWithFlatCahargesAndUpfrontAccrualAccountingEnabled() {
+
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
+
+ // Add charges with payment mode regular
+ List charges = new ArrayList<>();
+ Integer flatDisbursement = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC, ChargesHelper.getLoanDisbursementJSON());
+ addCharges(charges, flatDisbursement, "100", null);
+ Integer flatSpecifiedDueDate = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, "100", false));
+
+ Integer flatInstallmentFee = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanInstallmentJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, "50", false));
+ addCharges(charges, flatInstallmentFee, "50", null);
+
+ final Account assetAccount = ACCOUNT_HELPER.createAssetAccount();
+ final Account incomeAccount = ACCOUNT_HELPER.createIncomeAccount();
+ final Account expenseAccount = ACCOUNT_HELPER.createExpenseAccount();
+ final Account overpaymentAccount = ACCOUNT_HELPER.createLiabilityAccount();
+
+ List collaterals = new ArrayList<>();
+
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
+ Assertions.assertNotNull(collateralId);
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
+ String.valueOf(clientID), collateralId);
+ Assertions.assertNotNull(clientCollateralId);
+ addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
+
+ final Integer loanProductID = createLoanProduct(false, ACCRUAL_UPFRONT, assetAccount, incomeAccount, expenseAccount,
+ overpaymentAccount);
+ final Integer loanID = applyForLoanApplication(clientID, loanProductID, charges, null, "12,000.00", collaterals);
+ Assertions.assertNotNull(loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
+
+ ArrayList loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ verifyLoanRepaymentSchedule(loanSchedule);
+
+ List loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(flatDisbursement, loanCharges, "100", "100.00", "0.0", "0.0");
+ validateCharge(flatInstallmentFee, loanCharges, "50", "200.00", "0.0", "0.0");
+
+ // check for disbursement fee
+ HashMap disbursementDetail = loanSchedule.get(0);
+ validateNumberForEqual("100.00", String.valueOf(disbursementDetail.get("feeChargesDue")));
+
+ // check for charge at specified date and installment fee
+ HashMap firstInstallment = loanSchedule.get(1);
+ validateNumberForEqual("50.00", String.valueOf(firstInstallment.get("feeChargesDue")));
+
+ // check for installment fee
+ HashMap secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("50.00", String.valueOf(secondInstallment.get("feeChargesDue")));
+
+ LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.approveLoan("20 September 2011", loanID);
+ LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
+ LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
+
+ LOG.info("-------------------------------DISBURSE LOAN-------------------------------------------");
+ String loanDetails = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanWithNetDisbursalAmount("20 September 2011", loanID,
+ JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
+ LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
+
+ final JournalEntry[] assetAccountInitialEntry = { new JournalEntry(Float.parseFloat("605.94"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("100.00"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("200.00"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("12000.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("12000.00"), JournalEntry.TransactionType.DEBIT) };
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 September 2011", assetAccountInitialEntry);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 September 2011",
+ new JournalEntry(Float.parseFloat("605.94"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("100.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("200.00"), JournalEntry.TransactionType.CREDIT));
+
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(flatSpecifiedDueDate), "29 September 2011", "100"));
+
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(flatDisbursement, loanCharges, "100", "0.00", "100.0", "0.0");
+ validateCharge(flatSpecifiedDueDate, loanCharges, "100", "100.00", "0.0", "0.0");
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "29 September 2011",
+ new JournalEntry(Float.parseFloat("100.00"), JournalEntry.TransactionType.DEBIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "29 September 2011",
+ new JournalEntry(Float.parseFloat("100.00"), JournalEntry.TransactionType.CREDIT));
+
+ LOG.info("-------------Make repayment 1-----------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 October 2011", Float.parseFloat("3301.49"), loanID);
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(flatDisbursement, loanCharges, "100", "0.00", "100.0", "0.0");
+ validateCharge(flatSpecifiedDueDate, loanCharges, "100", "0.00", "100.0", "0.0");
+ validateCharge(flatInstallmentFee, loanCharges, "50", "150.00", "50.0", "0.0");
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("3301.49"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3301.49"), JournalEntry.TransactionType.CREDIT));
+
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(flatSpecifiedDueDate), "29 October 2011", "100"));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("150.00", String.valueOf(secondInstallment.get("feeChargesDue")));
+ LOG.info("----------- Waive installment charge for 2nd installment ---------");
+ LOAN_TRANSACTION_HELPER.waiveChargesForLoan(loanID, (Integer) getloanCharge(flatInstallmentFee, loanCharges).get("id"),
+ LoanTransactionHelper.getWaiveChargeJSON(String.valueOf(2)));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(flatInstallmentFee, loanCharges, "50", "100.00", "50.0", "50.0");
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("50.0"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForExpenseAccount(expenseAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("50.0"), JournalEntry.TransactionType.DEBIT));
+
+ LOG.info("----------Make repayment 2------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3251.49"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("3251.49"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3251.49"), JournalEntry.TransactionType.CREDIT));
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("0", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("--------------Waive interest---------------");
+ LOAN_TRANSACTION_HELPER.waiveInterest("20 December 2011", String.valueOf(61.79), loanID);
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap thirdInstallment = loanSchedule.get(3);
+ validateNumberForEqual("60.59", String.valueOf(thirdInstallment.get("interestOutstanding")));
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 December 2011",
+ new JournalEntry(Float.parseFloat("61.79"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForExpenseAccount(expenseAccount, "20 December 2011",
+ new JournalEntry(Float.parseFloat("61.79"), JournalEntry.TransactionType.DEBIT));
+
+ Integer flatPenaltySpecifiedDueDate = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, "100", true));
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(flatPenaltySpecifiedDueDate), "29 September 2011", "100"));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(flatPenaltySpecifiedDueDate, loanCharges, "100", "0.00", "100.0", "0.0");
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("100", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ // checking the journal entry as applied penalty has been collected
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("3301.49"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3301.49"), JournalEntry.TransactionType.CREDIT));
+
+ LOG.info("----------Make repayment 3 advance------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3301.49"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("3301.49"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3301.49"), JournalEntry.TransactionType.CREDIT));
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(flatPenaltySpecifiedDueDate), "10 January 2012", "100"));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap fourthInstallment = loanSchedule.get(4);
+ validateNumberForEqual("100", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
+ validateNumberForEqual("3239.68", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("----------Pay applied penalty ------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("100"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("100"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("100"), JournalEntry.TransactionType.CREDIT));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ fourthInstallment = loanSchedule.get(4);
+ validateNumberForEqual("0", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
+ validateNumberForEqual("3139.68", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("----------Make over payment for repayment 4 ------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("3220.60"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("3220.60"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3139.68"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForLiabilityAccount(overpaymentAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("80.92"), JournalEntry.TransactionType.CREDIT));
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.getLoanDetail(REQUEST_SPEC, RESPONSE_SPEC, loanID, "status");
+ LoanStatusChecker.verifyLoanAccountIsOverPaid(loanStatusHashMap);
+ }
+
+ /***
+ * Test case for checking AccuralUpfrontAccounting functionality adding charges with calculation type percentage of
+ * amount
+ */
+ @Test
+ public void loanWithCahargesAndUpfrontAccrualAccountingEnabled() {
+
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
+
+ // Add charges with payment mode regular
+ List charges = new ArrayList<>();
+ Integer percentageDisbursementCharge = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanDisbursementJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1"));
+ addCharges(charges, percentageDisbursementCharge, "1", null);
+
+ Integer percentageSpecifiedDueDateCharge = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1", false));
+ addCharges(charges, percentageSpecifiedDueDateCharge, "1", "29 September 2011");
+
+ Integer percentageInstallmentFee = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanInstallmentJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1", false));
+ addCharges(charges, percentageInstallmentFee, "1", "29 September 2011");
+
+ final Account assetAccount = ACCOUNT_HELPER.createAssetAccount();
+ final Account incomeAccount = ACCOUNT_HELPER.createIncomeAccount();
+ final Account expenseAccount = ACCOUNT_HELPER.createExpenseAccount();
+ final Account overpaymentAccount = ACCOUNT_HELPER.createLiabilityAccount();
+
+ List collaterals = new ArrayList<>();
+
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
+ Assertions.assertNotNull(collateralId);
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
+ String.valueOf(clientID), collateralId);
+ Assertions.assertNotNull(clientCollateralId);
+ addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
+
+ final Integer loanProductID = createLoanProduct(false, ACCRUAL_UPFRONT, assetAccount, incomeAccount, expenseAccount,
+ overpaymentAccount);
+ final Integer loanID = applyForLoanApplication(clientID, loanProductID, charges, null, "12,000.00", collaterals);
+ Assertions.assertNotNull(loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
+
+ ArrayList loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ verifyLoanRepaymentSchedule(loanSchedule);
+
+ List loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(percentageDisbursementCharge, loanCharges, "1", "120.00", "0.0", "0.0");
+ validateCharge(percentageSpecifiedDueDateCharge, loanCharges, "1", "120.00", "0.0", "0.0");
+ validateCharge(percentageInstallmentFee, loanCharges, "1", "120.00", "0.0", "0.0");
+
+ // check for disbursement fee
+ HashMap disbursementDetail = loanSchedule.get(0);
+ validateNumberForEqual("120.00", String.valueOf(disbursementDetail.get("feeChargesDue")));
+
+ // check for charge at specified date and installment fee
+ HashMap firstInstallment = loanSchedule.get(1);
+ validateNumberForEqual("149.11", String.valueOf(firstInstallment.get("feeChargesDue")));
+
+ // check for installment fee
+ HashMap secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("29.70", String.valueOf(secondInstallment.get("feeChargesDue")));
+
+ LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.approveLoan("20 September 2011", loanID);
+ LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
+ LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
+
+ LOG.info("-------------------------------DISBURSE LOAN-------------------------------------------");
+ String loanDetails = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanWithNetDisbursalAmount("20 September 2011", loanID,
+ JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
+ LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
+
+ final JournalEntry[] assetAccountInitialEntry = { new JournalEntry(Float.parseFloat("605.94"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("120.00"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("120.00"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("120.00"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("12000.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("12000.00"), JournalEntry.TransactionType.DEBIT) };
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 September 2011", assetAccountInitialEntry);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 September 2011",
+ new JournalEntry(Float.parseFloat("605.94"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("120.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("120.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("120.00"), JournalEntry.TransactionType.CREDIT));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(percentageDisbursementCharge, loanCharges, "1", "0.0", "120.00", "0.0");
+
+ LOG.info("-------------Make repayment 1-----------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 October 2011", Float.parseFloat("3300.60"), loanID);
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(percentageDisbursementCharge, loanCharges, "1", "0.00", "120.00", "0.0");
+ validateCharge(percentageSpecifiedDueDateCharge, loanCharges, "1", "0.00", "120.0", "0.0");
+ validateCharge(percentageInstallmentFee, loanCharges, "1", "90.89", "29.11", "0.0");
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("3300.60"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3300.60"), JournalEntry.TransactionType.CREDIT));
+
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(percentageSpecifiedDueDateCharge), "29 October 2011", "1"));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("149.70", String.valueOf(secondInstallment.get("feeChargesDue")));
+ LOG.info("----------- Waive installment charge for 2nd installment ---------");
+ LOAN_TRANSACTION_HELPER.waiveChargesForLoan(loanID, (Integer) getloanCharge(percentageInstallmentFee, loanCharges).get("id"),
+ LoanTransactionHelper.getWaiveChargeJSON(String.valueOf(2)));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(percentageInstallmentFee, loanCharges, "1", "61.19", "29.11", "29.70");
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("29.7"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForExpenseAccount(expenseAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("29.7"), JournalEntry.TransactionType.DEBIT));
+
+ LOG.info("----------Make repayment 2------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3271.49"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("3271.49"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3271.49"), JournalEntry.TransactionType.CREDIT));
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("0", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("--------------Waive interest---------------");
+ LOAN_TRANSACTION_HELPER.waiveInterest("20 December 2011", String.valueOf(61.79), loanID);
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap thirdInstallment = loanSchedule.get(3);
+ validateNumberForEqual("60.59", String.valueOf(thirdInstallment.get("interestOutstanding")));
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 December 2011",
+ new JournalEntry(Float.parseFloat("61.79"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForExpenseAccount(expenseAccount, "20 December 2011",
+ new JournalEntry(Float.parseFloat("61.79"), JournalEntry.TransactionType.DEBIT));
+
+ Integer percentagePenaltySpecifiedDueDate = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1", true));
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(percentagePenaltySpecifiedDueDate), "29 September 2011", "1"));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(percentagePenaltySpecifiedDueDate, loanCharges, "1", "0.00", "120.0", "0.0");
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("120", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ // checking the journal entry as applied penalty has been collected
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("3300.60"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3300.60"), JournalEntry.TransactionType.CREDIT));
+
+ LOG.info("----------Make repayment 3 advance------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3301.78"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("3301.78"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3301.78"), JournalEntry.TransactionType.CREDIT));
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(percentagePenaltySpecifiedDueDate), "10 January 2012", "1"));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap fourthInstallment = loanSchedule.get(4);
+ validateNumberForEqual("120", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
+ validateNumberForEqual("3240.58", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("----------Pay applied penalty ------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("120"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("120"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("120"), JournalEntry.TransactionType.CREDIT));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ fourthInstallment = loanSchedule.get(4);
+ validateNumberForEqual("0", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
+ validateNumberForEqual("3120.58", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("----------Make over payment for repayment 4 ------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("3220.58"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("3220.58"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3120.58"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForLiabilityAccount(overpaymentAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("100.00"), JournalEntry.TransactionType.CREDIT));
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.getLoanDetail(REQUEST_SPEC, RESPONSE_SPEC, loanID, "status");
+ LoanStatusChecker.verifyLoanAccountIsOverPaid(loanStatusHashMap);
+ }
+
+ /***
+ * Test case for checking AccuralUpfrontAccounting functionality adding charges with calculation type percentage of
+ * amount plus interest
+ */
+ @Test
+ public void loanWithCahargesOfTypeAmountPlusInterestPercentageAndUpfrontAccrualAccountingEnabled() {
+
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
+
+ // Add charges with payment mode regular
+ List charges = new ArrayList<>();
+ Integer amountPlusInterestPercentageDisbursementCharge = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanDisbursementJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST, "1"));
+ addCharges(charges, amountPlusInterestPercentageDisbursementCharge, "1", null);
+
+ Integer amountPlusInterestPercentageSpecifiedDueDateCharge = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC, ChargesHelper
+ .getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST, "1", false));
+
+ Integer amountPlusInterestPercentageInstallmentFee = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanInstallmentJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST, "1", false));
+ addCharges(charges, amountPlusInterestPercentageInstallmentFee, "1", "29 September 2011");
+
+ final Account assetAccount = ACCOUNT_HELPER.createAssetAccount();
+ final Account incomeAccount = ACCOUNT_HELPER.createIncomeAccount();
+ final Account expenseAccount = ACCOUNT_HELPER.createExpenseAccount();
+ final Account overpaymentAccount = ACCOUNT_HELPER.createLiabilityAccount();
+
+ List collaterals = new ArrayList<>();
+
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
+
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
+ String.valueOf(clientID), collateralId);
+ addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
+
+ final Integer loanProductID = createLoanProduct(false, ACCRUAL_UPFRONT, assetAccount, incomeAccount, expenseAccount,
+ overpaymentAccount);
+ final Integer loanID = applyForLoanApplication(clientID, loanProductID, charges, null, "12,000.00", collaterals);
+ Assertions.assertNotNull(loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
+
+ ArrayList loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ verifyLoanRepaymentSchedule(loanSchedule);
+
+ List loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(amountPlusInterestPercentageDisbursementCharge, loanCharges, "1", "126.06", "0.0", "0.0");
+ validateCharge(amountPlusInterestPercentageInstallmentFee, loanCharges, "1", "126.04", "0.0", "0.0");
+
+ // check for disbursement fee
+ HashMap disbursementDetail = loanSchedule.get(0);
+ validateNumberForEqual("126.06", String.valueOf(disbursementDetail.get("feeChargesDue")));
+
+ // check for charge at specified date and installment fee
+ HashMap firstInstallment = loanSchedule.get(1);
+ validateNumberForEqual("31.51", String.valueOf(firstInstallment.get("feeChargesDue")));
+
+ // check for installment fee
+ HashMap secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("31.51", String.valueOf(secondInstallment.get("feeChargesDue")));
+
+ LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.approveLoan("20 September 2011", loanID);
+ LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
+ LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
+
+ LOG.info("-------------------------------DISBURSE LOAN-------------------------------------------");
+ String loanDetails = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanWithNetDisbursalAmount("20 September 2011", loanID,
+ JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
+ LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
+
+ final JournalEntry[] assetAccountInitialEntry = { new JournalEntry(Float.parseFloat("605.94"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("126.06"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("126.04"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("12000.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("12000.00"), JournalEntry.TransactionType.DEBIT) };
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 September 2011", assetAccountInitialEntry);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 September 2011",
+ new JournalEntry(Float.parseFloat("605.94"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("126.06"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("126.04"), JournalEntry.TransactionType.CREDIT));
+
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(
+ String.valueOf(amountPlusInterestPercentageSpecifiedDueDateCharge), "29 September 2011", "1"));
+
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(amountPlusInterestPercentageDisbursementCharge, loanCharges, "1", "0.0", "126.06", "0.0");
+ validateCharge(amountPlusInterestPercentageSpecifiedDueDateCharge, loanCharges, "1", "126.06", "0.0", "0.0");
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "29 September 2011",
+ new JournalEntry(Float.parseFloat("126.06"), JournalEntry.TransactionType.DEBIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "29 September 2011",
+ new JournalEntry(Float.parseFloat("126.06"), JournalEntry.TransactionType.CREDIT));
+
+ LOG.info("-------------Make repayment 1-----------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 October 2011", Float.parseFloat("3309.06"), loanID);
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(amountPlusInterestPercentageDisbursementCharge, loanCharges, "1", "0.00", "126.06", "0.0");
+ validateCharge(amountPlusInterestPercentageSpecifiedDueDateCharge, loanCharges, "1", "0.00", "126.06", "0.0");
+ validateCharge(amountPlusInterestPercentageInstallmentFee, loanCharges, "1", "94.53", "31.51", "0.0");
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("3309.06"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3309.06"), JournalEntry.TransactionType.CREDIT));
+
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(
+ String.valueOf(amountPlusInterestPercentageSpecifiedDueDateCharge), "29 October 2011", "1"));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("157.57", String.valueOf(secondInstallment.get("feeChargesDue")));
+ LOG.info("----------- Waive installment charge for 2nd installment ---------");
+ LOAN_TRANSACTION_HELPER.waiveChargesForLoan(loanID,
+ (Integer) getloanCharge(amountPlusInterestPercentageInstallmentFee, loanCharges).get("id"),
+ LoanTransactionHelper.getWaiveChargeJSON(String.valueOf(2)));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(amountPlusInterestPercentageInstallmentFee, loanCharges, "1", "63.02", "31.51", "31.51");
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("31.51"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForExpenseAccount(expenseAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("31.51"), JournalEntry.TransactionType.DEBIT));
+
+ LOG.info("----------Make repayment 2------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3277.55"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("3277.55"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3277.55"), JournalEntry.TransactionType.CREDIT));
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("0", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("--------------Waive interest---------------");
+ LOAN_TRANSACTION_HELPER.waiveInterest("20 December 2011", String.valueOf(61.79), loanID);
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap thirdInstallment = loanSchedule.get(3);
+ validateNumberForEqual("60.59", String.valueOf(thirdInstallment.get("interestOutstanding")));
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 December 2011",
+ new JournalEntry(Float.parseFloat("61.79"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForExpenseAccount(expenseAccount, "20 December 2011",
+ new JournalEntry(Float.parseFloat("61.79"), JournalEntry.TransactionType.DEBIT));
+
+ Integer amountPlusInterestPercentagePenaltySpecifiedDueDate = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1", true));
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(
+ String.valueOf(amountPlusInterestPercentagePenaltySpecifiedDueDate), "29 September 2011", "1"));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(amountPlusInterestPercentagePenaltySpecifiedDueDate, loanCharges, "1", "0.0", "120.0", "0.0");
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("120", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ // checking the journal entry as applied penalty has been collected
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("3309.06"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3309.06"), JournalEntry.TransactionType.CREDIT));
+
+ LOG.info("----------Make repayment 3 advance------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3303"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("3303"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3303"), JournalEntry.TransactionType.CREDIT));
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(
+ String.valueOf(amountPlusInterestPercentagePenaltySpecifiedDueDate), "10 January 2012", "1"));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap fourthInstallment = loanSchedule.get(4);
+ validateNumberForEqual("120", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
+ validateNumberForEqual("3241.19", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("----------Pay applied penalty ------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("120"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("120"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("120"), JournalEntry.TransactionType.CREDIT));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ fourthInstallment = loanSchedule.get(4);
+ validateNumberForEqual("0", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
+ validateNumberForEqual("3121.19", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("----------Make over payment for repayment 4 ------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("3221.61"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("3221.61"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3121.19"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForLiabilityAccount(overpaymentAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("100.42"), JournalEntry.TransactionType.CREDIT));
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.getLoanDetail(REQUEST_SPEC, RESPONSE_SPEC, loanID, "status");
+ LoanStatusChecker.verifyLoanAccountIsOverPaid(loanStatusHashMap);
+ }
+
+ /***
+ * Test case for checking AccuralPeriodicAccounting functionality adding charges with calculation type flat
+ */
+ @Test
+ public void loanWithFlatChargesAndPeriodicAccrualAccountingEnabled() throws InterruptedException {
+
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
+
+ // Add charges with payment mode regular
+ List charges = new ArrayList<>();
+ Integer flatDisbursement = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC, ChargesHelper.getLoanDisbursementJSON());
+ addCharges(charges, flatDisbursement, "100", null);
+ Integer flatSpecifiedDueDate = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, "100", false));
+ addCharges(charges, flatSpecifiedDueDate, "100", "29 September 2011");
+ Integer flatInstallmentFee = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanInstallmentJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, "50", false));
+ addCharges(charges, flatInstallmentFee, "50", null);
+
+ final Account assetAccount = ACCOUNT_HELPER.createAssetAccount();
+ final Account incomeAccount = ACCOUNT_HELPER.createIncomeAccount();
+ final Account expenseAccount = ACCOUNT_HELPER.createExpenseAccount();
+ final Account overpaymentAccount = ACCOUNT_HELPER.createLiabilityAccount();
+
+ List collaterals = new ArrayList<>();
+
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
+
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
+ String.valueOf(clientID), collateralId);
+ addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
+
+ final Integer loanProductID = createLoanProduct(false, ACCRUAL_PERIODIC, assetAccount, incomeAccount, expenseAccount,
+ overpaymentAccount);
+ final Integer loanID = applyForLoanApplication(clientID, loanProductID, charges, null, "12,000.00", collaterals);
+ Assertions.assertNotNull(loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
+
+ ArrayList loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ verifyLoanRepaymentSchedule(loanSchedule);
+
+ List loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(flatDisbursement, loanCharges, "100", "100.00", "0.0", "0.0");
+ validateCharge(flatSpecifiedDueDate, loanCharges, "100", "100.00", "0.0", "0.0");
+ validateCharge(flatInstallmentFee, loanCharges, "50", "200.00", "0.0", "0.0");
+
+ // check for disbursement fee
+ HashMap disbursementDetail = loanSchedule.get(0);
+ validateNumberForEqual("100.00", String.valueOf(disbursementDetail.get("feeChargesDue")));
+
+ // check for charge at specified date and installment fee
+ HashMap firstInstallment = loanSchedule.get(1);
+ validateNumberForEqual("150.00", String.valueOf(firstInstallment.get("feeChargesDue")));
+
+ // check for installment fee
+ HashMap secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("50.00", String.valueOf(secondInstallment.get("feeChargesDue")));
+
+ LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.approveLoan("20 September 2011", loanID);
+ LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
+ LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
+
+ LOG.info("-------------------------------DISBURSE LOAN-------------------------------------------");
+ String loanDetails = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanWithNetDisbursalAmount("20 September 2011", loanID,
+ JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
+ LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
+
+ final JournalEntry[] assetAccountInitialEntry = { new JournalEntry(Float.parseFloat("100.00"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("12000.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("12000.00"), JournalEntry.TransactionType.DEBIT) };
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 September 2011", assetAccountInitialEntry);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 September 2011",
+ new JournalEntry(Float.parseFloat("100.00"), JournalEntry.TransactionType.CREDIT));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(flatDisbursement, loanCharges, "100", "0.00", "100.0", "0.0");
+
+ LOG.info("-------------Make repayment 1-----------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 October 2011", Float.parseFloat("3301.49"), loanID);
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(flatDisbursement, loanCharges, "100", "0.00", "100.0", "0.0");
+ validateCharge(flatSpecifiedDueDate, loanCharges, "100", "0.00", "100.0", "0.0");
+ validateCharge(flatInstallmentFee, loanCharges, "50", "150.00", "50.0", "0.0");
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("3301.49"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3301.49"), JournalEntry.TransactionType.CREDIT));
+
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(flatSpecifiedDueDate), "29 October 2011", "100"));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("150.00", String.valueOf(secondInstallment.get("feeChargesDue")));
+ LOG.info("----------- Waive installment charge for 2nd installment ---------");
+ LOAN_TRANSACTION_HELPER.waiveChargesForLoan(loanID, (Integer) getloanCharge(flatInstallmentFee, loanCharges).get("id"),
+ LoanTransactionHelper.getWaiveChargeJSON(String.valueOf(2)));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(flatInstallmentFee, loanCharges, "50", "100.00", "50.0", "50.0");
+
+ /*
+ * JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount( assetAccount, "20 September 2011", new
+ * JournalEntry(Float.parseFloat("50.0"), JournalEntry.TransactionType.CREDIT));
+ * JOURNAL_ENTRY_HELPER.checkJournalEntryForExpenseAccount (expenseAccount, "20 September 2011", new
+ * JournalEntry(Float.parseFloat("50.0"), JournalEntry.TransactionType.DEBIT));
+ */
+ final String jobName = "Add Accrual Transactions";
+
+ SCHEDULER_JOB_HELPER.executeAndAwaitJob(jobName);
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ checkAccrualTransactions(loanSchedule, loanID);
+
+ LOG.info("----------Make repayment 2------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3251.49"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("3251.49"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3251.49"), JournalEntry.TransactionType.CREDIT));
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("0", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("--------------Waive interest---------------");
+ LOAN_TRANSACTION_HELPER.waiveInterest("20 December 2011", String.valueOf(61.79), loanID);
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap thirdInstallment = loanSchedule.get(3);
+ validateNumberForEqual("60.59", String.valueOf(thirdInstallment.get("interestOutstanding")));
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 December 2011",
+ new JournalEntry(Float.parseFloat("61.79"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForExpenseAccount(expenseAccount, "20 December 2011",
+ new JournalEntry(Float.parseFloat("61.79"), JournalEntry.TransactionType.DEBIT));
+
+ Integer flatPenaltySpecifiedDueDate = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, "100", true));
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(flatPenaltySpecifiedDueDate), "29 September 2011", "100"));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(flatPenaltySpecifiedDueDate, loanCharges, "100", "0.00", "100.0", "0.0");
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("100", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ // checking the journal entry as applied penalty has been collected
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("3301.49"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3301.49"), JournalEntry.TransactionType.CREDIT));
+
+ LOG.info("----------Make repayment 3 advance------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3301.49"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("3301.49"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3301.49"), JournalEntry.TransactionType.CREDIT));
+
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(flatPenaltySpecifiedDueDate), "10 January 2012", "100"));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap fourthInstallment = loanSchedule.get(4);
+ validateNumberForEqual("100", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
+ validateNumberForEqual("3239.68", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("----------Pay applied penalty ------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("100"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("100"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("100"), JournalEntry.TransactionType.CREDIT));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ fourthInstallment = loanSchedule.get(4);
+ validateNumberForEqual("0", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
+ validateNumberForEqual("3139.68", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("----------Make repayment 4 ------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("3139.68"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("3139.68"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3139.68"), JournalEntry.TransactionType.CREDIT));
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.getLoanDetail(REQUEST_SPEC, RESPONSE_SPEC, loanID, "status");
+ LoanStatusChecker.verifyLoanAccountIsClosed(loanStatusHashMap);
+ }
+
+ /**
+ * Test case for checking AccuralPeriodicAccounting functionality adding charges with calculation type percentage of
+ * amount
+ */
+ @Test
+ public void loanWithChargesOfTypeAmountPercentageAndPeriodicAccrualAccountingEnabled() throws InterruptedException {
+
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
+
+ // Add charges with payment mode regular
+ List charges = new ArrayList<>();
+ Integer percentageDisbursementCharge = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanDisbursementJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1"));
+ addCharges(charges, percentageDisbursementCharge, "1", null);
+
+ Integer percentageSpecifiedDueDateCharge = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1", false));
+ addCharges(charges, percentageSpecifiedDueDateCharge, "1", "29 September 2011");
+
+ Integer percentageInstallmentFee = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanInstallmentJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1", false));
+ addCharges(charges, percentageInstallmentFee, "1", "29 September 2011");
+
+ final Account assetAccount = ACCOUNT_HELPER.createAssetAccount();
+ final Account incomeAccount = ACCOUNT_HELPER.createIncomeAccount();
+ final Account expenseAccount = ACCOUNT_HELPER.createExpenseAccount();
+ final Account overpaymentAccount = ACCOUNT_HELPER.createLiabilityAccount();
+
+ List collaterals = new ArrayList<>();
+
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
+
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
+ String.valueOf(clientID), collateralId);
+ addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
+
+ final Integer loanProductID = createLoanProduct(false, ACCRUAL_PERIODIC, assetAccount, incomeAccount, expenseAccount,
+ overpaymentAccount);
+ final Integer loanID = applyForLoanApplication(clientID, loanProductID, charges, null, "12,000.00", collaterals);
+ Assertions.assertNotNull(loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
+
+ ArrayList loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ verifyLoanRepaymentSchedule(loanSchedule);
+
+ List loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(percentageDisbursementCharge, loanCharges, "1", "120.00", "0.0", "0.0");
+ validateCharge(percentageSpecifiedDueDateCharge, loanCharges, "1", "120.00", "0.0", "0.0");
+ validateCharge(percentageInstallmentFee, loanCharges, "1", "120.00", "0.0", "0.0");
+
+ // check for disbursement fee
+ HashMap disbursementDetail = loanSchedule.get(0);
+ validateNumberForEqual("120.00", String.valueOf(disbursementDetail.get("feeChargesDue")));
+
+ // check for charge at specified date and installment fee
+ HashMap firstInstallment = loanSchedule.get(1);
+ validateNumberForEqual("149.11", String.valueOf(firstInstallment.get("feeChargesDue")));
+
+ // check for installment fee
+ HashMap secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("29.70", String.valueOf(secondInstallment.get("feeChargesDue")));
+
+ LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.approveLoan("20 September 2011", loanID);
+ LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
+ LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
+
+ LOG.info("-------------------------------DISBURSE LOAN-------------------------------------------");
+ GlobalConfigurationHelper.manageConfigurations(REQUEST_SPEC, RESPONSE_SPEC,
+ GlobalConfigurationHelper.ENABLE_AUTOGENERATED_EXTERNAL_ID, true);
+ String loanDetails = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanWithNetDisbursalAmount("20 September 2011", loanID,
+ JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
+ LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
+
+ ArrayList loanTransactionDetails = LOAN_TRANSACTION_HELPER.getLoanTransactionDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ validateAccrualTransactionForDisbursementCharge(loanTransactionDetails);
+ final JournalEntry[] assetAccountInitialEntry = { new JournalEntry(Float.parseFloat("120.00"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("12000.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("12000.00"), JournalEntry.TransactionType.DEBIT) };
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 September 2011", assetAccountInitialEntry);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 September 2011",
+ new JournalEntry(Float.parseFloat("120.00"), JournalEntry.TransactionType.CREDIT));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(percentageDisbursementCharge, loanCharges, "1", "0.0", "120.00", "0.0");
+
+ LOG.info("-------------Make repayment 1-----------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 October 2011", Float.parseFloat("3300.60"), loanID);
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(percentageDisbursementCharge, loanCharges, "1", "0.00", "120.00", "0.0");
+ validateCharge(percentageSpecifiedDueDateCharge, loanCharges, "1", "0.00", "120.0", "0.0");
+ validateCharge(percentageInstallmentFee, loanCharges, "1", "90.89", "29.11", "0.0");
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("3300.60"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3300.60"), JournalEntry.TransactionType.CREDIT));
+
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(percentageSpecifiedDueDateCharge), "29 October 2011", "1"));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("149.70", String.valueOf(secondInstallment.get("feeChargesDue")));
+ LOG.info("----------- Waive installment charge for 2nd installment ---------");
+ LOAN_TRANSACTION_HELPER.waiveChargesForLoan(loanID, (Integer) getloanCharge(percentageInstallmentFee, loanCharges).get("id"),
+ LoanTransactionHelper.getWaiveChargeJSON(String.valueOf(2)));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(percentageInstallmentFee, loanCharges, "1", "61.19", "29.11", "29.70");
+
+ /*
+ * JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount( assetAccount, "20 September 2011", new
+ * JournalEntry(Float.parseFloat("29.7"), JournalEntry.TransactionType.CREDIT));
+ * JOURNAL_ENTRY_HELPER.checkJournalEntryForExpenseAccount (expenseAccount, "20 September 2011", new
+ * JournalEntry(Float.parseFloat("29.7"), JournalEntry.TransactionType.DEBIT));
+ */
+
+ final String jobName = "Add Accrual Transactions";
+
+ SCHEDULER_JOB_HELPER.executeAndAwaitJob(jobName);
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ checkAccrualTransactions(loanSchedule, loanID);
+
+ LOG.info("----------Make repayment 2------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3271.49"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("3271.49"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3271.49"), JournalEntry.TransactionType.CREDIT));
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("0", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("--------------Waive interest---------------");
+ LOAN_TRANSACTION_HELPER.waiveInterest("20 December 2011", String.valueOf(61.79), loanID);
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap thirdInstallment = loanSchedule.get(3);
+ validateNumberForEqual("60.59", String.valueOf(thirdInstallment.get("interestOutstanding")));
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 December 2011",
+ new JournalEntry(Float.parseFloat("61.79"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForExpenseAccount(expenseAccount, "20 December 2011",
+ new JournalEntry(Float.parseFloat("61.79"), JournalEntry.TransactionType.DEBIT));
+
+ Integer percentagePenaltySpecifiedDueDate = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1", true));
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(percentagePenaltySpecifiedDueDate), "29 September 2011", "1"));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(percentagePenaltySpecifiedDueDate, loanCharges, "1", "0.00", "120.0", "0.0");
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("120", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ // checking the journal entry as applied penalty has been collected
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("3300.60"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3300.60"), JournalEntry.TransactionType.CREDIT));
+
+ LOG.info("----------Make repayment 3 advance------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3301.78"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("3301.78"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3301.78"), JournalEntry.TransactionType.CREDIT));
+
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper
+ .getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(percentagePenaltySpecifiedDueDate), "10 January 2012", "1"));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap fourthInstallment = loanSchedule.get(4);
+ validateNumberForEqual("120", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
+ validateNumberForEqual("3240.58", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("----------Pay applied penalty ------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("120"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("120"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("120"), JournalEntry.TransactionType.CREDIT));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ fourthInstallment = loanSchedule.get(4);
+ validateNumberForEqual("0", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
+ validateNumberForEqual("3120.58", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("----------Make repayment 4 ------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("3120.58"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("3120.58"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3120.58"), JournalEntry.TransactionType.CREDIT));
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.getLoanDetail(REQUEST_SPEC, RESPONSE_SPEC, loanID, "status");
+ LoanStatusChecker.verifyLoanAccountIsClosed(loanStatusHashMap);
+ }
+
+ /***
+ * Test case for checking AccuralPeriodicAccounting functionality adding charges with calculation type percentage of
+ * amount and interest
+ */
+ @Test
+ public void loanWithChargesOfTypeAmountPlusInterestPercentageAndPeriodicAccrualAccountingEnabled() throws InterruptedException {
+
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
+
+ // Add charges with payment mode regular
+ List charges = new ArrayList<>();
+ Integer amountPlusInterestPercentageDisbursementCharge = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanDisbursementJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST, "1"));
+ addCharges(charges, amountPlusInterestPercentageDisbursementCharge, "1", null);
+
+ Integer amountPlusInterestPercentageSpecifiedDueDateCharge = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC, ChargesHelper
+ .getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST, "1", false));
+ addCharges(charges, amountPlusInterestPercentageSpecifiedDueDateCharge, "1", "29 September 2011");
+
+ Integer amountPlusInterestPercentageInstallmentFee = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanInstallmentJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST, "1", false));
+ addCharges(charges, amountPlusInterestPercentageInstallmentFee, "1", "29 September 2011");
+
+ final Account assetAccount = ACCOUNT_HELPER.createAssetAccount();
+ final Account incomeAccount = ACCOUNT_HELPER.createIncomeAccount();
+ final Account expenseAccount = ACCOUNT_HELPER.createExpenseAccount();
+ final Account overpaymentAccount = ACCOUNT_HELPER.createLiabilityAccount();
+
+ List collaterals = new ArrayList<>();
+
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
+ Assertions.assertNotNull(collateralId);
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
+ String.valueOf(clientID), collateralId);
+ Assertions.assertNotNull(clientCollateralId);
+ addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
+
+ final Integer loanProductID = createLoanProduct(false, ACCRUAL_PERIODIC, assetAccount, incomeAccount, expenseAccount,
+ overpaymentAccount);
+ final Integer loanID = applyForLoanApplication(clientID, loanProductID, charges, null, "12,000.00", collaterals);
+ Assertions.assertNotNull(loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
+
+ ArrayList loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ verifyLoanRepaymentSchedule(loanSchedule);
+
+ List loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(amountPlusInterestPercentageDisbursementCharge, loanCharges, "1", "126.06", "0.0", "0.0");
+ validateCharge(amountPlusInterestPercentageSpecifiedDueDateCharge, loanCharges, "1", "126.06", "0.0", "0.0");
+ validateCharge(amountPlusInterestPercentageInstallmentFee, loanCharges, "1", "126.04", "0.0", "0.0");
+
+ // check for disbursement fee
+ HashMap disbursementDetail = loanSchedule.get(0);
+ validateNumberForEqual("126.06", String.valueOf(disbursementDetail.get("feeChargesDue")));
+
+ // check for charge at specified date and installment fee
+ HashMap firstInstallment = loanSchedule.get(1);
+ validateNumberForEqual("157.57", String.valueOf(firstInstallment.get("feeChargesDue")));
+
+ // check for installment fee
+ HashMap secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("31.51", String.valueOf(secondInstallment.get("feeChargesDue")));
+
+ LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.approveLoan("20 September 2011", loanID);
+ LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
+ LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
+
+ LOG.info("-------------------------------DISBURSE LOAN-------------------------------------------");
+ String loanDetails = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanWithNetDisbursalAmount("20 September 2011", loanID,
+ JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
+ LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
+
+ final JournalEntry[] assetAccountInitialEntry = { new JournalEntry(Float.parseFloat("126.06"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("12000.00"), JournalEntry.TransactionType.CREDIT),
+ new JournalEntry(Float.parseFloat("12000.00"), JournalEntry.TransactionType.DEBIT) };
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 September 2011", assetAccountInitialEntry);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForIncomeAccount(incomeAccount, "20 September 2011",
+ new JournalEntry(Float.parseFloat("126.06"), JournalEntry.TransactionType.CREDIT));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(amountPlusInterestPercentageDisbursementCharge, loanCharges, "1", "0.0", "126.06", "0.0");
+
+ LOG.info("-------------Make repayment 1-----------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 October 2011", Float.parseFloat("3309.06"), loanID);
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(amountPlusInterestPercentageDisbursementCharge, loanCharges, "1", "0.00", "126.06", "0.0");
+ validateCharge(amountPlusInterestPercentageSpecifiedDueDateCharge, loanCharges, "1", "0.00", "126.06", "0.0");
+ validateCharge(amountPlusInterestPercentageInstallmentFee, loanCharges, "1", "94.53", "31.51", "0.0");
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("3309.06"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3309.06"), JournalEntry.TransactionType.CREDIT));
+
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(
+ String.valueOf(amountPlusInterestPercentageSpecifiedDueDateCharge), "29 October 2011", "1"));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("157.57", String.valueOf(secondInstallment.get("feeChargesDue")));
+ LOG.info("----------- Waive installment charge for 2nd installment ---------");
+ LOAN_TRANSACTION_HELPER.waiveChargesForLoan(loanID,
+ (Integer) getloanCharge(amountPlusInterestPercentageInstallmentFee, loanCharges).get("id"),
+ LoanTransactionHelper.getWaiveChargeJSON(String.valueOf(2)));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(amountPlusInterestPercentageInstallmentFee, loanCharges, "1", "63.02", "31.51", "31.51");
+
+ /*
+ * JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount( assetAccount, "20 September 2011", new JournalEntry(
+ * Float.parseFloat("31.51"), JournalEntry.TransactionType.CREDIT));
+ * JOURNAL_ENTRY_HELPER.checkJournalEntryForExpenseAccount (expenseAccount, "20 September 2011", new
+ * JournalEntry(Float.parseFloat("31.51"), JournalEntry.TransactionType.DEBIT));
+ */
+
+ final String jobName = "Add Accrual Transactions";
+
+ SCHEDULER_JOB_HELPER.executeAndAwaitJob(jobName);
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ checkAccrualTransactions(loanSchedule, loanID);
+
+ LOG.info("----------Make repayment 2------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3277.55"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("3277.55"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3277.55"), JournalEntry.TransactionType.CREDIT));
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("0", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("--------------Waive interest---------------");
+ LOAN_TRANSACTION_HELPER.waiveInterest("20 December 2011", String.valueOf(61.79), loanID);
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap thirdInstallment = loanSchedule.get(3);
+ validateNumberForEqual("60.59", String.valueOf(thirdInstallment.get("interestOutstanding")));
+
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 December 2011",
+ new JournalEntry(Float.parseFloat("61.79"), JournalEntry.TransactionType.CREDIT));
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForExpenseAccount(expenseAccount, "20 December 2011",
+ new JournalEntry(Float.parseFloat("61.79"), JournalEntry.TransactionType.DEBIT));
+
+ Integer amountPlusInterestPercentagePenaltySpecifiedDueDate = ChargesHelper.createCharges(REQUEST_SPEC, RESPONSE_SPEC,
+ ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1", true));
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(
+ String.valueOf(amountPlusInterestPercentagePenaltySpecifiedDueDate), "29 September 2011", "1"));
+ loanCharges.clear();
+ loanCharges = LOAN_TRANSACTION_HELPER.getLoanCharges(loanID);
+ validateCharge(amountPlusInterestPercentagePenaltySpecifiedDueDate, loanCharges, "1", "0.0", "120.0", "0.0");
+
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("120", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ // checking the journal entry as applied penalty has been collected
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011",
+ new JournalEntry(Float.parseFloat("3309.06"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3309.06"), JournalEntry.TransactionType.CREDIT));
+
+ LOG.info("----------Make repayment 3 advance------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3303"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
+ new JournalEntry(Float.parseFloat("3303"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3303"), JournalEntry.TransactionType.CREDIT));
+
+ LOAN_TRANSACTION_HELPER.addChargesForLoan(loanID, LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(
+ String.valueOf(amountPlusInterestPercentagePenaltySpecifiedDueDate), "10 January 2012", "1"));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap fourthInstallment = loanSchedule.get(4);
+ validateNumberForEqual("120", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
+ validateNumberForEqual("3241.19", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("----------Pay applied penalty ------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("120"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("120"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("120"), JournalEntry.TransactionType.CREDIT));
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ fourthInstallment = loanSchedule.get(4);
+ validateNumberForEqual("0", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
+ validateNumberForEqual("3121.19", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+
+ LOG.info("----------Make repayment 4 ------------");
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("3121.19"), loanID);
+ JOURNAL_ENTRY_HELPER.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012",
+ new JournalEntry(Float.parseFloat("3121.19"), JournalEntry.TransactionType.DEBIT),
+ new JournalEntry(Float.parseFloat("3121.19"), JournalEntry.TransactionType.CREDIT));
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.getLoanDetail(REQUEST_SPEC, RESPONSE_SPEC, loanID, "status");
+ LoanStatusChecker.verifyLoanAccountIsClosed(loanStatusHashMap);
+ }
+
+ @Test
+ public void testClientLoanScheduleWithCurrencyDetails() {
+
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
+
+ List collaterals = new ArrayList<>();
+
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
+
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
+ String.valueOf(clientID), collateralId);
+ addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
+
+ final Integer loanProductID = createLoanProduct("100", "0", LoanProductTestBuilder.DEFAULT_STRATEGY);
+ final Integer loanID = applyForLoanApplication(clientID, loanProductID, null, collaterals);
+ final ArrayList loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ verifyLoanRepaymentScheduleForEqualPrincipal(loanSchedule);
+
+ }
+
+ @Test
+ public void testClientLoanScheduleWithCurrencyDetails_with_grace() {
+
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
+
+ List collaterals = new ArrayList<>();
+
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
+
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
+ String.valueOf(clientID), collateralId);
+ addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
+
+ final Integer loanProductID = createLoanProduct("100", "0", LoanProductTestBuilder.DEFAULT_STRATEGY);
+ final Integer loanID = applyForLoanApplication(clientID, loanProductID, "5", collaterals);
+ final ArrayList loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ verifyLoanRepaymentScheduleForEqualPrincipalWithGrace(loanSchedule);
+
+ }
+
+ /***
+ * Test case to verify RBI payment strategy
+ */
+ @Test
+ public void testRBIPaymentStrategy() {
+
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
+
+ /***
+ * Create loan product with RBI strategy
+ */
+ final Integer loanProductID = createLoanProduct("100", "0", LoanProductTestBuilder.RBI_INDIA_STRATEGY);
+ Assertions.assertNotNull(loanProductID);
+
+ /***
+ * Apply for loan application and verify loan status
+ */
+ final String savingsId = null;
+ final String principal = "12,000.00";
+
+ List collaterals = new ArrayList<>();
+
+ final Integer collateralId = CollateralManagementHelper.createCollateralProduct(REQUEST_SPEC, RESPONSE_SPEC);
+
+ final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(REQUEST_SPEC, RESPONSE_SPEC,
+ String.valueOf(clientID), collateralId);
+ addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
+
+ final Integer loanID = applyForLoanApplicationWithPaymentStrategy(clientID, loanProductID, null, savingsId, principal,
+ LoanApplicationTestBuilder.RBI_INDIA_STRATEGY, collaterals);
+ Assertions.assertNotNull(loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
+
+ LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.approveLoan("20 September 2011", loanID);
+ LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
+ LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
+
+ LOG.info("-------------------------------DISBURSE LOAN-------------------------------------------");
+ String loanDetails = LOAN_TRANSACTION_HELPER.getLoanDetails(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ loanStatusHashMap = LOAN_TRANSACTION_HELPER.disburseLoanWithNetDisbursalAmount("20 September 2011", loanID,
+ JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
+ LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
+
+ ArrayList loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ HashMap firstInstallment = loanSchedule.get(1);
+ validateNumberForEqual("3200", String.valueOf(firstInstallment.get("totalOutstandingForPeriod")));
+
+ /***
+ * Make payment for installment #1
+ */
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 October 2011", Float.parseFloat("3200"), loanID);
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ firstInstallment = loanSchedule.get(1);
+ validateNumberForEqual("0.00", String.valueOf(firstInstallment.get("totalOutstandingForPeriod")));
+
+ /***
+ * Verify 2nd and 3rd repayments dues before making excess payment for installment no 2
+ */
+ HashMap secondInstallment = loanSchedule.get(2);
+ HashMap thirdInstallment = loanSchedule.get(3);
+
+ validateNumberForEqual("3200", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+ validateNumberForEqual("3200", String.valueOf(thirdInstallment.get("totalOutstandingForPeriod")));
+
+ validateNumberForEqual("3000", String.valueOf(secondInstallment.get("principalOutstanding")));
+ validateNumberForEqual("3100", String.valueOf(thirdInstallment.get("principalOutstanding")));
+
+ /***
+ * Make payment for installment #2
+ */
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 November 2011", Float.parseFloat("3200"), loanID);
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ /***
+ * Verify 2nd and 3rd repayments after making excess payment for installment no 2
+ */
+ secondInstallment = loanSchedule.get(2);
+ validateNumberForEqual("0.00", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
+
+ /***
+ * According to RBI Excess payment should go to principal portion of next installment, but as interest
+ * recalculation is not implemented, it wont make any difference to schedule even though if we made excess
+ * payment, so excess payments will behave the same as regular payment with the excess amount
+ */
+ thirdInstallment = loanSchedule.get(3);
+ validateNumberForEqual("3200", String.valueOf(thirdInstallment.get("totalOutstandingForPeriod")));
+ validateNumberForEqual("3100", String.valueOf(thirdInstallment.get("principalOutstanding")));
+ validateNumberForEqual("0", String.valueOf(thirdInstallment.get("principalPaid")));
+ validateNumberForEqual("0", String.valueOf(thirdInstallment.get("interestPaid")));
+ validateNumberForEqual("100.00", String.valueOf(thirdInstallment.get("interestOutstanding")));
+
+ /***
+ * Make payment with due amount of 3rd installment on 4th installment date
+ */
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("3200"), loanID);
+ loanSchedule.clear();
+ loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+
+ /***
+ * Verify overdue interests are deducted first and then remaining amount for interest portion of due installment
+ */
+ thirdInstallment = loanSchedule.get(3);
+ HashMap fourthInstallment = loanSchedule.get(4);
+
+ validateNumberForEqual("100", String.valueOf(thirdInstallment.get("totalOutstandingForPeriod")));
+ validateNumberForEqual("100", String.valueOf(thirdInstallment.get("principalOutstanding")));
+
+ validateNumberForEqual("2900", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
+ validateNumberForEqual("100", String.valueOf(fourthInstallment.get("interestPaid")));
+ validateNumberForEqual("0.00", String.valueOf(fourthInstallment.get("interestOutstanding")));
+
+ LOAN_TRANSACTION_HELPER.makeRepayment("20 January 2012", Float.parseFloat("3000"), loanID);
+
+ /***
+ * verify loan is closed as we paid full amount
+ */
+ loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ LoanStatusChecker.verifyLoanAccountIsClosed(loanStatusHashMap);
+
+ }
+
+ @Test
+ public void testLoanScheduleWithInterestRecalculation_WITH_REST_SAME_AS_REPAYMENT_INTEREST_COMPOUND_NONE_STRATEGY_REDUCE_EMI() {
+
+ DateFormat dateFormat = new SimpleDateFormat(DATETIME_PATTERN, Locale.US);
+ dateFormat.setTimeZone(Utils.getTimeZoneOfTenant());
+
+ Calendar todaysDate = Calendar.getInstance(Utils.getTimeZoneOfTenant());
+ todaysDate.add(Calendar.DAY_OF_MONTH, -14);
+ final String LOAN_DISBURSEMENT_DATE = dateFormat.format(todaysDate.getTime());
+
+ final Integer clientID = ClientHelper.createClient(REQUEST_SPEC, RESPONSE_SPEC);
+ ClientHelper.verifyClientCreatedOnServer(REQUEST_SPEC, RESPONSE_SPEC, clientID);
+ final Integer loanProductID = createLoanProductWithInterestRecalculation(LoanProductTestBuilder.DEFAULT_STRATEGY,
+ LoanProductTestBuilder.RECALCULATION_COMPOUNDING_METHOD_NONE,
+ LoanProductTestBuilder.RECALCULATION_STRATEGY_REDUCE_EMI_AMOUN,
+ LoanProductTestBuilder.RECALCULATION_FREQUENCY_TYPE_SAME_AS_REPAYMENT_PERIOD, "0", null,
+ LoanProductTestBuilder.INTEREST_APPLICABLE_STRATEGY_ON_PRE_CLOSE_DATE, null, null, null);
+
+ final Integer loanID = applyForLoanApplicationForInterestRecalculation(clientID, loanProductID, LOAN_DISBURSEMENT_DATE, null,
+ LoanApplicationTestBuilder.DEFAULT_STRATEGY, new ArrayList<>(0));
+
+ Assertions.assertNotNull(loanID);
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
+
+ ArrayList loanSchedule = LOAN_TRANSACTION_HELPER.getLoanRepaymentSchedule(REQUEST_SPEC, RESPONSE_SPEC, loanID);
+ List