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