*/
public String generate(IStatusBar statusBar, KeyNamePair docTypeKNPair, String docActionSelected)
{
String info = "";
String trxName = Trx.createTrxName("IVG");
Trx trx = Trx.get(trxName, true); //trx needs to be committed too
setSelectionActive(false); // prevents from being called twice
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)
{
AD_Process_ID = 52002; // C_Invoice_GenerateRMA - org.adempiere.process.InvoiceGenerateRMA
}
else
{
AD_Process_ID = 134; // HARDCODED C_InvoiceCreate
}
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 )
{
String msg = "No Invoices"; // not translated!
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 )
{
String msg = "No Invoices"; // not translated!
info = msg;
log.config(msg);
trx.rollback();
return info;
}
}
ProcessInfo pi = new ProcessInfo ("", AD_Process_ID);