Search in sources :

Example 31 with MWorkflow

use of org.compiere.wf.MWorkflow in project adempiere by adempiere.

the class MTable method getworkFlowProcess.

/**
	 * Get / Create Process and Work Flow
	 * @return
	 */
private int getworkFlowProcess() {
    //	Search or create Work Flow
    MWorkflow workFlow = MWorkflow.getWorkFlowFromDocumentTable(getCtx(), getAD_Table_ID(), get_TrxName());
    //	validate null
    if (workFlow == null) {
        workFlow = new MWorkflow(getCtx(), 0, get_TrxName());
        workFlow.setValue("Process_" + getName());
        workFlow.setName(workFlow.getValue());
        workFlow.setDescription("(Standard Process_" + getName() + ")");
        workFlow.setWorkflowType(X_AD_Workflow.WORKFLOWTYPE_DocumentProcess);
        workFlow.setAD_Table_ID(getAD_Table_ID());
        workFlow.setAccessLevel(getAccessLevel());
        workFlow.setEntityType(getEntityType());
        workFlow.setPublishStatus(X_AD_Workflow.PUBLISHSTATUS_Test);
        workFlow.setAuthor("ADempiere");
        workFlow.setDuration(1);
        workFlow.saveEx();
        //	Create Work Flow Node for (Start)
        MWFNode wfNode_Start = new MWFNode(workFlow, "(Start)", "(Start)");
        wfNode_Start.setDescription(workFlow.getName());
        wfNode_Start.setEntityType(getEntityType());
        wfNode_Start.setJoinElement(X_AD_WF_Node.JOINELEMENT_XOR);
        wfNode_Start.setSplitElement(X_AD_WF_Node.SPLITELEMENT_XOR);
        wfNode_Start.setAction(X_AD_WF_Node.ACTION_WaitSleep);
        wfNode_Start.saveEx();
        //	Set Start node in Workflow
        workFlow.setAD_WF_Node_ID(wfNode_Start.getAD_WF_Node_ID());
        workFlow.saveEx();
        //	Create Work Flow Node for (DocAuto)
        MWFNode wfNode_Auto = new MWFNode(workFlow, "(DocAuto)", "(DocAuto)");
        wfNode_Auto.setDescription(workFlow.getName());
        wfNode_Auto.setEntityType(getEntityType());
        wfNode_Auto.setJoinElement(X_AD_WF_Node.JOINELEMENT_XOR);
        wfNode_Auto.setSplitElement(X_AD_WF_Node.SPLITELEMENT_XOR);
        wfNode_Auto.setAction(X_AD_WF_Node.ACTION_DocumentAction);
        wfNode_Auto.setDocAction(X_AD_WF_Node.DOCACTION_None);
        wfNode_Auto.saveEx();
        //	Create Work Flow Node for (DocPrepare)
        MWFNode wfNode_Prepare = new MWFNode(workFlow, "(DocPrepare)", "(DocPrepare)");
        wfNode_Prepare.setDescription(workFlow.getName());
        wfNode_Prepare.setEntityType(getEntityType());
        wfNode_Prepare.setJoinElement(X_AD_WF_Node.JOINELEMENT_XOR);
        wfNode_Prepare.setSplitElement(X_AD_WF_Node.SPLITELEMENT_XOR);
        wfNode_Prepare.setAction(X_AD_WF_Node.ACTION_DocumentAction);
        wfNode_Prepare.setDocAction(X_AD_WF_Node.DOCACTION_Prepare);
        wfNode_Prepare.saveEx();
        //	Create Work Flow Node for (DocComplete)
        MWFNode wfNode_Complete = new MWFNode(workFlow, "(DocComplete)", "(DocComplete)");
        wfNode_Complete.setDescription(workFlow.getName());
        wfNode_Complete.setEntityType(getEntityType());
        wfNode_Complete.setJoinElement(X_AD_WF_Node.JOINELEMENT_XOR);
        wfNode_Complete.setSplitElement(X_AD_WF_Node.SPLITELEMENT_XOR);
        wfNode_Complete.setAction(X_AD_WF_Node.ACTION_DocumentAction);
        wfNode_Complete.setDocAction(X_AD_WF_Node.DOCACTION_Complete);
        wfNode_Complete.saveEx();
        //	Create Transition For Start Node
        //	For Start
        MWFNodeNext wfNodeNext = new MWFNodeNext(wfNode_Start, wfNode_Prepare.getAD_WF_Node_ID());
        wfNodeNext.setDescription("(Standard Approval)");
        wfNodeNext.setEntityType(getEntityType());
        wfNodeNext.setSeqNo(10);
        wfNodeNext.setIsStdUserWorkflow(true);
        wfNodeNext.saveEx();
        //	For DocAuto
        wfNodeNext = new MWFNodeNext(wfNode_Start, wfNode_Auto.getAD_WF_Node_ID());
        wfNodeNext.setDescription("(Standard Transition)");
        wfNodeNext.setEntityType(getEntityType());
        wfNodeNext.setSeqNo(100);
        wfNodeNext.setIsStdUserWorkflow(false);
        wfNodeNext.saveEx();
        //	Create Transition For Prepare Node
        //	For DocComplete
        wfNodeNext = new MWFNodeNext(wfNode_Prepare, wfNode_Complete.getAD_WF_Node_ID());
        wfNodeNext.setDescription("(Standard Transition)");
        wfNodeNext.setEntityType(getEntityType());
        wfNodeNext.setSeqNo(100);
        wfNodeNext.setIsStdUserWorkflow(false);
        wfNodeNext.saveEx();
    }
    //	Create Standard Process for Document Action
    int m_AD_Process_ID = MProcess.getProcess_ID(getTableName() + "_Process", get_TrxName());
    if (m_AD_Process_ID <= 0) {
        MProcess workFlowProcess = new MProcess(getCtx(), 0, get_TrxName());
        workFlowProcess.setValue(getTableName() + "_Process");
        workFlowProcess.setName("Process " + getName());
        workFlowProcess.setEntityType(getEntityType());
        workFlowProcess.setAccessLevel(getAccessLevel());
        workFlowProcess.setAD_Workflow_ID(workFlow.getAD_Workflow_ID());
        workFlowProcess.saveEx();
        //	Default Return
        return workFlowProcess.getAD_Process_ID();
    }
    //	Default Return
    return m_AD_Process_ID;
}
Also used : MWorkflow(org.compiere.wf.MWorkflow) MWFNode(org.compiere.wf.MWFNode) MWFNodeNext(org.compiere.wf.MWFNodeNext)

Example 32 with MWorkflow

use of org.compiere.wf.MWorkflow in project adempiere by adempiere.

the class MPPMRP method createMOMakeTo.

public static MPPOrder createMOMakeTo(MOrderLine orderLine, BigDecimal qty) {
    MPPOrder order = MPPOrder.forC_OrderLine_ID(orderLine.getCtx(), orderLine.getC_OrderLine_ID(), orderLine.getM_Product_ID(), orderLine.get_TrxName());
    if (order == null) {
        //Search Plant for this Warehouse
        int plantId = 0;
        plantId = MPPProductPlanning.getPlantForWarehouse(orderLine.getM_Warehouse_ID());
        if (plantId <= 0)
            throw new NoPlantForWarehouseException(orderLine.getM_Warehouse_ID());
        final MProduct product = MProduct.get(orderLine.getCtx(), orderLine.getM_Product_ID());
        final String whereClause = MPPProductBOM.COLUMNNAME_BOMType + " IN (?,?)" + " AND " + MPPProductBOM.COLUMNNAME_BOMUse + "=?" + " AND " + MPPProductBOM.COLUMNNAME_Value + "=?";
        //Search standard BOM
        MPPProductBOM bom = new Query(orderLine.getCtx(), MPPProductBOM.Table_Name, whereClause, orderLine.get_TrxName()).setClient_ID().setParameters(MPPProductBOM.BOMTYPE_Make_To_Order, MPPProductBOM.BOMTYPE_Make_To_Kit, MPPProductBOM.BOMUSE_Manufacturing, product.getValue()).firstOnly();
        //Search workflow standard
        MWorkflow workflow = null;
        int workflowId = MWorkflow.getWorkflowSearchKey(product);
        if (workflowId > 0)
            workflow = MWorkflow.get(orderLine.getCtx(), workflowId);
        MPPProductPlanning productPlanning = null;
        //Search planning data if no exist BOM or Workflow Standard
        if (bom == null || workflow == null) {
            productPlanning = MPPProductPlanning.find(orderLine.getCtx(), orderLine.getAD_Org_ID(), orderLine.getM_Warehouse_ID(), plantId, orderLine.getM_Product_ID(), orderLine.get_TrxName());
            if (productPlanning == null)
                throw new AdempiereException("@NotFound@ @PP_Product_Planning_ID@");
        }
        //Validate BOM
        if (bom == null && productPlanning != null) {
            bom = new MPPProductBOM(orderLine.getCtx(), productPlanning.getPP_Product_BOM_ID(), orderLine.get_TrxName());
            if (bom != null && !MPPProductBOM.BOMTYPE_Make_To_Order.equals(bom.getBOMType()) && !MPPProductBOM.BOMTYPE_Make_To_Kit.equals(bom.getBOMType())) {
                throw new AdempiereException("@NotFound@ @PP_ProductBOM_ID@");
            }
        }
        if (workflow == null && productPlanning != null) {
            //Validate the workflow based in planning data 						
            workflow = new MWorkflow(orderLine.getCtx(), productPlanning.getAD_Workflow_ID(), orderLine.get_TrxName());
            if (workflow == null) {
                throw new AdempiereException("@NotFound@ @AD_Workflow_ID@");
            }
        }
        if (plantId > 0 && workflow != null) {
            String description = Msg.translate(orderLine.getCtx(), MRefList.getListName(orderLine.getCtx(), MPPOrderBOM.BOMTYPE_AD_Reference_ID, bom.getBOMType())) + " " + Msg.translate(orderLine.getCtx(), MOrder.COLUMNNAME_C_Order_ID) + " : " + orderLine.getParent().getDocumentNo();
            // Create temporary data planning to create Manufacturing Order
            productPlanning = new MPPProductPlanning(orderLine.getCtx(), 0, orderLine.get_TrxName());
            productPlanning.setAD_Org_ID(orderLine.getAD_Org_ID());
            productPlanning.setM_Product_ID(product.getM_Product_ID());
            productPlanning.setPlanner_ID(orderLine.getParent().getSalesRep_ID());
            productPlanning.setPP_Product_BOM_ID(bom.getPP_Product_BOM_ID());
            productPlanning.setAD_Workflow_ID(workflow.getAD_Workflow_ID());
            productPlanning.setM_Warehouse_ID(orderLine.getM_Warehouse_ID());
            productPlanning.setS_Resource_ID(plantId);
            order = MPPMRP.createMO(productPlanning, orderLine.getC_OrderLine_ID(), orderLine.getM_AttributeSetInstance_ID(), qty, orderLine.getDateOrdered(), orderLine.getDatePromised(), description);
            description = "";
            if (orderLine.getDescription() != null)
                description = orderLine.getDescription();
            description = description + " " + Msg.translate(orderLine.getCtx(), MRefList.getListName(orderLine.getCtx(), MPPOrderBOM.BOMTYPE_AD_Reference_ID, bom.getBOMType())) + " " + Msg.translate(orderLine.getCtx(), MPPOrder.COLUMNNAME_PP_Order_ID) + " : " + order.getDocumentNo();
            orderLine.setDescription(description);
            orderLine.saveEx();
        }
    } else {
        if (!order.isProcessed()) {
            //if you chance product in order line the Manufacturing order is void
            if (order.getM_Product_ID() != orderLine.getM_Product_ID()) {
                order.setDescription("");
                order.setQtyEntered(Env.ZERO);
                order.setC_OrderLine_ID(0);
                order.voidIt();
                order.setDocStatus(MPPOrder.DOCSTATUS_Voided);
                order.setDocAction(MPPOrder.ACTION_None);
                order.save();
                orderLine.setDescription("");
                orderLine.saveEx();
            }
            if (order.getQtyEntered().compareTo(orderLine.getQtyEntered()) != 0) {
                order.setQty(orderLine.getQtyEntered());
                order.saveEx();
            }
            if (order.getDatePromised().compareTo(orderLine.getDatePromised()) != 0) {
                order.setDatePromised(orderLine.getDatePromised());
                order.saveEx();
            }
        }
    }
    return order;
}
Also used : MProduct(org.compiere.model.MProduct) Query(org.compiere.model.Query) AdempiereException(org.adempiere.exceptions.AdempiereException) MWorkflow(org.compiere.wf.MWorkflow) NoPlantForWarehouseException(org.eevolution.exceptions.NoPlantForWarehouseException)

Example 33 with MWorkflow

use of org.compiere.wf.MWorkflow in project adempiere by adempiere.

the class MPPMRP method createMO.

/**
	 * Create Manufacturing Order base on Planning Data
	 * @param pp Product Planning 
	 * @param C_OrderLine_ID Sales Order Line
	 * @param M_AttributeSetInstance_ID ASI
	 * @param qty Quantity 
	 * @param dateOrdered Data Ordered
	 * @param datePromised Data Promised
	 * @param description Order Description
	 * @return Manufacturing Order or null
	 */
public static MPPOrder createMO(MPPProductPlanning pp, int C_OrderLine_ID, int M_AttributeSetInstance_ID, BigDecimal qty, Timestamp dateOrdered, Timestamp datePromised, String description) {
    MPPProductBOM bom = pp.getPP_Product_BOM();
    MWorkflow wf = pp.getAD_Workflow();
    if (pp.getS_Resource_ID() > 0 && bom != null && wf != null) {
        //RoutingService routingService = RoutingServiceFactory.get().getRoutingService(pp.getCtx());
        //int duration = routingService.calculateDuration(wf,MResource.get(pp.getCtx(), pp.getS_Resource_ID()),qty).intValueExact(); 
        int duration = MPPMRP.getDurationDays(qty, pp);
        MPPOrder order = new MPPOrder(pp.getCtx(), 0, pp.get_TrxName());
        order.setAD_Org_ID(pp.getAD_Org_ID());
        order.setDescription(description);
        order.setC_OrderLine_ID(C_OrderLine_ID);
        order.setS_Resource_ID(pp.getS_Resource_ID());
        order.setM_Warehouse_ID(pp.getM_Warehouse_ID());
        order.setM_Product_ID(pp.getM_Product_ID());
        order.setM_AttributeSetInstance_ID(M_AttributeSetInstance_ID);
        order.setPP_Product_BOM_ID(pp.getPP_Product_BOM_ID());
        order.setAD_Workflow_ID(pp.getAD_Workflow_ID());
        order.setPlanner_ID(pp.getPlanner_ID());
        order.setLine(10);
        order.setDateOrdered(dateOrdered);
        order.setDatePromised(datePromised);
        order.setDateStartSchedule(TimeUtil.addDays(datePromised, 0 - duration));
        order.setDateFinishSchedule(datePromised);
        order.setC_UOM_ID(pp.getM_Product().getC_UOM_ID());
        order.setQty(qty);
        order.setPriorityRule(MPPOrder.PRIORITYRULE_High);
        order.saveEx();
        order.setDocStatus(order.prepareIt());
        order.setDocAction(MPPOrder.ACTION_Complete);
        order.saveEx();
        return order;
    }
    return null;
}
Also used : MWorkflow(org.compiere.wf.MWorkflow)

Example 34 with MWorkflow

use of org.compiere.wf.MWorkflow in project adempiere by adempiere.

the class DefaultRoutingServiceImpl method calculateDuration.

public BigDecimal calculateDuration(I_AD_Workflow wf, I_S_Resource plant, BigDecimal qty) {
    if (plant == null)
        return Env.ZERO;
    final Properties ctx = ((PO) wf).getCtx();
    final MResourceType S_ResourceType = MResourceType.get(ctx, plant.getS_ResourceType_ID());
    BigDecimal AvailableDayTime = new BigDecimal(S_ResourceType.getTimeSlotHours());
    int AvailableDays = S_ResourceType.getAvailableDaysWeek();
    double durationBaseSec = getDurationBaseSec(wf.getDurationUnit());
    double durationTotal = 0.0;
    MWFNode[] nodes = ((MWorkflow) wf).getNodes(false, Env.getAD_Client_ID(ctx));
    for (I_AD_WF_Node node : nodes) {
        // Qty independent times:
        durationTotal += node.getQueuingTime();
        durationTotal += node.getSetupTime();
        durationTotal += node.getWaitingTime();
        durationTotal += node.getMovingTime();
        // Get OverlapUnits - number of units that must be completed before they are moved the next activity 
        double overlapUnits = qty.doubleValue();
        if (node.getOverlapUnits() > 0 && node.getOverlapUnits() < overlapUnits) {
            overlapUnits = node.getOverlapUnits();
        }
        double durationBeforeOverlap = node.getDuration() * overlapUnits;
        durationTotal += durationBeforeOverlap;
    }
    BigDecimal requiredTime = BigDecimal.valueOf(durationTotal * durationBaseSec / 60 / 60);
    // TODO: implement here, Victor's suggestion - https://sourceforge.net/forum/message.php?msg_id=5179460
    // Weekly Factor  	
    BigDecimal WeeklyFactor = new BigDecimal(7).divide(new BigDecimal(AvailableDays), 8, RoundingMode.UP);
    return (requiredTime.multiply(WeeklyFactor)).divide(AvailableDayTime, 0, RoundingMode.UP);
}
Also used : I_AD_WF_Node(org.compiere.model.I_AD_WF_Node) MWorkflow(org.compiere.wf.MWorkflow) MWFNode(org.compiere.wf.MWFNode) Properties(java.util.Properties) MResourceType(org.compiere.model.MResourceType) BigDecimal(java.math.BigDecimal) PO(org.compiere.model.PO)

Example 35 with MWorkflow

use of org.compiere.wf.MWorkflow in project adempiere by adempiere.

the class WFEditor method load.

private void load(int workflowId) {
    //	Get Workflow
    MWorkflow wf = new MWorkflow(Env.getCtx(), workflowId, null);
    WFNodeContainer nodeContainer = new WFNodeContainer();
    nodeContainer.setWorkflow(wf);
    //	Add Nodes for Paint
    MWFNode[] nodes = wf.getNodes(true, Env.getAD_Client_ID(Env.getCtx()));
    for (int i = 0; i < nodes.length; i++) {
        WFNode wfn = new WFNode(nodes[i]);
        nodeContainer.add(wfn);
        //	Add Lines
        MWFNodeNext[] nexts = nodes[i].getTransitions(Env.getAD_Client_ID(Env.getCtx()));
        for (int j = 0; j < nexts.length; j++) nodeContainer.add(new WFLine(nexts[j]));
    }
    Dimension dimension = nodeContainer.getDimension();
    BufferedImage bi = new BufferedImage(dimension.width + 2, dimension.height + 2, BufferedImage.TYPE_INT_ARGB);
    nodeContainer.paint(bi.createGraphics());
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        ImageIO.write(bi, "png", os);
        AImage imageContent = new AImage("workflow.png", os.toByteArray());
        imageMap.setWidth(dimension.width + "px");
        imageMap.setHeight(dimension.height + "px");
        imageMap.setContent(imageContent);
    } catch (Exception e) {
        logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
}
Also used : MWFNode(org.compiere.wf.MWFNode) MWorkflow(org.compiere.wf.MWorkflow) MWFNode(org.compiere.wf.MWFNode) Dimension(java.awt.Dimension) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MWFNodeNext(org.compiere.wf.MWFNodeNext) BufferedImage(java.awt.image.BufferedImage) WFLine(org.compiere.apps.wf.WFLine) AImage(org.zkoss.image.AImage)

Aggregations

MWorkflow (org.compiere.wf.MWorkflow)36 MWFNode (org.compiere.wf.MWFNode)18 BigDecimal (java.math.BigDecimal)9 ArrayList (java.util.ArrayList)8 MWFNodeNext (org.compiere.wf.MWFNodeNext)7 Query (org.compiere.model.Query)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 HttpSession (javax.servlet.http.HttpSession)4 AdempiereException (org.adempiere.exceptions.AdempiereException)4 BufferedImage (java.awt.image.BufferedImage)3 Properties (java.util.Properties)3 MProduct (org.compiere.model.MProduct)3 Trx (org.compiere.util.Trx)3 MPPProductPlanning (org.eevolution.model.MPPProductPlanning)3 Dimension (java.awt.Dimension)2 RoundingMode (java.math.RoundingMode)2 Arrays (java.util.Arrays)2 List (java.util.List)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 CostDimension (org.adempiere.engine.CostDimension)2