public boolean checkIfAllIssueQuantityGraterThanZero(final List<Entity> issues) { if (!issues.stream().filter(e -> e.getDecimalField(IssueFields.ISSUE_QUANTITY).compareTo(BigDecimal.ZERO) == 0) .collect(Collectors.toList()).isEmpty()) { return false; } return true; }
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); }
private void fillCoveredQuantity(final Map<Entity, Map<String, String>> values, final Entity coverageProduct) { BigDecimal coveredQuantity = null; if (coverageProduct == null) { coveredQuantity = BigDecimal.ZERO; } else { coveredQuantity = coverageProduct.getDecimalField(CoverageProductFields.COVERED_QUANTITY); } values.get(coverageProduct).put("coveredQuantity", numberService.format(coveredQuantity)); }
private void fillDeliveredQuantity(final Map<Entity, Map<String, String>> values, final Entity coverageProduct) { BigDecimal deliveredQuantity = null; if (coverageProduct == null) { deliveredQuantity = BigDecimal.ZERO; } else { deliveredQuantity = coverageProduct.getDecimalField(CoverageProductFields.DELIVERED_QUANTITY); } values.get(coverageProduct).put("deliveredQuantity", numberService.format(deliveredQuantity)); }
private void fillPricePerUnit(final Map<Entity, Map<String, String>> values, final Entity offerProduct) { BigDecimal pricePerUnit = null; if (offerProduct == null) { pricePerUnit = BigDecimal.ZERO; } else { pricePerUnit = offerProduct.getDecimalField(PRICE_PER_UNIT); } values.get(offerProduct).put("pricePerUnit", numberService.format(pricePerUnit)); }
private void fillDemandQuantity(final Map<Entity, Map<String, String>> values, final Entity coverageProduct) { BigDecimal demandQuantity = null; if (coverageProduct == null) { demandQuantity = BigDecimal.ZERO; } else { demandQuantity = coverageProduct.getDecimalField(CoverageProductFields.DEMAND_QUANTITY); } values.get(coverageProduct).put("demandQuantity", numberService.format(demandQuantity)); }
@Override public BigDecimal getPricePerUnit(final Entity offer, final Entity product) { Entity offerProduct = getOfferProduct(offer, product); if (offerProduct == null) { return null; } else { return offerProduct.getDecimalField(OfferProductFields.PRICE_PER_UNIT); } }
private void calculateReservationQuantities(final DataDefinition orderedProductDD, final Entity orderedProduct) { EntityList reservations = orderedProduct.getHasManyField(OrderedProductFields.RESERVATIONS); if (reservations != null) { BigDecimal conversion = orderedProduct.getDecimalField(OrderedProductFields.CONVERSION); for (Entity reservation : reservations) { BigDecimal orderedQuantity = reservation.getDecimalField(OrderedProductReservationFields.ORDERED_QUANTITY); BigDecimal newAdditionalQuantity = orderedQuantity.multiply(conversion, numberService.getMathContext()); newAdditionalQuantity = newAdditionalQuantity.setScale(NumberService.DEFAULT_MAX_FRACTION_DIGITS_IN_DECIMAL, RoundingMode.HALF_UP); reservation.setField(OrderedProductReservationFields.ADDITIONAL_QUANTITY, newAdditionalQuantity); } } }
private BigDecimal calculateQuantityInAdditionalUnit(Entity resource, String unit) { BigDecimal conversion = resource.getDecimalField(ResourceFields.CONVERSION); BigDecimal quantity = resource.getDecimalField(ResourceFields.QUANTITY); boolean isInteger = dictionaryService.checkIfUnitIsInteger(unit); BigDecimal value = quantity.multiply(conversion, numberService.getMathContext()); if (isInteger) { return numberService.setScaleWithDefaultMathContext(value, 0); } else { return value; } }
@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); }
public BigDecimal countAlreadyAssignedQuantityForProduct(final Entity product, final Entity additionalCode, final Entity offer, List<Entity> deliveredProducts) { BigDecimal alreadyAssignedQuantity = deliveredProducts .stream() .filter(p -> product.getId().equals(p.getBelongsToField(DeliveredProductFields.PRODUCT).getId()) && additionalCodesTheSame(additionalCode, p) && offerTheSame(offer, p)).map(p -> { BigDecimal deliveredQuantity = p.getDecimalField(DeliveredProductFields.DELIVERED_QUANTITY); return deliveredQuantity == null ? BigDecimal.ZERO : deliveredQuantity; }).reduce(BigDecimal.ZERO, BigDecimal::add); return alreadyAssignedQuantity; }
private void reduceReservationFor(Entity reservation, BigDecimal forQuantity) { BigDecimal newReservationQuantity = reservation.getDecimalField(ReservationFields.QUANTITY).subtract(forQuantity); if (newReservationQuantity.compareTo(BigDecimal.ZERO) > 0) { reservation.setField(ReservationFields.QUANTITY, newReservationQuantity); reservation.getDataDefinition().save(reservation); } else { reservation.setField(ReservationFields.QUANTITY, BigDecimal.ZERO); reservation.getDataDefinition().save(reservation); } }
private void checkMissingOrZero(Entity position, String fieldname, DataDefinition positionDataDefinition) { if (position.getField(fieldname) == null) { position.addError(positionDataDefinition.getField(fieldname), "qcadooView.validate.field.error.missing"); } else if (BigDecimal.ZERO.compareTo(position.getDecimalField(fieldname)) >= 0) { position.addError(positionDataDefinition.getField(fieldname), "qcadooView.validate.field.error.outOfRange.toSmall"); } }
private void copyOtherFields(Entity productionTracking, Entity correctingProductionTracking) { correctingProductionTracking.setField(ProductionTrackingFields.EXECUTED_OPERATION_CYCLES, productionTracking.getDecimalField(ProductionTrackingFields.EXECUTED_OPERATION_CYCLES)); copyStaffWorkTimes(productionTracking, correctingProductionTracking); copyTrackingOperationProductInComponents(productionTracking, correctingProductionTracking); copyTrackingOperationProductOutComponents(productionTracking, correctingProductionTracking); }
public void disableFieldsForIssuedPart(final ViewDefinitionState view) { FormComponent form = (FormComponent) view.getComponentByReference(L_FORM); Entity machinePartForEvent = form.getPersistedEntityWithIncludedFormValues(); BigDecimal issuedQuantity = machinePartForEvent.getDecimalField(MachinePartForEventFields.ISSUED_QUANTITY); if (issuedQuantity != null && issuedQuantity.compareTo(BigDecimal.ZERO) > 0) { LookupComponent machinePart = (LookupComponent) view.getComponentByReference(MachinePartForEventFields.MACHINE_PART); LookupComponent warehouse = (LookupComponent) view.getComponentByReference(MachinePartForEventFields.WAREHOUSE); machinePart.setEnabled(false); warehouse.setEnabled(false); } }
private BigDecimal getAvailableQuantity(final DataDefinition productToIssueDD, final Entity productToIssue) { BigDecimal oldQuantity = BigDecimal.ZERO; if (productToIssue.getId() != null) { Entity productToIssueFromDB = productToIssueDD.get(productToIssue.getId()); oldQuantity = productToIssueFromDB.getDecimalField(ProductsToIssueFields.DEMAND_QUANTITY); } Entity location = productToIssue.getBelongsToField(ProductsToIssueFields.WAREHOUSE_ISSUE) .getBelongsToField(WarehouseIssueFields.PLACE_OF_ISSUE); return resourceStockService .getResourceStockAvailableQuantity(productToIssue.getBelongsToField(ProductsToIssueFields.PRODUCT), location) .add(oldQuantity); }
private void fillOperationRuns(final Map<Long, BigDecimal> operationRuns, final Entity order) { List<Entity> productionCountingOperationRuns = dataDefinitionService .get(BasicProductionCountingConstants.PLUGIN_IDENTIFIER, BasicProductionCountingConstants.MODEL_PRODUCTION_COUNTING_OPERATON_RUN).find() .add(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.ORDER, order)).list().getEntities(); for (Entity productionCountingOperationRun : productionCountingOperationRuns) { Entity technologyOperationComponent = productionCountingOperationRun .getBelongsToField(ProductionCountingOperationRunFields.TECHNOLOGY_OPERATION_COMPONENT); BigDecimal runs = productionCountingOperationRun.getDecimalField(ProductionCountingOperationRunFields.RUNS); operationRuns.put(technologyOperationComponent.getId(), runs); } }
private Entity createRequestForQuotationProduct(final Entity negotiationProduct) { Entity requestForQuotationProduct = supplyNegotiationsService.getRequestForQuotationProductDD().create(); Entity product = negotiationProduct.getBelongsToField(PRODUCT); BigDecimal leftQuantity = negotiationProduct.getDecimalField(LEFT_QUANTITY); requestForQuotationProduct.setField(PRODUCT, product); requestForQuotationProduct.setField(ORDERED_QUANTITY, numberService.setScaleWithDefaultMathContext(leftQuantity)); return requestForQuotationProduct; }
@Override public void updateProducedQuantity(final Entity order) { Entity basicProductionCounting = getBasicProductionCountingDD().find() .add(SearchRestrictions.belongsTo(BasicProductionCountingFields.ORDER, order)).add(SearchRestrictions .belongsTo(BasicProductionCountingFields.PRODUCT, order.getBelongsToField(OrderFields.PRODUCT))) .setMaxResults(1).uniqueResult(); if (Objects.nonNull(basicProductionCounting)) { basicProductionCounting.setField(BasicProductionCountingFields.PRODUCED_QUANTITY, order.getDecimalField(OrderFields.DONE_QUANTITY)); basicProductionCounting.getDataDefinition().save(basicProductionCounting); } }