Example usage for org.joda.time LocalDate isEqual

List of usage examples for org.joda.time LocalDate isEqual

Introduction

In this page you can find the example usage for org.joda.time LocalDate isEqual.

Prototype

public boolean isEqual(ReadablePartial partial) 

Source Link

Document

Is this partial the same as the specified partial.

Usage

From source file:org.mifosplatform.portfolio.loanaccount.domain.HeavensFamilyLoanRepaymentScheduleTransactionProcessor.java

License:Mozilla Public License

@Override
protected boolean isTransactionInAdvanceOfInstallment(final int currentInstallmentIndex,
        final List<LoanRepaymentScheduleInstallment> installments, final LocalDate transactionDate,
        final Money transactionAmount) {

    boolean isInAdvance = false;

    LocalDate lastInstallmentDueDate = null;
    int previousInstallmentIndex = 0;
    if (currentInstallmentIndex > 0) {
        previousInstallmentIndex = currentInstallmentIndex - 1;
    }//from w w w .j a  v a 2 s .c  o  m

    LoanRepaymentScheduleInstallment previousInstallment = installments.get(previousInstallmentIndex);
    lastInstallmentDueDate = previousInstallment.getDueDate();

    isInAdvance = !(transactionDate.isAfter(lastInstallmentDueDate)
            || (transactionDate.isEqual(lastInstallmentDueDate)));

    return isInAdvance;
}

From source file:org.mifosplatform.portfolio.loanaccount.domain.Loan.java

License:Mozilla Public License

public void updateLoanRepaymentScheduleDates(final LocalDate meetingStartDate, final String recuringRule,
        final boolean isHolidayEnabled, final List<Holiday> holidays, final WorkingDays workingDays,
        final Boolean reschedulebasedOnMeetingDates, final LocalDate presentMeetingDate,
        final LocalDate newMeetingDate) {

    // first repayment's from date is same as disbursement date.
    /*//from  www  .j a v  a  2s.co  m
     * meetingStartDate is used as seedDate Capture the seedDate from user
     * and use the seedDate as meetingStart date
     */

    LocalDate tmpFromDate = getDisbursementDate();
    final PeriodFrequencyType repaymentPeriodFrequencyType = this.loanRepaymentScheduleDetail
            .getRepaymentPeriodFrequencyType();
    final Integer loanRepaymentInterval = this.loanRepaymentScheduleDetail.getRepayEvery();
    final String frequency = CalendarUtils
            .getMeetingFrequencyFromPeriodFrequencyType(repaymentPeriodFrequencyType);

    LocalDate newRepaymentDate = null;
    Boolean isFirstTime = true;

    for (final LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment : this.repaymentScheduleInstallments) {

        LocalDate oldDueDate = loanRepaymentScheduleInstallment.getDueDate();

        if (oldDueDate.isEqual(presentMeetingDate) || oldDueDate.isAfter(presentMeetingDate)) {

            if (isFirstTime) {

                isFirstTime = false;
                newRepaymentDate = newMeetingDate;

            } else {
                // tmpFromDate.plusDays(1) is done to make sure
                // getNewRepaymentMeetingDate method returns next meeting
                // date and not the same as tmpFromDate
                newRepaymentDate = CalendarUtils.getNewRepaymentMeetingDate(recuringRule, tmpFromDate,
                        tmpFromDate.plusDays(1), loanRepaymentInterval, frequency, workingDays);
            }

            if (isHolidayEnabled) {
                newRepaymentDate = HolidayUtil.getRepaymentRescheduleDateToIfHoliday(newRepaymentDate,
                        holidays);
            }

            loanRepaymentScheduleInstallment.updateDueDate(newRepaymentDate);
            // reset from date to get actual daysInPeriod

            if (!isFirstTime) {
                loanRepaymentScheduleInstallment.updateFromDate(tmpFromDate);
            }

            tmpFromDate = newRepaymentDate;// update with new repayment
            // date
        } else {
            tmpFromDate = oldDueDate;
        }
    }
}

From source file:org.mifosplatform.portfolio.loanaccount.loanschedule.domain.AbstractLoanScheduleGenerator.java

License:Mozilla Public License

/**
 * Method calculates interest on not paid outstanding principal and interest
 * (if compounding is enabled) till current date and adds new repayment
 * schedule detail//from w w  w .j  ava 2 s . co  m
 * 
 * @param compoundingMap
 *            TODO
 * @param loanCharges
 *            TODO
 * @param principalPortioMap
 *            TODO
 * 
 */
private Money addInterestOnlyRepaymentScheduleForCurrentdate(final MathContext mc,
        final LoanApplicationTerms loanApplicationTerms, final HolidayDetailDTO holidayDetailDTO,
        final MonetaryCurrency currency, final Collection<LoanScheduleModelPeriod> periods,
        LocalDate periodStartDate, LocalDate actualRepaymentDate, int instalmentNumber,
        Map<LocalDate, Money> latePaymentMap, final LocalDate currentDate,
        LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor,
        final Map<LocalDate, Money> principalPortionMap, TreeMap<LocalDate, Money> compoundingMap,
        final Collection<RecalculationDetail> transactions,
        final List<LoanRepaymentScheduleInstallment> installments, Set<LoanCharge> loanCharges) {
    boolean isFirstRepayment = false;
    LocalDate startDate = periodStartDate;
    Money outstanding = Money.zero(currency);
    Money totalInterest = Money.zero(currency);
    Money totalCumulativeInterest = Money.zero(currency);
    Map<LocalDate, Money> disburseDetailsMap = new HashMap<>();
    double interestCalculationGraceOnRepaymentPeriodFraction = Double.valueOf(0);
    int periodNumberTemp = 1;
    LocalDate lastRestDate = getNextRestScheduleDate(currentDate.minusDays(1), loanApplicationTerms,
            holidayDetailDTO);
    do {

        actualRepaymentDate = this.scheduledDateGenerator.generateNextRepaymentDate(actualRepaymentDate,
                loanApplicationTerms, isFirstRepayment);
        int daysInPeriod = Days.daysBetween(periodStartDate, actualRepaymentDate).getDays();
        if (actualRepaymentDate.isAfter(currentDate)) {
            actualRepaymentDate = currentDate;
        }
        outstanding = updateOutstandingFromLatePayment(periodStartDate, latePaymentMap, outstanding);

        Collection<RecalculationDetail> applicableTransactions = getApplicableTransactionsForPeriod(
                loanApplicationTerms, actualRepaymentDate, transactions);

        if (!latePaymentMap.isEmpty()) {
            populateCompoundingDatesInPeriod(periodStartDate, actualRepaymentDate, currentDate,
                    loanApplicationTerms, holidayDetailDTO, compoundingMap, loanCharges, currency);
        }

        for (RecalculationDetail detail : applicableTransactions) {
            if (detail.isProcessed()) {
                continue;
            }
            List<LoanTransaction> currentTransactions = createCurrentTransactionList(detail);

            if (!periodStartDate.isEqual(detail.getTransactionDate())) {
                PrincipalInterest principalInterestForThisPeriod = calculatePrincipalInterestComponentsForPeriod(
                        this.paymentPeriodsInOneYearCalculator,
                        interestCalculationGraceOnRepaymentPeriodFraction, totalInterest.zero(),
                        totalInterest.zero(), totalInterest.zero(), totalInterest.zero(), outstanding,
                        loanApplicationTerms, periodNumberTemp, mc,
                        mergeVariationsToMap(principalPortionMap, latePaymentMap, disburseDetailsMap,
                                compoundingMap),
                        compoundingMap, periodStartDate, detail.getTransactionDate(), daysInPeriod);

                Money interest = principalInterestForThisPeriod.interest();
                totalInterest = totalInterest.plus(interest);

                LoanScheduleModelRepaymentPeriod installment = LoanScheduleModelRepaymentPeriod.repayment(
                        instalmentNumber++, startDate, detail.getTransactionDate(), totalInterest.zero(),
                        totalInterest.zero(), totalInterest, totalInterest.zero(), totalInterest.zero(),
                        totalInterest, true);
                periods.add(installment);
                totalCumulativeInterest = totalCumulativeInterest.plus(totalInterest);
                totalInterest = totalInterest.zero();
                addLoanRepaymentScheduleInstallment(installments, installment);
                periodStartDate = detail.getTransactionDate();
                startDate = detail.getTransactionDate();
            }
            loanRepaymentScheduleTransactionProcessor.handleRepaymentSchedule(currentTransactions, currency,
                    installments);
            updateLatePaymentsToMap(loanApplicationTerms, holidayDetailDTO, currency, latePaymentMap,
                    currentDate, installments, false, lastRestDate, compoundingMap);
            outstanding = outstanding.zero();
            outstanding = updateOutstandingFromLatePayment(periodStartDate, latePaymentMap, outstanding);
            outstanding = updateBalanceForInterestCalculation(principalPortionMap, periodStartDate, outstanding,
                    false);
            if (latePaymentMap.isEmpty() && !outstanding.isGreaterThanZero()) {
                break;
            }
        }

        if (outstanding.isGreaterThanZero()) {
            PrincipalInterest principalInterestForThisPeriod = calculatePrincipalInterestComponentsForPeriod(
                    this.paymentPeriodsInOneYearCalculator, interestCalculationGraceOnRepaymentPeriodFraction,
                    totalInterest.zero(), totalInterest.zero(), totalInterest.zero(), totalInterest.zero(),
                    outstanding, loanApplicationTerms, periodNumberTemp, mc,
                    mergeVariationsToMap(principalPortionMap, latePaymentMap, disburseDetailsMap,
                            compoundingMap),
                    compoundingMap, periodStartDate, actualRepaymentDate, daysInPeriod);
            Money interest = principalInterestForThisPeriod.interest();
            totalInterest = totalInterest.plus(interest);
            if (loanApplicationTerms.getInterestRecalculationCompoundingMethod()
                    .isInterestCompoundingEnabled()) {
                LocalDate compoundingEffectiveDate = getNextCompoundScheduleDate(
                        actualRepaymentDate.minusDays(1), loanApplicationTerms, holidayDetailDTO);
                latePaymentMap.put(compoundingEffectiveDate, interest);

            }
        }
        periodStartDate = actualRepaymentDate;
    } while (actualRepaymentDate.isBefore(currentDate) && outstanding.isGreaterThanZero());

    if (totalInterest.isGreaterThanZero()) {
        LoanScheduleModelRepaymentPeriod installment = LoanScheduleModelRepaymentPeriod.repayment(
                instalmentNumber++, startDate, actualRepaymentDate, totalInterest.zero(), totalInterest.zero(),
                totalInterest, totalInterest.zero(), totalInterest.zero(), totalInterest, true);
        periods.add(installment);
        totalCumulativeInterest = totalCumulativeInterest.plus(totalInterest);
    }
    return totalCumulativeInterest;
}

From source file:pt.ulisboa.tecnico.softeng.car.domain.Renting.java

/**
 * @param begin/*from  w ww.  ja  v  a  2s  . c  o m*/
 * @param end
 * @return <code>true</code> if this Renting conflicts with the given date
 *         range.
 */
public boolean conflict(LocalDate begin, LocalDate end) {
    if (end.isBefore(begin)) {
        throw new CarException("Error: end date is before begin date.");
    } else if ((begin.equals(this.getBegin()) || begin.isAfter(this.getBegin()))
            && (begin.isBefore(this.getEnd()) || begin.equals(this.getEnd()))) {
        return true;
    } else if ((end.equals(this.getEnd()) || end.isBefore(this.getEnd()))
            && (end.isAfter(this.getBegin()) || end.isEqual(this.getBegin()))) {
        return true;
    } else if (begin.isBefore(this.getBegin()) && end.isAfter(this.getEnd())) {
        return true;
    }

    return false;
}

From source file:ru.codemine.ccms.sales.domino.DominoSalesLoader.java

License:Open Source License

private Map<LocalDate, Map<String, Sales>> getSalesMap() {
    File path = new File(settingsService.getStorageEmailPath());
    FilenameFilter filter = new EndsWithFilenameFilter(".xls", EndsWithFilenameFilter.NEVER);
    Map<LocalDate, Map<String, Sales>> result = new HashMap();
    for (File file : path.listFiles(filter)) {
        try {//from  ww  w .j  a v  a2 s  .  c  o  m

            log.info(" : " + file.getName());

            FileInputStream fs = new FileInputStream(file);
            HSSFWorkbook workbook = new HSSFWorkbook(fs);
            HSSFSheet sheet = workbook.getSheetAt(0);
            boolean dateFound = false;
            boolean colFound = false;
            Integer colNumber = 0;
            LocalDate fileDate = null;
            Map<String, Sales> parsedFileMap = new HashMap();

            for (Row row : sheet) {
                Cell firstCell = row.getCell(0);

                //
                // ?  
                //
                if (firstCell.getCellType() == Cell.CELL_TYPE_STRING && firstCell.getStringCellValue()
                        .startsWith("    ")) {
                    String bothDatesStr = firstCell.getStringCellValue()
                            .replace("     ? ", "");
                    String[] datesStr = bothDatesStr.split("  ");
                    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY");
                    LocalDate startDate = formatter.parseLocalDate(datesStr[0]);
                    LocalDate endDate = formatter.parseLocalDate(datesStr[1]);
                    if (startDate != null && startDate.isEqual(endDate)) {
                        dateFound = true;
                        fileDate = startDate;
                        log.info(" : " + fileDate);
                    }

                }

                //
                // ? ? ? ? ?
                //

                else if (firstCell.getCellType() == Cell.CELL_TYPE_STRING
                        && firstCell.getStringCellValue().startsWith(" /")) {
                    for (Cell headersCell : row) {
                        if (headersCell.getCellType() == Cell.CELL_TYPE_STRING && headersCell
                                .getStringCellValue().startsWith(" ??")) {
                            colFound = true;
                            colNumber = headersCell.getColumnIndex();
                            log.info(" : " + colNumber);
                        }
                    }
                }

                //
                // ?   ? 
                //

                else if (dateFound && colFound && firstCell.getCellType() == Cell.CELL_TYPE_STRING
                        && firstCell.getStringCellValue().startsWith(":")) {
                    Sales sale = new Sales();

                    // ?  
                    String namesStr = firstCell.getStringCellValue().replace(": ",
                            "");
                    String delimiter = " - ";
                    if (namesStr.indexOf(delimiter) > 0
                            && namesStr.indexOf(delimiter) != namesStr.lastIndexOf(delimiter)) {
                        String name = namesStr.substring(namesStr.indexOf(delimiter) + delimiter.length(),
                                namesStr.lastIndexOf(delimiter));

                        //  ? 
                        boolean shopFinished = false;
                        int rcrd = 1;
                        int cashb_rcrd = 0;
                        while (!shopFinished) {
                            Row r = sheet.getRow(row.getRowNum() + rcrd);
                            if (r.getCell(0).getCellType() == Cell.CELL_TYPE_NUMERIC) // ? ?   
                            {
                                Double val = r.getCell(colNumber).getNumericCellValue();
                                //log.debug("i is: " + i + ", val is: " + val);
                                if (val > 0)
                                    sale.setValue(sale.getValue() + val); //
                                else {
                                    sale.setCashback(sale.getCashback() - val); //
                                    cashb_rcrd++;
                                }
                            } else if (r.getCell(0).getStringCellValue().startsWith(" :")) {
                                //log.debug("finished shop record, i is: " + i);
                                sale.setChequeCount(rcrd - cashb_rcrd - 1);
                                shopFinished = true;
                            }

                            rcrd++;
                        }

                        parsedFileMap.put(name, sale);
                        //Double value = row.getCell(colNumber).getNumericCellValue();
                        //parsedFileMap.put(name, value);
                        //log.debug("Recieved file map: " + parsedFileMap);
                    }

                }

            } // foreach row in sheet

            if (dateFound && colFound) {
                result.put(fileDate, parsedFileMap);
                log.info("...ok");
                Files.delete(file.toPath());
            } else {
                if (!dateFound) {
                    log.warn("     " + file.getName());
                }
                if (!colFound) {
                    log.warn(" ?      "
                            + file.getName());
                }
                log.error("?   " + file.getName());
            }

        } catch (Exception e) {
            //e.printStackTrace();
            log.error("?  ,  : "
                    + e.getMessage());
        }

    } // foreach file in path

    return result;
}