Skip to content

Commit

Permalink
FINERACT-1806: Rework Product to GL account mapping and fix charge-of…
Browse files Browse the repository at this point in the history
…f reason typos
  • Loading branch information
adamsaghy committed Dec 17, 2024
1 parent e89a232 commit 6f3d751
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,22 @@ List<ProductToGLAccountMapping> findAllPenaltyToIncomeAccountMappings(@Param("pr
List<ProductToGLAccountMapping> findByProductIdAndProductType(Long productId, int productType);

@Query("select mapping from ProductToGLAccountMapping mapping where mapping.productId =:productId and mapping.productType =:productType and mapping.chargeOffReason is not NULL")
List<ProductToGLAccountMapping> findAllChargesOffReasonsMappings(@Param("productId") Long productId,
List<ProductToGLAccountMapping> findAllChargeOffReasonsMappings(@Param("productId") Long productId,
@Param("productType") int productType);

@Query("select mapping from ProductToGLAccountMapping mapping where mapping.chargeOffReason.id =:chargeOffReasonId")
ProductToGLAccountMapping findChargesOffReasonMappingById(@Param("chargeOffReasonId") Integer chargeOffReasonId);
ProductToGLAccountMapping findChargeOffReasonMappingById(@Param("chargeOffReasonId") Integer chargeOffReasonId);

List<ProductToGLAccountMapping> findAllByProductIdAndProductTypeAndPaymentTypeIsNullAndChargeIsNull(Long productId,
Integer productType);
@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);

List<ProductToGLAccountMapping> findAllByProductIdAndProductTypeAndChargeOffReasonIdIsNotNull(Long productId, Integer productType);
@Query("select mapping from ProductToGLAccountMapping mapping where mapping.productId =:productId and mapping.productType =:productType and mapping.paymentType is not NULL")
List<ProductToGLAccountMapping> findAllPaymentTypeMappings(@Param("productId") Long productId,
@Param("productType") Integer productType);

List<ProductToGLAccountMapping> findAllByProductIdAndProductTypeAndPaymentTypeIsNotNull(Long productId, Integer productType);
@Query("select mapping from ProductToGLAccountMapping mapping where mapping.productId =:productId AND mapping.productType =:productType AND mapping.charge.penalty = TRUE")
List<ProductToGLAccountMapping> findAllPenaltyMappings(@Param("productId") Long productId, @Param("productType") Integer productType);

List<ProductToGLAccountMapping> findAllByProductIdAndProductTypeAndCharge_PenaltyAndCharge_IdIsNotNull(Long productId,
Integer productType, boolean isPenalty);
@Query("select mapping from ProductToGLAccountMapping mapping where mapping.productId =:productId AND mapping.productType =:productType AND mapping.charge.penalty = FALSE")
List<ProductToGLAccountMapping> findAllFeeMappings(@Param("productId") Long productId, @Param("productType") Integer productType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public void saveChargesToGLAccountMappings(final JsonCommand command, final Json
public void saveChargeOffReasonToGLAccountMappings(final JsonCommand command, final JsonElement element, final Long productId,
final Map<String, Object> changes, final PortfolioProductType portfolioProductType) {

final String arrayName = LoanProductAccountingParams.CHARGE_OFF_REASONS_TO_EXPENSE.getValue();
final String arrayName = LoanProductAccountingParams.CHARGE_OFF_REASON_TO_EXPENSE_ACCOUNT_MAPPINGS.getValue();
final JsonArray chargeOffReasonToExpenseAccountMappingArray = this.fromApiJsonHelper.extractJsonArrayNamed(arrayName, element);

if (chargeOffReasonToExpenseAccountMappingArray != null) {
Expand Down Expand Up @@ -388,17 +388,17 @@ public void updateChargeOffReasonToGLAccountMappings(final JsonCommand command,
final Map<String, Object> changes, final PortfolioProductType portfolioProductType) {

final List<ProductToGLAccountMapping> existingChargeOffReasonToGLAccountMappings = this.accountMappingRepository
.findAllChargesOffReasonsMappings(productId, portfolioProductType.getValue());
.findAllChargeOffReasonsMappings(productId, portfolioProductType.getValue());
final JsonArray chargeOffReasonToGLAccountMappingArray = this.fromApiJsonHelper
.extractJsonArrayNamed(LoanProductAccountingParams.CHARGE_OFF_REASONS_TO_EXPENSE.getValue(), element);
.extractJsonArrayNamed(LoanProductAccountingParams.CHARGE_OFF_REASON_TO_EXPENSE_ACCOUNT_MAPPINGS.getValue(), element);

final Map<Long, Long> inputChargeOffReasonToGLAccountMap = new HashMap<>();

final Set<Long> existingChargeOffReasons = new HashSet<>();
if (chargeOffReasonToGLAccountMappingArray != null) {
if (changes != null) {
changes.put(LoanProductAccountingParams.CHARGE_OFF_REASONS_TO_EXPENSE.getValue(),
command.jsonFragment(LoanProductAccountingParams.CHARGE_OFF_REASONS_TO_EXPENSE.getValue()));
changes.put(LoanProductAccountingParams.CHARGE_OFF_REASON_TO_EXPENSE_ACCOUNT_MAPPINGS.getValue(),
command.jsonFragment(LoanProductAccountingParams.CHARGE_OFF_REASON_TO_EXPENSE_ACCOUNT_MAPPINGS.getValue()));
}

for (int i = 0; i < chargeOffReasonToGLAccountMappingArray.size(); i++) {
Expand Down Expand Up @@ -495,7 +495,7 @@ private void saveChargeOffReasonToExpenseMapping(final Long productId, final Lon
final Optional<GLAccount> glAccount = accountRepository.findById(expenseAccountId);

final boolean reasonMappingExists = this.accountMappingRepository
.findAllChargesOffReasonsMappings(productId, portfolioProductType.getValue()).stream()
.findAllChargeOffReasonsMappings(productId, portfolioProductType.getValue()).stream()
.anyMatch(mapping -> mapping.getChargeOffReason().getId().equals(reasonId));

final Optional<CodeValue> codeValueOptional = codeValueRepository.findById(reasonId);
Expand Down Expand Up @@ -577,7 +577,7 @@ public void validateChargeOffMappingsInDatabase(final List<JsonObject> mappings)
if (codeValue == null) {
validationErrors.add(ApiParameterError.parameterError("validation.msg.chargeoffreason.invalid",
"Charge-off reason with ID " + chargeOffReasonCodeValueId + " does not exist",
LoanProductAccountingParams.CHARGE_OFF_REASONS_TO_EXPENSE.getValue()));
LoanProductAccountingParams.CHARGE_OFF_REASON_TO_EXPENSE_ACCOUNT_MAPPINGS.getValue()));
}

// Validation: expenseGLAccountId must exist as a valid Expense GL account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public Map<String, Object> fetchAccountMappingDetailsForLoanProduct(final Long l

final Map<String, Object> accountMappingDetails = new LinkedHashMap<>(8);

final List<ProductToGLAccountMapping> mappings = productToGLAccountMappingRepository
.findAllByProductIdAndProductTypeAndPaymentTypeIsNullAndChargeIsNull(loanProductId, PortfolioProductType.LOAN.getValue());
final List<ProductToGLAccountMapping> mappings = productToGLAccountMappingRepository.findAllRegularMappings(loanProductId,
PortfolioProductType.LOAN.getValue());

if (AccountingValidations.isCashBasedAccounting(accountingType)) {

Expand Down Expand Up @@ -178,9 +178,8 @@ public Map<String, Object> fetchAccountMappingDetailsForLoanProduct(final Long l
@Override
public Map<String, Object> fetchAccountMappingDetailsForSavingsProduct(final Long savingsProductId, final Integer accountingType) {

final List<ProductToGLAccountMapping> mappings = productToGLAccountMappingRepository
.findAllByProductIdAndProductTypeAndPaymentTypeIsNullAndChargeIsNull(savingsProductId,
PortfolioProductType.SAVING.getValue());
final List<ProductToGLAccountMapping> mappings = productToGLAccountMappingRepository.findAllRegularMappings(savingsProductId,
PortfolioProductType.SAVING.getValue());

Map<String, Object> accountMappingDetails = null;
if (AccountingValidations.isCashBasedAccounting(accountingType)) {
Expand Down Expand Up @@ -210,14 +209,11 @@ public List<PaymentTypeToGLAccountMapper> fetchPaymentTypeToFundSourceMappingsFo
*/
private List<PaymentTypeToGLAccountMapper> fetchPaymentTypeToFundSourceMappings(final PortfolioProductType portfolioProductType,
final Long loanProductId) {
final List<ProductToGLAccountMapping> mappings = productToGLAccountMappingRepository
.findAllByProductIdAndProductTypeAndPaymentTypeIsNotNull(loanProductId, portfolioProductType.getValue());
final List<ProductToGLAccountMapping> mappings = productToGLAccountMappingRepository.findAllPaymentTypeMappings(loanProductId,
portfolioProductType.getValue());

List<PaymentTypeToGLAccountMapper> paymentTypeToGLAccountMappers = null;
List<PaymentTypeToGLAccountMapper> paymentTypeToGLAccountMappers = mappings.isEmpty() ? null : new ArrayList<>();
for (final ProductToGLAccountMapping mapping : mappings) {
if (paymentTypeToGLAccountMappers == null) {
paymentTypeToGLAccountMappers = new ArrayList<>();
}
final PaymentTypeData paymentTypeData = PaymentTypeData.instance(mapping.getPaymentType().getId(),
mapping.getPaymentType().getName());
final GLAccountData gLAccountData = new GLAccountData().setId(mapping.getGlAccount().getId())
Expand Down Expand Up @@ -252,14 +248,12 @@ public List<ChargeToGLAccountMapper> fetchPenaltyToIncomeAccountMappingsForSavin

private List<ChargeToGLAccountMapper> fetchChargeToIncomeAccountMappings(final PortfolioProductType portfolioProductType,
final Long loanProductId, final boolean penalty) {
final List<ProductToGLAccountMapping> mappings = productToGLAccountMappingRepository
.findAllByProductIdAndProductTypeAndCharge_PenaltyAndCharge_IdIsNotNull(loanProductId, portfolioProductType.getValue(),
penalty);
List<ChargeToGLAccountMapper> chargeToGLAccountMappers = null;
final List<ProductToGLAccountMapping> mappings = penalty
? productToGLAccountMappingRepository.findAllPenaltyMappings(loanProductId, portfolioProductType.getValue())
: productToGLAccountMappingRepository.findAllFeeMappings(loanProductId, portfolioProductType.getValue());

List<ChargeToGLAccountMapper> chargeToGLAccountMappers = mappings.isEmpty() ? null : new ArrayList<>();
for (final ProductToGLAccountMapping mapping : mappings) {
if (chargeToGLAccountMappers == null) {
chargeToGLAccountMappers = new ArrayList<>();
}
final GLAccountData gLAccountData = new GLAccountData().setId(mapping.getGlAccount().getId())
.setName(mapping.getGlAccount().getName()).setGlCode(mapping.getGlAccount().getGlCode());
final ChargeData chargeData = ChargeData.builder().id(mapping.getCharge().getId()).name(mapping.getCharge().getName())
Expand All @@ -273,13 +267,10 @@ private List<ChargeToGLAccountMapper> fetchChargeToIncomeAccountMappings(final P

private List<ChargeOffReasonToGLAccountMapper> fetchChargeOffReasonMappings(final PortfolioProductType portfolioProductType,
final Long loanProductId) {
final List<ProductToGLAccountMapping> mappings = productToGLAccountMappingRepository
.findAllByProductIdAndProductTypeAndChargeOffReasonIdIsNotNull(loanProductId, portfolioProductType.getValue());
List<ChargeOffReasonToGLAccountMapper> chargeOffReasonToGLAccountMappers = null;
final List<ProductToGLAccountMapping> mappings = productToGLAccountMappingRepository.findAllChargeOffReasonsMappings(loanProductId,
portfolioProductType.getValue());
List<ChargeOffReasonToGLAccountMapper> chargeOffReasonToGLAccountMappers = mappings.isEmpty() ? null : new ArrayList<>();
for (final ProductToGLAccountMapping mapping : mappings) {
if (chargeOffReasonToGLAccountMappers == null) {
chargeOffReasonToGLAccountMappers = new ArrayList<>();
}
final Long glAccountId = mapping.getGlAccount().getId();
final String glAccountName = mapping.getGlAccount().getName();
final String glCode = mapping.getGlAccount().getGlCode();
Expand All @@ -294,7 +285,7 @@ private List<ChargeOffReasonToGLAccountMapper> fetchChargeOffReasonMappings(fina
.description(codeDescription).position(orderPosition).active(isActive).mandatory(isMandatory).build();

final ChargeOffReasonToGLAccountMapper chargeOffReasonToGLAccountMapper = new ChargeOffReasonToGLAccountMapper()
.setChargeOffReasonsCodeValue(chargeOffReasonsCodeValue).setChargeOffExpenseAccount(chargeOffExpenseAccount);
.setChargeOffReasonCodeValue(chargeOffReasonsCodeValue).setChargeOffExpenseAccount(chargeOffExpenseAccount);
chargeOffReasonToGLAccountMappers.add(chargeOffReasonToGLAccountMapper);
}
return chargeOffReasonToGLAccountMappers;
Expand All @@ -305,8 +296,8 @@ public Map<String, Object> fetchAccountMappingDetailsForShareProduct(Long produc

final Map<String, Object> accountMappingDetails = new LinkedHashMap<>(8);

final List<ProductToGLAccountMapping> mappings = productToGLAccountMappingRepository
.findAllByProductIdAndProductTypeAndPaymentTypeIsNullAndChargeIsNull(productId, PortfolioProductType.SHARES.getValue());
final List<ProductToGLAccountMapping> mappings = productToGLAccountMappingRepository.findAllRegularMappings(productId,
PortfolioProductType.SHARES.getValue());

if (AccountingRuleType.CASH_BASED.getValue().equals(accountingType)) {
for (final ProductToGLAccountMapping mapping : mappings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public enum LoanProductAccountingParams {
INCOME_FROM_GOODWILL_CREDIT_INTEREST("incomeFromGoodwillCreditInterestAccountId"), //
INCOME_FROM_GOODWILL_CREDIT_FEES("incomeFromGoodwillCreditFeesAccountId"), //
INCOME_FROM_GOODWILL_CREDIT_PENALTY("incomeFromGoodwillCreditPenaltyAccountId"), //
CHARGE_OFF_REASONS_TO_EXPENSE("chargeOffReasonsToExpenseMappings"), //
CHARGE_OFF_REASON_TO_EXPENSE_ACCOUNT_MAPPINGS("chargeOffReasonToExpenseAccountMappings"), //
EXPENSE_GL_ACCOUNT_ID("expenseGLAccountId"), //
CHARGE_OFF_REASON_CODE_VALUE_ID("chargeOffReasonCodeValueId"); //

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
public class ChargeOffReasonToGLAccountMapper implements Serializable {

private static final long serialVersionUID = 1L;
private CodeValueData chargeOffReasonsCodeValue;
private CodeValueData chargeOffReasonCodeValue;
private GLAccountData chargeOffExpenseAccount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private PostLoanProductsRequest() {}
public Long incomeFromGoodwillCreditPenaltyAccountId;
public List<GetLoanProductsProductIdResponse.GetLoanPaymentChannelToFundSourceMappings> paymentChannelToFundSourceMappings;
public List<GetLoanProductsProductIdResponse.GetLoanFeeToIncomeAccountMappings> feeToIncomeAccountMappings;
public List<PostChargeOffReasonsToExpenseMappings> chargeOffReasonsToExpenseMappings;
public List<PostChargeOffReasonToExpenseAccountMappings> chargeOffReasonToExpenseAccountMappings;
public List<ChargeToGLAccountMapper> penaltyToIncomeAccountMappings;

// Multi Disburse
Expand Down Expand Up @@ -326,9 +326,9 @@ private RateData() {}
@Schema(example = "REGULAR")
public String chargeOffBehaviour;

static final class PostChargeOffReasonsToExpenseMappings {
static final class PostChargeOffReasonToExpenseAccountMappings {

private PostChargeOffReasonsToExpenseMappings() {}
private PostChargeOffReasonToExpenseAccountMappings() {}

@Schema(example = "1")
public Long chargeOffReasonCodeValueId;
Expand Down Expand Up @@ -1229,9 +1229,9 @@ private GetLoanPaymentChannelToFundSourceMappings() {}
public Long fundSourceAccountId;
}

static final class GetChargeOffReasonsToExpenseMappings {
static final class GetChargeOffReasonToExpenseAccountMappings {

private GetChargeOffReasonsToExpenseMappings() {}
private GetChargeOffReasonToExpenseAccountMappings() {}

public GetCodeValueData chargeOffReasonCodeValue;
public GetGLAccountData chargeOffExpenseAccount;
Expand Down Expand Up @@ -1376,7 +1376,7 @@ private GetLoanCharge() {}
public GetLoanAccountingMappings accountingMappings;
public Set<GetLoanPaymentChannelToFundSourceMappings> paymentChannelToFundSourceMappings;
public Set<GetLoanFeeToIncomeAccountMappings> feeToIncomeAccountMappings;
public Set<GetChargeOffReasonsToExpenseMappings> chargeOffReasonToGLAccountMappings;
public List<GetChargeOffReasonToExpenseAccountMappings> chargeOffReasonToExpenseAccountMappings;
@Schema(example = "false")
public Boolean isRatesEnabled;
@Schema(example = "true")
Expand Down Expand Up @@ -1636,7 +1636,7 @@ private PutLoanProductsProductIdRequest() {}
public Long incomeFromChargeOffPenaltyAccountId;
public List<GetLoanProductsProductIdResponse.GetLoanPaymentChannelToFundSourceMappings> paymentChannelToFundSourceMappings;
public List<GetLoanProductsProductIdResponse.GetLoanFeeToIncomeAccountMappings> feeToIncomeAccountMappings;
public List<PostLoanProductsRequest.PostChargeOffReasonsToExpenseMappings> chargeOffReasonsToExpenseMappings;
public List<PostLoanProductsRequest.PostChargeOffReasonToExpenseAccountMappings> chargeOffReasonToExpenseAccountMappings;
public List<ChargeToGLAccountMapper> penaltyToIncomeAccountMappings;
@Schema(example = "false")
public Boolean enableAccrualActivityPosting;
Expand Down
Loading

0 comments on commit 6f3d751

Please sign in to comment.