Skip to content

Commit

Permalink
FINERACT-1806: Fix mapping to handle multiple loan product configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsaghy committed Jan 8, 2025
1 parent afc09b5 commit d2afd1a
Show file tree
Hide file tree
Showing 5 changed files with 636 additions and 576 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ List<ProductToGLAccountMapping> findAllPenaltyToIncomeAccountMappings(@Param("pr
List<ProductToGLAccountMapping> findAllChargeOffReasonsMappings(@Param("productId") Long productId,
@Param("productType") int productType);

@Query("select mapping from ProductToGLAccountMapping mapping where mapping.chargeOffReason.id =:chargeOffReasonId")
ProductToGLAccountMapping findChargeOffReasonMappingById(@Param("chargeOffReasonId") Long chargeOffReasonId);
@Query("select mapping from ProductToGLAccountMapping mapping where mapping.chargeOffReason.id =:chargeOffReasonId AND mapping.productId =:productId AND mapping.productType =:productType")
ProductToGLAccountMapping findChargeOffReasonMapping(@Param("productId") Long productId, @Param("productType") Integer productType,
@Param("chargeOffReasonId") Long chargeOffReasonId);

@Query("select mapping from ProductToGLAccountMapping mapping where mapping.productId =:productId AND mapping.productType =:productType AND mapping.charge IS NULL AND mapping.paymentType IS NULL AND mapping.chargeOffReason IS NULL")
List<ProductToGLAccountMapping> findAllRegularMappings(@Param("productId") Long productId, @Param("productType") Integer productType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ public LoanDTO populateLoanDtoFromMap(final Map<String, Object> accountingBridge
chargeOffReasonCodeValue);
}

public ProductToGLAccountMapping getChargeOffMappingByCodeValue(Long chargeOffReasonCodeValue) {
return accountMappingRepository.findChargeOffReasonMappingById(chargeOffReasonCodeValue);
public ProductToGLAccountMapping getChargeOffMappingByCodeValue(Long loanProductId, PortfolioProductType productType,
Long chargeOffReasonId) {
return accountMappingRepository.findChargeOffReasonMapping(loanProductId, productType.getValue(), chargeOffReasonId);
}

public SavingsDTO populateSavingsDtoFromMap(final Map<String, Object> accountingBridgeData, final boolean cashBasedAccountingEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.fineract.accounting.producttoaccountmapping.domain.ProductToGLAccountMapping;
import org.apache.fineract.infrastructure.core.service.MathUtil;
import org.apache.fineract.organisation.office.domain.Office;
import org.apache.fineract.portfolio.PortfolioProductType;
import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionEnumData;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -233,7 +234,7 @@ private void createJournalEntriesForChargeOff(LoanDTO loanDTO, LoanTransactionDT
Long chargeOffReasonCodeValue = loanDTO.getChargeOffReasonCodeValue();

ProductToGLAccountMapping mapping = chargeOffReasonCodeValue != null
? helper.getChargeOffMappingByCodeValue(chargeOffReasonCodeValue)
? helper.getChargeOffMappingByCodeValue(loanProductId, PortfolioProductType.LOAN, chargeOffReasonCodeValue)
: null;
if (mapping != null) {
GLAccount accountCredit = this.helper.getLinkedGLAccountForLoanProduct(loanProductId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.fineract.accounting.journalentry.service.AccrualBasedAccountingProcessorForLoan;
import org.apache.fineract.accounting.producttoaccountmapping.domain.ProductToGLAccountMapping;
import org.apache.fineract.organisation.office.domain.Office;
import org.apache.fineract.portfolio.PortfolioProductType;
import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionEnumData;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -48,7 +49,7 @@
@ExtendWith(MockitoExtension.class)
class CreateJournalEntriesForChargeOffLoanTest {

private static final Long chargeOffReasons = 15L;
private static final Long chargeOffReasonId = 15L;

@Mock
private AccountingProcessorHelper helper;
Expand All @@ -71,7 +72,7 @@ void setUp() {
transactionType, new BigDecimal("500.00"), new BigDecimal("500.00"), null, null, null, null, false, Collections.emptyList(),
Collections.emptyList(), false, "", null, null, null, null);

loanDTO = new LoanDTO(1L, 1L, 1L, "USD", false, true, true, List.of(loanTransactionDTO), false, false, chargeOffReasons);
loanDTO = new LoanDTO(1L, 1L, 1L, "USD", false, true, true, List.of(loanTransactionDTO), false, false, chargeOffReasonId);
}

@Test
Expand All @@ -84,7 +85,7 @@ void shouldCreateJournalEntriesForChargeOff() {
ProductToGLAccountMapping chargeToGLAccountMapper = new ProductToGLAccountMapping();
chargeToGLAccountMapper.setGlAccount(chargeOffGLAccount);

when(helper.getChargeOffMappingByCodeValue(chargeOffReasons)).thenReturn(chargeToGLAccountMapper);
when(helper.getChargeOffMappingByCodeValue(1L, PortfolioProductType.LOAN, chargeOffReasonId)).thenReturn(chargeToGLAccountMapper);

GLAccount loanPortfolioGLAccount = new GLAccount();
loanPortfolioGLAccount.setId(20L);
Expand All @@ -96,7 +97,7 @@ void shouldCreateJournalEntriesForChargeOff() {

processor.createJournalEntriesForLoan(loanDTO);

verify(helper, times(1)).getChargeOffMappingByCodeValue(chargeOffReasons);
verify(helper, times(1)).getChargeOffMappingByCodeValue(1L, PortfolioProductType.LOAN, chargeOffReasonId);
verify(helper, times(1)).getLinkedGLAccountForLoanProduct(1L, AccrualAccountsForLoan.LOAN_PORTFOLIO.getValue(), 1L);
verify(helper, times(1)).createCreditJournalEntryOrReversalForLoan(helper.getOfficeById(1L), "USD",
AccrualAccountsForLoan.LOAN_PORTFOLIO, 1L, null, 1L, "txn-123", LocalDate.now(ZoneId.systemDefault()),
Expand All @@ -110,7 +111,7 @@ void shouldCreateJournalEntriesForChargeOff() {
void shouldCreateJournalEntriesForChargeOffWithFraud() {
loanDTO.setMarkedAsFraud(true);

when(helper.getChargeOffMappingByCodeValue(chargeOffReasons)).thenReturn(null);
when(helper.getChargeOffMappingByCodeValue(1L, PortfolioProductType.LOAN, chargeOffReasonId)).thenReturn(null);

GLAccount loanPortfolioGLAccount = new GLAccount();
loanPortfolioGLAccount.setId(20L);
Expand Down Expand Up @@ -138,7 +139,7 @@ void shouldCreateJournalEntriesForChargeOffWithFraud() {
void shouldCreateJournalEntriesForChargeOffWithoutFraud() {
loanDTO.setMarkedAsFraud(false);

when(helper.getChargeOffMappingByCodeValue(chargeOffReasons)).thenReturn(null);
when(helper.getChargeOffMappingByCodeValue(1L, PortfolioProductType.LOAN, chargeOffReasonId)).thenReturn(null);

GLAccount loanPortfolioGLAccount = new GLAccount();
loanPortfolioGLAccount.setId(20L);
Expand Down
Loading

0 comments on commit d2afd1a

Please sign in to comment.