Search in sources :

Example 1 with CostSheetLine

use of com.axelor.apps.production.db.CostSheetLine in project axelor-open-suite by axelor.

the class CostSheetLineServiceImpl method createCostSheetLine.

public CostSheetLine createCostSheetLine(String name, String code, int bomLevel, BigDecimal consumptionQty, BigDecimal costPrice, CostSheetGroup costSheetGroup, Product product, int typeSelect, int typeSelectIcon, Unit unit, WorkCenter workCenter, CostSheetLine parentCostSheetLine) {
    logger.debug("Add a new line of cost sheet ({} - {} - BOM level {} - cost price : {})", code, name, bomLevel, costPrice);
    CostSheetLine costSheetLine = new CostSheetLine(code, name);
    costSheetLine.setBomLevel(bomLevel);
    costSheetLine.setConsumptionQty(consumptionQty.setScale(appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_UP));
    costSheetLine.setCostSheetGroup(costSheetGroup);
    costSheetLine.setProduct(product);
    costSheetLine.setTypeSelect(typeSelect);
    costSheetLine.setTypeSelectIcon(typeSelectIcon);
    if (unit != null) {
        costSheetLine.setUnit(unitRepo.find(unit.getId()));
    }
    costSheetLine.setWorkCenter(workCenter);
    if (costPrice == null) {
        costPrice = BigDecimal.ZERO;
    }
    costSheetLine.setCostPrice(costPrice.setScale(appProductionService.getNbDecimalDigitForUnitPrice(), BigDecimal.ROUND_HALF_UP));
    if (parentCostSheetLine != null) {
        parentCostSheetLine.addCostSheetLineListItem(costSheetLine);
        this.createIndirectCostSheetGroups(costSheetGroup, parentCostSheetLine, costSheetLine.getCostPrice());
    }
    return costSheetLine;
}
Also used : CostSheetLine(com.axelor.apps.production.db.CostSheetLine)

Example 2 with CostSheetLine

use of com.axelor.apps.production.db.CostSheetLine in project axelor-open-suite by axelor.

the class CostSheetLineServiceImpl method createConsumedProductCostSheetLine.

public CostSheetLine createConsumedProductCostSheetLine(Company company, Product product, Unit unit, int bomLevel, CostSheetLine parentCostSheetLine, BigDecimal consumptionQty, int origin, UnitCostCalculation unitCostCalculation) throws AxelorException {
    Product parentProduct = parentCostSheetLine.getProduct();
    BigDecimal costPrice = null;
    switch(origin) {
        case CostSheetService.ORIGIN_MANUF_ORDER:
            costPrice = this.getComponentCostPrice(product, parentProduct.getManufOrderCompValuMethodSelect(), company);
            break;
        case CostSheetService.ORIGIN_BULK_UNIT_COST_CALCULATION:
            BillOfMaterial componentDefaultBillOfMaterial = product.getDefaultBillOfMaterial();
            if (componentDefaultBillOfMaterial != null) {
                UnitCostCalcLine unitCostCalcLine = unitCostCalcLineServiceImpl.getUnitCostCalcLine(unitCostCalculation, product);
                if (unitCostCalcLine != null) {
                    costPrice = unitCostCalcLine.getComputedCost();
                    break;
                }
            }
            costPrice = this.getComponentCostPrice(product, parentProduct.getBomCompValuMethodSelect(), company);
            break;
        // from its bill of materials
        case CostSheetService.ORIGIN_BILL_OF_MATERIAL:
            costPrice = this.getComponentCostPrice(product, parentProduct.getBomCompValuMethodSelect(), company);
            break;
        default:
            costPrice = BigDecimal.ZERO;
    }
    consumptionQty = consumptionQty.setScale(appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_UP);
    costPrice = costPrice.multiply(consumptionQty);
    costPrice = unitConversionService.convert(unit, product.getUnit(), costPrice, appProductionService.getNbDecimalDigitForUnitPrice(), product);
    List<CostSheetLine> costSheetLineList = parentCostSheetLine.getCostSheetLineList() != null ? parentCostSheetLine.getCostSheetLineList() : new ArrayList<CostSheetLine>();
    for (CostSheetLine costSheetLine : costSheetLineList) {
        if (product.equals(costSheetLine.getProduct()) && unit.equals(costSheetLine.getUnit())) {
            BigDecimal qty = costSheetLine.getConsumptionQty().add(consumptionQty);
            costSheetLine.setConsumptionQty(qty);
            costSheetLine.setCostPrice(costPrice.add(costSheetLine.getCostPrice()).setScale(appProductionService.getNbDecimalDigitForUnitPrice(), BigDecimal.ROUND_HALF_UP));
            return costSheetLine;
        }
    }
    return this.createCostSheetLine(product.getName(), product.getCode(), bomLevel, consumptionQty, costPrice, product.getCostSheetGroup(), product, CostSheetLineRepository.TYPE_CONSUMED_PRODUCT, CostSheetLineRepository.TYPE_CONSUMED_PRODUCT, unit, null, parentCostSheetLine);
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) CostSheetLine(com.axelor.apps.production.db.CostSheetLine) UnitCostCalcLine(com.axelor.apps.production.db.UnitCostCalcLine) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal)

Example 3 with CostSheetLine

use of com.axelor.apps.production.db.CostSheetLine in project axelor-open-suite by axelor.

the class CostSheetServiceImpl method computeCostPrice.

@Override
@Transactional(rollbackOn = { Exception.class })
public CostSheet computeCostPrice(ManufOrder manufOrder, int calculationTypeSelect, LocalDate calculationDate) throws AxelorException {
    this.init();
    List<CostSheet> costSheetList = manufOrder.getCostSheetList();
    LocalDate previousCostSheetDate = null;
    for (CostSheet costSheet : costSheetList) {
        if ((costSheet.getCalculationTypeSelect() == CostSheetRepository.CALCULATION_END_OF_PRODUCTION || costSheet.getCalculationTypeSelect() == CostSheetRepository.CALCULATION_PARTIAL_END_OF_PRODUCTION) && costSheet.getCalculationDate() != null) {
            if (previousCostSheetDate == null) {
                previousCostSheetDate = costSheet.getCalculationDate();
            } else if (costSheet.getCalculationDate().isAfter(previousCostSheetDate)) {
                previousCostSheetDate = costSheet.getCalculationDate();
            }
        }
    }
    manufOrder.addCostSheetListItem(costSheet);
    costSheet.setCalculationTypeSelect(calculationTypeSelect);
    costSheet.setCalculationDate(calculationDate != null ? calculationDate : Beans.get(AppBaseService.class).getTodayDate(manufOrder.getCompany()));
    BigDecimal producedQty = computeTotalProducedQty(manufOrder.getProduct(), manufOrder.getProducedStockMoveLineList(), costSheet.getCalculationDate(), previousCostSheetDate, costSheet.getCalculationTypeSelect());
    CostSheetLine producedCostSheetLine = costSheetLineService.createProducedProductCostSheetLine(manufOrder.getProduct(), manufOrder.getUnit(), producedQty);
    costSheet.addCostSheetLineListItem(producedCostSheetLine);
    Company company = manufOrder.getCompany();
    if (company != null && company.getCurrency() != null) {
        costSheet.setCurrency(company.getCurrency());
    }
    BigDecimal totalToProduceQty = getTotalToProduceQty(manufOrder);
    BigDecimal ratio = BigDecimal.ZERO;
    if (totalToProduceQty.compareTo(BigDecimal.ZERO) != 0) {
        ratio = producedQty.divide(totalToProduceQty, 5, RoundingMode.HALF_UP);
    }
    costSheet.setManufOrderProducedRatio(ratio);
    this.computeRealCostPrice(manufOrder, 0, producedCostSheetLine, previousCostSheetDate);
    this.computeRealResidualProduct(manufOrder);
    this.computeCostPrice(costSheet);
    manufOrder.setCostPrice(costSheet.getCostPrice());
    Beans.get(ManufOrderRepository.class).save(manufOrder);
    return costSheet;
}
Also used : CostSheetLine(com.axelor.apps.production.db.CostSheetLine) Company(com.axelor.apps.base.db.Company) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) LocalDate(java.time.LocalDate) CostSheet(com.axelor.apps.production.db.CostSheet) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 4 with CostSheetLine

use of com.axelor.apps.production.db.CostSheetLine in project axelor-open-suite by axelor.

the class CostSheetServiceImpl method computeCostPrice.

protected BigDecimal computeCostPrice(CostSheet costSheet) {
    BigDecimal costPrice = BigDecimal.ZERO;
    if (costSheet.getCostSheetLineList() != null) {
        for (CostSheetLine costSheetLine : costSheet.getCostSheetLineList()) {
            if (costSheetLine.getCostSheetLineList() != null && !costSheetLine.getCostSheetLineList().isEmpty()) {
                costPrice = costPrice.add(this.computeCostPrice(costSheetLine));
            } else {
                costPrice = costPrice.add(costSheetLine.getCostPrice());
            }
        }
    }
    costSheet.setCostPrice(costPrice);
    return costPrice;
}
Also used : CostSheetLine(com.axelor.apps.production.db.CostSheetLine) BigDecimal(java.math.BigDecimal)

Example 5 with CostSheetLine

use of com.axelor.apps.production.db.CostSheetLine in project axelor-open-suite by axelor.

the class CostSheetServiceImpl method computeCostPrice.

@Override
@Transactional(rollbackOn = { Exception.class })
public CostSheet computeCostPrice(BillOfMaterial billOfMaterial, int origin, UnitCostCalculation unitCostCalculation) throws AxelorException {
    this.init();
    billOfMaterial.addCostSheetListItem(costSheet);
    CostSheetLine producedCostSheetLine = costSheetLineService.createProducedProductCostSheetLine(billOfMaterial.getProduct(), billOfMaterial.getUnit(), billOfMaterial.getQty());
    costSheet.addCostSheetLineListItem(producedCostSheetLine);
    costSheet.setCalculationTypeSelect(CostSheetRepository.CALCULATION_BILL_OF_MATERIAL);
    costSheet.setCalculationDate(Beans.get(AppBaseService.class).getTodayDate(billOfMaterial.getCompany()));
    Company company = billOfMaterial.getCompany();
    if (company != null && company.getCurrency() != null) {
        costSheet.setCurrency(company.getCurrency());
    }
    this._computeCostPrice(billOfMaterial.getCompany(), billOfMaterial, 0, producedCostSheetLine, origin, unitCostCalculation);
    this.computeResidualProduct(billOfMaterial);
    billOfMaterial.setCostPrice(this.computeCostPrice(costSheet));
    billOfMaterialRepo.save(billOfMaterial);
    return costSheet;
}
Also used : CostSheetLine(com.axelor.apps.production.db.CostSheetLine) Company(com.axelor.apps.base.db.Company) Transactional(com.google.inject.persist.Transactional)

Aggregations

CostSheetLine (com.axelor.apps.production.db.CostSheetLine)10 BigDecimal (java.math.BigDecimal)5 Company (com.axelor.apps.base.db.Company)2 Product (com.axelor.apps.base.db.Product)2 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)2 ProdResidualProduct (com.axelor.apps.production.db.ProdResidualProduct)2 Transactional (com.google.inject.persist.Transactional)2 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 CostSheet (com.axelor.apps.production.db.CostSheet)1 ProdProduct (com.axelor.apps.production.db.ProdProduct)1 UnitCostCalcLine (com.axelor.apps.production.db.UnitCostCalcLine)1 ManufOrderRepository (com.axelor.apps.production.db.repo.ManufOrderRepository)1 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)1 LocalDate (java.time.LocalDate)1