Search in sources :

Example 1 with TimesheetLine

use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.

the class TimesheetReportServiceImpl method getTotalWeekWorkedHours.

private BigDecimal getTotalWeekWorkedHours(User user, LocalDate fromDate, LocalDate toDate, BigDecimal publicHolidays) throws AxelorException {
    BigDecimal totalHours = BigDecimal.ZERO;
    Employee employee = user.getEmployee();
    List<TimesheetLine> timesheetLineList = timesheetLineRepository.all().filter("self.user = ? AND (self.date BETWEEN ? AND ?) AND (self.timesheet.statusSelect = ? OR self.timesheet.statusSelect = ?)", user, fromDate, toDate, TimesheetRepository.STATUS_VALIDATED, TimesheetRepository.STATUS_CONFIRMED).fetch();
    Duration totalDuration = timesheetLineService.computeTotalDuration(timesheetLineList);
    totalHours = new BigDecimal(totalDuration.getSeconds()).divide(BigDecimal.valueOf(3600)).setScale(2, RoundingMode.HALF_UP);
    totalHours = totalHours.add(publicHolidays.multiply(employee.getDailyWorkHours()));
    totalHours = totalHours.add(getWeekLeaveHours(user, fromDate, toDate, employee.getDailyWorkHours()));
    return totalHours.setScale(2, RoundingMode.HALF_UP);
}
Also used : Employee(com.axelor.apps.hr.db.Employee) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) Duration(java.time.Duration) BigDecimal(java.math.BigDecimal)

Example 2 with TimesheetLine

use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.

the class TimesheetReportServiceImpl method getTotalWorkedHours.

private BigDecimal getTotalWorkedHours(User user, LocalDate date, boolean isPublicHoliday, BigDecimal dailyWorkingHours) throws AxelorException {
    BigDecimal totalHours = BigDecimal.ZERO;
    List<TimesheetLine> timesheetLineList = timesheetLineRepository.all().filter("self.user = ? AND self.date = ? AND (self.timesheet.statusSelect = ? OR self.timesheet.statusSelect = ?)", user, date, TimesheetRepository.STATUS_CONFIRMED, TimesheetRepository.STATUS_VALIDATED).fetch();
    Duration totalDuration = timesheetLineService.computeTotalDuration(timesheetLineList);
    totalHours = new BigDecimal(totalDuration.getSeconds()).divide(BigDecimal.valueOf(3600)).setScale(2, RoundingMode.HALF_UP);
    if (isPublicHoliday) {
        totalHours = totalHours.add(dailyWorkingHours);
    } else {
        totalHours = totalHours.add(getLeaveHours(user, date, dailyWorkingHours));
    }
    return totalHours.setScale(2, RoundingMode.HALF_UP);
}
Also used : TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) Duration(java.time.Duration) BigDecimal(java.math.BigDecimal)

Example 3 with TimesheetLine

use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.

the class TimesheetServiceImpl method removeAfterToDateTimesheetLines.

@Override
@Transactional
public void removeAfterToDateTimesheetLines(Timesheet timesheet) {
    List<TimesheetLine> removedTimesheetLines = new ArrayList<>();
    for (TimesheetLine timesheetLine : ListUtils.emptyIfNull(timesheet.getTimesheetLineList())) {
        if (timesheetLine.getDate().isAfter(timesheet.getToDate())) {
            removedTimesheetLines.add(timesheetLine);
            if (timesheetLine.getId() != null) {
                timesheetlineRepo.remove(timesheetLine);
            }
        }
    }
    timesheet.getTimesheetLineList().removeAll(removedTimesheetLines);
}
Also used : TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) ArrayList(java.util.ArrayList) Transactional(com.google.inject.persist.Transactional)

Example 4 with TimesheetLine

use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.

the class TimesheetServiceImpl method createInvoiceLines.

@Override
public List<InvoiceLine> createInvoiceLines(Invoice invoice, List<TimesheetLine> timesheetLineList, int priority) throws AxelorException {
    List<InvoiceLine> invoiceLineList = new ArrayList<>();
    int count = 0;
    DateFormat ddmmFormat = new SimpleDateFormat("dd/MM");
    HashMap<String, Object[]> timeSheetInformationsMap = new HashMap<>();
    // Check if a consolidation by product and user must be done
    boolean consolidate = appHumanResourceService.getAppTimesheet().getConsolidateTSLine();
    for (TimesheetLine timesheetLine : timesheetLineList) {
        Object[] tabInformations = new Object[5];
        tabInformations[0] = timesheetLine.getProduct();
        tabInformations[1] = timesheetLine.getUser();
        // Start date
        tabInformations[2] = timesheetLine.getDate();
        // End date, useful only for consolidation
        tabInformations[3] = timesheetLine.getDate();
        tabInformations[4] = timesheetLine.getHoursDuration();
        String key = null;
        if (consolidate) {
            key = timesheetLine.getProduct().getId() + "|" + timesheetLine.getUser().getId();
            if (timeSheetInformationsMap.containsKey(key)) {
                tabInformations = timeSheetInformationsMap.get(key);
                // Update date
                if (timesheetLine.getDate().compareTo((LocalDate) tabInformations[2]) < 0) {
                    // If date is lower than start date then replace start date by this one
                    tabInformations[2] = timesheetLine.getDate();
                } else if (timesheetLine.getDate().compareTo((LocalDate) tabInformations[3]) > 0) {
                    // If date is upper than end date then replace end date by this one
                    tabInformations[3] = timesheetLine.getDate();
                }
                tabInformations[4] = ((BigDecimal) tabInformations[4]).add(timesheetLine.getHoursDuration());
            } else {
                timeSheetInformationsMap.put(key, tabInformations);
            }
        } else {
            key = String.valueOf(timesheetLine.getId());
            timeSheetInformationsMap.put(key, tabInformations);
        }
        timesheetLine.setInvoiced(true);
    }
    for (Object[] timesheetInformations : timeSheetInformationsMap.values()) {
        String strDate = null;
        Product product = (Product) timesheetInformations[0];
        User user = (User) timesheetInformations[1];
        LocalDate startDate = (LocalDate) timesheetInformations[2];
        LocalDate endDate = (LocalDate) timesheetInformations[3];
        BigDecimal hoursDuration = (BigDecimal) timesheetInformations[4];
        PriceList priceList = Beans.get(PartnerPriceListService.class).getDefaultPriceList(invoice.getPartner(), PriceListRepository.TYPE_SALE);
        if (consolidate) {
            strDate = ddmmFormat.format(startDate) + " - " + ddmmFormat.format(endDate);
        } else {
            strDate = ddmmFormat.format(startDate);
        }
        invoiceLineList.addAll(this.createInvoiceLine(invoice, product, user, strDate, hoursDuration, priority * 100 + count, priceList));
        count++;
    }
    return invoiceLineList;
}
Also used : User(com.axelor.auth.db.User) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) PartnerPriceListService(com.axelor.apps.base.service.PartnerPriceListService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) SimpleDateFormat(java.text.SimpleDateFormat) PriceList(com.axelor.apps.base.db.PriceList)

Example 5 with TimesheetLine

use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.

the class TimesheetServiceImpl method validateDates.

/**
 * Checks validity of dates related to the timesheet.
 *
 * @param timesheet
 * @throws AxelorException if
 *     <ul>
 *       <li>fromDate of the timesheet is null
 *       <li>toDate of the timesheet is null
 *       <li>timesheetLineList of the timesheet is null or empty
 *       <li>date of a timesheet line is null
 *       <li>date of a timesheet line is before fromDate or after toDate of the timesheet
 *     </ul>
 */
protected void validateDates(Timesheet timesheet) throws AxelorException {
    List<TimesheetLine> timesheetLineList = timesheet.getTimesheetLineList();
    LocalDate fromDate = timesheet.getFromDate();
    LocalDate toDate = timesheet.getToDate();
    if (fromDate == null) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_NULL_FROM_DATE));
    } else if (toDate == null) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_NULL_TO_DATE));
    } else if (ObjectUtils.isEmpty(timesheetLineList)) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.TIMESHEET_TIMESHEET_LINE_LIST_IS_EMPTY));
    } else {
        for (TimesheetLine timesheetLine : timesheetLineList) {
            LocalDate timesheetLineDate = timesheetLine.getDate();
            if (timesheetLineDate == null) {
                throw new AxelorException(timesheetLine, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_LINE_NULL_DATE), timesheetLineList.indexOf(timesheetLine) + 1);
            }
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) LocalDate(java.time.LocalDate)

Aggregations

TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)32 BigDecimal (java.math.BigDecimal)15 Transactional (com.google.inject.persist.Transactional)9 LocalDate (java.time.LocalDate)8 User (com.axelor.auth.db.User)7 ArrayList (java.util.ArrayList)7 Timesheet (com.axelor.apps.hr.db.Timesheet)6 Project (com.axelor.apps.project.db.Project)6 AxelorException (com.axelor.exception.AxelorException)6 HashMap (java.util.HashMap)6 TimesheetLineService (com.axelor.apps.hr.service.timesheet.TimesheetLineService)5 Product (com.axelor.apps.base.db.Product)4 Employee (com.axelor.apps.hr.db.Employee)4 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)3 TimesheetLineRepository (com.axelor.apps.hr.db.repo.TimesheetLineRepository)3 ProjectTask (com.axelor.apps.project.db.ProjectTask)3 DayPlanning (com.axelor.apps.base.db.DayPlanning)2 PriceList (com.axelor.apps.base.db.PriceList)2 WeeklyPlanning (com.axelor.apps.base.db.WeeklyPlanning)2 ExpenseLine (com.axelor.apps.hr.db.ExpenseLine)2