Example usage for org.joda.time DateTime toLocalDate

List of usage examples for org.joda.time DateTime toLocalDate

Introduction

In this page you can find the example usage for org.joda.time DateTime toLocalDate.

Prototype

public LocalDate toLocalDate() 

Source Link

Document

Converts this object to a LocalDate with the same date and chronology.

Usage

From source file:org.kuali.kpme.tklm.time.timesheet.service.TimesheetServiceImpl.java

License:Educational Community License

@Override
public TimesheetDocument openTimesheetDocument(String principalId, CalendarEntry calendarDates)
        throws WorkflowException {
    TimesheetDocument timesheetDocument = null;

    DateTime begin = calendarDates.getBeginPeriodFullDateTime();
    DateTime end = calendarDates.getEndPeriodFullDateTime();

    TimesheetDocumentHeader header = TkServiceLocator.getTimesheetDocumentHeaderService()
            .getDocumentHeader(principalId, begin, end);

    if (header == null) {
        List<Assignment> activeAssignments = HrServiceLocator.getAssignmentService()
                .getAssignmentsByCalEntryForTimeCalendar(principalId, calendarDates);
        //HrServiceLocator.getAssignmentService().getAssignments(principalId, TKUtils.getTimelessDate(payCalendarDates.getEndPeriodDate()));
        if (activeAssignments.size() == 0) {
            LOG.warn("No active assignments for " + principalId + " for " + calendarDates.getEndPeriodDate());
            return null;
            //throw new RuntimeException("No active assignments for " + principalId + " for " + calendarDates.getEndPeriodDate());
        }//w w  w  . jav a 2s  .co  m

        EntityNamePrincipalName person = KimApiServiceLocator.getIdentityService()
                .getDefaultNamesForPrincipalId(principalId);
        String principalName = person != null && person.getDefaultName() != null
                ? person.getDefaultName().getCompositeName()
                : StringUtils.EMPTY;
        String endDateString = TKUtils.formatDate(end.toLocalDate());
        String timesheetDocumentTitle = TimesheetDocument.TIMESHEET_DOCUMENT_TYPE + " - " + principalName + " ("
                + principalId + ") - " + endDateString;

        timesheetDocument = this.initiateWorkflowDocument(principalId, begin, end, calendarDates,
                TimesheetDocument.TIMESHEET_DOCUMENT_TYPE, timesheetDocumentTitle);
        //timesheetDocument.setPayCalendarEntry(calendarDates);
        //this.loadTimesheetDocumentData(timesheetDocument, principalId, calendarDates);
        //TODO switch this to scheduled time offs
        //this.loadHolidaysOnTimesheet(timesheetDocument, principalId, begin, end);
    } else {
        timesheetDocument = this.getTimesheetDocument(header.getDocumentId());
        if (timesheetDocument != null) {
            timesheetDocument.setCalendarEntry(calendarDates);
        }
    }

    if (timesheetDocument != null) {
        timesheetDocument
                .setTimeSummary(TkServiceLocator.getTimeSummaryService().getTimeSummary(timesheetDocument));
    }

    return timesheetDocument;
}

From source file:org.kuali.kpme.tklm.time.timesheet.service.TimesheetServiceImpl.java

License:Educational Community License

protected TimesheetDocument initiateWorkflowDocument(String principalId, DateTime payBeginDate,
        DateTime payEndDate, CalendarEntry calendarEntry, String documentType, String title)
        throws WorkflowException {
    TimesheetDocument timesheetDocument = null;
    WorkflowDocument workflowDocument = null;

    workflowDocument = WorkflowDocumentFactory.createDocument(principalId, documentType, title);

    String status = workflowDocument.getStatus().getCode();
    TimesheetDocumentHeader documentHeader = new TimesheetDocumentHeader(workflowDocument.getDocumentId(),
            principalId, payBeginDate.toDate(), payEndDate.toDate(), status);

    documentHeader.setDocumentId(workflowDocument.getDocumentId().toString());
    documentHeader.setDocumentStatus("I");

    TkServiceLocator.getTimesheetDocumentHeaderService().saveOrUpdate(documentHeader);
    timesheetDocument = new TimesheetDocument(documentHeader);
    timesheetDocument.setCalendarEntry(calendarEntry);
    loadTimesheetDocumentData(timesheetDocument, principalId, calendarEntry);
    TkServiceLocator.getTkSearchableAttributeService().updateSearchableAttribute(timesheetDocument,
            payEndDate.toLocalDate());

    if (LmServiceLocator.getLeaveApprovalService().isActiveAssignmentFoundOnJobFlsaStatus(principalId,
            HrConstants.FLSA_STATUS_NON_EXEMPT, true)) {
        deleteNonApprovedLeaveBlocks(principalId, calendarEntry.getBeginPeriodFullDateTime().toLocalDate(),
                calendarEntry.getEndPeriodFullDateTime().toLocalDate());
    }/*from  w  ww. j  av  a 2 s.co m*/

    return timesheetDocument;
}

From source file:org.kuali.kpme.tklm.time.workflow.postprocessor.TkPostProcessor.java

License:Educational Community License

private void calculateLeaveCalendarOvertime(TimesheetDocumentHeader timesheetDocumentHeader,
        DocumentStatus newDocumentStatus) {
    if (DocumentStatus.FINAL.equals(newDocumentStatus)) {
        String documentId = timesheetDocumentHeader.getDocumentId();
        String principalId = timesheetDocumentHeader.getPrincipalId();
        DateTime endDate = timesheetDocumentHeader.getEndDateTime();

        if (LmServiceLocator.getLeaveApprovalService().isActiveAssignmentFoundOnJobFlsaStatus(principalId,
                HrConstants.FLSA_STATUS_NON_EXEMPT, true)) {
            List<TimeBlock> timeBlocks = TkServiceLocator.getTimeBlockService().getTimeBlocks(documentId);

            List<LeaveBlock> leaveBlocks = new ArrayList<LeaveBlock>();

            for (TimeBlock timeBlock : timeBlocks) {
                EarnCode overtimeEarnCode = getOvertimeEarnCode(timeBlock, endDate.toLocalDate());

                if (overtimeEarnCode != null) {
                    AccrualCategory accrualCategory = HrServiceLocator.getAccrualCategoryService()
                            .getAccrualCategory(overtimeEarnCode.getAccrualCategory(), endDate.toLocalDate());

                    if (accrualCategory != null) {
                        LocalDate leaveDate = LocalDate.fromDateFields(timeBlock.getBeginDate());
                        BigDecimal leaveAmount = timeBlock.getHours();
                        //What if [can] the units are [be] days?

                        LeaveBlock.Builder builder = new LeaveBlock.Builder(leaveDate, null, principalId,
                                overtimeEarnCode.getEarnCode(), leaveAmount)
                                        .accrualCategory(accrualCategory.getAccrualCategory())
                                        .leaveBlockType(LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE)
                                        .requestStatus(HrConstants.REQUEST_STATUS.APPROVED);

                        leaveBlocks.add(builder.build());
                    }//from w w  w.j a v  a  2  s. c  o  m
                }
            }

            LmServiceLocator.getLeaveBlockService().saveLeaveBlocks(leaveBlocks);
        }
    }
}

From source file:org.kuali.kpme.tklm.time.workflow.postprocessor.TkPostProcessor.java

License:Educational Community License

private void calculateMaxCarryOver(TimesheetDocumentHeader timesheetDocumentHeader,
        DocumentStatus newDocumentStatus) {
    String documentId = timesheetDocumentHeader.getDocumentId();
    String principalId = timesheetDocumentHeader.getPrincipalId();
    DateTime endDate = timesheetDocumentHeader.getEndDateTime();
    DateTime beginDate = timesheetDocumentHeader.getBeginDateTime();
    if (DocumentStatus.ENROUTE.equals(newDocumentStatus)) {
        //create pending carry over leave blocks.

        Calendar calendar = HrServiceLocator.getCalendarService().getCalendarByPrincipalIdAndDate(principalId,
                endDate.toLocalDate(), true);

        if (calendar != null) {
            List<CalendarEntry> calendarEntries = HrServiceLocator.getCalendarEntryService()
                    .getCalendarEntriesEndingBetweenBeginAndEndDate(calendar.getHrCalendarId(), beginDate,
                            endDate);/*  w  w  w .j ava2 s .  c  o m*/

            LmServiceLocator.getAccrualCategoryMaxCarryOverService().calculateMaxCarryOver(documentId,
                    principalId, calendarEntries, endDate.toLocalDate());
        }
    } else if (DocumentStatus.FINAL.equals(newDocumentStatus)) {
        // TODO: HrServiceLocator.getMaxCarryOverService.updateCarryOverLeaveBlockStatus(principalId, timesheetDocumentHeader.getBeginDateTime().toLocalDate(), endDate.toLocalDate());
        //approve the carry over leave block.
        List<LeaveBlock> leaveBlocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principalId,
                timesheetDocumentHeader.getBeginDateTime().toLocalDate(), endDate.toLocalDate());
        for (LeaveBlock lb : leaveBlocks) {
            if (StringUtils.equals(lb.getLeaveBlockType(),
                    LMConstants.LEAVE_BLOCK_TYPE.CARRY_OVER_ADJUSTMENT)) {
                lb.setRequestStatus(HrConstants.REQUEST_STATUS.APPROVED);
                LmServiceLocator.getLeaveBlockService().updateLeaveBlock(lb, HrContext.getPrincipalId());
            }
        }
    }
}

From source file:org.libreplan.web.planner.allocation.AdvancedAllocationController.java

License:Open Source License

private EffortDuration getEffortForDetailItem(DetailItem item) {
    DateTime startDate = item.getStartDate();
    DateTime endDate = item.getEndDate();

    return this.aggregate.effortBetween(startDate.toLocalDate(), endDate.toLocalDate());
}

From source file:org.mifos.accounts.business.AccountBO.java

License:Open Source License

/**
 * @deprecated - used to create installment dates based on 'loan meeting' and working das, holidays, moratoria etc
 *
 * better to pull capability of creating 'installments' out of loan into something more reuseable and isolated
 *///  w  w w. jav a  2s.  c  o m
@Deprecated
public final List<InstallmentDate> getInstallmentDates(final MeetingBO meeting, final Short noOfInstallments,
        final Short installmentToSkip, final boolean isRepaymentIndepOfMeetingEnabled,
        final boolean adjustForHolidays) {

    logger.debug("Generating intallment dates");

    List<InstallmentDate> dueInstallmentDates = new ArrayList<InstallmentDate>();
    if (noOfInstallments > 0) {
        List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
        List<Holiday> holidays = new ArrayList<Holiday>();

        DateTime startFromMeetingDate = new DateTime(meeting.getMeetingStartDate());

        if (adjustForHolidays) {
            HolidayDao holidayDao = ApplicationContextProvider.getBean(HolidayDao.class);
            holidays = holidayDao.findAllHolidaysFromDateAndNext(getOffice().getOfficeId(),
                    startFromMeetingDate.toLocalDate().toString());
        }

        final int occurrences = noOfInstallments + installmentToSkip;

        ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(meeting);
        ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(
                workingDays, holidays);

        List<Date> dueDates = new ArrayList<Date>();
        // FIXME - keithw - this whole area of installment creation should be pulled out of domain
        DateTime startFromDayAfterAssignedMeetingDateRatherThanSkippingInstallments = startFromMeetingDate;
        if (this.isLoanAccount()) {
            // ensure loans that are created or disbursed on a meeting date start on next valid meeting date and not todays meeting
            // ensure loans that are created or disbursed before a meeting date start on next valid meeting date
            startFromDayAfterAssignedMeetingDateRatherThanSkippingInstallments = startFromMeetingDate
                    .plusDays(1);
        }
        List<DateTime> installmentDates = dateGeneration.generateScheduledDates(occurrences,
                startFromDayAfterAssignedMeetingDateRatherThanSkippingInstallments, scheduledEvent, false);
        for (DateTime installmentDate : installmentDates) {
            dueDates.add(installmentDate.toDate());
        }

        dueInstallmentDates = createInstallmentDates(installmentToSkip, dueDates);
    }
    return dueInstallmentDates;
}

From source file:org.mifos.accounts.loan.struts.action.LoanAccountAction.java

License:Open Source License

private LoanAccountInfoDto getLoanAccountInfo(LoanAccountActionForm loanActionForm, DateTime disbursementDate,
        Integer customerId, Short fundId) {
    LoanAccountInfoDto loanAccountInfo = new LoanAccountInfoDto();
    loanAccountInfo.setCustomerId(customerId);
    loanAccountInfo.setFundId(fundId);//from ww w. j av a 2s  .c om
    loanAccountInfo.setDisbursementDate(disbursementDate.toLocalDate());

    loanAccountInfo.setProductId(loanActionForm.getPrdOfferingIdValue());
    loanAccountInfo.setLoanAmount(loanActionForm.getLoanAmount());
    loanAccountInfo.setInterestDeductedAtDisbursement(loanActionForm.isInterestDedAtDisbValue());
    loanAccountInfo.setInterest(loanActionForm.getInterestDoubleValue());
    loanAccountInfo.setGracePeriod(loanActionForm.getGracePeriodDurationValue());
    loanAccountInfo.setMaxLoanAmount(loanActionForm.getMaxLoanAmount());
    loanAccountInfo.setMinLoanAmount(loanActionForm.getMinLoanAmount());
    loanAccountInfo.setNumOfInstallments(loanActionForm.getNoOfInstallmentsValue());
    loanAccountInfo.setMaxNumOfInstallments(loanActionForm.getMaxNoInstallmentsValue());
    loanAccountInfo.setMinNumOfInstallments(loanActionForm.getMinNoInstallmentsValue());
    loanAccountInfo.setExternalId(loanActionForm.getExternalId());
    loanAccountInfo.setSelectedLoanPurpose(loanActionForm.getBusinessActivityIdValue());
    loanAccountInfo.setSelectedCollateralType(loanActionForm.getCollateralTypeIdValue());
    loanAccountInfo.setCollateralNote(loanActionForm.getCollateralNote());
    loanAccountInfo.setAccountState(loanActionForm.getState().getValue());

    List<CreateAccountFeeDto> accountFeesToCreate = new ArrayList<CreateAccountFeeDto>();
    for (FeeDto feeToApply : loanActionForm.getFeesToApply()) {
        accountFeesToCreate
                .add(new CreateAccountFeeDto(Integer.valueOf(feeToApply.getFeeId()), feeToApply.getAmount()));
    }
    loanAccountInfo.setFees(accountFeesToCreate);

    return loanAccountInfo;
}

From source file:org.mifos.clientportfolio.newloan.domain.IndividualLoanScheduleFactory.java

License:Open Source License

@Override
public LoanSchedule create(LocalDate disbursementDate, List<DateTime> loanScheduleDates,
        List<Number> totalInstallmentAmounts, LoanOfferingBO loanProduct, CustomerBO customer,
        MeetingBO loanMeeting, Money loanAmount, Double interestRate, Integer interestDays,
        Integer gracePeriodDuration, List<AccountFeesEntity> accountFees) {

    GraceType graceType = loanProduct.getGraceType();
    InterestType interestType = loanProduct.getInterestType();
    boolean variableInstallmentLoanProduct = loanProduct.isVariableInstallmentsAllowed();
    Integer numberOfInstallments = loanScheduleDates.size();

    RecurringScheduledEventFactory scheduledEventFactory = new RecurringScheduledEventFactoryImpl();
    ScheduledEvent meetingScheduledEvent = scheduledEventFactory.createScheduledEventFrom(loanMeeting);

    Integer installmentNumber = 1;
    List<InstallmentDate> dueInstallmentDates = new ArrayList<InstallmentDate>();
    for (DateTime scheduledDate : loanScheduleDates) {
        dueInstallmentDates.add(new InstallmentDate(installmentNumber.shortValue(),
                scheduledDate.toLocalDate().toDateMidnight().toDate()));
        installmentNumber++;//from ww  w  .jav a  2s .  com
    }

    if (loanProduct.isPrinDueLastInst()) {
        // Principal due on last installment has been cut, so throw an exception if we reach this code.
        throw new BusinessRuleException(AccountConstants.NOT_SUPPORTED_EMI_GENERATION);
    }

    // loan interest calculation for various interest calculation algorithms
    LoanDecliningInterestAnnualPeriodCalculator decliningInterestAnnualPeriodCalculator = new LoanDecliningInterestAnnualPeriodCalculatorFactory()
            .create(loanMeeting.getRecurrenceType());
    Double decliningInterestAnnualPeriod = decliningInterestAnnualPeriodCalculator
            .calculate(loanMeeting.getRecurAfter().intValue(), interestDays);
    Double interestFractionalRatePerInstallment = interestRate / decliningInterestAnnualPeriod / 100;

    LoanDurationInAccountingYearsCalculator loanDurationInAccountingYearsCalculator = new LoanDurationInAccountingYearsCalculatorFactory()
            .create(loanMeeting.getRecurrenceType());

    Double durationInYears = loanDurationInAccountingYearsCalculator
            .calculate(loanMeeting.getRecurAfter().intValue(), numberOfInstallments, interestDays);

    List<Money> totalInstallmentAmountsAsMoney = new ArrayList<Money>();
    for (Number totalInstallmentAmount : totalInstallmentAmounts) {
        Money totalAmount = new Money(loanAmount.getCurrency(),
                BigDecimal.valueOf(totalInstallmentAmount.doubleValue()));
        totalInstallmentAmountsAsMoney.add(totalAmount);
    }

    LoanInterestCalculationDetails loanInterestCalculationDetails = new LoanInterestCalculationDetails(
            loanAmount, interestRate, graceType, gracePeriodDuration, numberOfInstallments, durationInYears,
            interestFractionalRatePerInstallment, disbursementDate, loanScheduleDates);
    loanInterestCalculationDetails.setTotalInstallmentAmounts(totalInstallmentAmountsAsMoney);

    LoanInterestCalculatorFactory loanInterestCalculatorFactory = new LoanInterestCalculatorFactoryImpl();
    LoanInterestCalculator loanInterestCalculator = loanInterestCalculatorFactory.create(interestType,
            variableInstallmentLoanProduct);
    Money loanInterest = loanInterestCalculator.calculate(loanInterestCalculationDetails);
    // end of loan Interest creation

    EqualInstallmentGeneratorFactory equalInstallmentGeneratorFactory = new EqualInstallmentGeneratorFactoryImpl();
    PrincipalWithInterestGenerator equalInstallmentGenerator = equalInstallmentGeneratorFactory
            .create(interestType, loanInterest, variableInstallmentLoanProduct);

    List<InstallmentPrincipalAndInterest> EMIInstallments = equalInstallmentGenerator
            .generateEqualInstallments(loanInterestCalculationDetails);

    List<LoanScheduleEntity> unroundedLoanSchedules = createUnroundedLoanSchedulesFromInstallments(
            dueInstallmentDates, loanInterest, loanAmount, meetingScheduledEvent, EMIInstallments, accountFees,
            customer);

    Money rawAmount = calculateTotalFeesAndInterestForLoanSchedules(unroundedLoanSchedules,
            loanAmount.getCurrency(), accountFees);

    List<LoanScheduleEntity> allExistingLoanSchedules = new ArrayList<LoanScheduleEntity>();

    List<LoanScheduleEntity> finalisedLoanSchedules = new ArrayList<LoanScheduleEntity>(unroundedLoanSchedules);
    if (variableInstallmentLoanProduct && totalInstallmentAmounts.isEmpty()) {
        // only round inital loan schedule of variable installments product.
        LoanScheduleRounder loanScheduleInstallmentRounder = new VariableInstallmentLoanScheduleRounder();
        finalisedLoanSchedules = loanScheduleInstallmentRounder.round(graceType,
                gracePeriodDuration.shortValue(), loanAmount, interestType, unroundedLoanSchedules,
                allExistingLoanSchedules);
    } else if (!variableInstallmentLoanProduct) {
        LoanScheduleRounderHelper loanScheduleRounderHelper = new DefaultLoanScheduleRounderHelper();
        LoanScheduleRounder loanScheduleInstallmentRounder = new DefaultLoanScheduleRounder(
                loanScheduleRounderHelper);
        finalisedLoanSchedules = loanScheduleInstallmentRounder.round(graceType,
                gracePeriodDuration.shortValue(), loanAmount, interestType, unroundedLoanSchedules,
                allExistingLoanSchedules);
    }

    return new LoanSchedule(finalisedLoanSchedules, rawAmount);
}

From source file:org.mifos.platform.rest.controller.LoanAccountRESTController.java

License:Open Source License

@RequestMapping(value = "/account/loan/num-{globalAccountNum}/repay", method = RequestMethod.POST)
public @ResponseBody Map<String, String> repay(@PathVariable String globalAccountNum,
        @RequestParam BigDecimal amount, @RequestParam(required = false) String paymentDate,
        @RequestParam(required = false) Short receiptId, @RequestParam(required = false) String receiptDate,
        @RequestParam Short paymentModeId) throws Exception {

    validateAmount(amount);//from   w ww.jav a2s. co m

    LoanBO loan = loanDao.findByGlobalAccountNum(globalAccountNum);

    validateLoanAccountState(loan);

    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserReferenceDto userDto = new UserReferenceDto((short) user.getUserId());

    Money outstandingBeforePayment = loan.getLoanSummary().getOutstandingBalance();

    AccountReferenceDto accountDto = new AccountReferenceDto(loan.getAccountId());

    DateTime today = new DateTime();

    DateTime paymentDateTime = today;
    if (paymentDate != null && !paymentDate.isEmpty()) {
        paymentDateTime = validateDateString(paymentDate, format);
    }

    String receiptIdString = null;
    if (receiptId != null) {
        receiptIdString = receiptId.toString();
    }

    LocalDate receiptLocalDate = null;
    if (receiptDate != null && !receiptDate.isEmpty()) {
        receiptLocalDate = validateDateString(receiptDate, format).toLocalDate();
    }

    PaymentTypeDto paymentType = new PaymentTypeDto(paymentModeId, "");
    validatePaymentTypeId(paymentType, accountService.getLoanPaymentTypes());

    CustomerBO client = loan.getCustomer();
    CustomerDto customer = new CustomerDto();
    customer.setCustomerId(client.getCustomerId());
    AccountPaymentParametersDto payment = new AccountPaymentParametersDto(userDto, accountDto, amount,
            paymentDateTime.toLocalDate(), paymentType, globalAccountNum, receiptLocalDate, receiptIdString,
            customer);

    accountService.makePayment(payment);

    Map<String, String> map = new HashMap<String, String>();
    map.put("status", "success");
    map.put("clientName", client.getDisplayName());
    map.put("clientNumber", client.getGlobalCustNum());
    map.put("loanDisplayName", loan.getLoanOffering().getPrdOfferingName());
    map.put("paymentDate", today.toLocalDate().toString());
    map.put("paymentTime", today.toLocalTime().toString());
    map.put("paymentAmount", loan.getLastPmnt().getAmount().toString());
    map.put("paymentMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
    map.put("outstandingBeforePayment", outstandingBeforePayment.toString());
    map.put("outstandingAfterPayment", loan.getLoanSummary().getOutstandingBalance().toString());
    return map;
}

From source file:org.mifos.platform.rest.controller.LoanAccountRESTController.java

License:Open Source License

@RequestMapping(value = "/account/loan/num-{globalAccountNum}/fullrepay", method = RequestMethod.POST)
public @ResponseBody Map<String, String> fullRepay(@PathVariable String globalAccountNum,
        @RequestParam(required = false) String paymentDate, @RequestParam(required = false) Short receiptId,
        @RequestParam(required = false) String receiptDate, @RequestParam Short paymentModeId,
        @RequestParam Boolean waiveInterest) throws Exception {

    LoanBO loan = this.loanDao.findByGlobalAccountNum(globalAccountNum);
    validateLoanAccountState(loan);/*  www .  j a v a  2 s .  c o m*/

    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

    RepayLoanDto repayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(globalAccountNum);

    DateTime today = new DateTime();

    Date paymentDateTime = new Date(today.toDate().getTime());
    if (paymentDate != null && !paymentDate.isEmpty()) {
        paymentDateTime = new Date(validateDateString(paymentDate, format).toDate().getTime());
    }

    String receiptIdString = null;
    if (receiptId != null) {
        receiptIdString = receiptId.toString();
    }

    Date receiptDateTime = null;
    if (receiptDate != null && !receiptDate.isEmpty()) {
        receiptDateTime = new Date(validateDateString(receiptDate, format).toDate().getTime());
    }

    String paymentTypeId = "1";
    if (paymentModeId != null) {
        paymentTypeId = paymentModeId.toString();
    }
    validateDisbursementPaymentTypeId(paymentModeId, accountService.getLoanPaymentTypes());
    BigDecimal totalRepaymentAmount = (new Money(loan.getCurrency(), repayLoanDto.getEarlyRepaymentMoney()))
            .getAmount();
    BigDecimal waivedAmount = (new Money(loan.getCurrency(), repayLoanDto.getWaivedRepaymentMoney()))
            .getAmount();
    BigDecimal earlyRepayAmount = totalRepaymentAmount;
    if (Boolean.TRUE.equals(waiveInterest)) {
        earlyRepayAmount = waivedAmount;
    }
    RepayLoanInfoDto repayLoanInfoDto = new RepayLoanInfoDto(globalAccountNum,
            Double.toString(earlyRepayAmount.doubleValue()), receiptIdString, receiptDateTime, paymentTypeId,
            (short) user.getUserId(), waiveInterest.booleanValue(), paymentDateTime, totalRepaymentAmount,
            waivedAmount);

    Money outstandingBeforePayment = loan.getLoanSummary().getOutstandingBalance();

    this.loanAccountServiceFacade.makeEarlyRepaymentWithCommit(repayLoanInfoDto);

    CustomerBO client = loan.getCustomer();

    Map<String, String> map = new HashMap<String, String>();
    map.put("status", "success");
    map.put("clientName", client.getDisplayName());
    map.put("clientNumber", client.getGlobalCustNum());
    map.put("loanDisplayName", loan.getLoanOffering().getPrdOfferingName());
    map.put("paymentDate", today.toLocalDate().toString());
    map.put("paymentTime", today.toLocalTime().toString());
    map.put("paymentAmount", loan.getLastPmnt().getAmount().toString());
    map.put("paymentMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
    map.put("outstandingBeforePayment", outstandingBeforePayment.toString());
    map.put("outstandingAfterPayment", loan.getLoanSummary().getOutstandingBalance().toString());

    return map;
}