From cc4e9600ff6db2292b6dad74659a214864249f5e Mon Sep 17 00:00:00 2001 From: Muhimbura Brian Mart Date: Wed, 9 Oct 2024 22:59:30 +0300 Subject: [PATCH 1/4] Fix FSF-56 From 63f09d7bd408b1a334e6806c627b7c33c33d3818 Mon Sep 17 00:00:00 2001 From: Muhimbura Brian Mart Date: Mon, 14 Oct 2024 18:45:22 +0300 Subject: [PATCH 2/4] Fix FSF-56 --- .../ChequeWritePlatformServiceImpl.java | 88 ++++++++++--------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/bankcheque/service/ChequeWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/bankcheque/service/ChequeWritePlatformServiceImpl.java index 6ce092d3fde..bc34259b13b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/bankcheque/service/ChequeWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/bankcheque/service/ChequeWritePlatformServiceImpl.java @@ -251,6 +251,7 @@ public CommandProcessingResult reassignCheque(final Long chequeId, JsonCommand c newCheque.setIssuanceApprovedBy(oldCheque.getIssuanceApprovedBy()); newCheque.setIssuanceAuthorizeBy(oldCheque.getIssuanceAuthorizeBy()); newCheque.setIssuanceAuthorizeOnDate(oldCheque.getIssuanceAuthorizeOnDate()); + newCheque.setNumeroCliente(oldCheque.getNumeroCliente()); newCheque.setIsReassigned(true); this.chequeJpaRepository.saveAll(List.of(oldCheque, newCheque)); return new CommandProcessingResultBuilder().withCommandId(command.commandId()) @@ -482,49 +483,52 @@ public CommandProcessingResult printCheques(JsonCommand command) { throw new BankChequeException("guarantee.savings.account.not.found", "Guarantee savings is not found for client ID" + numeroCliente); } - BigDecimal availableBalance = BigDecimal.ZERO; - final SavingsAccountData savingsAccountData = savingsAccountDataOptional.get(); - final Long savingsAccountId = savingsAccountData.getId(); - if (savingsAccountData.getSummary() != null) { - availableBalance = savingsAccountData.getSummary().getAvailableBalance(); - } - if (guaranteeAmount.compareTo(availableBalance) > 0) { - throw new BankChequeException("guarantee.amount.greater.than.available.savings.account.balance", - "Guarantee amount is greater than savings account balance of" + availableBalance); - } - final String localeAsString = "en"; - final String dateFormat = "dd MMMM yyyy"; - final JsonObject jsonObject = new JsonObject(); - final LocalDate localDate = DateUtils.getBusinessLocalDate(); - Locale locale = JsonParserHelper.localeFromString(localeAsString); - final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateFormat).withLocale(locale); - final String localDateString = localDate.format(dateTimeFormatter); - jsonObject.addProperty("locale", localeAsString); - jsonObject.addProperty("dateFormat", dateFormat); - jsonObject.addProperty("transactionAmount", guaranteeAmount); - jsonObject.addProperty("transactionDate", localDateString); - if (!CollectionUtils.isEmpty(paymentTypeOptions)) { - Optional paymentTypeOptional = new ArrayList<>(paymentTypeOptions).stream() - .filter(pt -> BankChequeApiConstants.BANK_CHEQUE_PAYMENT_TYPE.equalsIgnoreCase(pt.getName())).findFirst(); - if (paymentTypeOptional.isPresent()) { - PaymentTypeData paymentType = paymentTypeOptional.get(); - jsonObject.addProperty("paymentTypeId", paymentType.getId()); + + if (!chequeData.getReassingedCheque()){ + BigDecimal availableBalance = BigDecimal.ZERO; + final SavingsAccountData savingsAccountData = savingsAccountDataOptional.get(); + final Long savingsAccountId = savingsAccountData.getId(); + if (savingsAccountData.getSummary() != null) { + availableBalance = savingsAccountData.getSummary().getAvailableBalance(); + } + if (guaranteeAmount.compareTo(availableBalance) > 0) { + throw new BankChequeException("guarantee.amount.greater.than.available.savings.account.balance", + "Guarantee amount is greater than savings account balance of" + availableBalance); + } + final String localeAsString = "en"; + final String dateFormat = "dd MMMM yyyy"; + final JsonObject jsonObject = new JsonObject(); + final LocalDate localDate = DateUtils.getBusinessLocalDate(); + Locale locale = JsonParserHelper.localeFromString(localeAsString); + final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateFormat).withLocale(locale); + final String localDateString = localDate.format(dateTimeFormatter); + jsonObject.addProperty("locale", localeAsString); + jsonObject.addProperty("dateFormat", dateFormat); + jsonObject.addProperty("transactionAmount", guaranteeAmount); + jsonObject.addProperty("transactionDate", localDateString); + if (!CollectionUtils.isEmpty(paymentTypeOptions)) { + Optional paymentTypeOptional = new ArrayList<>(paymentTypeOptions).stream() + .filter(pt -> BankChequeApiConstants.BANK_CHEQUE_PAYMENT_TYPE.equalsIgnoreCase(pt.getName())).findFirst(); + if (paymentTypeOptional.isPresent()) { + PaymentTypeData paymentType = paymentTypeOptional.get(); + jsonObject.addProperty("paymentTypeId", paymentType.getId()); + } + } + jsonObject.addProperty("accountNumber", bankAccNo); + jsonObject.addProperty("checkNumber", chequeData.getChequeNo()); + jsonObject.addProperty("receiptNumber", chequeData.getGuaranteeId()); + jsonObject.addProperty("bankNumber", chequeData.getBankName()); + jsonObject.addProperty("glAccountId", chequeData.getGlAccountId()); + jsonObject.addProperty("routingCode", ""); + final String note = "Retiro de garantía por ID de garantía " + guaranteeId; + jsonObject.addProperty("note", note); + final JsonCommand withdrawalJsonCommand = JsonCommand.fromJsonElement(savingsAccountId, jsonObject, this.fromApiJsonHelper); + withdrawalJsonCommand.setJsonCommand(jsonObject.toString()); + CommandProcessingResult result = this.savingsAccountWritePlatformService.withdrawal(savingsAccountId, + withdrawalJsonCommand); + if (result != null) { + log.info("Guarantee withdrawal is successful for savings account ID {}", result.getSavingsId()); } - } - jsonObject.addProperty("accountNumber", bankAccNo); - jsonObject.addProperty("checkNumber", chequeData.getChequeNo()); - jsonObject.addProperty("receiptNumber", chequeData.getGuaranteeId()); - jsonObject.addProperty("bankNumber", chequeData.getBankName()); - jsonObject.addProperty("glAccountId", chequeData.getGlAccountId()); - jsonObject.addProperty("routingCode", ""); - final String note = "Retiro de garantía por ID de garantía " + guaranteeId; - jsonObject.addProperty("note", note); - final JsonCommand withdrawalJsonCommand = JsonCommand.fromJsonElement(savingsAccountId, jsonObject, this.fromApiJsonHelper); - withdrawalJsonCommand.setJsonCommand(jsonObject.toString()); - CommandProcessingResult result = this.savingsAccountWritePlatformService.withdrawal(savingsAccountId, - withdrawalJsonCommand); - if (result != null) { - log.info("Guarantee withdrawal is successful for savings account ID {}", result.getSavingsId()); } } if (chequeAmount != null) { From 70bd1b6065e848fd3e6d6e488b7d8ea17c231baa Mon Sep 17 00:00:00 2001 From: Muhimbura Brian Mart Date: Thu, 17 Oct 2024 15:07:07 +0300 Subject: [PATCH 3/4] Fix FSF-59 --- .../fineract/portfolio/savings/domain/SavingsAccount.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java index 8deaec19d17..390392fa047 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java @@ -1454,9 +1454,9 @@ public void validateAccountBalanceDoesNotBecomeNegative(final BigDecimal transac LocalDate lastSavingsDate = null; final BigDecimal withdrawalFee = null; for (final SavingsAccountTransaction transaction : transactionsSortedByDate) { - if (transaction.isNotReversed() && transaction.isCredit() && !transaction.isReversalTransaction()) { + if (transaction.isNotReversed() && transaction.isCredit() && !transaction.isReversalTransaction() && !transaction.isAmountRelease()) { runningBalance = runningBalance.plus(transaction.getAmount(this.currency)); - } else if (transaction.isNotReversed() && transaction.isDebit() && !transaction.isReversalTransaction()) { + } else if (transaction.isNotReversed() && transaction.isDebit() && !transaction.isReversalTransaction() && !transaction.isAmountOnHold()) { runningBalance = runningBalance.minus(transaction.getAmount(this.currency)); } else { continue; From e1e4660020df3c376f6a96f6d63c2eab493854ff Mon Sep 17 00:00:00 2001 From: Muhimbura Brian Mart Date: Thu, 17 Oct 2024 15:10:58 +0300 Subject: [PATCH 4/4] Fix FSF-59 --- .../fineract/portfolio/savings/domain/SavingsAccount.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java index 390392fa047..c5a78759d10 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java @@ -1535,9 +1535,9 @@ public void validateAccountBalanceDoesNotBecomeNegative(final String transaction Money minRequiredBalance = minRequiredBalanceDerived(getCurrency()); LocalDate lastSavingsDate = null; for (final SavingsAccountTransaction transaction : transactionsSortedByDate) { - if (transaction.isNotReversed() && transaction.isCredit()) { + if (transaction.isNotReversed() && transaction.isCredit() && !transaction.isAmountRelease()) { runningBalance = runningBalance.plus(transaction.getAmount(this.currency)); - } else if (transaction.isNotReversed() && transaction.isDebit()) { + } else if (transaction.isNotReversed() && transaction.isDebit() && !transaction.isAmountOnHold()) { runningBalance = runningBalance.minus(transaction.getAmount(this.currency)); }