private void updateBasicProductionCounting(
      final Entity productionTracking, final Operation operation) {
    final Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER);

    final List<Entity> basicProductionCountings =
        order.getHasManyField(OrderFieldsBPC.BASIC_PRODUCTION_COUNTINGS);

    final List<Entity> trackingOperationProductInComponents =
        productionTracking.getHasManyField(
            ProductionTrackingFields.TRACKING_OPERATION_PRODUCT_IN_COMPONENTS);
    final List<Entity> trackingOperationProductOutComponents =
        productionTracking.getHasManyField(
            ProductionTrackingFields.TRACKING_OPERATION_PRODUCT_OUT_COMPONENTS);

    for (Entity trackingOperationProductInComponent : trackingOperationProductInComponents) {
      Entity basicProductionCounting;

      try {
        basicProductionCounting =
            getBasicProductionCounting(
                trackingOperationProductInComponent, basicProductionCountings);
      } catch (IllegalStateException e) {
        continue;
      }

      final BigDecimal usedQuantity =
          basicProductionCounting.getDecimalField(BasicProductionCountingFields.USED_QUANTITY);
      final BigDecimal productQuantity =
          trackingOperationProductInComponent.getDecimalField(
              TrackingOperationProductInComponentFields.USED_QUANTITY);
      final BigDecimal result = operation.perform(usedQuantity, productQuantity);

      basicProductionCounting.setField(BasicProductionCountingFields.USED_QUANTITY, result);
      basicProductionCounting =
          basicProductionCounting.getDataDefinition().save(basicProductionCounting);
    }

    for (Entity trackingOperationProductOutComponent : trackingOperationProductOutComponents) {
      Entity productionCounting;

      try {
        productionCounting =
            getBasicProductionCounting(
                trackingOperationProductOutComponent, basicProductionCountings);
      } catch (IllegalStateException e) {
        continue;
      }

      final BigDecimal usedQuantity =
          productionCounting.getDecimalField(BasicProductionCountingFields.PRODUCED_QUANTITY);
      final BigDecimal productQuantity =
          trackingOperationProductOutComponent.getDecimalField(
              TrackingOperationProductOutComponentFields.USED_QUANTITY);
      final BigDecimal result = operation.perform(usedQuantity, productQuantity);

      productionCounting.setField(BasicProductionCountingFields.PRODUCED_QUANTITY, result);
      productionCounting = productionCounting.getDataDefinition().save(productionCounting);
    }
  }
예제 #2
0
  private void updateReservations(Entity document) {

    List<Entity> positions = document.getHasManyField(DocumentFields.POSITIONS);
    for (Entity position : positions) {
      reservationsService.updateReservationFromDocumentPosition(position);
    }
  }
  @Override
  public Set<ImportedOrder> getImportedOrders(final Set<Long> orderIds) {
    Set<ImportedOrder> result = new HashSet<ImportedOrder>();
    for (Long importedOrderId : orderIds) {
      Entity orderEntity =
          dataDefinitionService
              .get(SfcSimpleConstants.PLUGIN_IDENTIFIER, SfcSimpleConstants.MODEL_IMPORTED_ORDER)
              .get(importedOrderId);

      ImportedOrder order = new ImportedOrder(importedOrderId);

      order.setNumber(orderEntity.getStringField(FIELD_NUMBER));
      order.setDrawDate((Date) orderEntity.getField(FIELD_DRAW_DATE));
      order.setRealizationDate((Date) orderEntity.getField(FIELD_REALIZATION_DATE));

      for (Entity orderProductEntity : orderEntity.getHasManyField("orderProducts")) {

        ImportedProduct orderItemProduct =
            createImportedProduct(orderProductEntity.getBelongsToField("product"), true);
        if (orderItemProduct != null) {
          ImportedOrderItem orderItem = new ImportedOrderItem();
          orderItem.setProduct(orderItemProduct);
          orderItem.setQuantity((BigDecimal) orderProductEntity.getField(FIELD_QUANTITY));
          order.addItem(orderItem);
        }
      }

      result.add(order);
    }

    return result;
  }
예제 #4
0
  @Override
  @Transactional
  public void updateResourcesForReleaseDocuments(final Entity document) {
    Entity warehouse = document.getBelongsToField(DocumentFields.LOCATION_FROM);
    WarehouseAlgorithm warehouseAlgorithm;

    boolean enoughResources = true;

    StringBuilder errorMessage = new StringBuilder();

    Multimap<Long, BigDecimal> quantitiesForWarehouse =
        getQuantitiesInWarehouse(warehouse, getProductsAndPositionsFromDocument(document));

    List<Entity> generatedPositions = Lists.newArrayList();

    for (Entity position : document.getHasManyField(DocumentFields.POSITIONS)) {
      Entity product = position.getBelongsToField(PositionFields.PRODUCT);
      Entity resource = position.getBelongsToField(PositionFields.RESOURCE);

      BigDecimal quantityInWarehouse;

      if (resource != null) {
        warehouse = resource.getBelongsToField(ResourceFields.LOCATION);
        warehouseAlgorithm = WarehouseAlgorithm.MANUAL;
      } else {
        warehouse = document.getBelongsToField(DocumentFields.LOCATION_FROM);
        warehouseAlgorithm =
            WarehouseAlgorithm.parseString(warehouse.getStringField(LocationFieldsMFR.ALGORITHM));
      }

      if (warehouseAlgorithm.equals(WarehouseAlgorithm.MANUAL)) {
        quantityInWarehouse = getQuantityOfProductInWarehouse(warehouse, product, position);
      } else {
        quantityInWarehouse = getQuantityOfProductFromMultimap(quantitiesForWarehouse, product);
      }

      generatedPositions.addAll(updateResources(warehouse, position, warehouseAlgorithm));

      enoughResources = enoughResources && position.isValid();

      if (!position.isValid()) {
        BigDecimal quantity = position.getDecimalField(QUANTITY);

        errorMessage.append(product.getStringField(ProductFields.NAME));
        errorMessage.append(" - ");
        errorMessage.append(numberService.format(quantity.subtract(quantityInWarehouse)));
        errorMessage.append(" ");
        errorMessage.append(product.getStringField(ProductFields.UNIT));
        errorMessage.append(", ");
      }
    }

    if (!enoughResources) {
      addDocumentError(document, warehouse, errorMessage);
    } else {
      deleteReservations(document);
      document.setField(DocumentFields.POSITIONS, generatedPositions);
    }
  }
 public void deleteOrderProducts(final Entity orderEntity) {
   for (Entity orrderProductEntity : orderEntity.getHasManyField("orderProducts")) {
     dataDefinitionService
         .get(
             SfcSimpleConstants.PLUGIN_IDENTIFIER, SfcSimpleConstants.MODEL_IMPORTED_ORDER_PRODUCT)
         .delete(orrderProductEntity.getId());
   }
 }
예제 #6
0
  private void setResourceAttributesFromPosition(final Entity resource, final Entity position) {
    List<Entity> attributes = position.getHasManyField(PositionFields.ATRRIBUTE_VALUES);

    for (Entity attribute : attributes) {
      attribute.setField(AttributeValueFields.RESOURCE, resource);
    }

    resource.setField(ResourceFields.ATRRIBUTE_VALUES, attributes);
  }
예제 #7
0
  @Override
  @Transactional
  public void createResourcesForReceiptDocuments(final Entity document) {
    Entity warehouse = document.getBelongsToField(DocumentFields.LOCATION_TO);
    Object date = document.getField(DocumentFields.TIME);

    for (Entity position : document.getHasManyField(DocumentFields.POSITIONS)) {
      createResource(document, warehouse, position, date);
    }
  }
  private boolean checkIfUsedQuantitiesWereFilled(
      final Entity productionTracking, final String modelName) {
    final SearchCriteriaBuilder searchBuilder =
        productionTracking
            .getHasManyField(modelName)
            .find()
            .add(SearchRestrictions.isNotNull(L_USED_QUANTITY));

    return (searchBuilder.list().getTotalNumberOfEntities() != 0);
  }
예제 #9
0
  private Multimap<Entity, Entity> getProductsAndPositionsFromDocument(final Entity document) {
    Multimap<Entity, Entity> map = ArrayListMultimap.create();

    List<Entity> positions = document.getHasManyField(DocumentFields.POSITIONS);

    positions
        .stream()
        .forEach(position -> map.put(position.getBelongsToField(PositionFields.PRODUCT), position));

    return map;
  }
예제 #10
0
  @Override
  @Transactional
  public void moveResourcesForTransferDocument(Entity document) {
    Entity warehouseFrom = document.getBelongsToField(DocumentFields.LOCATION_FROM);
    Entity warehouseTo = document.getBelongsToField(DocumentFields.LOCATION_TO);
    Object date = document.getField(DocumentFields.TIME);

    WarehouseAlgorithm warehouseAlgorithm =
        WarehouseAlgorithm.parseString(warehouseFrom.getStringField(LocationFieldsMFR.ALGORITHM));

    boolean enoughResources = true;

    StringBuilder errorMessage = new StringBuilder();

    Multimap<Long, BigDecimal> quantitiesForWarehouse =
        getQuantitiesInWarehouse(warehouseFrom, getProductsAndPositionsFromDocument(document));

    for (Entity position : document.getHasManyField(DocumentFields.POSITIONS)) {
      Entity product = position.getBelongsToField(PositionFields.PRODUCT);
      BigDecimal quantityInWarehouse;

      if (warehouseAlgorithm.equals(WarehouseAlgorithm.MANUAL)) {
        quantityInWarehouse = getQuantityOfProductInWarehouse(warehouseFrom, product, position);
      } else {
        quantityInWarehouse = getQuantityOfProductFromMultimap(quantitiesForWarehouse, product);
      }

      moveResources(warehouseFrom, warehouseTo, position, date, warehouseAlgorithm);
      enoughResources = enoughResources && position.isValid();

      if (!position.isValid()) {
        BigDecimal quantity = position.getDecimalField(QUANTITY);

        errorMessage.append(product.getStringField(ProductFields.NAME));
        errorMessage.append(" - ");
        errorMessage.append(numberService.format(quantity.subtract(quantityInWarehouse)));
        errorMessage.append(" ");
        errorMessage.append(product.getStringField(ProductFields.UNIT));
        errorMessage.append(", ");
      }
    }

    if (!enoughResources) {
      addDocumentError(document, warehouseFrom, errorMessage);
    } else {
      deleteReservations(document);
    }
  }
예제 #11
0
  private void setResourceAttributesFromResource(final Entity resource, final Entity baseResource) {
    List<Entity> attributes = baseResource.getHasManyField(ResourceFields.ATRRIBUTE_VALUES);

    List<Entity> newAttributes = Lists.newArrayList();

    DataDefinition attributeDD =
        dataDefinitionService.get(
            MaterialFlowResourcesConstants.PLUGIN_IDENTIFIER,
            MaterialFlowResourcesConstants.MODEL_ATTRIBUTE_VALUE);

    for (Entity attribute : attributes) {
      List<Entity> newAttribute = attributeDD.copy(attribute.getId());

      newAttribute.get(0).setField(AttributeValueFields.RESOURCE, resource);

      newAttributes.addAll(newAttribute);
    }

    resource.setField(ResourceFields.ATRRIBUTE_VALUES, newAttributes);
  }
  @Transactional
  public void generateSimpleMaterialBalance(
      final ViewDefinitionState viewDefinitionState,
      final ComponentState state,
      final String[] args) {
    if (state instanceof FormComponent) {
      ComponentState generated = viewDefinitionState.getComponentByReference(L_GENERATED);
      ComponentState date = viewDefinitionState.getComponentByReference(L_DATE);
      ComponentState worker = viewDefinitionState.getComponentByReference(L_WORKER);

      Entity simpleMaterialBalance =
          dataDefinitionService
              .get(
                  SimpleMaterialBalanceConstants.PLUGIN_IDENTIFIER,
                  SimpleMaterialBalanceConstants.MODEL_SIMPLE_MATERIAL_BALANCE)
              .get((Long) state.getFieldValue());

      if (simpleMaterialBalance == null) {
        state.addMessage("qcadooView.message.entityNotFound", MessageType.FAILURE);
        return;
      } else if (StringUtils.hasText(simpleMaterialBalance.getStringField(L_FILE_NAME))) {
        state.addMessage(
            "simpleMaterialBalance.simpleMaterialBalanceDetails.window.simpleMaterialBalance.documentsWasGenerated",
            MessageType.FAILURE);
        return;
      } else if (simpleMaterialBalance
          .getHasManyField(L_SIMPLE_MATERIAL_BALANCE_ORDERS_COMPONENTS)
          .isEmpty()) {
        state.addMessage(
            "simpleMaterialBalance.simpleMaterialBalance.window.simpleMaterialBalance.missingAssosiatedOrders",
            MessageType.FAILURE);
        return;
      } else if (simpleMaterialBalance
          .getHasManyField(L_SIMPLE_MATERIAL_BALANCE_LOCATIONS_COMPONENTS)
          .isEmpty()) {
        state.addMessage(
            "simpleMaterialBalance.simpleMaterialBalance.window.simpleMaterialBalance.missingAssosiatedLocations",
            MessageType.FAILURE);
        return;
      }

      if ("0".equals(generated.getFieldValue())) {
        worker.setFieldValue(securityService.getCurrentUserName());
        generated.setFieldValue("1");
        date.setFieldValue(
            new SimpleDateFormat(DateUtils.L_DATE_TIME_FORMAT, LocaleContextHolder.getLocale())
                .format(new Date()));
      }

      state.performEvent(viewDefinitionState, "save", new String[0]);

      if (state.getFieldValue() == null || !((FormComponent) state).isValid()) {
        worker.setFieldValue(null);
        generated.setFieldValue("0");
        date.setFieldValue(null);
        return;
      }

      simpleMaterialBalance =
          dataDefinitionService
              .get(
                  SimpleMaterialBalanceConstants.PLUGIN_IDENTIFIER,
                  SimpleMaterialBalanceConstants.MODEL_SIMPLE_MATERIAL_BALANCE)
              .get((Long) state.getFieldValue());

      try {
        generateSimpleMaterialBalanceDocuments(state, simpleMaterialBalance);
        state.performEvent(viewDefinitionState, "reset", new String[0]);
      } catch (IOException e) {
        throw new IllegalStateException(e.getMessage(), e);
      } catch (DocumentException e) {
        throw new IllegalStateException(e.getMessage(), e);
      }
    }
  }
  public boolean isEqualOrders(final Entity existingOrder, final ParsedOrder order) {
    if (!existingOrder.getField(FIELD_NUMBER).equals(order.getField(FIELD_NUMBER))) {
      return false;
    }
    if (!existingOrder.getField(FIELD_CLIENT_NAME).equals(order.getField(FIELD_CLIENT_NAME))) {
      return false;
    }
    if (!existingOrder
        .getField(FIELD_CLIENT_ADDRESS)
        .equals(order.getField(FIELD_CLIENT_ADDRESS))) {
      return false;
    }
    if (!existingOrder
        .getField(FIELD_DRAW_DATE)
        .equals(
            IntegrationParserUtils.parseDateWithoutException(order.getField(FIELD_DRAW_DATE)))) {
      return false;
    }
    if (!existingOrder
        .getField(FIELD_REALIZATION_DATE)
        .equals(
            IntegrationParserUtils.parseDateWithoutException(
                order.getField(FIELD_REALIZATION_DATE)))) {
      return false;
    }

    List<Entity> existingOrderProducts =
        new ArrayList<Entity>(existingOrder.getHasManyField("orderProducts"));
    List<ParsedOrderItem> orderProducts = new ArrayList<ParsedOrderItem>(order.getItems());
    if (existingOrderProducts.size() == orderProducts.size()) {
      Collections.sort(existingOrderProducts, new OrderProductEntityComparator());
      Collections.sort(orderProducts, new ParsedOrderProductComparator());
      for (int i = 0; i < existingOrderProducts.size(); i++) {
        Entity existingOrderProduct = existingOrderProducts.get(i);
        ParsedOrderItem orderProduct = orderProducts.get(i);
        if (!existingOrderProduct
            .getField(FIELD_ORDER_NUMBER)
            .equals(
                IntegrationParserUtils.parseIntegerWithoutException(
                    orderProduct.getField(FIELD_NUMBER)))) {
          return false;
        }
        if (((BigDecimal) existingOrderProduct.getField(FIELD_QUANTITY))
                .compareTo(
                    IntegrationParserUtils.parseBigDecimalWithoutException(
                        orderProduct.getField(FIELD_QUANTITY)))
            != 0) {
          return false;
        }
        if (!existingOrderProduct
            .getBelongsToField("product")
            .getField(FIELD_IDENTIFICATION_CODE)
            .equals(orderProduct.getProductIdentificationCode())) {
          return false;
        }
      }
      return true;
    }

    return false;
  }