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

📄 reportctl.java

📁 Java写的ERP系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
						if (P_String.indexOf("%") == -1)
							query.addRestriction(ParameterName, MQuery.EQUAL, P_String, Name, Info);
						else
							query.addRestriction(ParameterName, MQuery.LIKE, P_String, Name, Info);
					}
					else
						query.addRangeRestriction(ParameterName, P_String, P_String_To,
							Name, Info, Info_To);
				}
				else if (P_Number != null)
				{
					if (P_Number_To == null)
						query.addRestriction(ParameterName, MQuery.EQUAL, P_Number, Name, Info);
					else
						query.addRangeRestriction(ParameterName, P_Number, P_Number_To,
							Name, Info, Info_To);
				}
				else if (P_Date != null)
				{
					if (P_Date_To == null)
						query.addRestriction("TRUNC("+ParameterName+")", MQuery.EQUAL, P_Date, Name, Info);
					else
						query.addRangeRestriction("TRUNC("+ParameterName+")", P_Date, P_Date_To,
							Name, Info, Info_To);
				}
			}
			rs.close();
			pstmt.close();
		}
		catch (SQLException e2)
		{
			Log.error("ReportDispatcher.getQuery (Parameter)", e2);
		}
		Log.trace(9, query.getWhereClause(true));
		return query;
	}	//	getQuery

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

	public static final int		ORDER = 0;
	public static final int		SHIPMENT = 1;
	public static final int		INVOICE = 2;
	public static final int		REMITTANCE = 3;
	//
	public static final int		CHECK = 4;
	public static final int		DUNNING = 5;

	private static final String[]	DOC_TABLES = new String[] {
		"C_Order_Header_v", "M_InOut_Header_v", "C_Invoice_Header_v", "C_PaySelection_Check_v",
		"C_PaySelection_Check_v", "C_DunningRunEntry_v" };
	private static final String[]	DOC_BASETABLES = new String[] {
		"C_Order", "M_InOut", "C_Invoice", "C_PaySelectionCheck",
		"C_PaySelectionCheck", "C_DunningRunEntry" };
	private static final String[]	DOC_IDS = new String[] {
		"C_Order_ID", "M_InOut_ID", "C_Invoice_ID", "C_PaySelectionCheck_ID",
		"C_PaySelectionCheck_ID", "C_DunningRunEntry_ID" };

	/**
	 * 	Start Document Print of Type.
	 *  Called also directly from ProcessDialog, VInvoiceGen, VPayPrint
	 * 	@param type document type
	 * 	@param Record_ID document record id
	 *  @param IsDirectPrint if true, prints directly - otherwise View
	 *  @return true if success
	 */
	public static boolean startDocumentPrint (int type, int Record_ID, boolean IsDirectPrint)
	{
		//	Order - Print Shipment or Invoice
		if (type == ORDER)
		{
			int[] what = getDocumentWhat (Record_ID);
			if (what != null)
			{
				type = what[0];
				Record_ID = what[1];
			}
		}	//	Order

		String JobName = DOC_BASETABLES[type] + "_Print";
		int AD_PrintFormat_ID = 0;
		int copies = 1;

		//	Get Document Info
		Language language = Language.getLanguage();		//	Base Language
		String sql = null;
		if (type == CHECK)
			sql = "SELECT bad.Check_PrintFormat_ID,"								//	1
				+ "	c.IsMultiLingualDocument,bp.AD_Language "						//	2..3
				+ "FROM C_PaySelectionCheck d"
				+ " INNER JOIN C_PaySelection ps ON (d.C_PaySelection_ID=ps.C_PaySelection_ID)"
				+ " INNER JOIN C_BankAccountDoc bad ON (ps.C_BankAccount_ID=bad.C_BankAccount_ID AND d.PaymentRule=bad.PaymentRule)"
				+ " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)"
				+ " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID) "
				+ "WHERE d.C_PaySelectionCheck_ID=?";
		else if (type == DUNNING)
			sql = "SELECT dl.Dunning_PrintFormat_ID,"
				+ " c.IsMultiLingualDocument,bp.AD_Language "
				+ "FROM C_DunningRunEntry d"
				+ " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)"
				+ " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID)"
				+ " INNER JOIN C_DunningRun dr ON (d.C_DunningRun_ID=dr.C_DunningRun_ID)"
				+ " INNER JOIN C_DunningLevel dl ON (dr.C_DunningLevel_ID=dr.C_DunningLevel_ID) "
				+ "WHERE d.C_DunningRunEntry_ID=?";
		else if (type == REMITTANCE)
			sql = "SELECT pf.Remittance_PrintFormat_ID,"
				+ " c.IsMultiLingualDocument,bp.AD_Language "
				+ "FROM C_PaySelectionCheck d"
				+ " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)"
				+ " INNER JOIN AD_PrintForm pf ON (c.AD_Client_ID=pf.AD_Client_ID)"
				+ " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID)"
				+ "WHERE d.C_PaySelectionCheck_ID=?";
		else
			sql = "SELECT pf.Order_PrintFormat_ID,pf.Shipment_PrintFormat_ID,"		//	1..2
				+ " pf.Invoice_PrintFormat_ID,pf.Remittance_PrintFormat_ID,"		//	3..4
				+ " c.IsMultiLingualDocument,bp.AD_Language,"						//	5..6
				+ " COALESCE(dt.DocumentCopies,0)+COALESCE(bp.DocumentCopies,1) " 	// 	7
				+ "FROM " + DOC_BASETABLES[type] + " d"
				+ " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)"
				+ " INNER JOIN AD_PrintForm pf ON (c.AD_Client_ID=pf.AD_Client_ID)"
				+ " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID)"
				+ " LEFT OUTER JOIN C_DocType dt ON (d.C_DocType_ID=dt.C_DocType_ID) "
				+ "WHERE d." + DOC_IDS[type] + "=?";		//	#1

		try
		{
			PreparedStatement pstmt = DB.prepareStatement(sql);
			pstmt.setInt(1, Record_ID);
			ResultSet rs = pstmt.executeQuery();
			if (rs.next())
			{
				if (type == CHECK || type == DUNNING || type == REMITTANCE)
				{
					AD_PrintFormat_ID = rs.getInt(1);
					copies = 1;
					//	Set Language when enabled
					String AD_Language = rs.getString(3);
					if (AD_Language != null && "Y".equals(rs.getString(2)))
						language = Language.getLanguage(AD_Language);
				}
				else
				{
					//	Set PrintFormat
					AD_PrintFormat_ID = rs.getInt(type+1);
					copies = rs.getInt(7);
					//	Set Language when enabled
					String AD_Language = rs.getString("AD_Language");
					if (AD_Language != null && "Y".equals(rs.getString("IsMultiLingualDocument")))
						language = Language.getLanguage(AD_Language);
				}
			}
			rs.close();
			pstmt.close();
		}
		catch (SQLException e)
		{
			Log.error("ReportCtl.startDocumentPrint - Record_ID=" + Record_ID + ", SQL=" + sql, e);
		}
		if (AD_PrintFormat_ID == 0)
		{
			ADialog.error(0, null, "NoDocPrintFormat");
			return false;
		}
		//	Get Format & Data
		MPrintFormat format = MPrintFormat.get (AD_PrintFormat_ID, false);
		format.setLanguage(language);
	//	if (!Env.isBaseLanguage(language, DOC_TABLES[type]))
			format.setTranslationLanguage(language);
		//	query
		MQuery query = new MQuery(DOC_TABLES[type]);
		query.addRestriction(DOC_IDS[type], MQuery.EQUAL, new Integer(Record_ID));
	//	Log.trace(Log.l3_Util, "ReportCtrl.startDocumentPrint - " + format, query + " - " + language.getAD_Language());

		//	Engine
		ReportEngine re = new ReportEngine(Env.getCtx(), format, query);
		if (IsDirectPrint)
		{
		//	re.print (false, copies, true);		//	prints original and "copy"
			re.print (false, copies, false);	//	prints only original
			printConfirm (type, Record_ID);
		}
		else
			new Viewer(re);
		return true;
	}	//	startDocumentPrint

	/**
	 *	Determine what Order document to print.
	 *  @param C_Order_ID id
	 *	@return int Array with [printWhat, ID]
	 */
	private static int[] getDocumentWhat (int C_Order_ID)
	{
		int[] what = new int[2];
		what[0] = ORDER;
		what[1] = C_Order_ID;
		//
		String SQL = "SELECT dt.DocSubTypeSO "
			+ "FROM C_DocType dt, C_Order o "
			+ "WHERE o.C_DocType_ID=dt.C_DocType_ID"
			+ " AND o.C_Order_ID=?";
		String DocSubTypeSO = null;
		try
		{
			PreparedStatement pstmt = DB.prepareStatement(SQL);
			pstmt.setInt(1, C_Order_ID);
			ResultSet rs = pstmt.executeQuery();
			if (rs.next())
				DocSubTypeSO = rs.getString(1);
			rs.close();
			pstmt.close();
		}
		catch (SQLException e1)
		{
			Log.error ("ReportCtrl.getDocumentWhat DocSubType", e1);
			return null;		//	error
		}
		if (DocSubTypeSO == null)
			DocSubTypeSO = "";
		//	WalkIn Receipt, WalkIn Invoice,
		if (DocSubTypeSO.equals("WR") || DocSubTypeSO.equals("WI"))
			what[0] = INVOICE;
		//	WalkIn Pickup,
		else if (DocSubTypeSO.equals("WP"))
			what[0] = SHIPMENT;
		//	Offer Binding, Offer Nonbinding, Standard Order
		else
			return what;

		//	Get Record_ID of Invoice/Receipt
		if (what[0] == INVOICE)
			SQL = "SELECT C_Invoice_ID REC FROM C_Invoice WHERE C_Order_ID=?"	//	1
				+ " ORDER BY C_Invoice_ID DESC";
		else
			SQL = "SELECT M_InOut_ID REC FROM M_InOut WHERE C_Order_ID=?" 	//	1
				+ " ORDER BY M_InOut_ID DESC";
		try
		{
			PreparedStatement pstmt = DB.prepareStatement(SQL);
			pstmt.setInt(1, C_Order_ID);
			ResultSet rs = pstmt.executeQuery();
			if (rs.next())
			{
			//	if (i == 1 && ADialog.ask(0, null, what[0] == INVOICE ? "PrintOnlyRecentInvoice?" : "PrintOnlyRecentShipment?")) break;
				what[1] = rs.getInt(1);
			}
			else	//	No Document Found
				what[0] = ORDER;

			rs.close();
			pstmt.close();
		}
		catch (SQLException e2)
		{
			Log.error("ReportCtrl.getDocumentWhat Record_ID", e2);
			return null;
		}
		Log.trace(Log.l4_Data, "ReportCtrl.getDocumentWhat", "Order => " + what[0] + " ID=" + what[1]);
		return what;
	}	//	getDocumentWhat

	/**
	 * 	Print Confirm.
	 *  Update Date Printed
	 * 	@param type document type
	 * 	@param Record_ID record id
	 */
	public static void printConfirm (int type, int Record_ID)
	{
		StringBuffer sql = new StringBuffer();
		if (type == ORDER || type == SHIPMENT || type == INVOICE)
			sql.append("UPDATE ").append(DOC_BASETABLES[type])
				.append(" SET DatePrinted=SysDate, IsPrinted='Y' WHERE ")
				.append(DOC_IDS[type]).append("=").append(Record_ID);
		//
		if (sql.length() > 0)
		{
			int no = DB.executeUpdate(sql.toString());
			if (no != 1)
				Log.error("ReportCtl.printConfirm - Updated records=" + no + " - should be just one");
		}
	}	//	printConfirm

}	//	ReportCtl

⌨️ 快捷键说明

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