List of usage examples for org.joda.time LocalDate isEqual
public boolean isEqual(ReadablePartial partial)
From source file:br.com.moonjava.flight.util.VerifierString.java
License:Apache License
public static boolean isBirthDay(String word, String country) { boolean birthDay = false; LocalDate date = FormatDateTimeDesk.parseToLocalDate(word, country); boolean leapYear = new GregorianCalendar().isLeapYear(date.getYear()); LocalDate now = new LocalDate(); // US MM/DD/YYYY if (country.equals("US")) { // No pode conter 30 e 31 em fevereiro e nem ser maior que a data atual if (!word.startsWith("02/30") && !word.startsWith("02/31") && date.isBefore(now) || date.isEqual(now)) { // Se for bissexto deve considerar 02/29 if (word.startsWith("02/29") && leapYear || !word.startsWith("02/29")) { Pattern pattern = Pattern.compile("(0[1-9]|1[012])/(0[1-9]|[12][0-9]|3[01])/((19|20)\\d\\d)"); Matcher matcher = pattern.matcher(word); birthDay = matcher.find(); }/* w ww .j a v a 2 s. c om*/ } // BR DD/MM/YYYY } else { if (!word.startsWith("30/02") && !word.startsWith("31/02") && date.isBefore(now) || date.isEqual(now)) { // No pode conter 30 e 31 em fevereiro e nem ser maior que a data atual if (word.startsWith("29/02") && leapYear || !word.startsWith("29/02")) { // Se for bissexto deve considerar 29/02 Pattern pattern = Pattern.compile("(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/((19|20)\\d\\d)"); Matcher matcher = pattern.matcher(word); birthDay = matcher.find(); } } } return birthDay; }
From source file:br.com.moonjava.flight.util.VerifierString.java
License:Apache License
public static boolean isValidate(String word) { try {// w ww.j ava2s. c om boolean validate = false; LocalDate now = new LocalDate(); String year = word.substring(3, 7); String month = word.substring(0, 2); LocalDate date = new LocalDate().withYear(Integer.parseInt(year)) .withMonthOfYear(Integer.parseInt(month)); if (date.isAfter(now) || date.isEqual(now)) { Pattern pattern = Pattern.compile("(0[1-9]|1[012])/((19|20)\\d\\d)"); Matcher matcher = pattern.matcher(word); validate = matcher.find(); } return validate; } catch (IllegalFieldValueException e) { return false; } }
From source file:com.axelor.apps.account.service.BudgetService.java
License:Open Source License
public List<BudgetLine> updateLines(Budget budget) { if (budget.getBudgetLineList() != null && !budget.getBudgetLineList().isEmpty()) { for (BudgetLine budgetLine : budget.getBudgetLineList()) { budgetLine.setAmountRealized(BigDecimal.ZERO); }/* w ww. ja va2 s . c om*/ List<BudgetDistribution> budgetDistributionList = Beans.get(BudgetDistributionRepository.class).all() .filter("self.budget.id = ?1 AND (self.invoiceLine.invoice.statusSelect = ?2 OR self.invoiceLine.invoice.statusSelect = ?3)", budget.getId(), InvoiceRepository.STATUS_VALIDATED, InvoiceRepository.STATUS_VENTILATED) .fetch(); for (BudgetDistribution budgetDistribution : budgetDistributionList) { LocalDate orderDate = budgetDistribution.getInvoiceLine().getInvoice().getInvoiceDate(); if (orderDate != null) { for (BudgetLine budgetLine : budget.getBudgetLineList()) { LocalDate fromDate = budgetLine.getFromDate(); LocalDate toDate = budgetLine.getToDate(); if ((fromDate.isBefore(orderDate) || fromDate.isEqual(orderDate)) && (toDate.isAfter(orderDate) || toDate.isEqual(orderDate))) { budgetLine.setAmountRealized( budgetLine.getAmountRealized().add(budgetDistribution.getAmount())); break; } } } } } return budget.getBudgetLineList(); }
From source file:com.axelor.apps.cash.management.service.ForecastRecapService.java
License:Open Source License
public void populateWithSalaries(ForecastRecap forecastRecap) { List<Employee> employeeList = new ArrayList<Employee>(); if (forecastRecap.getBankDetails() != null) { employeeList = Beans.get(EmployeeRepository.class).all() .filter("self.user.activeCompany = ?1 AND self.bankDetails = ?2", forecastRecap.getCompany(), forecastRecap.getBankDetails()) .fetch();/* w w w . ja va2 s . c om*/ } else { employeeList = Beans.get(EmployeeRepository.class).all() .filter("self.user.activeCompany = ?1", forecastRecap.getCompany()).fetch(); } LocalDate itDate = new LocalDate(forecastRecap.getFromDate()); while (!itDate.isAfter(forecastRecap.getToDate())) { if (itDate.isEqual(new LocalDate(itDate.getYear(), itDate.getMonthOfYear(), itDate.dayOfMonth().getMaximumValue()))) { for (Employee employee : employeeList) { forecastRecap.setCurrentBalance(forecastRecap.getCurrentBalance().subtract(employee .getHourlyRate().multiply(employee.getWeeklyWorkHours().multiply(new BigDecimal(4))))); forecastRecap.addForecastRecapLineListItem(this.createForecastRecapLine(itDate, 2, null, employee.getHourlyRate() .multiply(employee.getWeeklyWorkHours().multiply(new BigDecimal(4))), forecastRecap.getCurrentBalance())); } itDate = itDate.plusMonths(1); } else { itDate = new LocalDate(itDate.getYear(), itDate.getMonthOfYear(), itDate.dayOfMonth().getMaximumValue()); } } }
From source file:com.axelor.apps.crm.web.EventController.java
License:Open Source License
@Transactional public void generateRecurrentEvents(ActionRequest request, ActionResponse response) throws AxelorException { Long eventId = new Long(request.getContext().get("_idEvent").toString()); Event event = eventRepo.find(eventId); RecurrenceConfiguration conf = request.getContext().asType(RecurrenceConfiguration.class); RecurrenceConfigurationRepository confRepo = Beans.get(RecurrenceConfigurationRepository.class); conf = confRepo.save(conf);/*from w w w .jav a2 s. com*/ event.setRecurrenceConfiguration(conf); event = eventRepo.save(event); if (request.getContext().get("recurrenceType") == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_RECURRENCE_TYPE)), IException.CONFIGURATION_ERROR); } int recurrenceType = new Integer(request.getContext().get("recurrenceType").toString()); if (request.getContext().get("periodicity") == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_PERIODICITY)), IException.CONFIGURATION_ERROR); } int periodicity = new Integer(request.getContext().get("periodicity").toString()); if (periodicity < 1) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_PERIODICITY)), IException.CONFIGURATION_ERROR); } boolean monday = (boolean) request.getContext().get("monday"); boolean tuesday = (boolean) request.getContext().get("tuesday"); boolean wednesday = (boolean) request.getContext().get("wednesday"); boolean thursday = (boolean) request.getContext().get("thursday"); boolean friday = (boolean) request.getContext().get("friday"); boolean saturday = (boolean) request.getContext().get("saturday"); boolean sunday = (boolean) request.getContext().get("sunday"); Map<Integer, Boolean> daysMap = new HashMap<Integer, Boolean>(); Map<Integer, Boolean> daysCheckedMap = new HashMap<Integer, Boolean>(); if (recurrenceType == 2) { daysMap.put(DateTimeConstants.MONDAY, monday); daysMap.put(DateTimeConstants.TUESDAY, tuesday); daysMap.put(DateTimeConstants.WEDNESDAY, wednesday); daysMap.put(DateTimeConstants.THURSDAY, thursday); daysMap.put(DateTimeConstants.FRIDAY, friday); daysMap.put(DateTimeConstants.SATURDAY, saturday); daysMap.put(DateTimeConstants.SUNDAY, sunday); for (Integer day : daysMap.keySet()) { if (daysMap.get(day)) { daysCheckedMap.put(day, daysMap.get(day)); } } if (daysMap.isEmpty()) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_DAYS_CHECKED)), IException.CONFIGURATION_ERROR); } } int monthRepeatType = new Integer(request.getContext().get("monthRepeatType").toString()); int endType = new Integer(request.getContext().get("endType").toString()); int repetitionsNumber = 0; if (endType == 1) { if (request.getContext().get("repetitionsNumber") == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_REPETITION_NUMBER)), IException.CONFIGURATION_ERROR); } repetitionsNumber = new Integer(request.getContext().get("repetitionsNumber").toString()); if (repetitionsNumber < 1) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_REPETITION_NUMBER)), IException.CONFIGURATION_ERROR); } } LocalDate endDate = new LocalDate(); if (endType == 2) { if (request.getContext().get("endDate") == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_END_DATE)), IException.CONFIGURATION_ERROR); } endDate = new LocalDate(request.getContext().get("endDate").toString()); if (endDate.isBefore(event.getStartDateTime()) && endDate.isEqual(event.getStartDateTime())) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_END_DATE)), IException.CONFIGURATION_ERROR); } } switch (recurrenceType) { case 1: eventService.addRecurrentEventsByDays(event, periodicity, endType, repetitionsNumber, endDate); break; case 2: eventService.addRecurrentEventsByWeeks(event, periodicity, endType, repetitionsNumber, endDate, daysCheckedMap); break; case 3: eventService.addRecurrentEventsByMonths(event, periodicity, endType, repetitionsNumber, endDate, monthRepeatType); break; case 4: eventService.addRecurrentEventsByYears(event, periodicity, endType, repetitionsNumber, endDate); break; default: break; } response.setCanClose(true); response.setReload(true); }
From source file:com.axelor.apps.crm.web.EventController.java
License:Open Source License
@Transactional public void changeAll(ActionRequest request, ActionResponse response) throws AxelorException { Long eventId = new Long(request.getContext().get("_idEvent").toString()); Event event = eventRepo.find(eventId); Event child = eventRepo.all().filter("self.parentEvent.id = ?1", event.getId()).fetchOne(); Event parent = event.getParentEvent(); child.setParentEvent(null);// w w w.ja v a 2s . com Event eventDeleted = child; child = eventRepo.all().filter("self.parentEvent.id = ?1", eventDeleted.getId()).fetchOne(); while (child != null) { child.setParentEvent(null); eventRepo.remove(eventDeleted); eventDeleted = child; child = eventRepo.all().filter("self.parentEvent.id = ?1", eventDeleted.getId()).fetchOne(); } while (parent != null) { Event nextParent = parent.getParentEvent(); eventRepo.remove(parent); parent = nextParent; } RecurrenceConfiguration conf = request.getContext().asType(RecurrenceConfiguration.class); RecurrenceConfigurationRepository confRepo = Beans.get(RecurrenceConfigurationRepository.class); conf = confRepo.save(conf); event.setRecurrenceConfiguration(conf); event = eventRepo.save(event); if (conf.getRecurrenceType() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_RECURRENCE_TYPE)), IException.CONFIGURATION_ERROR); } int recurrenceType = conf.getRecurrenceType(); if (conf.getPeriodicity() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_PERIODICITY)), IException.CONFIGURATION_ERROR); } int periodicity = conf.getPeriodicity(); if (periodicity < 1) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_PERIODICITY)), IException.CONFIGURATION_ERROR); } boolean monday = conf.getMonday(); boolean tuesday = conf.getTuesday(); boolean wednesday = conf.getWednesday(); boolean thursday = conf.getThursday(); boolean friday = conf.getFriday(); boolean saturday = conf.getSaturday(); boolean sunday = conf.getSunday(); Map<Integer, Boolean> daysMap = new HashMap<Integer, Boolean>(); Map<Integer, Boolean> daysCheckedMap = new HashMap<Integer, Boolean>(); if (recurrenceType == 2) { daysMap.put(DateTimeConstants.MONDAY, monday); daysMap.put(DateTimeConstants.TUESDAY, tuesday); daysMap.put(DateTimeConstants.WEDNESDAY, wednesday); daysMap.put(DateTimeConstants.THURSDAY, thursday); daysMap.put(DateTimeConstants.FRIDAY, friday); daysMap.put(DateTimeConstants.SATURDAY, saturday); daysMap.put(DateTimeConstants.SUNDAY, sunday); for (Integer day : daysMap.keySet()) { if (daysMap.get(day)) { daysCheckedMap.put(day, daysMap.get(day)); } } if (daysMap.isEmpty()) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_DAYS_CHECKED)), IException.CONFIGURATION_ERROR); } } int monthRepeatType = conf.getMonthRepeatType(); int endType = conf.getEndType(); int repetitionsNumber = 0; if (endType == 1) { if (conf.getRepetitionsNumber() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_REPETITION_NUMBER)), IException.CONFIGURATION_ERROR); } repetitionsNumber = conf.getRepetitionsNumber(); if (repetitionsNumber < 1) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_REPETITION_NUMBER)), IException.CONFIGURATION_ERROR); } } LocalDate endDate = new LocalDate(); if (endType == 2) { if (conf.getEndDate() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_END_DATE)), IException.CONFIGURATION_ERROR); } endDate = new LocalDate(conf.getEndDate()); if (endDate.isBefore(event.getStartDateTime()) && endDate.isEqual(event.getStartDateTime())) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_END_DATE)), IException.CONFIGURATION_ERROR); } } switch (recurrenceType) { case 1: eventService.addRecurrentEventsByDays(event, periodicity, endType, repetitionsNumber, endDate); break; case 2: eventService.addRecurrentEventsByWeeks(event, periodicity, endType, repetitionsNumber, endDate, daysCheckedMap); break; case 3: eventService.addRecurrentEventsByMonths(event, periodicity, endType, repetitionsNumber, endDate, monthRepeatType); break; case 4: eventService.addRecurrentEventsByYears(event, periodicity, endType, repetitionsNumber, endDate); break; default: break; } response.setCanClose(true); response.setReload(true); }
From source file:com.axelor.apps.hr.service.leave.LeaveService.java
License:Open Source License
public BigDecimal computeDuration(LeaveRequest leave) throws AxelorException { if (leave.getDateFrom() != null && leave.getDateTo() != null) { Employee employee = leave.getUser().getEmployee(); if (employee == null) { throw new AxelorException( String.format(I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), leave.getUser().getName()), IException.CONFIGURATION_ERROR); }//w ww . j a v a2s. c o m WeeklyPlanning weeklyPlanning = employee.getPlanning(); if (weeklyPlanning == null) { HRConfig conf = leave.getCompany().getHrConfig(); if (conf != null) { weeklyPlanning = conf.getWeeklyPlanning(); } } if (weeklyPlanning == null) { throw new AxelorException( String.format(I18n.get(IExceptionMessage.EMPLOYEE_PLANNING), employee.getName()), IException.CONFIGURATION_ERROR); } PublicHolidayPlanning publicHolidayPlanning = employee.getPublicHolidayPlanning(); if (publicHolidayPlanning == null) { HRConfig conf = leave.getCompany().getHrConfig(); if (conf != null) { publicHolidayPlanning = conf.getPublicHolidayPlanning(); } } if (publicHolidayPlanning == null) { throw new AxelorException( String.format(I18n.get(IExceptionMessage.EMPLOYEE_PUBLIC_HOLIDAY), employee.getName()), IException.CONFIGURATION_ERROR); } BigDecimal duration = BigDecimal.ZERO; duration = duration.add(new BigDecimal(this.computeStartDateWithSelect(leave.getDateFrom(), leave.getStartOnSelect(), weeklyPlanning))); LocalDate itDate = new LocalDate(leave.getDateFrom().plusDays(1)); while (!itDate.isEqual(leave.getDateTo()) && !itDate.isAfter(leave.getDateTo())) { duration = duration .add(new BigDecimal(weeklyPlanningService.workingDayValue(weeklyPlanning, itDate))); itDate = itDate.plusDays(1); } if (!leave.getDateFrom().isEqual(leave.getDateTo())) { duration = duration.add(new BigDecimal( this.computeEndDateWithSelect(leave.getDateTo(), leave.getEndOnSelect(), weeklyPlanning))); } duration = duration.subtract(Beans.get(PublicHolidayService.class).computePublicHolidayDays( leave.getDateFrom(), leave.getDateTo(), weeklyPlanning, publicHolidayPlanning)); return duration; } else { return BigDecimal.ZERO; } }
From source file:com.axelor.apps.hr.service.leave.LeaveService.java
License:Open Source License
public BigDecimal computeLeaveDaysByLeaveRequest(LocalDate fromDate, LocalDate toDate, LeaveRequest leaveRequest, Employee employee) throws AxelorException { BigDecimal leaveDays = BigDecimal.ZERO; WeeklyPlanning weeklyPlanning = employee.getPlanning(); if (leaveRequest.getDateFrom().equals(fromDate)) { leaveDays = leaveDays.add(new BigDecimal( this.computeStartDateWithSelect(fromDate, leaveRequest.getStartOnSelect(), weeklyPlanning))); }/*from ww w . j av a2 s.c o m*/ if (leaveRequest.getDateTo().equals(toDate)) { leaveDays = leaveDays.add(new BigDecimal( this.computeEndDateWithSelect(toDate, leaveRequest.getEndOnSelect(), weeklyPlanning))); } LocalDate itDate = new LocalDate(fromDate); if (fromDate.isBefore(leaveRequest.getDateFrom()) || fromDate.equals(leaveRequest.getDateFrom())) { itDate = new LocalDate(leaveRequest.getDateFrom().plusDays(1)); } while (!itDate.isEqual(leaveRequest.getDateTo()) && !itDate.isAfter(toDate)) { leaveDays = leaveDays .add(new BigDecimal(weeklyPlanningService.workingDayValue(weeklyPlanning, itDate))); if (publicHolidayService.checkPublicHolidayDay(itDate, employee)) { leaveDays = leaveDays.subtract(BigDecimal.ONE); } itDate = itDate.plusDays(1); } return leaveDays; }
From source file:com.axelor.apps.project.service.ProjectPlanningService.java
License:Open Source License
public void getTasksForUser(ActionRequest request, ActionResponse response) { List<Map<String, String>> dataList = new ArrayList<Map<String, String>>(); try {/* w w w . j a v a 2s .com*/ LocalDate todayDate = Beans.get(GeneralService.class).getTodayDate(); List<ProjectPlanningLine> linesList = Beans.get(ProjectPlanningLineRepository.class).all() .filter("self.user.id = ?1 AND self.year >= ?2 AND self.week >= ?3", AuthUtils.getUser().getId(), todayDate.getYear(), todayDate.getWeekOfWeekyear()) .fetch(); for (ProjectPlanningLine line : linesList) { if (line.getMonday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.MONDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getMonday().toString()); dataList.add(map); } } if (line.getTuesday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.TUESDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getTuesday().toString()); dataList.add(map); } } if (line.getWednesday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.WEDNESDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getWednesday().toString()); dataList.add(map); } } if (line.getThursday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.THURSDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getThursday().toString()); dataList.add(map); } } if (line.getFriday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.FRIDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getFriday().toString()); dataList.add(map); } } if (line.getSaturday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.SATURDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getSaturday().toString()); dataList.add(map); } } if (line.getSunday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.SUNDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getSunday().toString()); dataList.add(map); } } } response.setData(dataList); } catch (Exception e) { response.setStatus(-1); response.setError(e.getMessage()); } }
From source file:com.axelor.apps.supplychain.service.BudgetSupplychainService.java
License:Open Source License
@Override public List<BudgetLine> updateLines(Budget budget) { if (budget.getBudgetLineList() != null && !budget.getBudgetLineList().isEmpty()) { for (BudgetLine budgetLine : budget.getBudgetLineList()) { budgetLine.setAmountCommitted(BigDecimal.ZERO); budgetLine.setAmountRealized(BigDecimal.ZERO); }//from w ww . j a v a 2 s .com List<BudgetDistribution> budgetDistributionList = null; budgetDistributionList = Beans.get(BudgetDistributionRepository.class).all().filter( "self.budget.id = ?1 AND (self.purchaseOrderLine.purchaseOrder.statusSelect = ?2 OR self.purchaseOrderLine.purchaseOrder.statusSelect = ?3)", budget.getId(), IPurchaseOrder.STATUS_VALIDATED, IPurchaseOrder.STATUS_FINISHED).fetch(); for (BudgetDistribution budgetDistribution : budgetDistributionList) { LocalDate orderDate = budgetDistribution.getPurchaseOrderLine().getPurchaseOrder().getOrderDate(); if (orderDate != null) { for (BudgetLine budgetLine : budget.getBudgetLineList()) { LocalDate fromDate = budgetLine.getFromDate(); LocalDate toDate = budgetLine.getToDate(); if ((fromDate.isBefore(orderDate) || fromDate.isEqual(orderDate)) && (toDate.isAfter(orderDate) || toDate.isEqual(orderDate))) { budgetLine.setAmountCommitted( budgetLine.getAmountCommitted().add(budgetDistribution.getAmount())); break; } } } } budgetDistributionList = Beans.get(BudgetDistributionRepository.class).all().filter( "self.budget.id = ?1 AND (self.invoiceLine.invoice.statusSelect = ?2 OR self.invoiceLine.invoice.statusSelect = ?3)", budget.getId(), InvoiceRepository.STATUS_VALIDATED, InvoiceRepository.STATUS_VENTILATED) .fetch(); for (BudgetDistribution budgetDistribution : budgetDistributionList) { LocalDate orderDate = budgetDistribution.getInvoiceLine().getInvoice().getInvoiceDate(); if (orderDate != null) { for (BudgetLine budgetLine : budget.getBudgetLineList()) { LocalDate fromDate = budgetLine.getFromDate(); LocalDate toDate = budgetLine.getToDate(); if ((fromDate.isBefore(orderDate) || fromDate.isEqual(orderDate)) && (toDate.isAfter(orderDate) || toDate.isEqual(orderDate))) { budgetLine.setAmountRealized( budgetLine.getAmountRealized().add(budgetDistribution.getAmount())); break; } } } } } return budget.getBudgetLineList(); }