Search in sources :

Example 21 with MPInstancePara

use of org.compiere.model.MPInstancePara 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 22 with MPInstancePara

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

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