<?php
Doo::loadCore ( 'db/DooModel' );
class accountBook extends DooModel {
	public $aid;
	public $expensesType;
	public $accountType;
	public $accountMsg;
	public $receivedPrice;
	public $receivedMsg;
	public $receivedBank;
	public $receivedDate;
	public $expenditureType;
	public $expenditureMsg;
	public $expenditurePrice;
	public $expenditureBank;
	public $bookSerial;
	public $inputDate;
	public $remarks;
	public $expenditureDate;
	
	public $inputStaff;
	
	public $_table = 'CLD_accountBook';
	public $_primarykey = 'aid';
	public $_fields = array (
			'aid',
			'expensesType',
			'accountType',
			'accountMsg',
			'receivedPrice',
			'receivedMsg',
			'receivedBank',
			'receivedDate',
			'expenditureType',
			'expenditureMsg',
			'expenditurePrice',
			'expenditureBank',
			
			'expenditureDate',
			
			'bookSerial',
			'remarks',
			'inputDate' ,
			'inputStaff'
	);
	
	/**
	 */
	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;
	}
	function getAccountBookByAid($aid = 0, $select = "") {
		
		Doo::loadClass ( 'XDeode' );
		$XDeode = new XDeode ( 5 );
		Doo::loadModel ( 'staff' );
		$staff = new staff ();
		
		if (! is_numeric ( $aid ))
			$aid=$XDeode->decode( $aid );
			
		
		$condition = array (
				'where' => "aid=" . $aid,
				'asArray' => TRUE 
		);
		if (! empty ( $select ))
			$condition += array (
					'select' => $select 
			);
		
		$Detail = array ();
		if (is_numeric ( $aid ) && ! empty ( $aid ))
			$Detail = $this->getOne ( $condition );
		
		if (empty ( $Detail ))
			return $Detail;
		
		$Detail ['aidKey'] = $XDeode->encode ( $Detail ['aid'] );
		
		$Detail['expenditureTypeMsg']='';
		if($Detail ['expenditureType']==1){
			$Detail['expenditureTypeMsg']='银行手续费';
		}elseif($Detail ['expenditureType']==2){
			$Detail['expenditureTypeMsg']='总部电话费';
		}elseif($Detail ['expenditureType']==3){
			$Detail['expenditureTypeMsg']='缴税';
		}elseif($Detail ['expenditureType']==4){
			$Detail['expenditureTypeMsg']='广发理财';
		}elseif($Detail ['expenditureType']==5){
			$Detail['expenditureTypeMsg']='保证金';
		}elseif($Detail ['expenditureType']==6){
			$Detail['expenditureTypeMsg']='工行理财';
		}elseif($Detail ['expenditureType']==7){
			$Detail['expenditureTypeMsg']='理财支出';
		}
		
		$Detail['incomeTypeMsg']='';
		if($Detail ['accountType']==1){
			$Detail['incomeTypeMsg']='利息收入';
		}elseif($Detail ['accountType']==2){
			$Detail['incomeTypeMsg']='补贴收入';
		}elseif($Detail ['accountType']==3){
			$Detail['incomeTypeMsg']='纵横知道';
		}elseif($Detail ['accountType']==4){
			$Detail['incomeTypeMsg']='借款收回';
		}elseif($Detail ['accountType']==5){
			$Detail['incomeTypeMsg']='退汇';
		}elseif($Detail ['accountType']==6){
			$Detail['incomeTypeMsg']='其他';
		}elseif($Detail ['accountType']==7){
			$Detail['incomeTypeMsg']='广发理财';
		}elseif($Detail ['accountType']==8){
			$Detail['incomeTypeMsg']='保证金';
		}elseif($Detail ['accountType']==9){
			$Detail['incomeTypeMsg']='工行理财';
		}elseif($Detail ['accountType']==10){
			$Detail['incomeTypeMsg']='理财收入';
		}
		
		$Detail['staffDetail']=$staff->getStaffBySid($Detail['inputStaff']);
		
		return $Detail;
	}
	
	
	
}

?>