<?php
Doo::loadCore ( 'db/DooModel' );
/**
 * 收款退款相关信息及其操作业务逻辑
 * @author CP.
 * @version 1.0
 * @namespace invoice
 * @package invoiceModel
 */
class invoiceRefund extends DooModel {
	
	public $ireid;
	public $irid;
	public $refundType;
	public $refundCompany;
	public $refundNumber;
	public $refundPrice;
	public $refundLog;
	public $refundRemarks;
	public $date;
	public $_table = 'CLD_invoiceRefund';
	public $_primarykey = 'ireid';
	public $_fields = array (
			'ireid',
			'irid',
			'refundType',
			'refundCompany',
			'refundNumber',
			'refundPrice',
			'refundLog',
			'refundRemarks',
			'date' 
	);
	
	/**
	 * 根据irid获得退款信息
	 */
	public function getInvoiceRefundIrid($irid=0){
		if (empty($irid))
			return array();
		return $list = $this->find ( array ( 
				'where' => 'irid='.$irid,
				'asc'=>'ireid',
				'asArray' => TRUE
		));
	}
	
	/**
	 * 添加一个发票并进入审批状态
	 * @param array $item 发票相关数据
	 * @return number 返回发票ID
	 */
	public function addInvoiceRefund($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 setInvoicePaperByCondition($item = array()) {
		$lid = 0;
		if (is_array ( $item ) && ! empty ( $item )) {
			foreach ( $item as $key => $value ) {
				$this->$key = $value;
			}
			$lid = $this->update ();
		}
		return $lid;
	}
	
	
}

?>