use of org.compiere.model.PrintInfo in project adempiere by adempiere.
the class ReportEngine method get.
/**************************************************************************
* Get Report Engine for process info
* @param ctx context
* @param pi process info with AD_PInstance_ID
* @return report engine or null
*/
public static ReportEngine get(Properties ctx, ProcessInfo pi) {
int AD_Client_ID = pi.getAD_Client_ID();
//
int AD_Table_ID = 0;
int AD_ReportView_ID = 0;
String TableName = null;
String whereClause = "";
int AD_PrintFormat_ID = 0;
boolean IsForm = false;
int Client_ID = -1;
// Get AD_Table_ID and TableName
String sql = "SELECT rv.AD_ReportView_ID,rv.WhereClause," + " t.AD_Table_ID,t.TableName, pf.AD_PrintFormat_ID, pf.IsForm, pf.AD_Client_ID " + "FROM AD_PInstance pi" + " INNER JOIN AD_Process p ON (pi.AD_Process_ID=p.AD_Process_ID)" + " INNER JOIN AD_ReportView rv ON (p.AD_ReportView_ID=rv.AD_ReportView_ID)" + " INNER JOIN AD_Table t ON (rv.AD_Table_ID=t.AD_Table_ID)" + " LEFT OUTER JOIN AD_PrintFormat pf ON (p.AD_ReportView_ID=pf.AD_ReportView_ID AND pf.AD_Client_ID IN (0,?)) " + // #2
"WHERE pi.AD_PInstance_ID=? " + // own first
"ORDER BY pf.AD_Client_ID DESC, pf.IsDefault DESC";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Client_ID);
pstmt.setInt(2, pi.getAD_PInstance_ID());
rs = pstmt.executeQuery();
// Just get first
if (rs.next()) {
// required
AD_ReportView_ID = rs.getInt(1);
whereClause = rs.getString(2);
if (rs.wasNull())
whereClause = "";
whereClause = Env.parseContext(ctx, 0, whereClause, false);
//
AD_Table_ID = rs.getInt(3);
// required for query
TableName = rs.getString(4);
// required
AD_PrintFormat_ID = rs.getInt(5);
// required
IsForm = "Y".equals(rs.getString(6));
Client_ID = rs.getInt(7);
}
} catch (SQLException e1) {
log.log(Level.SEVERE, "(1) - " + sql, e1);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
// Nothing found
if (AD_ReportView_ID == 0) {
// Check Print format in Report Directly
sql = "SELECT t.AD_Table_ID,t.TableName, pf.AD_PrintFormat_ID, pf.IsForm " + "FROM AD_PInstance pi" + " INNER JOIN AD_Process p ON (pi.AD_Process_ID=p.AD_Process_ID)" + " INNER JOIN AD_PrintFormat pf ON (p.AD_PrintFormat_ID=pf.AD_PrintFormat_ID)" + " INNER JOIN AD_Table t ON (pf.AD_Table_ID=t.AD_Table_ID) " + "WHERE pi.AD_PInstance_ID=?";
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, pi.getAD_PInstance_ID());
rs = pstmt.executeQuery();
if (rs.next()) {
whereClause = "";
AD_Table_ID = rs.getInt(1);
// required for query
TableName = rs.getString(2);
// required
AD_PrintFormat_ID = rs.getInt(3);
// required
IsForm = "Y".equals(rs.getString(4));
Client_ID = AD_Client_ID;
}
} catch (SQLException e1) {
log.log(Level.SEVERE, "(2) - " + sql, e1);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
if (AD_PrintFormat_ID == 0) {
log.log(Level.SEVERE, "Report Info NOT found AD_PInstance_ID=" + pi.getAD_PInstance_ID() + ",AD_Client_ID=" + AD_Client_ID);
return null;
}
}
// Create Query from Parameters
MQuery query = null;
if (// Form = one record
IsForm && pi.getRecord_ID() != 0 && // Not temporary table - teo_sarca, BF [ 2828886 ]
!TableName.startsWith("T_")) {
MTable table = MTable.get(ctx, AD_Table_ID);
String columnKey = null;
if (table.isSingleKey())
columnKey = table.getKeyColumns()[0];
else
columnKey = TableName + "_ID";
query = MQuery.getEqualQuery(columnKey, pi.getRecord_ID());
} else {
query = MQuery.get(ctx, pi.getAD_PInstance_ID(), TableName);
}
// Add to static where clause from ReportView
if (whereClause.length() != 0)
query.addRestriction(whereClause);
// Get Print Format
MPrintFormat format = null;
Object so = pi.getSerializableObject();
if (so instanceof MPrintFormat)
format = (MPrintFormat) so;
if (format == null && AD_PrintFormat_ID != 0) {
// We have a PrintFormat with the correct Client
if (Client_ID == AD_Client_ID)
format = MPrintFormat.get(ctx, AD_PrintFormat_ID, false);
else
format = MPrintFormat.copyToClient(ctx, AD_PrintFormat_ID, AD_Client_ID);
}
if (format != null && format.getItemCount() == 0) {
log.info("No Items - recreating: " + format);
format.delete(true);
format = null;
}
// Create Format
if (format == null && AD_ReportView_ID != 0)
format = MPrintFormat.createFromReportView(ctx, AD_ReportView_ID, pi.getTitle());
if (format == null)
return null;
format.setTranslationLanguage(format.getLanguage());
//
PrintInfo info = new PrintInfo(pi);
info.setAD_Table_ID(AD_Table_ID);
// FR [ 295 ]
ReportEngine re = new ReportEngine(ctx, format, query, info, pi.getTransactionName());
// Set Process Information
re.setProcessInfo(pi);
return re;
}
use of org.compiere.model.PrintInfo in project adempiere by adempiere.
the class ServerReportCtl method startFinReport.
// startStandardReport
/**
* Start Financial Report.
* @param pi Process Info
* @return true if OK
*/
public static boolean startFinReport(ProcessInfo pi) {
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
// Create Query from Parameters
String TableName = pi.getAD_Process_ID() == 202 ? "T_Report" : "T_ReportStatement";
MQuery query = MQuery.get(Env.getCtx(), pi.getAD_PInstance_ID(), TableName);
// Get PrintFormat
MPrintFormat format = (MPrintFormat) pi.getTransientObject();
if (format == null)
format = (MPrintFormat) pi.getSerializableObject();
if (format == null) {
s_log.log(Level.SEVERE, "startFinReport - No PrintFormat");
return false;
}
PrintInfo printInfo = new PrintInfo(pi);
ReportEngine reportEngine = new ReportEngine(Env.getCtx(), format, query, printInfo);
createOutput(reportEngine, null);
return true;
}
use of org.compiere.model.PrintInfo 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.model.PrintInfo in project adempiere by adempiere.
the class VOrderDistributionReceipt method generateMovements_complete.
/**
* Complete generating movements.
* @param movement
*/
private void generateMovements_complete(MMovement movement) {
// Switch Tabs
tabbedPane.setSelectedIndex(1);
StringBuffer iText = new StringBuffer();
iText.append("<b>").append("").append("</b><br>").append(Msg.translate(Env.getCtx(), "DocumentNo") + " : " + movement.getDocumentNo()).append("<br>").append("");
info.setText(iText.toString());
confirmPanelGen.getOKButton().setEnabled(false);
// OK to print shipments
if (ADialog.ask(m_WindowNo, this, "PrintShipments")) {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
// see also ProcessDialog.printShipments/Invoices
int retValue = ADialogDialog.A_CANCEL;
do {
MPrintFormat format = MPrintFormat.get(Env.getCtx(), MPrintFormat.getPrintFormat_ID("Inventory Move Hdr (Example)", MMovement.Table_ID, 0), false);
MQuery query = new MQuery(MMovement.Table_Name);
query.addRestriction(MMovement.COLUMNNAME_M_Movement_ID, MQuery.EQUAL, movement.getM_Movement_ID());
// Engine
PrintInfo info = new PrintInfo(MMovement.Table_Name, MMovement.Table_ID, movement.getM_Movement_ID());
ReportEngine re = new ReportEngine(Env.getCtx(), format, query, info);
re.print();
new Viewer(re);
// Yamel Senih FR [ 114 ] 2015-11-23
ADialogDialog d = new ADialogDialog(m_frame.getCFrame(), Env.getHeader(Env.getCtx(), m_WindowNo), Msg.getMsg(Env.getCtx(), "PrintoutOK?"), JOptionPane.QUESTION_MESSAGE);
retValue = d.getReturnCode();
} while (retValue == ADialogDialog.A_CANCEL);
setCursor(Cursor.getDefaultCursor());
}
// OK to print shipments
//
confirmPanelGen.getOKButton().setEnabled(true);
}
use of org.compiere.model.PrintInfo in project adempiere by adempiere.
the class ReportStarter method startProcess.
/**
* Start the process.
* Called then pressing the Process button in R_Request.
* It should only return false, if the function could not be performed
* as this causes the process to abort.
* @author rlemeill
* @param ctx context
* @param pi standard process info
* @param trx
* @return true if success
*/
public boolean startProcess(Properties ctx, ProcessInfo pi, Trx trx) {
processInfo = pi;
String Name = pi.getTitle();
int AD_PInstance_ID = pi.getAD_PInstance_ID();
int Record_ID = pi.getRecord_ID();
log.info("Name=" + Name + " AD_PInstance_ID=" + AD_PInstance_ID + " Record_ID=" + Record_ID);
String trxName = null;
if (trx != null) {
trxName = trx.getTrxName();
}
ReportData reportData = getReportData(pi, trxName);
if (reportData == null) {
reportResult(AD_PInstance_ID, "Can not find report data", trxName);
return false;
}
String reportPath = reportData.getReportFilePath();
if (Util.isEmpty(reportPath, true)) {
reportResult(AD_PInstance_ID, "Can not find report", trxName);
return false;
}
JasperData data = null;
File reportFile = null;
String fileExtension = "";
HashMap<String, Object> params = new HashMap<String, Object>();
addProcessParameters(AD_PInstance_ID, params, trxName);
addProcessInfoParameters(params, pi.getParameter());
reportFile = getReportFile(reportPath, (String) params.get("ReportType"));
if (reportFile == null || reportFile.exists() == false) {
log.severe("No report file found for given type, falling back to " + reportPath);
reportFile = getReportFile(reportPath);
}
if (reportFile == null || reportFile.exists() == false) {
String tmp = "Can not find report file at path - " + reportPath;
log.severe(tmp);
reportResult(AD_PInstance_ID, tmp, trxName);
}
if (reportFile != null) {
data = processReport(reportFile);
if (data.getJasperReport() == null) {
log.severe("Could not load Jasper Report " + reportPath);
return false;
}
fileExtension = reportFile.getName().substring(reportFile.getName().lastIndexOf("."), reportFile.getName().length());
} else {
return false;
}
JasperReport jasperReport = data.getJasperReport();
String jasperName = data.getJasperName();
String name = jasperReport.getName();
File reportDir = data.getReportDir();
// Add reportDir to class path
ClassLoader scl = ClassLoader.getSystemClassLoader();
try {
java.net.URLClassLoader ucl = new java.net.URLClassLoader(new java.net.URL[] { reportDir.toURI().toURL() }, scl);
net.sf.jasperreports.engine.util.JRResourcesUtil.setThreadClassLoader(ucl);
} catch (MalformedURLException me) {
log.warning("Could not add report directory to classpath: " + me.getMessage());
}
if (jasperReport != null) {
File[] subreports;
// Subreports
if (reportPath.startsWith("http://") || reportPath.startsWith("https://")) {
// Locate and download subreports from remote webcontext
subreports = getHttpSubreports(jasperName + "Subreport", reportPath, fileExtension);
} else if (reportPath.startsWith("attachment:")) {
subreports = getAttachmentSubreports(reportPath);
} else if (reportPath.startsWith("resource:")) {
subreports = getResourceSubreports(name + "Subreport", reportPath, fileExtension);
} else // TODO: Implement file:/ lookup for subreports
{
// Locate subreports from local/remote filesystem
subreports = reportDir.listFiles(new FileFilter(jasperName + "Subreport", reportDir, fileExtension));
}
for (int i = 0; i < subreports.length; i++) {
// @Trifon - begin
if (subreports[i].getName().toLowerCase().endsWith(".jasper") || subreports[i].getName().toLowerCase().endsWith(".jrxml")) {
JasperData subData = processReport(subreports[i]);
if (subData.getJasperReport() != null) {
params.put(subData.getJasperName(), subData.getJasperFile().getAbsolutePath());
}
}
// @Trifon - end
}
if (Record_ID > 0)
params.put("RECORD_ID", new Integer(Record_ID));
// contribution from Ricardo (ralexsander)
// in iReports you can 'SELECT' AD_Client_ID, AD_Org_ID and AD_User_ID using only AD_PINSTANCE_ID
params.put("AD_PINSTANCE_ID", new Integer(AD_PInstance_ID));
// FR [3123850] - Add continiuosly needed parameters to Jasper Starter - Carlos Ruiz - GlobalQSS
params.put("AD_CLIENT_ID", new Integer(Env.getAD_Client_ID(Env.getCtx())));
params.put("AD_ROLE_ID", new Integer(Env.getAD_Role_ID(Env.getCtx())));
params.put("AD_USER_ID", new Integer(Env.getAD_User_ID(Env.getCtx())));
Language currLang = Env.getLanguage(Env.getCtx());
String printerName = null;
MPrintFormat printFormat = null;
PrintInfo printInfo = null;
ProcessInfoParameter[] pip = pi.getParameter();
// Get print format and print info parameters
if (pip != null) {
for (int i = 0; i < pip.length; i++) {
if (ServerReportCtl.PARAM_PRINT_FORMAT.equalsIgnoreCase(pip[i].getParameterName())) {
printFormat = (MPrintFormat) pip[i].getParameter();
}
if (ServerReportCtl.PARAM_PRINT_INFO.equalsIgnoreCase(pip[i].getParameterName())) {
printInfo = (PrintInfo) pip[i].getParameter();
}
if (ServerReportCtl.PARAM_PRINTER_NAME.equalsIgnoreCase(pip[i].getParameterName())) {
printerName = (String) pip[i].getParameter();
}
}
}
if (printFormat != null) {
if (printInfo != null) {
// Set the language of the print format if we're printing a document
if (printInfo.isDocument()) {
currLang = printFormat.getLanguage();
}
}
// Set printer name unless already set.
if (printerName == null) {
printerName = printFormat.getPrinterName();
}
}
params.put("CURRENT_LANG", currLang.getAD_Language());
params.put(JRParameter.REPORT_LOCALE, currLang.getLocale());
// Resources
File resFile = null;
if (reportPath.startsWith("attachment:") && attachment != null) {
resFile = getAttachmentResourceFile(jasperName, currLang);
} else if (reportPath.startsWith("resource:")) {
resFile = getResourcesForResourceFile(jasperName, currLang);
// TODO: Implement file:/ for resources
} else {
resFile = new File(jasperName + "_" + currLang.getLocale().getLanguage() + ".properties");
if (!resFile.exists()) {
resFile = null;
}
if (resFile == null) {
resFile = new File(jasperName + ".properties");
if (!resFile.exists()) {
resFile = null;
}
}
}
if (resFile != null) {
try {
PropertyResourceBundle res = new PropertyResourceBundle(new FileInputStream(resFile));
params.put("RESOURCE", res);
} catch (IOException e) {
;
}
}
Connection conn = null;
try {
conn = trx != null ? trx.getConnection() : getConnection();
jasperPrint = JasperFillManager.fillReport(jasperReport, params, conn);
if (reportData.isDirectPrint() && !processInfo.isPrintPreview()) {
log.info("ReportStarter.startProcess print report -" + jasperPrint.getName());
//RF 1906632
if (!processInfo.isBatch()) {
// Get printer job
PrinterJob printerJob = org.compiere.print.CPrinter.getPrinterJob(printerName);
// Set print request attributes
// Paper Attributes:
PrintRequestAttributeSet prats = new HashPrintRequestAttributeSet();
// add: copies, job-name, priority
if (// @Trifon
printInfo == null || printInfo.isDocumentCopy() || printInfo.getCopies() < 1)
prats.add(new Copies(1));
else
prats.add(new Copies(printInfo.getCopies()));
Locale locale = Language.getLoginLanguage().getLocale();
// @Trifon
String printFormat_name = printFormat == null ? "" : printFormat.getName();
int numCopies = printInfo == null ? 0 : printInfo.getCopies();
prats.add(new JobName(printFormat_name + "_" + pi.getRecord_ID(), locale));
prats.add(PrintUtil.getJobPriority(jasperPrint.getPages().size(), numCopies, true));
// Create print service exporter
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
;
// Set parameters
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, printerJob.getPrintService());
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printerJob.getPrintService().getAttributes());
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, prats);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);
// Print report / document
exporter.exportReport();
} else {
// Used For the PH
try {
File PDF = File.createTempFile("mail", ".pdf");
JasperExportManager.exportReportToPdfFile(jasperPrint, PDF.getAbsolutePath());
processInfo.setPDFReport(PDF);
} catch (IOException e) {
log.severe("ReportStarter.startProcess: Can not make PDF File - " + e.getMessage());
}
}
// You can use JasperPrint to create PDF
// JasperExportManager.exportReportToPdfFile(jasperPrint, "BasicReport.pdf");
} else {
log.info("ReportStarter.startProcess run report -" + jasperPrint.getName());
JRViewerProvider viewerLauncher = getReportViewerProvider();
//viewerLauncher.openViewer(jasperPrint, pi.getTitle()+" - " + reportPath);
viewerLauncher.openViewer(jasperPrint, pi.getTitle() + "_" + pi.getRecord_ID() + ".pdf");
}
} catch (JRException e) {
log.severe("ReportStarter.startProcess: Can not run report - " + e.getMessage());
} finally {
if (conn != null && trx == null)
try {
conn.close();
} catch (SQLException e) {
throw new AdempiereException("@Error@ " + e);
}
}
}
reportResult(AD_PInstance_ID, null, trxName);
return true;
}
Aggregations