Skip to content

Commit

Permalink
FINERACT-1668: Adding Configuration for reversal transaction (#2454)
Browse files Browse the repository at this point in the history
Co-authored-by: Dhaval Maniyar <dhavalmaniyar@Dhavals-MacBook-Pro.local>
  • Loading branch information
2 people authored and vidakovic committed Aug 20, 2022
1 parent 251b125 commit edc734c
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,6 @@ public interface ConfigurationDomainService {
boolean isBusinessDateEnabled();

boolean isCOBDateAdjustmentEnabled();

boolean isReversalTransactionAllowed();
}
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,11 @@ public boolean isBusinessDateEnabled() {
public boolean isCOBDateAdjustmentEnabled() {
return getGlobalConfigurationPropertyData(ENABLE_AUTOMATIC_COB_DATE_ADJUSTMENT).isEnabled();
}

@Override
public boolean isReversalTransactionAllowed() {
final String propertyName = "enable-post-reversal-txns-for-reverse-transactions";
final GlobalConfigurationPropertyData property = getGlobalConfigurationPropertyData(propertyName);
return property.isEnabled();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public SavingsAccountTransaction handleRDDeposit(final RecurringDepositAccount a
final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
.isSavingsInterestPostingAtCurrentPeriodEnd();
final Integer financialYearBeginningMonth = this.configurationDomainService.retrieveFinancialYearBeginningMonth();

boolean isAccountTransfer = false;
final boolean isPreMatureClosure = false;
final MathContext mc = MathContext.DECIMAL64;
Expand Down Expand Up @@ -348,7 +347,7 @@ public Long handleRDAccountClosure(final RecurringDepositAccount account, final
final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
.isSavingsInterestPostingAtCurrentPeriodEnd();
final Integer financialYearBeginningMonth = this.configurationDomainService.retrieveFinancialYearBeginningMonth();

final boolean postReversals = false;
boolean isRegularTransaction = false;
boolean isAccountTransfer = false;
final boolean isPreMatureClosure = false;
Expand All @@ -364,7 +363,7 @@ public Long handleRDAccountClosure(final RecurringDepositAccount account, final
final DateTimeFormatter fmt = DateTimeFormatter.ofPattern(command.dateFormat()).withLocale(locale);
final LocalDate closedDate = command.localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName);
Long savingsTransactionId = null;
account.postMaturityInterest(isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, closedDate);
account.postMaturityInterest(isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, closedDate, postReversals);
final BigDecimal transactionAmount = account.getAccountBalance();
final Integer onAccountClosureId = command.integerValueOfParameterNamed(onAccountClosureIdParamName);
final DepositAccountOnClosureType onClosureType = DepositAccountOnClosureType.fromInt(onAccountClosureId);
Expand All @@ -385,7 +384,7 @@ public Long handleRDAccountClosure(final RecurringDepositAccount account, final
Integer frequency = CalendarUtils.getInterval(calendar.getRecurrence());
frequency = frequency == -1 ? 1 : frequency;
reinvestedDeposit.generateSchedule(frequencyType, frequency, calendar);
reinvestedDeposit.processAccountUponActivation(fmt, user);
reinvestedDeposit.processAccountUponActivation(fmt, user, postReversals);
reinvestedDeposit.updateMaturityDateAndAmount(mc, isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd,
financialYearBeginningMonth);
this.savingsAccountRepository.save(reinvestedDeposit);
Expand Down Expand Up @@ -520,7 +519,7 @@ public Long handleRDAccountPreMatureClosure(final RecurringDepositAccount accoun
final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
.isSavingsInterestPostingAtCurrentPeriodEnd();
final Integer financialYearBeginningMonth = this.configurationDomainService.retrieveFinancialYearBeginningMonth();

final boolean postReversals = false;
boolean isAccountTransfer = false;
final boolean isPreMatureClosure = true;
boolean isRegularTransaction = false;
Expand All @@ -537,7 +536,7 @@ public Long handleRDAccountPreMatureClosure(final RecurringDepositAccount accoun
Long savingsTransactionId = null;
// post interest
account.postPreMaturityInterest(closedDate, isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd,
financialYearBeginningMonth);
financialYearBeginningMonth, postReversals);

final Integer closureTypeValue = command.integerValueOfParameterNamed(DepositsApiConstants.onAccountClosureIdParamName);
DepositAccountOnClosureType closureType = DepositAccountOnClosureType.fromInt(closureTypeValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import javax.persistence.FetchType;
import javax.persistence.OneToOne;
import javax.persistence.Transient;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
Expand Down Expand Up @@ -77,6 +78,8 @@ public class FixedDepositAccount extends SavingsAccount {

@Transient
protected InterestRateChartAssembler chartAssembler;
@Transient
private ConfigurationDomainService configurationDomainService;

protected FixedDepositAccount() {
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ public void updateMaturityDateAndAmount(final MathContext mc, final boolean isPr
}
}

public void updateMaturityStatus(final boolean isSavingsInterestPostingAtCurrentPeriodEnd, final Integer financialYearBeginningMonth) {
public void updateMaturityStatus(final boolean isSavingsInterestPostingAtCurrentPeriodEnd, final Integer financialYearBeginningMonth,
final boolean postReversals) {
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
.resource(RECURRING_DEPOSIT_ACCOUNT_RESOURCE_NAME + SavingsApiConstants.updateMaturityDetailsAction);

final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
if (!SavingsAccountStatusType.ACTIVE.hasStateOf(currentStatus)) {
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("not.in.active.state");
Expand All @@ -287,7 +287,7 @@ public void updateMaturityStatus(final boolean isSavingsInterestPostingAtCurrent
if (!this.maturityDate().isAfter(todayDate)) {
// update account status
this.status = SavingsAccountStatusType.MATURED.getValue();
postMaturityInterest(isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, todayDate);
postMaturityInterest(isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, todayDate, postReversals);
}
}

Expand Down Expand Up @@ -537,7 +537,7 @@ public Money activateWithBalance() {
return Money.of(this.currency, this.minRequiredOpeningBalance);
}

protected void processAccountUponActivation(final DateTimeFormatter fmt, final AppUser user) {
protected void processAccountUponActivation(final DateTimeFormatter fmt, final AppUser user, final boolean postReversals) {
final Money minRequiredOpeningBalance = Money.of(this.currency, this.minRequiredOpeningBalance);
final boolean backdatedTxnsAllowedTill = false;
String refNo = null;
Expand All @@ -549,7 +549,6 @@ protected void processAccountUponActivation(final DateTimeFormatter fmt, final A

// update existing transactions so derived balance fields are
// correct.
boolean postReversals = false;
recalculateDailyBalances(Money.zero(this.currency), DateUtils.getBusinessLocalDate(), backdatedTxnsAllowedTill, postReversals);
}
}
Expand Down Expand Up @@ -635,7 +634,7 @@ public void close(final AppUser currentUser, final JsonCommand command, final Lo
}

public void postMaturityInterest(final boolean isSavingsInterestPostingAtCurrentPeriodEnd, final Integer financialYearBeginningMonth,
final LocalDate closeDate) {
final LocalDate closeDate, final boolean postReversals) {
LocalDate interestPostingUpToDate = maturityDate();
if (interestPostingUpToDate == null) {
interestPostingUpToDate = closeDate;
Expand All @@ -645,7 +644,6 @@ public void postMaturityInterest(final boolean isSavingsInterestPostingAtCurrent
boolean isInterestTransfer = false;
LocalDate postInterestOnDate = null;
final boolean backdatedTxnsAllowedTill = false;
boolean postReversals = false;
final List<PostingPeriod> postingPeriods = calculateInterestUsing(mc, interestPostingUpToDate.minusDays(1), isInterestTransfer,
isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, postInterestOnDate, backdatedTxnsAllowedTill,
postReversals);
Expand Down Expand Up @@ -690,7 +688,7 @@ public void postMaturityInterest(final boolean isSavingsInterestPostingAtCurrent
}

public void postPreMaturityInterest(final LocalDate accountCloseDate, final boolean isPreMatureClosure,
final boolean isSavingsInterestPostingAtCurrentPeriodEnd, final Integer financialYearBeginningMonth) {
final boolean isSavingsInterestPostingAtCurrentPeriodEnd, final Integer financialYearBeginningMonth, boolean postReversals) {

final Money interestPostedToDate = totalInterestPosted();
// calculate interest before one day of closure date
Expand All @@ -713,7 +711,6 @@ public void postPreMaturityInterest(final LocalDate accountCloseDate, final bool
}

applyWithholdTaxForDepositAccounts(accountCloseDate, recalucateDailyBalance, backdatedTxnsAllowedTill);
boolean postReversals = false;
if (recalucateDailyBalance) {
// update existing transactions so derived balance fields are
// correct.
Expand Down Expand Up @@ -755,11 +752,11 @@ private Money calculatePreMatureInterest(final LocalDate preMatureDate, final Li
return interestOnMaturity;
}

@Override
public void postInterest(final MathContext mc, final LocalDate postingDate, final boolean isInterestTransfer,
final boolean isSavingsInterestPostingAtCurrentPeriodEnd, final Integer financialYearBeginningMonth,
final LocalDate postInterestAson, final boolean backdatedTxnsAllowedTill) {
final LocalDate postInterestAson, final boolean backdatedTxnsAllowedTill, final boolean postReversals) {
final LocalDate interestPostingUpToDate = interestPostingUpToDate(postingDate);
boolean postReversals = false;
super.postInterest(mc, interestPostingUpToDate, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd,
financialYearBeginningMonth, postInterestAson, backdatedTxnsAllowedTill, postReversals);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,6 @@ protected List<SavingsAccountTransaction> retreiveListOfTransactions() {

protected void recalculateDailyBalances(final Money openingAccountBalance, final LocalDate interestPostingUpToDate,
final boolean backdatedTxnsAllowedTill, boolean postReversals) {

Money runningBalance = openingAccountBalance.copy();

List<SavingsAccountTransaction> accountTransactionsSorted = null;
Expand Down Expand Up @@ -2775,6 +2774,7 @@ public void approveAndActivateApplication(final LocalDate appliedonDate, final A
private void payActivationCharges(final boolean isSavingsInterestPostingAtCurrentPeriodEnd, final Integer financialYearBeginningMonth,
final AppUser user, final boolean backdatedTxnsAllowedTill) {
boolean isSavingsChargeApplied = false;
boolean postReversals = false;
UUID refNo = UUID.randomUUID();
for (SavingsAccountCharge savingsAccountCharge : this.charges()) {
if (savingsAccountCharge.isSavingsActivation()) {
Expand All @@ -2788,7 +2788,6 @@ private void payActivationCharges(final boolean isSavingsInterestPostingAtCurren
final MathContext mc = MathContext.DECIMAL64;
boolean isInterestTransfer = false;
LocalDate postInterestAsOnDate = null;
boolean postReversals = false;
if (this.isBeforeLastPostingPeriod(getActivationLocalDate(), backdatedTxnsAllowedTill)) {
final LocalDate today = DateUtils.getBusinessLocalDate();
this.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth,
Expand Down Expand Up @@ -3551,12 +3550,12 @@ public void escheat(AppUser appUser) {
this.closedOnDate = DateUtils.getBusinessLocalDate();
this.closedBy = appUser;
boolean postInterestAsOnDate = false;
boolean postReversals = false;
LocalDate transactionDate = DateUtils.getBusinessLocalDate();
if (this.getSummary().getAccountBalance(this.getCurrency()).isGreaterThanZero()) {
SavingsAccountTransaction transaction = SavingsAccountTransaction.escheat(this, transactionDate, appUser, postInterestAsOnDate);
this.transactions.add(transaction);
}
boolean postReversals = false;
recalculateDailyBalances(Money.zero(this.currency), transactionDate, false, postReversals);
this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public SavingsAccountTransaction handleWithdrawal(final SavingsAccount account,
final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
.isSavingsInterestPostingAtCurrentPeriodEnd();
final Long relaxingDaysConfigForPivotDate = this.configurationDomainService.retrieveRelaxingDaysConfigForPivotDate();
final boolean postReversals = this.configurationDomainService.isReversalTransactionAllowed();
final Integer financialYearBeginningMonth = this.configurationDomainService.retrieveFinancialYearBeginningMonth();
if (transactionBooleanValues.isRegularTransaction() && !account.allowWithdrawal()) {
throw new DepositAccountTransactionNotAllowedException(account.getId(), "withdraw", account.depositAccountType());
Expand All @@ -115,7 +116,7 @@ public SavingsAccountTransaction handleWithdrawal(final SavingsAccount account,
final MathContext mc = MathContext.DECIMAL64;

final LocalDate today = DateUtils.getBusinessLocalDate();
boolean postReversals = false;

if (account.isBeforeLastPostingPeriod(transactionDate, backdatedTxnsAllowedTill)) {
account.postInterest(mc, today, transactionBooleanValues.isInterestTransfer(), isSavingsInterestPostingAtCurrentPeriodEnd,
financialYearBeginningMonth, postInterestOnDate, backdatedTxnsAllowedTill, postReversals);
Expand Down Expand Up @@ -202,7 +203,7 @@ private SavingsAccountTransaction handleDeposit(final SavingsAccount account, fi
final MathContext mc = MathContext.DECIMAL64;

final LocalDate today = DateUtils.getBusinessLocalDate();
boolean postReversals = false;
boolean postReversals = this.configurationDomainService.isReversalTransactionAllowed();
if (account.isBeforeLastPostingPeriod(transactionDate, backdatedTxnsAllowedTill)) {
account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth,
postInterestOnDate, backdatedTxnsAllowedTill, postReversals);
Expand Down Expand Up @@ -297,6 +298,7 @@ public SavingsAccountTransaction handleReversal(SavingsAccount account, List<Sav
.isSavingsInterestPostingAtCurrentPeriodEnd();
final Integer financialYearBeginningMonth = this.configurationDomainService.retrieveFinancialYearBeginningMonth();
final Long relaxingDaysConfigForPivotDate = this.configurationDomainService.retrieveRelaxingDaysConfigForPivotDate();
final boolean postReversals = true;
final Set<Long> existingTransactionIds = new HashSet<>();
final Set<Long> existingReversedTransactionIds = new HashSet<>();

Expand All @@ -314,15 +316,16 @@ public SavingsAccountTransaction handleReversal(SavingsAccount account, List<Sav
chargePaidBySet = savingsAccountTransaction.getSavingsAccountChargesPaid();
reversal.getSavingsAccountChargesPaid().addAll(chargePaidBySet);
account.undoTransaction(savingsAccountTransaction);
newTransactions.add(reversal);
if (postReversals) {
newTransactions.add(reversal);
}
}

boolean isInterestTransfer = false;
LocalDate postInterestOnDate = null;
final LocalDate today = DateUtils.getBusinessLocalDate();
final MathContext mc = new MathContext(15, MoneyHelper.getRoundingMode());
for (SavingsAccountTransaction savingsAccountTransaction : savingsAccountTransactions) {
boolean postReversals = true;
if (savingsAccountTransaction.isPostInterestCalculationRequired()
&& account.isBeforeLastPostingPeriod(savingsAccountTransaction.transactionLocalDate(), backdatedTxnsAllowedTill)) {

Expand Down
Loading

0 comments on commit edc734c

Please sign in to comment.