Search in sources :

Example 61 with Trx

use of org.compiere.util.Trx 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)

Example 62 with Trx

use of org.compiere.util.Trx in project lar_361 by comitsrl.

the class InvoiceGen method generate.

// saveSelection
/**
 ************************************************************************
 *	Generate Invoices
 */
// @emmie custom
public String generate(IStatusBar statusBar, KeyNamePair docTypeKNPair, int C_POS_ID, String docActionSelected) // @emmie custom
{
    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 = PROCESS_C_INVOICE_GENERATERMA_MANUAL;
    } else {
        // HARDCODED    C_InvoiceCreate
        AD_Process_ID = PROCESS_C_INVOICE_GENERATE_MANUAL;
    }
    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;
    }
    // @emmie custom
    para = new MPInstancePara(instance, 30);
    para.setParameter("C_POS_ID", C_POS_ID);
    if (!para.save()) {
        // not translated
        String msg = "No C_POS_ID Parameter added";
        info = msg;
        log.log(Level.SEVERE, msg);
        return info;
    }
    // @emmie custom
    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

Trx (org.compiere.util.Trx)62 SQLException (java.sql.SQLException)21 ProcessInfo (org.compiere.process.ProcessInfo)17 AdempiereException (org.adempiere.exceptions.AdempiereException)13 MPInstance (org.compiere.model.MPInstance)12 DBException (org.adempiere.exceptions.DBException)11 Timestamp (java.sql.Timestamp)9 File (java.io.File)8 Connection (java.sql.Connection)8 Properties (java.util.Properties)8 MPInstancePara (org.compiere.model.MPInstancePara)8 PreparedStatement (java.sql.PreparedStatement)7 ResultSet (java.sql.ResultSet)7 BigDecimal (java.math.BigDecimal)6 IOException (java.io.IOException)5 CConnection (org.compiere.db.CConnection)5 MTable (org.compiere.model.MTable)5 PO (org.compiere.model.PO)5 SimpleDateFormat (java.text.SimpleDateFormat)4 ServletException (javax.servlet.ServletException)4