use of org.compiere.print.ReportEngine in project adempiere by adempiere.
the class CompletePrintOrder method getReportEngine.
// doIt
/*
* get the a Report Engine Instance using the view table
* @param tableName
*/
private ReportEngine getReportEngine(String formatName, String tableName) {
// Get Format & Data
int format_id = MPrintFormat.getPrintFormat_ID(formatName, MTable.getTable_ID(tableName), getAD_Client_ID());
MPrintFormat format = MPrintFormat.get(getCtx(), format_id, true);
if (format == null) {
addLog("@NotFound@ @AD_PrintFormat_ID@");
return null;
}
// query
MQuery query = new MQuery(tableName);
query.addRestriction("PP_Order_ID", MQuery.EQUAL, p_PP_Order_ID);
// Engine
PrintInfo info = new PrintInfo(tableName, MTable.getTable_ID(tableName), p_PP_Order_ID);
ReportEngine re = new ReportEngine(getCtx(), format, query, info);
return re;
}
use of org.compiere.print.ReportEngine 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.print.ReportEngine in project adempiere by adempiere.
the class WReport method launchReport.
// launchReport
/**
* Launch Report
* @param pf print format
*/
private File launchReport(MPrintFormat pf, HttpServletRequest request, GridTab m_curTab, MQuery m_query) {
int Record_ID = 0;
WebSessionCtx wsc = WebSessionCtx.get(request);
WWindowStatus ws = WWindowStatus.get(request);
//Instance pInstance = new MPInstance (wsc.ctx, 0, 0);
File fileName = null;
if (m_query.getRestrictionCount() == 1 && m_query.getCode(0) instanceof Integer) {
Record_ID = ((Integer) m_query.getCode(0)).intValue();
}
PrintInfo info = new PrintInfo(pf.getName(), pf.getAD_Table_ID(), Record_ID);
info.setDescription(m_query.getInfo());
if (pf != null && pf.getJasperProcess_ID() > 0) {
// It's a report using the JasperReports engine
ProcessInfo pi = new ProcessInfo("", pf.getJasperProcess_ID());
Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
// Execute Process
WProcessCtl.process(this, m_curTab.getAD_Window_ID(), pi, trx, request);
} else {
// It's a default report using the standard printing engine
ReportEngine re = new ReportEngine(wsc.ctx, pf, m_query, info);
if (re == null) {
log.info("Could not start ReportEngine");
} else {
try {
File file = File.createTempFile("WProcess", ".pdf");
boolean ok = re.createPDF(file);
if (ok) {
fileName = file;
} else {
log.info("Could not create Report");
}
} catch (Exception e) {
log.info(e.toString());
}
}
}
return fileName;
}
use of org.compiere.print.ReportEngine 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.print.ReportEngine in project adempiere by adempiere.
the class WHRPayPrint method cmd_print.
// cmd_EFT
/**
* Print Checks and/or Remittance
*/
private void cmd_print() {
if (fPaymentRule.getSelectedItem() == null)
return;
String PaymentRule = fPaymentRule.getSelectedItem().toValueNamePair().getValue();
log.info(PaymentRule);
if (!getChecks(PaymentRule))
return;
// for all checks
List<File> pdfList = new ArrayList<File>();
for (MHRPaySelectionCheck check : m_checks) {
// ReportCtrl will check BankAccountDoc for PrintFormat
ReportEngine re = ReportEngine.get(Env.getCtx(), ReportEngine.HR_CHECK, check.get_ID());
try {
File file = File.createTempFile("WHRPayPrint", null);
re.getPDF(file);
pdfList.add(file);
} catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
return;
}
}
SimplePDFViewer chequeViewer = null;
try {
File outFile = File.createTempFile("WHRPayPrint", null);
AEnv.mergePdf(pdfList, outFile);
chequeViewer = new SimplePDFViewer(form.getFormName(), new FileInputStream(outFile));
chequeViewer.setAttribute(Window.MODE_KEY, Window.MODE_EMBEDDED);
chequeViewer.setWidth("100%");
} catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
return;
}
// Update BankAccountDoc
int lastDocumentNo = MHRPaySelectionCheck.confirmPrint(m_checks, m_batch);
if (lastDocumentNo != 0) {
StringBuffer sb = new StringBuffer();
sb.append("UPDATE C_BankAccountDoc SET CurrentNext=").append(++lastDocumentNo).append(" WHERE C_BankAccount_ID=").append(m_C_BankAccount_ID).append(" AND PaymentRule='").append(PaymentRule).append("'");
DB.executeUpdate(sb.toString(), null);
}
SimplePDFViewer remitViewer = null;
if (FDialog.ask(m_WindowNo, form, "VPayPrintPrintRemittance")) {
pdfList = new ArrayList<File>();
for (MHRPaySelectionCheck check : m_checks) {
ReportEngine re = ReportEngine.get(Env.getCtx(), ReportEngine.HR_REMITTANCE, check.get_ID());
try {
File file = File.createTempFile("WHRPayPrint", null);
re.getPDF(file);
pdfList.add(file);
} catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
try {
File outFile = File.createTempFile("WHRPayPrint", null);
AEnv.mergePdf(pdfList, outFile);
String name = Msg.translate(Env.getCtx(), "Remittance");
remitViewer = new SimplePDFViewer(form.getFormName() + " - " + name, new FileInputStream(outFile));
remitViewer.setAttribute(Window.MODE_KEY, Window.MODE_EMBEDDED);
remitViewer.setWidth("100%");
} catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
dispose();
if (chequeViewer != null)
SessionManager.getAppDesktop().showWindow(chequeViewer);
if (remitViewer != null)
SessionManager.getAppDesktop().showWindow(remitViewer);
}
Aggregations