Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FINERACT-1960: Accrual Transactions For Savings batch job - Interest #3973

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why to remove this?

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it support accrued fee and penalty as well no?

"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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont we need accrued fee and penalty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Accrual Fee mainly will be in other PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering whether it would be better to send support for fee and penalty as well in the same PR or disable the job till it is not complete. THoughts?


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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THis will be incorrect the moment accrual will be done for fee and penalties as well. I think we should immediately use the interest portion here, instead of the transaction amount.

}
}
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch! :)

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
Loading