You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by GitBox <gi...@apache.org> on 2023/01/06 08:58:09 UTC

[GitHub] [fineract] galovics commented on a diff in pull request #2854: FINERACT-1806: Charge-off API

galovics commented on code in PR #2854:
URL: https://github.com/apache/fineract/pull/2854#discussion_r1063245470


##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoanTransactionsApiResource.java:
##########
@@ -456,6 +460,8 @@ private String executeTransaction(final Long loanId, final String loanExternalId
             commandRequest = builder.loanForeclosure(resolvedLoanId).build();
         } else if (CommandParameterUtil.is(commandParam, "creditBalanceRefund")) {
             commandRequest = builder.creditBalanceRefund(resolvedLoanId).build();
+        } else if (CommandParameterUtil.is(commandParam, "charge-off")) {

Review Comment:
   Do you think you could extract the command name to a constant? Don't need to do anything with the existing ones. Just wanna make sure we show guideline for the future commands.



##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/ChargeOffLoanCommandHandler.java:
##########
@@ -0,0 +1,43 @@
+/**
+ * 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.handler;
+
+import lombok.RequiredArgsConstructor;
+import org.apache.fineract.commands.annotation.CommandType;
+import org.apache.fineract.commands.handler.NewCommandSourceHandler;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
+import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@RequiredArgsConstructor
+@CommandType(entity = "LOAN", action = "CHARGEOFF")
+public class ChargeOffLoanCommandHandler implements NewCommandSourceHandler {
+
+    private final LoanWritePlatformService writePlatformService;
+
+    @Transactional
+    @Override
+    public CommandProcessingResult processCommand(final JsonCommand command) {
+
+        return this.writePlatformService.chargeOff(command);

Review Comment:
   `this` not needed.



##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanAccountData.java:
##########
@@ -253,6 +253,7 @@ public class LoanAccountData {
     private CollectionData delinquent;
     private DelinquencyRangeData delinquencyRange;
     private LocalDate lastClosedBusinessDate;
+    private Boolean chargedOff;

Review Comment:
   Since you touched the LoanAccountData, do you mind extending the LoanAccountDataV1 Avro schema too? (Same for LoanApplicationTimelineData, LoanSummaryData)



##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java:
##########
@@ -2644,6 +2644,57 @@ public CommandProcessingResult forecloseLoan(final Long loanId, final JsonComman
                 .build();
     }
 
+    @Override
+    @Transactional
+    public CommandProcessingResult chargeOff(JsonCommand command) {
+
+        this.loanEventApiJsonValidator.validateChargeOffTransaction(command.json());
+
+        final Map<String, Object> changes = new LinkedHashMap<>();
+        changes.put("transactionDate", command.stringValueOfParameterNamed("transactionDate"));
+        changes.put("locale", command.locale());
+        changes.put("dateFormat", command.dateFormat());
+
+        // TODO: add business logic validation (transaction date cannot be future, cannot be earlier than latest

Review Comment:
   Don't we wanna do this in this PR? Or is there a follow up ticket for this?



##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanEventApiJsonValidator.java:
##########
@@ -341,6 +341,36 @@ public void validateTransactionWithNoAmount(final String json) {
         throwExceptionIfValidationWarningsExist(dataValidationErrors);
     }
 
+    public void validateChargeOffTransaction(final String json) {
+        if (StringUtils.isBlank(json)) {
+            throw new InvalidJsonException();
+        }
+
+        final Set<String> chargeOffParameters = new HashSet<>(
+                Arrays.asList("transactionDate", "note", "locale", "dateFormat", "chargeOffReasonId", "externalId"));
+
+        final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
+        this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, chargeOffParameters);

Review Comment:
   `this` not needed



##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java:
##########
@@ -2644,6 +2644,57 @@ public CommandProcessingResult forecloseLoan(final Long loanId, final JsonComman
                 .build();
     }
 
+    @Override
+    @Transactional
+    public CommandProcessingResult chargeOff(JsonCommand command) {
+
+        this.loanEventApiJsonValidator.validateChargeOffTransaction(command.json());
+
+        final Map<String, Object> changes = new LinkedHashMap<>();
+        changes.put("transactionDate", command.stringValueOfParameterNamed("transactionDate"));
+        changes.put("locale", command.locale());
+        changes.put("dateFormat", command.dateFormat());
+
+        // TODO: add business logic validation (transaction date cannot be future, cannot be earlier than latest
+        // transactions, etc)
+        Loan loan = loanAssembler.assembleFrom(command.getLoanId());
+        final LocalDate transactionDate = command.localDateValueOfParameterNamed("transactionDate");
+        final ExternalId txnExternalId = externalIdFactory.createFromCommand(command, LoanApiConstants.externalIdParameterName);
+        final AppUser currentUser = getAppUserIfPresent();
+
+        if (command.hasParameter("chargeOffReasonId")) {
+            Long chargeOffReasonId = command.longValueOfParameterNamed("chargeOffReasonId");
+            CodeValue chargeOffReason = this.codeValueRepository
+                    .findOneByCodeNameAndIdWithNotFoundDetection(LoanApiConstants.CHARGE_OFF_REASONS, chargeOffReasonId);
+            changes.put("chargeOffReasonId", chargeOffReasonId);
+            loan.markAsChargedOff(transactionDate, currentUser, chargeOffReason);
+        } else {
+            loan.markAsChargedOff(transactionDate, currentUser, null);
+        }
+
+        LoanTransaction chargeOffTransaction = LoanTransaction.chargeOff(loan, transactionDate, txnExternalId);
+        loanTransactionRepository.saveAndFlush(chargeOffTransaction);
+
+        String noteText = command.stringValueOfParameterNamed("note");
+        if (StringUtils.isNotBlank(noteText)) {
+            changes.put("note", noteText);
+            final Note note = Note.loanTransactionNote(loan, chargeOffTransaction, noteText);
+            this.noteRepository.save(note);
+        }
+
+        // TODO: add accounting

Review Comment:
   How about these?



##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java:
##########
@@ -2644,6 +2644,57 @@ public CommandProcessingResult forecloseLoan(final Long loanId, final JsonComman
                 .build();
     }
 
+    @Override
+    @Transactional
+    public CommandProcessingResult chargeOff(JsonCommand command) {
+
+        this.loanEventApiJsonValidator.validateChargeOffTransaction(command.json());

Review Comment:
   `this` not needed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org