MIFOSX-1918 : API changes to add option for fetching pre-close detail based on date

This commit is contained in:
Pramod Nuthakki
2015-04-07 20:20:30 +05:30
parent b1a429e3a2
commit e992a2b410
5 changed files with 57 additions and 7 deletions
+40
View File
@@ -1052,6 +1052,14 @@
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td>loans/{loanId}/transactions?command=prepayLoan</td>
<td><a href="#loans_transaction_pre_close_loan">Loan Pre-Closure transaction template</a></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
@@ -9531,7 +9539,39 @@ Request Body:
</code>
</div>
</div>
<a id="loans_transaction_pre_close_loan" name="loans_transaction_pre_close_loan" class="old-syle-anchor">&nbsp;</a>
<div class="method-section">
<div class="method-description">
<h4> Pre-Close template</h4>
<p>This Api retrieves pre closure details of loan</p>
</div>
<div class="method-example">
<code class="method-declaration">
POST https://DomainName/api/v1/loans/{loanId}/transactions?command=prepayLoan <b>or</b><br/>
https://DomainName/api/v1/loans/{loanId}/transactions?command=prepayLoan&dateFormat=dd+MMMM+yyyy&locale=en&transactionDate=02+April+2015
</code>
<code class="method-request">
POST loans/70/transactions?command=prepayLoan
Content-Type: application/json
Request Body:
{ }
</code>
<code class="method-response">
{
"amount":7765.28,
"principalPortion":7573.76,
"interestPortion":191.52,
"feeChargesPortion":0.00,
"penaltyChargesPortion":0.00
}
</code>
</div>
</div>
<a id="loans_transaction_retrieve" name="loans_transaction_retrieve" class="old-syle-anchor">&nbsp;</a>
<div class="method-section">
<div class="method-description">
@@ -22,6 +22,8 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.apache.commons.lang.StringUtils;
import org.joda.time.LocalDate;
import org.mifosplatform.accounting.journalentry.api.DateParam;
import org.mifosplatform.commands.domain.CommandWrapper;
import org.mifosplatform.commands.service.CommandWrapperBuilder;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
@@ -30,6 +32,7 @@ import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException;
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.mifosplatform.infrastructure.core.service.DateUtils;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.loanaccount.data.LoanTransactionData;
import org.mifosplatform.portfolio.loanaccount.service.LoanReadPlatformService;
@@ -79,7 +82,8 @@ public class LoanTransactionsApiResource {
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveTransactionTemplate(@PathParam("loanId") final Long loanId, @QueryParam("command") final String commandParam,
@Context final UriInfo uriInfo) {
@Context final UriInfo uriInfo, @QueryParam("dateFormat") final String dateFormat,
@QueryParam("transactionDate") final DateParam transactionDateParam, @QueryParam("locale") final String locale) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
@@ -101,7 +105,13 @@ public class LoanTransactionsApiResource {
} else if (is(commandParam, "recoverypayment")) {
transactionData = this.loanReadPlatformService.retrieveRecoveryPaymentTemplate(loanId);
} else if (is(commandParam, "prepayLoan")) {
transactionData = this.loanReadPlatformService.retrieveLoanPrePaymentTemplate(loanId);
LocalDate transactionDate = null;
if (transactionDateParam == null) {
transactionDate = DateUtils.getLocalDateOfTenant();
} else {
transactionDate = LocalDate.fromDateFields(transactionDateParam.getDate("transactionDate", dateFormat, locale));
}
transactionData = this.loanReadPlatformService.retrieveLoanPrePaymentTemplate(loanId, transactionDate);
} else if (is(commandParam, "refundbycash")) {
transactionData = this.loanReadPlatformService.retrieveRefundByCashTemplate(loanId);
} else if (is(commandParam, "refundbytransfer")) {
@@ -4737,7 +4737,7 @@ public class Loan extends AbstractPersistable<Long> {
}
public LoanRepaymentScheduleInstallment fetchPrepaymentDetail(final LoanScheduleGeneratorFactory loanScheduleFactory,
CalendarInstance restCalendarInstance, HolidayDetailDTO holidayDetailDTO) {
CalendarInstance restCalendarInstance, HolidayDetailDTO holidayDetailDTO, LocalDate onDate) {
LoanRepaymentScheduleInstallment installment = null;
if (this.loanRepaymentScheduleDetail.isInterestRecalculationEnabled()) {
@@ -4790,7 +4790,7 @@ public class Loan extends AbstractPersistable<Long> {
this.loanProduct.preCloseInterestCalculationStrategy());
installment = loanScheduleGenerator.calculatePrepaymentAmount(this.repaymentScheduleInstallments, getCurrency(),
DateUtils.getLocalDateOfTenant(), loanApplicationTerms, mc, charges(), holidayDetailDTO);
onDate, loanApplicationTerms, mc, charges(), holidayDetailDTO);
} else {
installment = this.getTotalOutstandingOnLoan();
}
@@ -96,7 +96,7 @@ public interface LoanReadPlatformService {
Collection<Long> fetchArrearLoans();
LoanTransactionData retrieveLoanPrePaymentTemplate(Long loanId);
LoanTransactionData retrieveLoanPrePaymentTemplate(Long loanId, LocalDate onDate);
Collection<LoanTransactionData> retrieveWaiverLoanTransactions(Long loanId);
@@ -398,7 +398,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
}
@Override
public LoanTransactionData retrieveLoanPrePaymentTemplate(final Long loanId) {
public LoanTransactionData retrieveLoanPrePaymentTemplate(final Long loanId, LocalDate onDate) {
this.context.authenticatedUser();
@@ -425,7 +425,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
}
final LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment = loan.fetchPrepaymentDetail(this.loanScheduleFactory,
restCalendarInstance, holidayDetailDTO);
restCalendarInstance, holidayDetailDTO, onDate);
final LoanTransactionEnumData transactionType = LoanEnumerations.transactionType(LoanTransactionType.REPAYMENT);
final Collection<PaymentTypeData> paymentOptions = this.paymentTypeReadPlatformService.retrieveAllPaymentTypes();
final BigDecimal outstandingLoanBalance = loanRepaymentScheduleInstallment.getPrincipalOutstanding(currency).getAmount();