Search in sources :

Example 96 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ProjectPlanningTimeServiceImpl method addMultipleProjectPlanningTime.

@Override
@Transactional(rollbackOn = { Exception.class })
public void addMultipleProjectPlanningTime(Map<String, Object> datas) throws AxelorException {
    if (datas.get("project") == null || datas.get("user") == null || datas.get("fromDate") == null || datas.get("toDate") == null) {
        return;
    }
    DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
    LocalDateTime fromDate = LocalDateTime.parse(datas.get("fromDate").toString(), formatter);
    LocalDateTime toDate = LocalDateTime.parse(datas.get("toDate").toString(), formatter);
    ProjectTask projectTask = null;
    Map<String, Object> objMap = (Map) datas.get("project");
    Project project = projectRepo.find(Long.parseLong(objMap.get("id").toString()));
    Integer timePercent = 0;
    if (datas.get("timepercent") != null) {
        timePercent = Integer.parseInt(datas.get("timepercent").toString());
    }
    objMap = (Map) datas.get("user");
    User user = userRepo.find(Long.parseLong(objMap.get("id").toString()));
    if (user.getEmployee() == null) {
        return;
    }
    if (datas.get("task") != null) {
        objMap = (Map) datas.get("task");
        projectTask = projectTaskRepo.find(Long.valueOf(objMap.get("id").toString()));
    }
    Product activity = null;
    if (datas.get("product") != null) {
        objMap = (Map) datas.get("product");
        activity = productRepo.find(Long.valueOf(objMap.get("id").toString()));
    }
    Employee employee = user.getEmployee();
    BigDecimal dailyWorkHrs = employee.getDailyWorkHours();
    while (fromDate.isBefore(toDate)) {
        LocalDate date = fromDate.toLocalDate();
        LOG.debug("Create Planning for the date: {}", date);
        double dayHrs = 0;
        if (employee.getWeeklyPlanning() != null) {
            dayHrs = weeklyPlanningService.getWorkingDayValueInDays(employee.getWeeklyPlanning(), date);
        }
        if (dayHrs > 0 && !holidayService.checkPublicHolidayDay(date, employee)) {
            ProjectPlanningTime planningTime = new ProjectPlanningTime();
            planningTime.setProjectTask(projectTask);
            planningTime.setProduct(activity);
            planningTime.setTimepercent(timePercent);
            planningTime.setUser(user);
            planningTime.setDate(date);
            planningTime.setProject(project);
            planningTime.setIsIncludeInTurnoverForecast((Boolean) datas.get("isIncludeInTurnoverForecast"));
            BigDecimal totalHours = BigDecimal.ZERO;
            if (timePercent > 0) {
                totalHours = dailyWorkHrs.multiply(new BigDecimal(timePercent)).divide(new BigDecimal(100));
            }
            planningTime.setPlannedHours(totalHours);
            planningTimeRepo.save(planningTime);
        }
        fromDate = fromDate.plusDays(1);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) User(com.axelor.auth.db.User) Product(com.axelor.apps.base.db.Product) ProjectPlanningTime(com.axelor.apps.project.db.ProjectPlanningTime) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Project(com.axelor.apps.project.db.Project) Employee(com.axelor.apps.hr.db.Employee) ProjectTask(com.axelor.apps.project.db.ProjectTask) DateTimeFormatter(java.time.format.DateTimeFormatter) Map(java.util.Map) Transactional(com.google.inject.persist.Transactional)

Example 97 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class TimesheetController method generateLines.

@SuppressWarnings("unchecked")
public void generateLines(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        Timesheet timesheet = request.getContext().asType(Timesheet.class);
        Context context = request.getContext();
        LocalDate fromGenerationDate = null;
        if (context.get("fromGenerationDate") != null)
            fromGenerationDate = LocalDate.parse(context.get("fromGenerationDate").toString(), DateTimeFormatter.ISO_DATE);
        LocalDate toGenerationDate = null;
        if (context.get("toGenerationDate") != null)
            toGenerationDate = LocalDate.parse(context.get("toGenerationDate").toString(), DateTimeFormatter.ISO_DATE);
        BigDecimal logTime = BigDecimal.ZERO;
        if (context.get("logTime") != null)
            logTime = new BigDecimal(context.get("logTime").toString());
        Map<String, Object> projectContext = (Map<String, Object>) context.get("project");
        Project project = null;
        if (projectContext != null) {
            project = Beans.get(ProjectRepository.class).find(((Integer) projectContext.get("id")).longValue());
        }
        Map<String, Object> productContext = (Map<String, Object>) context.get("product");
        Product product = null;
        if (productContext != null) {
            product = Beans.get(ProductRepository.class).find(((Integer) productContext.get("id")).longValue());
        }
        if (context.get("showActivity") == null || !(Boolean) context.get("showActivity")) {
            product = Beans.get(UserHrService.class).getTimesheetProduct(timesheet.getUser());
        }
        timesheet = Beans.get(TimesheetService.class).generateLines(timesheet, fromGenerationDate, toGenerationDate, logTime, project, product);
        response.setValue("timesheetLineList", timesheet.getTimesheetLineList());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) Timesheet(com.axelor.apps.hr.db.Timesheet) Product(com.axelor.apps.base.db.Product) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) Project(com.axelor.apps.project.db.Project) Map(java.util.Map)

Example 98 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class UserHrServiceImpl method getTimesheetProduct.

@Override
public Product getTimesheetProduct(User user) {
    if (user == null || user.getId() == null || user.getActiveCompany() == null) {
        return null;
    }
    user = userRepo.find(user.getId());
    Product product = null;
    HRConfig hrConfig = user.getActiveCompany().getHrConfig();
    if (hrConfig != null && hrConfig.getUseUniqueProductForTimesheet()) {
        product = hrConfig.getUniqueTimesheetProduct();
    }
    if (product == null && user.getEmployee() != null) {
        product = user.getEmployee().getProduct();
    }
    return product;
}
Also used : HRConfig(com.axelor.apps.hr.db.HRConfig) Product(com.axelor.apps.base.db.Product)

Example 99 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ReservedQtyServiceImpl method updateRequestedReservedQty.

@Override
@Transactional(rollbackOn = { Exception.class })
public void updateRequestedReservedQty(SaleOrderLine saleOrderLine, BigDecimal newReservedQty) throws AxelorException {
    if (saleOrderLine.getProduct() == null || !saleOrderLine.getProduct().getStockManaged()) {
        return;
    }
    StockMoveLine stockMoveLine = getPlannedStockMoveLine(saleOrderLine);
    if (stockMoveLine == null) {
        // only change requested quantity in sale order line
        saleOrderLine.setRequestedReservedQty(newReservedQty);
        return;
    }
    checkBeforeUpdatingQties(stockMoveLine, newReservedQty);
    if (Beans.get(AppSupplychainService.class).getAppSupplychain().getBlockDeallocationOnAvailabilityRequest()) {
        checkAvailabilityRequest(stockMoveLine, newReservedQty, true);
    }
    BigDecimal diffReservedQuantity = newReservedQty.subtract(saleOrderLine.getRequestedReservedQty());
    // update in stock move line and sale order line
    BigDecimal newAllocatedQty = updateRequestedReservedQuantityInStockMoveLines(saleOrderLine, stockMoveLine.getProduct(), newReservedQty);
    StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockMoveLine.getStockMove().getFromStockLocation(), stockMoveLine.getProduct());
    Product product = stockMoveLine.getProduct();
    // update in stock location line
    BigDecimal diffReservedQuantityLocation = convertUnitWithProduct(stockMoveLine.getUnit(), stockLocationLine.getUnit(), diffReservedQuantity, product);
    stockLocationLine.setRequestedReservedQty(stockLocationLine.getRequestedReservedQty().add(diffReservedQuantityLocation));
    // update reserved qty
    if (newAllocatedQty.compareTo(saleOrderLine.getReservedQty()) < 0) {
        updateReservedQty(saleOrderLine, newAllocatedQty);
    }
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 100 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ReservedQtyServiceImpl method updateReservedQty.

protected void updateReservedQty(StockLocationLine stockLocationLine, StockMoveLine stockMoveLine, BigDecimal newReservedQty) throws AxelorException {
    if (stockMoveLine.getProduct() == null || !stockMoveLine.getProduct().getStockManaged()) {
        return;
    }
    SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
    if (saleOrderLine != null) {
        updateReservedQty(saleOrderLine, newReservedQty);
    } else {
        checkBeforeUpdatingQties(stockMoveLine, newReservedQty);
        if (Beans.get(AppSupplychainService.class).getAppSupplychain().getBlockDeallocationOnAvailabilityRequest()) {
            checkAvailabilityRequest(stockMoveLine, newReservedQty, false);
        }
        if (stockMoveLine.getRequestedReservedQty().compareTo(newReservedQty) < 0 && newReservedQty.compareTo(BigDecimal.ZERO) > 0) {
            updateRequestedReservedQty(stockLocationLine, stockMoveLine, newReservedQty);
            requestQty(stockMoveLine);
        }
        BigDecimal availableQtyToBeReserved = stockLocationLine.getCurrentQty().subtract(stockLocationLine.getReservedQty());
        BigDecimal diffReservedQuantity = newReservedQty.subtract(stockMoveLine.getReservedQty());
        Product product = stockMoveLine.getProduct();
        BigDecimal diffReservedQuantityLocation = convertUnitWithProduct(stockMoveLine.getUnit(), stockLocationLine.getUnit(), diffReservedQuantity, product);
        if (availableQtyToBeReserved.compareTo(diffReservedQuantityLocation) < 0) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_QTY_NOT_AVAILABLE));
        }
        stockMoveLine.setReservedQty(newReservedQty);
        // update in stock location line
        updateReservedQty(stockLocationLine);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Product(com.axelor.apps.base.db.Product) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal)

Aggregations

Product (com.axelor.apps.base.db.Product)189 BigDecimal (java.math.BigDecimal)91 AxelorException (com.axelor.exception.AxelorException)70 Transactional (com.google.inject.persist.Transactional)45 ArrayList (java.util.ArrayList)38 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)33 Company (com.axelor.apps.base.db.Company)24 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)24 Unit (com.axelor.apps.base.db.Unit)23 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)23 HashMap (java.util.HashMap)20 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)19 StockLocation (com.axelor.apps.stock.db.StockLocation)19 List (java.util.List)19 ProdProduct (com.axelor.apps.production.db.ProdProduct)18 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)18 LocalDate (java.time.LocalDate)18 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)16 StockMove (com.axelor.apps.stock.db.StockMove)16 Map (java.util.Map)16