Search in sources :

Example 26 with TimesheetLine

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

the class TimesheetTimerServiceImpl method generateTimesheetLine.

@Transactional
public TimesheetLine generateTimesheetLine(TSTimer timer) {
    BigDecimal durationHours = this.convertSecondDurationInHours(timer.getDuration());
    Timesheet timesheet = Beans.get(TimesheetService.class).getCurrentOrCreateTimesheet();
    LocalDate startDateTime = (timer.getStartDateTime() == null) ? Beans.get(AppBaseService.class).getTodayDateTime().toLocalDate() : timer.getStartDateTime().toLocalDate();
    TimesheetLine timesheetLine = Beans.get(TimesheetLineService.class).createTimesheetLine(timer.getProject(), timer.getProduct(), timer.getUser(), startDateTime, timesheet, durationHours, timer.getComments());
    Beans.get(TimesheetRepository.class).save(timesheet);
    Beans.get(TimesheetLineRepository.class).save(timesheetLine);
    timer.setTimesheetLine(timesheetLine);
    return timesheetLine;
}
Also used : TimesheetLineRepository(com.axelor.apps.hr.db.repo.TimesheetLineRepository) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) TimesheetRepository(com.axelor.apps.hr.db.repo.TimesheetRepository) Timesheet(com.axelor.apps.hr.db.Timesheet) TimesheetLineService(com.axelor.apps.hr.service.timesheet.TimesheetLineService) TimesheetService(com.axelor.apps.hr.service.timesheet.TimesheetService) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 27 with TimesheetLine

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

the class TimesheetHRRepository method validate.

@Override
public Map<String, Object> validate(Map<String, Object> json, Map<String, Object> context) {
    Map<String, Object> obj = super.validate(json, context);
    if (json.get("id") == null) {
        Timesheet timesheet = create(json);
        if (timesheet.getTimesheetLineList() == null || timesheet.getTimesheetLineList().isEmpty()) {
            timesheet.setTimesheetLineList(new ArrayList<TimesheetLine>());
            obj.put("timesheetLineList", timesheetService.createDefaultLines(timesheet));
        }
    }
    return obj;
}
Also used : TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) Timesheet(com.axelor.apps.hr.db.Timesheet)

Example 28 with TimesheetLine

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

the class OperationOrderTimesheetServiceImpl method updateOperationOrders.

@Override
@Transactional(rollbackOn = { Exception.class })
public void updateOperationOrders(Timesheet timesheet) throws AxelorException {
    if (timesheet.getTimesheetLineList() == null) {
        return;
    }
    // ensure that correct hoursDuration is filled
    TimesheetLineService timesheetLineService = Beans.get(TimesheetLineService.class);
    for (TimesheetLine timesheetLine : timesheet.getTimesheetLineList()) {
        BigDecimal hoursDuration = timesheetLineService.computeHoursDuration(timesheet, timesheetLine.getDuration(), true);
        timesheetLine.setHoursDuration(hoursDuration);
    }
    if (!Beans.get(AppProductionService.class).getAppProduction().getEnableTimesheetOnManufOrder()) {
        return;
    }
    List<TimesheetLine> oldTimesheetLineList = Beans.get(TimesheetLineRepository.class).all().filter("self.timesheet.id = :timesheetId").bind("timesheetId", timesheet.getId()).fetch();
    List<TimesheetLine> newTimesheetLineList = timesheet.getTimesheetLineList();
    List<TimesheetLine> allTimesheetLineList = new ArrayList<>(oldTimesheetLineList);
    allTimesheetLineList.addAll(newTimesheetLineList);
    List<OperationOrder> operationOrdersToUpdate = allTimesheetLineList.stream().map(TimesheetLine::getOperationOrder).filter(Objects::nonNull).distinct().collect(Collectors.toList());
    operationOrdersToUpdate.forEach(operationOrder -> updateOperationOrder(operationOrder, oldTimesheetLineList, newTimesheetLineList));
}
Also used : TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) TimesheetLineService(com.axelor.apps.hr.service.timesheet.TimesheetLineService) ArrayList(java.util.ArrayList) Objects(java.util.Objects) OperationOrder(com.axelor.apps.production.db.OperationOrder) BigDecimal(java.math.BigDecimal) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) Transactional(com.google.inject.persist.Transactional)

Example 29 with TimesheetLine

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

the class TimesheetProjectServiceImpl method createInvoiceLines.

@Override
public List<InvoiceLine> createInvoiceLines(Invoice invoice, List<TimesheetLine> timesheetLineList, int priority) throws AxelorException {
    if (!Beans.get(AppHumanResourceService.class).isApp("business-project")) {
        return super.createInvoiceLines(invoice, timesheetLineList, priority);
    }
    List<InvoiceLine> invoiceLineList = new ArrayList<InvoiceLine>();
    int count = 0;
    DateTimeFormatter ddmmFormat = DateTimeFormatter.ofPattern("dd/MM");
    HashMap<String, Object[]> timeSheetInformationsMap = new HashMap<String, Object[]>();
    // Check if a consolidation by product and user must be done
    boolean consolidate = appHumanResourceService.getAppTimesheet().getConsolidateTSLine();
    for (TimesheetLine timesheetLine : timesheetLineList) {
        Object[] tabInformations = new Object[6];
        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.getDurationForCustomer() != null ? this.computeDurationForCustomer(timesheetLine) : timesheetLine.getHoursDuration();
        tabInformations[5] = timesheetLine.getProject();
        String key = null;
        if (consolidate) {
            key = timesheetLine.getProduct().getId() + "|" + timesheetLine.getUser().getId() + "|" + timesheetLine.getProject().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.getDurationForCustomer() != null ? this.computeDurationForCustomer(timesheetLine) : timesheetLine.getHoursDuration());
            } else {
                timeSheetInformationsMap.put(key, tabInformations);
            }
        } else {
            key = String.valueOf(timesheetLine.getId());
            timeSheetInformationsMap.put(key, tabInformations);
        }
    }
    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];
        Project project = (Project) timesheetInformations[5];
        PriceList priceList = project.getPriceList();
        if (consolidate) {
            if (startDate != null && endDate != null) {
                strDate = startDate.format(ddmmFormat) + " - " + endDate.format(ddmmFormat);
            }
        } else {
            if (startDate != null) {
                strDate = startDate.format(ddmmFormat);
            }
        }
        invoiceLineList.addAll(this.createInvoiceLine(invoice, product, user, strDate, hoursDuration, priority * 100 + count, priceList));
        invoiceLineList.get(invoiceLineList.size() - 1).setProject(project);
        count++;
    }
    return invoiceLineList;
}
Also used : User(com.axelor.auth.db.User) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) 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) Project(com.axelor.apps.project.db.Project) DateTimeFormatter(java.time.format.DateTimeFormatter) PriceList(com.axelor.apps.base.db.PriceList)

Example 30 with TimesheetLine

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

the class WorkflowVentilationProjectServiceImpl method afterVentilation.

@Override
@Transactional(rollbackOn = { Exception.class })
public void afterVentilation(Invoice invoice) throws AxelorException {
    super.afterVentilation(invoice);
    if (!Beans.get(AppBusinessProjectService.class).isApp("business-project")) {
        return;
    }
    InvoicingProject invoicingProject = invoicingProjectRepo.all().filter("self.invoice.id = ?", invoice.getId()).fetchOne();
    if (invoicingProject != null) {
        for (SaleOrderLine saleOrderLine : invoicingProject.getSaleOrderLineSet()) {
            saleOrderLine.setInvoiced(true);
        }
        for (PurchaseOrderLine purchaseOrderLine : invoicingProject.getPurchaseOrderLineSet()) {
            purchaseOrderLine.setInvoiced(true);
        }
        for (TimesheetLine timesheetLine : invoicingProject.getLogTimesSet()) {
            timesheetLine.setInvoiced(true);
            if (timesheetLine.getProjectTask() == null) {
                continue;
            }
            timesheetLine.getProjectTask().setInvoiced(this.checkInvoicedTimesheetLines(timesheetLine.getProjectTask()));
        }
        for (ExpenseLine expenseLine : invoicingProject.getExpenseLineSet()) {
            expenseLine.setInvoiced(true);
        }
        for (ProjectTask projectTask : invoicingProject.getProjectTaskSet()) {
            projectTask.setInvoiced(true);
        }
        for (Project project : invoicingProject.getProjectSet()) {
            project.setInvoiced(true);
        }
        invoicingProject.setStatusSelect(InvoicingProjectRepository.STATUS_VENTILATED);
        invoicingProjectRepo.save(invoicingProject);
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) InvoicingProject(com.axelor.apps.businessproject.db.InvoicingProject) Project(com.axelor.apps.project.db.Project) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine) ProjectTask(com.axelor.apps.project.db.ProjectTask) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) InvoicingProject(com.axelor.apps.businessproject.db.InvoicingProject) Transactional(com.google.inject.persist.Transactional)

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