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
@@ -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();