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

/**
 * 开票操作日志 业务逻辑
 *
 * @author CP.
 * @version 1.0
 * @namespace invoice
 * @package invoiceModel
 */
class invoiceOperationLog extends DooModel {
	
	/**
	 *
	 * @var integer $lid 操作日志ID
	 */
	public $lid;
	/**
	 *
	 * @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 $iid;
	/**
	 * 发票操作时的状态
	 * @var integer
	 */
	public $status;
	/**
	 * 表名
	 * @var string
	 */
	public $_table = 'CLD_invoiceOperationLog';
	/**
	 * 表主键
	 * @var string
	 */
	public $_primarykey = 'lid';
	/**
	 * 表字段
	 * @var array
	 */
	public $_fields = array (
			'lid',
			'username',
			'uid',
			'category',
			'date',
			'operation',
			'img',
			'iid',
			'status' 
	);
	public function __construct() {
		parent::setupModel ( __CLASS__ );
	}
	/**
	 * 添加相关开票操作日志
	 *
	 * @param array $item 要记录的相关发票操作数据
	 * @return integer|0 返回操作ID
	 */
	public function setInvoiceOperationLog($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 integer $iid 发票ID
	 * @param integer $desc 获得一条操作日志最新或者最旧
	 * @return array|array() 发票审批操作日志数据集
	 */
	public function getInvoiceOperationLogByIid($iid = 0, $desc = '') {
		$list = array ();
		if (! empty ( $iid ) && is_numeric ( $iid ) && empty ( $desc ))
			$list = $this->find ( array (
					'where' => ' iid=' . $iid,
					'asArray' => true 
			) );
		elseif (! empty ( $desc ))
			$list = $this->getOne ( array (
					'where' => 'iid=' . $iid,
					$desc => 'lid',
					'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;
	}
	
	public function getInvoiceOperationInStatus($iid = 0, $status = '0'){
		$list = $this->getOne ( array (
				'where' => 'iid=' . $iid . ' and status in(' . $status.')',
				'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;
	}
	
	/**
	 * 根据sql执行
	 * @param string $sql
	 * @return boolean
	 */
	function setInvoiceOperationLogBySql($sql = "") {
		if (empty ( $sql ))
			return false;
		$query = Doo::db ()->query ( $sql );
		
		return true;
	}
}

?>