private BigDecimal zeroToOne(final BigDecimal bigDecimal) { if (BigDecimalUtils.valueEquals(bigDecimal, BigDecimal.ZERO)) { return BigDecimal.ONE; } return bigDecimal; }
public BigDecimal getDifference() { if (planned == null || registered == null) { return null; } if (BigDecimalUtils.valueEquals(planned, BigDecimal.ZERO)) { return null; } return registered.subtract(planned); }
private boolean hasPlannedQuantityChanged(final Entity order, final BigDecimal plannedQuantity) { Entity existingOrder = getExistingOrder(order); if (existingOrder == null) { return false; } BigDecimal existingOrderPlannedQuantity = existingOrder.getDecimalField(OrderFields.PLANNED_QUANTITY); if (existingOrderPlannedQuantity == null) { return true; } return !BigDecimalUtils.valueEquals(existingOrderPlannedQuantity, plannedQuantity); }
public boolean validatePlannedQuantity(final DataDefinition productionCountingQuantityDD, final FieldDefinition plannedQuantityFieldDefinition, final Entity productionCountingQuantity, final Object oldValue, final Object newValue) { // I don't check if entity is updated or created (check null on id) because we should disallow also creating // of new ones if editing production progresses for accepted orders is locked. if (BigDecimalUtils.valueEquals((BigDecimal) oldValue, (BigDecimal) newValue)) { return true; } if (progressModifyLockHelper.isLocked(productionCountingQuantity .getBelongsToField(ProductionCountingQuantityFields.ORDER))) { productionCountingQuantity .addError(plannedQuantityFieldDefinition, "basicProductionCounting.productionCountingQuantity.plannedQuantity.error.valueChangeIsNotAllowedForAcceptetOrder"); return false; } return true; }
@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()); }