Search in sources :

Example 6 with MResource

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

the class MRPUpdate method doIt.

//	prepare
/**
	 *  doIT - run process
	 */
protected String doIt() throws Exception {
    String result = null;
    ArrayList<Object> parameters = new ArrayList<Object>();
    StringBuffer whereClause = new StringBuffer(MResource.COLUMNNAME_ManufacturingResourceType + "=? AND AD_Client_ID=?");
    parameters.add(MResource.MANUFACTURINGRESOURCETYPE_Plant);
    parameters.add(m_AD_Client_ID);
    if (p_S_Resource_ID > 0) {
        whereClause.append(" AND S_Resource_ID=?");
        parameters.add(p_S_Resource_ID);
    }
    List<MResource> plants = new Query(getCtx(), MResource.Table_Name, whereClause.toString(), get_TrxName()).setParameters(parameters).list();
    if (plants.size() == 0) {
        // TODO: translate
        throw new AdempiereException("No plants found");
    }
    for (MResource plant : plants) {
        log.info("Run MRP to Plant: " + plant.getName());
        parameters = new ArrayList<Object>();
        whereClause = new StringBuffer("AD_Client_ID=?");
        parameters.add(m_AD_Client_ID);
        if (p_AD_Org_ID > 0) {
            whereClause.append(" AND AD_Org_ID=?");
            parameters.add(p_AD_Org_ID);
        }
        List<MOrg> organizations = new Query(getCtx(), MOrg.Table_Name, whereClause.toString(), get_TrxName()).setParameters(parameters).list();
        for (MOrg organization : organizations) {
            log.info("Run MRP to Organization: " + organization.getName());
            if (p_M_Warehouse_ID == 0) {
                MWarehouse[] ws = MWarehouse.getForOrg(getCtx(), organization.getAD_Org_ID());
                for (MWarehouse w : ws) {
                    log.info("Run MRP to Wharehouse: " + w.getName());
                    deleteRecords(m_AD_Client_ID, organization.getAD_Org_ID(), plant.getS_Resource_ID(), w.getM_Warehouse_ID());
                    createRecords(m_AD_Client_ID, organization.getAD_Org_ID(), plant.getS_Resource_ID(), w.getM_Warehouse_ID());
                    result = result + "<br>finish MRP to Warehouse " + w.getName();
                }
            } else {
                log.info("Run MRP to Wharehouse: " + p_M_Warehouse_ID);
                deleteRecords(m_AD_Client_ID, organization.getAD_Org_ID(), plant.getS_Resource_ID(), p_M_Warehouse_ID);
                createRecords(m_AD_Client_ID, organization.getAD_Org_ID(), plant.getS_Resource_ID(), p_M_Warehouse_ID);
            }
            result = result + "<br>finish MRP to Organization " + organization.getName();
        }
        result = result + "<br>finish MRP to Plant " + plant.getName();
    }
    if (Util.isEmpty(result, true)) {
        // TODO: translate
        return "No records found";
    }
    return Msg.getMsg(getCtx(), "ProcessOK");
}
Also used : MResource(org.compiere.model.MResource) Query(org.compiere.model.Query) ArrayList(java.util.ArrayList) MWarehouse(org.compiere.model.MWarehouse) MOrg(org.compiere.model.MOrg) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 7 with MResource

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

the class MRP method doIt.

protected String doIt() throws Exception {
    parameters = new ArrayList<Object>();
    dd_order_id_cache.clear();
    partner_cache.clear();
    StringBuffer whereClause = new StringBuffer(MResource.COLUMNNAME_ManufacturingResourceType + "=? AND AD_Client_ID=?");
    parameters.add(MResource.MANUFACTURINGRESOURCETYPE_Plant);
    parameters.add(getAD_Client_ID());
    if (getPlant_ID() > 0) {
        whereClause.append(" AND " + MResource.COLUMNNAME_S_Resource_ID + "=?");
        parameters.add(getPlant_ID());
    }
    List<MResource> plants = new Query(getCtx(), MResource.Table_Name, whereClause.toString(), get_TrxName()).setParameters(parameters).list();
    if (plants == null || plants.size() <= 0)
        return MRefList.getListName(getCtx(), MResource.MANUFACTURINGRESOURCETYPE_AD_Reference_ID, "PT") + " @S_Resource_ID@ @NotFound@";
    for (MResource plant : plants) {
        log.info("Run MRP to Plant: " + plant.getName());
        this.Planning_Horizon = TimeUtil.addDays(getToday(), plant.getPlanningHorizon());
        parameters = new ArrayList<Object>();
        whereClause = new StringBuffer("AD_Client_ID=?");
        parameters.add(getAD_Client_ID());
        if (getAD_Org_ID() > 0) {
            whereClause.append(" AND AD_Org_ID=?");
            parameters.add(getAD_Org_ID());
        }
        List<MOrg> orgList = new Query(getCtx(), MOrg.Table_Name, whereClause.toString(), get_TrxName()).setParameters(parameters).list();
        for (MOrg org : orgList) {
            // Set Default Document Type To Requisition
            int AD_User_ID = Env.getAD_User_ID(getCtx());
            docTypeReq_ID = MPPMRP.getDocType(getCtx(), MDocType.DOCBASETYPE_PurchaseRequisition, org.getAD_Org_ID(), AD_User_ID, get_TrxName());
            docTypeMO_ID = MPPMRP.getDocType(getCtx(), MDocType.DOCBASETYPE_ManufacturingOrder, org.getAD_Org_ID(), AD_User_ID, get_TrxName());
            docTypeMF_ID = MPPMRP.getDocType(getCtx(), MDocType.DOCBASETYPE_MaintenanceOrder, org.getAD_Org_ID(), AD_User_ID, get_TrxName());
            docTypeDO_ID = MPPMRP.getDocType(getCtx(), MDocType.DOCBASETYPE_DistributionOrder, org.getAD_Org_ID(), AD_User_ID, get_TrxName());
            log.info("Run MRP to Organization: " + org.getName());
            MWarehouse[] ws;
            if (getM_Warehouse_ID() <= 0) {
                ws = MWarehouse.getForOrg(getCtx(), org.getAD_Org_ID());
            } else {
                ws = new MWarehouse[] { MWarehouse.get(getCtx(), getM_Warehouse_ID()) };
            }
            //
            for (MWarehouse w : ws) {
                // remove using DRP should be executed
                //if(plant.getM_Warehouse_ID() == w.getM_Warehouse_ID() && isRequiredDRP())
                //	continue;
                log.info("Run MRP to Wharehouse: " + w.getName());
                runMRP(getAD_Client_ID(), org.getAD_Org_ID(), plant.getS_Resource_ID(), w.getM_Warehouse_ID());
                StringBuffer resultMsg = new StringBuffer();
                resultMsg.append("<br> <b> @AD_Org_ID@: </b>" + org.getName());
                resultMsg.append("<b>, @M_Warehouse_ID@: </b>" + w.getName());
                resultMsg.append("<b>, @S_Resource_ID@: </b>" + plant.getName());
                resultMsg.append("<hr>");
                resultMsg.append("<br><b>@PP_Order_ID@:</b> " + count_MO);
                resultMsg.append("<br><b>@DD_Order_ID@:</b> " + count_DO);
                resultMsg.append("<br><b>@M_Requisition_ID@:</b> " + count_MR);
                resultMsg.append("<br><b>@AD_Note_ID@:</b> " + count_Msg);
                count_MO = 0;
                count_MR = 0;
                count_DO = 0;
                count_Msg = 0;
                addLog("");
                addLog(resultMsg.toString());
            }
        //resultMsg.append("<br>finish MRP to Organization " +org.getName());
        }
    }
    //
    return "";
}
Also used : MResource(org.compiere.model.MResource) MOrg(org.compiere.model.MOrg) Query(org.compiere.model.Query) MWarehouse(org.compiere.model.MWarehouse)

Example 8 with MResource

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

the class WCRP method onEvent.

@Override
public void onEvent(Event event) throws Exception {
    String cmd = event.getTarget().getId();
    if (cmd.equals(ConfirmPanel.A_OK)) {
        Timestamp date = null;
        if (dateFrom.getValue() != null)
            date = (Timestamp) dateFrom.getValue();
        int S_Resource_ID = 0;
        if (resource.getValue() != null)
            S_Resource_ID = ((Integer) resource.getValue()).intValue();
        if (date != null && S_Resource_ID != 0) {
            MResource r = MResource.get(Env.getCtx(), S_Resource_ID);
            int uom_id = r.getResourceType().getC_UOM_ID();
            MUOM uom = MUOM.get(Env.getCtx(), uom_id);
            CategoryDataset dataset = null;
            if (uom.isHour()) {
                dataset = createDataset(date, r);
            } else {
                dataset = createWeightDataset(date, r);
            }
            String title = r.getName() != null ? r.getName() : "";
            title = title + " " + r.getDescription() != null ? r.getDescription() : "";
            JFreeChart jfreechart = createChart(dataset, title, uom);
            renderChart(jfreechart);
        }
    }
    if (cmd.equals(ConfirmPanel.A_CANCEL)) {
        dispose();
    }
}
Also used : MResource(org.compiere.model.MResource) MUOM(org.compiere.model.MUOM) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) Timestamp(java.sql.Timestamp) JFreeChart(org.jfree.chart.JFreeChart)

Example 9 with MResource

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

the class WCRPDetail method getChartTitle.

private String getChartTitle() {
    MResource r = getResource(resource.getValue());
    String title = r.getName() != null ? r.getName() : "";
    title = title + " " + r.getDescription() != null ? r.getDescription() : "";
    return title;
}
Also used : MResource(org.compiere.model.MResource)

Example 10 with MResource

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

the class CreateRfQAction method createRfQ.

private void createRfQ(DefaultMutableTreeNode node) {
    BOMWrapper bom = (BOMWrapper) node.getUserObject();
    MPPOrder mo = new MPPOrder(Env.getCtx(), bom.getPP_Order_ID(), null);
    MResource r = MResource.get(Env.getCtx(), mo.getS_Resource_ID());
    Calendar cal = Calendar.getInstance();
    MRfQ rfq = new MRfQ(Env.getCtx(), 0, null);
    rfq.setName(Msg.translate(Env.getCtx(), "C_RFQ_ID") + ": " + mo.getDocumentNo() + "_" + r.getName() + " (" + bom.getName() + ")");
    rfq.setC_Currency_ID(Env.getContextAsInt(Env.getCtx(), "$C_Currency_ID"));
    rfq.setQuoteType(MRfQ.QUOTETYPE_QuoteSelectedLines);
    rfq.setDateWorkStart(mo.getDateStartSchedule());
    rfq.setDateWorkComplete(mo.getDateFinishSchedule());
    // process parameters
    rfq.setC_RfQ_Topic_ID(((BigDecimal) getParameterValue("C_RFQ_Topic_ID")).intValue());
    rfq.setSalesRep_ID(((BigDecimal) getParameterValue("SalesRep_ID")).intValue());
    savePO(rfq);
    if (successful()) {
        createRfQLines(rfq.get_ID(), node);
    }
}
Also used : MResource(org.compiere.model.MResource) MRfQ(org.compiere.model.MRfQ) Calendar(java.util.Calendar) BOMWrapper(org.eevolution.model.wrapper.BOMWrapper) MPPOrder(org.eevolution.model.MPPOrder)

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