FINERACT-2203: LoanTransactionsApi add getLoanTransactions

This commit is contained in:
adam.magyari
2025-03-19 17:38:19 +01:00
committed by Adam Saghy
parent a8bbba0b24
commit 2cfc0b2503
18 changed files with 763 additions and 19 deletions
@@ -0,0 +1,56 @@
/**
* 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.portfolio.loanaccount.api;
public interface LoanTransactionApiConstants {
enum TransactionType {
disbursement, //
repayment, //
waiver, //
repaymentAtDisbursement, //
writeOff, //
markedForRescheduling, //
recoveryRepayment, //
waiveCharges, //
accrual, //
initiateTransfer, //
approveTransfer, //
withdrawTransfer, //
rejectTransfer, //
refund, //
chargePayment, //
incomePosting, //
creditBalanceRefund, //
merchantIssuedRefund, //
payoutRefund, //
goodwillCredit, //
chargeRefund, //
chargeback, //
chargeAdjustment, //
chargeOff, //
downPayment, //
reAge, //
reAmortize, //
interestPaymentWaiver, //
accrualActivity, //
interestRefund, //
accrualAdjustment, //
}
}
@@ -21,6 +21,7 @@ package org.apache.fineract.portfolio.loanaccount.api;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDate;
import java.util.Set;
import org.springframework.data.domain.Page;
/**
* Created by Chirag Gupta on 12/30/17.
@@ -275,6 +276,12 @@ final class LoanTransactionsApiResourceSwagger {
}
}
@Schema(description = "GetLoansLoanIdTransactionsResponse")
public abstract static class GetLoansLoanIdTransactionsResponse implements Page<GetLoansLoanIdTransactionsTransactionIdResponse> {
private GetLoansLoanIdTransactionsResponse() {}
}
@Schema(description = "PostLoansLoanIdTransactionsRequest")
public static final class PostLoansLoanIdTransactionsRequest {
@@ -29,6 +29,7 @@ import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.apache.fineract.portfolio.account.data.AccountTransferData;
import org.apache.fineract.portfolio.paymentdetail.data.PaymentDetailData;
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeData;
import org.springframework.integration.annotation.Default;
/**
* Immutable data object representing a loan transaction.
@@ -213,6 +214,7 @@ public class LoanTransactionData {
}
@Default // Default constructor for mapper
public LoanTransactionData(final Long id, final Long officeId, final String officeName, final LoanTransactionEnumData transactionType,
final PaymentDetailData paymentDetailData, final CurrencyData currency, final LocalDate date, final BigDecimal amount,
final BigDecimal netDisbursalAmount, final BigDecimal principalPortion, final BigDecimal interestPortion,
@@ -288,4 +288,8 @@ public class LoanRepositoryWrapper {
public List<Long> findIdByExternalIds(List<ExternalId> externalIds) {
return repository.findIdsByExternalIds(externalIds);
}
public boolean existsByLoanId(Long loanId) {
return repository.existsById(loanId);
}
}
@@ -44,17 +44,13 @@ import org.apache.fineract.infrastructure.core.domain.AbstractAuditableWithUTCDa
import org.apache.fineract.infrastructure.core.domain.ExternalId;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.core.service.MathUtil;
import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
import org.apache.fineract.organisation.monetary.domain.Money;
import org.apache.fineract.organisation.office.domain.Office;
import org.apache.fineract.portfolio.account.data.AccountTransferData;
import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionData;
import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionEnumData;
import org.apache.fineract.portfolio.loanaccount.domain.reaging.LoanReAgeParameter;
import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanScheduleType;
import org.apache.fineract.portfolio.loanproduct.service.LoanEnumerations;
import org.apache.fineract.portfolio.paymentdetail.data.PaymentDetailData;
import org.apache.fineract.portfolio.paymentdetail.domain.PaymentDetail;
/**
@@ -724,19 +720,6 @@ public class LoanTransaction extends AbstractAuditableWithUTCDateTimeCustom<Long
return !MathUtil.isEmpty(amount);
}
public LoanTransactionData toData(final CurrencyData currencyData, final AccountTransferData transfer) {
final LoanTransactionEnumData transactionType = LoanEnumerations.transactionType(this.typeOf);
PaymentDetailData paymentDetailData = null;
if (this.paymentDetail != null) {
paymentDetailData = this.paymentDetail.toData();
}
return new LoanTransactionData(getId(), this.office.getId(), this.office.getName(), transactionType, paymentDetailData,
currencyData, getTransactionDate(), this.amount, this.loan.getNetDisbursalAmount(), this.principalPortion,
this.interestPortion, this.feeChargesPortion, this.penaltyChargesPortion, this.overPaymentPortion, this.externalId,
transfer, null, outstandingLoanBalance, this.unrecognizedIncomePortion, this.manuallyAdjustedOrReversed, this.loan.getId(),
this.loan.getExternalId());
}
public Map<String, Object> toMapData(final String currencyCode) {
final Map<String, Object> thisTransactionData = new LinkedHashMap<>();
@@ -0,0 +1,51 @@
/**
* 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.portfolio.loanaccount.mapper;
import org.apache.fineract.infrastructure.core.config.MapstructMapperConfig;
import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionData;
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
@Mapper(config = MapstructMapperConfig.class, uses = { LoanTransactionRelationMapper.class, LoanChargePaidByMapper.class })
public interface LoanTransactionMapper {
@Mapping(target = "numberOfRepayments", ignore = true)
@Mapping(target = "loanRepaymentScheduleInstallments", ignore = true)
@Mapping(target = "writeOffReasonOptions", ignore = true)
@Mapping(target = "chargeOffReasonOptions", ignore = true)
@Mapping(target = "paymentTypeOptions", ignore = true)
@Mapping(target = "overpaymentPortion", ignore = true)
@Mapping(target = "transfer", ignore = true)
@Mapping(target = "fixedEmiAmount", ignore = true)
@Mapping(target = "date", source = "dateOf")
@Mapping(target = "loanChargePaidByList", source = "loanChargesPaid")
@Mapping(target = "manuallyReversed", source = "manuallyAdjustedOrReversed")
@Mapping(target = "transactionRelations", source = "loanTransactionRelations")
@Mapping(target = "officeId", source = "office.id")
@Mapping(target = "officeName", source = "office.name")
@Mapping(target = "loanId", source = "loan.id")
@Mapping(target = "externalLoanId", source = "loan.externalId")
@Mapping(target = "netDisbursalAmount", source = "loan.netDisbursalAmount")
@Mapping(target = "transactionType", expression = "java(org.apache.fineract.portfolio.loanproduct.service.LoanEnumerations.transactionType(loanTransaction.getTypeOf()))")
@Mapping(target = "paymentDetailData", expression = "java(loanTransaction.getPaymentDetail() != null ? loanTransaction.getPaymentDetail().toData() : null)")
@Mapping(target = "currency", expression = "java(loanTransaction.getLoan().getCurrency().toData())")
LoanTransactionData mapLoanTransaction(LoanTransaction loanTransaction);
}