Example usage for org.joda.time LocalDate withDayOfMonth

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

Introduction

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

Prototype

public LocalDate withDayOfMonth(int dayOfMonth) 

Source Link

Document

Returns a copy of this date with the day of month field updated.

Usage

From source file:org.apache.fineract.portfolio.account.service.StandingInstructionWritePlatformServiceImpl.java

License:Apache License

@Override
@CronTarget(jobName = JobName.EXECUTE_STANDING_INSTRUCTIONS)
public void executeStandingInstructions() throws JobExecutionException {
    Collection<StandingInstructionData> instructionDatas = this.standingInstructionReadPlatformService
            .retrieveAll(StandingInstructionStatus.ACTIVE.getValue());
    final StringBuilder sb = new StringBuilder();
    for (StandingInstructionData data : instructionDatas) {
        boolean isDueForTransfer = false;
        AccountTransferRecurrenceType recurrenceType = data.recurrenceType();
        StandingInstructionType instructionType = data.instructionType();
        LocalDate transactionDate = new LocalDate();
        if (recurrenceType.isPeriodicRecurrence()) {
            final ScheduledDateGenerator scheduledDateGenerator = new DefaultScheduledDateGenerator();
            PeriodFrequencyType frequencyType = data.recurrenceFrequency();
            LocalDate startDate = data.validFrom();
            if (frequencyType.isMonthly()) {
                startDate = startDate.withDayOfMonth(data.recurrenceOnDay());
                if (startDate.isBefore(data.validFrom())) {
                    startDate = startDate.plusMonths(1);
                }/* www.jav a 2 s . co  m*/
            } else if (frequencyType.isYearly()) {
                startDate = startDate.withDayOfMonth(data.recurrenceOnDay())
                        .withMonthOfYear(data.recurrenceOnMonth());
                if (startDate.isBefore(data.validFrom())) {
                    startDate = startDate.plusYears(1);
                }
            }
            isDueForTransfer = scheduledDateGenerator.isDateFallsInSchedule(frequencyType,
                    data.recurrenceInterval(), startDate, transactionDate);

        }
        BigDecimal transactionAmount = data.amount();
        if (data.toAccountType().isLoanAccount() && (recurrenceType.isDuesRecurrence()
                || (isDueForTransfer && instructionType.isDuesAmoutTransfer()))) {
            StandingInstructionDuesData standingInstructionDuesData = this.standingInstructionReadPlatformService
                    .retriveLoanDuesData(data.toAccount().accountId());
            if (data.instructionType().isDuesAmoutTransfer()) {
                transactionAmount = standingInstructionDuesData.totalDueAmount();
            }
            if (recurrenceType.isDuesRecurrence()) {
                isDueForTransfer = new LocalDate().equals(standingInstructionDuesData.dueDate());
            }
        }

        if (isDueForTransfer && transactionAmount != null && transactionAmount.compareTo(BigDecimal.ZERO) > 0) {
            final AccountTransferDetails accountTransferDetails = this.accountTransferDetailRepository
                    .findOne(data.accountDetailId());
            final SavingsAccount fromSavingsAccount = null;
            final boolean isRegularTransaction = true;
            final boolean isExceptionForBalanceCheck = false;
            accountTransferDetails.accountTransferStandingInstruction()
                    .updateLatsRunDate(transactionDate.toDate());
            AccountTransferDTO accountTransferDTO = new AccountTransferDTO(transactionDate, transactionAmount,
                    data.fromAccountType(), data.toAccountType(), data.fromAccount().accountId(),
                    data.toAccount().accountId(), data.name() + " Standing instruction trasfer ", null, null,
                    null, null, data.toTransferType(), null, null, data.transferType().getValue(),
                    accountTransferDetails, null, null, null, null, fromSavingsAccount, isRegularTransaction,
                    isExceptionForBalanceCheck);
            transferAmount(sb, accountTransferDTO, data.getId());
        }
    }
    if (sb.length() > 0) {
        throw new JobExecutionException(sb.toString());
    }

}

From source file:org.gnucash.android.ui.report.barchart.StackedBarChartFragment.java

License:Apache License

/**
 * Returns the start data of x-axis for the specified account type
 * @param accountType account type//from  ww w . ja v  a 2  s.  c  o  m
 * @return the start data
 */
private LocalDate getStartDate(AccountType accountType) {
    TransactionsDbAdapter adapter = TransactionsDbAdapter.getInstance();
    String code = mCommodity.getCurrencyCode();
    LocalDate startDate;
    if (mReportPeriodStart == -1) {
        startDate = new LocalDate(adapter.getTimestampOfEarliestTransaction(accountType, code));
    } else {
        startDate = new LocalDate(mReportPeriodStart);
    }
    startDate = startDate.withDayOfMonth(1);
    Log.d(TAG, accountType + " X-axis star date: " + startDate.toString("dd MM yyyy"));
    return startDate;
}

From source file:org.gnucash.android.ui.report.barchart.StackedBarChartFragment.java

License:Apache License

/**
 * Returns the end data of x-axis for the specified account type
 * @param accountType account type/*from   ww  w . j  av a 2  s. co m*/
 * @return the end data
 */
private LocalDate getEndDate(AccountType accountType) {
    TransactionsDbAdapter adapter = TransactionsDbAdapter.getInstance();
    String code = mCommodity.getCurrencyCode();
    LocalDate endDate;
    if (mReportPeriodEnd == -1) {
        endDate = new LocalDate(adapter.getTimestampOfLatestTransaction(accountType, code));
    } else {
        endDate = new LocalDate(mReportPeriodEnd);
    }
    endDate = endDate.withDayOfMonth(1);
    Log.d(TAG, accountType + " X-axis end date: " + endDate.toString("dd MM yyyy"));
    return endDate;
}

From source file:org.gnucash.android.ui.report.BarChartFragment.java

License:Apache License

/**
 * Returns the start data of x-axis for the specified account type
 * @param accountType account type/*from  w w w  .  j  a v  a2  s  .c om*/
 * @return the start data
 */
private LocalDate getStartDate(AccountType accountType) {
    TransactionsDbAdapter adapter = TransactionsDbAdapter.getInstance();
    String code = mCurrency.getCurrencyCode();
    LocalDate startDate;
    if (mReportStartTime == -1) {
        startDate = new LocalDate(adapter.getTimestampOfEarliestTransaction(accountType, code));
    } else {
        startDate = new LocalDate(mReportStartTime);
    }
    startDate = startDate.withDayOfMonth(1);
    Log.d(TAG, accountType + " X-axis star date: " + startDate.toString("dd MM yyyy"));
    return startDate;
}

From source file:org.gnucash.android.ui.report.BarChartFragment.java

License:Apache License

/**
 * Returns the end data of x-axis for the specified account type
 * @param accountType account type/*from www.j  a v  a2s . co m*/
 * @return the end data
 */
private LocalDate getEndDate(AccountType accountType) {
    TransactionsDbAdapter adapter = TransactionsDbAdapter.getInstance();
    String code = mCurrency.getCurrencyCode();
    LocalDate endDate;
    if (mReportEndTime == -1) {
        endDate = new LocalDate(adapter.getTimestampOfLatestTransaction(accountType, code));
    } else {
        endDate = new LocalDate(mReportEndTime);
    }
    endDate = endDate.withDayOfMonth(1);
    Log.d(TAG, accountType + " X-axis end date: " + endDate.toString("dd MM yyyy"));
    return endDate;
}

From source file:org.kuali.kpme.core.accrualcategory.rule.service.AccrualCategoryRuleServiceImpl.java

License:Educational Community License

public AccrualCategoryRule getAccrualCategoryRuleForDate(AccrualCategory accrualCategory, LocalDate currentDate,
        LocalDate serviceDate) {/*www  .  j  av  a2  s.co  m*/
    if (serviceDate == null) {
        return null;
    }
    List<AccrualCategoryRule> acrList = this
            .getActiveAccrualCategoryRules(accrualCategory.getLmAccrualCategoryId());
    for (AccrualCategoryRule acr : acrList) {
        String uot = acr.getServiceUnitOfTime();
        int startTime = acr.getStart().intValue();
        int endTime = acr.getEnd().intValue();

        LocalDate startDate = serviceDate;
        LocalDate endDate = serviceDate;
        if (uot.equals("M")) { // monthly
            startDate = startDate.plusMonths(startTime);
            endDate = endDate.plusMonths(endTime).minusDays(1);
        } else if (uot.endsWith("Y")) { // yearly
            startDate = startDate.plusYears(startTime);
            endDate = endDate.plusYears(endTime).minusDays(1);
        }

        // max days in months differ, if the date is bigger than the max day, set it to the max day of the month
        if (startDate.getDayOfMonth() > startDate.dayOfMonth().getMaximumValue()) {
            startDate = startDate.withDayOfMonth(startDate.dayOfMonth().getMaximumValue());
        }
        if (endDate.getDayOfMonth() > endDate.dayOfMonth().getMaximumValue()) {
            endDate = endDate.withDayOfMonth(endDate.dayOfMonth().getMaximumValue());
        }

        if (currentDate.compareTo(startDate) >= 0 && currentDate.compareTo(endDate) <= 0) {
            return acr;
        }
    }
    return null;
}

From source file:org.kuali.kpme.tklm.leave.accrual.service.AccrualServiceImpl.java

License:Educational Community License

@Override
public void calculateFutureAccrualUsingPlanningMonth(String principalId, LocalDate asOfDate,
        String runAsPrincipalId) {
    PrincipalHRAttributes phra = HrServiceLocator.getPrincipalHRAttributeService()
            .getPrincipalCalendar(principalId, asOfDate);
    if (phra != null) {
        // use the date from pay period to get the leave plan
        LeavePlan lp = HrServiceLocator.getLeavePlanService().getLeavePlan(phra.getLeavePlan(), asOfDate);
        if (lp != null && StringUtils.isNotEmpty(lp.getPlanningMonths())) {
            // go back a year 
            LocalDate startDate = asOfDate.minusYears(1);
            if (startDate.getDayOfMonth() > startDate.dayOfMonth().getMaximumValue()) {
                startDate = startDate.withDayOfMonth(startDate.dayOfMonth().getMaximumValue());
            }//from   ww  w . j a v a 2  s.  com
            // go forward using planning months
            LocalDate endDate = asOfDate.plusMonths(Integer.parseInt(lp.getPlanningMonths()));
            // max days in months differ, if the date is bigger than the max day, set it to the max day of the month
            if (endDate.getDayOfMonth() > endDate.dayOfMonth().getMaximumValue()) {
                endDate = endDate.withDayOfMonth(endDate.dayOfMonth().getMaximumValue());
            }
            runAccrual(principalId, startDate.toDateTimeAtStartOfDay(), endDate.toDateTimeAtStartOfDay(), true,
                    runAsPrincipalId);

        }
    }
}

From source file:org.kuali.kpme.tklm.leave.accrual.service.AccrualServiceImpl.java

License:Educational Community License

public List<AccrualCategoryRule> getAccrualCategoryRulesForDate(List<AccrualCategoryRule> acrList,
        String accrualCategoryId, LocalDate currentDate, LocalDate serviceDate) {
    List<AccrualCategoryRule> aList = new ArrayList<AccrualCategoryRule>();
    if (CollectionUtils.isNotEmpty(acrList)) {
        for (AccrualCategoryRule acr : acrList) {
            if (acr.getLmAccrualCategoryId().equals(accrualCategoryId)) {
                String uot = acr.getServiceUnitOfTime();
                int startTime = acr.getStart().intValue();
                int endTime = acr.getEnd().intValue();

                LocalDate startDate = serviceDate;
                LocalDate endDate = serviceDate;
                if (uot.equals("M")) { // monthly
                    startDate = startDate.plusMonths(startTime);
                    endDate = endDate.plusMonths(endTime).minusDays(1);
                } else if (uot.endsWith("Y")) { // yearly
                    startDate = startDate.plusYears(startTime);
                    endDate = endDate.plusYears(endTime).minusDays(1);
                }//from   w w w.  jav  a 2s.co m

                // max days in months differ, if the date is bigger than the max day, set it to the max day of the month
                if (startDate.getDayOfMonth() > startDate.dayOfMonth().getMaximumValue()) {
                    startDate = startDate.withDayOfMonth(startDate.dayOfMonth().getMaximumValue());
                }
                if (endDate.getDayOfMonth() > endDate.dayOfMonth().getMaximumValue()) {
                    endDate = endDate.withDayOfMonth(endDate.dayOfMonth().getMaximumValue());
                }

                if (currentDate.compareTo(startDate) >= 0 && currentDate.compareTo(endDate) <= 0) {
                    aList.add(acr);
                }
            }
        }
    }
    return aList;
}

From source file:org.mifos.accounts.productdefinition.business.SavingsOfferingBO.java

License:Open Source License

private LocalDate startOfFiscalYear(LocalDate updateDate) {
    return updateDate.withDayOfMonth(1).withMonthOfYear(1);
}

From source file:org.zkoss.ganttz.timetracker.zoom.DetailFourTimeTrackerState.java

License:Open Source License

@Override
protected LocalDate round(LocalDate date, boolean down) {
    if (date.getDayOfMonth() == 1) {
        return date;
    }/*from ww  w.  j a v  a2  s .  co  m*/

    return down ? date.withDayOfMonth(1) : date.plusMonths(1).withDayOfMonth(1);
}