Search in sources :

Example 91 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.

the class OrderStatesListenerServicePFTD method getProductQuantityTakenForOrder.

private BigDecimal getProductQuantityTakenForOrder(final Long productId, final Long orderId) {
    DataDefinition issueDD = dataDefinitionService.get(ProductFlowThruDivisionConstants.PLUGIN_IDENTIFIER, ProductFlowThruDivisionConstants.MODEL_ISSUE);
    SearchQueryBuilder searchQueryBuilder = issueDD.find("SELECT SUM(issue.issueQuantity) AS totalQuantity " + "FROM #productFlowThruDivision_issue issue JOIN issue.warehouseIssue AS warehouseIssue " + "WHERE warehouseIssue.order = :order_id AND issue.product = :product_id AND issue.issued = :issued " + "GROUP BY warehouseIssue.order, issue.product, issue.issued");
    searchQueryBuilder.setLong("order_id", orderId);
    searchQueryBuilder.setLong("product_id", productId);
    searchQueryBuilder.setBoolean("issued", true);
    Entity result = searchQueryBuilder.setMaxResults(1).uniqueResult();
    return result != null ? result.getDecimalField("totalQuantity") : BigDecimal.ZERO;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchQueryBuilder(com.qcadoo.model.api.search.SearchQueryBuilder) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 92 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.

the class ProductionTrackingListenerServicePFTD method updateCostsForOrder.

public void updateCostsForOrder(final Entity order) {
    DataDefinition positionDD = getPositionDD();
    SearchQueryBuilder searchQueryBuilder = positionDD.find("SELECT pr.id AS product, SUM(p.quantity) AS quantity, SUM(p.quantity * p.price) AS price " + "FROM #materialFlowResources_position p JOIN p.document AS d join p.product AS pr " + "WHERE d.order = :order_id AND d.type = :type " + "GROUP BY d.order, d.type, pr.id");
    searchQueryBuilder.setLong("order_id", order.getId());
    searchQueryBuilder.setString("type", DocumentType.INTERNAL_OUTBOUND.getStringValue());
    SearchResult result = searchQueryBuilder.list();
    List<ProductWithQuantityAndCost> productsWithQuantitiesAndCosts = Lists.newArrayList();
    for (Entity costsForProduct : result.getEntities()) {
        Long product = (Long) costsForProduct.getField(PositionFields.PRODUCT);
        BigDecimal quantity = costsForProduct.getDecimalField(PositionFields.QUANTITY);
        BigDecimal cost = costsForProduct.getDecimalField(PositionFields.PRICE);
        productsWithQuantitiesAndCosts.add(new ProductWithQuantityAndCost(product, quantity, cost));
    }
    List<Entity> updatedCosts = costNormsForMaterialsService.updateCostsForProductInOrder(order, productsWithQuantitiesAndCosts);
    order.setField(OrderFieldsCNFM.TECHNOLOGY_INST_OPER_PRODUCT_IN_COMPS, updatedCosts);
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchQueryBuilder(com.qcadoo.model.api.search.SearchQueryBuilder) SearchResult(com.qcadoo.model.api.search.SearchResult) DataDefinition(com.qcadoo.model.api.DataDefinition) BigDecimal(java.math.BigDecimal) ProductWithQuantityAndCost(com.qcadoo.mes.costNormsForMaterials.orderRawMaterialCosts.domain.ProductWithQuantityAndCost)

Example 93 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.

the class ProductionLineAddMultiListeners method createProductionLine.

private Entity createProductionLine(final Entity technology, final Entity productionLine) {
    DataDefinition technologyProductionLineDD = getTechnologyProductionLineDD();
    Entity newProductionLine = technologyProductionLineDD.create();
    newProductionLine.setField(TechnologyProductionLineFields.TECHNOLOGY, technology);
    newProductionLine.setField(TechnologyProductionLineFields.PRODUCTION_LINE, productionLine);
    newProductionLine.setField(TechnologyProductionLineFields.MASTER, false);
    return technologyProductionLineDD.save(newProductionLine);
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 94 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.

the class TechnologyDetailsListenersPFTD method createModelCard.

public void createModelCard(final ViewDefinitionState view, final ComponentState componentState, final String[] args) {
    FormComponent technologyForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity technology = technologyForm.getPersistedEntityWithIncludedFormValues();
    Entity product = technology.getBelongsToField(TechnologyFields.PRODUCT);
    Entity parameter = parameterService.getParameter();
    DataDefinition modelCardDD = dataDefinitionService.get(ProductFlowThruDivisionConstants.PLUGIN_IDENTIFIER, ProductFlowThruDivisionConstants.MODEL_MODEL_CARD);
    Entity modelCard = modelCardDD.create();
    modelCard.setField(ModelCardFields.NAME, product.getField(ProductFields.NAME));
    modelCard.setField(ModelCardFields.MATERIAL_COSTS_USED, parameter.getStringField(ParameterFieldsPFTD.MATERIAL_COSTS_USED_MC));
    modelCard.setField(ModelCardFields.USE_NOMINAL_COST_PRICE_NOT_SPECIFIED, parameter.getBooleanField(ParameterFieldsPFTD.USE_NOMINAL_COST_PRICE_NOT_SPECIFIED_MC));
    DataDefinition modelCardProductDD = dataDefinitionService.get(ProductFlowThruDivisionConstants.PLUGIN_IDENTIFIER, ProductFlowThruDivisionConstants.MODEL_MODEL_CARD_PRODUCT);
    Entity modelCardProduct = modelCardProductDD.create();
    modelCardProduct.setField(ModelCardProductFields.PRODUCT, product);
    modelCardProduct.setField(ModelCardProductFields.TECHNOLOGY, technology);
    modelCardProduct.setField(ModelCardProductFields.QUANTITY, 1L);
    modelCard.setField(ModelCardFields.MODEL_CARD_PRODUCTS, Collections.singletonList(modelCardProduct));
    modelCard = modelCardDD.save(modelCard);
    Map<String, Object> parameters = Maps.newHashMap();
    parameters.put("form.id", modelCard.getId());
    String url = "../page/productFlowThruDivision/modelCardDetails.html";
    view.redirectTo(url, false, true, parameters);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) JSONObject(org.json.JSONObject) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 95 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.

the class SupplyParametersHooksPFTD method draftOrInProgressWarehouseIssuesDoesntExist.

private boolean draftOrInProgressWarehouseIssuesDoesntExist() {
    DataDefinition dd = dataDefinitionService.get(ProductFlowThruDivisionConstants.PLUGIN_IDENTIFIER, ProductFlowThruDivisionConstants.MODEL_WAREHOUSE_ISSUE);
    SearchResult result = dd.find().add(SearchRestrictions.or(SearchRestrictions.eq(WarehouseIssueFields.STATE, WarehouseIssueState.DRAFT.getStringValue()), SearchRestrictions.eq(WarehouseIssueFields.STATE, WarehouseIssueState.IN_PROGRESS.getStringValue()))).list();
    return result.getTotalNumberOfEntities() == 0;
}
Also used : SearchResult(com.qcadoo.model.api.search.SearchResult) DataDefinition(com.qcadoo.model.api.DataDefinition)

Aggregations

DataDefinition (com.qcadoo.model.api.DataDefinition)415 Entity (com.qcadoo.model.api.Entity)285 Test (org.junit.Test)165 BigDecimal (java.math.BigDecimal)53 FieldDefinition (com.qcadoo.model.api.FieldDefinition)48 List (java.util.List)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)32 Service (org.springframework.stereotype.Service)31 Autowired (org.springframework.beans.factory.annotation.Autowired)27 Date (java.util.Date)26 Map (java.util.Map)26 Collectors (java.util.stream.Collectors)26 FormComponent (com.qcadoo.view.api.components.FormComponent)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)22 IOException (java.io.IOException)21 Objects (java.util.Objects)21 GridComponent (com.qcadoo.view.api.components.GridComponent)20 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)20 Lists (com.google.common.collect.Lists)16