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-2081: Refactor GL account balance calculation #4189

Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* 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 creditAccount, @NotNull BigDecimal amount) {
addToProperBalance(creditBalances, creditAccount, amount);
}

public void addToDebit(@NotNull GLAccount debitAccount, @NotNull BigDecimal amount) {
addToProperBalance(debitBalances, debitAccount, amount);
}

private void addToProperBalance(@NotNull Map<Long, BigDecimal> balanceMap, @NotNull @NotNull GLAccount account,
@NotNull BigDecimal amount) {
glAccountMap.putIfAbsent(account.getId(), account);
if (balanceMap.containsKey(account.getId())) {
BigDecimal totalAmount = balanceMap.get(account.getId()).add(amount);
balanceMap.put(account.getId(), totalAmount);
} else {
balanceMap.put(account.getId(), amount);
}
}
}
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
Loading