Search in sources :

Example 1 with MrpForecast

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();
    }
}
Also used : ArrayList(java.util.ArrayList) MrpLineType(com.axelor.apps.supplychain.db.MrpLineType) MrpForecast(com.axelor.apps.supplychain.db.MrpForecast)

Example 2 with MrpForecast

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);
}
Also used : MrpForecast(com.axelor.apps.supplychain.db.MrpForecast) Transactional(com.google.inject.persist.Transactional)

Example 3 with 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);
}
Also used : Unit(com.axelor.apps.base.db.Unit) MrpForecast(com.axelor.apps.supplychain.db.MrpForecast) Transactional(com.google.inject.persist.Transactional)

Example 4 with 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);
}
Also used : Context(com.axelor.rpc.Context) CurrencyRepository(com.axelor.apps.base.db.repo.CurrencyRepository) SortedSet(java.util.SortedSet) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Inject(com.google.inject.Inject) HashMap(java.util.HashMap) MrpForecastRepository(com.axelor.apps.supplychain.db.repo.MrpForecastRepository) Mapper(com.axelor.db.mapper.Mapper) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) MrpForecast(com.axelor.apps.supplychain.db.MrpForecast) Currency(com.axelor.apps.base.db.Currency) TreeSet(java.util.TreeSet) LinkedHashMap(java.util.LinkedHashMap) BigDecimal(java.math.BigDecimal) List(java.util.List) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) ActionRequest(com.axelor.rpc.ActionRequest) Comparator(java.util.Comparator) Context(com.axelor.rpc.Context) Singleton(com.google.inject.Singleton) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) TreeSet(java.util.TreeSet) Currency(com.axelor.apps.base.db.Currency) MrpForecast(com.axelor.apps.supplychain.db.MrpForecast) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with MrpForecast

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;
}
Also used : MrpForecast(com.axelor.apps.supplychain.db.MrpForecast)

Aggregations

MrpForecast (com.axelor.apps.supplychain.db.MrpForecast)5 Transactional (com.google.inject.persist.Transactional)2 Currency (com.axelor.apps.base.db.Currency)1 Product (com.axelor.apps.base.db.Product)1 Unit (com.axelor.apps.base.db.Unit)1 CurrencyRepository (com.axelor.apps.base.db.repo.CurrencyRepository)1 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 MrpLineType (com.axelor.apps.supplychain.db.MrpLineType)1 MrpForecastRepository (com.axelor.apps.supplychain.db.repo.MrpForecastRepository)1 Mapper (com.axelor.db.mapper.Mapper)1 Beans (com.axelor.inject.Beans)1 ActionRequest (com.axelor.rpc.ActionRequest)1 ActionResponse (com.axelor.rpc.ActionResponse)1 Context (com.axelor.rpc.Context)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1