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);
}
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);
}
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);
}
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;
}
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);
}
}
}
}
Aggregations