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

📄 calloutsystem.java

📁 Java写的ERP系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
				if (C_BPartner_ID.toString().equals(Env.getContext(ctx, WindowNo, Env.TAB_INFO, "C_BPartner_ID")))
				{
					String cont = Env.getContext(ctx, WindowNo, Env.TAB_INFO, "C_BPartner_Contact_ID");
					if (cont.length() > 0)
						contID = Integer.parseInt(cont);
				}
				if (contID == 0)
					mTab.setValue("C_BPartner_Contact_ID", null);
				else
					mTab.setValue("C_BPartner_Contact_ID", new Integer(contID));

				//	CreditAvailable
				double CreditAvailable = rs.getDouble("CreditAvailable");
				if (!rs.wasNull() && CreditAvailable < 0)
					mTab.fireDataStatusEEvent("CreditLimitOver",
						DisplayType.getNumberFormat(DisplayType.Amount).format(CreditAvailable));

				//	PO Reference
				s = rs.getString("POReference");
				if (s != null && s.length() != 0)
					mTab.setValue("POReference", s);
				else
					mTab.setValue("POReference", null);
				//	SO Description
				s = rs.getString("SO_Description");
				if (s != null && s.trim().length() != 0)
					mTab.setValue("Description", s);
				//	IsDiscountPrinted
				s = rs.getString("IsDiscountPrinted");
				if (s != null && s.length() != 0)
					mTab.setValue("IsDiscountPrinted", s);
				else
					mTab.setValue("IsDiscountPrinted", "N");
			}
			rs.close();
			pstmt.close();
		}
		catch (SQLException e)
		{
			s_log.error("Invoice_BPartner", e);
			return e.getLocalizedMessage();
		}

		return "";
	}	//	Invoice_BPartner

	/**************************************************************************
	 *	Invoice Line
	 *			- Defaults for Product
	 *			- UOM
	 *			- PriceList, PriceStd
	 */
	private static String Invoice_Product (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value)
	{
		Integer M_Product_ID = (Integer)value;
		if (M_Product_ID == null || M_Product_ID.intValue() == 0)
			return "";
		calloutActive = true;
		mTab.setValue("C_Charge_ID", null);

		//	get order date - or default to today's date
		Timestamp orderDate = Env.getContextAsDate(ctx, WindowNo, "DateInvoiced");
		if (orderDate == null)
			orderDate = new Timestamp(System.currentTimeMillis());

		String SQL = "SELECT BOM_PriceStd(p.M_Product_ID,pv.M_PriceList_Version_ID) AS PriceStd,"
			+ "BOM_PriceList(p.M_Product_ID,pv.M_PriceList_Version_ID) AS PriceList,"
			+ "BOM_PriceLimit(p.M_Product_ID,pv.M_PriceList_Version_ID) AS PriceLimit,"
			+ "p.C_UOM_ID,pv.ValidFrom,pl.C_Currency_ID "
			+ "FROM M_Product p, M_ProductPrice pp, M_Pricelist pl, M_PriceList_Version pv "
			+ "WHERE p.M_Product_ID=pp.M_Product_ID"
			+ " AND pp.M_PriceList_Version_ID=pv.M_PriceList_Version_ID"
			+ " AND pv.M_PriceList_ID=pl.M_PriceList_ID"
			+ " AND pv.IsActive='Y'"
			+ " AND p.M_Product_ID=?"				//	1
			+ " AND pv.M_PriceList_Version_ID=?";	//	2
		try
		{
			boolean noPrice = true;
			BigDecimal priceActual = Env.ZERO;

			//	Check if Product was selected from Info
			int M_PriceList_Version_ID = Env.getContextAsInt(ctx, WindowNo, "M_PriceList_Version_ID");
			if (M_PriceList_Version_ID != 0)
			{
				PreparedStatement pstmt = DB.prepareStatement(SQL);
				pstmt.setInt(1, M_Product_ID.intValue());
				pstmt.setInt(2, M_PriceList_Version_ID);
				ResultSet rs = pstmt.executeQuery();
				if (rs.next())
				{
					noPrice = false;
					//	UOM
					Integer ii = new Integer(rs.getInt("C_UOM_ID"));
					if (!rs.wasNull())
						mTab.setValue("C_UOM_ID", ii);
					//	Price List
					mTab.setValue("PriceList", rs.getBigDecimal("PriceList"));
					if (rs.wasNull())
						mTab.setValue("PriceList", Env.ZERO);
					//	Price Std
					priceActual = rs.getBigDecimal("PriceStd");
					//  Price Limit
					mTab.setValue("PriceLimit", rs.getBigDecimal("PriceLimit"));
					if (rs.wasNull())
						mTab.setValue("PriceLimit", Env.ZERO);
					//	Currency
				//	ii = new Integer(rs.getInt("C_Currency_ID"));
				//	if (!rs.wasNull())
				//		mTab.setValue("C_Currency_ID", ii);
				}
				rs.close();
				pstmt.close();
			}

			//	Search Pricelist for current version
			if (noPrice)
			{
				SQL = "SELECT BOM_PriceStd(p.M_Product_ID,pv.M_PriceList_Version_ID) AS PriceStd,"
					+ "BOM_PriceList(p.M_Product_ID,pv.M_PriceList_Version_ID) AS PriceList,"
					+ "BOM_PriceLimit(p.M_Product_ID,pv.M_PriceList_Version_ID) AS PriceLimit,"
					+ "p.C_UOM_ID,pv.ValidFrom,pl.C_Currency_ID "
					+ "FROM M_Product p, M_ProductPrice pp, M_Pricelist pl, M_PriceList_Version pv "
					+ "WHERE p.M_Product_ID=pp.M_Product_ID"
					+ " AND pp.M_PriceList_Version_ID=pv.M_PriceList_Version_ID"
					+ " AND pv.M_PriceList_ID=pl.M_PriceList_ID"
					+ " AND pv.IsActive='Y'"
					+ " AND p.M_Product_ID=?"		//	1
					+ " AND pl.M_PriceList_ID=?"	//	2
					+ " ORDER BY pv.ValidFrom DESC";
				PreparedStatement pstmt = DB.prepareStatement(SQL);
				pstmt.setInt(1, M_Product_ID.intValue());
				pstmt.setInt(2, Env.getContextAsInt(ctx, WindowNo, "M_PriceList_ID"));
				ResultSet rs = pstmt.executeQuery();
				while (rs.next() && noPrice)
				{
					java.sql.Date plDate = rs.getDate("ValidFrom");
					//	we have the price list
					//	if order date is after or equal PriceList validFrom
					if (plDate == null || !orderDate.before(plDate))
					{
						noPrice = false;
						//	UOM
						Integer ii = new Integer(rs.getInt("C_UOM_ID"));
						if (!rs.wasNull())
							mTab.setValue("C_UOM_ID", ii);
						//	Price List
						mTab.setValue("PriceList", rs.getBigDecimal("PriceList"));
						if (rs.wasNull())
							mTab.setValue("PriceList", Env.ZERO);
						//	Price Std
						priceActual = rs.getBigDecimal("PriceStd");
						//  Price Limit
						mTab.setValue("PriceLimit", rs.getBigDecimal("PriceLimit"));
						if (rs.wasNull())
							mTab.setValue("PriceLimit", Env.ZERO);
					}
				}
				rs.close();
				pstmt.close();
			}

			//	no prices yet - look base pricelist
			if (noPrice)
			{
				//	Find if via Base Pricelist
				SQL = "SELECT BOM_PriceStd(p.M_Product_ID,pv.M_PriceList_Version_ID) AS PriceStd,"
					+ "BOM_PriceList(p.M_Product_ID,pv.M_PriceList_Version_ID) AS PriceList,"
					+ "BOM_PriceLimit(p.M_Product_ID,pv.M_PriceList_Version_ID) AS PriceLimit,"
					+ "p.C_UOM_ID,pv.ValidFrom,pl.C_Currency_ID "
					+ "FROM M_Product p, M_ProductPrice pp, M_Pricelist pl, M_Pricelist bpl, M_PriceList_Version pv "
					+ "WHERE p.M_Product_ID=pp.M_Product_ID"
					+ " AND pp.M_PriceList_Version_ID=pv.M_PriceList_Version_ID"
					+ " AND pv.M_PriceList_ID=bpl.M_PriceList_ID"
					+ " AND pv.IsActive='Y'"
					+ " AND bpl.M_PriceList_ID=pl.BasePriceList_ID"	//	Base
					+ " AND p.M_Product_ID=?"		//  1
					+ " AND pl.M_PriceList_ID=?"	//	2
					+ " ORDER BY pv.ValidFrom DESC";

				PreparedStatement pstmt = DB.prepareStatement(SQL);
				pstmt.setInt(1, M_Product_ID.intValue());
				pstmt.setInt(2, Env.getContextAsInt(ctx, WindowNo, "M_PriceList_ID"));
				ResultSet rs = pstmt.executeQuery();
				while (rs.next() && noPrice)
				{
					java.sql.Date plDate = rs.getDate("ValidFrom");
					//	we have the price list
					//	if order date is after or equal PriceList validFrom
					if (plDate == null || !orderDate.before(plDate))
					{
						noPrice = false;
						//	UOM
						Integer ii = new Integer(rs.getInt("C_UOM_ID"));
						if (!rs.wasNull())
							mTab.setValue("C_UOM_ID", ii);
						//	Price List
						mTab.setValue("PriceList", rs.getBigDecimal("PriceList"));
						if (rs.wasNull())
							mTab.setValue("PriceList", Env.ZERO);
						//	Price Std
						priceActual = rs.getBigDecimal("PriceStd");
						//  Price Limit
						mTab.setValue("PriceLimit", rs.getBigDecimal("PriceLimit"));
						if (rs.wasNull())
							mTab.setValue("PriceLimit", Env.ZERO);
					}
				}
				rs.close();
				pstmt.close();
			}

			//	still no price, get UOM
			if (noPrice)
			{
				SQL = "SELECT C_UOM_ID FROM M_Product WHERE M_Product_ID=?";
				PreparedStatement pstmt = DB.prepareStatement(SQL);
				pstmt.setInt(1, M_Product_ID.intValue());
				ResultSet rs = pstmt.executeQuery();
				if (rs.next())
				{
					//	UOM
					Integer ii = new Integer(rs.getInt(1));
					if (!rs.wasNull())
						mTab.setValue("C_UOM_ID", ii);
				}
				rs.close();
				pstmt.close();
			}
			//
			calloutActive = false;	//	calculate discount, etc.
			if (priceActual == null)
				priceActual = Env.ZERO;
			mTab.setValue("PriceActual", priceActual);
		}
		catch (SQLException e)
		{
			s_log.error("Invoice_Product", e);
			calloutActive = false;
			return e.getLocalizedMessage();
		}

	//	calloutActive = true;
		return "";
	}	//	Invoice_Product


	/**
	 *	Invoice - Tax.
	 *			- called when tax basis changes (Product)
	 *			- sets C_Tax_ID
	 */
	private static String Invoice_Tax (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value)
	{
		String column = mField.getColumnName();
		if (value == null)
			return "";

		//	Check Product
		int M_Product_ID = 0;
		if (column.equals("M_Product_ID"))
			M_Product_ID = ((Integer)value).intValue();
		else
			M_Product_ID = Env.getContextAsInt(ctx, WindowNo, "M_Product_ID");
		int C_Charge_ID = 0;
		if (column.equals("C_Charge_ID"))
			C_Charge_ID = ((Integer)value).intValue();
		else
			C_Charge_ID = Env.getContextAsInt(ctx, WindowNo, "C_Charge_ID");
		s_log.debug("Product=" + M_Product_ID + ", C_Charge_ID=" + C_Charge_ID);
		if (M_Product_ID == 0 && C_Charge_ID == 0)
			return "";

		//	Check Partner Location
		int shipC_BPartner_Location_ID = Env.getContextAsInt(ctx, WindowNo, "C_BPartner_Location_ID");
		if (shipC_BPartner_Location_ID == 0)
			return "";
		s_log.debug("Ship BP_Location=" + shipC_BPartner_Location_ID);
		int billC_BPartner_Location_ID = shipC_BPartner_Location_ID;
		s_log.debug("Bill BP_Location=" + billC_BPartner_Location_ID);

		//	Dates
		Timestamp billDate = Env.getContextAsDate(ctx, WindowNo, "DateInvoiced");
		s_log.debug("Bill Date=" + billDate);
		Timestamp shipDate = billDate;
		s_log.debug("Ship Date=" + shipDate);

		int AD_Org_ID = Env.getContextAsInt(ctx, WindowNo, "AD_Org_ID");
		s_log.debug("Org=" + AD_Org_ID);

		int M_Warehouse_ID = Env.getContextAsInt(ctx, "#M_Warehouse_ID");
		s_log.debug("Warehouse=" + M_Warehouse_ID);

		//
		int C_Tax_ID = Tax.get(ctx, M_Product_ID, C_Charge_ID, billDate, shipDate,
			AD_Org_ID, M_Warehouse_ID, billC_BPartner_Location_ID, shipC_BPartner_Location_ID,
			Env.getContext(ctx, WindowNo, "IsSOTrx").equals("Y"));
		s_log.debug("Tax ID=" + C_Tax_ID);
		//
		if (C_Tax_ID == 0)
			mTab.fireDataStatusEEvent(Log.retrieveError());
		else
			mTab.setValue("C_Tax_ID", new Integer(C_Tax_ID));
		return "";
	}	//	Invoice_Tax


	/**
	 *	Invoice - Amount.
	 *		- called from QtyInvoiced, Discount and PriceActual
	 *		- calculates LineNetAmt
	 */
	private static String Invoice_Amt (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value)
	{
		if (calloutActive)
			return "";
		calloutActive = true;

		int StdPrecision = Env.getContextAsInt(ctx, WindowNo, "StdPrecision");
		//	get values
		BigDecimal QtyInvoiced = (BigDecimal)mTab.getValue("QtyInvoiced");		//
		BigDecimal PriceActual = ((BigDecimal)mTab.getValue("PriceActual")).setScale(StdPrecision, BigDecimal.ROUND_HALF_UP);

		//	Multiply
		BigDecimal LineNetAmt = QtyInvoiced.multiply(PriceActual);
		if (LineNetAmt.scale() > StdPrecision)
			LineNetAmt = LineNetAmt.setScale(StdPrecision, BigDecimal.ROUND_HALF_UP);
		mTab.setValue("LineNetAmt", LineNetAmt);
		s_log.debug("Line=" + LineNetAmt);

		calloutActive = false;
		return "";
	}	//	Invoice_Amt


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

	/**
	 *	Inventory - Product.
	 *			- QtyOnHand
	 */
	private static String Inventory_Product (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value)
	{
		if (value == null)
			return "";

		int M_Product_ID = ((Integer)value).intValue();
		int M_Locator_ID = Env.getContextAsInt(ctx, WindowNo, "M_Locator_ID");
		if (M_Product_ID == 0 || M_Locator_ID == 0)
			return "";

		String SQL = "SELECT QtyOnHand FROM M_Storage "
			+ "WHERE M_Product_ID=?"	//	1
			+ " AND M_Locator_ID=?";	//	2
		try
		{
			PreparedStatement pstmt = DB.prepareStatement(SQL);
			pstmt.setInt(1, M_Product_ID);
			pstmt.setInt(2, M_Locator_ID);
			ResultSet rs = pstmt.executeQuery();
			if (rs.next())
			{
				BigDecimal bd = rs.getBigDecimal(1);
				if (!rs.wasNull())
					mTab.setValue("QtyBook", bd);
			}
			rs.close();
			pstmt.close();
		}
		catch (SQLException e)
		{
			s_log.error("Inventory_Product", e);
			return e.getLocalizedMessage();
		}

		return "";
	}	//	Inventory_Product

⌨️ 快捷键说明

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