use of org.compiere.process.ProcessInfo 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;
}
use of org.compiere.process.ProcessInfo in project adempiere by adempiere.
the class Browser method initProcessInfo.
/**
* FR [ 245 ]
* Initialize process info
*/
public void initProcessInfo() {
m_process = MProcess.get(Env.getCtx(), m_Browse.getAD_Process_ID());
browsePI = new ProcessInfo(m_process.getName(), m_Browse.getAD_Process_ID());
browsePI.setAD_User_ID(Env.getAD_User_ID(Env.getCtx()));
browsePI.setAD_Client_ID(Env.getAD_Client_ID(Env.getCtx()));
browsePI.setWindowNo(getWindowNo());
browsePI.setIsSelection(true);
// Copy Values
if (m_pi != null) {
browsePI.setTable_ID(m_pi.getTable_ID());
browsePI.setRecord_ID(m_pi.getRecord_ID());
}
}
use of org.compiere.process.ProcessInfo in project adempiere by adempiere.
the class VBrowser method cmd_Process.
/**
* Process Action
*/
private void cmd_Process() {
m_frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
m_ok = true;
// End Worker
if (m_worker != null) {
// worker continues, but it does not block UI
if (m_worker.isAlive())
m_worker.interrupt();
log.config("Worker alive=" + m_worker.isAlive());
}
m_worker = null;
saveResultSelection(detail);
saveSelection(detail);
// Is Process ok
boolean isOk = false;
// Valid Process, Selected Keys and process parameters
if (getAD_Process_ID() > 0 && getSelectedKeys() != null) {
processParameterPanel.getProcessInfo().setAD_PInstance_ID(-1);
// BR [ 249 ]
if (processParameterPanel.validateParameters() == null) {
// Save Parameters
if (processParameterPanel.saveParameters() == null) {
// Get Process Info
ProcessInfo pi = processParameterPanel.getProcessInfo();
// Set Selected Values
if (getFieldKey() != null && getFieldKey().get_ID() > 0) {
MViewDefinition viewDefinition = (MViewDefinition) getFieldKey().getAD_View_Column().getAD_View_Definition();
pi.setAliasForTableSelection(viewDefinition.getTableAlias());
pi.setTableSelectionId(viewDefinition.getAD_Table_ID());
}
pi.setSelectionValues(getSelectedValues());
//
setBrowseProcessInfo(pi);
// Execute Process
ProcessCtl worker = new ProcessCtl(this, getWindowNo(), pi, null);
//
String msg = Msg.getMsg(Env.getCtx(), "Processing");
// For Dialog
if (m_frame.isDialog()) {
m_waiting = new Waiting(m_frame.getCDialog(), msg, false, getBrowseProcessInfo().getEstSeconds());
} else {
m_waiting = new Waiting(m_frame.getCFrame(), msg, false, getBrowseProcessInfo().getEstSeconds());
}
// complete tasks in unlockUI /
worker.run();
m_waiting.doNotWait();
setStatusLine(pi.getSummary(), pi.isError());
// For Valid Ok
isOk = !pi.isError();
}
}
}
m_frame.setCursor(Cursor.getDefaultCursor());
// For when is ok the process
if (isOk) {
// Close
if (getParentWindowNo() > 0) {
dispose();
return;
}
// Else Reset
p_loadedOK = initBrowser();
collapsibleSearch.setCollapsed(false);
}
}
use of org.compiere.process.ProcessInfo 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;
}
use of org.compiere.process.ProcessInfo in project lar_361 by comitsrl.
the class PosBasePanel method voidDocuments.
/**
* Invoca la anulación de los documentos generados debido a un error en la
* impresión fiscal
*/
private void voidDocuments() {
SwingWorker worker = new SwingWorker() {
private String errorMsg = null;
@Override
public Object construct() {
// Crea parámetro que se enviará al proceso
final ProcessInfoParameter param = new ProcessInfoParameter("C_Order_ID", m_order.getC_Order_ID(), "", "", "");
// Crea información del proceso
int AD_Process_ID = 3000037;
final ProcessInfo pi = new ProcessInfo("PosOrderGlobalVoiding", AD_Process_ID);
pi.setParameter(new ProcessInfoParameter[] { param });
// Crea una instancia de proceso (para registro y sincronizacion)
final MPInstance pinstance = new MPInstance(m_ctx, 0, null);
pinstance.setAD_Process_ID(AD_Process_ID);
pinstance.setRecord_ID(0);
pinstance.save();
// Conecta el proceso con la instancia de proceso
pi.setAD_PInstance_ID(pinstance.get_ID());
// Crea el proceso a ejecutar
final PosOrderGlobalVoiding process = new PosOrderGlobalVoiding();
log.info("Iniciando proceso global de anulaci\u00f3n");
return process.startProcess(m_ctx, pi, null);
}
@Override
public void finished() {
boolean success = (Boolean) getValue();
if (!success) {
ADialog.error(getWindowNo(), PosBasePanel.this, errorMsg);
if (ADialog.ask(getWindowNo(), PosBasePanel.this, Msg.parseTranslation(m_ctx, "@RetryVoidInvoice@"))) {
// Re intenta anular los documentos.
voidDocuments();
} else {
newOrder();
stopGlassPane();
}
} else {
newOrder();
stopGlassPane();
}
}
};
// new SwingWorker
startGlassPane("VoidingInvoice");
worker.start();
}
Aggregations