use of org.compiere.model.MPInstance in project adempiere by adempiere.
the class WProcess method createProcessPage.
// createParameterPage
//Modified by Rob klein 4/29/07
/**************************************************************************
* Create Parocess Page
* @param request request
* @param AD_Process_ID Process
* @return Page
*/
public void createProcessPage(HttpServletRequest request, HttpServletResponse response, int AD_Process_ID, int AD_Window_ID) {
WebSessionCtx wsc = WebSessionCtx.get(request);
MProcess process = MProcess.get(wsc.ctx, AD_Process_ID);
log.info("PI table id " + process.get_Table_ID());
log.info("PI table name id " + process.get_TableName());
log.info("PI table client id " + process.getAD_Client_ID());
log.info("PI table process id " + process.getAD_Process_ID());
log.info("PI process class name " + process.getClassname());
// need to check if Role can access
WebDoc doc = null;
if (process == null) {
doc = WebDoc.createWindow("Process Not Found");
} else {
doc = WebDoc.createWindow(process.getName());
td center = doc.addWindowCenter(false);
if (process.getDescription() != null)
center.addElement(new p(new i(process.getDescription())));
if (process.getHelp() != null)
center.addElement(new p(process.getHelp(), AlignType.LEFT));
// Create Process Instance
MPInstance pInstance = fillParameter(request, process);
//
int AD_Table_ID = WebUtil.getParameterAsInt(request, "AD_Table_ID");
int AD_Record_ID = WebUtil.getParameterAsInt(request, "AD_Record_ID");
ProcessInfo pi = new ProcessInfo(process.getName(), process.getAD_Process_ID(), AD_Table_ID, AD_Record_ID);
pi.setAD_User_ID(Env.getAD_User_ID(wsc.ctx));
pi.setAD_Client_ID(Env.getAD_Client_ID(wsc.ctx));
pi.setClassName(process.getClassname());
log.info("PI client id " + pi.getAD_Client_ID());
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
// Info
p p = new p();
p.addElement(Msg.translate(wsc.ctx, "AD_PInstance_ID") + ": " + pInstance.getAD_PInstance_ID());
center.addElement(p);
// Start
boolean processOK = false;
if (process.isWorkflow()) {
Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
try {
WProcessCtl.process(this, AD_Window_ID, pi, trx, request);
//processOK = process.processIt(pi, trx);
trx.commit();
trx.close();
} catch (Throwable t) {
trx.rollback();
trx.close();
}
if (pi.isError()) {
center.addElement(new p("Error:" + pi.getSummary(), AlignType.LEFT).setClass("Cerror"));
processOK = false;
} else {
center.addElement(new p("OK: Workflow Started", AlignType.LEFT));
processOK = true;
}
center.addElement(new p().addElement(pi.getSummary()));
center.addElement(pi.getLogInfo(true));
}
String jasper = process.getJasperReport();
if (process.isJavaProcess()) {
if (jasper != null) {
pi.setPrintPreview(false);
pi.setIsBatch(true);
}
Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
try {
processOK = process.processIt(pi, trx);
trx.commit();
trx.close();
} catch (Throwable t) {
trx.rollback();
trx.close();
}
if (!processOK || pi.isError()) {
center.addElement(new p("Error:" + pi.getSummary(), AlignType.LEFT).setClass("Cerror"));
processOK = false;
} else {
if (jasper != null) {
String error = WebUtil.streamFile(response, pi.getPDFReport());
//String error = streamResult (request, response, pInstance.getAD_PInstance_ID(), file);
if (error == null)
return;
doc = WebDoc.create(error);
wsc.ctx.put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
} else {
center.addElement(new p().addElement(pi.getSummary()));
center.addElement(pi.getLogInfo(true));
}
}
}
// Report
if (process.isReport()) //if (processOK && process.isReport())
{
if (jasper == null) {
log.info(response.toString());
ReportEngine re = ReportEngine.get(wsc.ctx, pi);
if (re == null) {
center.addElement(new p("Could not start ReportEngine", AlignType.LEFT).setClass("Cerror"));
} else {
try {
File file = File.createTempFile("WProcess", ".pdf");
boolean ok = re.createPDF(file);
if (ok) {
String error = WebUtil.streamFile(response, file);
//String error = streamResult (request, response, pInstance.getAD_PInstance_ID(), file);
if (error == null)
return;
doc = WebDoc.create(error);
//Modified by Rob Klein 6/1/07
/**
String url = "WProcess?AD_PInstance_ID="
+ pInstance.getAD_PInstance_ID()
+ "&File="
+ URLEncoder.encode(file.getAbsolutePath(), WebEnv.ENCODING);
a link = new a (url, null, a.TARGET_BLANK, process.getName());
center
.addElement(new p()
.addElement("Report created: ")
.addElement(link));
// Marker that Process is OK
* */
wsc.ctx.put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
} else
center.addElement(new p("Could not create Report", AlignType.LEFT).setClass("Cerror"));
} catch (Exception e) {
center.addElement(new p("Could not create Report:", AlignType.LEFT).setClass("Cerror"));
center.addElement(e.toString());
}
}
}
}
}
doc.addPopupClose(wsc.ctx);
try {
WebUtil.createResponse(request, response, this, null, doc, false);
} catch (IOException e) {
log.info(e.toString());
}
}
use of org.compiere.model.MPInstance in project adempiere by adempiere.
the class CostResult method createTrxAndInventoryValuationReport.
void createTrxAndInventoryValuationReport() {
int AD_Process_ID = MProcess.getProcess_ID("Transaction Valuation", trxName);
ProcessInfo pi = new ProcessInfo("Transaction Valuation", AD_Process_ID);
MPInstance instance = new MPInstance(getCtx(), AD_Process_ID, 0);
instance.saveEx();
pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
pi.setAD_Client_ID(Env.getAD_Client_ID(getCtx()));
// Add Parameters
MPInstancePara para = new MPInstancePara(instance, 10);
para.setParameter(MCostDetail.COLUMNNAME_M_Product_ID, product.getM_Product_ID());
para.saveEx();
para = new MPInstancePara(instance, 20);
para.setParameter(MCostDetail.COLUMNNAME_M_CostType_ID, 50000);
para.saveEx();
para = new MPInstancePara(instance, 30);
para.setParameter(MCostDetail.COLUMNNAME_M_CostElement_ID, 100);
para.saveEx();
pi.setTransactionName(trxName);
//ReportCtl.startStandardReport(pi);
ReportEngine re = ReportEngine.get(getCtx(), pi);
File trxValuation = null;
trxValuation = re.getPDF();
AD_Process_ID = MProcess.getProcess_ID("Valuation Effective Date", trxName);
pi = new ProcessInfo("Valuation Effective Date", AD_Process_ID);
instance = new MPInstance(getCtx(), AD_Process_ID, 0);
instance.saveEx();
pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
pi.setAD_Client_ID(Env.getAD_Client_ID(getCtx()));
para = new MPInstancePara(instance, 10);
para.setParameter("DateValue", new Timestamp(System.currentTimeMillis()));
para.saveEx();
// Add Parameters
para = new MPInstancePara(instance, 20);
para.setParameter(MCostDetail.COLUMNNAME_M_Product_ID, product.getM_Product_ID());
para.saveEx();
para = new MPInstancePara(instance, 30);
para.setParameter(MCostDetail.COLUMNNAME_M_CostType_ID, 50000);
para.saveEx();
para = new MPInstancePara(instance, 40);
para.setParameter(MCostDetail.COLUMNNAME_M_CostElement_ID, 100);
para.saveEx();
ValuationEffectiveDate process = new ValuationEffectiveDate();
process.startProcess(getCtx(), pi, Trx.get(trxName, false));
pi.setTransactionName(trxName);
re = ReportEngine.get(getCtx(), pi);
File report = null;
report = re.getPDF();
EMail email = new EMail(getCtx(), "smtp.gmail.com", "victor.perez@e-evolution.com", "victor.perez@e-evolution.com", "Transaction and Inventory Valuation Report Test", "Transaction and Inventory Valuation " + new Timestamp(System.currentTimeMillis()));
email.addAttachment(trxValuation);
email.addAttachment(report);
email.createAuthenticator(Mail, MailPassword);
String msg = email.send();
System.out.println(msg);
}
use of org.compiere.model.MPInstance in project adempiere by adempiere.
the class CostResult method generateHistoryCost.
void generateHistoryCost() {
int AD_Process_ID = MProcess.getProcess_ID("M_CostDetail Generate Cost Transaction", trxName);
ProcessInfo pi = new ProcessInfo("Generate Cost Transaction", AD_Process_ID);
MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
instance.saveEx();
pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
pi.setAD_Client_ID(Env.getAD_Client_ID(Env.getCtx()));
// Add Parameters
MPInstancePara para = new MPInstancePara(instance, 10);
para.setParameter(MCostDetail.COLUMNNAME_C_AcctSchema_ID, Env.getContext(Env.getCtx(), "$C_AcctSchema_ID"));
para.saveEx();
para = new MPInstancePara(instance, 20);
para.setParameter(MCostDetail.COLUMNNAME_M_CostType_ID, 50000);
para.saveEx();
para = new MPInstancePara(instance, 30);
para.setParameter(MCostDetail.COLUMNNAME_M_CostElement_ID, 100);
para.saveEx();
//Add Parameters
para = new MPInstancePara(instance, 40);
para.setParameter(MCostDetail.COLUMNNAME_M_Product_ID, product.getM_Product_ID());
para.saveEx();
para = new MPInstancePara(instance, 50);
para.setParameter(MCostDetail.COLUMNNAME_DateAcct, Timestamp.valueOf("2000-01-01 00:00:00.0"));
para.saveEx();
GenerateCostDetail process = new GenerateCostDetail();
process.startProcess(Env.getCtx(), pi, Trx.get(trxName, false));
}
use of org.compiere.model.MPInstance in project adempiere by adempiere.
the class VInOutInvoiceGen method generateInvoices.
// generateShipments_complete
/**************************************************************************
* Generate Invoices
*/
private void generateInvoices() {
String trxName = Trx.createTrxName("IVG");
//trx needs to be committed too
Trx trx = Trx.get(trxName, true);
//String trxName = null;
//Trx trx = null;
// prevents from being called twice
m_selectionActive = false;
statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InvGenerateGen"));
statusBar.setStatusDB(String.valueOf(selection.size()));
// Prepare Process
int AD_Process_ID = 0;
KeyNamePair docTypeKNPair = (KeyNamePair) cmbDocType.getSelectedItem();
if (docTypeKNPair.getKey() == MRMA.Table_ID) {
// C_Invoice_GenerateRMA - org.adempiere.process.InvoiceGenerateRMA
AD_Process_ID = 52002;
} else {
// HARDCODED C_InvoiceCreate
AD_Process_ID = 134;
}
MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
if (!instance.save()) {
info.setText(Msg.getMsg(Env.getCtx(), "ProcessNoInstance"));
return;
}
//insert selection
/*Selection exist from shipment*/
StringBuffer insert = new StringBuffer();
insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
int counter = 0;
for (Integer selectedId : selection) {
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.setText(msg);
trx.rollback();
return;
}
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.setText(msg);
trx.rollback();
return;
}
}
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.setText(msg);
log.log(Level.SEVERE, msg);
return;
}
para = new MPInstancePara(instance, 20);
para.setParameter("DocAction", "CO");
if (!para.save()) {
// not translated
String msg = "No DocAction Parameter added";
info.setText(msg);
log.log(Level.SEVERE, msg);
return;
}
// Execute Process
ProcessCtl worker = new ProcessCtl(this, Env.getWindowNo(this), pi, trx);
// complete tasks in unlockUI / generateInvoice_complete
worker.start();
}
use of org.compiere.model.MPInstance in project adempiere by adempiere.
the class VInOutInvoiceGen method generateShipments.
// saveSelection
/**************************************************************************
* Generate Shipments
*/
private void generateShipments() {
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);
//String trxName = null;
//Trx trx = null;
// prevents from being called twice
m_selectionActive = false;
statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InOutGenerateGen"));
statusBar.setStatusDB(String.valueOf(selection.size()));
// Prepare Process
int AD_Process_ID = 0;
KeyNamePair docTypeKNPair = (KeyNamePair) cmbDocType.getSelectedItem();
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.setText(Msg.getMsg(Env.getCtx(), "ProcessNoInstance"));
return;
}
//insert selection
StringBuffer insert = new StringBuffer();
insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
int counter = 0;
for (Integer selectedId : selection) {
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.setText(msg);
trx.rollback();
return;
}
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.setText(msg);
trx.rollback();
return;
}
}
//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.setText(msg);
log.log(Level.SEVERE, msg);
return;
}
// Add Parameter - M_Warehouse_ID=x
ip = new MPInstancePara(instance, 20);
ip.setParameter("M_Warehouse_ID", Integer.parseInt(m_M_Warehouse_ID.toString()));
if (!ip.save()) {
// not translated
String msg = "No Parameter added";
info.setText(msg);
log.log(Level.SEVERE, msg);
return;
}
// Execute Process
ProcessCtl worker = new ProcessCtl(this, Env.getWindowNo(this), pi, trx);
// complete tasks in unlockUI / generateShipments_complete
worker.start();
//
}
Aggregations