IDEMPIERE-270 Reports should inherit search filter from window

This commit is contained in:
Elaine Tan 2012-09-10 11:30:17 +08:00
parent 4c951dd67d
commit ab31be0c56
7 changed files with 873 additions and 68 deletions

View File

@ -0,0 +1,42 @@
-- Sep 6, 2012 7:37:01 PM SGT
-- IDEMPIERE-270 Reports should inherit search filter from window
INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('I','Current Row Only',200037,'D','fdab48f5-7599-4421-8877-a9b0df4ab6d5','CurrentRowOnly','Y',TO_DATE('2012-09-06 19:36:59','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_DATE('2012-09-06 19:36:59','YYYY-MM-DD HH24:MI:SS'))
;
-- Sep 6, 2012 7:37:01 PM SGT
-- IDEMPIERE-270 Reports should inherit search filter from window
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200037 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID)
;
-- Sep 6, 2012 7:37:21 PM SGT
-- IDEMPIERE-270 Reports should inherit search filter from window
INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('I','All Columns',200038,'D','fdb4bafe-6270-40b1-a6e3-c52a0eaf9292','AllColumns','Y',TO_DATE('2012-09-06 19:37:20','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_DATE('2012-09-06 19:37:20','YYYY-MM-DD HH24:MI:SS'))
;
-- Sep 6, 2012 7:37:21 PM SGT
-- IDEMPIERE-270 Reports should inherit search filter from window
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200038 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID)
;
-- Sep 6, 2012 7:38:06 PM SGT
-- IDEMPIERE-270 Reports should inherit search filter from window
INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Print Format is Mandatory',200039,'D','c5f497b6-fdbd-4773-9710-38f50940c319','PrintFormatMandatory','Y',TO_DATE('2012-09-06 19:38:05','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_DATE('2012-09-06 19:38:05','YYYY-MM-DD HH24:MI:SS'))
;
-- Sep 6, 2012 7:38:06 PM SGT
-- IDEMPIERE-270 Reports should inherit search filter from window
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200039 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID)
;
-- Sep 6, 2012 7:38:23 PM SGT
-- IDEMPIERE-270 Reports should inherit search filter from window
INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Export File of Type is Mandatory',200040,'D','32ee772e-1109-4698-ba38-9f0ba0a6a24a','ExportFileTypeMandatory','Y',TO_DATE('2012-09-06 19:38:23','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_DATE('2012-09-06 19:38:23','YYYY-MM-DD HH24:MI:SS'))
;
-- Sep 6, 2012 7:38:23 PM SGT
-- IDEMPIERE-270 Reports should inherit search filter from window
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200040 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID)
;
SELECT register_migration_script('905_IDEMPIERE-270.sql') FROM dual
;

View File

@ -0,0 +1,42 @@
-- Sep 6, 2012 7:37:01 PM SGT
-- IDEMPIERE-270 Reports should inherit search filter from window
INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('I','Current Row Only',200037,'D','fdab48f5-7599-4421-8877-a9b0df4ab6d5','CurrentRowOnly','Y',TO_TIMESTAMP('2012-09-06 19:36:59','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_TIMESTAMP('2012-09-06 19:36:59','YYYY-MM-DD HH24:MI:SS'))
;
-- Sep 6, 2012 7:37:01 PM SGT
-- IDEMPIERE-270 Reports should inherit search filter from window
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200037 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID)
;
-- Sep 6, 2012 7:37:21 PM SGT
-- IDEMPIERE-270 Reports should inherit search filter from window
INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('I','All Columns',200038,'D','fdb4bafe-6270-40b1-a6e3-c52a0eaf9292','AllColumns','Y',TO_TIMESTAMP('2012-09-06 19:37:20','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_TIMESTAMP('2012-09-06 19:37:20','YYYY-MM-DD HH24:MI:SS'))
;
-- Sep 6, 2012 7:37:21 PM SGT
-- IDEMPIERE-270 Reports should inherit search filter from window
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200038 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID)
;
-- Sep 6, 2012 7:38:06 PM SGT
-- IDEMPIERE-270 Reports should inherit search filter from window
INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Print Format is Mandatory',200039,'D','c5f497b6-fdbd-4773-9710-38f50940c319','PrintFormatMandatory','Y',TO_TIMESTAMP('2012-09-06 19:38:05','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_TIMESTAMP('2012-09-06 19:38:05','YYYY-MM-DD HH24:MI:SS'))
;
-- Sep 6, 2012 7:38:06 PM SGT
-- IDEMPIERE-270 Reports should inherit search filter from window
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200039 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID)
;
-- Sep 6, 2012 7:38:23 PM SGT
-- IDEMPIERE-270 Reports should inherit search filter from window
INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Export File of Type is Mandatory',200040,'D','32ee772e-1109-4698-ba38-9f0ba0a6a24a','ExportFileTypeMandatory','Y',TO_TIMESTAMP('2012-09-06 19:38:23','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_TIMESTAMP('2012-09-06 19:38:23','YYYY-MM-DD HH24:MI:SS'))
;
-- Sep 6, 2012 7:38:23 PM SGT
-- IDEMPIERE-270 Reports should inherit search filter from window
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200040 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID)
;
SELECT register_migration_script('905_IDEMPIERE-270.sql') FROM dual
;

View File

@ -21,15 +21,21 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.sql.RowSet;
import org.adempiere.model.MTabCustomization;
import org.compiere.model.GridField;
import org.compiere.model.GridTab;
import org.compiere.model.GridTable;
import org.compiere.model.MQuery;
import org.compiere.model.MRole;
import org.compiere.model.PO;
import org.compiere.model.X_AD_PrintFormat;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
@ -447,7 +453,145 @@ public class MPrintFormat extends X_AD_PrintFormat
return "NULL";
return value.toString();
} // saveNewSpecial
static public MPrintFormat createFromGridLayout(Properties ctx, GridTab gridTab, boolean allColumns)
{
int AD_Client_ID = Env.getAD_Client_ID(ctx);
MPrintFormat pf = new MPrintFormat(ctx, 0, null);
pf.setAD_Table_ID(gridTab.getAD_Table_ID());
// Get Info
String sql = "SELECT TableName," // 1
+ " (SELECT COUNT(*) FROM AD_PrintFormat x WHERE x.AD_Table_ID=t.AD_Table_ID AND x.AD_Client_ID=c.AD_Client_ID) AS Count,"
+ " COALESCE (cpc.AD_PrintColor_ID, pc.AD_PrintColor_ID) AS AD_PrintColor_ID," // 3
+ " COALESCE (cpf.AD_PrintFont_ID, pf.AD_PrintFont_ID) AS AD_PrintFont_ID,"
+ " COALESCE (cpp.AD_PrintPaper_ID, pp.AD_PrintPaper_ID) AS AD_PrintPaper_ID "
+ "FROM AD_Table t, AD_Client c"
+ " LEFT OUTER JOIN AD_PrintColor cpc ON (cpc.AD_Client_ID=c.AD_Client_ID AND cpc.IsDefault='Y')"
+ " LEFT OUTER JOIN AD_PrintFont cpf ON (cpf.AD_Client_ID=c.AD_Client_ID AND cpf.IsDefault='Y')"
+ " LEFT OUTER JOIN AD_PrintPaper cpp ON (cpp.AD_Client_ID=c.AD_Client_ID AND cpp.IsDefault='Y'),"
+ " AD_PrintColor pc, AD_PrintFont pf, AD_PrintPaper pp "
+ "WHERE t.AD_Table_ID=? AND c.AD_Client_ID=?" // #1/2
+ " AND pc.IsDefault='Y' AND pf.IsDefault='Y' AND pp.IsDefault='Y'";
boolean error = true;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, gridTab.getAD_Table_ID());
pstmt.setInt(2, AD_Client_ID);
rs = pstmt.executeQuery();
if (rs.next())
{
// Name
String TableName = rs.getString(1);
String ColumnName = TableName + "_ID";
String s = ColumnName;
if (!ColumnName.equals("T_Report_ID"))
{
s = Msg.translate (ctx, ColumnName);
if (ColumnName.equals (s)) // not found
s = Msg.translate (ctx, TableName);
}
int count = rs.getInt(2);
if (count > 0)
s += "_" + (count+1);
pf.setName(s);
//
pf.setAD_PrintColor_ID(rs.getInt(3));
pf.setAD_PrintFont_ID(rs.getInt(4));
pf.setAD_PrintPaper_ID(rs.getInt(5));
//
error = false;
}
else
s_log.log(Level.SEVERE, "No info found " + gridTab.getAD_Table_ID());
}
catch (SQLException e)
{
s_log.log(Level.SEVERE, sql, e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
if (error)
return null;
// Save & complete
if (!pf.save())
return null;
GridField[] gridFields = null;
GridTable tableModel = gridTab.getTableModel();
GridField[] tmpFields = tableModel.getFields();
MTabCustomization tabCustomization = MTabCustomization.get(Env.getCtx(), Env.getAD_User_ID(Env.getCtx()), gridTab.getAD_Tab_ID(), null);
if (tabCustomization != null && tabCustomization.getAD_Tab_Customization_ID() > 0
&& tabCustomization.getCustom() != null && tabCustomization.getCustom().trim().length() > 0)
{
String custom = tabCustomization.getCustom().trim();
String[] customComponent = custom.split(";");
String[] fieldIds = customComponent[0].split("[,]");
List<GridField> fieldList = new ArrayList<GridField>();
for(String fieldIdStr : fieldIds)
{
fieldIdStr = fieldIdStr.trim();
if (fieldIdStr.length() == 0) continue;
int AD_Field_ID = Integer.parseInt(fieldIdStr);
for(GridField gridField : tmpFields)
{
if (gridField.getAD_Field_ID() == AD_Field_ID)
{
if(allColumns || gridField.isDisplayedGrid())
fieldList.add(gridField);
break;
}
}
}
gridFields = fieldList.toArray(new GridField[0]);
}
else
{
ArrayList<GridField> gridFieldList = new ArrayList<GridField>();
for(GridField field:tmpFields)
{
if(allColumns || field.isDisplayedGrid())
gridFieldList.add(field);
}
Collections.sort(gridFieldList, new Comparator<GridField>() {
@Override
public int compare(GridField o1, GridField o2) {
return o1.getSeqNoGrid()-o2.getSeqNoGrid();
}
});
gridFields = new GridField[gridFieldList.size()];
gridFieldList.toArray(gridFields);
}
ArrayList<MPrintFormatItem> printFormatItemList = new ArrayList<MPrintFormatItem>();
int seqNo = 1;
for (GridField gridField : gridFields)
{
MPrintFormatItem pfi = MPrintFormatItem.createFromColumn (pf, gridField.getAD_Column_ID(), seqNo++);
if (pfi != null)
{
printFormatItemList.add (pfi);
s_log.finest("Tab: " + pfi);
}
}
MPrintFormatItem[] printFormatItems = new MPrintFormatItem[printFormatItemList.size()];
printFormatItemList.toArray(printFormatItems);
pf.setItems(printFormatItems);
return pf;
}
/**************************************************************************
* Create MPrintFormat for Table

View File

@ -124,6 +124,18 @@ public class ProcessInfo implements Serializable
private boolean m_reportingProcess = false;
//FR 1906632
private File m_pdf_report = null;
/** Record IDs */
private int[] m_Record_IDs;
/** Export */
private boolean m_export = false;
/** Export File Extension */
private String m_exportFileExtension = null;
/** Export File */
private File m_exportFile = null;
/**
* String representation
@ -684,7 +696,69 @@ public class ProcessInfo implements Serializable
public File getPDFReport()
{
return m_pdf_report;
}
}
/**
* Is this a export or print process?
* @return
*/
public boolean isExport()
{
return m_export;
}
/**
* Set Export
* @param export
*/
public void setExport(boolean export)
{
this.m_export = export;
}
/**
* Get Export File Extension
* @param
*/
public String getExportFileExtension()
{
return m_exportFileExtension;
}
/**
* Set Export File Extension
* @param exportFileOfType
*/
public void setExportFileExtension(String exportFileExtension)
{
m_exportFileExtension = exportFileExtension;
}
/**
* Get Export File
* @return
*/
public File getExportFile()
{
return m_exportFile;
}
/**
* Set Export File
* @param exportFile
*/
public void setExportFile(File exportFile)
{
m_exportFile = exportFile;
}
public int[] getRecord_IDs()
{
return m_Record_IDs;
}
public void setRecord_IDs(int[] Record_IDs)
{
m_Record_IDs = Record_IDs;
}
} // ProcessInfo

View File

@ -48,29 +48,42 @@ import javax.print.attribute.standard.JobName;
import net.sf.jasperreports.engine.DefaultJasperReportsContext;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JRParameter;
import net.sf.jasperreports.engine.JRPropertiesUtil;
import net.sf.jasperreports.engine.JRQuery;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JRDesignQuery;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.export.JRCsvExporter;
import net.sf.jasperreports.engine.export.JRHtmlExporter;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.engine.export.JRPrintServiceExporter;
import net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter;
import net.sf.jasperreports.engine.export.JRTextExporter;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.JRXmlExporter;
import net.sf.jasperreports.engine.fill.JRSwapFileVirtualizer;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.engine.util.JRSwapFile;
import net.sf.jasperreports.engine.util.LocalJasperReportsContext;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.xml.JRXmlWriter;
import org.adempiere.base.Service;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.exceptions.DBException;
import org.adempiere.util.IProcessUI;
import org.adempiere.util.IProcessUI;
import org.compiere.model.MAttachment;
import org.compiere.model.MAttachmentEntry;
import org.compiere.model.MProcess;
import org.compiere.model.MQuery;
import org.compiere.model.MSysConfig;
import org.compiere.model.MTable;
import org.compiere.model.PrintInfo;
import org.compiere.model.X_AD_PInstance_Para;
import org.compiere.print.MPrintFormat;
@ -405,6 +418,68 @@ public class ReportStarter implements ProcessCall, ClientProcess
}
params.put("SUBREPORT_DIR", resourcePath);
params.put("RESOURCE_DIR", resourcePath);
if (jasperReport != null && pi.getTable_ID() > 0 && Record_ID <= 0 && pi.getRecord_IDs() != null && pi.getRecord_IDs().length > 0)
{
try
{
JRQuery originalQuery = jasperReport.getQuery();
if (originalQuery != null)
{
String originalQueryText = originalQuery.getText();
if (originalQueryText != null)
{
MTable table = new MTable(ctx, pi.getTable_ID(), trxName);
String tableName = table.getTableName();
String originalQueryTemp = originalQueryText.toUpperCase();
int index1 = originalQueryTemp.indexOf(" " + tableName.toUpperCase());
if (index1 != -1)
{
int index2 = originalQueryTemp.substring(index1).indexOf(",");
if (index2 != -1)
{
String tableVariable = originalQueryTemp.substring(index1 + tableName.length() + 1, index1 + index2);
tableVariable = tableVariable.trim();
if (tableVariable.length() == 0)
tableVariable = tableName;
MQuery query = new MQuery(tableName);
for (int recordId : pi.getRecord_IDs())
query.addRestriction(tableVariable + "." + query.getTableName() + "_ID" + MQuery.EQUAL + recordId, false, 0);
String newQueryText = null;
int index3 = originalQueryTemp.indexOf("WHERE");
if (index3 != -1)
newQueryText = originalQueryText + " AND " + query.toString();
else
newQueryText = originalQueryText + " WHERE " + query.toString();
File jrxmlFile = File.createTempFile(makePrefix(jasperReport.getName()), ".jrxml");
JRXmlWriter.writeReport(jasperReport, new FileOutputStream(jrxmlFile), "UTF-8");
JasperDesign jasperDesign = JRXmlLoader.load(jrxmlFile);
JRDesignQuery newQuery = new JRDesignQuery();
newQuery.setText(newQueryText);
jasperDesign.setQuery(newQuery);
JasperReport newJasperReport = JasperCompileManager.compileReport(jasperDesign);
if (newJasperReport != null)
{
data.jasperReport = newJasperReport;
jasperReport = newJasperReport;
}
}
}
}
}
}
catch(Exception e)
{
log.severe("Failed to modify the report query");
}
}
if (jasperReport != null) {
File[] subreports;
@ -529,72 +604,120 @@ public class ReportStarter implements ProcessCall, ClientProcess
DefaultJasperReportsContext jasperContext = DefaultJasperReportsContext.getInstance();
JRPropertiesUtil.getInstance(jasperContext).setProperty("net.sf.jasperreports.awt.ignore.missing.font", "true");
JasperPrint jasperPrint = JasperFillManager.fillReport( jasperReport, params, conn);
if (reportData.isDirectPrint())
if (!processInfo.isExport())
{
log.info( "ReportStarter.startProcess print report -" + jasperPrint.getName());
//RF 1906632
if (!processInfo.isBatch()) {
// Get printer job
PrinterJob printerJob = PrintUtil.getPrinterJob(printerName);
// Set print request attributes
// Paper Attributes:
PrintRequestAttributeSet prats = new HashPrintRequestAttributeSet();
// add: copies, job-name, priority
if (printInfo == null || printInfo.isDocumentCopy() || printInfo.getCopies() < 1) // @Trifon
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
{
// You can use JasperPrint to create PDF
// Used For the PH
try
{
File PDF = File.createTempFile(makePrefix(jasperPrint.getName()), ".pdf");
DefaultJasperReportsContext jrContext = DefaultJasperReportsContext.getInstance();
LocalJasperReportsContext ljrContext = new LocalJasperReportsContext(jrContext);
ljrContext.setClassLoader(this.getClass().getClassLoader());
JRPdfExporter exporter = new JRPdfExporter(ljrContext);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, PDF.getAbsolutePath());
exporter.exportReport();
processInfo.setPDFReport(PDF);
}
catch (IOException e)
{
log.severe("ReportStarter.startProcess: Can not make PDF File - "+ e.getMessage());
}
if (reportData.isDirectPrint())
{
log.info( "ReportStarter.startProcess print report -" + jasperPrint.getName());
//RF 1906632
if (!processInfo.isBatch()) {
// Get printer job
PrinterJob printerJob = PrintUtil.getPrinterJob(printerName);
// Set print request attributes
// Paper Attributes:
PrintRequestAttributeSet prats = new HashPrintRequestAttributeSet();
// add: copies, job-name, priority
if (printInfo == null || printInfo.isDocumentCopy() || printInfo.getCopies() < 1) // @Trifon
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
{
// You can use JasperPrint to create PDF
// Used For the PH
try
{
File PDF = File.createTempFile(makePrefix(jasperPrint.getName()), ".pdf");
DefaultJasperReportsContext jrContext = DefaultJasperReportsContext.getInstance();
LocalJasperReportsContext ljrContext = new LocalJasperReportsContext(jrContext);
ljrContext.setClassLoader(this.getClass().getClassLoader());
JRPdfExporter exporter = new JRPdfExporter(ljrContext);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, PDF.getAbsolutePath());
exporter.exportReport();
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 = Service.locate(JRViewerProvider.class);
viewerLauncher.openViewer(jasperPrint, pi.getTitle()+" - " + reportPath);
}
}
else
{
try
{
String ext = pi.getExportFileExtension();
if (ext == null)
ext = "pdf";
File file = File.createTempFile(makePrefix(jasperPrint.getName()), "." + ext);
DefaultJasperReportsContext jrContext = DefaultJasperReportsContext.getInstance();
LocalJasperReportsContext ljrContext = new LocalJasperReportsContext(jrContext);
ljrContext.setClassLoader(this.getClass().getClassLoader());
// You can use JasperPrint to create PDF
// JasperExportManager.exportReportToPdfFile(jasperPrint, "BasicReport.pdf");
} else {
log.info( "ReportStarter.startProcess run report -"+jasperPrint.getName());
JRViewerProvider viewerLauncher = Service.locate(JRViewerProvider.class);
viewerLauncher.openViewer(jasperPrint, pi.getTitle()+" - " + reportPath);
JRExporter exporter = null;
if (ext.equals("pdf"))
exporter = new JRPdfExporter(ljrContext);
else if (ext.equals("ps"))
exporter = new JRPrintServiceExporter(ljrContext);
else if (ext.equals("xml"))
exporter = new JRXmlExporter(ljrContext);
else if (ext.equals("csv") || ext.equals("ssv"))
exporter = new JRCsvExporter(ljrContext);
else if (ext.equals("txt"))
exporter = new JRTextExporter(ljrContext);
else if (ext.equals("html") || ext.equals("htm"))
exporter = new JRHtmlExporter(ljrContext);
else if (ext.equals("xls"))
exporter = new JRXlsExporter(ljrContext);
else
log.severe("FileInvalidExtension="+ext);
if (exporter == null)
exporter = new JRPdfExporter(ljrContext);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, new FileOutputStream(file));
exporter.exportReport();
processInfo.setExportFile(file);
}
catch (IOException e)
{
log.severe("ReportStarter.startProcess: Can not export PDF File - "+ e.getMessage());
}
}
} catch (JRException e) {
log.severe("ReportStarter.startProcess: Can not run report - "+ e.getMessage());

View File

@ -54,6 +54,7 @@ import org.adempiere.webui.event.DialogEvents;
import org.adempiere.webui.event.ToolbarListener;
import org.adempiere.webui.exception.ApplicationException;
import org.adempiere.webui.panel.action.ExportAction;
import org.adempiere.webui.panel.action.ReportAction;
import org.adempiere.webui.part.AbstractUIPart;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.window.CustomizeGridViewDialog;
@ -2067,7 +2068,9 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
}
private void onReport0() {
// Query
ReportAction reportAction = new ReportAction(this);
reportAction.show();
/* // Query
MQuery query = new MQuery(curTab.getTableName());
// Link for detail records
String queryColumn = curTab.getLinkColumnName();
@ -2101,6 +2104,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
}
new WReport (curTab.getAD_Table_ID(), query, toolbar.getEvent().getTarget(), curWindowNo, curTab.getWhereExtended());
*/
}
/**

View File

@ -0,0 +1,376 @@
package org.adempiere.webui.panel.action;
import static org.compiere.model.SystemIDs.WINDOW_PRINTFORMAT;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.StringWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import javax.sql.RowSet;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.apps.WProcessCtl;
import org.adempiere.webui.component.Checkbox;
import org.adempiere.webui.component.ConfirmPanel;
import org.adempiere.webui.component.Label;
import org.adempiere.webui.component.ListItem;
import org.adempiere.webui.component.Listbox;
import org.adempiere.webui.component.Window;
import org.adempiere.webui.panel.AbstractADWindowPanel;
import org.adempiere.webui.window.FDialog;
import org.compiere.model.GridTab;
import org.compiere.model.MQuery;
import org.compiere.model.MRole;
import org.compiere.model.PrintInfo;
import org.compiere.print.MPrintFormat;
import org.compiere.print.ReportCtl;
import org.compiere.print.ReportEngine;
import org.compiere.process.ProcessInfo;
import org.compiere.process.ServerProcessCtl;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.zkoss.util.media.AMedia;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Div;
import org.zkoss.zul.Filedownload;
import org.zkoss.zul.Hbox;
import org.zkoss.zul.Vbox;
public class ReportAction implements EventListener<Event>
{
private static CLogger log = CLogger.getCLogger(ReportAction.class);
private AbstractADWindowPanel panel;
private Window winReport = null;
private ConfirmPanel confirmPanel = new ConfirmPanel(true);
private Listbox cboPrintFormat = new Listbox();
private Listbox cboExportType = new Listbox();
private Checkbox chkCurrentRowOnly = new Checkbox();
private Checkbox chkExport = new Checkbox();
private Checkbox chkAllColumns = new Checkbox();
private ArrayList<KeyNamePair> printFormatList = new ArrayList<KeyNamePair>();
public ReportAction(AbstractADWindowPanel panel)
{
this.panel = panel;
getPrintFormats(panel.getActiveGridTab().getAD_Table_ID());
}
public void show()
{
if(winReport == null)
{
winReport = new Window();
winReport.setTitle(Msg.getMsg(Env.getCtx(), "Export") + ": " + panel.getActiveGridTab().getName());
winReport.setWidth("450px");
winReport.setClosable(true);
winReport.setBorder("normal");
winReport.setStyle("position:absolute");
cboPrintFormat.setMold("select");
cboPrintFormat.getItems().clear();
for (KeyNamePair printFormat : printFormatList)
cboPrintFormat.appendItem(printFormat.getName(), printFormat.getKey());
if (cboPrintFormat.getItemCount() > 0)
cboPrintFormat.setSelectedIndex(0);
cboExportType.setMold("select");
cboExportType.getItems().clear();
cboExportType.appendItem("ps" + " - " + Msg.getMsg(Env.getCtx(), "FilePS"), "ps");
cboExportType.appendItem("xml" + " - " + Msg.getMsg(Env.getCtx(), "FileXML"), "xml");
cboExportType.appendItem("pdf" + " - " + Msg.getMsg(Env.getCtx(), "FilePDF"), "pdf");
cboExportType.appendItem("html" + " - " + Msg.getMsg(Env.getCtx(), "FileHTML"), "html");
cboExportType.appendItem("txt" + " - " + Msg.getMsg(Env.getCtx(), "FileTXT"), "txt");
cboExportType.appendItem("ssv" + " - " + Msg.getMsg(Env.getCtx(), "FileSSV"), "ssv");
cboExportType.appendItem("csv" + " - " + Msg.getMsg(Env.getCtx(), "FileCSV"), "csv");
ListItem li = cboExportType.appendItem("xls" + " - " + Msg.getMsg(Env.getCtx(), "FileXLS"), "xls");
cboExportType.setSelectedItem(li);
cboExportType.setVisible(false);
chkCurrentRowOnly.setLabel(Msg.getMsg(Env.getCtx(), "CurrentRowOnly"));
chkCurrentRowOnly.setSelected(false);
chkExport.setLabel(Msg.getMsg(Env.getCtx(), "Export"));
chkExport.setSelected(false);
chkAllColumns.setLabel(Msg.getMsg(Env.getCtx(), "AllColumns"));
chkAllColumns.setSelected(false);
chkAllColumns.setVisible(false);
Vbox vb = new Vbox();
vb.setWidth("100%");
winReport.appendChild(vb);
Hbox hb = new Hbox();
hb.setAlign("center");
Div div = new Div();
div.appendChild(new Label(Msg.translate(Env.getCtx(), "AD_PrintFormat_ID")));
hb.appendChild(div);
hb.appendChild(cboPrintFormat);
cboPrintFormat.setWidth("100%");
cboPrintFormat.addEventListener(Events.ON_SELECT, this);
vb.appendChild(hb);
vb.appendChild(chkCurrentRowOnly);
hb = new Hbox();
hb.setAlign("center");
hb.appendChild(chkExport);
chkExport.addEventListener(Events.ON_CHECK, this);
hb.appendChild(cboExportType);
cboExportType.setWidth("100%");
vb.appendChild(hb);
vb.appendChild(chkAllColumns);
vb.appendChild(confirmPanel);
confirmPanel.addActionListener(this);
}
winReport.setAttribute(Window.MODE_KEY, Window.MODE_HIGHLIGHTED);
AEnv.showWindow(winReport);
}
@Override
public void onEvent(Event event) throws Exception {
if(event.getTarget().getId().equals(ConfirmPanel.A_CANCEL))
winReport.onClose();
else if(event.getTarget().getId().equals(ConfirmPanel.A_OK))
validate();
else if(event.getTarget() == cboPrintFormat)
{
ListItem li = cboPrintFormat.getSelectedItem();
if (li != null && li.getValue() != null)
{
int AD_PrintFormat_ID = Integer.valueOf(li.getValue().toString());
chkAllColumns.setVisible(AD_PrintFormat_ID == -1);
}
}
else if(event.getTarget() == chkExport)
cboExportType.setVisible(chkExport.isChecked());
}
private void validate()
{
ListItem li = cboPrintFormat.getSelectedItem();
if(li == null || li.getValue() == null)
{
FDialog.error(0, winReport, "PrintFormatMandatory");
return;
}
int AD_PrintFormat_ID = Integer.valueOf(li.getValue().toString());
boolean export = chkExport.isChecked();
if (export)
{
li = cboExportType.getSelectedItem();
if(li == null || li.getValue() == null)
{
FDialog.error(0, winReport, "ExportFileTypeMandatory");
return;
}
}
GridTab gridTab = panel.getActiveGridTab();
// Print Format
boolean allColumns = chkAllColumns.isChecked();
MPrintFormat pf = null;
if (AD_PrintFormat_ID == -1)
pf = MPrintFormat.createFromGridLayout(Env.getCtx(), gridTab, allColumns);
else
pf = MPrintFormat.get (Env.getCtx(), AD_PrintFormat_ID, true);
// Query
boolean currentRowOnly = chkCurrentRowOnly.isChecked();
int Record_ID = 0;
int[] RecordIDs = null;
MQuery query = new MQuery(gridTab.getTableName());
if (currentRowOnly)
{
Record_ID = gridTab.getRecord_ID();
query.addRestriction(query.getTableName() + "_ID", MQuery.EQUAL, Record_ID);
}
else
{
RecordIDs = new int[gridTab.getRowCount()];
for(int i = 0; i < gridTab.getRowCount(); i++)
{
RecordIDs[i] = gridTab.getKeyID(i);
query.addRestriction(query.getTableName() + "." + query.getTableName() + "_ID" + MQuery.EQUAL + RecordIDs[i], false, 0);
}
}
PrintInfo info = new PrintInfo(pf.getName(), pf.getAD_Table_ID(), Record_ID);
info.setDescription(query.getInfo());
if(pf != null && pf.getJasperProcess_ID() > 0)
{
// It's a report using the JasperReports engine
ProcessInfo pi = new ProcessInfo ("", pf.getJasperProcess_ID(), pf.getAD_Table_ID(), Record_ID);
pi.setRecord_IDs(RecordIDs);
pi.setIsBatch(true);
if (export)
{
li = cboExportType.getSelectedItem();
String ext = li.getValue().toString();
pi.setExportFileExtension(ext);
pi.setExport(true);
winReport.onClose();
ServerProcessCtl.process(null, pi, null);
try
{
File exportFile = pi.getExportFile();
AMedia media = new AMedia(exportFile.getName() + "." + ext, null, "application/octet-stream", exportFile, true);
Filedownload.save(media, exportFile.getName() + "." + ext);
}
catch (Exception e)
{
log.log(Level.SEVERE, "Failed to export content.", e);
}
}
else
{
winReport.onClose();
WProcessCtl.process(gridTab.getWindowNo(), pi, null);
}
}
else
{
// It's a default report using the standard printing engine
ReportEngine re = new ReportEngine (Env.getCtx(), pf, query, info);
re.setWhereExtended(gridTab.getWhereExtended());
re.setWindowNo(gridTab.getWindowNo());
if (export)
export(re);
else
print(re);
}
}
private void print(ReportEngine re)
{
winReport.onClose();
ReportCtl.preview(re);
}
private void export(ReportEngine re)
{
try
{
ListItem li = cboExportType.getSelectedItem();
if(li == null || li.getValue() == null)
{
FDialog.error(0, winReport, "FileInvalidExtension");
return;
}
String ext = li.getValue().toString();
byte[] data = null;
File inputFile = null;
if (ext.equals("pdf"))
{
data = re.createPDFData();
}
else if (ext.equals("ps"))
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
re.createPS(baos);
data = baos.toByteArray();
}
else if (ext.equals("xml"))
{
StringWriter sw = new StringWriter();
re.createXML(sw);
data = sw.getBuffer().toString().getBytes();
}
else if (ext.equals("csv") || ext.equals("ssv"))
{
StringWriter sw = new StringWriter();
re.createCSV(sw, ',', re.getPrintFormat().getLanguage());
data = sw.getBuffer().toString().getBytes();
}
else if (ext.equals("txt"))
{
StringWriter sw = new StringWriter();
re.createCSV(sw, '\t', re.getPrintFormat().getLanguage());
data = sw.getBuffer().toString().getBytes();
}
else if (ext.equals("html") || ext.equals("htm"))
{
StringWriter sw = new StringWriter();
re.createHTML(sw, false, re.getPrintFormat().getLanguage());
data = sw.getBuffer().toString().getBytes();
}
else if (ext.equals("xls"))
{
inputFile = File.createTempFile("Export", ".xls");
re.createXLS(inputFile, re.getPrintFormat().getLanguage());
}
else
{
FDialog.error(0, winReport, "FileInvalidExtension");
return;
}
winReport.onClose();
AMedia media = null;
if (data != null)
media = new AMedia(re.getPrintFormat().getName() + "." + ext, null, "application/octet-stream", data);
else
media = new AMedia(re.getPrintFormat().getName() + "." + ext, null, "application/octet-stream", inputFile, true);
Filedownload.save(media, re.getPrintFormat().getName() + "." + ext);
}
catch (Exception e)
{
log.log(Level.SEVERE, "Failed to export content.", e);
}
}
private void getPrintFormats(int AD_Table_ID)
{
printFormatList.clear();
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
RowSet rowSet = MPrintFormat.getAccessiblePrintFormats(AD_Table_ID, -1, null);
KeyNamePair pp = null;
try
{
while (rowSet.next())
{
pp = new KeyNamePair (rowSet.getInt(1), rowSet.getString(2));
if (rowSet.getInt(3) == AD_Client_ID)
{
printFormatList.add(pp);
}
}
}
catch (SQLException e)
{
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
if (MRole.getDefault().isTableAccess(MPrintFormat.Table_ID, false) && MRole.getDefault().getWindowAccess(WINDOW_PRINTFORMAT))
{
StringBuffer sb = new StringBuffer("** ").append(Msg.getMsg(Env.getCtx(), "NewReport")).append(" **");
pp = new KeyNamePair(-1, sb.toString());
printFormatList.add(pp);
}
}
}