⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reportctl.java

📁 Java写的ERP系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
 * The contents of this file are subject to the   Compiere License  Version 1.1
 * ("License"); You may not use this file except in compliance with the License
 * You may obtain a copy of the License at http://www.compiere.org/license.html
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * The Original Code is                  Compiere  ERP & CRM  Business Solution
 * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
 * Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
 * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
 * Contributor(s): ______________________________________.
 *****************************************************************************/
package org.compiere.print;

import java.sql.*;

import org.compiere.apps.*;
import org.compiere.model.*;
import org.compiere.util.*;
import org.compiere.process.*;

/**
 *	Report Controller
 *
 * 	@author 	Jorg Janke
 * 	@version 	$Id: ReportCtl.java,v 1.21 2003/04/24 06:11:11 jjanke Exp $
 */
public class ReportCtl
{
	/**
	 *	Constructor
	 */
	private ReportCtl()
	{
	}	//	ReportCtrl

	/**
	 *	Create Report.
	 *	- Called from ProcessCtl
	 *	- Check special reports first, if not, create standard Report
	 *
	 *  @param pi process info
	 *  @param IsDirectPrint if true, prints directly - otherwise View
	 *  @return true if created
	 */
	static public boolean start (ProcessInfo pi, boolean IsDirectPrint)
	{
		Log.trace(Log.l2_Sub, "ReportCtl.start", pi);

		/**
		 *	Order Print
		 */
		if (pi.AD_Process_ID == 110)			//	C_Order
			return startDocumentPrint(ORDER, pi.Record_ID, IsDirectPrint);
		else if (pi.AD_Process_ID == 116)		//	C_Invoice
			return startDocumentPrint(INVOICE, pi.Record_ID, IsDirectPrint);
		else if (pi.AD_Process_ID == 117)		//	M_InOut
			return startDocumentPrint(SHIPMENT, pi.Record_ID, IsDirectPrint);
		/**
		else if (pi.AD_Process_ID == 9999999)	//	PaySelection
			return startDocumentPrint(CHECK, pi.Record_ID, IsDirectPrint);
		else if (pi.AD_Process_ID == 9999999)	//	PaySelection
			return startDocumentPrint(REMITTANCE, pi.Record_ID, IsDirectPrint);
		else if (pi.AD_Process_ID == 9999999)	//	Dunning
			return startDocumentPrint(DUNNING, pi.Record_ID, IsDirectPrint);
		**/
	   else if (pi.AD_Process_ID == 202			//	Financial Report
			|| pi.AD_Process_ID == 204)			//	Financial Statement
		   return startFinReport (pi);
		/********************
		 *	Standard Report
		 *******************/
		return startStandardReport (pi, IsDirectPrint);
	}	//	create

	/*************************************************************************/

	/**
	 *	Start Standard Report.
	 *  - Get Table Info & submit
	 *  @param pi Process Info
	 *  @param IsDirectPrint if true, prints directly - otherwise View
	 *  @return true if OK
	 */
	static public boolean startStandardReport (ProcessInfo pi, boolean IsDirectPrint)
	{
		int AD_Client_ID = Env.getContextAsInt(Env.getCtx(), "#AD_Client_ID");
		//
		int AD_Table_ID = 0;
		int AD_ReportView_ID = 0;
		String TableName = null;
		String whereClause = "";
		int AD_PrintFormat_ID = 0;
		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.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,?)) "
			+ "WHERE pi.AD_PInstance_ID=?"		//	#2
			+ "ORDER BY pf.AD_Client_ID DESC";	//	own first
		try
		{
			PreparedStatement pstmt = DB.prepareStatement(sql);
			pstmt.setInt(1, AD_Client_ID);
			pstmt.setInt(2, pi.AD_PInstance_ID);
			ResultSet rs = pstmt.executeQuery();
			//	Just get first
			if (rs.next())
			{
				AD_ReportView_ID = rs.getInt(1);
				whereClause = rs.getString(2);
				if (rs.wasNull())
					whereClause = "";
				//
				AD_Table_ID = rs.getInt(3);
				TableName = rs.getString(4);
				AD_PrintFormat_ID = rs.getInt(5);
				Client_ID = rs.getInt(6);
			}
			rs.close();
			pstmt.close();
		}
		catch (SQLException e1)
		{
			Log.error("ReportCtrl.startStandardReport", e1);
		}

		//  Create Query from Parameters
		MQuery query = getQuery (pi.AD_PInstance_ID, TableName);
		//  Add to static where clause from ReportView
		if (whereClause.length() != 0)
			query.addRestriction(whereClause);

		//	Get PrintFormat
		MPrintFormat format = null;
		if (AD_PrintFormat_ID != 0)
		{
			//	We have a PrintFormat with the correct Client
			if (Client_ID == AD_Client_ID)
				format = MPrintFormat.get (AD_PrintFormat_ID, false);
			else
				format = MPrintFormat.copyToClient (Env.getCtx(), AD_PrintFormat_ID, AD_Client_ID);
		}
		if (format == null)
			format = MPrintFormat.createFromReportView(Env.getCtx(), AD_ReportView_ID, pi.Title);

		ReportEngine re = new ReportEngine(Env.getCtx(), format, query);
		if (IsDirectPrint)
			re.print(false, 1, false);
		else
			new Viewer(re);
		return true;
	}	//	startStandardReport

	/**
	 *	Start Financial Report.
	 *  @param pi Process Info
	 *  @return true if OK
	 */
	static public boolean startFinReport (ProcessInfo pi)
	{
		int AD_Client_ID = Env.getContextAsInt(Env.getCtx(), "#AD_Client_ID");

		//  Create Query from Parameters
		String TableName = pi.AD_Process_ID == 202 ? "T_Report" : "T_ReportStatement";
		MQuery query = getQuery (pi.AD_PInstance_ID, TableName);

		//	Get PrintFormat
		if (pi.Data == null)
		{
			Log.error("ReportCtl.startFinReport - No PrintFormat");
			return false;
		}
		MPrintFormat format = (MPrintFormat)pi.Data;

		ReportEngine re = new ReportEngine(Env.getCtx(), format, query);
		new Viewer(re);
		return true;
	}	//	startFinReport

	/**
	 *	Get Query from Parameter
	 *  @param AD_PInstance_ID instance
	 *  @param TableName table name
	 *  @return where clause
	 */
	static private MQuery getQuery (int AD_PInstance_ID, String TableName)
	{
		MQuery query = new MQuery(TableName);
		//	Temporary Tables - add qualifier (not displayed)
		if (TableName.startsWith("T_"))
			query.addRestriction(TableName + ".AD_PInstance_ID=" + AD_PInstance_ID);

		//	How many rows do we have?
		int rows = 0;
		String SQL = "SELECT COUNT(*) FROM AD_PInstance_Para WHERE AD_PInstance_ID=?";
		try
		{
			PreparedStatement pstmt = DB.prepareStatement(SQL);
			pstmt.setInt(1, AD_PInstance_ID);
			ResultSet rs = pstmt.executeQuery();
			if (rs.next())
				rows = rs.getInt(1);
			rs.close();
			pstmt.close();
		}
		catch (SQLException e1)
		{
			Log.error("ReportCtrl.getQuery (ParameterCount)", e1);
		}

		if (rows < 1)
			return query;

		//	Msg.getMsg(Env.getCtx(), "Parameter")
		boolean trl = !Env.isBaseLanguage(Env.getCtx(), "AD_Process_Para");
		if (!trl)
			SQL = "SELECT ip.ParameterName,ip.P_String,ip.P_String_To,"			//	1..3
				+ "ip.P_Number,ip.P_Number_To,"									//	4..5
				+ "ip.P_Date,ip.P_Date_To, ip.Info,ip.Info_To, pp.Name "		//	6..10
				+ "FROM AD_PInstance_Para ip, AD_PInstance i, AD_Process_Para pp "
				+ "WHERE i.AD_PInstance_ID=ip.AD_PInstance_ID"
				+ " AND pp.AD_Process_ID=i.AD_Process_ID"
				+ " AND pp.ColumnName=ip.ParameterName"
				+ " AND ip.AD_PInstance_ID=?";
		else
			SQL = "SELECT ip.ParameterName,ip.P_String,ip.P_String_To, ip.P_Number,ip.P_Number_To,"
				+ "ip.P_Date,ip.P_Date_To, ip.Info,ip.Info_To, ppt.Name "
				+ "FROM AD_PInstance_Para ip, AD_PInstance i, AD_Process_Para pp, AD_Process_Para_Trl ppt "
				+ "WHERE i.AD_PInstance_ID=ip.AD_PInstance_ID"
				+ " AND pp.AD_Process_ID=i.AD_Process_ID"
				+ " AND pp.ColumnName=ip.ParameterName"
				+ " AND pp.AD_Process_Para_ID=ppt.AD_Process_Para_ID"
				+ " AND ip.AD_PInstance_ID=?"
				+ " AND ppt.AD_Language=?";
		try
		{
			PreparedStatement pstmt = DB.prepareStatement(SQL);
			pstmt.setInt(1, AD_PInstance_ID);
			if (trl)
				pstmt.setString(2, Env.getAD_Language(Env.getCtx()));
			ResultSet rs = pstmt.executeQuery();
			//	all records
			for (int row = 0; rs.next(); row++)
			{
				if (row == rows)
				{
					Log.error("ReportCtrl.getQuery (Parameter) - more rows than expected");
					break;
				}
				String ParameterName = rs.getString(1);
				String P_String = rs.getString(2);
				String P_String_To = rs.getString(3);
				//
				Double P_Number = null;
				double d = rs.getDouble(4);
				if (!rs.wasNull())
					P_Number = new Double(d);
				Double P_Number_To = null;
				d = rs.getDouble(5);
				if (!rs.wasNull())
					P_Number_To = new Double(d);
				//
				Timestamp P_Date = rs.getTimestamp(6);
				Timestamp P_Date_To = rs.getTimestamp(7);
				//
				String Info = rs.getString(8);
				String Info_To = rs.getString(9);
				//
				String Name = rs.getString(10);
				Log.trace(9, "ReportCtrl.getQuery", ParameterName + " S=" + P_String + "-" + P_String_To
					+ ", N=" + P_Number + "-" + P_Number_To + ", D=" + P_Date + "-" + P_Date_To
					+ " - " + Name + " - " + Info + "-" + Info_To);

				//-------------------------------------------------------------
				if (P_String != null)
				{
					if (P_String_To == null)
					{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -