List of usage examples for org.joda.time LocalDate dayOfMonth
public Property dayOfMonth()
From source file:com.axelor.apps.account.service.invoice.InvoiceToolService.java
License:Open Source License
public static LocalDate getDueDate(PaymentCondition paymentCondition, LocalDate invoiceDate) { switch (paymentCondition.getTypeSelect()) { case PaymentConditionRepository.TYPE_NET: return invoiceDate.plusDays(paymentCondition.getPaymentTime()); case PaymentConditionRepository.TYPE_END_OF_MONTH_N_DAYS: return invoiceDate.dayOfMonth().withMaximumValue().plusDays(paymentCondition.getPaymentTime()); case PaymentConditionRepository.TYPE_N_DAYS_END_OF_MONTH: return invoiceDate.plusDays(paymentCondition.getPaymentTime()).dayOfMonth().withMaximumValue(); case PaymentConditionRepository.TYPE_N_DAYS_END_OF_MONTH_AT: return invoiceDate.plusDays(paymentCondition.getPaymentTime()).dayOfMonth().withMaximumValue() .plusDays(paymentCondition.getDaySelect()); default:/*from ww w .java 2s .c o m*/ return invoiceDate; } }
From source file:com.axelor.apps.base.service.scheduler.SchedulerService.java
License:Open Source License
/** * Obtient le prochain jour du mois partir d'une date * * @param localDate/* ww w .j ava2 s. com*/ * Date de rfrence * @param dayMonthly * Jour du mois * * @return LocalDate * Date correspondant au prochain jour du mois */ public LocalDate getNextDayMonth(LocalDate localDate, int dayMonthly) { LocalDate date = null; int start = localDate.dayOfMonth().getMinimumValue(); int end = localDate.dayOfMonth().getMaximumValue(); if (localDate.dayOfMonth().get() <= dayMonthly) { if (start <= dayMonthly && dayMonthly <= end) date = localDate.withDayOfMonth(dayMonthly); else if (dayMonthly < start) date = localDate.dayOfMonth().withMinimumValue(); else if (dayMonthly > end) date = localDate.dayOfMonth().withMaximumValue(); } else { int startNext = localDate.plusMonths(1).dayOfMonth().getMinimumValue(); int endNext = localDate.plusMonths(1).dayOfMonth().getMaximumValue(); if (startNext <= dayMonthly && dayMonthly <= endNext) date = localDate.plusMonths(1).withDayOfMonth(dayMonthly); else if (dayMonthly < startNext) date = localDate.plusMonths(1).dayOfMonth().withMinimumValue(); else if (dayMonthly > endNext) date = localDate.plusMonths(1).dayOfMonth().withMaximumValue(); } return date; }
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();/*from ww w. j a v a 2 s. c o m*/ } 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.hr.service.PayrollPreparationService.java
License:Open Source License
public List<PayrollLeave> fillInLeaves(PayrollPreparation payrollPreparation) throws AxelorException { List<PayrollLeave> payrollLeaveList = new ArrayList<PayrollLeave>(); LocalDate fromDate = new LocalDate(payrollPreparation.getYearPeriod(), payrollPreparation.getMonthSelect(), 1);/*w w w. j av a 2 s. com*/ LocalDate toDate = new LocalDate(fromDate); toDate = toDate.dayOfMonth().withMaximumValue(); Employee employee = payrollPreparation.getEmployee(); if (employee.getPublicHolidayPlanning() == null) { throw new AxelorException( String.format(I18n.get(IExceptionMessage.EMPLOYEE_PUBLIC_HOLIDAY), employee.getName()), IException.CONFIGURATION_ERROR); } if (employee.getPlanning() == null) { throw new AxelorException( String.format(I18n.get(IExceptionMessage.EMPLOYEE_PLANNING), employee.getName()), IException.CONFIGURATION_ERROR); } List<LeaveRequest> leaveRequestList = leaveRequestRepo.all().filter( "self.statusSelect = 3 AND self.user.employee = ?3 AND self.dateFrom <= ?1 AND self.dateTo >= ?2", toDate, fromDate, employee).fetch(); for (LeaveRequest leaveRequest : leaveRequestList) { PayrollLeave payrollLeave = new PayrollLeave(); if (leaveRequest.getDateFrom().isBefore(fromDate)) { payrollLeave.setFromDate(fromDate); } else { payrollLeave.setFromDate(leaveRequest.getDateFrom()); } if (leaveRequest.getDateTo().isAfter(toDate)) { payrollLeave.setToDate(toDate); } else { payrollLeave.setToDate(leaveRequest.getDateTo()); } payrollLeave.setDuration( leaveService.computeLeaveDaysByLeaveRequest(fromDate, toDate, leaveRequest, employee)); payrollLeave.setReason(leaveRequest.getReason()); payrollLeave.setLeaveRequest(leaveRequest); payrollLeaveList.add(payrollLeave); } return payrollLeaveList; }
From source file:com.axelor.apps.hr.service.PayrollPreparationService.java
License:Open Source License
public BigDecimal computeWorkingDaysNumber(PayrollPreparation payrollPreparation, List<PayrollLeave> payrollLeaveList) { LocalDate fromDate = new LocalDate(payrollPreparation.getYearPeriod(), payrollPreparation.getMonthSelect(), 1);/*from w w w. j av a2s .c o m*/ LocalDate toDate = new LocalDate(fromDate); toDate = toDate.dayOfMonth().withMaximumValue(); LocalDate itDate = new LocalDate(fromDate); BigDecimal workingDays = BigDecimal.ZERO; while (!itDate.isAfter(toDate)) { workingDays = workingDays.add(new BigDecimal( weeklyPlanningService.workingDayValue(payrollPreparation.getEmployee().getPlanning(), itDate))); itDate = itDate.plusDays(1); } if (payrollLeaveList != null) { for (PayrollLeave payrollLeave : payrollLeaveList) { workingDays = workingDays.subtract(payrollLeave.getDuration()); } } return workingDays; }
From source file:com.axelor.apps.hr.service.PayrollPreparationService.java
License:Open Source License
public void fillInExtraHours(PayrollPreparation payrollPreparation) { LocalDate fromDate = new LocalDate(payrollPreparation.getYearPeriod(), payrollPreparation.getMonthSelect(), 1);//from ww w . j a va 2 s .c o m LocalDate toDate = new LocalDate(fromDate); toDate = toDate.dayOfMonth().withMaximumValue(); for (ExtraHoursLine extraHoursLine : Beans.get(ExtraHoursLineRepository.class).all().filter( "self.user.employee = ?1 AND self.extraHours.statusSelect = 3 AND self.date BETWEEN ?2 AND ?3 AND self.payrollPreparation = null", payrollPreparation.getEmployee(), fromDate, toDate).fetch()) { payrollPreparation.addExtraHoursLineListItem(extraHoursLine); } }
From source file:com.axelor.apps.project.service.ProjectPlanningService.java
License:Open Source License
public LocalDate getFromDate() { LocalDate todayDate = generalService.getTodayDate(); return new LocalDate(todayDate.getYear(), todayDate.getMonthOfYear(), todayDate.dayOfMonth().getMinimumValue()); }
From source file:com.axelor.apps.project.service.ProjectPlanningService.java
License:Open Source License
public LocalDate getToDate() { LocalDate todayDate = generalService.getTodayDate(); return new LocalDate(todayDate.getYear(), todayDate.getMonthOfYear(), todayDate.dayOfMonth().getMaximumValue()); }
From source file:com.axelor.apps.tool.date.DateTool.java
License:Open Source License
private static int days360Between(LocalDate startDate, LocalDate endDate) { int nbDayOfFirstMonth = 0; int nbDayOfOthersMonths = 0; int nbDayOfLastMonth = 0; LocalDate start = startDate;/* ww w .j a v a 2s .co m*/ if (endDate.getMonthOfYear() != startDate.getMonthOfYear() || endDate.getYear() != startDate.getYear()) { // First month :: if the startDate is not the last day of the month if (!startDate.isEqual(startDate.dayOfMonth().withMaximumValue())) { nbDayOfFirstMonth = 30 - startDate.getDayOfMonth(); } // The startDate is included nbDayOfFirstMonth = nbDayOfFirstMonth + 1; // Months between the first one and the last one LocalDate date1 = startDate.plusMonths(1).dayOfMonth().withMinimumValue(); while (endDate.getMonthOfYear() != date1.getMonthOfYear() || endDate.getYear() != date1.getYear()) { nbDayOfOthersMonths = nbDayOfOthersMonths + 30; date1 = date1.plusMonths(1); } // Last Month start = endDate.dayOfMonth().withMinimumValue(); } if (endDate.isEqual(endDate.dayOfMonth().withMaximumValue())) { nbDayOfLastMonth = 30 - start.getDayOfMonth(); } else { nbDayOfLastMonth = endDate.getDayOfMonth() - start.getDayOfMonth(); } // The endDate is included nbDayOfLastMonth = nbDayOfLastMonth + 1; return nbDayOfFirstMonth + nbDayOfOthersMonths + nbDayOfLastMonth; }
From source file:com.axelor.csv.script.UpdateAll.java
License:Open Source License
@Transactional public Object updatePeriod(Object bean, Map<String, Object> values) { try {//from w w w .ja v a 2 s .com assert bean instanceof Company; Company company = (Company) bean; List<? extends Period> periods = periodRepo.all().filter("self.company.id = ?1", company.getId()) .fetch(); if (periods == null || periods.isEmpty()) { for (Year year : yearRepo.all() .filter("self.company.id = ?1 AND self.typeSelect = 1", company.getId()).fetch()) { for (Integer month : Arrays.asList(new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 })) { Period period = new Period(); LocalDate dt = new LocalDate(year.getFromDate().getYear(), month, 1); period.setToDate(dt.dayOfMonth().withMaximumValue()); period.setFromDate(dt.dayOfMonth().withMinimumValue()); period.setYear(year); period.setStatusSelect(PeriodRepository.STATUS_OPENED); period.setCompany(company); period.setCode(dt.toString().split("-")[1] + "/" + year.getCode().split("_")[0] + "_" + company.getName()); period.setName(dt.toString().split("-")[1] + '/' + year.getName()); periodRepo.save(period); } } } return company; } catch (Exception e) { e.printStackTrace(); } return bean; }