Search in sources :

Example 1 with MResourceType

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

the class CRPDatasetFactory method get.

public static CRPModel get(Timestamp start, Timestamp end, MResource r) {
    MResourceType t = MResourceType.get(Env.getCtx(), r.getS_ResourceType_ID());
    // UOM ID - 'Minutes' is base unit
    final MUOM uom1 = MUOM.get(Env.getCtx(), MUOM.getMinute_UOM_ID(Env.getCtx()));
    // Target UOM is the resource type's UOM
    final MUOM uom2 = MUOM.get(Env.getCtx(), t.getC_UOM_ID());
    CRPDatasetFactory factory = new CRPDatasetFactory() {

        protected BigDecimal convert(BigDecimal minutes) {
            return MUOMConversion.convert(Env.getCtx(), uom1.get_ID(), uom2.get_ID(), minutes);
        }
    };
    factory.generate(start, end, r);
    return factory;
}
Also used : MUOM(org.compiere.model.MUOM) MResourceType(org.compiere.model.MResourceType) BigDecimal(java.math.BigDecimal)

Example 2 with MResourceType

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

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

the class CRP method createDataset.

/**
     * Create Category Dataset based on date start and resource
     * @param start
     * @param resource
     * @return CategoryDataset
     */
protected CategoryDataset createDataset(Timestamp start, MResource resource) {
    GregorianCalendar gc1 = new GregorianCalendar();
    gc1.setTimeInMillis(start.getTime());
    gc1.clear(Calendar.MILLISECOND);
    gc1.clear(Calendar.SECOND);
    gc1.clear(Calendar.MINUTE);
    gc1.clear(Calendar.HOUR_OF_DAY);
    Timestamp date = start;
    String namecapacity = Msg.translate(Env.getCtx(), "Capacity");
    String nameload = Msg.translate(Env.getCtx(), "Load");
    String namesummary = Msg.translate(Env.getCtx(), "Summary");
    MResourceType t = MResourceType.get(Env.getCtx(), resource.getS_ResourceType_ID());
    int days = 1;
    long hours = t.getTimeSlotHours();
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    //		Long Hours = new Long(hours); 			 		 			 
    int C_UOM_ID = DB.getSQLValue(null, "SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? ", resource.getS_Resource_ID());
    MUOM uom = MUOM.get(Env.getCtx(), C_UOM_ID);
    if (!uom.isHour()) {
        return dataset;
    }
    long summary = 0;
    while (days < 32) {
        String day = new String(new Integer(date.getDate()).toString());
        long HoursLoad = getLoad(resource, date).longValue();
        Long Hours = new Long(hours);
        switch(gc1.get(Calendar.DAY_OF_WEEK)) {
            case Calendar.SUNDAY:
                days++;
                if (t.isOnSunday()) {
                    dataset.addValue(hours, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary + Hours.intValue() - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                } else {
                    dataset.addValue(0, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                }
            case Calendar.MONDAY:
                days++;
                if (t.isOnMonday()) {
                    dataset.addValue(hours, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary + Hours.intValue() - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                } else {
                    dataset.addValue(0, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                }
            case Calendar.TUESDAY:
                days++;
                if (t.isOnTuesday()) {
                    dataset.addValue(hours, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary + Hours.intValue() - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                } else {
                    dataset.addValue(0, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                }
            case Calendar.WEDNESDAY:
                days++;
                if (t.isOnWednesday()) {
                    dataset.addValue(hours, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary + Hours.intValue() - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                } else {
                    dataset.addValue(0, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                }
            case Calendar.THURSDAY:
                days++;
                if (t.isOnThursday()) {
                    dataset.addValue(hours, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary + Hours.intValue() - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                } else {
                    dataset.addValue(0, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                }
            case Calendar.FRIDAY:
                days++;
                if (t.isOnFriday()) {
                    dataset.addValue(hours, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary + Hours.intValue() - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                } else {
                    dataset.addValue(0, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                }
            case Calendar.SATURDAY:
                days++;
                if (t.isOnSaturday()) {
                    dataset.addValue(hours, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary + Hours.intValue() - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                } else {
                    dataset.addValue(0, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                }
        }
    }
    return dataset;
}
Also used : MUOM(org.compiere.model.MUOM) GregorianCalendar(java.util.GregorianCalendar) Timestamp(java.sql.Timestamp) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) MResourceType(org.compiere.model.MResourceType)

Example 4 with MResourceType

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

the class CRP method createWeightDataset.

/**
     * Create Category Dataset based on Weight , date start and resource
     * @param start
     * @param resource
     * @return CategoryDataset
     */
protected CategoryDataset createWeightDataset(Timestamp start, MResource rosource) {
    GregorianCalendar gc1 = new GregorianCalendar();
    gc1.setTimeInMillis(start.getTime());
    gc1.clear(Calendar.MILLISECOND);
    gc1.clear(Calendar.SECOND);
    gc1.clear(Calendar.MINUTE);
    gc1.clear(Calendar.HOUR_OF_DAY);
    String namecapacity = Msg.translate(Env.getCtx(), "Capacity");
    String nameload = Msg.translate(Env.getCtx(), "Load");
    String namesummary = Msg.translate(Env.getCtx(), "Summary");
    String namepossiblecapacity = "Possible Capacity";
    MResourceType t = MResourceType.get(Env.getCtx(), rosource.getS_ResourceType_ID());
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    double currentweight = DB.getSQLValue(null, "SELECT SUM( (mo.qtyordered-mo.qtydelivered)*(SELECT mp.weight FROM M_Product mp WHERE  mo.m_product_id=mp.m_product_id )) FROM PP_Order mo WHERE AD_Client_ID=?", rosource.getAD_Client_ID());
    double dailyCapacity = rosource.getDailyCapacity().doubleValue();
    double utilization = rosource.getPercentUtilization().doubleValue();
    double summary = 0;
    int day = 0;
    while (day < 32) {
        day++;
        switch(gc1.get(Calendar.DAY_OF_WEEK)) {
            case Calendar.SUNDAY:
                if (t.isOnSunday()) {
                    currentweight -= (dailyCapacity * utilization) / 100;
                    summary += ((dailyCapacity * utilization) / 100);
                    dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                    dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
                } else {
                    dataset.addValue(0, namepossiblecapacity, new Integer(day));
                    dataset.addValue(0, namecapacity, new Integer(day));
                }
                break;
            case Calendar.MONDAY:
                if (t.isOnMonday()) {
                    currentweight -= (dailyCapacity * utilization) / 100;
                    summary += ((dailyCapacity * utilization) / 100);
                    dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                    dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
                } else {
                    dataset.addValue(0, namepossiblecapacity, new Integer(day));
                    dataset.addValue(0, namecapacity, new Integer(day));
                }
                break;
            case Calendar.TUESDAY:
                if (t.isOnTuesday()) {
                    currentweight -= (dailyCapacity * utilization) / 100;
                    summary += ((dailyCapacity * utilization) / 100);
                    dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                    dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
                } else {
                    dataset.addValue(0, namepossiblecapacity, new Integer(day));
                    dataset.addValue(0, namecapacity, new Integer(day));
                }
                break;
            case Calendar.WEDNESDAY:
                if (t.isOnWednesday()) {
                    currentweight -= (dailyCapacity * utilization) / 100;
                    summary += ((dailyCapacity * utilization) / 100);
                    dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                    dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
                } else {
                    dataset.addValue(0, namepossiblecapacity, new Integer(day));
                    dataset.addValue(0, namecapacity, new Integer(day));
                }
                break;
            case Calendar.THURSDAY:
                if (t.isOnThursday()) {
                    currentweight -= (dailyCapacity * utilization) / 100;
                    summary += ((dailyCapacity * utilization) / 100);
                    dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                    dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
                } else {
                    dataset.addValue(0, namepossiblecapacity, new Integer(day));
                    dataset.addValue(0, namecapacity, new Integer(day));
                }
                break;
            case Calendar.FRIDAY:
                if (t.isOnFriday()) {
                    currentweight -= (dailyCapacity * utilization) / 100;
                    summary += ((dailyCapacity * utilization) / 100);
                    dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                    dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
                } else {
                    dataset.addValue(0, namepossiblecapacity, new Integer(day));
                    dataset.addValue(0, namecapacity, new Integer(day));
                }
                break;
            case Calendar.SATURDAY:
                if (t.isOnSaturday()) {
                    currentweight -= (dailyCapacity * utilization) / 100;
                    summary += ((dailyCapacity * utilization) / 100);
                    dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                    dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
                } else {
                    dataset.addValue(0, namepossiblecapacity, new Integer(day));
                    dataset.addValue(0, namecapacity, new Integer(day));
                }
                break;
        }
        dataset.addValue(currentweight, nameload, new Integer(day));
        dataset.addValue(summary, namesummary, new Integer(day));
        gc1.add(Calendar.DATE, 1);
    }
    return dataset;
}
Also used : GregorianCalendar(java.util.GregorianCalendar) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) MResourceType(org.compiere.model.MResourceType)

Example 5 with MResourceType

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

the class CRPSummary method Summary.

public void Summary(Timestamp start, Timestamp finish, MResource r) {
    GregorianCalendar gc1 = new GregorianCalendar();
    gc1.setTimeInMillis(start.getTime());
    gc1.clear(Calendar.MILLISECOND);
    gc1.clear(Calendar.SECOND);
    gc1.clear(Calendar.MINUTE);
    gc1.clear(Calendar.HOUR_OF_DAY);
    GregorianCalendar gc2 = new GregorianCalendar();
    gc2.setTimeInMillis(finish.getTime());
    gc2.clear(Calendar.MILLISECOND);
    gc2.clear(Calendar.SECOND);
    gc2.clear(Calendar.MINUTE);
    gc2.clear(Calendar.HOUR_OF_DAY);
    MResourceType t = MResourceType.get(Env.getCtx(), r.getS_ResourceType_ID());
    long hours = 0;
    if (t.isTimeSlot())
        hours = getHoursAvailable(t.getTimeSlotStart(), t.getTimeSlotStart());
    else
        hours = 24;
    boolean available = false;
    ArrayList<Col> list = new ArrayList<Col>();
    int col = 0;
    int row = 1;
    int summary = 0;
    Col cols = new Col();
    cols.setFrom("Past Due");
    cols.setTo(start.toString());
    cols.setDays(0);
    cols.setCapacity(0);
    cols.setLoad(0);
    cols.setSummary(0);
    list.add(0, cols);
    col++;
    while (gc1.before(gc2)) {
        gc1.add(Calendar.DATE, 1);
        switch(gc1.get(Calendar.DAY_OF_WEEK)) {
            case Calendar.SUNDAY:
                if (t.isOnSunday())
                    available = true;
                break;
            case Calendar.MONDAY:
                if (t.isOnMonday())
                    available = true;
                break;
            case Calendar.TUESDAY:
                if (t.isOnTuesday())
                    available = true;
                break;
            case Calendar.WEDNESDAY:
                if (t.isOnWednesday())
                    available = true;
                break;
            case Calendar.THURSDAY:
                if (t.isOnThursday())
                    available = true;
                break;
            case Calendar.FRIDAY:
                if (t.isOnFriday())
                    available = true;
                break;
            case Calendar.SATURDAY:
                if (t.isOnSaturday())
                    available = true;
                break;
        }
        if (available) {
            cols = new Col();
            cols.setFrom(gc1.getTime().toString());
            cols.setTo(gc1.getTime().toString());
            cols.setDays(1);
            Long Hours = new Long(hours);
            cols.setCapacity(Hours.intValue());
            int C_UOM_ID = DB.getSQLValue(null, "SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? ", r.getS_Resource_ID());
            MUOM oum = MUOM.get(getCtx(), C_UOM_ID);
            if (oum.isHour()) {
                Timestamp date = new Timestamp(gc1.getTimeInMillis());
                int seconds = getLoad(r.getS_Resource_ID(), date, date);
                cols.setLoad(seconds / 3600);
            }
            cols.setSummary(summary + cols.getDifference());
            summary = cols.getSummary();
            list.add(col, cols);
        }
    }
    col = 0;
    boolean newrow = true;
    Col[] lines = new Col[list.size()];
    //set Title
    for (int z = 0; z <= lines.length; z++) {
    }
    for (int i = 0; i <= lines.length; i++) {
        if (newrow) {
            X_T_MRP_CRP crp = new X_T_MRP_CRP(getCtx(), 0, null);
            crp.setDescription("CRP Resource" + r.getName());
        //crp.setRange00(lines[i].getFrom() + "/" + lines[i].getTo());
        }
        switch(col) {
            case 0:
                col++;
            case 1:
                col++;
            case 2:
                col++;
            case 3:
                col++;
            case 4:
                col++;
            case 5:
                col++;
            case 6:
                col++;
            case 7:
                col++;
            case 8:
                col++;
            case 9:
                col++;
            case 10:
                col++;
            case 11:
                col++;
            case 12:
                col = 0;
                newrow = true;
        }
        col++;
    }
}
Also used : MUOM(org.compiere.model.MUOM) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) X_T_MRP_CRP(org.eevolution.model.X_T_MRP_CRP) MResourceType(org.compiere.model.MResourceType)

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