Skip to content

Commit

Permalink
FINERACT-1960: Accrual Transactions For Savings batch job
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Alberto Hernandez authored and Jose Alberto Hernandez committed Jul 16, 2024
1 parent 6c4932b commit a99c79b
Show file tree
Hide file tree
Showing 40 changed files with 1,447 additions and 177 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ plugins {
id 'org.asciidoctor.jvm.pdf' version '3.3.2' apply false
id 'org.asciidoctor.jvm.epub' version '3.3.2' apply false
id 'org.asciidoctor.jvm.revealjs' version '3.3.2' apply false
id 'org.asciidoctor.jvm.gems' version '3.3.2' apply false
id 'org.asciidoctor.kindlegen.base' version '3.2.0' apply false
id 'com.google.cloud.tools.jib' version '3.4.2' apply false
id 'org.sonarqube' version '4.4.1.3373'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@
"null",
"string"
]
},
{
"default": null,
"name": "accruedTillDate",
"type": [
"null",
"string"
]
},
{
"default": null,
"name": "totalInterestAccrued",
"type": [
"null",
"bigdecimal"
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public enum JobName {
SEND_ASYNCHRONOUS_EVENTS("Send Asynchronous Events"), //
PURGE_EXTERNAL_EVENTS("Purge External Events"), //
PURGE_PROCESSED_COMMANDS("Purge Processed Commands"), //
ADD_PERIODIC_ACCRUAL_ENTRIES_FOR_SAVINGS("Add Periodic Accrual Transactions for Savings"); //
;

private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ public class SavingsAccountSummaryData implements Serializable {
private LocalDate interestPostedTillDate;
private LocalDate prevInterestPostedTillDate;
private transient BigDecimal runningBalanceOnInterestPostingTillDate = BigDecimal.ZERO;
private LocalDate accruedTillDate;
private BigDecimal totalInterestAccrued;

public SavingsAccountSummaryData(final CurrencyData currency, final BigDecimal totalDeposits, final BigDecimal totalWithdrawals,
final BigDecimal totalWithdrawalFees, final BigDecimal totalAnnualFees, final BigDecimal totalInterestEarned,
final BigDecimal totalInterestPosted, final BigDecimal accountBalance, final BigDecimal totalFeeCharge,
final BigDecimal totalPenaltyCharge, final BigDecimal totalOverdraftInterestDerived, final BigDecimal totalWithholdTax,
final BigDecimal interestNotPosted, final LocalDate lastInterestCalculationDate, final BigDecimal availableBalance,
final LocalDate interestPostedTillDate) {
final LocalDate interestPostedTillDate, final LocalDate accruedTillDate) {
this.currency = currency;
this.totalDeposits = totalDeposits;
this.totalWithdrawals = totalWithdrawals;
Expand All @@ -79,6 +81,7 @@ public SavingsAccountSummaryData(final CurrencyData currency, final BigDecimal t
this.lastInterestCalculationDate = lastInterestCalculationDate;
this.availableBalance = availableBalance;
this.interestPostedTillDate = interestPostedTillDate;
this.accruedTillDate = accruedTillDate;
}

public void setPrevInterestPostedTillDate(LocalDate interestPostedTillDate) {
Expand Down Expand Up @@ -255,6 +258,7 @@ public void updateSummary(final CurrencyData currency, final SavingsAccountTrans
this.totalPenaltyCharge = wrapper.calculateTotalPenaltyChargeWaived(currency, transactions);
this.totalOverdraftInterestDerived = wrapper.calculateTotalOverdraftInterest(currency, transactions);
this.totalWithholdTax = wrapper.calculateTotalWithholdTaxWithdrawal(currency, transactions);
this.totalInterestAccrued = wrapper.calculateTotalInterestAccrued(currency, transactions);

// boolean isUpdated = false;
updateRunningBalanceAndPivotDate(false, transactions, null, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,10 @@ public boolean isWithHoldTaxAndNotReversed() {
return SavingsAccountTransactionType.fromInt(this.transactionType.getId().intValue()).isWithHoldTax() && isNotReversed();
}

public boolean isAccrual() {
return this.transactionType.isAccrual();
}

public boolean isNotReversed() {
return !isReversed();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,15 @@ public BigDecimal calculateTotalWithholdTaxWithdrawal(CurrencyData currency, Lis
}
return total.getAmountDefaultedToNullIfZero();
}

public BigDecimal calculateTotalInterestAccrued(CurrencyData currency, List<SavingsAccountTransactionData> transactions) {
Money total = Money.zero(currency);
for (final SavingsAccountTransactionData transaction : transactions) {
if (transaction.isAccrual() && !transaction.isReversalTransaction()) {
total = total.plus(transaction.getAmount());
}
}
return total.getAmountDefaultedToNullIfZero();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,13 @@ public SavingsDTO populateSavingsDtoFromMap(final Map<String, Object> accounting
if (map.containsKey("savingsChargesPaid")) {
@SuppressWarnings("unchecked")
final List<Map<String, Object>> savingsChargesPaidData = (List<Map<String, Object>>) map.get("savingsChargesPaid");
for (final Map<String, Object> loanChargePaid : savingsChargesPaidData) {
final Long chargeId = (Long) loanChargePaid.get("chargeId");
final Long loanChargeId = (Long) loanChargePaid.get("savingsChargeId");
final boolean isPenalty = (Boolean) loanChargePaid.get("isPenalty");
final BigDecimal chargeAmountPaid = (BigDecimal) loanChargePaid.get("amount");
for (final Map<String, Object> savingsChargesPaid : savingsChargesPaidData) {
final Long chargeId = (Long) savingsChargesPaid.get("chargeId");
final Long loanChargeId = (Long) savingsChargesPaid.get("savingsChargeId");
final boolean isPenalty = (Boolean) savingsChargesPaid.get("isPenalty");
final BigDecimal chargeAmountPaid = (BigDecimal) savingsChargesPaid.get("amount");
final ChargePaymentDTO chargePaymentDTO = new ChargePaymentDTO(chargeId, chargeAmountPaid, loanChargeId);

if (isPenalty) {
penaltyPayments.add(chargePaymentDTO);
} else {
Expand Down Expand Up @@ -602,6 +603,21 @@ public void createAccrualBasedJournalEntriesAndReversalsForSavingsTax(final Offi
savingsProductId, paymentTypeId, savingsId, transactionId, transactionDate, amount, isReversal);
}

public void createAccrualBasedJournalEntriesAndReversalsForSavings(final Office office, final String currencyCode,
final Integer accountTypeToBeDebited, final Integer accountTypeToBeCredited, final Long savingsProductId,
final Long paymentTypeId, final Long loanId, final String transactionId, final LocalDate transactionDate,
final BigDecimal amount, final Boolean isReversal) {
int accountTypeToDebitId = accountTypeToBeDebited;
int accountTypeToCreditId = accountTypeToBeCredited;
// reverse debits and credits for reversals
if (isReversal) {
accountTypeToDebitId = accountTypeToBeCredited;
accountTypeToCreditId = accountTypeToBeDebited;
}
createJournalEntriesForSavings(office, currencyCode, accountTypeToDebitId, accountTypeToCreditId, savingsProductId, paymentTypeId,
loanId, transactionId, transactionDate, amount);
}

public void createCashBasedDebitJournalEntriesAndReversalsForSavings(final Office office, final String currencyCode,
final Integer accountTypeToBeDebited, final Long savingsProductId, final Long paymentTypeId, final Long savingsId,
final String transactionId, final LocalDate transactionDate, final BigDecimal amount, final Boolean isReversal) {
Expand Down
Loading

0 comments on commit a99c79b

Please sign in to comment.