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

📄 uom.java

📁 Java写的ERP系统
💻 JAVA
字号:
/******************************************************************************
 * 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.model;

import java.util.*;
import java.sql.*;
import java.math.*;

import org.compiere.util.*;

/**
 *	Unit Of Measure (R/O Value Object)
 *
 * 	@author 	Jorg Janke
 * 	@version 	$Id: UOM.java,v 1.3 2002/06/29 04:32:17 jjanke Exp $
 */
public class UOM
{
	/**
	 *	Constructor
	 *
	 *  @param C_UOM_ID UOM ID
	 *  @param X12DE355 X12 Data Element 355
	 *  @param UOMSymbol UOM Symbol
	 *  @param Name Name
	 *  @param Description Description
	 *  @param StdPrecision Standard precision
	 *  @param CostingPrecision Costing Precision
	 */
	public UOM (int C_UOM_ID, String X12DE355, String UOMSymbol,
		String Name, String Description, int StdPrecision, int CostingPrecision)
	{
		m_C_UOM_ID = C_UOM_ID;
		if (X12DE355 != null)
			m_X12DE355 = X12DE355;
		if (UOMSymbol != null)
			m_UOMSymbol = UOMSymbol;
		if (Name != null)
			m_Name = Name;
		if (Description != null)
			m_Description = Description;
		m_StdPrecision = StdPrecision;
		m_CostingPrecision = CostingPrecision;
	}	//	UOM

	private int 		m_C_UOM_ID = 0;
	private String 		m_X12DE355 = "";
	private String 		m_UOMSymbol = "";
	private String 		m_Name = "";
	private String 		m_Description = "";
	private int 		m_StdPrecision = 0;
	private int 		m_CostingPrecision = 0;


	public int getC_UOM_ID()
	{
		return m_C_UOM_ID;
	}
	public int getCostingPrecision()
	{
		return m_CostingPrecision;
	}
	public String getDescription()
	{
		return m_Description;
	}
	public String getName()
	{
		return m_Name;
	}
	public int getStdPrecision()
	{
		return m_StdPrecision;
	}
	public String getUOMSymbol()
	{
		return m_UOMSymbol;
	}
	public String getX12DE355()
	{
		return m_X12DE355;
	}

	public String toString()
	{
		StringBuffer sb = new StringBuffer("UOM[");
		sb.append("ID=").append(m_C_UOM_ID)
			.append(", Name=").append(m_Name);
		return sb.toString();
	}

	public BigDecimal round (BigDecimal qty)
	{
		return qty.setScale(m_StdPrecision, BigDecimal.ROUND_HALF_UP);
	}

	public boolean isMinute()
	{
		return X12_MINUTE.equals(m_X12DE355);
	}
	public boolean isHour()
	{
		return X12_HOUR.equals(m_X12DE355);
	}
	public boolean isDay()
	{
		return X12_DAY.equals(m_X12DE355);
	}
	public boolean isWorkDay()
	{
		return X12_DAY_WORK.equals(m_X12DE355);
	}
	public boolean isWeek()
	{
		return X12_WEEK.equals(m_X12DE355);
	}
	public boolean isMonth()
	{
		return X12_MONTH.equals(m_X12DE355);
	}
	public boolean isWorkMonth()
	{
		return X12_MONTH_WORK.equals(m_X12DE355);
	}
	public boolean isYear()
	{
		return X12_YEAR.equals(m_X12DE355);
	}

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

	/** X12 Element 355 Code	Minute	*/
	static final String		X12_MINUTE = "MJ";
	/** X12 Element 355 Code	Hour	*/
	static final String		X12_HOUR = "HR";
	/** X12 Element 355 Code	Day 	*/
	static final String		X12_DAY = "DA";
	/** X12 Element 355 Code	Work Day (8 hours / 5days)	 	*/
	static final String		X12_DAY_WORK = "WD";
	/** X12 Element 355 Code	Week 	*/
	static final String		X12_WEEK = "WK";
	/** X12 Element 355 Code	Month 	*/
	static final String		X12_MONTH = "MO";
	/** X12 Element 355 Code	Work Month (20 days / 4 weeks) 	*/
	static final String		X12_MONTH_WORK = "WM";
	/** X12 Element 355 Code	Year 	*/
	static final String		X12_YEAR = "YR";


	/**
	 * 	Get UOM from Server
	 * 	@param ctx context
	 *	@param C_UOM_ID ID
	 * 	@return UOM
	 */
	public static UOM getUOM (Properties ctx, int C_UOM_ID)
	{
		if (Ini.isClient())
			return getUOMfromCache(ctx, C_UOM_ID);
		String sql = Access.addROAccessSQL(ctx,
			"SELECT C_UOM_ID, X12DE355, UOMSymbol, "
			+ "Name, Description, StdPrecision, CostingPrecision "
			+ "FROM C_UOM "
			+ "WHERE IsActive='Y' AND C_UOM_ID=?",
			   "C_UOM", false);
		UOM retValue = null;
		try
		{
			PreparedStatement pstmt = DB.prepareStatement(sql);
			pstmt.setInt(1, C_UOM_ID);
			ResultSet rs = pstmt.executeQuery();
			if (rs.next())
			{
				retValue = new UOM(rs.getInt(1), rs.getString(2), rs.getString(3).trim(),
					rs.getString(4), rs.getString(5), rs.getInt(6), rs.getInt(7));
			}
			rs.close();
			pstmt.close();
		}
		catch (SQLException e)
		{
			Log.error("UOM.getUOM", e);
		}
		return retValue;
	}	//	getUOM

	/**
	 * 	Get Minute C_UOM_ID
	 *  @param ctx context
	 * 	@return C_UOM_ID for Minute
	 */
	public static int getMinute_UOM_ID (Properties ctx)
	{
		if (Ini.isClient())
		{
			if (s_UOMs == null)
				s_UOMs = getUOMs (ctx);
			//
			for (int i = 0; i < s_UOMs.length; i++)
			{
				if (s_UOMs[i].isMinute())
					return s_UOMs[i].getC_UOM_ID();
			}
			return 0;
		}
		//	Server
		int C_UOM_ID = 0;
		String sql = "SELECT C_UOM_ID FROM C_UOM "
			+ "WHERE IsActive='Y' AND X12DE355='MJ'";	//	HardCoded
		try
		{
			PreparedStatement pstmt = DB.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			if (rs.next())
				C_UOM_ID = rs.getInt(1);
			rs.close();
			pstmt.close();
		}
		catch (SQLException e)
		{
			Log.error("getMinute_UOM_ID", e);
		}
		return C_UOM_ID;
	}	//	getMinute_UOM_ID

	/**
	 * 	Get All UOMs
	 * 	@param ctx context
	 * 	@return UOM Array
	 */
	public static UOM[] getUOMs (Properties ctx)
	{
		String sql = Access.addROAccessSQL(ctx,
			"SELECT C_UOM_ID, X12DE355, UOMSymbol, "
			+ "Name, Description, StdPrecision, CostingPrecision "
			+ "FROM C_UOM "
			+ "WHERE IsActive='Y'",
			"C_UOM", false);
		ArrayList list = new ArrayList();
		try
		{
			PreparedStatement pstmt = DB.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next())
			{
				UOM uom = new UOM(rs.getInt(1), rs.getString(2), rs.getString(3).trim(),
					rs.getString(4), rs.getString(5), rs.getInt(6), rs.getInt(7));
				list.add(uom);
			}
			rs.close();
			pstmt.close();
		}
		catch (SQLException e)
		{
			Log.error("UOM.getUOMs", e);
		}
		UOM[] retValue = new UOM[list.size()];
		list.toArray(retValue);
		return retValue;
	}	//	getUOMs

	/**	UOM Cache				*/
	private static UOM[]	s_UOMs = null;

	/**
	 * 	Get UOM from Cache
	 * 	@param ctx context
	 *	@param C_UOM_ID ID
	 * 	@return UOM
	 */
	private static UOM getUOMfromCache (Properties ctx, int C_UOM_ID)
	{
		if (s_UOMs == null)
			s_UOMs = getUOMs (ctx);
		//
		for (int i = 0; i < s_UOMs.length; i++)
		{
			if (s_UOMs[i].getC_UOM_ID() == C_UOM_ID)
				return s_UOMs[i];
		}
		return null;
	}	//	getUOMfromCache

}	//	UOM

⌨️ 快捷键说明

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