List of usage examples for org.joda.time LocalDate minusDays
public LocalDate minusDays(int days)
From source file:cherry.sqlapp.controller.sqltool.search.SqltoolSearchControllerImpl.java
License:Apache License
@Override public SqltoolSearchForm getForm() { LocalDate today = bizDateTime.today(); SqltoolSearchForm form = new SqltoolSearchForm(); LocalDateTime from = LocalDateTimeUtil.rangeFrom(today.minusDays(defaultFromDays)); form.setRegisteredFromDt(from.toLocalDate()); form.setRegisteredFromTm(from.toLocalTime()); LocalDateTime to = LocalDateTimeUtil.rangeTo(today).minusSeconds(1); form.setRegisteredToDt(to.toLocalDate()); form.setRegisteredToTm(to.toLocalTime()); form.setSqlType(Arrays.asList(SqlType.CLAUSE, SqlType.STATEMENT, SqlType.LOAD)); form.setPublished(Arrays.asList(Published.PUBLIC, Published.PRIVATE)); return form;//from w ww .j av a2 s . com }
From source file:cherry.sqlman.tool.search.SqlSearchControllerImpl.java
License:Apache License
private void initializeForm(SqlSearchForm form) { LocalDate today = bizDateTime.today(); LocalDateTime from = LocalDateTimeUtil.rangeFrom(today.minusDays(config.getSearchDefaultFromDays())); form.setRegisteredFromDt(from.toLocalDate()); form.setRegisteredFromTm(from.toLocalTime()); LocalDateTime to = LocalDateTimeUtil.rangeTo(today).minusSeconds(1); form.setRegisteredToDt(to.toLocalDate()); form.setRegisteredToTm(to.toLocalTime()); form.setSqlType(Arrays.asList(SqlType.CLAUSE, SqlType.STATEMENT, SqlType.LOAD)); form.setPublished(Arrays.asList(Published.PUBLIC, Published.PRIVATE)); }
From source file:com.app.gpo.services.OrderItemAutoChangeStatus.java
License:Open Source License
@Scheduled(cron = "0 30 * * * ?") public void scheduleChangeStatus() { // something that should execute on weekdays only logger.info("Searching for order items to change status"); LocalDate today = new LocalDate(); LocalDate threDaysAgo = today.minusDays(3); OrderStatus orderStatus = orderStatusService.findIdByName("W toku"); OrderStatus orderStatusNew = orderStatusService.findIdByName("Zakoczone"); List<OrderItem> orderItemList = orderItemService.findByOrderStatus(orderStatus); Iterator<OrderItem> orderItem = orderItemList.iterator(); while (orderItem.hasNext()) { OrderItem oI = orderItem.next(); LocalDate orderStatusDate = new LocalDate(oI.getorderStatusDate()); boolean olderThen3 = threDaysAgo.isAfter(orderStatusDate); //logger.info("Order item "+oI.getorderNumber()+" has status change date: "+oI.getorderStatusDate()); if (olderThen3) { logger.info("Order item " + oI.getorderNumber() + " status has been changed to 'Zakoczone'."); oI.setorderStatus(orderStatusNew); orderItemService.update(oI); }/*from w ww .j a v a 2 s . c o m*/ } }
From source file:com.axelor.apps.account.web.GeneralController.java
License:Open Source License
public void updateCurrencyConversion(ActionRequest request, ActionResponse response) { General general = request.getContext().asType(General.class); LocalDate today = generalService.getTodayDate(); Map<Long, Long> currencyMap = new HashMap<Long, Long>(); for (CurrencyConversionLine ccl : general.getCurrencyConversionLineList()) { currencyMap.put(ccl.getEndCurrency().getId(), ccl.getStartCurrency().getId()); }/*from w w w . ja v a2 s . c om*/ for (Long key : currencyMap.keySet()) { CurrencyConversionLine ccl = cclRepo.all() .filter("startCurrency.id = ?1 AND endCurrency.id = ?2 AND fromDate <= ?3 AND toDate is null", currencyMap.get(key), key, today) .fetchOne(); LOG.info("Currency Conversion Line without toDate : {}", ccl); if (ccl == null) { ccl = cclRepo.all() .filter("startCurrency.id = ?1 AND endCurrency.id = ?2 AND fromDate <= ?3 AND toDate > ?3", currencyMap.get(key), key, today) .fetchOne(); if (ccl != null) { LOG.info("Already convered Currency Conversion Line found : {}", ccl); continue; } ccl = cclRepo.all().filter( "startCurrency.id = ?1 AND endCurrency.id = ?2 AND fromDate <= ?3 AND (toDate not null AND toDate <= ?3)", currencyMap.get(key), key, today).order("-toDate").fetchOne(); LOG.info("Currency Conversion Line found with toDate : {}", ccl); } if (ccl != null) { BigDecimal currentRate = ccs.convert(ccl.getStartCurrency(), ccl.getEndCurrency()); if (currentRate.compareTo(new BigDecimal(-1)) == 0) { response.setFlash(I18n.get(IExceptionMessage.CURRENCY_6)); break; } ccl = cclRepo.find(ccl.getId()); ccl.setToDate(today.minusDays(1)); ccs.saveCurrencyConversionLine(ccl); BigDecimal previousRate = ccl.getExchangeRate(); String variations = ccs.getVariations(currentRate, previousRate); ccs.createCurrencyConversionLine(ccl.getStartCurrency(), ccl.getEndCurrency(), today, currentRate, gs.getGeneral(), variations); } } response.setReload(true); }
From source file:com.axelor.apps.base.web.CurrencyConversionLineController.java
License:Open Source License
public void applyExchangeRate(ActionRequest request, ActionResponse response) { Context context = request.getContext(); LOG.debug("Apply Conversion Rate Context: {}", new Object[] { context }); HashMap currencyFrom = (HashMap) context.get("startCurrency"); HashMap currencyTo = (HashMap) context.get("endCurrency"); if (currencyFrom.get("id") != null && currencyTo.get("id") != null) { Currency fromCurrency = currencyRepo.find(Long.parseLong(currencyFrom.get("id").toString())); Currency toCurrency = currencyRepo.find(Long.parseLong(currencyTo.get("id").toString())); LocalDate today = gs.getTodayDate(); CurrencyConversionLine cclCoverd = cclRepo.all().filter( "startCurrency = ?1 AND endCurrency = ?2 AND fromDate >= ?3 AND (toDate <= ?3 OR toDate = null)", fromCurrency, toCurrency, today).fetchOne(); if (cclCoverd == null) { CurrencyConversionLine ccl = cclRepo.all() .filter("startCurrency = ?1 AND endCurrency = ?2", fromCurrency, toCurrency) .order("-fromDate").fetchOne(); LOG.debug("Last conversion line {}", ccl); if (ccl != null && ccl.getToDate() == null) { ccl.setToDate(today.minusDays(1)); ccs.saveCurrencyConversionLine(ccl); }// w w w . j av a 2 s . co m BigDecimal rate = new BigDecimal(context.get("newExchangeRate").toString()); String variation = null; if (ccl != null) variation = ccs.getVariations(rate, ccl.getExchangeRate()); General general = null; if (context.get("general") != null && ((HashMap) context.get("general")).get("id") != null) general = generalRepo .find(Long.parseLong(((HashMap) context.get("general")).get("id").toString())); ccs.createCurrencyConversionLine(fromCurrency, toCurrency, today, rate, general, variation); } else response.setFlash(I18n.get(IExceptionMessage.CURRENCY_3)); } else response.setFlash(I18n.get(IExceptionMessage.CURRENCY_5)); LOG.debug("Set can close for wizarBoth currencies must be saved before currency rate applyd"); response.setCanClose(true); }
From source file:com.axelor.apps.supplychain.service.MrpServiceImpl.java
License:Open Source License
public MrpLine getPreviousProposalMrpLine(Product product, MrpLineType mrpLineType, Location location, LocalDate maturityDate) { LocalDate startPeriodDate = maturityDate; MrpFamily mrpFamily = product.getMrpFamily(); if (mrpFamily != null) { if (mrpFamily.getDayNb() == 0) { return null; }//from ww w .ja v a 2 s . c o m startPeriodDate = maturityDate.minusDays(mrpFamily.getDayNb()); } return mrpLineRepository.all().filter( "self.mrp = ?1 AND self.product = ?2 AND self.mrpLineType = ?3 AND self.location = ?4 AND self.maturityDate > ?5 AND self.maturityDate <= ?6", mrp, product, mrpLineType, location, startPeriodDate, maturityDate).fetchOne(); }
From source file:com.axelor.apps.supplychain.service.MrpServiceImpl.java
License:Open Source License
protected void createProposalMrpLine(Product product, MrpLineType mrpLineType, BigDecimal reorderQty, Location location, LocalDate maturityDate, List<MrpLineOrigin> mrpLineOriginList, String relatedToSelectName) throws AxelorException { if (mrpLineType.getElementSelect() == MrpLineTypeRepository.ELEMENT_PURCHASE_PROPOSAL) { maturityDate = maturityDate.minusDays(product.getSupplierDeliveryTime()); reorderQty = reorderQty.max(this.getSupplierCatalogMinQty(product)); }/* w w w.j a va 2 s .co m*/ MrpLine mrpLine = this.getPreviousProposalMrpLine(product, mrpLineType, location, maturityDate); if (mrpLine != null) { mrpLine.setQty(mrpLine.getQty().add(reorderQty)); mrpLine.setRelatedToSelectName(null); } else { mrpLine = mrpLineRepository.save( this.createMrpLine(product, mrpLineType, reorderQty, maturityDate, BigDecimal.ZERO, location)); mrp.addMrpLineListItem(mrpLine); mrpLine.setRelatedToSelectName(relatedToSelectName); } this.copyMrpLineOrigins(mrpLine, mrpLineOriginList); }
From source file:com.axelor.apps.tool.date.DateTool.java
License:Open Source License
/** * Calculer la date de la prochaine occurence d'un vnement suivant le calcul suivant : * Supprimer autant de fois que possible la frquence en mois la date vise * tout en tant suprieure la date de dbut * //from w ww . j ava 2s . c om * @param startDate * La date de dbut * * @param goalDate * La date vise * * @param frequencyInMonth * Nombre de mois reprsentant la frquence de l'vnement */ public static LocalDate nextOccurency(LocalDate startDate, LocalDate goalDate, int frequencyInMonth) { if (frequencyInMonth == 0) { LOG.debug("La frquence ne doit pas etre gale 0."); return null; } else { if (startDate == null && goalDate == null) { return null; } else { if (startDate.isAfter(goalDate)) { return goalDate; } return minusMonths(goalDate, days360MonthsBetween(startDate.plusDays(1), goalDate.minusDays(1)) / frequencyInMonth * frequencyInMonth); } } }
From source file:com.axelor.apps.tool.date.DateTool.java
License:Open Source License
/** * Calculer la date de la prochaine occurence d'un vnement suivant le calcul suivant : * Supprimer autant de fois que possible la frquence en mois la date vise * tout en tant suprieure ou gale la date de dbut * /* ww w . j a v a 2s . c om*/ * @param startDate * La date de dbut * * @param goalDate * La date vise * * @param frequencyInMonth * Nombre de mois reprsentant la frquence de l'vnement */ public LocalDate nextOccurencyStartDateIncluded(LocalDate startDate, LocalDate goalDate, int frequencyInMonth) { if (frequencyInMonth == 0) { LOG.debug("La frquence ne doit pas etre gale 0."); return null; } else { if (startDate == null && goalDate == null) { return null; } else { if (startDate.isAfter(goalDate)) { return goalDate; } return minusMonths(goalDate, days360MonthsBetween(startDate, goalDate.minusDays(1)) / frequencyInMonth * frequencyInMonth); } } }
From source file:com.esofthead.mycollab.core.utils.BusinessDayTimeUtils.java
License:Open Source License
public static LocalDate plusDays(LocalDate refDate, int lagDate) { DateCalculator<LocalDate> calc1; boolean isForward = false; if (lagDate >= 0) { calc1 = LocalDateKitCalculatorsFactory.forwardCalculator("MyCollab"); isForward = true;/*from w w w . jav a2 s. c o m*/ } else { calc1 = LocalDateKitCalculatorsFactory.backwardCalculator("MyCollab"); } if (isForward) { refDate = refDate.minusDays(1); while (calc1.isNonWorkingDay(refDate)) { refDate = refDate.minusDays(1); } } else { refDate.plusDays(1); while (calc1.isNonWorkingDay(refDate)) { refDate = refDate.plusDays(1); } } calc1.setStartDate(refDate); calc1.moveByBusinessDays(lagDate); return calc1.getCurrentBusinessDate(); }