diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryRunningBalanceUpdateServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryRunningBalanceUpdateServiceImpl.java index 313504bd62b..7c1f6a83bc8 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryRunningBalanceUpdateServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryRunningBalanceUpdateServiceImpl.java @@ -108,13 +108,13 @@ private void updateOrganizationRunningBalance(LocalDate entityDate) { final String organizationRunningBalanceQuery = """ SELECT je.organization_running_balance AS runningBalance, - je.account_id AS accountId + je.account_id AS accountId FROM acc_gl_journal_entry je - INNER JOIN ( SELECT max( id ) AS id FROM acc_gl_journal_entry WHERE entry_date < ? GROUP BY account_id, entry_date ) je2 ON je2.id = je.id - INNER JOIN ( SELECT max( entry_date ) AS entrydt FROM acc_gl_journal_entry WHERE entry_date < ? GROUP BY account_id ) je3 ON je.entry_date = je3.entrydt + INNER JOIN ( SELECT max( id ) AS id FROM acc_gl_journal_entry WHERE entry_date < ? GROUP BY account_id, entry_date ) je2 ON je2.id = je.id + INNER JOIN ( SELECT max( entry_date ) AS entrydt FROM acc_gl_journal_entry WHERE entry_date < ? GROUP BY account_id ) je3 ON je.entry_date = je3.entrydt GROUP BY - je.id + je.id ORDER BY je.entry_date DESC LIMIT 10000; """; @@ -131,13 +131,13 @@ INNER JOIN ( SELECT max( entry_date ) AS entrydt FROM acc_gl_journal_entry WHERE SELECT je.office_running_balance AS runningBalance, je.account_id AS accountId, - je.office_id AS officeId + je.office_id AS officeId FROM acc_gl_journal_entry je INNER JOIN ( SELECT max( id ) AS id FROM acc_gl_journal_entry WHERE entry_date < ? GROUP BY office_id, account_id, entry_date ) je2 ON je2.id = je.id - INNER JOIN ( SELECT max( entry_date ) AS entrydt FROM acc_gl_journal_entry WHERE entry_date < ? GROUP BY office_id, account_id ) je3 ON je.entry_date = je3.entrydt + INNER JOIN ( SELECT max( entry_date ) AS entrydt FROM acc_gl_journal_entry WHERE entry_date < ? GROUP BY office_id, account_id ) je3 ON je.entry_date = je3.entrydt GROUP BY - je.id + je.id ORDER BY je.entry_date DESC LIMIT 10000; """; diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loan/LoanImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loan/LoanImportHandler.java index 79c06120c15..c62fbc7ab45 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loan/LoanImportHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loan/LoanImportHandler.java @@ -41,16 +41,15 @@ import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.infrastructure.core.serialization.GoogleGsonSerializerHelper; +import org.apache.fineract.portfolio.collateral.data.CollateralData; import org.apache.fineract.portfolio.group.domain.Group; import org.apache.fineract.portfolio.group.domain.GroupRepositoryWrapper; import org.apache.fineract.portfolio.loanaccount.data.DisbursementData; import org.apache.fineract.portfolio.loanaccount.data.LoanAccountData; import org.apache.fineract.portfolio.loanaccount.data.LoanApprovalData; import org.apache.fineract.portfolio.loanaccount.data.LoanChargeData; -import org.apache.fineract.portfolio.loanaccount.data.LoanCollateralManagementData; import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionData; import org.apache.fineract.portfolio.loanaccount.domain.LoanCharge; -import org.apache.fineract.portfolio.loanaccount.exception.InvalidAmountOfCollateralQuantity; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.ss.usermodel.Row; @@ -350,17 +349,7 @@ private LoanAccountData readLoan(Row row, String locale, String dateFormat) { } } - List loanCollateralManagementData = new ArrayList<>(); - - if (collateralId != null) { - if (ImportHandlerUtils.readAsDouble(LoanConstants.LOAN_COLLATERAL_QUANTITY, row) != null) { - loanCollateralManagementData.add(new LoanCollateralManagementData(collateralId, - BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(LoanConstants.LOAN_COLLATERAL_QUANTITY, row)), null, null, - null)); - } else { - throw new InvalidAmountOfCollateralQuantity(null); - } - } + List loanCollateralManagementData = new ArrayList<>(); statuses.add(status); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/collateral/service/CollateralReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/collateral/service/CollateralReadPlatformServiceImpl.java index 29df93832e0..8896ec010cf 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/collateral/service/CollateralReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/collateral/service/CollateralReadPlatformServiceImpl.java @@ -54,7 +54,9 @@ private static final class CollateralMapper implements RowMapper private final StringBuilder sqlBuilder = new StringBuilder( "lc.id as id, lc.description as description, lc.value as value, cv.id as typeId, cv.code_value as typeName, oc.code as currencyCode, ") - .append(" oc.name as currencyName,oc.decimal_places as currencyDecimalPlaces, oc.currency_multiplesof as inMultiplesOf, oc.display_symbol as currencyDisplaySymbol, oc.internationalized_name_code as currencyNameCode") + .append(" oc.name as currencyName,oc.decimal_places as currencyDecimalPlaces, oc.currency_multiplesof as inMultiplesOf, " + + "oc.display_symbol as currencyDisplaySymbol, oc.internationalized_name_code as currencyNameCode, " + + "oc.int_code as intCode") .append(" FROM m_loan_collateral lc") // .append(" JOIN m_code_value cv on lc.type_cv_id = cv.id")// .append(" JOIN m_loan loan on lc.loan_id = loan.id")// diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResource.java index 5d1ea9831f1..0d8a7198057 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResource.java @@ -110,8 +110,8 @@ import org.apache.fineract.portfolio.client.data.EconomicSectorData; import org.apache.fineract.portfolio.client.service.ClientReadPlatformService; import org.apache.fineract.portfolio.client.service.EconomicActivityReadPlatformService; -import org.apache.fineract.portfolio.collateralmanagement.data.LoanCollateralResponseData; -import org.apache.fineract.portfolio.collateralmanagement.service.LoanCollateralManagementReadPlatformService; +import org.apache.fineract.portfolio.collateral.data.CollateralData; +import org.apache.fineract.portfolio.collateral.service.CollateralReadPlatformService; import org.apache.fineract.portfolio.cupo.data.CupoData; import org.apache.fineract.portfolio.cupo.domain.CupoStatus; import org.apache.fineract.portfolio.cupo.service.CupoReadService; @@ -131,7 +131,6 @@ import org.apache.fineract.portfolio.loanaccount.data.LoanAccountData; import org.apache.fineract.portfolio.loanaccount.data.LoanApprovalData; import org.apache.fineract.portfolio.loanaccount.data.LoanChargeData; -import org.apache.fineract.portfolio.loanaccount.data.LoanCollateralManagementData; import org.apache.fineract.portfolio.loanaccount.data.LoanTermVariationsData; import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionData; import org.apache.fineract.portfolio.loanaccount.data.PaidInAdvanceData; @@ -284,7 +283,7 @@ public class LoansApiResource { private final ConfigurationDomainService configurationDomainService; private final DefaultToApiJsonSerializer glimTemplateToApiJsonSerializer; private final GLIMAccountInfoReadPlatformService glimAccountInfoReadPlatformService; - private final LoanCollateralManagementReadPlatformService loanCollateralManagementReadPlatformService; + private final CollateralReadPlatformService collateralReadPlatformService; private final CupoReadService cupoReadService; private final AppUserReadPlatformService appUserReadPlatformService; private final AgencyReadPlatformServiceImpl agencyReadPlatformService; @@ -316,9 +315,8 @@ public LoansApiResource(final PlatformSecurityContext context, final LoanReadPla final ConfigurationDomainService configurationDomainService, final DefaultToApiJsonSerializer glimTemplateToApiJsonSerializer, final GLIMAccountInfoReadPlatformService glimAccountInfoReadPlatformService, - final LoanCollateralManagementReadPlatformService loanCollateralManagementReadPlatformService, - final CupoReadService cupoReadService, AppUserReadPlatformService appUserReadPlatformService, - EconomicActivityReadPlatformService economicActivityReadPlatformService, + final CollateralReadPlatformService collateralReadPlatformService, final CupoReadService cupoReadService, + AppUserReadPlatformService appUserReadPlatformService, EconomicActivityReadPlatformService economicActivityReadPlatformService, AgencyReadPlatformServiceImpl agencyReadPlatformService, CenterReadPlatformServiceImpl centerReadPlatformService) { this.context = context; this.loanReadPlatformService = loanReadPlatformService; @@ -350,7 +348,7 @@ public LoansApiResource(final PlatformSecurityContext context, final LoanReadPla this.configurationDomainService = configurationDomainService; this.glimTemplateToApiJsonSerializer = glimTemplateToApiJsonSerializer; this.glimAccountInfoReadPlatformService = glimAccountInfoReadPlatformService; - this.loanCollateralManagementReadPlatformService = loanCollateralManagementReadPlatformService; + this.collateralReadPlatformService = collateralReadPlatformService; this.cupoReadService = cupoReadService; this.clientReadPlatformService = clientReadPlatformService; this.ageLimitValidationJsonSerializer = ageLimitValidationJsonSerializer; @@ -715,8 +713,7 @@ public String retrieveLoan(@PathParam("loanId") @Parameter(description = "loanId CupoData linkedCupo = this.accountAssociationsReadPlatformService.retrieveLinkedCupo(loanId); Collection disbursementData = null; Collection emiAmountVariations = null; - Collection loanCollateralManagements = null; - Collection loanCollateralManagementData = new ArrayList<>(); + Collection collateralData = null; CollectionData collectionData = CollectionData.template(); final Set mandatoryResponseParameters = new HashSet<>(); @@ -803,13 +800,8 @@ public String retrieveLoan(@PathParam("loanId") @Parameter(description = "loanId if (associationParameters.contains(DataTableApiConstant.collateralAssociateParamName)) { mandatoryResponseParameters.add(DataTableApiConstant.collateralAssociateParamName); - loanCollateralManagements = this.loanCollateralManagementReadPlatformService.getLoanCollateralResponseDataList(loanId); - for (LoanCollateralResponseData loanCollateralManagement : loanCollateralManagements) { - loanCollateralManagementData.add(loanCollateralManagement.toCommand()); - } - if (CollectionUtils.isEmpty(loanCollateralManagements)) { - loanCollateralManagements = null; - } + collateralData = this.collateralReadPlatformService.retrieveCollaterals(loanId); + } if (associationParameters.contains(DataTableApiConstant.meetingAssociateParamName)) { @@ -941,13 +933,12 @@ public String retrieveLoan(@PathParam("loanId") @Parameter(description = "loanId } final LoanAccountData loanAccount = LoanAccountData.associationsAndTemplate(loanBasicDetails, repaymentSchedule, loanRepayments, - charges, loanCollateralManagementData, guarantors, meeting, productOptions, loanTermFrequencyTypeOptions, - repaymentFrequencyTypeOptions, repaymentFrequencyNthDayTypeOptions, repaymentFrequencyDayOfWeekTypeOptions, - repaymentStrategyOptions, interestRateFrequencyTypeOptions, amortizationTypeOptions, interestTypeOptions, - interestCalculationPeriodTypeOptions, fundOptions, chargeOptions, chargeTemplate, allowedLoanOfficers, loanPurposeOptions, - loanCollateralOptions, calendarOptions, notes, accountLinkingOptions, linkedAccount, disbursementData, emiAmountVariations, - overdueCharges, paidInAdvanceTemplate, interestRatesPeriods, clientActiveLoanOptions, rates, isRatesEnabled, - collectionData); + charges, collateralData, guarantors, meeting, productOptions, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions, + repaymentFrequencyNthDayTypeOptions, repaymentFrequencyDayOfWeekTypeOptions, repaymentStrategyOptions, + interestRateFrequencyTypeOptions, amortizationTypeOptions, interestTypeOptions, interestCalculationPeriodTypeOptions, + fundOptions, chargeOptions, chargeTemplate, allowedLoanOfficers, loanPurposeOptions, loanCollateralOptions, calendarOptions, + notes, accountLinkingOptions, linkedAccount, disbursementData, emiAmountVariations, overdueCharges, paidInAdvanceTemplate, + interestRatesPeriods, clientActiveLoanOptions, rates, isRatesEnabled, collectionData); loanAccount.setLinkedCupo(linkedCupo); loanAccount.setCupoLinkingOptions(cupoLinkingOptions); loanAccount.setPrequalificationId(prequalificationId); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanAccountData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanAccountData.java index 5b10e33fc22..df53ce85826 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanAccountData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanAccountData.java @@ -41,6 +41,7 @@ import org.apache.fineract.portfolio.calendar.data.CalendarData; import org.apache.fineract.portfolio.charge.data.ChargeData; import org.apache.fineract.portfolio.client.data.EconomicSectorData; +import org.apache.fineract.portfolio.collateral.data.CollateralData; import org.apache.fineract.portfolio.common.domain.PeriodFrequencyType; import org.apache.fineract.portfolio.cupo.data.CupoData; import org.apache.fineract.portfolio.floatingrates.data.InterestRatePeriodData; @@ -142,7 +143,7 @@ public final class LoanAccountData { private final LoanScheduleData repaymentSchedule; private final Collection transactions; private final Collection charges; - private final Collection collateral; + private final Collection collateral; private final Collection guarantors; private final CalendarData meeting; private final Collection notes; @@ -346,7 +347,7 @@ public static LoanAccountData disburseLoanByCheques(final Collection final LoanScheduleData repaymentSchedule = null; final Collection transactions = null; final Collection charges = null; - final Collection collateral = null; + final Collection collateral = null; final Collection guarantors = null; final Collection notes = null; final CalendarData calendarData = null; @@ -442,14 +443,14 @@ public static LoanAccountData importInstanceIndividual(EnumOptionData loanTypeEn BigDecimal inArrearsTolerance, Long transactionProcessingStrategyId, Integer graceOnPrincipalPayment, Integer graceOnInterestPayment, Integer graceOnInterestCharged, LocalDate interestChargedFromDate, LocalDate repaymentsStartingFromDate, Integer rowIndex, String externalId, Long groupId, Collection charges, - String linkAccountId, String locale, String dateFormat, List loanCollateralManagementData) { + String linkAccountId, String locale, String dateFormat, List CollateralData) { return new LoanAccountData(loanTypeEnumOption, clientId, productId, loanOfficerId, submittedOnDate, fundId, principal, numberOfRepayments, repaymentEvery, repaidEveryFrequencyEnums, loanTermFrequency, loanTermFrequencyTypeEnum, nominalInterestRate, expectedDisbursementDate, amortizationEnumOption, interestMethodEnum, interestCalculationPeriodTypeEnum, inArrearsTolerance, transactionProcessingStrategyId, graceOnPrincipalPayment, graceOnInterestPayment, graceOnInterestCharged, interestChargedFromDate, repaymentsStartingFromDate, rowIndex, externalId, - groupId, charges, linkAccountId, locale, dateFormat, loanCollateralManagementData); + groupId, charges, linkAccountId, locale, dateFormat, CollateralData); } public static LoanAccountData importInstanceGroup(EnumOptionData loanTypeEnumOption, Long groupIdforGroupLoan, Long productId, @@ -477,7 +478,7 @@ private LoanAccountData(EnumOptionData loanType, Long clientId, Long productId, Integer graceOnPrincipalPayment, Integer graceOnInterestPayment, Integer graceOnInterestCharged, LocalDate interestChargedFromDate, LocalDate repaymentsStartingFromDate, Integer rowIndex, String externalId, Long groupId, Collection charges, String linkAccountId, String locale, String dateFormat, - Collection loanCollateralManagementData) { + Collection CollateralData) { this.dateFormat = dateFormat; this.locale = locale; this.rowIndex = rowIndex; @@ -562,7 +563,7 @@ private LoanAccountData(EnumOptionData loanType, Long clientId, Long productId, this.repaymentSchedule = null; this.transactions = null; - this.collateral = loanCollateralManagementData; + this.collateral = CollateralData; this.guarantors = null; this.meeting = null; this.notes = null; @@ -946,7 +947,7 @@ public static LoanAccountData collateralTemplate(final Collection final LoanScheduleData repaymentSchedule = null; final Collection transactions = null; final Collection charges = null; - final Collection collateral = null; + final Collection collateral = null; final Collection guarantors = null; final Collection notes = null; final CalendarData calendarData = null; @@ -1099,7 +1100,7 @@ public static LoanAccountData clientDefaults(final Long clientId, final String c final LoanScheduleData repaymentSchedule = null; final Collection transactions = null; final Collection charges = null; - final Collection collateral = null; + final Collection collateral = null; final Collection guarantors = null; final Collection notes = null; final CalendarData calendarData = null; @@ -1289,7 +1290,7 @@ public static LoanAccountData groupDefaults(final GroupGeneralData group, final final LoanScheduleData repaymentSchedule = null; final Collection transactions = null; final Collection charges = null; - final Collection collateral = null; + final Collection collateral = null; final Collection guarantors = null; final Collection notes = null; final CalendarData calendarData = null; @@ -1469,7 +1470,7 @@ public static LoanAccountData loanProductWithTemplateDefaults(final LoanProductD final LoanScheduleData repaymentSchedule = null; final Collection transactions = null; - final Collection collateral = null; + final Collection collateral = null; final Collection guarantors = null; final Collection notes = null; final CalendarData calendarData = null; @@ -1596,7 +1597,7 @@ public static LoanAccountData populateLoanProductDefaults(final LoanAccountData final LoanScheduleData repaymentSchedule = null; final Collection transactions = null; - final Collection collateral = null; + final Collection collateral = null; final Collection guarantors = null; final Collection notes = null; final CalendarData calendarData = null; @@ -1703,7 +1704,7 @@ public static LoanAccountData basicLoanDetails(final Long id, final String accou final LoanScheduleData repaymentSchedule = null; final Collection transactions = null; final Collection charges = null; - final Collection collateral = null; + final Collection collateral = null; final Collection guarantors = null; final Collection notes = null; final CalendarData calendarData = null; @@ -1773,9 +1774,9 @@ public static LoanAccountData basicLoanDetails(final Long id, final String accou */ public static LoanAccountData associationsAndTemplate(final LoanAccountData acc, final LoanScheduleData repaymentSchedule, final Collection transactions, final Collection charges, - final Collection collateral, final Collection guarantors, - final CalendarData calendarData, final Collection productOptions, - final Collection termFrequencyTypeOptions, final Collection repaymentFrequencyTypeOptions, + final Collection collateral, final Collection guarantors, final CalendarData calendarData, + final Collection productOptions, final Collection termFrequencyTypeOptions, + final Collection repaymentFrequencyTypeOptions, final Collection repaymentFrequencyNthDayTypeOptions, final Collection repaymentFrequencyDayOfWeekTypeOptions, final Collection transactionProcessingStrategyOptions, @@ -2064,7 +2065,7 @@ private LoanAccountData(final Long id, // final Integer graceOnInterestPayment, final Integer graceOnInterestCharged, final LocalDate interestChargedFromDate, final LoanApplicationTimelineData timeline, final LoanSummaryData summary, final BigDecimal feeChargesDueAtDisbursementCharged, final LoanScheduleData repaymentSchedule, final Collection transactions, - final Collection charges, final Collection collateral, + final Collection charges, final Collection collateral, final Collection guarantors, final CalendarData meeting, final Collection productOptions, final Collection termFrequencyTypeOptions, final Collection repaymentFrequencyTypeOptions, final Collection repaymentFrequencyNthDayTypeOptions,