Search in sources :

Example 11 with MResourceType

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

the class DefaultRoutingServiceImplTest method getCreatePlant.

private I_S_Resource getCreatePlant() {
    final String plantValue = "JUnit_Plant_24x7";
    MResource plant = new Query(getCtx(), MResource.Table_Name, "Value=?", null).setParameters(new Object[] { plantValue }).setClient_ID().firstOnly();
    if (plant == null) {
        plant = new MResource(getCtx(), 0, null);
        plant.setValue(plantValue);
    }
    plant.setName(plantValue);
    plant.setIsManufacturingResource(true);
    plant.setManufacturingResourceType(MResource.MANUFACTURINGRESOURCETYPE_Plant);
    plant.setPlanningHorizon(365);
    plant.setM_Warehouse_ID(getM_Warehouse_ID());
    //
    MResourceType rt = null;
    if (plant.getS_ResourceType_ID() <= 0) {
        rt = new MResourceType(getCtx(), 0, null);
    } else {
        rt = new MResourceType(getCtx(), plant.getS_ResourceType_ID(), null);
    }
    rt.setValue(plantValue);
    rt.setName(plantValue);
    rt.setAllowUoMFractions(true);
    rt.setC_TaxCategory_ID(getC_TaxCategory_ID());
    rt.setM_Product_Category_ID(getM_Product_Category_ID());
    // Hour
    rt.setC_UOM_ID(getC_UOM_ID("HR"));
    rt.setIsDateSlot(false);
    rt.setIsTimeSlot(false);
    rt.setIsSingleAssignment(false);
    rt.saveEx();
    plant.setS_ResourceType_ID(rt.getS_ResourceType_ID());
    //
    plant.saveEx();
    return plant;
}
Also used : MResource(org.compiere.model.MResource) Query(org.compiere.model.Query) MResourceType(org.compiere.model.MResourceType)

Example 12 with MResourceType

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

Aggregations

MResourceType (org.compiere.model.MResourceType)12 Timestamp (java.sql.Timestamp)7 MUOM (org.compiere.model.MUOM)4 BigDecimal (java.math.BigDecimal)3 GregorianCalendar (java.util.GregorianCalendar)3 ArrayList (java.util.ArrayList)2 MResource (org.compiere.model.MResource)2 Query (org.compiere.model.Query)2 CRPException (org.eevolution.exceptions.CRPException)2 MPPOrder (org.eevolution.model.MPPOrder)2 MPPOrderNode (org.eevolution.model.MPPOrderNode)2 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Properties (java.util.Properties)1 I_AD_WF_Node (org.compiere.model.I_AD_WF_Node)1 MProduct (org.compiere.model.MProduct)1 MResourceUnAvailable (org.compiere.model.MResourceUnAvailable)1 PO (org.compiere.model.PO)1 MWFNode (org.compiere.wf.MWFNode)1 MWorkflow (org.compiere.wf.MWorkflow)1