Search in sources :

Example 31 with MPInstance

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

the class ProcessController method saveParameters.

//	validateParameters
/**
	 * Validate and save parameters if not happened error
	 * @return null if nothing happened
	 */
public String saveParameters() {
    log.config("");
    setIsProcessed(false);
    //	Valid parameters
    String validError = validateParameters();
    if (validError != null)
        return validError;
    //	FR [ 295 ]
    if (processInfo.getAD_PInstance_ID() <= 0) {
        MPInstance instance = null;
        //	Set to null for reload
        //	BR [ 380 ]
        processInfo.setParameter(null);
        try {
            instance = new MPInstance(Env.getCtx(), processInfo.getAD_Process_ID(), processInfo.getRecord_ID());
            instance.saveEx();
            //	Set Instance
            processInfo.setAD_PInstance_ID(instance.getAD_PInstance_ID());
        } catch (Exception e) {
            processInfo.setSummary(e.getLocalizedMessage());
            processInfo.setError(true);
            log.warning(processInfo.toString());
            return processInfo.getSummary();
        }
    }
    /**********************************************************************
		 *	Save Now
		 */
    for (int i = 0; i < getFieldSize(); i++) {
        //	Get Values
        GridField field = (GridField) getField(i);
        GridField fieldTo = (GridField) getFieldTo(i);
        //	FR [ 566 ] Only Information
        if (field.isInfoOnly())
            continue;
        //	Validate
        field.validateValue();
        Object result = getValue(i);
        Object result2 = null;
        if (fieldTo != null) {
            result2 = getValue_To(i);
        }
        //	Create Parameter
        MPInstancePara para = new MPInstancePara(Env.getCtx(), processInfo.getAD_PInstance_ID(), i);
        para.setParameterName(field.getColumnName());
        //	
        if (result instanceof Timestamp || result2 instanceof Timestamp) {
            //	Date
            para.setP_Date((Timestamp) result);
            if (fieldTo != null && result2 != null)
                para.setP_Date_To((Timestamp) result2);
        } else if (result instanceof Integer || result2 instanceof Integer) {
            //	Integer
            if (result != null) {
                Integer ii = (Integer) result;
                para.setP_Number(ii.intValue());
            }
            if (fieldTo != null && result2 != null) {
                Integer ii = (Integer) result2;
                para.setP_Number_To(ii.intValue());
            }
        } else if (result instanceof BigDecimal || result2 instanceof BigDecimal) {
            //	BigDecimal
            para.setP_Number((BigDecimal) result);
            if (fieldTo != null && result2 != null)
                para.setP_Number_To((BigDecimal) result2);
        } else if (result instanceof Boolean) {
            //	Boolean
            Boolean bb = (Boolean) result;
            String value = bb.booleanValue() ? "Y" : "N";
            para.setP_String(value);
        //	to does not make sense
        } else {
            //	String
            if (result != null)
                para.setP_String(result.toString());
            if (fieldTo != null && result2 != null)
                para.setP_String_To(result2.toString());
        }
        //  Info
        para.setInfo(getDisplay(i));
        if (fieldTo != null)
            para.setInfo_To(getDisplay_To(i));
        //
        para.saveEx();
        log.fine(para.toString());
    }
    //	for every parameter
    setIsProcessed(true);
    return null;
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) GridField(org.compiere.model.GridField) Timestamp(java.sql.Timestamp) AdempiereException(org.adempiere.exceptions.AdempiereException) BigDecimal(java.math.BigDecimal)

Example 32 with MPInstance

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

the class ProcessController method createNewInstance.

/**
	 * Create New Instance
	 * @param saveName
	 * @return
	 */
public String createNewInstance(String saveName) {
    String errorMsg = null;
    try {
        MPInstance instance = new MPInstance(Env.getCtx(), processInfo.getAD_Process_ID(), processInfo.getRecord_ID());
        instance.setName(saveName);
        instance.saveEx();
        processInfo.setAD_PInstance_ID(instance.getAD_PInstance_ID());
        //	Get Parameters
        errorMsg = saveParameters();
    } catch (Exception ex) {
        errorMsg = ex.getLocalizedMessage();
        log.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
    //	Default Return
    return errorMsg;
}
Also used : MPInstance(org.compiere.model.MPInstance) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 33 with MPInstance

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

the class EnableNativeSequence method main.

/**
	 * Main test
	 * @param args
	 * @throws Exception 
	 */
public static void main(String[] args) {
    Adempiere.startupEnvironment(true);
    CLogMgt.setLevel(Level.INFO);
    Properties ctx = Env.getCtx();
    // HARDCODED
    int AD_Process_ID = 53156;
    MPInstance pinstance = new MPInstance(ctx, AD_Process_ID, -1);
    pinstance.saveEx();
    ProcessInfo pi = new ProcessInfo("", AD_Process_ID, 0, 0);
    pi.setAD_Client_ID(Env.getAD_Client_ID(ctx));
    pi.setAD_User_ID(Env.getAD_User_ID(ctx));
    pi.setAD_PInstance_ID(pinstance.getAD_PInstance_ID());
    //
    EnableNativeSequence proc = new EnableNativeSequence();
    proc.startProcess(ctx, pi, null);
    if (pi.isError()) {
        throw new AdempiereException(pi.getSummary());
    }
}
Also used : MPInstance(org.compiere.model.MPInstance) AdempiereException(org.adempiere.exceptions.AdempiereException) ProcessInfo(org.compiere.process.ProcessInfo) Properties(java.util.Properties)

Example 34 with MPInstance

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

the class InOutGen method generate.

//	saveSelection
/**************************************************************************
	 *	Generate Shipments
	 */
public String generate(IStatusBar statusBar, KeyNamePair docTypeKNPair, String docActionSelected) {
    String info = "";
    log.info("M_Warehouse_ID=" + m_M_Warehouse_ID);
    String trxName = Trx.createTrxName("IOG");
    //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(), "InOutGenerateGen"));
    statusBar.setStatusDB(String.valueOf(getSelection().size()));
    //	Prepare Process
    int AD_Process_ID = 0;
    if (docTypeKNPair.getKey() == MRMA.Table_ID) {
        // M_InOut_GenerateRMA - org.adempiere.process.InOutGenerateRMA
        AD_Process_ID = 52001;
    } else {
        // M_InOut_Generate - org.compiere.process.InOutGenerate
        AD_Process_ID = 199;
    }
    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 Shipments";
                log.config(msg);
                info = 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 Shipments";
            log.config(msg);
            info = msg;
            trx.rollback();
            return info;
        }
    }
    //call process
    ProcessInfo pi = new ProcessInfo("VInOutGen", AD_Process_ID);
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    //	Add Parameter - Selection=Y
    MPInstancePara ip = new MPInstancePara(instance, 10);
    ip.setParameter("Selection", "Y");
    if (!ip.save()) {
        //  not translated
        String msg = "No Parameter added";
        info = msg;
        log.log(Level.SEVERE, msg);
        return info;
    }
    //Add Document action parameter
    ip = new MPInstancePara(instance, 20);
    //		String docActionSelected = (String)docAction.getValue();
    ip.setParameter("DocAction", docActionSelected);
    if (!ip.save()) {
        String msg = "No DocACtion Parameter added";
        info = msg;
        log.log(Level.SEVERE, msg);
        return info;
    }
    //	Add Parameter - M_Warehouse_ID=x
    ip = new MPInstancePara(instance, 30);
    ip.setParameter("M_Warehouse_ID", Integer.parseInt(m_M_Warehouse_ID.toString()));
    if (!ip.save()) {
        //  not translated
        String msg = "No 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 35 with MPInstance

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

the class InvoiceGen method generate.

//	saveSelection
/**************************************************************************
	 *	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() == MRMA.Table_ID) {
        // C_Invoice_GenerateRMA - org.adempiere.process.InvoiceGenerateRMA
        AD_Process_ID = 52002;
    } else {
        // HARDCODED    C_Invoice_Generate (manual)
        AD_Process_ID = 134;
    }
    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)

Aggregations

MPInstance (org.compiere.model.MPInstance)37 ProcessInfo (org.compiere.process.ProcessInfo)21 MPInstancePara (org.compiere.model.MPInstancePara)19 Trx (org.compiere.util.Trx)12 SQLException (java.sql.SQLException)8 Timestamp (java.sql.Timestamp)8 File (java.io.File)7 AdempiereException (org.adempiere.exceptions.AdempiereException)7 MProcess (org.compiere.model.MProcess)7 IOException (java.io.IOException)6 ReportEngine (org.compiere.print.ReportEngine)6 BigDecimal (java.math.BigDecimal)4 ServletException (javax.servlet.ServletException)4 InvalidClassException (java.io.InvalidClassException)3 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)3 JasperPrint (net.sf.jasperreports.engine.JasperPrint)3 ProcessCtl (org.compiere.apps.ProcessCtl)3 MProcessPara (org.compiere.model.MProcessPara)3 ProcessInfoParameter (org.compiere.process.ProcessInfoParameter)3 PosOrderGlobalVoiding (ar.com.ergio.process.PosOrderGlobalVoiding)2