use of com.axelor.apps.production.db.UnitCostCalcLine in project axelor-open-suite by axelor.
the class UnitCostCalculationServiceImpl method calculationProductProcess.
@Transactional(rollbackOn = { Exception.class })
protected void calculationProductProcess(UnitCostCalculation unitCostCalculation, Product product) throws AxelorException {
int level = this.productMap.get(product.getId()).intValue();
log.debug("Unit cost price calculation for product : {}, level : {}", product.getCode(), level);
int origin = unitCostCalculation.getAllBomLevels() ? CostSheetService.ORIGIN_BULK_UNIT_COST_CALCULATION : CostSheetService.ORIGIN_BILL_OF_MATERIAL;
BillOfMaterial billOfMaterial = product.getDefaultBillOfMaterial();
CostSheet costSheet = costSheetService.computeCostPrice(billOfMaterial, origin, unitCostCalculation);
UnitCostCalcLine unitCostCalcLine = unitCostCalcLineService.createUnitCostCalcLine(product, billOfMaterial.getCompany(), level, costSheet);
unitCostCalculation.addUnitCostCalcLineListItem(unitCostCalcLine);
unitCostCalculationRepository.save(unitCostCalculation);
}
use of com.axelor.apps.production.db.UnitCostCalcLine in project axelor-open-suite by axelor.
the class CostSheetLineServiceImpl method createConsumedProductWasteCostSheetLine.
public CostSheetLine createConsumedProductWasteCostSheetLine(Company company, Product product, Unit unit, int bomLevel, CostSheetLine parentCostSheetLine, BigDecimal consumptionQty, BigDecimal wasteRate, int origin, UnitCostCalculation unitCostCalculation) throws AxelorException {
Product parentProduct = parentCostSheetLine.getProduct();
BigDecimal qty = consumptionQty.multiply(wasteRate).divide(new BigDecimal("100"), appBaseService.getNbDecimalDigitForQty(), BigDecimal.ROUND_HALF_UP);
BigDecimal costPrice = null;
switch(origin) {
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;
case CostSheetService.ORIGIN_BILL_OF_MATERIAL:
costPrice = this.getComponentCostPrice(product, parentProduct.getBomCompValuMethodSelect(), company);
break;
default:
costPrice = BigDecimal.ZERO;
}
costPrice = unitConversionService.convert(unit, product.getUnit(), costPrice, appProductionService.getNbDecimalDigitForUnitPrice(), product).multiply(qty);
return this.createCostSheetLine(product.getName(), product.getCode(), bomLevel, qty, costPrice.setScale(appProductionService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP), product.getCostSheetGroup(), product, CostSheetLineRepository.TYPE_CONSUMED_PRODUCT_WASTE, CostSheetLineRepository.TYPE_CONSUMED_PRODUCT_WASTE, unit, null, parentCostSheetLine);
}
use of com.axelor.apps.production.db.UnitCostCalcLine 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.UnitCostCalcLine in project axelor-open-suite by axelor.
the class UnitCostCalcLineServiceImpl method createUnitCostCalcLine.
public UnitCostCalcLine createUnitCostCalcLine(Product product, Company company, int maxLevel, CostSheet costSheet) throws AxelorException {
UnitCostCalcLine unitCostCalcLine = new UnitCostCalcLine();
unitCostCalcLine.setProduct(product);
unitCostCalcLine.setCompany(company);
unitCostCalcLine.setPreviousCost((BigDecimal) productCompanyService.get(product, "costPrice", company));
unitCostCalcLine.setCostSheet(costSheet);
unitCostCalcLine.setComputedCost(costSheet.getCostPrice());
unitCostCalcLine.setCostToApply(costSheet.getCostPrice());
unitCostCalcLine.setMaxLevel(maxLevel);
return unitCostCalcLine;
}
use of com.axelor.apps.production.db.UnitCostCalcLine in project axelor-open-suite by axelor.
the class UnitCostCalculationServiceImpl method exportUnitCostCalc.
@Override
public MetaFile exportUnitCostCalc(UnitCostCalculation unitCostCalculation, String fileName) throws IOException {
List<String[]> list = new ArrayList<>();
List<UnitCostCalcLine> unitCostCalcLineList = unitCostCalculation.getUnitCostCalcLineList();
Collections.sort(unitCostCalcLineList, new Comparator<UnitCostCalcLine>() {
@Override
public int compare(UnitCostCalcLine unitCostCalcLine1, UnitCostCalcLine unitCostCalcLine2) {
return unitCostCalcLine1.getProduct().getCode().compareTo(unitCostCalcLine2.getProduct().getCode());
}
});
for (UnitCostCalcLine unitCostCalcLine : unitCostCalcLineList) {
String[] item = new String[4];
item[0] = unitCostCalcLine.getProduct() == null ? "" : unitCostCalcLine.getProduct().getCode();
item[1] = unitCostCalcLine.getProduct() == null ? "" : unitCostCalcLine.getProduct().getName();
item[2] = unitCostCalcLine.getComputedCost().toString();
item[3] = unitCostCalcLine.getCostToApply().toString();
list.add(item);
}
File file = MetaFiles.createTempFile(fileName, ".csv").toFile();
log.debug("File located at: {}", file.getPath());
String[] headers = { I18n.get("Product_code"), I18n.get("Product_name"), I18n.get("Product_currency"), I18n.get("Computed_cost"), I18n.get("Cost_to_apply") };
CsvTool.csvWriter(file.getParent(), file.getName(), ';', '"', headers, list);
try (InputStream is = new FileInputStream(file)) {
DMSFile dmsFile = Beans.get(MetaFiles.class).attach(is, file.getName(), unitCostCalculation);
return dmsFile.getMetaFile();
}
}
Aggregations