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 0a11c8f
Show file tree
Hide file tree
Showing 38 changed files with 1,416 additions and 102 deletions.
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_WITH_INCOME_POSTED_AS_TRANSACTIONS("Add 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
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,16 @@ else if (savingsTransactionDTO.getTransactionType().isInterestPosting()) {
else if (savingsTransactionDTO.getTransactionType().isAccrual()) {
// Post journal entry for Accrual Recognition
if (savingsTransactionDTO.getAmount().compareTo(BigDecimal.ZERO) > 0) {
this.helper.createCashBasedJournalEntriesAndReversalsForSavings(office, currencyCode,
AccrualAccountsForSavings.INTEREST_ON_SAVINGS.getValue(), AccrualAccountsForSavings.INTEREST_PAYABLE.getValue(),
savingsProductId, paymentTypeId, savingsId, transactionId, transactionDate, amount, isReversal);
if (feePayments.size() > 0 || penaltyPayments.size() > 0) {
this.helper.createCashBasedJournalEntriesAndReversalsForSavings(office, currencyCode,
AccrualAccountsForSavings.FEES_RECEIVABLE.getValue(), AccrualAccountsForSavings.INCOME_FROM_FEES.getValue(),
savingsProductId, paymentTypeId, savingsId, transactionId, transactionDate, amount, isReversal);
} else {
this.helper.createCashBasedJournalEntriesAndReversalsForSavings(office, currencyCode,
AccrualAccountsForSavings.INTEREST_ON_SAVINGS.getValue(),
AccrualAccountsForSavings.INTEREST_PAYABLE.getValue(), savingsProductId, paymentTypeId, savingsId,
transactionId, transactionDate, amount, isReversal);
}
}
}

Expand All @@ -205,35 +212,45 @@ else if (savingsTransactionDTO.getTransactionType().isFeeDeduction() && savingsT
savingsProductId, paymentTypeId, savingsId, transactionId, transactionDate, overdraftAmount, isReversal,
penaltyPayments);
if (isPositive) {
final ChargePaymentDTO chargePaymentDTO = penaltyPayments.get(0);
AccrualAccountsForSavings accountTypeToBeDebited = AccrualAccountsForSavings.SAVINGS_CONTROL;

this.helper.createAccrualBasedJournalEntriesAndReversalsForSavingsCharges(office, currencyCode,
AccrualAccountsForSavings.SAVINGS_CONTROL, AccrualAccountsForSavings.INCOME_FROM_PENALTIES,
savingsProductId, paymentTypeId, savingsId, transactionId, transactionDate,
amount.subtract(overdraftAmount), isReversal, penaltyPayments);
accountTypeToBeDebited, AccrualAccountsForSavings.INCOME_FROM_PENALTIES, savingsProductId, paymentTypeId,
savingsId, transactionId, transactionDate, amount.subtract(overdraftAmount), isReversal, penaltyPayments);
}
} else {
this.helper.createAccrualBasedJournalEntriesAndReversalsForSavingsCharges(office, currencyCode,
AccrualAccountsForSavings.OVERDRAFT_PORTFOLIO_CONTROL, AccrualAccountsForSavings.INCOME_FROM_FEES,
savingsProductId, paymentTypeId, savingsId, transactionId, transactionDate, overdraftAmount, isReversal,
feePayments);
if (isPositive) {
final ChargePaymentDTO chargePaymentDTO = feePayments.get(0);
AccrualAccountsForSavings accountTypeToBeDebited = AccrualAccountsForSavings.SAVINGS_CONTROL;

this.helper.createAccrualBasedJournalEntriesAndReversalsForSavingsCharges(office, currencyCode,
AccrualAccountsForSavings.SAVINGS_CONTROL, AccrualAccountsForSavings.INCOME_FROM_FEES, savingsProductId,
paymentTypeId, savingsId, transactionId, transactionDate, amount.subtract(overdraftAmount), isReversal,
feePayments);
accountTypeToBeDebited, AccrualAccountsForSavings.INCOME_FROM_FEES, savingsProductId, paymentTypeId,
savingsId, transactionId, transactionDate, amount.subtract(overdraftAmount), isReversal, feePayments);
}
}
}

else if (savingsTransactionDTO.getTransactionType().isFeeDeduction()) {
// Is the Charge a penalty?
if (penaltyPayments.size() > 0) {
final ChargePaymentDTO chargePaymentDTO = penaltyPayments.get(0);
AccrualAccountsForSavings accountTypeToBeCredited = AccrualAccountsForSavings.INCOME_FROM_PENALTIES;

this.helper.createAccrualBasedJournalEntriesAndReversalsForSavingsCharges(office, currencyCode,
AccrualAccountsForSavings.SAVINGS_CONTROL, AccrualAccountsForSavings.INCOME_FROM_PENALTIES, savingsProductId,
paymentTypeId, savingsId, transactionId, transactionDate, amount, isReversal, penaltyPayments);
AccrualAccountsForSavings.SAVINGS_CONTROL, accountTypeToBeCredited, savingsProductId, paymentTypeId, savingsId,
transactionId, transactionDate, amount, isReversal, penaltyPayments);
} else {
final ChargePaymentDTO chargePaymentDTO = feePayments.get(0);
AccrualAccountsForSavings accountTypeToBeCredited = AccrualAccountsForSavings.INCOME_FROM_PENALTIES;

this.helper.createAccrualBasedJournalEntriesAndReversalsForSavingsCharges(office, currencyCode,
AccrualAccountsForSavings.SAVINGS_CONTROL, AccrualAccountsForSavings.INCOME_FROM_FEES, savingsProductId,
paymentTypeId, savingsId, transactionId, transactionDate, amount, isReversal, feePayments);
AccrualAccountsForSavings.SAVINGS_CONTROL, accountTypeToBeCredited, savingsProductId, paymentTypeId, savingsId,
transactionId, transactionDate, amount, isReversal, feePayments);
}
}

Expand Down
Loading

0 comments on commit 0a11c8f

Please sign in to comment.