List of usage examples for org.joda.time LocalDate dayOfMonth
public Property dayOfMonth()
From source file:op.care.supervisor.PnlHandover.java
License:Open Source License
private JPanel createContentPanel4Month(LocalDate month) { /***//from w ww. j a v a2s .c o m * _ _ __ __ __ ___ _ _ _____ _ _ * ___ ___ _ __ | |_ ___ _ __ | |_ / _| ___ _ __ | \/ |/ _ \| \ | |_ _| | | | * / __/ _ \| '_ \| __/ _ \ '_ \| __| | |_ / _ \| '__| | |\/| | | | | \| | | | | |_| | * | (_| (_) | | | | || __/ | | | |_ | _| (_) | | | | | | |_| | |\ | | | | _ | * \___\___/|_| |_|\__\___|_| |_|\__| |_| \___/|_| |_| |_|\___/|_| \_| |_| |_| |_| * */ JPanel pnlMonth = new JPanel(new VerticalLayout()); pnlMonth.setOpaque(false); LocalDate now = new LocalDate(); boolean sameMonth = now.dayOfMonth().withMaximumValue().equals(month.dayOfMonth().withMaximumValue()); final LocalDate start = sameMonth ? now : month.dayOfMonth().withMaximumValue(); final LocalDate end = month.dayOfMonth().withMinimumValue(); for (LocalDate day = start; end.compareTo(day) <= 0; day = day.minusDays(1)) { pnlMonth.add(createCP4Day(day)); } return pnlMonth; }
From source file:op.tools.SYSCalendar.java
License:Open Source License
/** * bottom of month//from ww w . j a va2s.co m * * @param d * @return */ public static LocalDate bom(LocalDate d) { return d.dayOfMonth().withMinimumValue(); }
From source file:op.tools.SYSCalendar.java
License:Open Source License
public static LocalDate eom(LocalDate d) { return d.dayOfMonth().withMaximumValue(); }
From source file:org.alexlg.bankit.controllers.AccountController.java
License:Open Source License
/** * Display operations list for history and future. * @param model Model to fill with operations list * @return view name//from ww w .j a v a 2 s . c om */ @RequestMapping("/list") @Transactional(readOnly = true) public String list(@RequestParam(required = false) String startDate, @RequestParam(required = false) String endDate, ModelMap model) { //start/end date of operations displayed LocalDate startDay = null; LocalDate endDay = null; boolean buildFuture = false; //parse dates if present if (startDate != null) startDay = parseMonth(startDate); if (endDate != null) endDay = parseMonth(endDate); //select start/end day from parsing or default if (startDay == null) startDay = calculateFirstHistoDay(); if (endDay == null) { endDay = new LocalDate(); buildFuture = true; } else { //select the last day of the endMonth endDay = endDay.dayOfMonth().withMaximumValue(); //force endDay to not go beyond today LocalDate today = new LocalDate(); if (endDay.isAfter(today)) { endDay = today; buildFuture = true; } } //switch start/end if not in correct order if (startDay.isAfter(endDay)) { LocalDate tmp = endDay; endDay = startDay; startDay = tmp; } //getting history operations List<Operation> ops = operationDao.getHistory(startDay, endDay); //calculating balance for history //current balance BigDecimal current = operationDao.getBalanceHistory(startDay); //difference between planned and real BigDecimal currentDiff = new BigDecimal("0"); //balance for planned op but not debited BigDecimal plannedWaiting = new BigDecimal("0"); //checking if a balance exists or init the account if (current == null && ops.size() == 0) { return "redirect:/account/init"; } if (current == null) current = new BigDecimal("0"); BigDecimal initialBalance = current; //calculating total for old operations for (Operation op : ops) { BigDecimal amount = op.getAmount(); BigDecimal planned = op.getPlanned(); if (amount != null) { //operation done current = current.add(amount); op.setTotal(current); if (planned != null) { currentDiff = currentDiff.add(amount).subtract(planned); } } } //calculating total for planned undebit operations for (Operation op : ops) { if (op.getAmount() == null) { plannedWaiting = plannedWaiting.add(op.getPlanned()); op.setTotal(current.add(plannedWaiting)); } } if (buildFuture) { //getting future operations Set<MonthOps> futureOps = buildFutureOps(endDay, operationDao.getFuture(endDay), costDao.getList(), current.add(plannedWaiting), NB_FUTURE_MONTH); model.put("futureOps", futureOps); } model.put("startDay", startDay.toDate()); model.put("endDay", endDay.toDate()); model.put("ops", ops); model.put("current", current); model.put("currentDiff", currentDiff); model.put("periodBalance", current.subtract(initialBalance)); model.put("plannedWaiting", plannedWaiting); model.put("currentWaiting", current.add(plannedWaiting)); model.put("lastSyncDate", optionsService.getDate(SyncService.OP_SYNC_OPT)); model.put("categories", categoryDao.getList()); //get categories summary (for previous and current month) model.put("categoriesSummary", buildCategories(startDay, endDay)); return "account/list"; }
From source file:org.alexlg.bankit.controllers.AccountController.java
License:Open Source License
/** * Build a set of MonthOps for all future ops : "manual" or costs (beyond 2 days of current) * @param day Current day// www. j a v a2 s .c o m * @param futurePlannedOps List of manual future operations * @param costs List of costs * @param balance Start balance * @param nbMonth Number of month to build in addition to the current month. * @return A set of MonthOps for each month planned */ protected Set<MonthOps> buildFutureOps(LocalDate day, List<Operation> futurePlannedOps, List<Cost> costs, BigDecimal balance, int nbMonth) { Set<MonthOps> futureOps = new TreeSet<MonthOps>(); //going through all months for (int i = 0; i < nbMonth + 1; i++) { LocalDate monthDate = day.monthOfYear().addToCopy(i); int lastDayOfMonth = monthDate.dayOfMonth().getMaximumValue(); MonthOps monthOps = new MonthOps(monthDate, balance); futureOps.add(monthOps); //adding "manual" operation of the current month if (futurePlannedOps.size() > 0) { //loop an add all operation of the month for (Operation op : futurePlannedOps) { if (new LocalDate(op.getOperationDate()).getMonthOfYear() == monthDate.getMonthOfYear()) { op.setAuto(false); monthOps.addOp(op); } } } //adding costs of the current month LocalDate costStartDay = day.plusDays(2); for (Cost cost : costs) { int costDay = cost.getDay(); //if the operation is planned after the last day of month //set it to the last day if (costDay > lastDayOfMonth) costDay = lastDayOfMonth; LocalDate opDate = new LocalDate(monthDate.getYear(), monthDate.getMonthOfYear(), costDay); //checking if we add the cost (the date is after current+2) if (opDate.isAfter(costStartDay)) { Operation op = new Operation(); //setting a fake id for comparison (as we put the operation in the set) op.setOperationId(cost.getCostId() + i); op.setOperationDate(opDate.toDate()); op.setPlanned(cost.getAmount()); op.setLabel(cost.getLabel()); op.setCategory(cost.getCategory()); op.setAuto(true); monthOps.addOp(op); } } //saving current balance for next monthOp balance = monthOps.getBalance(); } return futureOps; }
From source file:org.alexlg.bankit.controllers.MonthOps.java
License:Open Source License
/** * Construct MonthOps with Calendar month number. * Used for generate the lastDay of the month * @param month One day in the month of any operation * @param balance Current balance to add operation planned *///from w w w . java2 s. c o m public MonthOps(LocalDate month, BigDecimal balance) { lastDay = month.dayOfMonth().withMaximumValue(); ops = new TreeSet<Operation>(); amount = new BigDecimal("0"); this.balance = (balance != null ? balance : new BigDecimal("0")); this.initialBalance = this.balance; }
From source file:org.alexlg.bankit.dao.CategoryDao.java
License:Open Source License
/** * Calculate the amount of operations for all categories on a specific month * @param yearMonth Year and month of the summary to calculate * @return Map containing the Category and the amount for the month *//* ww w .j a v a 2s . c o m*/ public Map<Category, BigDecimal> getMonthSummary(YearMonth yearMonth) { CriteriaBuilder b = getBuilder(); //SELECT PASSED OPERATION //create criteria and join CriteriaQuery<Tuple> q = b.createTupleQuery(); Root<Operation> operation = q.from(Operation.class); //we left join to get operation with no categories Join<Operation, Category> category = operation.join(Operation_.category, JoinType.LEFT); //select //sum all amount operation for operation imported from the bank Expression<BigDecimal> sum = b.sum(operation.get(Operation_.amount)); //sum only planned amount if the amount is not set (as we have a planned operation) //we use a sum(case when xx end) for that //in sql, it will be translated into : sum(case when o.amount is null then o.planned otherwise 0 end) Expression<BigDecimal> sumPlanned = b.sum(b.<BigDecimal>selectCase() .when(b.isNull(operation.get(Operation_.amount)), operation.get(Operation_.planned)) .otherwise(BigDecimal.ZERO)); //select the 3 fields into a tuple q.select(b.tuple(category, sum, sumPlanned)); //where clause : between the start/end date, and for operation with no category, only < 0 LocalDate startDate = yearMonth.toLocalDate(1); LocalDate endDate = startDate.withDayOfMonth(startDate.dayOfMonth().getMaximumValue()); q.where(b.between(operation.get(Operation_.operationDate), startDate.toDate(), endDate.toDate()), b.or(b.isNotNull(operation.get(Operation_.category)), b.lt(operation.get(Operation_.amount), 0), b.lt(operation.get(Operation_.planned), 0))); //group by q.groupBy(category.get(Category_.categoryId)); //order by q.orderBy(b.asc(category.get(Category_.name))); //execute query List<Tuple> results = getEm().createQuery(q).getResultList(); //put in map Map<Category, BigDecimal> resMap = new LinkedHashMap<Category, BigDecimal>(results.size()); //saving null category for adding at the end BigDecimal noCatAmount = null; for (Tuple res : results) { Category resCat = res.get(category); BigDecimal sumVal = res.get(sum); BigDecimal sumPlannedVal = res.get(sumPlanned); if (sumVal == null) sumVal = BigDecimal.ZERO; if (sumPlannedVal == null) sumPlannedVal = BigDecimal.ZERO; BigDecimal sumTotal = sumVal.add(sumPlannedVal); if (!sumTotal.equals(BigDecimal.ZERO)) { if (resCat != null) { resMap.put(resCat, sumTotal); } else { noCatAmount = sumTotal; } } } //adding operation with no categories at the end of the list if (noCatAmount != null) { Category noCat = new Category(); noCat.setCategoryId(-1); noCat.setName(""); resMap.put(noCat, noCatAmount); } return resMap; }
From source file:org.alexlg.bankit.services.SyncService.java
License:Open Source License
/** * This function take all the costs between * the last execution to create the associated * operations in the operation list./*from w w w .java 2s .c o m*/ * It runs every day at midnight and 5 seconds */ @Transactional @Scheduled(cron = "5 0 0 * * *") public void materializeCostsIntoOperation() { logger.info("Starting materializeCostsIntoOperation"); //materialize operations 2 days beyond current date LocalDate endDate = getEndSyncDate().plusDays(2); Date startSync = optionsService.getDate(COST_SYNC_OPT); if (startSync == null) { optionsService.set(COST_SYNC_OPT, endDate.toDate()); return; } LocalDate startDate = new LocalDate(startSync); //retrieve costs list List<Cost> costs = null; int nbMonth = 1; if (endDate.getYear() == startDate.getYear() && endDate.getMonthOfYear() == startDate.getMonthOfYear()) { //only retrieve the costs between this 2 "days" costs = costDao.getList(startDate.getDayOfMonth(), endDate.getDayOfMonth()); } else { //getting all costs costs = costDao.getList(); //we generate a least for the current month (as nbMonth = 1) //then we add whole months between start and end. nbMonth += Months.monthsBetween(startDate, endDate).getMonths(); //as monthsBetween calculate for whole month, if start is for example the 24-09 //and the end is the 02-10, monthsBetween will return 0 but we need to have //2 loops, one for september and one for november so we add a month. if (endDate.getDayOfMonth() <= startDate.getDayOfMonth()) { nbMonth++; } } //going through each month and each cost to create the operation for (int m = 0; m < nbMonth; m++) { LocalDate curMonth = startDate.plusMonths(m); int lastDayOfMonth = curMonth.dayOfMonth().getMaximumValue(); for (Cost cost : costs) { int costDay = cost.getDay(); //if the operation is planned after the last day of month //set it to the last day if (costDay > lastDayOfMonth) costDay = lastDayOfMonth; //creating operation date LocalDate opDate = new LocalDate(curMonth.getYear(), curMonth.getMonthOfYear(), costDay); //check if date is in the date interval before creating op if (opDate.isAfter(startDate) && opDate.compareTo(endDate) <= 0) { Operation op = new Operation(); op.setOperationDate(opDate.toDate()); op.setLabel(cost.getLabel()); op.setPlanned(cost.getAmount()); op.setCategory(cost.getCategory()); operationDao.save(op); } } } optionsService.set(COST_SYNC_OPT, endDate.toDate()); }
From source file:org.apache.fineract.portfolio.savings.domain.SavingsHelper.java
License:Apache License
private LocalDate determineInterestPostingPeriodEndDateFrom(final LocalDate periodStartDate, final SavingsPostingInterestPeriodType interestPostingPeriodType, final LocalDate interestPostingUpToDate, Integer financialYearBeginningMonth) { LocalDate periodEndDate = interestPostingUpToDate; final Integer monthOfYear = periodStartDate.getMonthOfYear(); financialYearBeginningMonth--;//from w w w . j a va2s. c o m if (financialYearBeginningMonth == 0) financialYearBeginningMonth = 12; final ArrayList<LocalDate> quarterlyDates = new ArrayList<>(); quarterlyDates .add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).dayOfMonth().withMaximumValue()); quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(3) .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue()); quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(6) .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue()); quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(9) .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue()); Collections.sort(quarterlyDates); final ArrayList<LocalDate> biannualDates = new ArrayList<>(); biannualDates .add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).dayOfMonth().withMaximumValue()); biannualDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(6) .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue()); Collections.sort(biannualDates); boolean isEndDateSet = false; switch (interestPostingPeriodType) { case INVALID: break; case MONTHLY: // produce period end date on last day of current month periodEndDate = periodStartDate.dayOfMonth().withMaximumValue(); break; case QUATERLY: for (LocalDate quarterlyDate : quarterlyDates) { if (quarterlyDate.isAfter(periodStartDate)) { periodEndDate = quarterlyDate; isEndDateSet = true; break; } } if (!isEndDateSet) periodEndDate = quarterlyDates.get(0).plusYears(1).dayOfMonth().withMaximumValue(); break; case BIANNUAL: for (LocalDate biannualDate : biannualDates) { if (biannualDate.isAfter(periodStartDate)) { periodEndDate = biannualDate; isEndDateSet = true; break; } } if (!isEndDateSet) periodEndDate = biannualDates.get(0).plusYears(1).dayOfMonth().withMaximumValue(); break; case ANNUAL: if (financialYearBeginningMonth < monthOfYear) { periodEndDate = periodStartDate.withMonthOfYear(financialYearBeginningMonth); periodEndDate = periodEndDate.plusYears(1); } else { periodEndDate = periodStartDate.withMonthOfYear(financialYearBeginningMonth); } periodEndDate = periodEndDate.dayOfMonth().withMaximumValue(); break; } // interest posting always occurs on next day after the period end date. periodEndDate = periodEndDate.plusDays(1); return periodEndDate; }
From source file:org.egov.lcms.transactions.service.LegalCommonReportService.java
License:Open Source License
private BoolQueryBuilder getFilterQuery(final LegalCommonReportResult searchRequest, final String reportType) throws ParseException { final SimpleDateFormat formatter = new SimpleDateFormat(LcmsConstants.DATE_FORMAT); final SimpleDateFormat newFormat = new SimpleDateFormat(ApplicationConstant.ES_DATE_FORMAT); final Map<String, Integer> monthValuesMapnumber = LegalCaseUtil.getAllMonthsInNumber(); BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); boolQuery.filter(QueryBuilders.termQuery("cityName", ApplicationThreadLocals.getCityName())); if (StringUtils.isNotBlank(searchRequest.getAggregatedByValue())) { if (searchRequest.getAggregatedBy().equals(LcmsConstants.COURTNAME)) boolQuery.filter(QueryBuilders.matchQuery(COURTNAME, searchRequest.getAggregatedByValue())); if (searchRequest.getAggregatedBy().equals(LcmsConstants.PETITIONTYPE)) boolQuery.filter(QueryBuilders.matchQuery(PETITIONTYPE, searchRequest.getAggregatedByValue())); else if (searchRequest.getAggregatedBy().equals(LcmsConstants.CASECATEGORY)) boolQuery.filter(QueryBuilders.matchQuery(CASETYPE, searchRequest.getAggregatedByValue())); else if (searchRequest.getAggregatedBy().equals(LcmsConstants.CASESTATUS)) boolQuery.filter(QueryBuilders.matchQuery(CASESTATUS, searchRequest.getAggregatedByValue())); else if (searchRequest.getAggregatedBy().equals(LcmsConstants.COURTTYPE)) boolQuery.filter(QueryBuilders.matchQuery(COURTTYPE, searchRequest.getAggregatedByValue())); else if (searchRequest.getAggregatedBy().equals(LcmsConstants.OFFICERINCHRGE)) boolQuery.filter(QueryBuilders.matchQuery(OFFICERINCHRGE, searchRequest.getAggregatedByValue().split("@")[0])); else if (searchRequest.getAggregatedBy().equals(LcmsConstants.STANDINGCOUNSEL)) boolQuery.filter(QueryBuilders.matchQuery(STANDINGCOUNSEL, searchRequest.getAggregatedByValue())); else if (searchRequest.getAggregatedBy().equals(LcmsConstants.JUDGEMENTOUTCOME)) boolQuery.filter(QueryBuilders.matchQuery(JUDGEMENTOUTCOME, searchRequest.getAggregatedByValue())); }//w ww . j a va 2 s .c o m if (StringUtils.isNotBlank(searchRequest.getMonth()) && StringUtils.isNotBlank(searchRequest.getYear())) { final Integer monthName = monthValuesMapnumber.get(searchRequest.getMonth()); // Prepare the start date based on the month number and year final String monthYearStartDateStr = searchRequest.getYear().concat("-").concat(monthName.toString()) .concat("-").concat("01"); final LocalDate monthYearStDate = new LocalDate(monthYearStartDateStr); // Fetch the start date of the 1st week of the month and the last day of the month if (MONTH.equalsIgnoreCase(searchRequest.getPeriod())) { final LocalDate weekStart = monthYearStDate.dayOfWeek().withMinimumValue(); final LocalDate endOfMonth = monthYearStDate.dayOfMonth().withMaximumValue(); final String startDate = weekStart.toString(LcmsConstants.DATE_FORMAT); final String endDate = endOfMonth.toString(LcmsConstants.DATE_FORMAT); boolQuery = boolQuery.filter( QueryBuilders.rangeQuery(CASE_DATE).gte(newFormat.format(formatter.parse(startDate))) .lte(new DateTime(newFormat.format(formatter.parse(endDate))))); } if (YEAR.equalsIgnoreCase(searchRequest.getPeriod())) { final LocalDate monthStart = monthYearStDate.dayOfMonth().withMinimumValue(); final LocalDate endOfYear = monthYearStDate.dayOfYear().withMaximumValue(); final String startDate = monthStart.toString(LcmsConstants.DATE_FORMAT); final String endDate = endOfYear.toString(LcmsConstants.DATE_FORMAT); boolQuery = boolQuery.filter( QueryBuilders.rangeQuery(CASE_DATE).gte(newFormat.format(formatter.parse(startDate))) .lte(new DateTime(newFormat.format(formatter.parse(endDate))))); } } if (reportType != null) { if (reportType.equals(LcmsConstants.DUEPWRREPORT)) boolQuery.mustNot(QueryBuilders.existsQuery("pwrDueDate")); else if (reportType.equals(LcmsConstants.DUECAREPORT)) boolQuery.must(QueryBuilders.existsQuery("caDueDate")); else if (reportType.equals(LcmsConstants.DUEJUDGEMENTIMPLPREPORT)) boolQuery.mustNot(QueryBuilders.matchQuery("status", LcmsConstants.LEGALCASE_STATUS_CLOSED_DESC)); if (reportType.equals(LcmsConstants.DUEJUDGEMENTIMPLPREPORT) && StringUtils.isNotBlank(searchRequest.getCaseFromDate())) boolQuery = boolQuery.filter(QueryBuilders.rangeQuery("judgmentImplDate") .gte(newFormat.format(formatter.parse(searchRequest.getCaseFromDate()))) .lte(new DateTime(newFormat.format(formatter.parse(searchRequest.getCaseToDate()))))); if (reportType.equals(LcmsConstants.DUEEMPLOYEEHEARINGREPORT)) { final List<String> statusCodeList = new ArrayList<>(); statusCodeList.add(LcmsConstants.LEGALCASE_STATUS_HEARING_DESC); statusCodeList.add(LcmsConstants.LEGALCASE_INTERIMSTAY_STATUS_DESC); boolQuery.must(QueryBuilders.termsQuery(CASESTATUS, statusCodeList)); if (searchRequest.getLcNumber() != null) boolQuery = boolQuery.filter(QueryBuilders.matchQuery("lcNumber", searchRequest.getLcNumber())); if (StringUtils.isNotBlank(searchRequest.getCaseFromDate())) boolQuery = boolQuery.filter(QueryBuilders.rangeQuery(CASE_DATE) .gte(newFormat.format(formatter.parse(searchRequest.getCaseFromDate()))) .lte(new DateTime(newFormat.format(formatter.parse(searchRequest.getCaseToDate()))))); } } else if (StringUtils.isNotBlank(searchRequest.getCaseFromDate())) boolQuery = boolQuery.filter(QueryBuilders.rangeQuery(CASE_DATE) .gte(newFormat.format(formatter.parse(searchRequest.getCaseFromDate()))) .lte(new DateTime(newFormat.format(formatter.parse(searchRequest.getCaseToDate()))))); if (StringUtils.isNotBlank(searchRequest.getOfficerIncharge())) boolQuery = boolQuery.filter( QueryBuilders.termQuery(OFFICERINCHRGE, searchRequest.getOfficerIncharge().split("@")[0])); if (StringUtils.isNotBlank(searchRequest.getCaseCategory())) boolQuery = boolQuery.filter(QueryBuilders.termQuery(CASETYPE, searchRequest.getCaseCategory())); if (StringUtils.isNotBlank(searchRequest.getCourtName())) boolQuery = boolQuery.filter(QueryBuilders.termQuery(COURTNAME, searchRequest.getCourtName())); if (StringUtils.isNotBlank(searchRequest.getCaseStatus())) boolQuery = boolQuery.filter(QueryBuilders.termQuery(CASESTATUS, searchRequest.getCaseStatus())); if (StringUtils.isNotBlank(searchRequest.getCourtType())) boolQuery = boolQuery.filter(QueryBuilders.termQuery(COURTTYPE, searchRequest.getCourtType())); if (StringUtils.isNotBlank(searchRequest.getPetitionType())) boolQuery = boolQuery.filter(QueryBuilders.termQuery(PETITIONTYPE, searchRequest.getPetitionType())); if (StringUtils.isNotBlank(searchRequest.getJudgmentType())) boolQuery = boolQuery .filter(QueryBuilders.termQuery(JUDGEMENTOUTCOME, searchRequest.getJudgmentType())); if (StringUtils.isNotBlank(searchRequest.getStandingCounsel())) boolQuery = boolQuery .filter(QueryBuilders.termQuery("advocateName", searchRequest.getStandingCounsel())); if (StringUtils.isNotBlank(searchRequest.getReportStatus())) boolQuery = boolQuery.filter(QueryBuilders.termQuery("subStatus", searchRequest.getReportStatus())); return boolQuery; }