Search in sources :

Example 1 with MPPOrderWorkflow

use of org.eevolution.model.MPPOrderWorkflow in project adempiere by adempiere.

the class CRPDatasetFactory method getTreeNodeRepresentation.

private String getTreeNodeRepresentation(Timestamp dateTime, DefaultMutableTreeNode node, MResource r) {
    String name = null;
    if (node.getUserObject() instanceof MResource) {
        MResource res = (MResource) node.getUserObject();
        name = res.getName();
    } else if (node.getUserObject() instanceof Timestamp) {
        Timestamp d = (Timestamp) node.getUserObject();
        SimpleDateFormat df = Env.getLanguage(Env.getCtx()).getDateFormat();
        name = df.format(d);
        if (!isAvailable(r, d)) {
            name = "{" + name + "}";
        }
    } else if (node.getUserObject() instanceof MPPOrder) {
        MPPOrder o = (MPPOrder) node.getUserObject();
        MProduct p = MProduct.get(Env.getCtx(), o.getM_Product_ID());
        name = o.getDocumentNo() + " (" + p.getName() + ")";
    } else if (node.getUserObject() instanceof MPPOrderNode) {
        MPPOrderNode on = (MPPOrderNode) node.getUserObject();
        MPPOrderWorkflow owf = on.getMPPOrderWorkflow();
        MResourceType rt = MResourceType.get(Env.getCtx(), r.getS_ResourceType_ID());
        // no function
        //Env.getLanguage(Env.getCtx()).getTimeFormat();
        SimpleDateFormat df = new SimpleDateFormat("HH:mm");
        Timestamp[] interval = getDayBorders(dateTime, on, rt);
        name = df.format(interval[0]) + " - " + df.format(interval[1]) + " " + on.getName() + " (" + owf.getName() + ")";
    }
    return name;
}
Also used : MResource(org.compiere.model.MResource) MPPOrderNode(org.eevolution.model.MPPOrderNode) MProduct(org.compiere.model.MProduct) MPPOrderWorkflow(org.eevolution.model.MPPOrderWorkflow) Timestamp(java.sql.Timestamp) SimpleDateFormat(java.text.SimpleDateFormat) MPPOrder(org.eevolution.model.MPPOrder) MResourceType(org.compiere.model.MResourceType)

Example 2 with MPPOrderWorkflow

use of org.eevolution.model.MPPOrderWorkflow in project adempiere by adempiere.

the class CRP method runCRP.

public void runCRP(MPPOrder order) {
    log.info("PP_Order DocumentNo:" + order.getDocumentNo());
    MPPOrderWorkflow owf = order.getMPPOrderWorkflow();
    if (owf == null) {
        // TODO: generate notice
        addLog("WARNING: No workflow found - " + order);
        return;
    }
    log.info("PP_Order Workflow:" + owf.getName());
    final ArrayList<Integer> visitedNodes = new ArrayList<Integer>();
    // Schedule Fordward
    if (p_ScheduleType.equals(FORWARD_SCHEDULING)) {
        Timestamp date = order.getDateStartSchedule();
        int nodeId = owf.getPP_Order_Node_ID();
        MPPOrderNode node = null;
        while (nodeId != 0) {
            node = owf.getNode(nodeId);
            if (visitedNodes.contains(nodeId)) {
                throw new CRPException("Cyclic transition found").setPP_Order_Node(node);
            }
            visitedNodes.add(nodeId);
            log.info("PP_Order Node:" + node.getName() != null ? node.getName() : "" + " Description:" + node.getDescription() != null ? node.getDescription() : "");
            //
            MResource resource = MResource.get(getCtx(), node.getS_Resource_ID());
            // Skip this node if there is no resource
            if (resource == null) {
                nodeId = owf.getNext(nodeId, getAD_Client_ID());
                continue;
            }
            if (!reasoner.isAvailable(resource)) {
                throw new CRPException("@ResourceNotInSlotDay@").setS_Resource(resource);
            }
            long nodeMillis = calculateMillisFor(node, owf.getDurationBaseSec());
            Timestamp dateFinish = scheduleForward(date, nodeMillis, resource);
            node.setDateStartSchedule(date);
            node.setDateFinishSchedule(dateFinish);
            node.saveEx();
            date = node.getDateFinishSchedule();
            nodeId = owf.getNext(nodeId, getAD_Client_ID());
        }
        // Update order finish date
        if (node != null && node.getDateFinishSchedule() != null) {
            order.setDateFinishSchedule(node.getDateFinishSchedule());
        }
    } else // Schedule backward
    if (p_ScheduleType.equals(BACKWARD_SCHEDULING)) {
        Timestamp date = order.getDateFinishSchedule();
        int nodeId = owf.getNodeLastID(getAD_Client_ID());
        MPPOrderNode node = null;
        while (nodeId != 0) {
            node = owf.getNode(nodeId);
            if (visitedNodes.contains(nodeId)) {
                throw new CRPException("Cyclic transition found - ").setPP_Order_Node(node);
            }
            visitedNodes.add(nodeId);
            log.info("PP_Order Node:" + node.getName() != null ? node.getName() : "" + " Description:" + node.getDescription() != null ? node.getDescription() : "");
            //
            MResource resource = MResource.get(getCtx(), node.getS_Resource_ID());
            // Skip this node if there is no resource
            if (resource == null) {
                nodeId = owf.getPrevious(nodeId, getAD_Client_ID());
                continue;
            }
            if (!reasoner.isAvailable(resource)) {
                throw new CRPException("@ResourceNotInSlotDay@").setS_Resource(resource);
            }
            long nodeMillis = calculateMillisFor(node, owf.getDurationBaseSec());
            Timestamp dateStart = scheduleBackward(date, nodeMillis, resource);
            node.setDateStartSchedule(dateStart);
            node.setDateFinishSchedule(date);
            node.saveEx();
            date = node.getDateStartSchedule();
            nodeId = owf.getPrevious(nodeId, getAD_Client_ID());
        }
        // Update order start date
        if (node != null && node.getDateStartSchedule() != null) {
            order.setDateStartSchedule(node.getDateStartSchedule());
        }
    } else {
        throw new CRPException("Unknown scheduling method - " + p_ScheduleType);
    }
    order.saveEx(get_TrxName());
}
Also used : MResource(org.compiere.model.MResource) MPPOrderNode(org.eevolution.model.MPPOrderNode) ArrayList(java.util.ArrayList) MPPOrderWorkflow(org.eevolution.model.MPPOrderWorkflow) CRPException(org.eevolution.exceptions.CRPException) Timestamp(java.sql.Timestamp)

Aggregations

Timestamp (java.sql.Timestamp)2 MResource (org.compiere.model.MResource)2 MPPOrderNode (org.eevolution.model.MPPOrderNode)2 MPPOrderWorkflow (org.eevolution.model.MPPOrderWorkflow)2 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 MProduct (org.compiere.model.MProduct)1 MResourceType (org.compiere.model.MResourceType)1 CRPException (org.eevolution.exceptions.CRPException)1 MPPOrder (org.eevolution.model.MPPOrder)1