reluxa commented on code in PR #3367:
URL: https://github.com/apache/fineract/pull/3367#discussion_r1291386197


##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java:
##########
@@ -2954,6 +2956,51 @@ private void handleDisbursementTransaction(final 
LocalDate disbursedOn, final Pa
 
     }
 
+    public void handleDownPayment(final BigDecimal disbursedAmount, final 
JsonCommand command,
+            final ScheduleGeneratorDTO scheduleGeneratorDTO) {
+        if (isAutoRepaymentForDownPaymentEnabled()) {
+            LocalDate disbursedOn = 
command.localDateValueOfParameterNamed(ACTUAL_DISBURSEMENT_DATE);
+            BigDecimal disbursedAmountPercentageForDownPayment = 
this.loanRepaymentScheduleDetail
+                    .getDisbursedAmountPercentageForDownPayment();
+            ExternalId externalId = ExternalId.empty();
+            if 
(TemporaryConfigurationServiceContainer.isExternalIdAutoGenerationEnabled()) {
+                externalId = ExternalId.generate();
+            }
+            Money downPaymentMoney = Money.of(getCurrency(), 
percentageOf(disbursedAmount, disbursedAmountPercentageForDownPayment));
+            LoanTransaction downPaymentTransaction = 
LoanTransaction.downPayment(getOffice(), downPaymentMoney, null, disbursedOn,
+                    externalId);
+            /**
+             * Currently mapping down payment transaction as repayment 
transaction to loan repayment schedule for
+             * consistency. Need to replace below logic for creating new 
installment for down payment and mapping.
+             */
+
+            LoanEvent event = LoanEvent.LOAN_REPAYMENT_OR_WAIVER;
+            validateRepaymentTypeAccountStatus(downPaymentTransaction, event);
+            HolidayDetailDTO holidayDetailDTO = 
scheduleGeneratorDTO.getHolidayDetailDTO();
+            
validateRepaymentDateIsOnHoliday(downPaymentTransaction.getTransactionDate(), 
holidayDetailDTO.isAllowTransactionsOnHoliday(),
+                    holidayDetailDTO.getHolidays());
+            
validateRepaymentDateIsOnNonWorkingDay(downPaymentTransaction.getTransactionDate(),
 holidayDetailDTO.getWorkingDays(),
+                    holidayDetailDTO.isAllowTransactionsOnNonWorkingDay());
+
+            
handleRepaymentOrRecoveryOrWaiverTransaction(downPaymentTransaction, 
loanLifecycleStateMachine, null, scheduleGeneratorDTO);
+        }
+    }
+
+    private BigDecimal percentageOf(final BigDecimal value, final BigDecimal 
percentage) {

Review Comment:
   We already seem to have percentageOf on Money. Can we reuse that maybe?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to