Download Cyclos 4 PRO Documentation
Transcript
type: new TransferTypeVO(loanType.id),
amount: loanAmount,
description: config.'loan.description'
]))
Payment loan = entityManagerHandler.find(Payment, loanVO.id)
// Ensure the initial status is correct
Transfer loanTransfer = loan.transfer
if (loanTransfer == null) {
throw new IllegalStateException(
"The loan was not processed (probably pending authorization)")
}
TransferStatus currentStatus = loanTransfer.getStatus(flow)
if (currentStatus != open) {
throw new IllegalStateException(
"The initial status for flow ${flow.name} in ${loanType.name} "
+ "is not the expected one: ${open.name}, "
+ "but ${currentStatus} instead")
}
// Perform the repayment scheduled payment
PerformScheduledPaymentDTO dto = new PerformScheduledPaymentDTO()
def bean = scriptHelper.wrap(dto, [loanField])
bean.from = user
bean.to = SystemAccountOwner.instance()
bean.type = repaymentType
bean.amount = loanAmount
bean.description = config.'repayment.description'
bean.installmentsCount = installments
bean.firstInstallmentDate = firstDueDate
bean[loanField.internalName] = loan
// Interest
if (monthlyInterestRate > 0.00001) {
BigDecimal installmentAmount = calculateInstallmentAmount(
loanAmount, installments, new Date(), firstDueDate)
dto.installments = []
Date dueDate = firstDueDate
for (int i = 0; i < installments; i++) {
def installment = new ScheduledPaymentInstallmentDTO()
def instBean = scriptHelper.wrap(installment)
instBean.dueDate = dueDate
instBean.amount = installmentAmount
dto.installments << installment
dueDate += 30
}
bean.amount = installmentAmount * installments
}
ScheduledPaymentVO repaymentVO = scheduledPaymentService.perform(dto)
ScheduledPayment repayment = entityManagerHandler.find(
ScheduledPayment, repaymentVO.id)
// Update the loan with the repayment link
bean = scriptHelper.wrap(loan, [repaymentField])
bean[repaymentField.internalName] = repayment
}
Cyclos 4 PRO Documentation
75