@Override public ICalculate appendAdditionalDirectCosts() { realProductionCost.value = realProductionCost.value.add(BigDecimalUtils.convertNullToZero(realProductionCost.order .getDecimalField("directAdditionalCost"))); return this; } }
public BigDecimal getLaborCostMargin(final BigDecimal laborCost, final BigDecimal margin) { return laborCost.multiply(BigDecimalUtils.convertNullToZero(margin).divide(new BigDecimal(100l)), numberService.getMathContext()); }
public BigDecimal getMaterialCostMargin(final BigDecimal materialCost, final BigDecimal margin) { return materialCost.multiply(BigDecimalUtils.convertNullToZero(margin).divide(new BigDecimal(100l)), numberService.getMathContext()); }
public static String amountAndRest(Entity position) { BigDecimal amount = position.getDecimalField(PositionFields.QUANTITY); amount = amount.setScale(0, RoundingMode.DOWN); BigDecimal wholeAmount = amount.multiply(convertNullToZero(position.getDecimalField(PositionFields.CONVERSION))); BigDecimal rest = convertNullToZero(position.getDecimalField(PositionFields.GIVEN_QUANTITY)).subtract(wholeAmount); rest = rest.setScale(5, RoundingMode.HALF_UP); return amount.stripTrailingZeros().toPlainString() + "\n" + rest.stripTrailingZeros().toPlainString(); }
public static BigDecimal restDecimal(Entity position) { BigDecimal amount = position.getDecimalField(PositionFields.QUANTITY); amount = amount.setScale(0, RoundingMode.DOWN); BigDecimal wholeAmount = amount.multiply(convertNullToZero(position.getDecimalField(PositionFields.CONVERSION))); BigDecimal rest = convertNullToZero(position.getDecimalField(PositionFields.GIVEN_QUANTITY)).subtract(wholeAmount); return rest.setScale(5, RoundingMode.HALF_UP); }
public Set<String> fillRowStyles(final Entity warehouseStocks) { final Set<String> rowStyles = Sets.newHashSet(); if (warehouseStocks.getDecimalField("minimumState") != null && BigDecimal.ZERO.compareTo(BigDecimalUtils.convertNullToZero(warehouseStocks.getDecimalField("minimumState"))) != 0) { if (BigDecimalUtils.convertNullToZero(warehouseStocks.getDecimalField("minimumState")).compareTo( BigDecimalUtils.convertNullToZero(warehouseStocks.getDecimalField("quantity"))) == 1) { rowStyles.add(RowStyle.RED_BACKGROUND); } } return rowStyles; }
public Set<String> fillRowStyles(final Entity issue) { final Set<String> rowStyles = Sets.newHashSet(); if (issue.getDecimalField(IssueFields.ISSUE_QUANTITY) != null) { if (BigDecimalUtils.convertNullToZero(issue.getDecimalField(IssueFields.ISSUE_QUANTITY)) .compareTo(BigDecimal.ZERO) == 0) { rowStyles.add(RowStyle.RED_BACKGROUND); } } return rowStyles; }
@Override public BigDecimal calculateProductionCost(final Entity entity) { BigDecimal totalMachine = BigDecimalUtils.convertNullToZero(entity .getDecimalField(CostCalculationFields.TOTAL_MACHINE_HOURLY_COSTS)); BigDecimal totalLabor = BigDecimalUtils.convertNullToZero(entity .getDecimalField(CostCalculationFields.TOTAL_LABOR_HOURLY_COSTS)); return totalMachine.add(totalLabor, numberService.getMathContext()); }
@Override public BigDecimal getNeededQuantity(final Entity coverageProduct) { BigDecimal reservceMissingQuantity = BigDecimalUtils.convertNullToZero(coverageProduct .getDecimalField(CoverageProductFields.RESERVE_MISSING_QUANTITY)); BigDecimal negotiatiedQuantity = BigDecimalUtils.convertNullToZero(coverageProduct .getDecimalField(CoverageProductFieldsNFOS.NEGOTIATED_QUANTITY)); return reservceMissingQuantity.abs(numberService.getMathContext()).subtract(negotiatiedQuantity, numberService.getMathContext()); }
public void setRemainingQuantity(final Entity order) { BigDecimal remainingAmountOfProductToProduce = BigDecimalUtils.convertNullToZero( order.getDecimalField(OrderFields.PLANNED_QUANTITY)).subtract( BigDecimalUtils.convertNullToZero(order.getDecimalField(OrderFields.AMOUNT_OF_PRODUCT_PRODUCED)), numberService.getMathContext()); order.setField(OrderFields.REMAINING_AMOUNT_OF_PRODUCT_TO_PRODUCE, remainingAmountOfProductToProduce); }
private BigDecimal calculateQuantityForReservation(Entity productToIssue) { BigDecimal demandQuantity = productToIssue.getDecimalField(ProductsToIssueFields.DEMAND_QUANTITY); BigDecimal correctionQuantity = BigDecimalUtils.convertNullToZero(productToIssue .getDecimalField(ProductsToIssueFields.CORRECTION)); BigDecimal newQuantityForReservation = demandQuantity.subtract(calculateIssuedQuantityForProduct(productToIssue)) .subtract(correctionQuantity); if (newQuantityForReservation.compareTo(BigDecimal.ZERO) < 0) { newQuantityForReservation = BigDecimal.ZERO; } return newQuantityForReservation; }
@Override public void calculateSellPrice(final Entity entity) { final BigDecimal totalCostPerUnit = BigDecimalUtils.convertNullToZero(entity .getDecimalField(CostCalculationFields.TOTAL_COST_PER_UNIT)); final BigDecimal registrationPriceOverheadValue = BigDecimalUtils.convertNullToZero(entity .getDecimalField(CostCalculationFields.REGISTRATION_PRICE_OVERHEAD_VALUE)); final BigDecimal profitValue = BigDecimalUtils.convertNullToZero(entity .getDecimalField(CostCalculationFields.PROFIT_VALUE)); final BigDecimal sellPriceValue = totalCostPerUnit.add(registrationPriceOverheadValue, numberService.getMathContext()) .add(profitValue, numberService.getMathContext()); entity.setField(CostCalculationFields.SELL_PRICE_VALUE, numberService.setScaleWithDefaultMathContext(sellPriceValue, 2)); } }
private BigDecimal extractSumValueFromResultEntity(final Entity dynamicEntity) { BigDecimal sum = dynamicEntity.getDecimalField(L_SUM_RESULT); return numberService.setScaleWithDefaultMathContext(BigDecimalUtils.convertNullToZero(sum)); }
private boolean checkIfCanIssueQuantityForOrder(final Entity issue) { Entity wi = issue.getBelongsToField(IssueFields.WAREHOUSE_ISSUE); Entity product = issue.getBelongsToField(IssueFields.PRODUCT); BigDecimal alreadyIssued = BigDecimal.ZERO; alreadyIssued = warehouseIssueService.getIssuedQuantityForProductAndOrder(wi, product); BigDecimal toIssue = BigDecimalUtils.convertNullToZero(issue.getDecimalField(IssueFields.ISSUE_QUANTITY)); BigDecimal summaryIssue = alreadyIssued.add(toIssue, numberService.getMathContext()); if (summaryIssue.compareTo(BigDecimalUtils.convertNullToZero(issue.getDecimalField(IssueFields.DEMAND_QUANTITY))) == 1) { return false; } return true; } }
private void updateProductToIssueManual(Entity issue) { Optional<Entity> optionalValue = findProductForIssue(issue); if (optionalValue.isPresent()) { Entity value = optionalValue.get(); BigDecimal issueQuantity = value.getDecimalField(ProductsToIssueFields.ISSUE_QUANTITY); issueQuantity = BigDecimalUtils.convertNullToZero(issueQuantity).add( issue.getDecimalField(IssueFields.ISSUE_QUANTITY), numberService.getMathContext()); value.setField(ProductsToIssueFields.ISSUE_QUANTITY, issueQuantity); value.getDataDefinition().save(value); } }
private BigDecimal getPlannedQuantityForOrder(final Entity masterOrderProduct) { BigDecimal masterOrderQuantity, cumulatedOrderQuantity; Entity masterOrderProductDto = getMasterOrderProductDtoDD().get(masterOrderProduct.getId()); masterOrderQuantity = masterOrderProductDto.getDecimalField(MasterOrderProductFields.MASTER_ORDER_QUANTITY); cumulatedOrderQuantity = masterOrderProductDto.getDecimalField(CUMULATED_MASTER_ORDER_QUANTITY); BigDecimal quantity = masterOrderQuantity.subtract(convertNullToZero(cumulatedOrderQuantity)); return quantity; }
private BigDecimal getOperationRuns(final Map<Entity, BigDecimal> operationRuns, final Entity operationComponent) { Entity operComp = operationComponent; String entityType = operationComponent.getDataDefinition().getName(); if (!TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT.equals(entityType)) { operComp = operComp.getBelongsToField(L_TECHNOLOGY_OPERATION_COMPONENT).getDataDefinition() .get(operComp.getBelongsToField(L_TECHNOLOGY_OPERATION_COMPONENT).getId()); } return BigDecimalUtils.convertNullToZero(operationRuns.get(operComp)); }
private BigDecimal getOperationRunsFromMap(final Map<Long, BigDecimal> operationRuns, final Entity operationComponent) { Entity operComp = operationComponent; String entityType = operationComponent.getDataDefinition().getName(); if (!TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT.equals(entityType)) { operComp = operComp.getBelongsToField(L_TECHNOLOGY_OPERATION_COMPONENT).getDataDefinition() .get(operComp.getBelongsToField(L_TECHNOLOGY_OPERATION_COMPONENT).getId()); } return BigDecimalUtils.convertNullToZero(operationRuns.get(operComp.getId())); }
@Override public BigDecimal calculateProductCostForGivenQuantity(final Entity product, final BigDecimal quantity, final String calculateMaterialCostsMode) { BigDecimal cost = BigDecimalUtils.convertNullToZero(product.getField(ProductsCostFields.forMode( calculateMaterialCostsMode).getStrValue())); BigDecimal costForNumber = BigDecimalUtils.convertNullToOne(product.getDecimalField("costForNumber")); if (BigDecimalUtils.valueEquals(costForNumber, BigDecimal.ZERO)) { costForNumber = BigDecimal.ONE; } BigDecimal costPerUnit = cost.divide(costForNumber, numberService.getMathContext()); return costPerUnit.multiply(quantity, numberService.getMathContext()); }
public BigDecimal findOrderedQuantity(Entity delivery, Entity product, Entity additionalCode) { SearchCriteriaBuilder searchCriteriaBuilder = dataDefinitionService .get(DeliveriesConstants.PLUGIN_IDENTIFIER, DeliveriesConstants.MODEL_ORDERED_PRODUCT).find() .add(SearchRestrictions.belongsTo(DELIVERY, delivery)).add(SearchRestrictions.belongsTo(PRODUCT, product)) .add(SearchRestrictions.belongsTo(ADDITIONAL_CODE, additionalCode)); Entity orderedProductFromDB = searchCriteriaBuilder.setMaxResults(1).uniqueResult(); if (orderedProductFromDB == null) { return BigDecimal.ZERO; } return BigDecimalUtils.convertNullToZero(orderedProductFromDB.getDecimalField(OrderedProductFields.ORDERED_QUANTITY)); }