Search in sources :

Example 16 with MResource

use of org.compiere.model.MResource in project adempiere by adempiere.

the class DefaultRoutingServiceImpl method convertDurationToResourceUOM.

protected BigDecimal convertDurationToResourceUOM(BigDecimal duration, int S_Resource_ID, I_AD_WF_Node node) {
    MResource resource = MResource.get(Env.getCtx(), S_Resource_ID);
    I_AD_Workflow wf = MWorkflow.get(Env.getCtx(), node.getAD_Workflow_ID());
    I_C_UOM resourceUOM = MUOM.get(Env.getCtx(), resource.getC_UOM_ID());
    return convertDuration(duration, wf.getDurationUnit(), resourceUOM);
}
Also used : MResource(org.compiere.model.MResource) I_AD_Workflow(org.compiere.model.I_AD_Workflow) I_C_UOM(org.compiere.model.I_C_UOM)

Example 17 with MResource

use of org.compiere.model.MResource in project adempiere by adempiere.

the class DefaultRoutingServiceImpl method getResourceBaseValue.

protected BigDecimal getResourceBaseValue(int S_Resource_ID, I_AD_WF_Node node, I_PP_Cost_Collector cc) {
    if (node == null)
        node = cc.getPP_Order_Node().getAD_WF_Node();
    final Properties ctx = (node instanceof PO ? ((PO) node).getCtx() : Env.getCtx());
    final MResource resource = MResource.get(ctx, S_Resource_ID);
    final MUOM resourceUOM = MUOM.get(ctx, resource.getC_UOM_ID());
    //
    if (isTime(resourceUOM)) {
        BigDecimal duration = calculateDuration(node, cc);
        I_AD_Workflow wf = MWorkflow.get(ctx, node.getAD_Workflow_ID());
        BigDecimal convertedDuration = convertDuration(duration, wf.getDurationUnit(), resourceUOM);
        return convertedDuration;
    } else {
        throw new AdempiereException("@NotSupported@ @C_UOM_ID@ - " + resourceUOM);
    }
}
Also used : MResource(org.compiere.model.MResource) MUOM(org.compiere.model.MUOM) AdempiereException(org.adempiere.exceptions.AdempiereException) Properties(java.util.Properties) I_AD_Workflow(org.compiere.model.I_AD_Workflow) BigDecimal(java.math.BigDecimal) PO(org.compiere.model.PO)

Example 18 with MResource

use of org.compiere.model.MResource 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

MResource (org.compiere.model.MResource)18 Timestamp (java.sql.Timestamp)6 Query (org.compiere.model.Query)4 MPPOrder (org.eevolution.model.MPPOrder)4 JFreeChart (org.jfree.chart.JFreeChart)4 MUOM (org.compiere.model.MUOM)3 MPPOrderNode (org.eevolution.model.MPPOrderNode)3 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 I_AD_Workflow (org.compiere.model.I_AD_Workflow)2 MOrg (org.compiere.model.MOrg)2 MProduct (org.compiere.model.MProduct)2 MResourceType (org.compiere.model.MResourceType)2 MWarehouse (org.compiere.model.MWarehouse)2 MPPOrderWorkflow (org.eevolution.model.MPPOrderWorkflow)2 BOMWrapper (org.eevolution.model.wrapper.BOMWrapper)2 ChartPanel (org.jfree.chart.ChartPanel)2 CategoryDataset (org.jfree.data.category.CategoryDataset)2 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)2