adamsaghy commented on code in PR #4837:
URL: https://github.com/apache/fineract/pull/4837#discussion_r2213103043
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountDomainServiceJpa.java:
##########
@@ -326,8 +331,277 @@ public SavingsAccountTransaction
handleReversal(SavingsAccount account, List<Sav
this.savingsAccountRepository.save(account);
newTransactions.addAll(account.getSavingsAccountTransactionsWithPivotConfig());
this.savingsAccountTransactionRepository.saveAll(newTransactions);
- postJournalEntries(account, existingTransactionIds,
existingReversedTransactionIds, false, backdatedTxnsAllowedTill);
+ postJournalEntries(account, existingTransactionIds,
existingReversedTransactionIds, false, backdatedTxnsAllowedTill, false);
return reversal;
}
+
+ @Override
+ public void postInterest(SavingsAccount account, final MathContext mc,
final LocalDate interestPostingUpToDate,
+ final boolean isInterestTransfer, final boolean
isSavingsInterestPostingAtCurrentPeriodEnd,
+ final Integer financialYearBeginningMonth, final LocalDate
postInterestOnDate, final boolean backdatedTxnsAllowedTill,
+ final boolean postReversals) {
+ final List<PostingPeriod> postingPeriods =
account.calculateInterestUsing(mc, interestPostingUpToDate, isInterestTransfer,
+ isSavingsInterestPostingAtCurrentPeriodEnd,
financialYearBeginningMonth, postInterestOnDate, backdatedTxnsAllowedTill,
+ postReversals);
+ log.debug("postInterest {}", postingPeriods.size());
+
+ MonetaryCurrency currency = account.getCurrency();
+ Money interestPostedToDate = Money.zero(currency);
+
+ if (backdatedTxnsAllowedTill) {
+ interestPostedToDate = Money.of(currency,
account.getSummary().getTotalInterestPosted());
+ }
+
+ boolean recalucateDailyBalanceDetails = false;
+ boolean applyWithHoldTax =
account.isWithHoldTaxApplicableForInterestPosting();
+ final List<SavingsAccountTransaction> withholdTransactions = new
ArrayList<>();
+
+ if (backdatedTxnsAllowedTill) {
+
withholdTransactions.addAll(account.findWithHoldSavingsTransactionsWithPivotConfig());
+ } else {
+ withholdTransactions.addAll(account.findWithHoldTransactions());
+ }
+
+ for (final PostingPeriod interestPostingPeriod : postingPeriods) {
+ log.debug(" period: {}",
interestPostingPeriod.dateOfPostingTransaction());
+
+ final LocalDate interestPostingTransactionDate =
interestPostingPeriod.dateOfPostingTransaction();
+ final Money interestEarnedToBePostedForPeriod =
interestPostingPeriod.getInterestEarned();
+ log.debug(" interestEarnedToBePostedForPeriod: {}",
interestEarnedToBePostedForPeriod.toString());
+
+ if
(!interestPostingTransactionDate.isAfter(interestPostingUpToDate)) {
+ interestPostedToDate =
interestPostedToDate.plus(interestEarnedToBePostedForPeriod);
+
+ SavingsAccountTransaction postingTransaction = null;
+ if (backdatedTxnsAllowedTill) {
+ postingTransaction =
account.findInterestPostingSavingsTransactionWithPivotConfig(interestPostingTransactionDate);
+ } else {
+ postingTransaction =
account.findInterestPostingTransactionFor(interestPostingTransactionDate);
+ }
+ if (postingTransaction == null) {
+ SavingsAccountTransaction newPostingTransaction = null;
+ if
(interestEarnedToBePostedForPeriod.isGreaterThanOrEqualTo(Money.zero(currency)))
{
+ if
(interestEarnedToBePostedForPeriod.isGreaterThan(Money.zero(currency))) {
+ newPostingTransaction =
SavingsAccountTransaction.interestPosting(account, account.office(),
+ interestPostingTransactionDate,
interestEarnedToBePostedForPeriod,
+ interestPostingPeriod.isUserPosting());
+ }
+ } else {
+ newPostingTransaction =
SavingsAccountTransaction.overdraftInterest(account, account.office(),
+ interestPostingTransactionDate,
interestEarnedToBePostedForPeriod.negated(),
+ interestPostingPeriod.isUserPosting());
+ }
+ if (newPostingTransaction != null) {
+ if (backdatedTxnsAllowedTill) {
+
account.addTransactionToExisting(newPostingTransaction);
+ } else {
+ account.addTransaction(newPostingTransaction);
+ }
+ if
(account.savingsProduct().isAccrualBasedAccountingEnabled()) {
+ if
(MathUtil.isGreaterThanZero(interestEarnedToBePostedForPeriod)) {
+ SavingsAccountTransaction accrualTransaction =
SavingsAccountTransaction.accrual(account, account.office(),
+ interestPostingTransactionDate,
interestEarnedToBePostedForPeriod,
+ interestPostingPeriod.isUserPosting(),
false);
+ if (backdatedTxnsAllowedTill) {
+
account.addTransactionToExisting(accrualTransaction);
+ } else {
+ account.addTransaction(accrualTransaction);
+ }
+ } else {
+ log.info("Accrual for Overdraft interest");
+ }
+ }
+ if (applyWithHoldTax) {
+
account.createWithHoldTransaction(interestEarnedToBePostedForPeriod.getAmount(),
interestPostingTransactionDate,
+ backdatedTxnsAllowedTill);
+ }
+ }
+ recalucateDailyBalanceDetails = true;
+ } else {
+ boolean correctionRequired = false;
+ if (postingTransaction.isInterestPostingAndNotReversed()) {
+ correctionRequired =
postingTransaction.hasNotAmount(interestEarnedToBePostedForPeriod);
+ } else {
+ correctionRequired =
postingTransaction.hasNotAmount(interestEarnedToBePostedForPeriod.negated());
+ }
+ log.debug(" correctionRequired {}", correctionRequired);
+ if (correctionRequired) {
+ boolean applyWithHoldTaxForOldTransaction = false;
+ postingTransaction.reverse();
+ SavingsAccountTransaction reversal = null;
+ if (postReversals) {
+ reversal =
SavingsAccountTransaction.reversal(postingTransaction);
+ }
+ final SavingsAccountTransaction withholdTransaction =
account.findTransactionFor(interestPostingTransactionDate,
+ withholdTransactions);
+ if (withholdTransaction != null) {
+ withholdTransaction.reverse();
+ applyWithHoldTaxForOldTransaction = true;
+ }
+ SavingsAccountTransaction newPostingTransaction;
+ if
(interestEarnedToBePostedForPeriod.isGreaterThanOrEqualTo(Money.zero(currency)))
{
+ newPostingTransaction =
SavingsAccountTransaction.interestPosting(account, account.office(),
+ interestPostingTransactionDate,
interestEarnedToBePostedForPeriod,
+ interestPostingPeriod.isUserPosting());
+ } else {
+ newPostingTransaction =
SavingsAccountTransaction.overdraftInterest(account, account.office(),
+ interestPostingTransactionDate,
interestEarnedToBePostedForPeriod.negated(),
+ interestPostingPeriod.isUserPosting());
+ }
+ if (backdatedTxnsAllowedTill) {
+
account.addTransactionToExisting(newPostingTransaction);
+ if (reversal != null) {
+ account.addTransactionToExisting(reversal);
+ }
+ } else {
+ account.addTransaction(newPostingTransaction);
+ if (reversal != null) {
+ account.addTransaction(reversal);
+ }
+ }
+ if
(account.savingsProduct().isAccrualBasedAccountingEnabled()
+ &&
MathUtil.isGreaterThanZero(interestEarnedToBePostedForPeriod)) {
+ log.info("TX2: {}",
interestEarnedToBePostedForPeriod.getAmount());
+ SavingsAccountTransaction accrualTransaction =
SavingsAccountTransaction.accrual(account, account.office(),
+ interestPostingTransactionDate,
interestEarnedToBePostedForPeriod,
+ interestPostingPeriod.isUserPosting(),
false);
+ if (backdatedTxnsAllowedTill) {
+
account.addTransactionToExisting(accrualTransaction);
+ } else {
+ account.addTransaction(accrualTransaction);
+ }
+ } else {
+ log.info("Accrual for Overdraft2 interest");
Review Comment:
No info level logging please! Also "Overdraft2"??
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]