Search in sources :

Example 6 with MPInstancePara

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

the class Process method fillParameter.

//	createProcessPage
private static MPInstance fillParameter(CompiereService m_cs, DataRow dr, MProcess process) throws Exception {
    MPInstance pInstance = new MPInstance(process, 0);
    DataField[] f = dr.getFieldArray();
    HashMap fmap = new HashMap();
    for (int i = 0; i < f.length; i++) fmap.put(f[i].getColumn(), f[i].getVal());
    //
    MPInstancePara[] iParams = pInstance.getParameters();
    for (int pi = 0; pi < iParams.length; pi++) {
        MPInstancePara iPara = iParams[pi];
        String key = iPara.getParameterName();
        MProcessPara pPara = process.getParameter(key);
        if (pPara == null) {
            log.log(Level.SEVERE, "Parameter not found: " + key);
            continue;
        }
        int displayType = pPara.getAD_Reference_ID();
        String valueString = null;
        Object ob = fmap.get(key);
        if (ob != null)
            valueString = ob.toString();
        String valueString2 = null;
        if (pPara.isRange()) {
            ob = fmap.get(key + "_2");
            if (ob != null)
                valueString2 = ob.toString();
        }
        log.fine("fillParameter - " + key + " = " + valueString);
        Object value = valueString;
        if (valueString != null && valueString.length() == 0)
            value = null;
        if (value != null && (DisplayType.List == displayType || DisplayType.TableDir == displayType || DisplayType.Table == displayType) && value.equals("-1"))
            value = null;
        //	No Value
        if (value == null && DisplayType.YesNo != pPara.getAD_Reference_ID()) {
            if (pPara.isMandatory())
                throw new Exception(" Parameter " + pPara.getName() + " is required.");
        } else {
            //	Convert to Type
            try {
                if (DisplayType.isNumeric(displayType) || DisplayType.isID(displayType)) {
                    BigDecimal bd = null;
                    if (value instanceof BigDecimal)
                        bd = (BigDecimal) value;
                    else if (value instanceof Integer)
                        bd = new BigDecimal(((Integer) value).intValue());
                    else
                        bd = new BigDecimal(value.toString());
                    iPara.setP_Number(bd);
                    log.fine("fillParameter - " + key + " = " + valueString + " (=" + bd + "=)");
                    if (pPara.isRange()) {
                        bd = null;
                        bd = new BigDecimal(valueString2.toString());
                        iPara.setP_Number_To(bd);
                    }
                } else if (DisplayType.isDate(displayType)) {
                    java.util.Date d;
                    if (displayType == DisplayType.DateTime)
                        d = m_cs.dateFormat.parse(value.toString());
                    else
                        // TODO: datetime
                        d = m_cs.dateFormat.parse(value.toString());
                    //d = m_cs.dateTimeFormat.parse(value.toString());
                    Timestamp ts = null;
                    ts = new Timestamp(d.getTime());
                    iPara.setP_Date(ts);
                    if (pPara.isRange()) {
                        if (displayType == DisplayType.DateTime)
                            d = m_cs.dateFormat.parse(valueString2);
                        else //d = m_cs.dateTimeFormat.parse(valueString2);
                        {
                            if (valueString2 == null || valueString2.length() == 0)
                                d = new java.util.Date();
                            else
                                //TODO: datetime
                                d = m_cs.dateFormat.parse(valueString2);
                        }
                        ts = new Timestamp(d.getTime());
                        iPara.setP_Date_To(ts);
                    }
                    log.fine("fillParameter - " + key + " = " + valueString + " (=" + ts + "=)");
                } else if (DisplayType.YesNo == pPara.getAD_Reference_ID()) {
                    String bv = "N";
                    if (value == null)
                        bv = "N";
                    else //if (value.toString().toLowerCase().charAt(0)=='t')
                    {
                        if ("true".equalsIgnoreCase(valueString) || "y".equalsIgnoreCase(valueString))
                            bv = "Y";
                        else
                            bv = "N";
                    }
                    //bv ="Y";
                    iPara.setP_String(bv);
                } else {
                    iPara.setP_String(value.toString());
                }
                if (// kolec - ustawia wartosc dla parametru Lookup
                pPara.isLookup()) {
                    Lookup lok = pPara.getLookup();
                    if (lok != null) {
                        NamePair np = lok.getDirect(value, false, false);
                        if (np != null) {
                            iPara.setInfo(np.getName());
                        }
                    }
                } else {
                    if (value != null)
                        iPara.setInfo(value.toString());
                    if (valueString2 != null)
                        iPara.setInfo_To(valueString2);
                }
                //
                iPara.save();
            } catch (Exception e) {
                log.warning("fillParameter - " + key + " = " + valueString + " (" + value + ") " + value.getClass().getName() + " - " + e.getLocalizedMessage());
            }
        }
    //	not null
    }
    //	instance parameter loop
    // kolec - tego chyba brakowalo
    pInstance.save();
    return pInstance;
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) HashMap(java.util.HashMap) NamePair(org.compiere.util.NamePair) MProcessPara(org.compiere.model.MProcessPara) Timestamp(java.sql.Timestamp) JasperPrint(net.sf.jasperreports.engine.JasperPrint) SQLException(java.sql.SQLException) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) MPInstance(org.compiere.model.MPInstance) DataField(pl.x3E.adInterface.DataField) Lookup(org.compiere.model.Lookup)

Example 7 with MPInstancePara

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

the class ReportProcessor method addProcessParameters.

// runReport   
private void addProcessParameters(int AD_PInstance_ID, Map params) {
    log.finest("ReportStarter.addProcessParameters");
    MPInstance pinstance = new MPInstance(m_ctx, AD_PInstance_ID, null);
    MPInstancePara[] pinstancePara = pinstance.getParameters();
    m_Record_ID = pinstance.getRecord_ID();
    params.put("AD_Client_ID", new Integer(pinstance.getAD_Client_ID()));
    params.put("AD_Org_ID", new Integer(pinstance.getAD_Org_ID()));
    for (int i = 0; i < pinstancePara.length; i++) {
        MPInstancePara para = pinstancePara[i];
        if (para.getInfo() != null) {
            if (para.getInfo_To() != null) {
                params.put(para.getParameterName() + "_Info1", para.getInfo());
                params.put(para.getParameterName() + "_info2", para.getInfo_To());
            } else
                params.put(para.getParameterName() + "_Info", para.getInfo());
        } else {
            params.put(para.getParameterName() + "_Info", "");
            params.put(para.getParameterName() + "_Info1", "");
            params.put(para.getParameterName() + "_info2", "");
        }
        if (para.getP_String() != null) {
            if (para.getP_String_To() != null) {
                params.put(para.getParameterName() + "1", para.getP_String());
                params.put(para.getParameterName() + "2", para.getP_String_To());
            } else
                params.put(para.getParameterName(), para.getP_String());
        } else if (para.getP_Date() != null) {
            if (para.getP_Date() != null) {
                params.put(para.getParameterName() + "1", para.getP_Date());
                params.put(para.getParameterName() + "2", para.getP_Date_To());
            } else
                params.put(para.getParameterName(), para.getP_Date());
        } else if (para.getP_Number() != null) {
            if (para.getP_Number_To() != null && !para.getP_Number_To().equals("")) {
                try {
                    Integer pIntNum = Integer.valueOf(para.getP_Number().toString());
                    Integer pIntNumTo = Integer.valueOf(para.getP_Number_To().toString());
                    params.put(para.getParameterName() + "1", pIntNum);
                    params.put(para.getParameterName() + "2", pIntNumTo);
                } catch (NumberFormatException nfe) {
                    try {
                        Double pDoubleNum = Double.valueOf(para.getP_Number().toString());
                        Double pDoubleNumTo = Double.valueOf(para.getP_Number_To().toString());
                        params.put(para.getParameterName() + "1", pDoubleNum);
                        params.put(para.getParameterName() + "2", pDoubleNumTo);
                    } catch (NumberFormatException nfe2) {
                        params.put(para.getParameterName() + "1", para.getP_Number());
                        params.put(para.getParameterName() + "2", para.getP_Number_To());
                    }
                }
            } else {
                try {
                    Integer pIntNum = Integer.valueOf(para.getP_Number().toString());
                    params.put(para.getParameterName(), pIntNum);
                } catch (NumberFormatException nfe) {
                    try {
                        Double pDoubleNum = Double.valueOf(para.getP_Number().toString());
                        params.put(para.getParameterName(), pDoubleNum);
                    } catch (NumberFormatException nfe2) {
                        params.put(para.getParameterName(), para.getP_Number());
                    }
                }
            }
        }
    }
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) JasperPrint(net.sf.jasperreports.engine.JasperPrint)

Example 8 with MPInstancePara

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

the class InvoiceGenFromShipment method generate.

/**************************************************************************
	 *	Generate Invoices
	 */
public String generate(IStatusBar statusBar, KeyNamePair docTypeKNPair, String docActionSelected) {
    String info = "";
    String trxName = Trx.createTrxName("IVG");
    //trx needs to be committed too
    Trx trx = Trx.get(trxName, true);
    //  prevents from being called twice
    setSelectionActive(false);
    statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InvGenerateGen"));
    statusBar.setStatusDB(String.valueOf(getSelection().size()));
    //	Prepare Process
    int AD_Process_ID = 0;
    if (docTypeKNPair.getKey() == MInOut.Table_ID) {
        // HARDCODED- AD_Process.Value=C_Invoice_Generate_from_Shipment; class=org.adempiere.process.InvoiceGenerateFromShipment
        AD_Process_ID = 53345;
    } else {
    //        	AD_Process_ID = 52002; // AD_Process.Value=C_Invoice_GenerateRMA (Manual); class=org.adempiere.process.InvoiceGenerateRMA
    }
    MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
    if (!instance.save()) {
        info = Msg.getMsg(Env.getCtx(), "ProcessNoInstance");
        return info;
    }
    //insert selection
    StringBuffer insert = new StringBuffer();
    insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
    int counter = 0;
    for (Integer selectedId : getSelection()) {
        counter++;
        if (counter > 1)
            insert.append(" UNION ");
        insert.append("SELECT ");
        insert.append(instance.getAD_PInstance_ID());
        insert.append(", ");
        insert.append(selectedId);
        insert.append(" FROM DUAL ");
        if (counter == 1000) {
            if (DB.executeUpdate(insert.toString(), trxName) < 0) {
                //  not translated!
                String msg = "No Invoices";
                info = msg;
                log.config(msg);
                trx.rollback();
                return info;
            }
            insert = new StringBuffer();
            insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
            counter = 0;
        }
    }
    if (counter > 0) {
        if (DB.executeUpdate(insert.toString(), trxName) < 0) {
            //  not translated!
            String msg = "No Invoices";
            info = msg;
            log.config(msg);
            trx.rollback();
            return info;
        }
    }
    ProcessInfo pi = new ProcessInfo("", AD_Process_ID);
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    //	Add Parameters
    MPInstancePara para = new MPInstancePara(instance, 10);
    para.setParameter("Selection", "Y");
    if (!para.save()) {
        //  not translated
        String msg = "No Selection Parameter added";
        info = msg;
        log.log(Level.SEVERE, msg);
        return info;
    }
    para = new MPInstancePara(instance, 20);
    para.setParameter("DocAction", docActionSelected);
    if (!para.save()) {
        //  not translated
        String msg = "No DocAction Parameter added";
        info = msg;
        log.log(Level.SEVERE, msg);
        return info;
    }
    setTrx(trx);
    setProcessInfo(pi);
    return info;
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) Trx(org.compiere.util.Trx) ProcessInfo(org.compiere.process.ProcessInfo)

Example 9 with MPInstancePara

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

the class ProcessInfoHandler method extractParameters.

protected Hashtable extractParameters() {
    Hashtable param = new Hashtable();
    MPInstancePara p = null;
    int i = 0;
    int b = countParams();
    while (i < b) {
        p = new MPInstancePara(getProcessInstance(), i);
        p.load(null);
        param.put(p.getParameterName(), getValueFrom(p));
        i++;
    }
    return param;
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) Hashtable(java.util.Hashtable)

Example 10 with MPInstancePara

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

the class WProcess method fillParameter.

/**
	 * 	Fill Parameter
	 *	@param request request
	 *	@param process process
	 *	@return process instance
	 */
private MPInstance fillParameter(HttpServletRequest request, MProcess process) {
    MPInstance pInstance = new MPInstance(process, 0);
    //
    MPInstancePara[] iParams = pInstance.getParameters();
    for (int pi = 0; pi < iParams.length; pi++) {
        MPInstancePara iPara = iParams[pi];
        String key = iPara.getParameterName();
        MProcessPara pPara = process.getParameter(key);
        if (pPara == null) {
            log.log(Level.SEVERE, "Parameter not found: " + key);
            continue;
        }
        String valueString = MobileUtil.getParameter(request, key);
        log.fine("fillParameter - " + key + " = " + valueString);
        Object value = valueString;
        if (valueString != null && valueString.length() == 0)
            value = null;
        //	No Value
        if (value == null) {
        //	if (pPara.isMandatory())
        //		log.log(Level.WARNING,"fillParameter - " + key 
        //			+ " - empty - mandatory!");
        } else {
            //	Convert to Type
            try {
                if (DisplayType.isNumeric(pPara.getAD_Reference_ID()) || DisplayType.isID(pPara.getAD_Reference_ID())) {
                    BigDecimal bd = null;
                    if (value instanceof BigDecimal)
                        bd = (BigDecimal) value;
                    else if (value instanceof Integer)
                        bd = new BigDecimal(((Integer) value).intValue());
                    else
                        bd = new BigDecimal(value.toString());
                    iPara.setP_Number(bd);
                    log.fine("fillParameter - " + key + " = " + valueString + " (=" + bd + "=)");
                } else if (DisplayType.isDate(pPara.getAD_Reference_ID())) {
                    Timestamp ts = null;
                    if (value instanceof Timestamp)
                        ts = (Timestamp) value;
                    else
                        ts = Timestamp.valueOf(value.toString());
                    iPara.setP_Date(ts);
                    log.fine("fillParameter - " + key + " = " + valueString + " (=" + ts + "=)");
                } else {
                    if (pPara.getAD_Reference_ID() == DisplayType.YesNo)
                        value = "true".equalsIgnoreCase(value.toString()) ? "Y" : "N";
                    iPara.setP_String(value.toString());
                }
                //
                iPara.saveEx();
            } catch (Exception e) {
                log.warning("fillParameter - " + key + " = " + valueString + " (" + value + ") " + value.getClass().getName() + " - " + e.getLocalizedMessage());
            }
        }
    //	not null
    }
    return pInstance;
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) MProcessPara(org.compiere.model.MProcessPara) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Aggregations

MPInstancePara (org.compiere.model.MPInstancePara)22 MPInstance (org.compiere.model.MPInstance)17 ProcessInfo (org.compiere.process.ProcessInfo)10 Timestamp (java.sql.Timestamp)8 BigDecimal (java.math.BigDecimal)7 Trx (org.compiere.util.Trx)7 SQLException (java.sql.SQLException)4 IOException (java.io.IOException)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 MProcessPara (org.compiere.model.MProcessPara)3 File (java.io.File)2 ServletException (javax.servlet.ServletException)2 JasperPrint (net.sf.jasperreports.engine.JasperPrint)2 ProcessCtl (org.compiere.apps.ProcessCtl)2 GridField (org.compiere.model.GridField)2 MProcess (org.compiere.model.MProcess)2 KeyNamePair (org.compiere.util.KeyNamePair)2 Savepoint (java.sql.Savepoint)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1