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