<?php

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

class statistics extends DooModel {

    public $sid;
    public $date;
    public $cid;
    public $staff;
    public $rePrice;
    public $agPrice;
    
    public $_table = 'CLD_statistics';
    public $_primarykey = 'sid';
    
    public $_fields = array('sid',  'staff', 'rePrice', 'date', 'cid','agPrice');

    function statisticsByYear($year,$sid){
    	//
    	$sql = "select sum(rePrice) as rePrice,sum(agPrice) as agPrice from " . $this->_table . " where staff= '".$sid."' and Year(date) =".$year." group by Year(date)" ;
    	//echo '<div style="display:none">'.$sql.'</div>';
    	$query = Doo::db ()->query ( $sql );
		$result = $query->fetch ();
		
		return $result;
    }
    
	function statisticsByComPanyYear($year,$sid){
    	//staff= '".$sid."' and
    	$sql = "select sum(rePrice) as rePrice,sum(agPrice) as agPrice from " . $this->_table . " where  Year(date) =".$year." group by Year(date)" ;
    	$query = Doo::db ()->query ( $sql );
		$result = $query->fetch ();
		
		return $result;
    }
    
	function statisticsByCid($year,$cid){
    	//
    	$sql = "select sum(rePrice) as rePrice,sum(agPrice) as agPrice from " . $this->_table . " where cid= '".$cid."' and Year(date) =".$year." group by Year(date)" ;
    	$query = Doo::db ()->query ( $sql );
		$result = $query->fetch ();
		
		return $result;
    }
    /*
    public function getProjectByIdList($projectid){
    	return $this->find ( array ('where' => "pid= '".$projectid."'", 'asArray' => TRUE ) );
    }
    */
}

?>