<?php
Doo::loadCore ( 'db/DooModel' );

/**
 * 开票操作日志 业务逻辑
 *
 * @author CP.
 * @version 1.0
 * @namespace invoice
 * @package invoiceModel
 */
class invoiceROLog extends DooModel {
	
	/**
	 *
	 * @var integer $lid 操作日志ID
	 */
	public $iroId;
	/**
	 *
	 * @var string $username 操作员相关：名称
	 */
	public $username;
	/**
	 *
	 * @var string $category 办事处
	 */
	public $category;
	/**
	 *
	 * @var string $img 操作员相关：头像
	 */
	public $img;
	/**
	 *
	 * @var integer $uid 用户ID
	 */
	public $uid;
	/**
	 * 操作时间
	 * @var datetime
	 */
	public $date;
	/**
	 * 操作动作
	 * @var string
	 */
	public $operation;
	
	/**
	 * 开票ID
	 * @var integer
	 */
	public $irid;
	/**
	 * 发票操作时的状态
	 * @var integer
	 */
	public $status;
	/**
	 * 表名
	 * @var string
	 */
	public $_table = 'CLD_invoiceROLog';
	/**
	 * 表主键
	 * @var string
	 */
	public $_primarykey = 'iroId';
	/**
	 * 表字段
	 * @var array
	 */
	public $_fields = array (
			'iroId',
			'username',
			'uid',
			'category',
			'date',
			'operation',
			'img',
			'irid',
			'status' 
	);
	public function __construct() {
		parent::setupModel ( __CLASS__ );
	}
	
	/**
	 * 添加相关收款操作日志
	 *
	 * @param array $item 要记录的相关收款操作数据
	 * @return integer|0 返回操作ID
	 */
	public function setInvoiceROLog($item = array()) {
		$lid = 0;
		if (is_array ( $item ) && ! empty ( $item )) {
			foreach ( $item as $key => $value ) {
				$this->$key = $value;
			}
			$iroId = $this->insert ();
		}
		return $iroId;
	}
	
	/**
	 * 根据收款ID获取操作日志数据
	 *
	 * @param integer $irid 收款ID
	 * @param integer $desc 获得一条操作日志最新或者最旧
	 * @return array|array() 发票审批操作日志数据集
	 */
	public function getInvoiceROLogByIrid($irid = 0, $desc = '') {
		$list = array ();
		if ( is_numeric ( $irid ) && empty ( $desc ))
			$list = $this->find ( array (
					'where' => ' irid=' . $irid,
					'asArray' => true 
			) );
		elseif (! empty ( $desc ))
			$list = $this->getOne ( array (
					'where' => 'irid=' . $irid,
					$desc => 'iroId',
					'asArray' => true 
			) );
		return $list;
	}
	
	
	
	
	/**
	 * 获得一条最新的退回操作记录
	 * @param number $iid
	 * @param string $desc
	 * @return unknown
	 */
	public function getInvoiceOperationByDropped($iid = 0,$desc = 'desc') {
		$list = $this->getOne ( array (
				'where' => ' iid=' . $iid.' and status=3',
				$desc => 'lid',
				'asArray' => true 
		) );
		return $list;
	}
	
	/**
	 * 根据状态和发票ID获得一条最新的操作日志
	 * @param number $iid
	 * @param number $status
	 * @param string $desc
	 * @return unknown
	 */
	public function getInvoiceOperationByStatus($iid = 0,$status = 0,$desc = 'desc') {
		$list = $this->getOne ( array (
				'where' => 'iid=' . $iid.' and status='.$status,
				$desc => 'lid',
				'asArray' => true
		) );
		return $list;
	}
	
}

?>