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

📄 infoproduct.java

📁 Java写的ERP系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	private void setPriceListVersion(int M_PriceList_Version_ID)
	{
		Log.trace(Log.l3_Util, "InfoProduct.setPriceListVersion - " + M_PriceList_Version_ID);
		for (int i = 0; i < pickPriceList.getItemCount(); i++)
		{
			KeyNamePair kn = (KeyNamePair)pickPriceList.getItemAt(i);
			if (kn.getKey() == M_PriceList_Version_ID)
			{
				pickPriceList.setSelectedIndex(i);
				return;
			}
		}
		Log.trace(Log.l5_DData, "NOT found");
	}	//	setPriceList

	/**
	 *	Find Price List Version and update context
	 *
	 * @param M_PriceList_ID price list
	 * @return M_PriceList_Version_ID price list version
	 */
	private int findPLV (int M_PriceList_ID)
	{
		Log.trace(Log.l3_Util, "InfoProduct.findPLV - " + M_PriceList_ID);
		int retValue = 0;
		String SQL = "SELECT plv.M_PriceList_Version_ID, plv.ValidFrom "
			+ "FROM M_PriceList pl, M_PriceList_Version plv "
			+ "WHERE pl.M_PriceList_ID=plv.M_PriceList_ID"
			+ " AND plv.IsActive='Y'"
			+ " AND pl.M_PriceList_ID=? "					//	1
			+ "ORDER BY plv.ValidFrom DESC";
		//	find newest one
		try
		{
			PreparedStatement pstmt = DB.prepareStatement(SQL);
			pstmt.setInt(1, M_PriceList_ID);
			ResultSet rs = pstmt.executeQuery();
			Timestamp docDate = new Timestamp(System.currentTimeMillis());
			while (rs.next() && retValue == 0)
			{
				Timestamp vf = rs.getTimestamp(2);
				if (!vf.after(docDate))
					retValue = rs.getInt(1);
			}
			rs.close();
			pstmt.close();
		}
		catch (SQLException e)
		{
			Log.error ("InfoProduct.findPLV", e);
		}
		Env.setContext(Env.getCtx(), m_WindowNo, "M_PriceList_Version_ID", retValue);
		return retValue;
	}	//	findPLV

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

	/**
	 *	Construct SQL Where Clause and define parameters
	 *  (setParameters needs to set parameters)
	 *  Includes first AND
	 *  @return SQL WHERE clause
	 */
	String getSQLWhere()
	{
		StringBuffer where = new StringBuffer(" AND pr.M_PriceList_Version_ID=?");

		//  => Value
		String value = fieldValue.getText().toUpperCase();
		if (!(value.equals("") || value.equals("%")))
			where.append(" AND UPPER(p.Value) LIKE ?");

		//  => Name
		String name = fieldName.getText().toUpperCase();
		if (!(name.equals("") || name.equals("%")))
			where.append(" AND UPPER(p.Name) LIKE ?");

		return where.toString();
	}	//	getSQLWhere

	/**
	 *  Set Parameters for Query
	 *  (as defined in getSQLWhere)
	 *
	 * @param pstmt pstmt
	 * @throws SQLException
	 */
	void setParameters(PreparedStatement pstmt) throws SQLException
	{
		int index = 1;

		//  => Warehouse
		int M_Warehouse_ID = 0;
		KeyNamePair wh = (KeyNamePair)pickWarehouse.getSelectedItem();
		if (wh != null)
			M_Warehouse_ID = wh.getKey();
		for (int i = 0; i < m_layout.length; i++)
		{
			if (m_layout[i].getColSQL().indexOf("?") != -1)
				pstmt.setInt(index++, M_Warehouse_ID);
		}
		Log.trace(Log.l5_DData, "InfoProduct.setParameters", "M_Warehouse_ID=" + M_Warehouse_ID + " (" + (index-1) + "*)");

		//  => PriceList
		int M_PriceList_Version_ID = 0;
		KeyNamePair pl = (KeyNamePair)pickPriceList.getSelectedItem();
		if (pl != null)
			M_PriceList_Version_ID = pl.getKey();
		pstmt.setInt(index++, M_PriceList_Version_ID);
		Log.trace(Log.l5_DData, "InfoProduct.setParameters", "M_PriceList_Version_ID=" + M_PriceList_Version_ID);

		//  => Value
		String value = fieldValue.getText().toUpperCase();
		if (!(value.equals("") || value.equals("%")))
		{
			if (!value.endsWith("%"))
				value += "%";
			pstmt.setString(index++, value);
			Log.trace(Log.l5_DData, "InfoProduct.setParameters", "Value: " + value);
		}

		//  => Name
		String name = fieldName.getText().toUpperCase();
		if (!(name.equals("") || name.equals("%")))
		{
			if (!name.endsWith("%"))
				name += "%";
			pstmt.setString(index++, name);
			Log.trace(Log.l5_DData, "InfoProduct.setParameters", "Name: " + name);
		}

	}   //  setParameters

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

	/**
	 *  Action Listner
	 *
	 * @param e event
	 */
	public void actionPerformed (ActionEvent e)
	{
		//  don't requery if fieldValue and fieldName are empty
		if ((e.getSource() == pickWarehouse || e.getSource() == pickPriceList)
			&& (fieldValue.getText().length() == 0 && fieldName.getText().length() == 0))
			return;
		//
		super.actionPerformed(e);
	}   //  actionPerformed


	/**
	 *	Show History
	 */
	void showHistory()
	{
		Log.trace(Log.l1_User, "InfoProduct.showHistory");
		Integer M_Product_ID = getSelectedRowKey();
		if (M_Product_ID == null)
			return;

		InvoiceHistory ih = new InvoiceHistory (this, 0, M_Product_ID.intValue());
		ih.setVisible(true);
		ih = null;
	}	//	showHistory

	/**
	 *	Has History
	 *
	 * @return true (has history)
	 */
	boolean hasHistory()
	{
		return true;
	}	//	hasHistory

	/**
	 *	Zoom
	 */
	void zoom()
	{
		Log.trace(Log.l1_User, "InfoProduct.zoom");
		Integer M_Product_ID = getSelectedRowKey();
		if (M_Product_ID == null)
			return;
		MQuery query = new MQuery("M_Product");
		query.addRestriction("M_Product_ID", MQuery.EQUAL, M_Product_ID);
		zoom (140, query);
	}	//	zoom

	/**
	 *	Has Zoom
	 *  @return (has zoom)
	 */
	boolean hasZoom()
	{
		return true;
	}	//	hasZoom

	/**
	 *	Customize
	 */
	void customize()
	{
		Log.trace(Log.l1_User, "InfoProduct.customize");
	}	//	customize

	/**
	 *	Has Customize
	 *  @return false (no customize)
	 */
	boolean hasCustomize()
	{
		return false;	//	for now
	}	//	hasCustomize

	/**
	 *	Save Selection Settings for PriceList
	 */
	void saveSelectionDetail()
	{
		KeyNamePair kn = (KeyNamePair)pickPriceList.getSelectedItem();
		Env.setContext(Env.getCtx(), m_WindowNo, "M_PriceList_Version_ID", kn.getKey());
		//
		kn = (KeyNamePair)pickWarehouse.getSelectedItem();
		Env.setContext(Env.getCtx(), m_WindowNo, "M_Warehouse_ID", kn.getKey());
	}	//	saveSelectionDetail

	/**
	 *  Get Product Layout
	 *
	 * @return array of Column_Info
	 */
	private Info_Column[] getProductLayout()
	{
		//  Euro 13
		if (Env.getContext(Env.getCtx(), "#Client_Value").equals("FRIE"))
		{
			final Info_Column[] frieLayout = {
				new Info_Column(" ", "p.M_Product_ID", IDColumn.class),
		//		new Info_Column(Msg.translate(Env.getCtx(), "Value"), "p.Value", String.class),
				new Info_Column(Msg.translate(Env.getCtx(), "Name"), "p.Name", String.class),
				new Info_Column(Msg.translate(Env.getCtx(), "QtyAvailable"), "BOM_Qty_Available(p.M_Product_ID,?) AS QtyAvailable", Double.class, true, true, null),
				new Info_Column(Msg.translate(Env.getCtx(), "PriceList"), "BOM_PriceList(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceList",  BigDecimal.class),
				new Info_Column(Msg.translate(Env.getCtx(), "PriceStd"), "BOM_PriceStd(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceStd", BigDecimal.class),
				new Info_Column("Einzel MWSt", "pr.PriceStd * 1.16", BigDecimal.class),
				new Info_Column("Einzel kompl", "(pr.PriceStd+13) * 1.16", BigDecimal.class),
				new Info_Column("Satz kompl", "(pr.PriceStd+13) * 4 * 1.16", BigDecimal.class),
				new Info_Column(Msg.translate(Env.getCtx(), "QtyOnHand"), "BOM_Qty_OnHand(p.M_Product_ID,?) AS QtyOnHand", Double.class),
				new Info_Column(Msg.translate(Env.getCtx(), "QtyReserved"), "BOM_Qty_Reserved(p.M_Product_ID,?) AS QtyReserved", Double.class),
				new Info_Column(Msg.translate(Env.getCtx(), "QtyOrdered"), "BOM_Qty_Ordered(p.M_Product_ID,?) AS QtyOrdered", Double.class),
				new Info_Column(Msg.translate(Env.getCtx(), "Discontinued").substring(0, 1), "p.Discontinued", Boolean.class),
				new Info_Column(Msg.translate(Env.getCtx(), "Margin"), "BOM_PriceStd(p.M_Product_ID, pr.M_PriceList_Version_ID)-BOM_PriceLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS Margin", BigDecimal.class),
				new Info_Column(Msg.translate(Env.getCtx(), "PriceLimit"), "BOM_PriceLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceLimit", BigDecimal.class)
			};
			return frieLayout;
		}
		return s_productLayout;
	}   //  getProductLayout

}	//	InfoProduct

⌨️ 快捷键说明

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