From 0b760277c181a5c958d807690c95750f9505dc97 Mon Sep 17 00:00:00 2001 From: Faheem Ahmad Date: Wed, 11 Dec 2024 02:39:35 +0500 Subject: [PATCH] SU-477 (#1371) * SU-477 --- .../loanaccount/data/LoanChargeData.java | 33 ++++++++++ .../importhandler/loan/LoanImportHandler.java | 61 +++++++++++-------- 2 files changed, 68 insertions(+), 26 deletions(-) diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanChargeData.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanChargeData.java index 32a7e6d669a..e0a2ce9b330 100644 --- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanChargeData.java +++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanChargeData.java @@ -472,6 +472,39 @@ public LoanChargeData(final Long id, final LocalDate dueAsOfDate, final BigDecim this.externalId = ExternalId.empty(); } + public LoanChargeData(final Long id, final BigDecimal amount) { + this.id = null; + this.chargeId = id; + this.name = null; + this.currency = null; + this.amount = amount; + this.amountPaid = null; + this.amountWaived = null; + this.amountWrittenOff = null; + this.amountOutstanding = null; + this.chargeTimeType = null; + this.submittedOnDate = null; + this.dueDate = null; + this.chargeCalculationType = null; + this.percentage = null; + this.amountPercentageAppliedTo = null; + this.penalty = false; + this.chargePaymentMode = null; + this.paid = false; + this.waived = false; + this.amountOrPercentage = null; + this.chargeOptions = null; + this.chargePayable = false; + this.loanId = null; + this.externalLoanId = ExternalId.empty(); + this.minCap = null; + this.maxCap = null; + this.installmentChargeData = null; + this.amountAccrued = null; + this.amountUnrecognized = null; + this.externalId = ExternalId.empty(); + } + public boolean isChargePayable() { boolean isAccountTransfer = false; if (this.chargePaymentMode != null) { 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 604e8edaec9..33852376023 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 @@ -295,21 +295,25 @@ private LoanAccountData readLoan(final Workbook workbook, final Row row, final L if (chargeOneId != null) { if (ImportHandlerUtils.readAsDouble(LoanConstants.CHARGE_AMOUNT_1, row) != null) { - EnumOptionData chargeOneTimeTypeEnum = ImportHandlerUtils - .getChargeTimeTypeEmun(workbook.getSheet(TemplatePopulateImportConstants.CHARGE_SHEET_NAME), chargeOneName); - EnumOptionData chargeOneAmountTypeEnum = ImportHandlerUtils - .getChargeAmountTypeEnum(ImportHandlerUtils.readAsString(LoanConstants.CHARGE_AMOUNT_TYPE_1, row)); - - BigDecimal chargeAmount; - BigDecimal amountOrPercentage = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(LoanConstants.CHARGE_AMOUNT_1, row)); - if (chargeOneAmountTypeEnum.getValue().equalsIgnoreCase("1")) { - chargeAmount = amountOrPercentage; + if (!isMigratedLoan) { + EnumOptionData chargeOneTimeTypeEnum = ImportHandlerUtils + .getChargeTimeTypeEmun(workbook.getSheet(TemplatePopulateImportConstants.CHARGE_SHEET_NAME), chargeOneName); + EnumOptionData chargeOneAmountTypeEnum = ImportHandlerUtils + .getChargeAmountTypeEnum(ImportHandlerUtils.readAsString(LoanConstants.CHARGE_AMOUNT_TYPE_1, row)); + + BigDecimal chargeAmount; + BigDecimal amountOrPercentage = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(LoanConstants.CHARGE_AMOUNT_1, row)); + if (chargeOneAmountTypeEnum.getValue().equalsIgnoreCase("1")) { + chargeAmount = amountOrPercentage; + } else { + chargeAmount = LoanCharge.percentageOf(principal, amountOrPercentage); + } + charges.add(new LoanChargeData(chargeOneId, ImportHandlerUtils.readAsDate(LoanConstants.CHARGE_DUE_DATE_1, row), + chargeAmount, chargeOneAmountTypeEnum, chargeOneTimeTypeEnum)); } else { - chargeAmount = LoanCharge.percentageOf(principal, amountOrPercentage); + BigDecimal amountOrPercentage = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(LoanConstants.CHARGE_AMOUNT_1, row)); + charges.add(new LoanChargeData(chargeOneId, amountOrPercentage)); } - - charges.add(new LoanChargeData(chargeOneId, ImportHandlerUtils.readAsDate(LoanConstants.CHARGE_DUE_DATE_1, row), - chargeAmount, chargeOneAmountTypeEnum, chargeOneTimeTypeEnum)); } else { charges.add(new LoanChargeData(chargeOneId, ImportHandlerUtils.readAsDate(LoanConstants.CHARGE_DUE_DATE_1, row), null)); } @@ -317,21 +321,26 @@ private LoanAccountData readLoan(final Workbook workbook, final Row row, final L if (chargeTwoId != null) { if (ImportHandlerUtils.readAsDouble(LoanConstants.CHARGE_AMOUNT_2, row) != null) { - EnumOptionData chargeTwoTimeTypeEnum = ImportHandlerUtils - .getChargeTimeTypeEmun(workbook.getSheet(TemplatePopulateImportConstants.CHARGE_SHEET_NAME), chargeTwoName); - EnumOptionData chargeTwoAmountTypeEnum = ImportHandlerUtils - .getChargeAmountTypeEnum(ImportHandlerUtils.readAsString(LoanConstants.CHARGE_AMOUNT_TYPE_2, row)); - - BigDecimal chargeAmount; - BigDecimal amountOrPercentage = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(LoanConstants.CHARGE_AMOUNT_2, row)); - if (chargeTwoTimeTypeEnum.getValue().equalsIgnoreCase("1")) { - chargeAmount = amountOrPercentage; + if (!isMigratedLoan) { + EnumOptionData chargeTwoTimeTypeEnum = ImportHandlerUtils + .getChargeTimeTypeEmun(workbook.getSheet(TemplatePopulateImportConstants.CHARGE_SHEET_NAME), chargeTwoName); + EnumOptionData chargeTwoAmountTypeEnum = ImportHandlerUtils + .getChargeAmountTypeEnum(ImportHandlerUtils.readAsString(LoanConstants.CHARGE_AMOUNT_TYPE_2, row)); + + BigDecimal chargeAmount; + BigDecimal amountOrPercentage = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(LoanConstants.CHARGE_AMOUNT_2, row)); + if (chargeTwoTimeTypeEnum.getValue().equalsIgnoreCase("1")) { + chargeAmount = amountOrPercentage; + } else { + chargeAmount = LoanCharge.percentageOf(principal, amountOrPercentage); + } + + charges.add(new LoanChargeData(chargeTwoId, ImportHandlerUtils.readAsDate(LoanConstants.CHARGE_DUE_DATE_2, row), + chargeAmount, chargeTwoAmountTypeEnum, chargeTwoTimeTypeEnum)); } else { - chargeAmount = LoanCharge.percentageOf(principal, amountOrPercentage); + BigDecimal amountOrPercentage = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(LoanConstants.CHARGE_AMOUNT_2, row)); + charges.add(new LoanChargeData(chargeTwoId, amountOrPercentage)); } - - charges.add(new LoanChargeData(chargeTwoId, ImportHandlerUtils.readAsDate(LoanConstants.CHARGE_DUE_DATE_2, row), - chargeAmount, chargeTwoAmountTypeEnum, chargeTwoTimeTypeEnum)); } else { charges.add(new LoanChargeData(chargeTwoId, ImportHandlerUtils.readAsDate(LoanConstants.CHARGE_DUE_DATE_2, row), null)); }