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

📄 mbpartner.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 Smart Business Solution
 * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
 * Portions created by Jorg Janke are Copyright (C) 1999-2003 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 java.io.Serializable;
import org.apache.log4j.Logger;

import org.compiere.util.DB;
import org.compiere.util.Env;

/**
 *	Business Partner Model
 *
 *  @author Jorg Janke
 *  @version $Id: MBPartner.java,v 1.10 2003/04/28 04:18:58 jjanke Exp $
 */
public class MBPartner extends PO
{
	/**
	 * 	Get Template Business Partner
	 * 	@param ctx context
	 * 	@param AD_Client_ID client
	 * 	@return Template Business Partner or null
	 */
	public static MBPartner getTemplate (Properties ctx, int AD_Client_ID)
	{
		if (s_template != null)
			return s_template;
		//
		String sql = "SELECT * FROM C_BPartner "
			+ "WHERE C_BPartner_ID=(SELECT C_BPartnerCashTrx_ID FROM AD_ClientInfo WHERE AD_Client_ID=?)";
		PreparedStatement pstmt = null;
		try
		{
			pstmt = DB.prepareStatement(sql);
			pstmt.setInt(1, AD_Client_ID);
			ResultSet rs = pstmt.executeQuery();
			if (rs.next())
				s_template = new MBPartner (ctx, rs);
			else
				s_log.error("getTemplate - No Template BP for AD_Client_ID=" + AD_Client_ID);
			rs.close();
			pstmt.close();
			pstmt = null;
		}
		catch (Exception e)
		{
			s_log.error("getTemplate", e);
		}
		finally
		{
			try
			{
				if (pstmt != null)
					pstmt.close ();
			}
			catch (Exception e)
			{}
			pstmt = null;
		}
		//	Reset
		if (s_template != null)
		{
			s_template.setValueNoCheck ("C_BPartner_ID", null);
			s_template.setValueNoCheck ("Value", "");
			s_template.setValueNoCheck ("Name", "");
			s_template.setValueNoCheck ("Name2", "");
			s_template.setSO_CreditLimit (Env.ZERO);
			s_template.setSO_CreditUsed (Env.ZERO);
		}
		return s_template;
	}	//	getTemplate

	/**	Static Logger				*/
	private static Logger		s_log = Logger.getLogger (PO.class);
	/** Tamplate BPartner			*/
	private static 	MBPartner	s_template;

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

	/**
	 * 	Constructor for new BPartner from Template
	 * 	@param ctx context
	 */
	public MBPartner (Properties ctx)
	{
		this (ctx, -1);
	}

	/**
	 * 	Default Constructor
	 * 	@param ctx context
	 * 	@param rs ResultSet to load from
	 */
	public MBPartner (Properties ctx, ResultSet rs)
	{
		super (ctx, rs);
	}	//	MBPartner

	/**
	 * 	Default Constructor
	 * 	@param ctx context
	 * 	@param C_BPartner_ID partner or 0 or -1 (load from template)
	 */
	public MBPartner (Properties ctx, int C_BPartner_ID)
	{
		super (ctx, C_BPartner_ID);
		//
		if (C_BPartner_ID == -1)
		{
			getTemplate (Env.getContextAsInt(ctx, "AD_Client_ID"));
			C_BPartner_ID = 0;
		}
		if (C_BPartner_ID == 0)
		{
			setValueNoCheck ("Value", "");
			setValueNoCheck ("Name", "");
			setName2("");
			setDUNS("");
			setFirstSale(null);
			//
			setIsCustomer (true);
			setIsProspect (true);
			//
			setSendEMail (false);
			setIsOneTime (false);
			setIsVendor (false);
			setIsSummary (false);
			setIsEmployee (false);
			setIsSalesRep (false);
			//
			setSO_CreditLimit (Env.ZERO);
			setSO_CreditUsed (Env.ZERO);
		}
		log.info(toString());
	}	//	MBPartner

	private MBPartner_Contact[]		m_contacts = null;
	private MBPartner_Location[]	m_locations = null;
	private MBP_BankAccount[]		m_accounts = null;


	protected POInfo initPO (Properties ctx)
	{
		int AD_Table_ID = 291;
		POInfo poi = POInfo.getPOInfo (ctx, AD_Table_ID);
		return poi;
	}

	/**
	 * 	Load Default BPartner
	 * 	@param AD_Client_ID client
	 */
	private void getTemplate (int AD_Client_ID)
	{
		if (AD_Client_ID == 0)
			throw new IllegalArgumentException ("MBPartner new - Client_ID=0");

		String sql = "SELECT * FROM C_BPartner "
			+ "WHERE C_BPartner_ID=(SELECT C_BPartnerCashTrx_ID FROM AD_ClientInfo WHERE AD_Client_ID=?)";
		PreparedStatement pstmt = null;
		try
		{
			pstmt = DB.prepareStatement(sql);
			pstmt.setInt(1, AD_Client_ID);
			ResultSet rs = pstmt.executeQuery();
			if (rs.next())
				load (rs);
			else
				log.error("getTemplate - None found");
			rs.close();
			pstmt.close();
			pstmt = null;
		}
		catch (Exception e)
		{
			log.error("getTemplate", e);
		}
		finally
		{
			try
			{
				if (pstmt != null)
					pstmt.close ();
			}
			catch (Exception e)
			{}
			pstmt = null;
		}
		setStandardDefaults();
		setValueNoCheck("C_BPartner_ID", null);
		setValueNoCheck("Value", null);
		setValueNoCheck("Name", null);
		setName2(null);
	}	//	loadDefaultBPartner


	/**
	 * 	Get Contacts
	 *	@return contacts
	 */
	public MBPartner_Contact[] getContacts()
	{
		if (m_contacts == null || m_contacts.length == 0)
			;
		else
			return m_contacts;
		//
		ArrayList list = new ArrayList();
		String sql = "SELECT * FROM C_BPartner_Contact WHERE C_BPartner_ID=?";
		PreparedStatement pstmt = null;
		try
		{
			pstmt = DB.prepareStatement(sql);
			pstmt.setInt(1, getC_BPartner_ID());
			ResultSet rs = pstmt.executeQuery();
			while (rs.next())
				list.add(new MBPartner_Contact (getCtx(), rs));
			rs.close();
			pstmt.close();
			pstmt = null;
		}
		catch (Exception e)
		{
			log.error("getContacts", e);
		}
		finally
		{
			try
			{
				if (pstmt != null)
					pstmt.close ();
			}
			catch (Exception e)
			{}
			pstmt = null;
		}

		m_contacts = new MBPartner_Contact[list.size()];
		list.toArray(m_contacts);
		return m_contacts;
	}	//	getContacts

	/**
	 * 	Get Locations
	 *	@return locations
	 */
	public MBPartner_Location[] getLocations()
	{
		if (m_locations == null || m_locations.length == 0)
			;
		else
			return m_locations;
		//
		ArrayList list = new ArrayList();
		String sql = "SELECT * FROM C_BPartner_Location WHERE C_BPartner_ID=?";
		PreparedStatement pstmt = null;
		try
		{
			pstmt = DB.prepareStatement(sql);
			pstmt.setInt(1, getC_BPartner_ID());
			ResultSet rs = pstmt.executeQuery();
			while (rs.next())
				list.add(new MBPartner_Location (getCtx(), rs));
			rs.close();
			pstmt.close();
			pstmt = null;
		}
		catch (Exception e)
		{
			log.error("getLocations", e);
		}
		finally
		{
			try
			{
				if (pstmt != null)
					pstmt.close ();
			}
			catch (Exception e)
			{}
			pstmt = null;
		}

		m_locations = new MBPartner_Location[list.size()];
		list.toArray(m_locations);
		return m_locations;
	}	//	getLocations

	/**
	 * 	Get Bank Accounts
	 *	@return Bank Accounts
	 */
	public MBP_BankAccount[] getBankAccounts()
	{
		if (m_accounts == null || m_accounts.length == 0)	//	re-load
			;
		else
			return m_accounts;
		//
		ArrayList list = new ArrayList();
		String sql = "SELECT * FROM C_BP_BankAccount WHERE C_BPartner_ID=?";
		PreparedStatement pstmt = null;
		try
		{
			pstmt = DB.prepareStatement(sql);
			pstmt.setInt(1, getC_BPartner_ID());
			ResultSet rs = pstmt.executeQuery();
			while (rs.next())
				list.add(new MBP_BankAccount (getCtx(), rs));
			rs.close();
			pstmt.close();
			pstmt = null;
		}
		catch (Exception e)
		{
			log.error("getBankAccounts", e);
		}
		finally
		{
			try
			{
				if (pstmt != null)
					pstmt.close ();
			}
			catch (Exception e)
			{}
			pstmt = null;
		}

		m_accounts = new MBP_BankAccount[list.size()];
		list.toArray(m_accounts);
		return m_accounts;
	}	//	getBankAccounts

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

	/**
	 * 	Save
	 *	@return true if saved
	 */
	public boolean save ()
	{
		log.info ("save");
		return super.save ();
	}

	public String toString ()
	{
		StringBuffer sb = new StringBuffer ("MBPartner[ID=")
			.append(getID())
			.append(",Value=").append(getValue())
			.append(",Name=").append(getName())
			.append ("]");
		return sb.toString ();
	}

	public void setC_PaymentTerm_ID (int C_PaymentTerm_ID)
	{
		setValue ("C_PaymentTerm_ID", new Integer (C_PaymentTerm_ID));
	}

	public int getC_PaymentTerm_ID ()
	{
		Integer ii = (Integer)getValue ("C_PaymentTerm_ID");
		if (ii == null)
			return 0;
		return ii.intValue ();
	}

	public void setName2 (String Name2)
	{
		setValue ("Name2", Name2);
	}

	public String getName2 ()
	{
		return (String)getValue ("Name2");
	}

	public void setInvoiceRule (String InvoiceRule)
	{
		if (InvoiceRule.equals ("D") || InvoiceRule.equals ("I")
		  || InvoiceRule.equals ("O") || InvoiceRule.equals ("S"))
			;
		else
			throw new IllegalArgumentException (
			  "InvoiceRule Invalid value - Reference_ID=150 - D - I - O - S");
		setValue ("InvoiceRule", InvoiceRule);
	}

	public String getInvoiceRule ()
	{
		return (String)getValue ("InvoiceRule");
	}

	public void setC_BP_Group_ID (int C_BP_Group_ID)
	{
		setValue ("C_BP_Group_ID", new Integer (C_BP_Group_ID));
	}

	public int getC_BP_Group_ID ()
	{
		Integer ii = (Integer)getValue ("C_BP_Group_ID");
		if (ii == null)
			return 0;
		return ii.intValue ();
	}

	public void setC_InvoiceSchedule_ID (int C_InvoiceSchedule_ID)
	{
		setValue ("C_InvoiceSchedule_ID", new Integer (C_InvoiceSchedule_ID));
	}

	public int getC_InvoiceSchedule_ID ()
	{
		Integer ii = (Integer)getValue ("C_InvoiceSchedule_ID");
		if (ii == null)
			return 0;
		return ii.intValue ();
	}

	public int getC_BPartner_ID ()
	{
		return getID();
	}

	public void setTaxID (String TaxID)
	{
		setValue ("TaxID", TaxID);
	}

	public String getTaxID ()
	{
		return (String)getValue ("TaxID");
	}

	public void setPO_PaymentTerm_ID (int PO_PaymentTerm_ID)
	{
		setValue ("PO_PaymentTerm_ID", new Integer (PO_PaymentTerm_ID));
	}

	public int getPO_PaymentTerm_ID ()
	{
		Integer ii = (Integer)getValue ("PO_PaymentTerm_ID");
		if (ii == null)
			return 0;
		return ii.intValue ();
	}

	public void setSO_Description (String SO_Description)
	{
		setValue ("SO_Description", SO_Description);
	}

	public String getSO_Description ()
	{
		return (String)getValue ("SO_Description");
	}

	public void setSO_CreditLimit (BigDecimal SO_CreditLimit)
	{
		if (SO_CreditLimit == null)
			throw new IllegalArgumentException ("SO_CreditLimit is mandatory");
		setValue ("SO_CreditLimit", SO_CreditLimit);
	}

	public BigDecimal getSO_CreditLimit ()
	{
		BigDecimal bd = (BigDecimal)getValue ("SO_CreditLimit");
		if (bd == null)
			return Env.ZERO;
		return bd;
	}

	public void setFreightCostRule (String FreightCostRule)
	{
		if (FreightCostRule.equals ("C") || FreightCostRule.equals ("F")
		  || FreightCostRule.equals ("I") || FreightCostRule.equals ("L"))
			;
		else
			throw new IllegalArgumentException (
			  "FreightCostRule Invalid value - Reference_ID=153 - C - F - I - L");
		setValue ("FreightCostRule", FreightCostRule);
	}

	public String getFreightCostRule ()
	{
		return (String)getValue ("FreightCostRule");
	}

	public void setDeliveryViaRule (String DeliveryViaRule)
	{
		if (DeliveryViaRule.equals ("D") || DeliveryViaRule.equals ("P")
		  || DeliveryViaRule.equals ("S"))
			;

⌨️ 快捷键说明

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