use of com.axelor.apps.supplychain.db.MrpForecast in project axelor-open-suite by axelor.
the class MrpServiceImpl method createSaleForecastMrpLines.
protected void createSaleForecastMrpLines() throws AxelorException {
MrpLineType saleForecastMrpLineType = this.getMrpLineType(MrpLineTypeRepository.ELEMENT_SALE_FORECAST);
if (saleForecastMrpLineType == null) {
return;
}
List<MrpForecast> mrpForecastList = new ArrayList<>();
mrp = mrpRepository.find(mrp.getId());
if (mrp.getMrpForecastSet().isEmpty()) {
mrpForecastList.addAll(mrpForecastRepository.all().filter("self.product.id in (?1) AND self.stockLocation in (?2) AND self.forecastDate >= ?3 AND self.statusSelect = ?4", this.productMap.keySet(), this.stockLocationList, today, MrpForecastRepository.STATUS_CONFIRMED).fetch());
} else {
mrpForecastList.addAll(mrp.getMrpForecastSet());
}
for (MrpForecast mrpForecast : mrpForecastList) {
this.createSaleForecastMrpLines(mrpRepository.find(mrp.getId()), mrpForecastRepository.find(mrpForecast.getId()), mrpLineTypeRepository.find(saleForecastMrpLineType.getId()));
JPA.clear();
}
}
use of com.axelor.apps.supplychain.db.MrpForecast in project axelor-open-suite by axelor.
the class MrpForecastProductionServiceImpl method RemoveMrpForecast.
@Transactional
public void RemoveMrpForecast(Long id) {
MrpForecast mrpForecast = id != null ? mrpForecastRepo.find(id) : new MrpForecast();
mrpForecastRepo.remove(mrpForecast);
}
use of com.axelor.apps.supplychain.db.MrpForecast in project axelor-open-suite by axelor.
the class MrpForecastProductionServiceImpl method createMrpForecast.
@Transactional
public void createMrpForecast(Long id, LocalDate forecastDate, Product product, StockLocation stockLocation, BigDecimal qty, int technicalOrigin) {
Unit unit = product.getSalesUnit() != null ? product.getSalesUnit() : product.getUnit();
MrpForecast mrpForecast = id != null ? mrpForecastRepo.find(id) : new MrpForecast();
if (id != null && mrpForecast.getForecastDate().equals(forecastDate) && mrpForecast.getStockLocation().equals(stockLocation) && mrpForecast.getQty().compareTo(qty) == 0 && mrpForecast.getUnit().equals(unit)) {
return;
}
mrpForecast.setForecastDate(forecastDate);
mrpForecast.setProduct(product);
mrpForecast.setStockLocation(stockLocation);
mrpForecast.setQty(qty);
mrpForecast.setTechnicalOrigin(technicalOrigin);
mrpForecast.setUnit(unit);
mrpForecast.setStatusSelect(MrpForecastRepository.STATUS_DRAFT);
mrpForecastRepo.save(mrpForecast);
}
use of com.axelor.apps.supplychain.db.MrpForecast in project axelor-open-suite by axelor.
the class SopLineController method fillMrpForecast.
public void fillMrpForecast(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> productCategoryMap = (LinkedHashMap<String, Object>) context.get("_productCategory");
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> sopLineMap = (LinkedHashMap<String, Object>) context.get("_sopLine");
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> currencyMap = (LinkedHashMap<String, Object>) sopLineMap.get("currency");
BigDecimal sopSalesForecast = new BigDecimal(sopLineMap.get("sopSalesForecast").toString());
Long productCategoryId = Long.parseLong(productCategoryMap.get("id").toString());
Currency currency = currencyRepo.find(Long.parseLong(currencyMap.get("id").toString()));
BigDecimal totalForecast = BigDecimal.ZERO;
SortedSet<Map<String, Object>> mrpForecastSet = new TreeSet<Map<String, Object>>(Comparator.comparing(m -> (String) m.get("code")));
List<Product> productList = Beans.get(ProductRepository.class).all().filter("self.productCategory.id = ?1 ", productCategoryId).fetch();
if (productList != null) {
for (Product product : productList) {
Map<String, Object> map = new HashMap<String, Object>();
MrpForecast mrpForecast = mrpForecastRepo.all().filter("self.product.id = ?1 AND self.technicalOrigin = ?2", product.getId(), MrpForecastRepository.TECHNICAL_ORIGIN_CREATED_FROM_SOP).fetchOne();
if (mrpForecast != null) {
map = Mapper.toMap(mrpForecast);
BigDecimal totalPrice = mrpForecast.getQty().multiply(product.getSalePrice());
map.put("$totalPrice", totalPrice);
map.put("$unitPrice", product.getSalePrice());
map.put("code", product.getCode());
totalForecast = totalForecast.add(totalPrice);
mrpForecastSet.add(map);
continue;
}
map.put("product", product);
map.put("qty", BigDecimal.ZERO);
map.put("$totalPrice", BigDecimal.ZERO);
map.put("$unitPrice", product.getSalePrice());
map.put("code", product.getCode());
mrpForecastSet.add(map);
}
}
response.setValue("$mrpForecasts", mrpForecastSet);
response.setValue("$sopSalesForecast", sopSalesForecast);
response.setValue("$totalForecast", totalForecast);
response.setValue("$difference", sopSalesForecast.subtract(totalForecast).setScale(Beans.get(AppBaseService.class).getNbDecimalDigitForUnitPrice()));
response.setValue("$currency", currency);
}
use of com.axelor.apps.supplychain.db.MrpForecast in project axelor-open-suite by axelor.
the class MrpForecastManagementRepository method copy.
@Override
public MrpForecast copy(MrpForecast entity, boolean deep) {
MrpForecast copy = super.copy(entity, deep);
copy.setStatusSelect(MrpForecastRepository.STATUS_DRAFT);
return copy;
}
Aggregations