Skip to content
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
Expand Up @@ -167,8 +167,18 @@ public void savePaymentChannelToFundSourceMappings(final JsonCommand command, fi
}
for (int i = 0; i < paymentChannelMappingArray.size(); i++) {
final JsonObject jsonObject = paymentChannelMappingArray.get(i).getAsJsonObject();
final Long paymentTypeId = jsonObject.get(LoanProductAccountingParams.PAYMENT_TYPE.getValue()).getAsLong();
final Long paymentSpecificFundAccountId = jsonObject.get(LoanProductAccountingParams.FUND_SOURCE.getValue()).getAsLong();
JsonElement jsonPaymentTypeId = jsonObject.get(LoanProductAccountingParams.PAYMENT_TYPE.getValue());
JsonElement jsonElementFoundId = jsonObject.get(LoanProductAccountingParams.FUND_SOURCE.getValue());
if (jsonPaymentTypeId == null) {
throw new PlatformApiDataValidationException("payment.type.id.is.mandatory", "field: paymentTypeId is mandatory",
LoanProductAccountingParams.PAYMENT_TYPE.getValue());
}
if (jsonElementFoundId == null) {
throw new PlatformApiDataValidationException("fund.source.account.id.is.mandatory",
"field: fundSourceAccountId is mandatory", LoanProductAccountingParams.FUND_SOURCE.getValue());
}
final Long paymentTypeId = jsonPaymentTypeId.getAsLong();
final Long paymentSpecificFundAccountId = jsonElementFoundId.getAsLong();
savePaymentChannelToFundSourceMapping(productId, paymentTypeId, paymentSpecificFundAccountId, portfolioProductType);
}
}
Expand Down Expand Up @@ -200,7 +210,18 @@ public void saveChargesToGLAccountMappings(final JsonCommand command, final Json
}
for (int i = 0; i < chargeToIncomeAccountMappingArray.size(); i++) {
final JsonObject jsonObject = chargeToIncomeAccountMappingArray.get(i).getAsJsonObject();
final Long chargeId = jsonObject.get(LoanProductAccountingParams.CHARGE_ID.getValue()).getAsLong();
JsonElement chargeIdJson = jsonObject.get(LoanProductAccountingParams.CHARGE_ID.getValue());
JsonElement incomeAccountJson = jsonObject.get(LoanProductAccountingParams.INCOME_ACCOUNT_ID.getValue());
if (chargeIdJson == null) {
throw new PlatformApiDataValidationException("charge.id.is.mandatory", "chargeId is mandatory",
LoanProductAccountingParams.CHARGE_ID.getValue());
}
if (incomeAccountJson == null) {
throw new PlatformApiDataValidationException("income.account.id.is.mandatory", "incomeAccountId is mandatory",
LoanProductAccountingParams.INCOME_ACCOUNT_ID.getValue());

}
final Long chargeId = chargeIdJson.getAsLong();
final Long incomeAccountId = jsonObject.get(LoanProductAccountingParams.INCOME_ACCOUNT_ID.getValue()).getAsLong();
saveChargeToFundSourceMapping(productId, chargeId, incomeAccountId, portfolioProductType, isPenalty);
}
Expand All @@ -222,8 +243,20 @@ public void saveReasonToGLAccountMappings(final JsonCommand command, final JsonE

for (int i = 0; i < reasonToExpenseAccountMappingArray.size(); i++) {
final JsonObject jsonObject = reasonToExpenseAccountMappingArray.get(i).getAsJsonObject();
final Long reasonId = jsonObject.get(reasonCodeValueIdParam.getValue()).getAsLong();
final Long expenseAccountId = jsonObject.get(LoanProductAccountingParams.EXPENSE_GL_ACCOUNT_ID.getValue()).getAsLong();

JsonElement reasonIdJson = jsonObject.get(reasonCodeValueIdParam.getValue());
JsonElement expenseAccountJson = jsonObject.get(LoanProductAccountingParams.EXPENSE_GL_ACCOUNT_ID.getValue());
if (reasonIdJson == null) {
throw new PlatformApiDataValidationException(reasonCodeValueIdParam.getValue() + ".is.mandatory",
reasonCodeValueIdParam.getValue() + " is mandatory", reasonCodeValueIdParam.getValue());
}
if (expenseAccountJson == null) {
throw new PlatformApiDataValidationException("expense.gl.account.id.is.mandatory", "expenseGlAccountId is mandatory",
LoanProductAccountingParams.EXPENSE_GL_ACCOUNT_ID.getValue());
}

final Long reasonId = reasonIdJson.getAsLong();
final Long expenseAccountId = expenseAccountJson.getAsLong();

saveReasonToExpenseMapping(productId, reasonId, expenseAccountId, portfolioProductType, cashAccountsForLoan);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* 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.producttoaccountmapping.service;

import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.accounting.glaccount.data.GLAccountData;
import org.apache.fineract.accounting.producttoaccountmapping.data.AdvancedMappingToExpenseAccountData;
import org.apache.fineract.accounting.producttoaccountmapping.data.ChargeToGLAccountMapper;
import org.apache.fineract.accounting.producttoaccountmapping.data.PaymentTypeToGLAccountMapper;
import org.apache.fineract.accounting.producttoaccountmapping.domain.ProductToGLAccountMapping;
import org.apache.fineract.accounting.producttoaccountmapping.domain.ProductToGLAccountMappingRepository;
import org.apache.fineract.infrastructure.codes.data.CodeValueData;
import org.apache.fineract.infrastructure.codes.mapper.CodeValueMapper;
import org.apache.fineract.portfolio.PortfolioProductType;
import org.apache.fineract.portfolio.charge.data.ChargeData;
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeData;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class WorkingCapitalLoanProductAdvancedAccountingReadHelper {

private final ProductToGLAccountMappingRepository productToGLAccountMappingRepository;
private final CodeValueMapper codeValueMapper;

public List<PaymentTypeToGLAccountMapper> fetchPaymentTypeToFundSourceMappings(final Long wcLoanProductId) {
final List<ProductToGLAccountMapping> mappings = productToGLAccountMappingRepository.findAllPaymentTypeMappings(wcLoanProductId,
PortfolioProductType.WORKING_CAPITAL_LOAN.getValue());
final List<PaymentTypeToGLAccountMapper> result = new ArrayList<>();
for (final ProductToGLAccountMapping mapping : mappings) {
final PaymentTypeData paymentTypeData = PaymentTypeData.builder().id(mapping.getPaymentType().getId())
.name(mapping.getPaymentType().getName()).build();
final GLAccountData gLAccountData = new GLAccountData().setId(mapping.getGlAccount().getId())
.setName(mapping.getGlAccount().getName()).setGlCode(mapping.getGlAccount().getGlCode());
result.add(new PaymentTypeToGLAccountMapper().setPaymentType(paymentTypeData).setFundSourceAccount(gLAccountData));
}
return result.isEmpty() ? null : result;
}

public List<ChargeToGLAccountMapper> fetchFeeToIncomeMappings(final Long wcLoanProductId) {
return fetchChargeToIncomeMappings(wcLoanProductId, false);
}

public List<ChargeToGLAccountMapper> fetchPenaltyToIncomeMappings(final Long wcLoanProductId) {
return fetchChargeToIncomeMappings(wcLoanProductId, true);
}

public List<AdvancedMappingToExpenseAccountData> fetchChargeOffReasonMappings(final Long wcLoanProductId) {
return fetchReasonMappings(productToGLAccountMappingRepository.findAllChargeOffReasonsMappings(wcLoanProductId,
PortfolioProductType.WORKING_CAPITAL_LOAN.getValue()));
}

public List<AdvancedMappingToExpenseAccountData> fetchWriteOffReasonMappings(final Long wcLoanProductId) {
return fetchReasonMappings(productToGLAccountMappingRepository.findAllWriteOffReasonsMappings(wcLoanProductId,
PortfolioProductType.WORKING_CAPITAL_LOAN.getValue()));
}

private List<ChargeToGLAccountMapper> fetchChargeToIncomeMappings(final Long wcLoanProductId, final boolean penalty) {
final List<ProductToGLAccountMapping> mappings = penalty
? productToGLAccountMappingRepository.findAllPenaltyMappings(wcLoanProductId,
PortfolioProductType.WORKING_CAPITAL_LOAN.getValue())
: productToGLAccountMappingRepository.findAllFeeMappings(wcLoanProductId,
PortfolioProductType.WORKING_CAPITAL_LOAN.getValue());
final List<ChargeToGLAccountMapper> result = new ArrayList<>();
for (final ProductToGLAccountMapping mapping : mappings) {
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())
.penalty(mapping.getCharge().isPenalty()).build();
result.add(new ChargeToGLAccountMapper().setCharge(chargeData).setIncomeAccount(gLAccountData));
}
return result.isEmpty() ? null : result;
}

private List<AdvancedMappingToExpenseAccountData> fetchReasonMappings(final List<ProductToGLAccountMapping> mappings) {
final List<AdvancedMappingToExpenseAccountData> result = new ArrayList<>();
for (final ProductToGLAccountMapping mapping : mappings) {
final GLAccountData expenseAccount = new GLAccountData().setId(mapping.getGlAccount().getId())
.setName(mapping.getGlAccount().getName()).setGlCode(mapping.getGlAccount().getGlCode());
final CodeValueData codeValue = mapping.getChargeOffReason() != null ? codeValueMapper.map(mapping.getChargeOffReason())
: codeValueMapper.map(mapping.getWriteOffReason());
result.add(new AdvancedMappingToExpenseAccountData().setReasonCodeValue(codeValue).setExpenseAccount(expenseAccount));
}
return result.isEmpty() ? null : result;
}
}
Loading
Loading