Search in sources :

Example 26 with CheckBoxComponent

use of com.qcadoo.view.api.components.CheckBoxComponent in project mes by qcadoo.

the class ReplacementsListeners method addManyReplacements.

public final void addManyReplacements(final ViewDefinitionState view, final ComponentState state, final String[] args) throws JSONException {
    JSONObject obj = view.getJsonContext();
    if (obj.has("window.mainTab.product.productId")) {
        GridComponent grid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
        Long productId = obj.getLong("window.mainTab.product.productId");
        for (Long sub : grid.getSelectedEntitiesIds()) {
            Entity substituteComponent = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE_COMPONENT).create();
            substituteComponent.setField(SubstituteComponentFields.BASE_PRODUCT, productId);
            substituteComponent.setField(SubstituteComponentFields.PRODUCT, sub);
            substituteComponent.setField(SubstituteComponentFields.QUANTITY, 1);
            substituteComponent.getDataDefinition().save(substituteComponent);
        }
        CheckBoxComponent generated = (CheckBoxComponent) view.getComponentByReference("generated");
        generated.setChecked(true);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) JSONObject(org.json.JSONObject) GridComponent(com.qcadoo.view.api.components.GridComponent) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent)

Example 27 with CheckBoxComponent

use of com.qcadoo.view.api.components.CheckBoxComponent in project mes by qcadoo.

the class MachinePartDetailsHooks method setMachinePartCheckbox.

public void setMachinePartCheckbox(final ViewDefinitionState view) {
    CheckBoxComponent machinePartCheckbox = (CheckBoxComponent) view.getComponentByReference(ProductFields.MACHINE_PART);
    machinePartCheckbox.setChecked(true);
    machinePartCheckbox.requestComponentUpdateState();
}
Also used : CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent)

Example 28 with CheckBoxComponent

use of com.qcadoo.view.api.components.CheckBoxComponent in project mes by qcadoo.

the class CostCalculationReportService method generateCostCalculationReport.

public void generateCostCalculationReport(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    if (state instanceof FormComponent) {
        FieldComponent dateField = (FieldComponent) view.getComponentByReference(CostCalculationFields.DATE);
        CheckBoxComponent generatedField = (CheckBoxComponent) view.getComponentByReference(CostCalculationFields.GENERATED);
        Entity costCalculation = getCostCalculation((Long) state.getFieldValue());
        if (costCalculation == null) {
            state.addMessage("qcadooView.message.entityNotFound", MessageType.FAILURE);
            return;
        } else if (StringUtils.hasText(costCalculation.getStringField(CostCalculationFields.FILE_NAME))) {
            state.addMessage("qcadooReport.errorMessage.documentsWasNotGenerated", MessageType.FAILURE);
            return;
        }
        if (!generatedField.isChecked()) {
            dateField.setFieldValue(new SimpleDateFormat(DateUtils.L_DATE_TIME_FORMAT, view.getLocale()).format(new Date()));
            generatedField.setChecked(true);
        }
        state.performEvent(view, "save");
        if (state.isHasError()) {
            return;
        }
        if (state.getFieldValue() == null || !((FormComponent) state).isValid()) {
            dateField.setFieldValue(null);
            generatedField.setChecked(false);
            return;
        }
        costCalculation = getCostCalculation((Long) state.getFieldValue());
        try {
            Entity costCalculationWithFileName = fileService.updateReportFileName(costCalculation, CostCalculationFields.DATE, "costCalculation.costCalculation.report.fileName");
            costCalculationXlsService.generateDocument(costCalculationWithFileName, state.getLocale());
            state.performEvent(view, "reset");
            view.getComponentByReference(QcadooViewConstants.L_FORM).addMessage("costCalculation.messages.success.calculationComplete", MessageType.SUCCESS);
        } catch (IOException e) {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) FieldComponent(com.qcadoo.view.api.components.FieldComponent) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent)

Example 29 with CheckBoxComponent

use of com.qcadoo.view.api.components.CheckBoxComponent in project mes by qcadoo.

the class CostCalculationDetailsHooks method setFieldsEnabled.

public void setFieldsEnabled(final ViewDefinitionState view) {
    Set<String> referenceNames = Sets.newHashSet(CostCalculationFields.QUANTITY, CostCalculationFields.NUMBER, CostCalculationFields.DESCRIPTION, CostCalculationFields.MATERIAL_COSTS_USED, CostCalculationFields.AVERAGE_LABOR_HOURLY_COST, CostCalculationFields.STANDARD_LABOR_COST, CostCalculationFields.PRODUCTION_COST_MARGIN, CostCalculationFields.AVERAGE_MACHINE_HOURLY_COST, CostCalculationFields.MATERIAL_COST_MARGIN, CostCalculationFields.ADDITIONAL_OVERHEAD, CostCalculationFields.INCLUDE_TPZ, CostCalculationFields.USE_NOMINAL_COST_PRICE_NOT_SPECIFIED, CostCalculationFields.INCLUDE_ADDITIONAL_TIME, CostCalculationFields.SOURCE_OF_OPERATION_COSTS, CostCalculationFields.REGISTRATION_PRICE_OVERHEAD, CostCalculationFields.TECHNICAL_PRODUCTION_COST_OVERHEAD, CostCalculationFields.PROFIT);
    Map<String, FieldComponent> componentsMap = Maps.newHashMap();
    for (String referenceName : referenceNames) {
        FieldComponent fieldComponent = (FieldComponent) view.getComponentByReference(referenceName);
        componentsMap.put(referenceName, fieldComponent);
    }
    CheckBoxComponent generatedField = (CheckBoxComponent) view.getComponentByReference(CostCalculationFields.GENERATED);
    boolean isGenerated = generatedField.isChecked();
    for (Entry<String, FieldComponent> entry : componentsMap.entrySet()) {
        entry.getValue().setEnabled(!isGenerated);
    }
    if (isGenerated) {
        view.getComponentByReference(CostCalculationFields.TECHNOLOGIES).setEnabled(false);
    }
    if (!isGenerated) {
        FieldComponent sourceOfOperationCosts = (FieldComponent) view.getComponentByReference(CostCalculationFields.SOURCE_OF_OPERATION_COSTS);
        FieldComponent standardLaborCost = (FieldComponent) view.getComponentByReference(CostCalculationFields.STANDARD_LABOR_COST);
        CheckBoxComponent includeTPZ = (CheckBoxComponent) view.getComponentByReference(CostCalculationFields.INCLUDE_TPZ);
        CheckBoxComponent includeAdditionalTime = (CheckBoxComponent) view.getComponentByReference(CostCalculationFields.INCLUDE_ADDITIONAL_TIME);
        FieldComponent averageMachineHourlyCost = (FieldComponent) view.getComponentByReference(CostCalculationFields.AVERAGE_MACHINE_HOURLY_COST);
        FieldComponent averageLaborHourlyCost = (FieldComponent) view.getComponentByReference(CostCalculationFields.AVERAGE_LABOR_HOURLY_COST);
        standardLaborCost.setEnabled(SourceOfOperationCosts.STANDARD_LABOR_COSTS.getStringValue().equals(sourceOfOperationCosts.getFieldValue()));
        standardLaborCost.setRequired(SourceOfOperationCosts.STANDARD_LABOR_COSTS.getStringValue().equals(sourceOfOperationCosts.getFieldValue()));
        if (!SourceOfOperationCosts.STANDARD_LABOR_COSTS.getStringValue().equals(sourceOfOperationCosts.getFieldValue())) {
            standardLaborCost.setFieldValue(null);
        }
        standardLaborCost.requestComponentUpdateState();
        includeTPZ.setEnabled(!SourceOfOperationCosts.STANDARD_LABOR_COSTS.getStringValue().equals(sourceOfOperationCosts.getFieldValue()));
        includeAdditionalTime.setEnabled(!SourceOfOperationCosts.STANDARD_LABOR_COSTS.getStringValue().equals(sourceOfOperationCosts.getFieldValue()));
        averageMachineHourlyCost.setEnabled(SourceOfOperationCosts.PARAMETERS.getStringValue().equals(sourceOfOperationCosts.getFieldValue()));
        averageLaborHourlyCost.setEnabled(SourceOfOperationCosts.PARAMETERS.getStringValue().equals(sourceOfOperationCosts.getFieldValue()));
    }
}
Also used : FieldComponent(com.qcadoo.view.api.components.FieldComponent) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent)

Example 30 with CheckBoxComponent

use of com.qcadoo.view.api.components.CheckBoxComponent in project mes by qcadoo.

the class CostCalculationDetailsHooks method setButtonsEnabled.

private void setButtonsEnabled(ViewDefinitionState view) {
    WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
    RibbonActionItem saveNominalCosts = window.getRibbon().getGroupByName(CostCalculationFields.SAVE_COSTS).getItemByName(CostCalculationFields.NOMINAL_COSTS);
    RibbonActionItem generate = window.getRibbon().getGroupByName("generate").getItemByName("generate");
    RibbonActionItem pdfButton = window.getRibbon().getGroupByName("export").getItemByName("pdf");
    RibbonActionItem xlsButton = window.getRibbon().getGroupByName("export").getItemByName("xls");
    RibbonActionItem save = window.getRibbon().getGroupByName(ACTIONS).getItemByName("save");
    RibbonActionItem saveBack = window.getRibbon().getGroupByName(ACTIONS).getItemByName("saveBack");
    RibbonActionItem saveNew = window.getRibbon().getGroupByName(ACTIONS).getItemByName("saveNew");
    RibbonActionItem copy = window.getRibbon().getGroupByName(ACTIONS).getItemByName("copy");
    RibbonActionItem cancel = window.getRibbon().getGroupByName(ACTIONS).getItemByName("cancel");
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    boolean pdf = form.getPersistedEntityWithIncludedFormValues().getBooleanField(CostCalculationFields.PDF);
    boolean entityExists = form.getEntityId() != null;
    if (entityExists) {
        CheckBoxComponent generatedField = (CheckBoxComponent) view.getComponentByReference(CostCalculationFields.GENERATED);
        int technologiesCount = ((GridComponent) view.getComponentByReference(CostCalculationFields.TECHNOLOGIES)).getEntities().size();
        generate.setEnabled(technologiesCount > 0);
        generate.requestUpdate(true);
        saveNominalCosts.setEnabled(generatedField.isChecked());
        saveNominalCosts.requestUpdate(true);
        if (generatedField.isChecked()) {
            if (pdf) {
                pdfButton.setEnabled(true);
                pdfButton.requestUpdate(true);
            } else {
                xlsButton.setEnabled(true);
                xlsButton.requestUpdate(true);
            }
            generate.setEnabled(false);
            generate.requestUpdate(true);
            save.setEnabled(false);
            save.setMessage(COST_CALCULATION_RIBBON_MESSAGE_RECORD_ALREADY_GENERATED);
            save.requestUpdate(true);
            saveNew.setEnabled(false);
            saveNew.setMessage(COST_CALCULATION_RIBBON_MESSAGE_RECORD_ALREADY_GENERATED);
            saveNew.requestUpdate(true);
            saveBack.setEnabled(false);
            saveBack.setMessage(COST_CALCULATION_RIBBON_MESSAGE_RECORD_ALREADY_GENERATED);
            saveBack.requestUpdate(true);
            cancel.setEnabled(false);
            cancel.setMessage(COST_CALCULATION_RIBBON_MESSAGE_RECORD_ALREADY_GENERATED);
        } else {
            pdfButton.setEnabled(false);
            pdfButton.setMessage("costCalculation.ribbon.message.recordNotGenerated");
            pdfButton.requestUpdate(true);
            xlsButton.setEnabled(false);
            xlsButton.setMessage("costCalculation.ribbon.message.recordNotGenerated");
            xlsButton.requestUpdate(true);
            save.setEnabled(true);
            save.requestUpdate(true);
            cancel.setEnabled(true);
        }
    } else {
        copy.setEnabled(false);
        copy.setMessage(RECORD_NOT_CREATED);
        copy.requestUpdate(true);
        pdfButton.setEnabled(false);
        pdfButton.setMessage(RECORD_NOT_CREATED);
        pdfButton.requestUpdate(true);
        xlsButton.setEnabled(false);
        xlsButton.setMessage(RECORD_NOT_CREATED);
        xlsButton.requestUpdate(true);
        save.setEnabled(true);
        save.requestUpdate(true);
        cancel.setEnabled(true);
    }
    cancel.requestUpdate(true);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) WindowComponent(com.qcadoo.view.api.components.WindowComponent) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent)

Aggregations

CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)100 FormComponent (com.qcadoo.view.api.components.FormComponent)38 Entity (com.qcadoo.model.api.Entity)33 FieldComponent (com.qcadoo.view.api.components.FieldComponent)30 GridComponent (com.qcadoo.view.api.components.GridComponent)19 LookupComponent (com.qcadoo.view.api.components.LookupComponent)11 Date (java.util.Date)7 JSONObject (org.json.JSONObject)7 BigDecimal (java.math.BigDecimal)6 ComponentState (com.qcadoo.view.api.ComponentState)4 WindowComponent (com.qcadoo.view.api.components.WindowComponent)4 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)4 IOException (java.io.IOException)4 MaterialFlowResourcesConstants (com.qcadoo.mes.materialFlowResources.constants.MaterialFlowResourcesConstants)2 DataDefinition (com.qcadoo.model.api.DataDefinition)2 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)2 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)2 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)2 AwesomeDynamicListComponent (com.qcadoo.view.api.components.AwesomeDynamicListComponent)2 Ribbon (com.qcadoo.view.api.ribbon.Ribbon)2