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;
}
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);
}
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);
}
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);
}
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;
}
Aggregations