<?php

Doo::loadCore ( 'db/DooModel' );

class longle extends DooModel {
	
	public $lid;
	public $year;
	public $cid;
	public $category;
	public $status;
	public $statuslog;
	public $statusT;
	public $key_num;
	public $product;
	public $alloted_time;
	public $product_id;
	public $make_day;
	public $version;
	public $responsible;
	public $client;
	public $clientid;
	public $licences;
	public $SerialNumber;
	
	
	public $_table = 'CLD_longle';
	public $_primarykey = 'lid';
	public $_fields = array ('lid', 'year', 'cid','category','product_id', 'status','statuslog','statusT', 'key_num','SerialNumber','product','alloted_time', 'make_day','version', 'responsible','client','clientid'
			,'licences'
	);
	
	public function getLongleByStatus($year=0,$cid=0,$staff=0,$status=0,$search="",$productW=""){
		
		if(empty($search)){
			$str="( status=".$status." or statuslog like '%".$status."%' )";
			$str2=" and make_day like '%".$year."%'";
			$str3=" and cid =".$cid."";
			$str4=" and product like '%".$productW."%'";
			$str5=' and responsible="'.$staff.'"';
			if(empty($productW))
				$str4="";
				
			if($cid==0)
				$str3="";
				
			if($year==0)
				$str2="";

			if(empty($staff))
				$str5="";

			if($status==0)
				$str=" 1 ";
				
				//echo $str.$str2.$str3.$str4;
				
//			'select * form CLD_longle as a left join CLD_client as b on (a.clientid =b.cid) where ( status=3 or statuslog like "%3%" ) and make_day like "%2015%" and cid =10';
			return $this->find ( array ('where' => $str.$str2.$str3.$str4.$str5, 'asArray' => TRUE ) );
		}else{
			return $this->find ( array ('where' => " key_num like '%".$search."%'", 'asArray' => TRUE ) );
		}
	}
	
	public function getLongleReceive($cid,$status,$othercid=""){
		
		$str="";
		if(!empty($othercid))
			$str= " cid in (".$cid.",".$othercid." )";
		else 
			$str= " cid in (".$cid." )";
			
		return $this->find ( array ('where' => $str." and status=".$status, 'asArray' => TRUE ) );
	}
	
	public function getLongleBykeynum($keynum){
		return $this->find ( array ('where' => " key_num = '".$keynum."'", 'asArray' => TRUE ) );
	}
	
	public function getLongleBykeynum2($keynum){
		return $this->find ( array ('where' => " key_num like '%".$keynum."%'",'limit'=>'10', 'asArray' => TRUE ) );
	}
	
	public function getLongleByLid($lid){
		return $this->find ( array ('where' => " lid =".$lid, 'asArray' => TRUE ) );
	}
	
	public function getLongleByClient($clientname){
		return $this->find ( array ('where' => " client like '".$clientname."'", 'asArray' => TRUE ) );
	}
	
	public function getLongleByClientid($client){
		return $this->find ( array ('where' => " clientid = '".$client."'", 'asArray' => TRUE ) );
	}
	
//	public function getLongleByRe($cid,$status=1){
//		
//	}
	
	public function getUser() {
		return $this->find ( array ('asc' => 'uid', 'asArray' => TRUE ) );
	}

	public function getUserByIdList($puid){
		return $this->find ( array ('where' => "uid= '".$puid."'", 'asArray' => TRUE ) );
	}
	
}

?>