use of org.compiere.print.ReportEngine in project adempiere by adempiere.
the class PrintBOM method print.
/**
* Print result generate for this report
*/
void print() throws Exception {
// Base Language
Language language = Language.getLoginLanguage();
MPrintFormat pf = null;
int pfid = 0;
// get print format for client, else copy system to client
RowSet pfrs = MPrintFormat.getAccessiblePrintFormats(X_RV_PP_Product_BOMLine_Table_ID, -1, null);
pfrs.next();
pfid = pfrs.getInt("AD_PrintFormat_ID");
if (pfrs.getInt("AD_Client_ID") != 0)
pf = MPrintFormat.get(getCtx(), pfid, false);
else
pf = MPrintFormat.copyToClient(getCtx(), pfid, getAD_Client_ID());
pfrs.close();
if (pf == null)
raiseError("Error: ", "No Print Format");
pf.setLanguage(language);
pf.setTranslationLanguage(language);
// query
MQuery query = MQuery.get(getCtx(), AD_PInstance_ID, X_RV_PP_Product_BOMLine_Table_Name);
query.addRestriction("AD_PInstance_ID", MQuery.EQUAL, AD_PInstance_ID);
PrintInfo info = new PrintInfo(X_RV_PP_Product_BOMLine_Table_Name, X_RV_PP_Product_BOMLine_Table_ID, getRecord_ID());
ReportEngine re = new ReportEngine(getCtx(), pf, query, info);
ReportCtl.preview(re);
// records are deleted when process ends
while (re.getView().isDisplayable()) {
Env.sleep(1);
}
}
use of org.compiere.print.ReportEngine in project adempiere by adempiere.
the class VPrintDocument method print.
@Override
public void print(PO document, String printFormantName, int windowNo) {
JFrame window = Env.getWindow(windowNo);
if (ADialog.ask(windowNo, window, "PrintShipments")) {
window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
// see also ProcessDialog.printShipments/Invoices
int retValue = ADialogDialog.A_CANCEL;
do {
String keyColumnName = document.get_KeyColumns()[0];
MPrintFormat format = MPrintFormat.get(Env.getCtx(), MPrintFormat.getPrintFormat_ID(printFormantName, document.get_Table_ID(), 0), false);
MQuery query = new MQuery(document.get_TableName());
query.addRestriction(keyColumnName, MQuery.EQUAL, document.get_ValueAsInt(keyColumnName));
// Engine
PrintInfo info = new PrintInfo(document.get_TableName(), document.get_Table_ID(), document.get_ValueAsInt(keyColumnName));
ReportEngine re = new ReportEngine(Env.getCtx(), format, query, info);
re.print();
new Viewer(re);
ADialogDialog d = new ADialogDialog(window, Env.getHeader(Env.getCtx(), windowNo), Msg.getMsg(Env.getCtx(), "PrintoutOK?"), JOptionPane.QUESTION_MESSAGE);
retValue = d.getReturnCode();
} while (retValue == ADialogDialog.A_CANCEL);
window.setCursor(Cursor.getDefaultCursor());
}
}
use of org.compiere.print.ReportEngine in project adempiere by adempiere.
the class WCollect method printTicketWeb.
/**
* Print Ticket for Web
* @return void
*/
public void printTicketWeb() {
try {
if (posPanel.isToPrint() && posPanel.hasOrder()) {
ReportCtl.startDocumentPrint(0, posPanel.getC_Order_ID(), false);
ReportEngine m_reportEngine = ReportEngine.get(p_ctx, ReportEngine.ORDER, posPanel.getC_Order_ID());
StringWriter sw = new StringWriter();
m_reportEngine.createCSV(sw, '\t', m_reportEngine.getPrintFormat().getLanguage());
byte[] data = sw.getBuffer().toString().getBytes();
AMedia media = new AMedia(m_reportEngine.getPrintFormat().getName() + ".txt", null, "application/octet-stream", data);
posPanel.printFile(media.getByteData(), posPanel.getC_Order_ID());
}
} catch (Exception e) {
log.severe("PrintTicket - Error Printing Ticket");
}
}
use of org.compiere.print.ReportEngine in project adempiere by adempiere.
the class VGenPanel method generateComplete.
/**
* Complete generating shipments/invoices.
* Called from Unlock UI
* @param pi process info
*/
public void generateComplete(ProcessInfo pi) {
// Switch Tabs
tabbedPane.setSelectedIndex(1);
//
ProcessInfoUtil.setLogFromDB(pi);
StringBuffer iText = new StringBuffer();
iText.append("<b>").append(pi.getSummary()).append("</b><br>(").append(Msg.getMsg(Env.getCtx(), genForm.getTitle())).append(")<br>").append(pi.getLogInfo(true));
info.setText(iText.toString());
// Reset Selection
/*
String sql = "UPDATE C_Order SET IsSelected='N' WHERE " + m_whereClause;
int no = DB.executeUpdate(sql, null);
log.config("Reset=" + no);*/
// Get results
int[] ids = pi.getIDs();
if (ids == null || ids.length == 0)
return;
log.config("PrintItems=" + ids.length);
confirmPanelGen.getOKButton().setEnabled(false);
// OK to print
if (ADialog.ask(m_WindowNo, this, genForm.getAskPrintMsg())) {
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
// see also ProcessDialog.printShipments/Invoices
int retValue = ADialogDialog.A_CANCEL;
do {
// Loop through all items
for (int i = 0; i < ids.length; i++) {
int Record_ID = ids[i];
if (genForm.getPrintFormat() != null) {
MPrintFormat format = genForm.getPrintFormat();
MTable table = MTable.get(Env.getCtx(), format.getAD_Table_ID());
MQuery query = new MQuery(table.getTableName());
query.addRestriction(table.getTableName() + "_ID", MQuery.EQUAL, Record_ID);
// Engine
PrintInfo info = new PrintInfo(table.getTableName(), table.get_Table_ID(), Record_ID);
ReportEngine re = new ReportEngine(Env.getCtx(), format, query, info);
re.print();
new Viewer(m_frame.getGraphicsConfiguration(), re);
} else
ReportCtl.startDocumentPrint(genForm.getReportEngineType(), Record_ID, this, Env.getWindowNo(this), true);
}
// Yamel Senih 2015-11-23 FR [ 114 ] Add Supoort to dynamic create from
ADialogDialog d = new ADialogDialog(m_frame.getCFrame(), Env.getHeader(Env.getCtx(), m_WindowNo), Msg.getMsg(Env.getCtx(), "PrintoutOK?"), JOptionPane.QUESTION_MESSAGE);
// End Yamel Senih
retValue = d.getReturnCode();
} while (retValue == ADialogDialog.A_CANCEL);
this.setCursor(Cursor.getDefaultCursor());
}
// OK to print
//
confirmPanelGen.getOKButton().setEnabled(true);
}
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) {
MobileSessionCtx wsc = MobileSessionCtx.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
MobileDoc doc = null;
if (process == null) {
doc = MobileDoc.createWindow("Process Not Found");
} else {
doc = MobileDoc.createWindow(process.getName());
fieldset center = new fieldset();
doc.getBody().addElement(center);
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 = MobileUtil.getParameterAsInt(request, "AD_Table_ID");
int AD_Record_ID = MobileUtil.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 = MobileUtil.streamFile(response, pi.getPDFReport());
//String error = streamResult (request, response, pInstance.getAD_PInstance_ID(), file);
if (error == null)
return;
doc = MobileDoc.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 = MobileUtil.streamFile(response, file);
//String error = streamResult (request, response, pInstance.getAD_PInstance_ID(), file);
if (error == null)
return;
doc = MobileDoc.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());
}
}
}
}
}
try {
MobileUtil.createResponse(request, response, this, null, doc, false);
} catch (IOException e) {
log.info(e.toString());
}
}
Aggregations