<?php
Doo::loadCore ( 'db/DooModel' );
class invoiceInfoBase extends DooModel {
	public $iibID;
	public $invoiceTitle;
	public $TIN;
	public $address;
	public $phone;
	public $bank;
	public $bankAccount;
	public $updateDate;
	
	public $_table = 'CLD_invoiceInfoBase';
	public $_primarykey = 'iibID';
	public $_fields = array (
			'iibID',
			'invoiceTitle',
			'TIN',
			'address',
			'phone',
			'bank',
			'bankAccount',
			'updateDate'
	);
	
	/**
	 * 
	 */
	function getIFBByTitle($fill=''){
		if(empty($fill)){
			return array();
		}
		return $this->find ( array ('where' => "invoiceTitle like '%".$fill."%'", 'asArray' => TRUE ) );
	}
	
	function getIFBByTIN($fill=''){
		if(empty($fill)){
			return array();
		}
		return $this->find ( array ('where' => "TIN like '%".$fill."%'", 'asArray' => TRUE ) );
	}
	
	/**
	 * 根据纳税人识别码和抬头获得发票
	 * @param string $TIN
	 * @return unknown
	 */
	function getInvoiceInfoByTT($TIN='',$invoiceTitle=''){
		if(empty($TIN)){
			return array();
		}
		
		$list = $this->find ( array ( 
				'where' => "(TIN=  '" . $TIN."' and invoiceTitle='".$invoiceTitle."' ) or TIN=  '" . $TIN."' or invoiceTitle='".$invoiceTitle."'",
				'asArray' => TRUE 
		) );
		
		return $list;
	}
	
	/**
	 * 添加一个发票并进入审批状态
	 * @param array $item 发票相关数据
	 * @return number 返回发票ID
	 */
	public function addInvoiceInfoBase($item = array()) {
		$lid = 0;
		if (is_array ( $item ) && ! empty ( $item )) {
			foreach ( $item as $key => $value ) {
				$this->$key = $value;
			}
			$lid = $this->insert ();
		}
		return $lid;
	}
	/**
	 * 根据参数字段更新相应字段（主键ID必须传）
	 * @param array $item 相关需要更新的字段信息
	 * @return number 返回发票ID
	 */
	public function setInvoiceInfoBaseByCondition($item = array()) {
		$lid = 0;
		if (is_array ( $item ) && ! empty ( $item )) {
			foreach ( $item as $key => $value ) {
				$this->$key = $value;
			}
			$lid = $this->update ();
		}
		return $lid;
	}
	
	public function delInvoiceInfoBaseByIibStr($iibIDStr=''){
		if (empty($iibIDStr)){
			return '';
		}
		$sql='delete from '.$this->_table.' where iibID in('.$iibIDStr.')';
		$query = Doo::db ()->query ( $sql );
	}
	
}

?>