Search in sources :

Example 1 with ABCAnalysisLine

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

the class ABCAnalysisServiceStockImpl method createABCAnalysisLine.

@Override
protected Optional<ABCAnalysisLine> createABCAnalysisLine(ABCAnalysis abcAnalysis, Product product) throws AxelorException {
    ABCAnalysisLine abcAnalysisLine = null;
    List<StockLocation> stockLocationList = stockLocationService.getAllLocationAndSubLocation(abcAnalysis.getStockLocation(), false);
    BigDecimal productQty = BigDecimal.ZERO;
    BigDecimal productWorth = BigDecimal.ZERO;
    List<StockLocationLine> stockLocationLineList;
    int offset = 0;
    Query<StockLocationLine> stockLocationLineQuery = stockLocationLineRepository.all().filter("self.stockLocation IN :stockLocationList AND self.product.id = :productId AND self.currentQty != 0 ").bind("stockLocationList", stockLocationList).bind("productId", product.getId());
    while (!(stockLocationLineList = stockLocationLineQuery.fetch(FETCH_LIMIT, offset)).isEmpty()) {
        offset += stockLocationLineList.size();
        abcAnalysis = abcAnalysisRepository.find(abcAnalysis.getId());
        if (abcAnalysisLine == null) {
            abcAnalysisLine = super.createABCAnalysisLine(abcAnalysis, product).get();
        }
        for (StockLocationLine stockLocationLine : stockLocationLineList) {
            BigDecimal convertedQty = unitConversionService.convert(stockLocationLine.getUnit(), product.getUnit(), stockLocationLine.getCurrentQty(), 5, product);
            productQty = productQty.add(convertedQty);
            productWorth = productWorth.add(stockLocationLine.getAvgPrice());
        }
        super.incTotalQty(productQty);
        super.incTotalWorth(productWorth);
        JPA.clear();
    }
    if (abcAnalysisLine != null) {
        setQtyWorth(abcAnalysisLineRepository.find(abcAnalysisLine.getId()), productQty, productWorth);
    }
    return Optional.ofNullable(abcAnalysisLine);
}
Also used : ABCAnalysisLine(com.axelor.apps.base.db.ABCAnalysisLine) StockLocation(com.axelor.apps.stock.db.StockLocation) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal)

Example 2 with ABCAnalysisLine

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

the class ABCAnalysisServiceImpl method createABCAnalysisLine.

@Transactional(rollbackOn = { Exception.class })
protected Optional<ABCAnalysisLine> createABCAnalysisLine(ABCAnalysis abcAnalysis, Product product) throws AxelorException {
    ABCAnalysisLine abcAnalysisLine = new ABCAnalysisLine();
    abcAnalysisLine.setAbcAnalysis(abcAnalysis);
    abcAnalysisLine.setProduct(product);
    abcAnalysisLineRepository.save(abcAnalysisLine);
    return Optional.of(abcAnalysisLine);
}
Also used : ABCAnalysisLine(com.axelor.apps.base.db.ABCAnalysisLine) Transactional(com.google.inject.persist.Transactional)

Example 3 with ABCAnalysisLine

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

the class ABCAnalysisServiceSaleImpl method createABCAnalysisLine.

@Override
protected Optional<ABCAnalysisLine> createABCAnalysisLine(ABCAnalysis abcAnalysis, Product product) throws AxelorException {
    ABCAnalysisLine abcAnalysisLine = null;
    BigDecimal productQty = BigDecimal.ZERO;
    BigDecimal productWorth = BigDecimal.ZERO;
    List<SaleOrderLine> saleOrderLineList;
    int offset = 0;
    Query<SaleOrderLine> saleOrderLineQuery = saleOrderLineRepository.all().filter("(self.saleOrder.statusSelect = :statusConfirmed OR self.saleOrder.statusSelect = :statusCompleted) AND self.saleOrder.confirmationDateTime >= :startDate AND self.saleOrder.confirmationDateTime <= :endDate AND self.product.id = :productId").bind("statusConfirmed", SaleOrderRepository.STATUS_ORDER_CONFIRMED).bind("statusCompleted", SaleOrderRepository.STATUS_ORDER_COMPLETED).bind("startDate", toLocalDateT(toDate(abcAnalysis.getStartDate()))).bind("endDate", toLocalDateT(toDate(abcAnalysis.getEndDate())).withHour(23).withMinute(59).withSecond(59)).bind("productId", product.getId()).order("id");
    while (!(saleOrderLineList = saleOrderLineQuery.fetch(FETCH_LIMIT, offset)).isEmpty()) {
        offset += saleOrderLineList.size();
        abcAnalysis = abcAnalysisRepository.find(abcAnalysis.getId());
        if (abcAnalysisLine == null) {
            abcAnalysisLine = super.createABCAnalysisLine(abcAnalysis, product).get();
        }
        for (SaleOrderLine saleOrderLine : saleOrderLineList) {
            BigDecimal convertedQty = unitConversionService.convert(saleOrderLine.getUnit(), product.getUnit(), saleOrderLine.getQty(), 5, product);
            productQty = productQty.add(convertedQty);
            productWorth = productWorth.add(saleOrderLine.getCompanyExTaxTotal());
        }
        super.incTotalQty(productQty);
        super.incTotalWorth(productWorth);
        JPA.clear();
    }
    if (abcAnalysisLine != null) {
        setQtyWorth(abcAnalysisLineRepository.find(abcAnalysisLine.getId()), productQty, productWorth);
    }
    return Optional.ofNullable(abcAnalysisLine);
}
Also used : ABCAnalysisLine(com.axelor.apps.base.db.ABCAnalysisLine) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal)

Example 4 with ABCAnalysisLine

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

the class ABCAnalysisServicePurchaseImpl method createABCAnalysisLine.

@Override
protected Optional<ABCAnalysisLine> createABCAnalysisLine(ABCAnalysis abcAnalysis, Product product) throws AxelorException {
    ABCAnalysisLine abcAnalysisLine = null;
    BigDecimal productQty = BigDecimal.ZERO;
    BigDecimal productWorth = BigDecimal.ZERO;
    List<PurchaseOrderLine> purchaseOrderLineList;
    int offset = 0;
    Query<PurchaseOrderLine> purchaseOrderLineQuery = purchaseOrderLineRepository.all().filter("(self.purchaseOrder.statusSelect = :statusValidated OR self.purchaseOrder.statusSelect = :statusFinished) AND self.purchaseOrder.validationDate >= :startDate AND self.purchaseOrder.validationDate <= :endDate AND self.product.id = :productId").bind("statusValidated", PurchaseOrderRepository.STATUS_VALIDATED).bind("statusFinished", PurchaseOrderRepository.STATUS_FINISHED).bind("startDate", abcAnalysis.getStartDate()).bind("endDate", abcAnalysis.getEndDate()).bind("productId", product.getId()).order("id");
    while (!(purchaseOrderLineList = purchaseOrderLineQuery.fetch(FETCH_LIMIT, offset)).isEmpty()) {
        offset += purchaseOrderLineList.size();
        abcAnalysis = abcAnalysisRepository.find(abcAnalysis.getId());
        if (abcAnalysisLine == null) {
            abcAnalysisLine = super.createABCAnalysisLine(abcAnalysis, product).get();
        }
        for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
            BigDecimal convertedQty = unitConversionService.convert(purchaseOrderLine.getUnit(), product.getUnit(), purchaseOrderLine.getQty(), 2, product);
            productQty = productQty.add(convertedQty);
            productWorth = productWorth.add(purchaseOrderLine.getCompanyExTaxTotal());
        }
        super.incTotalQty(productQty);
        super.incTotalWorth(productWorth);
        JPA.clear();
    }
    if (abcAnalysisLine != null) {
        setQtyWorth(abcAnalysisLineRepository.find(abcAnalysisLine.getId()), productQty, productWorth);
    }
    return Optional.ofNullable(abcAnalysisLine);
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) ABCAnalysisLine(com.axelor.apps.base.db.ABCAnalysisLine) BigDecimal(java.math.BigDecimal)

Aggregations

ABCAnalysisLine (com.axelor.apps.base.db.ABCAnalysisLine)4 BigDecimal (java.math.BigDecimal)3 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)1 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)1 StockLocation (com.axelor.apps.stock.db.StockLocation)1 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)1 Transactional (com.google.inject.persist.Transactional)1