use of org.compiere.model.MQuery in project adempiere by adempiere.
the class TableReference method main.
// printRunningTotal
/*************************************************************************
* Test
* @param args args
*/
public static void main(String[] args) {
org.compiere.Adempiere.startup(true);
// DataEngine de = new DataEngine(null);
DataEngine de = new DataEngine(Language.getLanguage("de_DE"));
MQuery query = new MQuery();
query.addRestriction("AD_Table_ID", MQuery.LESS, 105);
// PrintData pd = de.load_fromTable(100, query, null, null, false);
// pd.dump();
// pd.createXML(new javax.xml.transform.stream.StreamResult(System.out));
}
use of org.compiere.model.MQuery 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.MQuery 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.MQuery in project adempiere by adempiere.
the class ServerReportCtl method runJasperProcess.
// StartDocumentPrint
/**
* Runs a Jasper process that prints the record
*
* @param recordId
* @param reportEngine
* @param isDirectPrint
* @param printerName
* @param processInfo
* @return
*/
public static boolean runJasperProcess(int recordId, ReportEngine reportEngine, boolean isDirectPrint, String printerName, ProcessInfo processInfo) {
Trx trx;
if (processInfo != null)
trx = Trx.get(processInfo.getTransactionName(), false);
else
trx = null;
MPrintFormat format = reportEngine.getPrintFormat();
ProcessInfo jasperProcessInfo = new ProcessInfo("", format.getJasperProcess_ID());
jasperProcessInfo.setPrintPreview(!isDirectPrint);
MQuery query = reportEngine.getQuery();
if (query != null)
recordId = (Integer) query.getCode(0);
jasperProcessInfo.setRecord_ID(recordId);
Vector<ProcessInfoParameter> jasperPrintParams = new Vector<ProcessInfoParameter>();
ProcessInfoParameter pip;
if (printerName != null && printerName.trim().length() > 0) {
// Override printer name
pip = new ProcessInfoParameter(PARAM_PRINTER_NAME, printerName, null, null, null);
jasperPrintParams.add(pip);
}
pip = new ProcessInfoParameter(PARAM_PRINT_FORMAT, format, null, null, null);
jasperPrintParams.add(pip);
pip = new ProcessInfoParameter(PARAM_PRINT_INFO, reportEngine.getPrintInfo(), null, null, null);
jasperPrintParams.add(pip);
jasperProcessInfo.setParameter(jasperPrintParams.toArray(new ProcessInfoParameter[] {}));
// Parent set to null for synchronous processing, see bugtracker 3010932
ServerProcessCtl.process(// Parent set to null for synchronous processing, see bugtracker 3010932
null, jasperProcessInfo, trx);
if (processInfo != null)
processInfo.setPDFReport(jasperProcessInfo.getPDFReport());
boolean result = true;
return (result);
}
use of org.compiere.model.MQuery in project adempiere by adempiere.
the class Graph method chartMouseClicked.
public void chartMouseClicked(ChartMouseEvent event) {
if ((event.getEntity() != null) && (event.getTrigger().getClickCount() > 1)) {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
GraphColumn bgc = getGraphColumn(event);
if (bgc == null) {
return;
}
MQuery query = bgc.getMQuery(builder.getMGoal());
if (query != null)
AEnv.zoom(query);
else
log.warning("Nothing to zoom to - " + bgc);
} finally {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
}
Aggregations