Skip to content

Commit

Permalink
FINERACT-2081: Refactor GL account balance calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsaghy committed Nov 26, 2024
1 parent dcb18d8 commit 5c001b4
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.accounting.journalentry.data;

import jakarta.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.LinkedHashMap;
import java.util.Map;
import lombok.Data;
import org.apache.fineract.accounting.glaccount.domain.GLAccount;

@Data
public class GLAccountBalanceHolder {

private final Map<Long, GLAccount> glAccountMap = new LinkedHashMap<>();
private final Map<Long, BigDecimal> debitBalances = new LinkedHashMap<>();
private final Map<Long, BigDecimal> creditBalances = new LinkedHashMap<>();

public void addToCredit(@NotNull GLAccount accountCredit, @NotNull BigDecimal transactionPartAmount) {
getGlAccountMap().putIfAbsent(accountCredit.getId(), accountCredit);
if (getCreditBalances().containsKey(accountCredit.getId())) {
BigDecimal amount = getCreditBalances().get(accountCredit.getId()).add(transactionPartAmount);
getCreditBalances().put(accountCredit.getId(), amount);
} else {
getCreditBalances().put(accountCredit.getId(), transactionPartAmount);
}
}

public void addToDebit(@NotNull GLAccount accountDebit, @NotNull BigDecimal transactionPartAmount) {
getGlAccountMap().putIfAbsent(accountDebit.getId(), accountDebit);
if (getDebitBalances().containsKey(accountDebit.getId())) {
BigDecimal amount = getDebitBalances().get(accountDebit.getId()).add(transactionPartAmount);
getDebitBalances().put(accountDebit.getId(), amount);
} else {
getDebitBalances().put(accountDebit.getId(), transactionPartAmount);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,16 @@ public void createDebitJournalEntryOrReversalForLoan(final Office office, final
}
}

public void createDebitJournalEntryOrReversalForLoan(final Office office, final String currencyCode, final Long loanId,
final String transactionId, final LocalDate transactionDate, final BigDecimal amount, final Boolean isReversal,
final GLAccount account) {
if (isReversal) {
createCreditJournalEntryForLoan(office, currencyCode, account, loanId, transactionId, transactionDate, amount);
} else {
createDebitJournalEntryForLoan(office, currencyCode, account, loanId, transactionId, transactionDate, amount);
}
}

public void createDebitJournalEntryOrReversalForLoanCharges(final Office office, final String currencyCode,
final int accountMappingTypeId, final Long loanProductId, final Long chargeId, final Long loanId, final String transactionId,
final LocalDate transactionDate, final BigDecimal amount, final Boolean isReversal) {
Expand Down
Loading

0 comments on commit 5c001b4

Please sign in to comment.