<?php
Doo::loadCore ( 'db/DooModel' );
class RIExtend extends DooModel {
	public $riid;
	public $rid;
	public $iid;
	public $RIstatus;
	
	public $_table = 'CLD_RIExtend';
	public $_primarykey = 'riid';
	public $_fields = array (
			'riid',
			'rid',
			'iid',
			'RIstatus',
			
	);
	
	/**
	 * 
	 */
	function getRIExtendByRid($rid=0){
		$sql = 'select a.iid,b.irid
				from ' . $this->_table . ' as a left join  CLD_invoice  as b on (a.iid=b.iid)
				where b.status=2 and b.printStatus=1 and  b.untreadStatus=3 and b.irid!="" and a.RIstatus=1 and a.rid= '.$rid;
		
		$query = Doo::db ()->query ( $sql );
		$list = $query->fetchAll ();
		return $list;
	}
	
	/**
	 */
	function getAccountBookByLimit($limit = 3) {
		$sql = 'select *
				from ' . $this->_table . '
						 ORDER BY  aid desc limit ' . $limit;
		$query = Doo::db ()->query ( $sql );
		$list = $query->fetchAll ();
		
		Doo::loadClass ( 'XDeode' );
		$XDeode = new XDeode ( 5 );
		
		foreach ( $list as $key => $value ) {
			$list [$key] ['aidKey'] = $XDeode->encode ( $value ['aid'] );
		}
		
		return $list;
	}
	/**
	 *
	 * @param number $limit
	 * @param string $con
	 * @param string $desc
	 * @return boolean
	 */
	function getAccountBookBySql($limit = 0, $con = "", $desc = 'desc') {
		
		// $listCount = $this->count ( array (
		// 'where' => $con,
		// 'asArray' => TRUE
		// ) );
		$list = $this->find ( array (
				'where' => '1 ' . $con,
				'limit' => $limit,
				$desc => 'aid',
				'asArray' => TRUE 
		) ); // echo $con;
		Doo::loadClass ( 'XDeode' );
		$XDeode = new XDeode ( 5 );
		
		foreach ( $list as $key => $value ) {
			// $list [$key] ['count'] = $listCount;
			$list [$key] ['aidKey'] = $XDeode->encode ( $value ['aid'] );
		}
		
		return $list;
	}
	
}

?>