www.pudn.com > code_source_compiere_erp_crm_logiciel_java.zip > MBankAccount.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 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.compiere.util.*; 
 
 
/** 
 *  Bank Account Model 
 * 
 *  @author Jorg Janke 
 *  @version $Id: MBankAccount.java,v 1.3 2003/05/04 06:40:55 jjanke Exp $ 
 */ 
public class MBankAccount 
  extends PO 
{ 
	/** 
	 * 	Bank Account Model 
	 *	@param ctx context 
	 *	@param C_BankAccount_ID bank account 
	 */ 
	public MBankAccount (Properties ctx, int C_BankAccount_ID) 
	{ 
		super (ctx, C_BankAccount_ID); 
		if (C_BankAccount_ID == 0) 
		{ 
			setIsDefault (false); 
			setBankAccountType (null); 
			setAccountNo (null); 
			setCurrentBalance (Env.ZERO); 
			setC_Currency_ID (0); 
			setCreditLimit (Env.ZERO); 
			setC_BankAccount_ID (0); 
			setC_Bank_ID (0); 
		} 
	}	//	MBankAccount 
 
	/** 
	 * 	Bank Account Model 
	 *	@param ctx context 
	 *	@param rs result set 
	 */ 
	public MBankAccount (Properties ctx, ResultSet rs) 
	{ 
		super (ctx, rs); 
	} 
 
	protected POInfo initPO (Properties ctx) 
	{ 
		int AD_Table_ID = 297; 
		POInfo poi = POInfo.getPOInfo (ctx, AD_Table_ID); 
		return poi; 
	} 
 
	public boolean save () 
	{ 
		Log.trace (Log.l4_Data, "MBankAccount.save"); 
		return super.save (); 
	} 
 
	public String toString () 
	{ 
		StringBuffer sb = new StringBuffer ("MBankAccount[") 
			.append (getID()) 
			.append("-").append(getAccountNo()) 
			.append ("]"); 
		return sb.toString (); 
	} 
 
	public void setIsDefault (boolean IsDefault) 
	{ 
		setValue ("IsDefault", new Boolean (IsDefault)); 
	} 
 
	public boolean isDefault () 
	{ 
		Boolean bb = (Boolean)getValue ("IsDefault"); 
		if (bb != null) 
			return bb.booleanValue (); 
		return false; 
	} 
 
	public void setStmtProcessorClass (String StmtProcessorClass) 
	{ 
		setValue ("StmtProcessorClass", StmtProcessorClass); 
	} 
 
	public String getStmtProcessorClass () 
	{ 
		return (String)getValue ("StmtProcessorClass"); 
	} 
 
 
	public static final String BankAccountType_Checking = "C"; 
	public static final String BankAccountType_Savings = "S"; 
 
	public void setBankAccountType (String BankAccountType) 
	{ 
		if (BankAccountType.equals ("C") || BankAccountType.equals ("S")) 
			; 
		else 
			throw new IllegalArgumentException ("BankAccountType Invalid value - Reference_ID=216 - C - S"); 
		if (BankAccountType == null) 
			throw new IllegalArgumentException ("BankAccountType is mandatory"); 
		setValue ("BankAccountType", BankAccountType); 
	} 
 
	public String getBankAccountType () 
	{ 
		return (String)getValue ("BankAccountType"); 
	} 
 
	public void setAccountNo (String AccountNo) 
	{ 
		if (AccountNo == null) 
			throw new IllegalArgumentException ("AccountNo is mandatory"); 
		setValue ("AccountNo", AccountNo); 
	} 
 
	public String getAccountNo () 
	{ 
		return (String)getValue ("AccountNo"); 
	} 
 
	public void setCurrentBalance (BigDecimal CurrentBalance) 
	{ 
		if (CurrentBalance == null) 
			throw new IllegalArgumentException ("CurrentBalance is mandatory"); 
		setValue ("CurrentBalance", CurrentBalance); 
	} 
 
	public BigDecimal getCurrentBalance () 
	{ 
		BigDecimal bd = (BigDecimal)getValue ("CurrentBalance"); 
		if (bd == null) 
			return Env.ZERO; 
		return bd; 
	} 
 
	public void setC_Currency_ID (int C_Currency_ID) 
	{ 
		setValue ("C_Currency_ID", new Integer (C_Currency_ID)); 
	} 
 
	public int getC_Currency_ID () 
	{ 
		Integer ii = (Integer)getValue ("C_Currency_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	public void setCreditLimit (BigDecimal CreditLimit) 
	{ 
		if (CreditLimit == null) 
			throw new IllegalArgumentException ("CreditLimit is mandatory"); 
		setValue ("CreditLimit", CreditLimit); 
	} 
 
	public BigDecimal getCreditLimit () 
	{ 
		BigDecimal bd = (BigDecimal)getValue ("CreditLimit"); 
		if (bd == null) 
			return Env.ZERO; 
		return bd; 
	} 
 
	void setC_BankAccount_ID (int C_BankAccount_ID) 
	{ 
		setValueNoCheck ("C_BankAccount_ID", new Integer (C_BankAccount_ID)); 
	} 
 
	public int getC_BankAccount_ID () 
	{ 
		Integer ii = (Integer)getValue ("C_BankAccount_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	void setC_Bank_ID (int C_Bank_ID) 
	{ 
		setValueNoCheck ("C_Bank_ID", new Integer (C_Bank_ID)); 
	} 
 
	public int getC_Bank_ID () 
	{ 
		Integer ii = (Integer)getValue ("C_Bank_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	/*************************************************************************/ 
 
	/**	Payment Processprs					*/ 
	private MPaymentProcessor[]		m_pp = null; 
	/**	Payment Amount for CC selection		*/ 
	private BigDecimal 		m_payAmt = Env.ZERO; 
 
	/** 
	 * 	Get Payment Processors 
	 *	@return Payment Processor list 
	 */ 
	private MPaymentProcessor[] getPaymentProcessors() 
	{ 
		if (m_pp == null) 
		{ 
			ArrayList list = new ArrayList(); 
			String sql = "SELECT * FROM C_PaymentProcessor WHERE C_BankAccount_ID=?"; 
			PreparedStatement pstmt = null; 
			try 
			{ 
				pstmt = DB.prepareStatement(sql); 
				pstmt.setInt(1, getC_BankAccount_ID()); 
				ResultSet rs = pstmt.executeQuery(); 
				while (rs.next()) 
				{ 
					list.add(new MPaymentProcessor(getCtx(), rs)); 
				} 
				rs.close(); 
				pstmt.close(); 
				pstmt = null; 
			} 
			catch (Exception e) 
			{ 
				Log.error("", e); 
			} 
			finally 
			{ 
				try 
				{ 
					if (pstmt != null) 
						pstmt.close (); 
				} 
				catch (Exception e) 
				{} 
				pstmt = null; 
			} 
 
 
			// 
			m_pp = new MPaymentProcessor[list.size()]; 
			list.toArray(m_pp); 
		} 
		return m_pp; 
	}	//	getPaymentProcessors 
 
	/** 
	 * 	Set Payment Amount for Credit Card selection 
	 *	@param amt Amount 
	 */ 
	public void setPayAmt(BigDecimal amt) 
	{ 
		if (amt != null) 
			m_payAmt = amt; 
	}	//	setPayAmt 
 
	/** 
	 * 	Get Accepted Credit Cards for PayAmt (default 0) 
	 *	@return credit cards 
	 */ 
	public ValueNamePair[] getCreditCards () 
	{ 
		return getCreditCards(m_payAmt); 
	}	//	getCreditCards 
 
	/** 
	 * 	Get Accepted Credit Cards for amount 
	 *	@param amt trx amount 
	 *	@return credit cards 
	 */ 
	public ValueNamePair[] getCreditCards (BigDecimal amt) 
	{ 
		getPaymentProcessors(); 
		BigDecimal amexLimit = new BigDecimal(300);		//	hard coded limit 
		HashMap map = new HashMap(); 
		for (int i = 0; i < m_pp.length; i++) 
		{ 
			if (m_pp[i].isAcceptAMEX() && amexLimit.compareTo(amt) < 1) 
				map.put(MPayment.CC_AMEX, new ValueNamePair(MPayment.CC_AMEX, "Amex")); 
			if (m_pp[i].isAcceptDiners()) 
				map.put(MPayment.CC_DINERS, new ValueNamePair(MPayment.CC_DINERS, "Diners")); 
			if (m_pp[i].isAcceptDiscover()) 
				map.put(MPayment.CC_DISCOVER, new ValueNamePair(MPayment.CC_DISCOVER, "Discover")); 
			if (m_pp[i].isAcceptMC()) 
				map.put(MPayment.CC_MASTERCARD, new ValueNamePair(MPayment.CC_MASTERCARD, "MasterCard")); 
			if (m_pp[i].isAcceptCorporate()) 
				map.put(MPayment.CC_PURCHASE, new ValueNamePair(MPayment.CC_PURCHASE, "Corporate")); 
			if (m_pp[i].isAcceptVisa()) 
				map.put(MPayment.CC_VISA, new ValueNamePair(MPayment.CC_VISA, "Visa")); 
		}	//	for all payment processors 
		// 
		ValueNamePair[] retValue = new ValueNamePair[map.size()]; 
		map.values().toArray(retValue); 
		return retValue; 
	}	//	getCreditCards 
 
	/*************************************************************************/ 
 
}	//	MBankAccount