<?php

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

class client extends DooModel {

    public $cid;
    public $gender;
    public $qq;
    public $nicename;
    public $telephone;
    public $phone;
    public $email;
    public $clientname;
    public $keynum;
    public $companyid;
    public $tag;
    public $tooltip;
    public $nature;
    public $companyname;
    
    public $local;
    public $district;
    public $unit;
	public $fax;
	public $webservice;
	public $department;
	public $position;
	public $office;
	public $address;
	public $ride;
	public $stay;
	public $landmarks;
    public $mark;
    public $priority;
    public $updatetime;
    public $servicetime;
    
    public $_table = 'CLD_client';
    public $_primarykey = 'cid';
    public $_fields = array('cid', 'gender','qq', 'nature','nicename','companyname', 'telephone','phone','qq','email','clientname','keynum','companyid','unit','tooltip','tag'
    ,'district','fax','webservice','department','position','office','address','ride','stay','landmarks','mark','priority','updatetime','servicetime','local');

    function getlaborhoutByPid($pid,$date,$uid){
    	
    	$uidstr="";
    	
    	if(!empty($uid))
    		$uidstr=" and a.uid =".$uid;
    		
    	$sql = "select a.day,b.color,a.worktime from " . $this->_table . " as a left join user as b on (a.uid=b.uid)  where a.pid= '".$pid."' ".$uidstr." and a.dateline = '".$date."'" ;
		
    	$query = Doo::db ()->query ( $sql );
		
		$result = $query->fetchAll ();
		
		return $result;
    }
    
    function getClientToName($clientname,$companyname,$local){
    	return $this->find ( array ('where' => "clientname = '".$clientname."' and companyname = '".$companyname."' and district = '".$local."'", 'asArray' => TRUE ) );
    }
    
	function getClientByName2($name,$company){
		
    	return $this->find ( array ('where' => "clientname = '".$name."' and companyname ='".$company."'", 'asArray' => TRUE ) );
    }
    
    function getClientByName($name){
    	return $this->find ( array ('where' => "clientname like '%".$name."%'", 'asArray' => TRUE ) );
    }
    
	function getClientByNameT($name){
    	return $this->find ( array ('where' => "clientname like '".$name."'", 'asArray' => TRUE ) );
    }
    
	function getClientByDistrict($str){
    	return $this->find ( array ('where' => $str, 'asArray' => TRUE ) );
    }
    
    function getClientByCompanyId($cid){
    	return $this->find ( array ('where' => "companyid= '".$cid."'",'asc'=>'priority','asArray' => TRUE ) );
    }
	
    function getCountByCompany($comcid){
    	$sql = "select count(*) as count,companyid from " . $this->_table . " where companyid in (".$comcid.") GROUP BY companyid" ;
		
    	$query = Doo::db ()->query ( $sql );
		
		$result = $query->fetchAll ();
		
		return $result;
    }
    
    function getDepartment($comcid){
    	$sql = "select department from " . $this->_table . " where companyid in (".$comcid.") GROUP BY department" ;
		
    	$query = Doo::db ()->query ( $sql );
		
		$result = $query->fetchAll ();
		
		return $result;
    }

    function getClientByID($id){
        return $this->getOne ( array ('where' => "cid=?", 'param' => array($id), 'asArray' => TRUE ) );
    }
    
}

?>