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/05 08:39:01 UTC

[GitHub] [fineract] adamsaghy opened a new pull request, #2854: FINERACT-1806: Charge-off API

adamsaghy opened a new pull request, #2854:
URL: https://github.com/apache/fineract/pull/2854

   ## Description
   
   Describe the changes made and why they were made.
   
   Ignore if these details are present on the associated [Apache Fineract JIRA ticket](https://github.com/apache/fineract/pull/1284).
   
   
   ## Checklist
   
   Please make sure these boxes are checked before submitting your pull request - thanks!
   
   - [ ] Write the commit message as per https://github.com/apache/fineract/#pull-requests
   
   - [ ] Acknowledge that we will not review PRs that are not passing the build _("green")_ - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
   
   - [ ] Create/update unit or integration tests for verifying the changes made.
   
   - [ ] Follow coding conventions at https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions.
   
   - [ ] Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
   
   - [ ] Submission is not a "code dump".  (Large changes can be made "in repository" via a branch.  Ask on the developer mailing list for guidance, if required.)
   
   FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.
   


-- 
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


[GitHub] [fineract] galovics merged pull request #2854: FINERACT-1806: Charge-off API

Posted by GitBox <gi...@apache.org>.
galovics merged PR #2854:
URL: https://github.com/apache/fineract/pull/2854


-- 
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


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

Posted by GitBox <gi...@apache.org>.
adamsaghy commented on code in PR #2854:
URL: https://github.com/apache/fineract/pull/2854#discussion_r1063302793


##########
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:
   Follow up stories



-- 
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


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

Posted by GitBox <gi...@apache.org>.
adamsaghy commented on code in PR #2854:
URL: https://github.com/apache/fineract/pull/2854#discussion_r1062498638


##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/self/loanaccount/api/SelfLoansApiResourceSwagger.java:
##########
@@ -165,9 +165,9 @@ private GetLoansLoanIdInterestCalculationPeriodType() {}
             public String description;
         }
 
-        static final class GetLoansLoanIdTimeline {
+        static final class GetSelfLoanIdTimeline {

Review Comment:
   This was intentional. the class with ```GetLoansLoanIdTimeline``` is already existing and they were overriding each other. 



-- 
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


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

Posted by GitBox <gi...@apache.org>.
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


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

Posted by GitBox <gi...@apache.org>.
adamsaghy commented on code in PR #2854:
URL: https://github.com/apache/fineract/pull/2854#discussion_r1063252189


##########
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:
   Follow up tickets... should i remove them?



-- 
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


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

Posted by GitBox <gi...@apache.org>.
adamsaghy commented on code in PR #2854:
URL: https://github.com/apache/fineract/pull/2854#discussion_r1063253027


##########
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:
   True!



-- 
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